project QadFinancials > class BBankEntry > method GetPossibleAllocationsDInvoice

Description

this method returns a temp-table containing all allocation possibilities that fit the input criteria of this method., called by UI when pressing Apply on the search criteria window


Parameters


iiCompanyIDinputintegerEntity ID
ilIncludeAllCompaniesinputlogicalIncludeAllCompanies
iiBankStateLineIDinputintegerBankStateLine ID wherefor the allocations need to be proposed
icBankStateLineTcRowidinputcharacterBankStateLine TcRowid wherefor the allocations need to be proposed
icBusinessRelationCodeinputcharacter
icCodeinputcharacterDebtorCreditorEmployeeCode
Code of the debtor/creditor/employee
icReferenceinputcharacterReference of the debtor/creditor/employee
icCurrencyCodeinputcharacterCurrencyCode that should fit the Invoice/Collection/Document. This is not used in case iiCurrencyID is passed
icBankAccountNumberinputcharacterBankAccountNumber that should fit the Creditor-Invoice or the Debtor
iiPeriodYearinputinteger
icJournalCodeinputcharacterDaybook Code
iiVoucherinputintegerVoucher
icBankCurrencyCodeinputcharacterBank Currency Code
itBankStateLineValueDateinputdateValue Date of the Bank State Line
icTSMNumberinputcharacterTSMNumber
icShipperCodeinputcharacter
tPossibleBankStateAllocoutputtemp-tableTable containing all possibilities that fit the selection critaria.
tPossibleBankStateStageAllocoutputtemp-tableTable containing all possibilities for staged payments that fit the selection critaria.
iiBillYearinputinteger
iiBillNumberinputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankEntry.GetPossibleAllocations


program code (program6/bbankentry.p)

/* Start the queries used inside the for... each */

assign vcShipperValues = "":U
       viDebtor_ID = ?.

if icCode <> ? and icCode <> ''
then do :
    <Q-5 run DebtorPrim (all) (Read) (NoCache)
        (input ?, (CompanyId)
         input icCode, (DebtorCode)
         input ?, (Debtor_ID)
         output dataset tqDebtorPrim) in BDebtor >

    find tqDebtorPrim where tqDebtorPrim.tcDebtorCode = icCode no-error.
    
    if available tqDebtorPrim
    then  assign viDebtor_ID = tqDebtorPrim.tiDebtor_ID.

end. /* IF icCode <> ? and icCode <> '' */

<Q-49 run DInvoiceByAllocationInfo (all) (Read) (NoCache)
   (input if ilIncludeAllCompanies then ? else iiCompanyID, (CompanyId)
    input icBusinessRelationCode, (BusinessRelationCode)
    input ?, (DInvoiceID)
    input icReference, (DInvoiceDescription)
    input icCode, (DebtorCode)
    input icCurrencyCode, (CurrencyCode)
    input true, (DInvoiceIsOpen)
    input vdMinimumAmount, (DInvoiceAmountTCMinimum)
    input vdMaximumAmount, (DInvoiceAmountTCMaximum)
    input ?, (PeriodYearMinimum)
    input icJournalCode, (JournalCode)
    input iiPeriodYear, (PeriodYear)
    input iiVoucher, (Voucher)
    input icTSMNumber, (DInvoiceTSMNumber)
    input icShipperCode, (ShipperCode)
    input ?, (CorporateGroupCode)
    input ?, (CompIsOICrossCy)
    input viDebtor_ID, (Debtor_ID)
    input false, (DInvoiceIsSelected)
    input iiBillNumber, (BillNumber)
    input iiBillYear, (BillYear)
    output dataset tqDInvoiceByAllocationInfo) in BDInvoice>

