project QadFinancials > class BBankEntry > method AdditionalUpdatesInvCurrDiff

Description

Post currency differenct for banking entry


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankEntry.AdditionalUpdatesInv


program code (program4/bbankentry.p)

/* Set default ReturnStatus */
assign oiReturnStatus = -98
       viBlockError   = 0.

assign vcExchangeRateType = <M-1 GetExchangeRateType () in BBankEntry>.

/* Start block */
BLOCKBANKSTATEALLOC: DO :     
/* ==================================================== */
/* Postings on control accounts and on discount account */
/* Loop through BankState Allocation records for:       */
/* - Supplier Invoice                                   */
/* - Customer Invoice                                   */
/* - Supplier Prepayments                               */
/* - Customer Prepayments                               */
/* - Supplier Payment selections                        */
/* - Customer Payment Selections                        */
/* ==================================================== */
for each tBankStateAlloc where
         tBankStateAlloc.tc_ParentRowid     = tBankStateLine.tc_Rowid        and
         (tBankStateAlloc.tc_Status          = "N":U or
          tBankStateAlloc.tc_Status          = "C":U)                        and
         ((tBankStateAlloc.CInvoice_ID        <> 0    and
           tBankStateAlloc.CInvoice_ID        <> ?)                        or
          tBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-NCINV} or
          (tBankStateAlloc.DInvoice_ID      <> 0 and
           tBankStateAlloc.DInvoice_ID      <> ?)                          or
          tBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-NDINV} or
          tBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-CCOLL} or
          tBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-DCOLL}):
          
    /* ====================================================================== */          
    /* Retrieve the rate between LC and the document currency                 */
    /* for each time the document currency is different from the previous one */
    /* ====================================================================== */           
    if vcDocCurrency <> tBankStateAlloc.tcDocCurrencyCode
    then do :
         <M-71 run GetExchangeRate
            (input  tBankStateLine.Company_ID (iiCompanyID), 
             input  ? (iiFromCurrencyID), 
             input  tBankStateAlloc.tcDocCurrencyCode (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>
         assign vcDocCurrency = tBankStateAlloc.tcDocCurrencyCode.
         /* Check if the exchange rate used during banking entry is the same as the one used for the document. Always use the banking entry exchange rate */
         if tBankStateAlloc.BankStateAllocAmountLC <> tBankStateAlloc.BankStateAllocBankAmountLC
         then assign vdExchangeRate = tBankStateAlloc.BankStateAllocBankAmountLC / (tBankStateAlloc.BankStateAllocAmountTC * vdExchangeRateScale).
    end. /* if vcDocCurrency <> tBankStateAlloc.tcDocCurrencyCode */

    /* Actions for the CurrencyDifferences-PostingLine */
    if tBankStateAlloc.BankStateAllocDifferenceLC <> 0 and 
       tBankStateAlloc.BankStateAllocDifferenceLC <> ?
    then do:
        empty temp-table tBankDefaultSafs.
        <M-26 run AddStandardPosting
           (input  tBankStateLine.tcPostingRowId (icPostingtcRowid), 
            input  tBankStateAlloc.tcCurrencyDifferenceGLCode (icGLCode), 
            input  '':U (icDivisionCode), 
            input  '':U (icCostCentreCode), 
            input  '':U (icCostCentreText), 
            input  '':U (icProjectCode), 
            input  '':U (icProjectText), 
            input  '':U (icIntercoBusinessRelationCode), 
            input  tBankStateAlloc.tcDocCurrencyCode (icCurrencyCode), 
            input  0 (idDebitTC), 
            input  if tBankStateAlloc.tcCurrDifferenceCrDt = {&CREDITDEBITABBREVIATION-DEBIT} then tBankStateAlloc.BankStateAllocDifferenceLC else 0 (idDebitLC), 
            input  0 (idDebitCC), 
            input  ? (idDebitPC), 
            input  0 (idCreditTC), 
            input  if tBankStateAlloc.tcCurrDifferenceCrDt = {&CREDITDEBITABBREVIATION-DEBIT} then 0 else tBankStateAlloc.BankStateAllocDifferenceLC (idCreditLC), 
            input  0 (idCreditCC), 
            input  ? (idCreditPC), 
            input  0 (idQty), 
            input  '':U (icLineText), 
            input  '':U (icSafText), 
            input  tBankDefaultSafs (tDefaultSafs), 
            input  vcExchangeRateType (icExchangeRateType), 
            input  vdExchangeRate (idExchangeRate), 
            input  vdExchangeRateScale (idExchangeRateScale), 
            input  0 (idPostingLineCCRate), 
            input  0 (idPostingLineCCScale), 
            output viDummyPostingLineId (oiPostingLineId), 
            input  ? (iiSafStructureId), 
            input  ? (icSafStructureCode), 
            input  ? (icAllocationKey), 
            input  false (ilLinkedCrCyDaemonReqExists), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        assign vcBankPostingLineId = if vcBankPostingLineId = "":U 
                                     then string(viDummyPostingLineId) 
                                     else vcBankPostingLineId + ",":U + string(viDummyPostingLineId).            
        if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
        if viBlockError < 0 then leave BLOCKBANKSTATEALLOC.
    end. /* if tBankStateAlloc.BankStateAllocDifferenceLC <> 0 and */
    
    if tBankStateAlloc.BankStateAllocDifferenceCC <> 0 and 
       tBankStateAlloc.BankStateAllocDifferenceCC <> ?
    then do:
        empty temp-table tBankDefaultSafs.
        <M-28 run AddStandardPosting
           (input  tBankStateLine.tcPostingRowId (icPostingtcRowid), 
            input  tBankStateAlloc.tcCCCurrencyDifferenceGLCode (icGLCode), 
            input  '':U (icDivisionCode), 
            input  '':U (icCostCentreCode), 
            input  '':U (icCostCentreText), 
            input  '':U (icProjectCode), 
            input  '':U (icProjectText), 
            input  '':U (icIntercoBusinessRelationCode), 
            input  tBankStateAlloc.tcDocCurrencyCode (icCurrencyCode), 
            input  0 (idDebitTC), 
            input  0 (idDebitLC), 
            input  if tBankStateAlloc.tcCCCurrDifferenceCrDt = {&CREDITDEBITABBREVIATION-DEBIT} then tBankStateAlloc.BankStateAllocDifferenceCC else 0 (idDebitCC), 
            input  ? (idDebitPC), 
            input  0 (idCreditTC), 
            input  0 (idCreditLC), 
            input  if tBankStateAlloc.tcCCCurrDifferenceCrDt = {&CREDITDEBITABBREVIATION-DEBIT} then 0 else tBankStateAlloc.BankStateAllocDifferenceCC (idCreditCC), 
            input  ? (idCreditPC), 
            input  0 (idQty), 
            input  '':U (icLineText), 
            input  '':U (icSafText), 
            input  tBankDefaultSafs (tDefaultSafs), 
            input  vcExchangeRateType (icExchangeRateType), 
            input  vdExchangeRate (idExchangeRate), 
            input  vdExchangeRateScale (idExchangeRateScale), 
            input  tBankStateAlloc.BankStateAllocCCRate (idPostingLineCCRate), 
            input  tBankStateAlloc.BankStateAllocCCScale (idPostingLineCCScale), 
            output viDummyPostingLineId (oiPostingLineId), 
            input  ? (iiSafStructureId), 
            input  ? (icSafStructureCode), 
            input  ? (icAllocationKey), 
            input  false (ilLinkedCrCyDaemonReqExists), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        assign vcBankPostingLineId = if vcBankPostingLineId = "":U 
                                     then string(viDummyPostingLineId) 
                                     else vcBankPostingLineId + ",":U + string(viDummyPostingLineId).            
        if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
        if viBlockError < 0 then leave BLOCKBANKSTATEALLOC.
    end. /* if tBankStateAlloc.BankStateAllocDifferenceCC <> 0 and */
    
    if tBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-CCOLL} or
       tBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-DCOLL}
    then do:
        for each tBankStateAllocColl where
                 tBankStateAllocColl.tc_ParentRowid = tBankStateAlloc.tc_Rowid
                 no-lock : 
            if vcDocCollCurrency <>  tBankStateAllocColl.tcDocCurrencyCode
            then do:
                <M-82 run GetExchangeRate
                   (input  tBankStateLine.Company_ID (iiCompanyID), 
                    input  ? (iiFromCurrencyID), 
                    input  tBankStateAllocColl.tcDocCurrencyCode (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>
                /* Check if the exchange rate used during banking entry is the same as the one used for the document. Always use the banking entry exchange rate */
                if tBankStateAlloc.BankStateAllocAmountLC <> tBankStateAlloc.tdCollBalance
                then assign vdExchangeRate = tBankStateAlloc.BankStateAllocAmountLC / (tBankStateAlloc.tdCollBalance / vdExchangeRate / vdExchangeRateScale).
                 
            end. /* if vcDocCollCurrency <>  tBankStateAllocColl.tcDocCurrencyCode */

            if ((tBankStateAllocColl.BankStateAllocCollDiffLC <> 0 and tBankStateAllocColl.BankStateAllocCollDiffLC <> ?)  or
                (tBankStateAllocColl.BankStateAllocCollDiffTC <> 0 and tBankStateAllocColl.BankStateAlloccollDiffTC <> ?)) and
               (if vlIsCDocExchRateChecked then vlIsCDocDiffExchRateLC else true)
            then do:
                empty temp-table tBankDefaultSafs.
                <M-27 run AddStandardPosting
                   (input  tBankStateLine.tcPostingRowId (icPostingtcRowid), 
                    input  tBankStateAllocColl.tcCurrencyDifferenceGLCode (icGLCode), 
                    input  '':U (icDivisionCode), 
                    input  '':U (icCostCentreCode), 
                    input  '':U (icCostCentreText), 
                    input  '':U (icProjectCode), 
                    input  '':U (icProjectText), 
                    input  '':U (icIntercoBusinessRelationCode), 
                    input  tBankStateAllocColl.tcDocCurrencyCode (icCurrencyCode), 
                    input  0 (idDebitTC), 
                    input  if tBankStateAllocColl.tcCurrDifferenceCrDt = {&CREDITDEBITABBREVIATION-DEBIT} then tBankStateAllocColl.BankStateAllocCollDiffLC else 0 (idDebitLC), 
                    input  0 (idDebitCC), 
                    input  ? (idDebitPC), 
                    input  0 (idCreditTC), 
                    input  if tBankStateAllocColl.tcCurrDifferenceCrDt = {&CREDITDEBITABBREVIATION-DEBIT} then 0 else tBankStateAllocColl.BankStateAllocCollDiffLC (idCreditLC), 
                    input  0 (idCreditCC), 
                    input  ? (idCreditPC), 
                    input  0 (idQty), 
                    input  '':U (icLineText), 
                    input  '':U (icSafText), 
                    input  tBankDefaultSafs (tDefaultSafs), 
                    input  vcExchangeRateType (icExchangeRateType), 
                    input  vdExchangeRate (idExchangeRate), 
                    input  vdExchangeRateScale (idExchangeRateScale), 
                    input  0 (idPostingLineCCRate), 
                    input  0 (idPostingLineCCScale), 
                    output viDummyPostingLineId (oiPostingLineId), 
                    input  ? (iiSafStructureId), 
                    input  ? (icSafStructureCode), 
                    input  ? (icAllocationKey), 
                    input  false (ilLinkedCrCyDaemonReqExists), 
                    output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
                assign vcBankPostingLineId = if vcBankPostingLineId = "":U 
                                             then string(viDummyPostingLineId) 
                                             else vcBankPostingLineId + ",":U + string(viDummyPostingLineId).                    
                if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
                if viBlockError < 0 then leave BLOCKBANKSTATEALLOC.
            end. /* if (tBankStateAllocColl.BankStateAllocCollDiffLC <> 0 and tBankStateAllocColl.BankStateAllocCollDiffLC <> ?) or */
            if tBankStateAllocColl.BankStateAllocCollDiffCC <> 0 and 
               tBankStateAllocColl.BankStateAllocCollDiffCC <> ? and
               (if vlIsCDocExchRateChecked then vlIsCDocDiffExchRateCC else true)
            then do:
                empty temp-table tBankDefaultSafs.
                <M-29 run AddStandardPosting
                   (input  tBankStateLine.tcPostingRowId (icPostingtcRowid), 
                    input  tBankStateAllocColl.tcCCCurrencyDifferenceGLCode (icGLCode), 
                    input  '':U (icDivisionCode), 
                    input  '':U (icCostCentreCode), 
                    input  '':U (icCostCentreText), 
                    input  '':U (icProjectCode), 
                    input  '':U (icProjectText), 
                    input  '':U (icIntercoBusinessRelationCode), 
                    input  tBankStateAllocColl.tcDocCurrencyCode (icCurrencyCode), 
                    input  0 (idDebitTC), 
                    input  0 (idDebitLC), 
                    input  if tBankStateAllocColl.tcCCCurrDifferenceCrDt = {&CREDITDEBITABBREVIATION-DEBIT} then tBankStateAllocColl.BankStateAllocCollDiffCC else 0 (idDebitCC), 
                    input  ? (idDebitPC), 
                    input  0 (idCreditTC), 
                    input  0 (idCreditLC), 
                    input  if tBankStateAllocColl.tcCCCurrDifferenceCrDt = {&CREDITDEBITABBREVIATION-DEBIT} then 0 else tBankStateAllocColl.BankStateAllocCollDiffCC (idCreditCC), 
                    input  ? (idCreditPC), 
                    input  0 (idQty), 
                    input  '':U (icLineText), 
                    input  '':U (icSafText), 
                    input  tBankDefaultSafs (tDefaultSafs), 
                    input  vcExchangeRateType (icExchangeRateType), 
                    input  vdExchangeRate (idExchangeRate), 
                    input  vdExchangeRateScale (idExchangeRateScale), 
                    input  tBankStateAllocColl.BankStateAllocCollCCRate (idPostingLineCCRate), 
                    input  tBankStateAllocColl.BankStateAllocCollCCScale (idPostingLineCCScale), 
                    output viDummyPostingLineId (oiPostingLineId), 
                    input  ? (iiSafStructureId), 
                    input  ? (icSafStructureCode), 
                    input  ? (icAllocationKey), 
                    input  false (ilLinkedCrCyDaemonReqExists), 
                    output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
                assign vcBankPostingLineId = if vcBankPostingLineId = "":U 
                                             then string(viDummyPostingLineId) 
                                             else vcBankPostingLineId + ",":U + string(viDummyPostingLineId).                    
                if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
                if viBlockError < 0 then leave BLOCKBANKSTATEALLOC.
            end. /* if (tBankStateAllocColl.BankStateAllocCollDiffCC <> 0 and tBankStateAllocColl.BankStateAllocCollDiffCC <> ?) */
        end. /* for each tBankStateAllocColl where */
    end. /* if tBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-CCOLL} */    
end. /* for each tBankStateAlloc where */

/* Check for possible rounding in LC and CC */
<M-86 run AdditionalUpdatesInvRounding  (output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viBlockError = 0)
then assign viBlockError = viFcReturnSuper.
if viFcReturnSuper < 0 
then leave BLOCKBANKSTATEALLOC.
END. /* stop block BLOCKBANKSTATEALLOC */

/* Capture the errors produced in the BankStateALLOCBlock */
if viBlockError <> 0 then assign oiReturnStatus = viBlockError.
if viBlockError < 0 then return.

/* Set ReturnStatus = OK */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.