project QadFinancials > class BDPaymentSelection > method CalculateDPaySelLine

Description

Calculate the calculated fields on DPaySelLine.


Parameters


ilPrepaymentOnlyinputlogical
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDPaymentSelection.Calculate
method BDPaymentSelection.StoreSelectedObjects


program code (program3/bdpaymentselection.p)

/*======================================================================*/
/*  When this method is run, the instance should already be available   */
/*======================================================================*/
if not ilPrepaymentOnly
then do:
    
   /*==================*/
    /*= DInvoice lines =*/
    /*==================*/
    assign vcDummy = {&PAYMENTSELECTIONTYPE-INVOICE}        + ',':U 
                   + {&PAYMENTSELECTIONTYPE-INVOICECORR}    + ',':U 
                   + {&PAYMENTSELECTIONTYPE-CREDITNOTE}     + ',':U
                   + {&PAYMENTSELECTIONTYPE-CREDITNOTECORR} + ',':U
                   + {&PAYMENTSELECTIONTYPE-PREPAYMENTINV}  + ',':U
                   + {&PAYMENTSELECTIONTYPE-ADJUSTMENT}.

    /* Run the DInvoice query a PaySel line of that type exists */
    if can-find(first tDPaySelLine where 
                      tDPaySelLine.tc_ParentRowid        = tDPaySel.tc_Rowid and
                      (tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICE} or
                       tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICECORR} or
                       tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTE} or
                       tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTECORR} or
                       tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENTINV} or
                       tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-ADJUSTMENT}) and
                       tDPaySelLine.DPaySelLineParentObject_ID > 0)
     then do: 
         <Q-24 run DPaySelLineDInvoiceByDPaySelId (all) (Read) (NoCache)
            (input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
             input vcDummy, (ObjectTypeList)
             input tDPaySel.DPaySel_ID, (DPaySel_Id)
             input ?, (CompanyId)
             output dataset tqDPaySelLineDInvoiceByPaySelId) in BDPaymentSelection>
    end.               
       
    for each tDPaySelLine where 
             tDPaySelLine.tc_ParentRowid       = tDPaySel.tc_Rowid and
             
             (tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-DEBTORCREDITNOTE} or
              tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-DEBTORCNCORR} or
              tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICE} or 
              tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICECORR} or
              tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTE} or
              tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTECORR}) and
             tDPaySelLine.DPaySelLineParentObject_ID > 0:
             
        find tqDPaySelLineDInvoiceByPaySelId where
             tqDPaySelLineDInvoiceByPaySelId.tiDPaySelLine_ID = tDPaySelLine.DPaySelLine_ID
             no-error.
        if not available tqDPaySelLineDInvoiceByPaySelId
        then next.

        assign tDPaySelLine.tcBusinessRelationCode    = tqDPaySelLineDInvoiceByPaySelId.tcBusinessRelationCode               
               tDPaySelLine.tcDebtorCode              = tqDPaySelLineDInvoiceByPaySelId.tcDebtorCode
               tDPaySelLine.tcDivisionCode            = tqDPaySelLineDInvoiceByPaySelId.tcDivisionCode               
               tDPaySelLine.tcDInvoiceNumber          = string(tqDPaySelLineDInvoiceByPaySelId.tiPeriodYear) + "/":U +
                                                              tqDPaySelLineDInvoiceByPaySelId.tcJournalCode + "/":U +
                                                       string(tqDPaySelLineDInvoiceByPaySelId.tiDInvoiceVoucher,"999999999":U)
               tDPaySelLine.ttDiscountDueDate         = tqDPaySelLineDInvoiceByPaySelId.ttDInvoiceDiscountDueDate
               tDPaySelLine.tdDiscountPercentage      = tqDPaySelLineDInvoiceByPaySelId.tdPaymentConditionPercentage               
               tDPaySelLine.ttInvoiceDate             = tqDPaySelLineDInvoiceByPaySelId.ttDInvoiceDate
               tDPaySelLine.tdInvoiceRate             = tqDPaySelLineDInvoiceByPaySelId.tdDInvoiceExchangeRate
               tDPaySelLine.tdInvoiceRateScale        = tqDPaySelLineDInvoiceByPaySelId.tdDinvoiceRateScale 
               tDPaySelLine.ttDueDate                 = tqDPaySelLineDInvoiceByPaySelId.ttDInvoiceDueDate
               tDPaySelLine.tcInvoiceCurrencyCode     = tqDPaySelLineDInvoiceByPaySelId.tcCurrencyCode               
               tDPaySelLine.tcInvoiceCrDt             = if tqDPaySelLineDInvoiceByPaySelId.tdDInvoiceOriginalCreditTC <> 0 and
                                                          tqDPaySelLineDInvoiceByPaySelId.tdDInvoiceOriginalCreditTC <> ?
                                                       then {&CREDITDEBITABBREVIATION-CREDIT}
                                                       else {&CREDITDEBITABBREVIATION-DEBIT}
               tDPaySelLine.tcPaymentCrDt             = if tqDPaySelLineDInvoiceByPaySelId.tdDInvoiceOriginalCreditTC <> 0 and
                                                          tqDPaySelLineDInvoiceByPaySelId.tdDInvoiceOriginalCreditTC <> ?
                                                       then {&CREDITDEBITABBREVIATION-DEBIT}
                                                       else {&CREDITDEBITABBREVIATION-CREDIT}                                                       
               tDPaySelLine.tdOpenInvoiceAmountTC     = tqDPaySelLineDInvoiceByPaySelId.tdDInvoiceBalanceDebitTC 
                                                     - tqDPaySelLineDInvoiceByPaySelId.tdDInvoiceBalanceCreditTC
               tDPaySelLine.tdOriginalInvoiceAmountTC = tqDPaySelLineDInvoiceByPaySelId.tdDInvoiceOriginalDebitTC
                                                     - tqDPaySelLineDInvoiceByPaySelId.tdDInvoiceOriginalCreditTC
               tDPaySelLine.tdOriginalInvoiceAmountNetTC = tqDPaySelLineDInvoiceByPaySelId.tdDInvoiceOriginalDebitTC
                                                        + tqDPaySelLineDInvoiceByPaySelId.tdDInvoiceVatDebitTC 
                                                        - tqDPaySelLineDInvoiceByPaySelId.tdDInvoiceOriginalCreditTC
                                                        - tqDPaySelLineDInvoiceByPaySelId.tdDInvoiceVatCreditTC.               
                        
         /* Populate the due date on the stage */
         for each tDPaySelLineStg 
            where tDPaySelLineStg.DPaySelLine_ID =  tDPaySelLine.DPaySelLine_ID:
                  
             <Q-78 run DInvoiceStageByID (all) (Read) (NoCache)
                (input tDPaySelLineStg.DInvoiceStage_ID, (DInvoiceStageID)
                 output dataset tqDInvoiceStageByID) in BDInvoice>
             for first tqDInvoiceStageByID 
                 where tqDInvoiceStageByID.tiDInvoiceStage_ID = tDPaySelLineStg.DInvoiceStage_ID:
                 assign tDPaySelLineStg.ttDInvoiceStageDueDate = tqDInvoiceStageByID.ttDInvoiceStageDueDate.
             end.
         end.

    end.
end.