project QadFinancials > class BDDocument > method AdditionalUpdatesPostingRounding

Description

This method retrieves the balance in LC (Base Currency) and CC (Statutory Currency).
If they are not balanced and the difference does not exceed the currency rounding method unit times the number of linked invoices, then an extra posting line is created to round the balance (in LC and/or in CC)


Parameters


icPostingRowIdinputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDDocument.AdditionalUpdatesPosting


program code (program5/bddocument.p)

assign vdBalanceLC = 0
       vdBalanceCC = 0
       viInvoicesCount = 0.

/* ===================================== */
/* Get the Posting ID based on the Rowid */
/* ===================================== */
<M-4 run GetPostingIDBasedOnPostingRowid
   (input  icPostingRowId (icPostingRowid), 
    output viPostingId (oiPostingID), 
    output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
    
/* ================================= */
/* Get the Posting LC and CC Amounts */
/* ================================= */
<M-6 run GetPostingAmount
   (input  viPostingId (iiPostingId), 
    output vdPostingAmountDebitLC (odPostingAmountDebitLC), 
    output vdPostingAmountCreditLC (odPostingAmountCreditLC), 
    output vdDummy (odPostingAmountCreditTC), 
    output vdPostingAmountCreditCC (odPostingAmountCreditCC), 
    output vdDummy (odPostingAmountDebitTC), 
    output vdPostingAmountDebitCC (odPostingAmountDebitCC), 
    output vcDummy (ocCurrencyCode), 
    output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

/* =============================== */
/* Calculate the LC and CC Balance */
/* =============================== */
assign vdBalanceLC = vdPostingAmountDebitLC - vdPostingAmountCreditLC
       vdBalanceCC = vdPostingAmountDebitCC - vdPostingAmountCreditCC.


if vdBalanceLC <> 0 or
   vdBalanceCC <> 0
then do:
    /* ========================================== */
    /* Count the invoices linked to this document */
    /* ========================================== */
    for each tDDocumentInvoiceXref where
             tDDocumentInvoiceXref.tc_ParentRowid = tDDocument.tc_Rowid:
        assign viInvoicesCount = viInvoicesCount + 1.
    end. /* for each tDDocumentInvoiceXref where */

    /* ============================= */
    /* Retrieve the rounding account */
    /* ============================= */
    <Q-8 run GLByGLSystemType (all) (Read) (NoCache)
       (input viCompanyID, (CompanyId)
        input {&GLSYSTEMTYPE-ROUND}, (GLSystemTypeCode)
        input {&GLTYPECODE-SYST}, (GlTypeCode)
        input ?, (GlIsDivisionAccount)
        output dataset tqGLByGLSystemType) in BGL >    
    find first tqGLByGLSystemType where
               tqGLByGLSystemType.tcGLSystemTypeCode = {&GLSYSTEMTYPE-ROUND} and
               tqGLByGLSystemType.tcGLTypeCode       = {&GLTYPECODE-SYST}
               no-error.
    if not available tqGLByGLSystemType
    then do:
         assign vcMessage = trim(#T-10'The system account for rounding differences has not been defined.':250(16626)T-10#)
                oiReturnStatus = -1.
        <M-9 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-9480':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDDocument>        
        return.        
    end. /* if not available tqGLByGLSystemType */

    /* ================================ */
    /* Round the LC Amounts when needed */
    /* ================================ */
    if vdBalanceLC <> 0
    then do:
         /* ========================================================================== */
         /* Retrieve the unit of the rounding method that is linked to the LC currency */
         /* When we can't find it we will use 0.01 as a default.                       */
         /* ========================================================================== */
         <Q-11 run CurrencyByCurrRoundingMethod (all) (Read) (NoCache)
            (input viCompanyLCid, (CurrencyID)
             input vcCompanyLC, (CurrencyCode)
             input ?, (RoundingMethodCode)
             output dataset tqCurrencyByCurrRoundingMethod) in BCurrency >        
        find first tqCurrencyByCurrRoundingMethod where
                   tqCurrencyByCurrRoundingMethod.tiCurrency_ID = viCompanyLCId 
                   no-error.
        if available tqCurrencyByCurrRoundingMethod
        then assign vdRoundingUnit = tqCurrencyByCurrRoundingMethod.tdRoundingMethodUnit.
        else assign vdRoundingUnit = 0.01.

        /* ========================================================================= */
        /* Check if the balance is within the limits of a reasonable rounding amount */
        /* --> this means: currency unit * number of invoices linked to the movement */
        /* If it is, create a new postingline to balance the LC amounts              */
        /* ========================================================================= */
        if abs(vdBalanceLC) <= vdRoundingUnit * viInvoicesCount
        then do:
            empty temp-table tDefaultSafsDDoc.
            assign vdDebitLC = if vdBalanceLC > 0 then 0 else - vdBalanceLC
                   vdCreditLC= if vdBalanceLC > 0 then vdBalanceLC else 0.
            <M-12 run AddStandardPosting
               (input  icPostingRowId (icPostingtcRowid), 
                input  tqGLByGLSystemType.tcGLCode (icGLCode), 
                input  ? (icDivisionCode), 
                input  ? (icCostCentreCode), 
                input  ? (icCostCentreText), 
                input  ? (icProjectCode), 
                input  ? (icProjectText), 
                input  ? (icIntercoBusinessRelationCode), 
                input  vcCompanyLC (icCurrencyCode), 
                input  0 (idDebitTC), 
                input  vdDebitLC (idDebitLC), 
                input  0 (idDebitCC), 
                input  0 (idDebitPC), 
                input  0 (idCreditTC), 
                input  vdCreditLC (idCreditLC), 
                input  0 (idCreditCC), 
                input  0 (idCreditPC), 
                input  0 (idQty), 
                input  ? (icLineText), 
                input  ? (icSafText), 
                input  tDefaultSafsDDoc (tDefaultSafs), 
                input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType), 
                input  1 (idExchangeRate), 
                input  1 (idExchangeRateScale), 
                input  1 (idPostingLineCCRate), 
                input  1 (idPostingLineCCScale), 
                output viPostingLineId (oiPostingLineId), 
                input  ? (iiSafStructureId), 
                input  ? (icSafStructureCode), 
                input  ? (icAllocationKey), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>          
            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
            then assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 then return.
        end. /* if abs(vdBalanceLC) <= vdRoundingUnit * viInvoicesCount */
    end. /* if vdBalanceLC <> 0 */

    /* ================================ */
    /* Round the CC Amounts when needed */
    /* ================================ */
    if vdBalanceCC <> 0
    then do:
         /* ========================================================================== */
         /* Retrieve the unit of the rounding method that is linked to the CC currency */
         /* When we can't find it we will use 0.01 as a default.                       */
         /* ========================================================================== */
         <Q-13 run CurrencyByCurrRoundingMethod (all) (Read) (NoCache)
            (input viCompanyCCid, (CurrencyID)
             input vcCompanyCC, (CurrencyCode)
             input ?, (RoundingMethodCode)
             output dataset tqCurrencyByCurrRoundingMethod) in BCurrency >
        find first tqCurrencyByCurrRoundingMethod where
                   tqCurrencyByCurrRoundingMethod.tiCurrency_ID = viCompanyCCId 
                   no-error.
        if available tqCurrencyByCurrRoundingMethod
        then assign vdRoundingUnit = tqCurrencyByCurrRoundingMethod.tdRoundingMethodUnit.
        else assign vdRoundingUnit = 0.01.

        /* ========================================================================= */
        /* Check if the balance is within the limits of a reasonable rounding amount */
        /* --> this means: currency unit * number of invoices linked to the movement */
        /* If it is, create a new postingline to balance the CC amounts              */
        /* ========================================================================= */
        if abs(vdBalanceCC) <= vdRoundingUnit * viInvoicesCount
        then do:
            empty temp-table tDefaultSafsDDoc.
            assign vdDebitCC = if vdBalanceCC > 0 then 0 else - vdBalanceCC
                   vdCreditCC= if vdBalanceCC > 0 then vdBalanceCC else 0.
             <M-14 run AddStandardPosting
                (input  icPostingRowId (icPostingtcRowid), 
                 input  tqGLByGLSystemType.tcGLCode (icGLCode), 
                 input  ? (icDivisionCode), 
                 input  ? (icCostCentreCode), 
                 input  ? (icCostCentreText), 
                 input  ? (icProjectCode), 
                 input  ? (icProjectText), 
                 input  ? (icIntercoBusinessRelationCode), 
                 input  vcCompanyCC (icCurrencyCode), 
                 input  0 (idDebitTC), 
                 input  0 (idDebitLC), 
                 input  vdDebitCC (idDebitCC), 
                 input  0 (idDebitPC), 
                 input  0 (idCreditTC), 
                 input  0 (idCreditLC), 
                 input  vdCreditCC (idCreditCC), 
                 input  0 (idCreditPC), 
                 input  0 (idQty), 
                 input  ? (icLineText), 
                 input  ? (icSafText), 
                 input  tDefaultSafsDDoc (tDefaultSafs), 
                 input  {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateType), 
                 input  1 (idExchangeRate), 
                 input  1 (idExchangeRateScale), 
                 input  1 (idPostingLineCCRate), 
                 input  1 (idPostingLineCCScale), 
                 output viPostingLineId (oiPostingLineId), 
                 input  ? (iiSafStructureId), 
                 input  ? (icSafStructureCode), 
                 input  ? (icAllocationKey), 
                 output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
            then assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 then return.
        end. /* if abs(vdBalanceCC) <= vdRoundingUnit * viInvoicesCount */
    end. /* if vdBalanceCC <> 0 */
end. /* if vdBalanceLC <> 0 or */