project QadFinancials > class BBankEntry > method CalculateAll

Description

everything from calculate is done here


Parameters


oiReturnStatusoutputinteger


Internal usage


QadFinancials
method BBankEntry.Calculate


program code (program4/bbankentry.p)

assign oiReturnStatus      = -98
       viLocalReturnStatus = 0.

/* ================================================================================== */ 
/* Fill in GL-information of BankState.gl_id                                          */
/* ================================================================================== */
for each tBankState where
         tBankState.tcGLBankNumber = "":U :

    <M-1 run CalculateBankState
       (input  tBankState.Company_ID (iiCompanyID), 
        input  tBankState.GL_ID (iiBankStateGLID), 
        input  ? (icBankStateGLCode), 
        output tBankState.Currency_ID (oiGLCurrencyID), 
        output tBankState.tcCurrencyCode (ocGLCurrencyCode), 
        output tBankState.tcGLDescription (ocGLDescription), 
        output vdDummy (odGLBalanceLC), 
        output vdDummy (odGLBalanceCC), 
        output vdDummy (odGLBalanceGLCurr), 
        output tBankState.tcGLBankNumber (ocGLBankNumber), 
        output viDummy1 (oiGLJournalID), 
        output tBankState.tcGLJournalCode (ocGLJournalCode), 
        output tBankState.tcGLJournalLayerCode (ocGLJournalLayerCode), 
        output tBankState.tdGLUnallocStatBalance (odGLUnallocStatBalance), 
        output vdBankStateOpeningBalance (odBankStateOpeningBalance), 
        output tBankState.tdGLBalance (odGLBalanceTC), 
        output tBankState.tiGLBankNumberId (oiGLBankNumberId), 
        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>

    if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viLocalReturnStatus <  0 then next.

    for each tBankStateLine where
             tBankStateLine.BankState_ID = tBankState.BankState_ID
    break by tBankStateLine.BankStateLineValueDate:
        /*Calculating tdBankStateLineAmountLC by checking if it is only allocated to GL Accounts and no other allocations exist for it*/
        find first tBankStateAlloc where
                   tBankStateAlloc.BankStateLine_ID = tBankStateLine.BankStateLine_ID no-error.
        if not available tBankStateAlloc and
                         tBankStateLine.BankStateLineStatus = {&BANKSTATELINESTATUS-ALLOCPOST}
 
        then do:
        
           <Q-72 run PostingLineByPostingId (all) (Read) (NoCache)
              (input viCompanyId, (CompanyId)
               input tBankStateLine.Posting_ID, (PostingId)
               input ?, (GLSystemTypeCode)
               input '':U, (GLTypeCode)
               output dataset tqPostingLineByPostingId) in BPosting>
 
           find first tqPostingLineByPostingId where   
                      tqPostingLineByPostingId.tiPosting_ID = tBankStateLine.Posting_ID and
                      tqPostingLineByPostingId.tiGL_ID      = tBankState.GL_ID  no-error.
           if available tqPostingLineByPostingId
           then assign tBankStateLine.tdBankStateLineAmountLC = if tqPostingLineByPostingId.tdPostingLineDebitLC <> 0
                                                                then tqPostingLineByPostingId.tdPostingLineDebitLC
                                                                else tqPostingLineByPostingId.tdPostingLineCreditLC.
               assign tBankStateLine.tdBankStateLineAmountLC = if tBankStateLine.BankStateLineInOut = {&BANKSTATELINEINOUT-OUT}                                                                                                                     
                                                               then tBankStateLine.tdBankStateLineAmountLC * -1
                                                               else tBankStateLine.tdBankStateLineAmountLC.
        end.  /* if not available tBankStateAlloc */
        else do:
            if first-of(BankStateLineValueDate)
            then assign vlRateRetrieved = false.
        
            if (tBankStateLine.tdBankStateLineAmountLC = 0 or  tBankStateLine.tdBankStateLineAmountLC = ?) and
               (tBankStateLine.BankStateLineAmountTC  <> 0 and tBankStateLine.BankStateLineAmountTC <> ?)
            then do:
                if tBankState.tcCurrencyCode = vcCompanyLC
                then assign tBankStateLine.tdBankStateLineAmountLC = tBankStateLine.BankStateLineAmountTC.
        
                else do:
                    if vlRateRetrieved = false
                    then do:
                        assign vlRateRetrieved = true.
                        <M-60 run GetExchangeRate
                           (input  tBankStateLine.Company_ID (iiCompanyID), 
                            input  ? (iiFromCurrencyID), 
                            input  tBankState.tcCurrencyCode (icFromCurrencyCode), 
                            input  viCompanyLCId (iiToCurrencyID), 
                            input  ? (icToCurrencyCode), 
                            input  ? (iiExchangeRateTypeID), 
                            input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode), 
                            input  tBankStateLine.BankStateLineValueDate (itValidityDate), 
                            output vdExchangeRate (odExchangeRate), 
                            output vdExchangeRateScale (odExchangeScaleFactor), 
                            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                        if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0
                        then assign viLocalReturnStatus = viFcReturnSuper.
                        if viLocalReturnStatus < 0 then next.
                    end. /* if vlRateRetrieved */
                    
                    assign tBankStateLine.tdBankStateLineAmountLC = <M-47 RoundAmount
                                                                       (input  tBankStateLine.BankStateLineAmountTC * vdExchangeRate * vdExchangeRateScale (idUnroundedAmount), 
                                                                        input  viCompanyLCId (iiCurrencyID), 
                                                                        input  vcCompanyLC (icCurrencyCode)) in BBankEntry>.
                end. /* else do */
            end. /* if (tBankStateLine.tdBankStateLineAmountLC = 0 or  tBankStateLine.tdBankStateLineAmountLC = ?) */
        end. /* else do */
    end. /* for each tBankStateLine */
end. /* for each tBankState */

/* ======================================================================= */
/* Fill in Doc/Coll info of tBankStateAlloc based on the type and the ID's */
/* Fill in the CompanyCode as this cannot be done using RKBF               */
/* ======================================================================= */
assign viSequence = 0.
<Q-24 run CompanyPrim (all) (Read) (NoCache)
      (input ?, (LookupCompanyId)
       input ?, (CompanyCode)
       output dataset tqCompanyPrim) in BCompany >

for each tBankStateAlloc where 
         tBankStateAlloc.tc_Rowid <> "D":U:
    
    if tBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-DEDUCTIONINV} then
    do:
        <Q-52 run GetDeductionDetailByInvoiceID (all) (Read) (NoCache)
           (input ?, (CompanyId)
            input tBankStateAlloc.DInvoice_ID, (InvoiceID)
            output dataset tqGetDeductionDetailByInvoiceID) in BDInvoice>

        for each tqGetDeductionDetailByInvoiceID no-lock:

             assign tBankStateAlloc.tdDInvoiceDeductionTC      = tBankStateAlloc.tdDInvoiceDeductionTC + tqGetDeductionDetailByInvoiceID.tdDInvoiceDeductionTC
                    tBankStateAlloc.tcDInvoiceDeductionCode = if tBankStateAlloc.tcDInvoiceDeductionCode = '':U then tqGetDeductionDetailByInvoiceID.tcDeductionCatCode
                                                               else trim(#T-80'See details':20(648722267)T-80#)
                    tBankStateAlloc.tcDInvoiceDeductionStatus = if tBankStateAlloc.tcDInvoiceDeductionStatus = {&INVOICEDEDUCTSTATUS-REJECTED} then {&INVOICEDEDUCTSTATUS-REJECTED}
                                                               else if tqGetDeductionDetailByInvoiceID.tcDInvoiceDeductionStatus = {&INVOICEDEDUCTSTATUS-REJECTED} then {&INVOICEDEDUCTSTATUS-REJECTED}
                                                               else if tBankStateAlloc.tcDInvoiceDeductionStatus = '':U then tqGetDeductionDetailByInvoiceID.tcDInvoiceDeductionStatus
                                                               else trim(#T-43'See details':20(648722267)T-43#).
        end.
    end. /* if tBankStateAlloc.BankStateAllocType */ 
    
    if tBankStateAlloc.tcDocNumberReference = "":U 
    then do:
        find first tBankStateLine where
                   tBankStateLine.BankStateLine_ID = tBankStateAlloc.BankStateLine_ID
                   no-error.
        if available tBankStateLine
        then do:
            find first tBankState where
                       tBankState.BankState_ID = tBankStateLine.BankState_ID
                       no-error.
        end.
        if tBankStateAlloc.Company_id <> 0 and 
           tBankStateAlloc.Company_ID <> ? 
        then do :
            find tqCompanyPrim where
                 tqCompanyPrim.tiCompany_ID = tBankStateAlloc.Company_ID
                 no-lock no-error.
            if available tqCompanyPrim
            then assign tBankStateAlloc.tcCompanyCode = tqCompanyPrim.tcCompanyCode.
        end. /* if tBankStateAlloc.Company_id <> 0 and */

        <M-2 run CalculateBankStateAlloc
           (input  tBankStateAlloc.CInvoice_ID (iiCInvoiceID), 
            input  tBankStateAlloc.DInvoice_ID (iiDInvoiceID), 
            input  tBankStateAlloc.CCollection_ID (iiCCollectionID), 
            input  tBankStateAlloc.DCollection_ID (iiDCollectionID), 
            input  tBankStateAlloc.Posting_ID (iiPostingId), 
            input  if available tBankState then tBankState.GL_ID else ? (iiGLId), 
            output tBankStateAlloc.tcDocNumberReference (ocDocNumberReference), 
            output tBankStateAlloc.tcDocBusinessRelationCode (ocDocBusinessRelationCode), 
            output tBankStateAlloc.ttDocDueDate (otDocDueDate), 
            output tBankStateAlloc.ttDocDiscountDueDate (otDocDiscountDueDate), 
            output tBankStateAlloc.ttDocInvDate (otDocInvDate), 
            output tBankStateAlloc.tdDocBalance (odDocBalance), 
            output tBankStateAlloc.tcDocBalanceCrDt (ocDocBalanceCrDt), 
            output tBankStateAlloc.tcDocCurrencyCode (ocDocCurrencyCode), 
            output tBankStateAlloc.tiCollNumber (oiCollNumber), 
            output tBankStateAlloc.tcCollReference (ocCollReference), 
            output tBankStateAlloc.tdCollBalance (odCollBalance), 
            output tBankStateAlloc.tcCollBalanceCrDt (ocCollBalanceCrDt), 
            output tBankStateAlloc.ttCollRequestedDate (otCollRequestedDate), 
            output tBankStateAlloc.tcAllocAmountCrDt (ocAllocAmountCrDt), 
            output tBankStateAlloc.tcNewBalanceCrDt (ocNewBalanceCrDt), 
            output tBankStateAlloc.tdDocExchangeRate (odDocExchangeRate), 
            output tBankStateAlloc.BankStateAllocBankRteScale (odDocExchangeRateScale), 
            output tBankStateAlloc.tdDocVatBase (odDocVatBase), 
            output tBankStateAlloc.tcDocVatCrDt (ocDocVatBaseCrDt), 
            output tBankStateAlloc.tdDocVat (odDocVat), 
            output tBankStateAlloc.tcDocVatCrDt (ocDocVatCrDt), 
            output tBankStateAlloc.tiDocPostingID (oiDocPostingID), 
            output tBankStateAlloc.tcVatCountryCode (ocVatCountryCode), 
            output tBankStateAlloc.tlDiscountTaxAtPayment (olDiscountTaxAtPayment), 
            output tBankStateAlloc.tcInvoiceDescription (ocDInvoiceDescription), 
            output tBankStateAlloc.tdBankStateAllocOpenBalTCSign (odOpenBalTCSign), 
            output tBankStateAlloc.tdNonDiscAmtTC (odNonDiscAmt), 
            output tBankStateAlloc.tcReasonCode (ocReasonCode), 
            output tBankStateAlloc.ttDocPostingDate (otDocPostingDate), 
            output tBankStateAlloc.tiBillNumber (oiBillNumber), 
            output tBankStateAlloc.tiBillYear (oiBillYear), 
            output tBankStateAlloc.tcBillStatus (ocBillStatus), 
            output tBankStateAlloc.tcDInvoiceDIText (ocCustomerInvoiceNumber), 
            output tBankStateAlloc.tcShipperCode (ocShipperCode), 
            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>

        if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viLocalReturnStatus < 0 then next.

        assign tBankStateAlloc.tcLocalCurrencyCode      = vcCompanyLC
               tBankStateAlloc.tiBankStateAllocSequence = viSequence + 1
               tBankStateAlloc.tdNewBalanceTC           = tBankStateAlloc.BankStateAllocOpenBalTC - tBankStateAlloc.BankStateAllocAmountTC
               tBankStateAlloc.BankStateAllocPaidAmtTC  = tBankStateAlloc.BankStateAllocAmountTC - tBankStateAlloc.BankStateAllocDiscountTC
               tBankStateAlloc.tcDocDescription         = tBankStateAlloc.tcInvoiceDescription.    
    
        /* Update Bank State Alloc Stage details */
        <M-58 run CalculateBankStateStageAlloc  (output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
        if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0 then assign viLocalReturnStatus = viFcReturnSuper.
        if viLocalReturnStatus < 0 then next.

    end. /* end if docreference is "" */

    assign   tBankStateAlloc.tlUIFullAllocation           = tBankStateAlloc.tdNewBalanceTC = 0.

end. /* for each tBankStateAlloc where  */

/* ====================================================================== */
/* Fill in Doc info of tBankStateAllocColl based on the type and the ID's */
/* ====================================================================== */
for each tBankStateAllocColl where 
         tBankStateAllocColl.tc_Rowid             <> "D":U and 
         tBankStateAllocColl.tcDocNumberReference  = "":U :

    <M-3 run CalculateBankStateAllocColl
       (input  tBankStateAllocColl.CDocument_ID (iiCDocumentID), 
        input  tBankStateAllocColl.DDocument_ID (iiDDocumentID), 
        output tBankStateAllocColl.tcDocBusinessRelationCode (ocDocBusinessRelationCode), 
        output tBankStateAllocColl.tcDocNumberReference (ocDocNumberReference), 
        output tBankStateAllocColl.tcDocType (ocDocType), 
        output tBankStateAllocColl.tdDocAmount (odDocAmount), 
        output tBankStateAllocColl.tcDocAmountCrDt (ocDocAmountCrDt), 
        output tBankStateAllocColl.tcDocCurrencyCode (ocDocCurrencyCode), 
        output tBankStateAllocColl.tiCDocumentPrePrintedNumber (oiPrePrintedNumber), 
        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>

    if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0
    then assign viLocalReturnStatus = viFcReturnSuper.

    if viLocalReturnStatus < 0 
    then next.

end. /* for each tBankStateAllocColl where */

assign oiReturnStatus = viLocalReturnStatus.