for each tqDInvoiceByAllocationInfo where
         tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC  <> 0 or
         tqDInvoiceByAllocationInfo.tdDInvoiceBalanceCreditTC <> 0
         no-lock
         break by tqDInvoiceByAllocationInfo.tiDInvoice_ID
               by tqDInvoiceByAllocationInfo.tcDInvoiceOpInfoType
               by tqDInvoiceByAllocationInfo.tcDInvoiceOpInfoCode:

    assign vcShipperValues = if vcShipperValues = "":U 
                             then tqDInvoiceByAllocationInfo.tcDInvoiceOpInfoCode
                             else vcShipperValues + ",":U + tqDInvoiceByAllocationInfo.tcDInvoiceOpInfoCode.
    
    if last-of(tqDInvoiceByAllocationInfo.tiDInvoice_ID)
    then do:
        /* Check if the banknumber fits the input in case it is filled */
        if icBankAccountNumber <> "":U
        then do :
            <Q-50 assign vlFcQueryRecordsAvailable = BankNumberPrim (Cache)
               (input ?, (BankNumberId)
                input  tqDInvoiceByAllocationInfo.tiDebtor_ID, (ParentObjectId)
                input  icBankAccountNumber, (BankNumber)
                input ?, (BankNumberExtension)
                input ?, (BankPayFormatID)) in BBankNumber >
            if vlFcQueryRecordsAvailable = false
            then next.
        end. /* if icBankAccountNumber <> "":U */
        
        /*  Create output records */
        create tPossibleBankStateAlloc.
        assign tPossibleBankStateAlloc.Company_ID                = tqDInvoiceByAllocationInfo.tiCompany_ID
               tPossibleBankStateAlloc.tcCompanyCode             = tqDInvoiceByAllocationInfo.tcCompanyCode
               tPossibleBankStateAlloc.DInvoice_ID               = tqDInvoiceByAllocationInfo.tiDInvoice_ID
               tPossibleBankStateAlloc.Currency_ID               = ?
               tPossibleBankStateAlloc.tcCurrencyCode            = icBankCurrencyCode
               tPossibleBankStateAlloc.BankStateLine_ID          = iiBankStateLineID
               tPossibleBankStateAlloc.tc_ParentRowid            = icBankStateLineTcRowid
               tPossibleBankStateAlloc.tc_Rowid                  = entry(1,tqDInvoiceByAllocationInfo.tc_rowid)
               tPossibleBankStateAlloc.tcDocBusinessRelationCode = tqDInvoiceByAllocationInfo.tcBusinessRelationCode
               tPossibleBankStateAlloc.tcDocNumberReference      = trim(string(tqDInvoiceByAllocationInfo.tiPeriodYear)) + "/":U + trim(tqDInvoiceByAllocationInfo.tcJournalCode) + "/":U + string(tqDInvoiceByAllocationInfo.tiDInvoiceVoucher,"999999999":U) + "/":U + tqDInvoiceByAllocationInfo.tcDInvoiceDescription
               tPossibleBankStateAlloc.ttDocDueDate              = tqDInvoiceByAllocationInfo.ttDInvoiceDueDate 
               tPossibleBankStateAlloc.ttDocDiscountDueDate      = tqDInvoiceByAllocationInfo.ttDInvoiceDiscountDueDate
               tPossibleBankStateAlloc.ttDocInvDate              = tqDInvoiceByAllocationInfo.ttDInvoiceDate 
               tPossibleBankStateAlloc.tdDocBalance              = if tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC <> 0 and tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC <> ? then tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC else tqDInvoiceByAllocationInfo.tdDInvoiceBalanceCreditTC
               tPossibleBankStateAlloc.tdDocOriginal             = abs(tqDInvoiceByAllocationInfo.tdDInvoiceOriginalCreditTC - tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC)

               tPossibleBankStateAlloc.BankStateAllocOpenBalTC   = if tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC <> 0 and tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC <> ? then tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC else tqDInvoiceByAllocationInfo.tdDInvoiceBalanceCreditTC
               tPossibleBankStateAlloc.tcDocBalanceCrDt          = if tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC <> 0 and tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC <> ? then {&CREDITDEBITABBREVIATION-DEBIT} else {&CREDITDEBITABBREVIATION-CREDIT}
               tPossibleBankStateAlloc.tdDocVatBase              = Abs(tqDInvoiceByAllocationInfo.tdDInvoiceVatBaseDebitTC - tqDInvoiceByAllocationInfo.tdDInvoiceVatBaseCreditTC)
               tPossibleBankStateAlloc.tcDocVatBaseCrDt          = if (tqDInvoiceByAllocationInfo.tdDInvoiceVatBaseDebitTC - tqDInvoiceByAllocationInfo.tdDInvoiceVatBaseCreditTC) >= 0  then {&CREDITDEBITABBREVIATION-DEBIT}  else {&CREDITDEBITABBREVIATION-CREDIT}
               tPossibleBankStateAlloc.tdDocVat                  = Abs(tqDInvoiceByAllocationInfo.tdDInvoiceVatDebitTC - tqDInvoiceByAllocationInfo.tdDInvoiceVatCreditTC)
               tPossibleBankStateAlloc.tcDocVatCrDt              = if (tqDInvoiceByAllocationInfo.tdDInvoiceVatDebitTC - tqDInvoiceByAllocationInfo.tdDInvoiceVatCreditTC) >= 0 then {&CREDITDEBITABBREVIATION-DEBIT}  else {&CREDITDEBITABBREVIATION-CREDIT}
               tPossibleBankStateAlloc.tcDocCurrencyCode         = tqDInvoiceByAllocationInfo.tcCurrencyCode
               tPossibleBankStateAlloc.tiDocPostingID            = tqDInvoiceByAllocationInfo.tiPosting_ID
               tPossibleBankStateAlloc.tcLocalCurrencyCode       = vcCompanyLC
               tPossibleBankStateAlloc.tdDocExchangeRate         = tqDInvoiceByAllocationInfo.tdDInvoiceExchangeRate
               tPossibleBankStateAlloc.tdDocExchangeRateScale    = tqDInvoiceByAllocationInfo.tdDInvoiceRateScale
               tPossibleBankStateAlloc.tdDocCCExchangeRate       = tqDInvoiceByAllocationInfo.tdDInvoiceCCRate
               tPossibleBankStateAlloc.tdDocCCExchangeRateScale  = tqDInvoiceByAllocationInfo.tdDInvoiceCCScale 
               tPossibleBankStateAlloc.tcDocTSMNumber            = tqDInvoiceByAllocationInfo.tcDInvoiceTSMNumber
               tPossibleBankStateAlloc.tcNewBalanceCrDt          = tPossibleBankStateAlloc.tcDocBalanceCrDt
               tPossibleBankStateAlloc.tdNewBalanceTC            = if tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC <> 0 and tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC <> ? then tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC else tqDInvoiceByAllocationInfo.tdDInvoiceBalanceCreditTC
               tPossibleBankStateAlloc.tcAllocAmountCrDt         = (if tPossibleBankStateAlloc.tcDocBalanceCrDt = {&CREDITDEBITABBREVIATION-CREDIT} then {&CREDITDEBITABBREVIATION-DEBIT} else {&CREDITDEBITABBREVIATION-CREDIT})
               tPossibleBankStateAlloc.tcShipperCode             = vcShipperValues
               /* fields must be filled, otherwise errors on save */
               tPossibleBankStateAlloc.tcCurrDifferenceCrDt      = {&CREDITDEBITABBREVIATION-DEBIT}
               tPossibleBankStateAlloc.tcCCCurrDifferenceCrDt    = {&CREDITDEBITABBREVIATION-DEBIT}
               tPossibleBankStateAlloc.tcCollBalanceCrDt         = {&CREDITDEBITABBREVIATION-DEBIT}
               tPossibleBankStateAlloc.BankStateAllocType        = "?":U
               tPossibleBankStateAlloc.BankStateAllocBankRate     = vdBankRate
               tPossibleBankStateAlloc.BankStateAllocBankRteScale = vdBankRateScale
               tPossibleBankStateAlloc.tcReasonCode               = tqDInvoiceByAllocationInfo.tcReasonCode
               tPossibleBankStateAlloc.tcDInvoiceDIText          = tqDInvoiceByAllocationInfo.tcDInvoiceDIText
               tPossibleBankStateAlloc.tcInvoiceDescription      = tqDInvoiceByAllocationInfo.tcDInvoiceDescription
               tPossibleBankStateAlloc.tdBankStateAllocOpenBalTCSign = if tPossibleBankStateAlloc.tcDocBalanceCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
                                                                   then tPossibleBankStateAlloc.BankStateAllocOpenBalTC
                                                                   else (0 - tPossibleBankStateAlloc.BankStateAllocOpenBalTC) 
               tPossibleBankStateAlloc.tdDiscountPercentage      = if /*tqDInvoiceByAllocationInfo.tiDiscPaymentCondition_ID <> 0 and tqDInvoiceByAllocationInfo.tiDiscPaymentCondition_ID <> ? and*/
                                                                      itBankStateLineValueDate <= tqDInvoiceByAllocationInfo.ttDInvoiceDiscountDueDate
                                                                   then tqDInvoiceByAllocationInfo.tdPaymentConditionPercentage
                                                                   else 0
               tPossibleBankStateAlloc.tdNonDiscAmtTC            = tqDInvoiceByAllocationInfo.tdDInvoiceNonDiscAmtTC
               tPossibleBankStateAlloc.ttDocPostingDate          = tqDInvoiceByAllocationInfo.ttDInvoicePostingDate.
               tPossibleBankStateAlloc.tiBillNumber              = if tqDInvoiceByAllocationInfo.tiBillNumber <> 0
                                                                   then tqDInvoiceByAllocationInfo.tiBillNumber
                                                                   else ?.
               tPossibleBankStateAlloc.tiBillYear              = if tqDInvoiceByAllocationInfo.tiBillYear <> 0
                                                                   then tqDInvoiceByAllocationInfo.tiBillYear
                                                                   else ?.
               tPossibleBankStateAlloc.tcDocDescription        = tqDInvoiceByAllocationInfo.tcDInvoiceDescription.
               

        /* GET THE DEDUCTION DETAIL STATUS FOR DEDUCTION INVOICE */                                        
        if tqDInvoiceByAllocationInfo.tcDInvoiceType = {&INVOICETYPE-DEDUCTION} then
        do:
           <Q-42 run DInvoiceDedStatusByDInvoiceID (all) (Read) (NoCache)
              (input tqDInvoiceByAllocationInfo.tiCompany_ID, (CompanyId)
               input tqDInvoiceByAllocationInfo.tiDInvoice_ID, (DInvoiceID)
               output dataset tqDInvoiceDedStatusByDInvoiceID) in BDInvoice>
           find first tqDInvoiceDedStatusByDInvoiceID where tqDInvoiceDedStatusByDInvoiceID.tcDInvoiceDeductionStatus = {&INVOICEDEDUCTSTATUS-REJECTED} no-error.
           if available tqDInvoiceDedStatusByDInvoiceID then 
           do:
              assign tPossibleBankStateAlloc.tcDInvoiceDeductionStatus = {&INVOICEDEDUCTSTATUS-REJECTED}.
              assign tPossibleBankStateAlloc.tcDInvoiceDeductionStatus = {&INVOICEDEDUCTSTATUS-REJECTED}.
           end.
        end.      

        do viCounter = num-entries(vcInvoiceTypes,chr(2)) to 1 by -2 :
            if entry(viCounter,vcInvoiceTypes,chr(2)) = tqDInvoiceByAllocationInfo.tcDInvoiceType
            then do :
                /* put untranslatable value in it */
                assign tPossibleBankStateAlloc.BankStateAllocType = entry(viCounter,vcInvoiceTypes,chr(2)) no-error.
                leave.
            end. /* if entry */
        end.

        /* Miz FIN-2314 ====================================================================================== *
         * Calculate correct amount of LC and CC for the invoice                                               *
         * =================================================================================================== */
        <M-11 run GetPossibleAllocationsDInvoiceCrossCy
           (input  iiCompanyID (iiCompanyID), 
            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
        if viFcReturnSuper < 0 or viFcReturnSuper > 0 and oiReturnStatus = 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then leave.

        assign tPossibleBankStateAlloc.tlDiscountTaxAtPayment = false.

        <Q-39 run DInvoiceVatByDInvoiceId (all) (Read) (NoCache)
           (input tqDInvoiceByAllocationInfo.tiDInvoice_ID, (DInvoiceId)
            output dataset tqDInvoiceVatByDInvoiceId) in BDInvoice >

        for each tqDInvoiceVatByDInvoiceId where
                 tqDInvoiceVatByDInvoiceId.tiDInvoice_ID = tqDInvoiceByAllocationInfo.tiDInvoice_ID :

             <Q-40 assign vlFcQueryRecordsAvailable = MfgTaxCodeByTaxCode (NoCache)
                (input tqDInvoiceVatByDInvoiceId.tcVatCode, (TaxCode)
                 input tqDInvoiceVatByDInvoiceId.tcDomainCode, (DomainCode)
                 input true, (DiscountAtPayment)
                 input ?, (IsTaxByLine)) in BMfgTaxCode >

             if vlFcQueryRecordsAvailable = yes or vlFcQueryRecordsAvailable = ?
             then do:
                assign tPossibleBankStateAlloc.tlDiscountTaxAtPayment = true
                       vlDiscountTaxAtInvoice                         = true.
                leave.
             end.
        end. /* for each tqDInvoiceVatByDInvoiceId  */
        
        /* ================================================== */
        /* Create extra records for staged payment conditions */
        /* ================================================== */
        if tqDInvoiceByAllocationInfo.tcPaymentConditionPaymentTyp = {&PAYMENTCONDITIONPAYMENTTYPE-STAGED}
        then do:
            assign vdTotalDefaultPaymentAmountTC  = 0
                   vdTotalDefaultDiscountAmountTC = 0.

            /* Calculate discountable amount of whole invoice */
            if tPossibleBankStateAlloc.tlDiscountTaxAtPayment
            then assign vdDiscountableInvoiceTC = tPossibleBankStateAlloc.tdDocOriginal - tPossibleBankStateAlloc.tdNonDiscAmtTC.
            else assign vdDiscountableInvoiceTC = tPossibleBankStateAlloc.tdDocOriginal - tPossibleBankStateAlloc.tdNonDiscAmtTC - tPossibleBankStateAlloc.tdDocVat.
        
            <Q-58 run DInvoiceStageByDueDate (all) (Read) (NoCache)
               (input tqDInvoiceByAllocationInfo.tiDInvoice_ID, (DInvoiceID)
                input ?, (DueDate)
                output dataset tqDInvoiceStageByDueDate) in BDInvoice >
           
            for each tqDInvoiceStageByDueDate where
                     tqDInvoiceStageByDueDate.tiDInvoice_ID = tqDInvoiceByAllocationInfo.tiDInvoice_ID :
                
                create tPossibleBankStateStageAlloc.
                assign tPossibleBankStateStageAlloc.tc_ParentRowid        = tPossibleBankStateAlloc.tc_Rowid
                       tPossibleBankStateStageAlloc.tc_Rowid              = tqDInvoiceStageByDueDate.tc_rowid
                       tPossibleBankStateStageAlloc.DInvoiceStage_ID      = tqDInvoiceStageByDueDate.tiDInvoiceStage_ID
                       tPossibleBankStateStageAlloc.tdDefaultDiscountPerc = tqDInvoiceStageByDueDate.tdDInvoiceStageDiscPerc
                       tPossibleBankStateStageAlloc.ttDefaultDueDate      = tqDInvoiceStageByDueDate.ttDInvoiceStageDueDate
                       tPossibleBankStateStageAlloc.ttDefaultDiscDate     = tqDInvoiceStageByDueDate.ttDInvoiceStageDiscDate
                       vdDefaultAllocAmountTC                             = tqDInvoiceStageByDueDate.tdDInvoiceStageAmountTC - tqDInvoiceStageByDueDate.tdDInvoiceStageAmtAppliedTC.
                        
                
                if itBankStateLineValueDate <= tqDInvoiceStageByDueDate.ttDInvoiceStageDiscDate
                then assign tPossibleBankStateStageAlloc.tdDefaultDiscountAmountTC = vdDiscountableInvoiceTC 
                                                                                   * (vdDefaultAllocAmountTC / tPossibleBankStateAlloc.tdDocOriginal)
                                                                                   * (tqDInvoiceStageByDueDate.tdDInvoiceStageDiscPerc / 100)
                            tPossibleBankStateStageAlloc.tdDefaultDiscountAmountTC = <M-60 RoundAmount
                                                                                        (input  tPossibleBankStateStageAlloc.tdDefaultDiscountAmountTC (idUnroundedAmount), 
                                                                                         input  tqDInvoiceByAllocationInfo.tiDInvoiceCurrency_ID (iiCurrencyID), 
                                                                                         input  tqDInvoiceByAllocationInfo.tcCurrencyCode (icCurrencyCode)) in BBankEntry>
                            tPossibleBankStateStageAlloc.tdDefaultPaymentAmountTC  = vdDefaultAllocAmountTC - tPossibleBankStateStageAlloc.tdDefaultDiscountAmountTC.
                else assign tPossibleBankStateStageAlloc.tdDefaultDiscountAmountTC = 0
                            tPossibleBankStateStageAlloc.tdDefaultPaymentAmountTC  = vdDefaultAllocAmountTC.
                            
                assign vdTotalDefaultPaymentAmountTC  = vdTotalDefaultPaymentAmountTC  + tPossibleBankStateStageAlloc.tdDefaultPaymentAmountTC
                       vdTotalDefaultDiscountAmountTC = vdTotalDefaultDiscountAmountTC + tPossibleBankStateStageAlloc.tdDefaultDiscountAmountTC
                       tPossibleBankStateStageAlloc.tdDefaultAllocAmountTC = vdDefaultAllocAmountTC.
                            
            end. /* for each tqDInvoiceStageByDueDate */      
            assign tPossibleBankStateAlloc.tdDefaultPaymentAmountTC  = vdTotalDefaultPaymentAmountTC
                   tPossibleBankStateAlloc.tdDefaultDiscountAmountTC = vdTotalDefaultDiscountAmountTC.                      

        end. /* PAYMENTCONDITIONPAYMENTTYPE-STAGED */

        else do:

          /******************************************************************************************************************/
          /*     Calculation of Discount Amount                                                                             */
          /*     ==============================                                                                             */
          /*    1) In case of Discount Tax at Payment = YES                                                                 */
          /*      Discount Amount =  Invoice amount with Tax *                                                              */
          /*                         ((Invoice amount without Tax ?- Non-discountable amount) / Invoice amount without Tax) */ 
          /*                         Discount %  *                                                                          */
          /*                        (Invoice open amount / Invoice amount with Tax).                                        */
          /*    2) In case of Discount Tax at Payment = NO                                                                  */
          /*      Discount Amount = (Invoice amount without Tax - Non-discountable amount) *                                */
          /*                        Discount %  *                                                                           */
          /*                       (Invoice open amount / Invoice amount with Tax).                                         */
          /******************************************************************************************************************/
          if itBankStateLineValueDate <= tqDInvoiceByAllocationInfo.ttDInvoiceDiscountDueDate
          then assign vdDiscountBaseTC  = if tPossibleBankStateAlloc.tlDiscountTaxAtPayment 
                                          then abs(tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC - tqDInvoiceByAllocationInfo.tdDInvoiceOriginalCreditTC) *
                                          
                                                (((abs(tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC - tqDInvoiceByAllocationInfo.tdDInvoiceOriginalCreditTC) - 
                                                 abs(tqDInvoiceByAllocationInfo.tdDInvoiceVatDebitTC - tqDInvoiceByAllocationInfo.tdDInvoiceVatCreditTC)) - tPossibleBankStateAlloc.tdNonDiscAmtTC) / 
                                                  
                                                (abs(tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC - tqDInvoiceByAllocationInfo.tdDInvoiceOriginalCreditTC) - 
                                                 abs(tqDInvoiceByAllocationInfo.tdDInvoiceVatDebitTC - tqDInvoiceByAllocationInfo.tdDInvoiceVatCreditTC))) *
                                                 
                                                (tPossibleBankStateAlloc.BankStateAllocOpenBalTC /
                                                 abs(tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC - tqDInvoiceByAllocationInfo.tdDInvoiceOriginalCreditTC))
                                         else  ((abs(tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC - tqDInvoiceByAllocationInfo.tdDInvoiceOriginalCreditTC) - 
                                                 abs(tqDInvoiceByAllocationInfo.tdDInvoiceVatDebitTC - tqDInvoiceByAllocationInfo.tdDInvoiceVatCreditTC)) - tPossibleBankStateAlloc.tdNonDiscAmtTC)*
                                                 
                                                 (tPossibleBankStateAlloc.BankStateAllocOpenBalTC /
                                                 abs(tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC - tqDInvoiceByAllocationInfo.tdDInvoiceOriginalCreditTC))
                                                                            
                        tPossibleBankStateAlloc.tdDefaultDiscountAmountTC = <M-56 RoundAmount
                                                                               (input  (tqDInvoiceByAllocationInfo.tdPaymentConditionPercentage / 100) * vdDiscountBaseTC (idUnroundedAmount), 
                                                                                input  0 (iiCurrencyID), 
                                                                                input  icBankCurrencyCode (icCurrencyCode)) in business>
                        tPossibleBankStateAlloc.tdDefaultPaymentAmountTC  = tPossibleBankStateAlloc.BankStateAllocOpenBalTC -
                                                                            tPossibleBankStateAlloc.tdDefaultDiscountAmountTC.

            else assign tPossibleBankStateAlloc.tdDefaultPaymentAmountTC  = tPossibleBankStateAlloc.BankStateAllocOpenBalTC
                        tPossibleBankStateAlloc.tdDefaultDiscountAmountTC = 0.

        end. /* NOT PAYMENTCONDITIONPAYMENTTYPE-STAGED */
        
        assign vcShipperValues = "":U.

    end. /* End last-of */
    
end. /* for each tqDInvoiceByAllocationInfo no-lock */