project QadFinancials > class BDPaymentSelection > method DPaySelLineCalcValues


Parameters


icDPaySelLineObjectTypeinputcharacterPaySelLineObjectType
iiDPaySelLineParentObject_IDinputinteger
ocBusinessRelationCodeoutputcharacter
ocBusinessRelationName1outputcharacter
ocCorporateGroupCodeoutputcharacter
ocDebtorCodeoutputcharacter
ocInternalNumberoutputcharacter
ocExternalNumberoutputcharacter
otDiscountDueDateoutputdate
odDiscountPercentageoutputdecimal
otInvoiceDateoutputdate
otDueDateoutputdate
ocInvoiceCurrencyCodeoutputcharacter
odOpenInvoiceAmountTCoutputdecimal
odOriginalInvoiceAmountTCoutputdecimal
odOriginalInvoiceAmountNetTCoutputdecimal
odInvoiceRateoutputdecimal
odInvoiceRateScaleoutputdecimal
itDPaySelDateinputdatePaySelDate
ocDivisionCodeoutputcharacterSub-Account Code
oiMasterIDoutputinteger
odNonDiscountableAmountTCoutputdecimalNon Discount Amount
ocPaymentConditionPaymentTypeoutputcharacterNormal or Staged payment condition
odDefaultPaymentAmountTCoutputdecimal
odDefaultDiscountAmountTCoutputdecimal
ocDInvoiceDITextoutputcharacter
oiDInvoicePostingYearoutputinteger
ocJournalCodeoutputcharacter
oiDInvoiceVoucheroutputinteger
ocShipperInfooutputcharacterParameter to output shipper info
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDPaymentSelection.GetToPayObjectsInitialLoad


program code (program1/bdpaymentselection.p)

/* DInvoice lines */
if (icDPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICE}        or
    icDPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICECORR}    or
    icDPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTE}     or
    icDPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTECORR} or
    icDPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENTINV}  or
    icDPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENT}  or 
    icDPaySelLineObjectType = {&INVOICETYPE-DEDUCTION} or 
    icDPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-ADJUSTMENT}) and
    iiDPaySelLineParentObject_ID <> 0
then do:
    <Q-45 run GetDInvoiceForPaymentSelection (all) (Read) (NoCache)
       (input 0, (CompanyId)
        input ?, (IsPaymentAllowed)
        input ?, (BusinessRelationCode)
        input iiDPaySelLineParentObject_ID, (DInvoice_ID)
        input ?, (CurrencyCode)
        input ?, (DivisionCode)
        input ?, (BusinessRelationIsInterco)
        input ?, (DInvoiceType)
        input ?, (DInvoiceIsOpen)
        input ?, (DInvoiceIsSelected)
        input ?, (BusinessRelationCountryCode)
        input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
        output dataset tqGetDInvoiceForPaymentSelection) in BDInvoice>
    find first tqGetDInvoiceForPaymentSelection no-error.
    if not available tqGetDInvoiceForPaymentSelection
    then do:
        <M-94 run SetMessage
           (input  #T-39'The expected customer invoice (ID = $1) was not found. Contact your system administrator to rectify any database inconsistencies. ':150(3002)T-39# (icMessage), 
            input  string(iiDPaySelLineParentObject_ID) (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'D':U (icType), 
            input  2 (iiSeverity), 
            input  '':U (icRowid), 
            input  'qadfin-415601':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
        assign oiReturnStatus = -98.
        return.
    end.
    
    if tqGetDInvoiceForPaymentSelection.tcPaymentConditionPaymentTyp = {&PAYMENTCONDITIONPAYMENTTYPE-NORMAL}
        then do:
            assign vlDInvoiceIsWithOneBank     = false
                   vlProposePayment            = false
                   vdInvoiceAmount             = if tqGetDInvoiceForPaymentSelection.tdDInvoiceOriginalDebitTC <> 0 and
                                                    tqGetDInvoiceForPaymentSelection.tdDInvoiceOriginalDebitTC <> ?
                                                 then tqGetDInvoiceForPaymentSelection.tdDInvoiceOriginalDebitTC
                                                 else tqGetDInvoiceForPaymentSelection.tdDInvoiceOriginalCreditTC
                   vdInvoiceBalance            = if tqGetDInvoiceForPaymentSelection.tdDInvoiceBalanceDebitTC <> 0 and
                                                    tqGetDInvoiceForPaymentSelection.tdDInvoiceBalanceDebitTC <> ?
                                                 then tqGetDInvoiceForPaymentSelection.tdDInvoiceBalanceDebitTC
                                                 else tqGetDInvoiceForPaymentSelection.tdDInvoiceBalanceCreditTC.
                                                     
            <Q-30 run DInvoiceBankByDInvoiceID (all) (Read) (NoCache)
                    (input tqGetDInvoiceForPaymentSelection.tiDInvoice_ID, (DInvoiceId)
                     output dataset tqDInvoiceBankByDInvoiceID) in BDInvoice>
        
        
            find tqDInvoiceBankByDInvoiceID no-error.
            if available tqDInvoiceBankByDInvoiceID
            then assign vlDInvoiceIsWithOneBank = true.
        
            /* Propose payment if there is only one invoice bank or this is the first payment on the invoice */        
            if (vlDInvoiceIsWithOneBank or vdInvoiceBalance = vdInvoiceAmount)
            then assign vlProposePayment = true.
        
        
        /**************************************************************************************************************** 
               Calculation of Discount Base Amount 
               ===================================
              1) In case of Discount Tax at Payment = YES
                Discount Base Amount =  Invoice amount with Tax * 
                                       ((Invoice amount without Tax ?- Non-discountable amount) / Invoice amount without Tax) * 
                                       (Invoice open amount / Invoice amount with Tax).
              2) In case of Discount Tax at Payment = NO
                Discount Base Amount = (Invoice amount without Tax - Non-discountable amount) * 
                                       (Invoice open amount / Invoice amount with Tax).
         *****************************************************************************************************************/  
    
         if itDPaySelDate <= tqGetDInvoiceForPaymentSelection.ttDInvoiceDiscountDueDate
            then assign vdDiscountBase          = if tqGetDInvoiceForPaymentSelection.tlDInvoiceIsDiscTaxAtPaym
                                                  then vdInvoiceAmount * 
                                                      
                                                      ((vdInvoiceAmount - abs(tqGetDInvoiceForPaymentSelection.tdDInvoiceVatDebitTC - tqGetDInvoiceForPaymentSelection.tdDInvoiceVatCreditTC)) - tqGetDInvoiceForPaymentSelection.tdDInvoiceNonDiscAmtTC) /
                                                       (vdInvoiceAmount - abs(tqGetDInvoiceForPaymentSelection.tdDInvoiceVatDebitTC - tqGetDInvoiceForPaymentSelection.tdDInvoiceVatCreditTC)) *
                                                      
                                                      (vdInvoiceBalance / vdInvoiceAmount)
                                                      
                                                  else ((vdInvoiceAmount - abs(tqGetDInvoiceForPaymentSelection.tdDInvoiceVatDebitTC - tqGetDInvoiceForPaymentSelection.tdDInvoiceVatCreditTC)) - tqGetDInvoiceForPaymentSelection.tdDInvoiceNonDiscAmtTC) * 
                                                        
                                                        (vdInvoiceBalance / vdinvoiceAmount) 
                                                                                                       
                        vdInvoiceDiscountAmount = vdDiscountBase * tqGetDInvoiceForPaymentSelection.tdPaymentConditionPercentage / 100
                        vdInvoicePaymentAmount  = vdInvoiceBalance - vdInvoiceDiscountAmount.
            else assign vdInvoiceDiscountAmount = 0
                        vdInvoicePaymentAmount  = vdInvoiceBalance.
                        
            if vlProposePayment
                then assign vdInvoiceBankPercentage               = tqGetDInvoiceForPaymentSelection.tdDInvoiceBankToPayTC / vdInvoiceBalance
                            odDefaultDiscountAmountTC = vdInvoiceDiscountAmount * vdInvoiceBankPercentage
                            odDefaultPaymentAmountTC  = vdInvoicePaymentAmount * vdInvoiceBankPercentage.
                else assign odDefaultPaymentAmountTC = 0
                            odDefaultDiscountAmountTC = 0.
                      
                            
            assign odDefaultPaymentAmountTC =  <M-62 RoundAmount
                                                   (input  odDefaultPaymentAmountTC (idUnroundedAmount), 
                                                    input  '' (iiCurrencyID), 
                                                    input  tqGetDInvoiceForPaymentSelection.tcCurrencyCode (icCurrencyCode)) in BDPaymentSelection>
                   odDefaultDiscountAmountTC  = <M-38 RoundAmount
                                                  (input  odDefaultDiscountAmountTC (idUnroundedAmount), 
                                                   input  '' (iiCurrencyID), 
                                                   input  tqGetDInvoiceForPaymentSelection.tcCurrencyCode (icCurrencyCode)) in BDPaymentSelection>.
    end.
                                           
    assign ocBusinessRelationCode    = tqGetDInvoiceForPaymentSelection.tcBusinessRelationCode
           ocBusinessRelationName1   = tqGetDInvoiceForPaymentSelection.tcBusinessRelationName1
           ocCorporateGroupCode      = tqGetDInvoiceForPaymentSelection.tcCorporateGroupCode
           ocDebtorCode              = tqGetDInvoiceForPaymentSelection.tcDebtorCode
           oiMasterID                = tqGetDInvoiceForPaymentSelection.tiDebtor_ID           
           ocInternalNumber          = if tqGetDInvoiceForPaymentSelection.tcDInvoiceDIText = "" or
                                          tqGetDInvoiceForPaymentSelection.tcDInvoiceDITexT = ? 
                                       then string(tqGetDInvoiceForPaymentSelection.tiPeriodYear) + "/":U +
                                            tqGetDInvoiceForPaymentSelection.tcJournalCode + "/":U +
                                            string(tqGetDInvoiceForPaymentSelection.tiDInvoiceVoucher,"9999999999":U)
                                       else tqGetDInvoiceForPaymentSelection.tcDInvoiceDIText
           otDiscountDueDate         = tqGetDInvoiceForPaymentSelection.ttDInvoiceDiscountDueDate
           odDiscountPercentage      = tqGetDInvoiceForPaymentSelection.tdPaymentConditionPercentage
           ocPaymentConditionPaymentType = tqGetDInvoiceForPaymentSelection.tcPaymentConditionPaymentTyp
           otInvoiceDate             = tqGetDInvoiceForPaymentSelection.ttDInvoiceDate
           otDueDate                 = tqGetDInvoiceForPaymentSelection.ttDInvoiceDueDate
           ocInvoiceCurrencyCode     = tqGetDInvoiceForPaymentSelection.tcCurrencyCode
           ocPaymentConditionPaymentType = tqGetDInvoiceForPaymentSelection.tcPaymentConditionPaymentTyp
           odOpenInvoiceAmountTC     = tqGetDInvoiceForPaymentSelection.tdDInvoiceBalanceDebitTC 
                                       - tqGetDInvoiceForPaymentSelection.tdDInvoiceBalanceCreditTC
           odOriginalInvoiceAmountTC = tqGetDInvoiceForPaymentSelection.tdDInvoiceOriginalDebitTC
                                       - tqGetDInvoiceForPaymentSelection.tdDInvoiceOriginalCreditTC
           odOriginalInvoiceAmountNetTC = tqGetDInvoiceForPaymentSelection.tdDInvoiceOriginalDebitTC
                                        + tqGetDInvoiceForPaymentSelection.tdDInvoiceVatDebitTC
                                        - tqGetDInvoiceForPaymentSelection.tdDInvoiceOriginalCreditTC
                                        - tqGetDInvoiceForPaymentSelection.tdDInvoiceVatCreditTC
           odInvoiceRate             = tqGetDInvoiceForPaymentSelection.tdDInvoiceExchangeRate
           odInvoiceRateScale        = tqGetDInvoiceForPaymentSelection.tdDInvoiceRateScale
           ocDivisionCode            = tqGetDInvoiceForPaymentSelection.tcDivisionCode
           odNonDiscountableAmountTC = tqGetDInvoiceForPaymentSelection.tdDInvoiceNonDiscAmtTC
           ocDInvoiceDIText          = tqGetDInvoiceForPaymentSelection.tcDInvoiceDIText
           oiDInvoicePostingYear     = tqGetDInvoiceForPaymentSelection.tiDInvoicePostingYear
           ocJournalCode             = tqGetDInvoiceForPaymentSelection.tcJournalCode
           oiDInvoiceVoucher         = tqGetDInvoiceForPaymentSelection.tiDInvoiceVoucher
           ocShipperInfo             = tqGetDInvoiceForPaymentSelection.tcDInvoiceShipperList.
end.