project QadFinancials > class BAPMatching > method AdditionalUpdatesAllLinesPLVarExchRate

Description

AdditionalUpdatesAllLinesPLVarExchRate; submethod of AdditionalUpdatesAllLines that is located in the same segment and that takes care of the creation of a posting-line for the ExchangeRateVariance (difference in exch-rates between invoice and receipt)


Parameters


icAPMatchingPostingRowidIDinputcharacterAPMatchingPostingRowidID
icPostingTextinputcharacterPostingText
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.AdditionalUpdatesAllLines


program code (program6/bapmatching.p)

/* ===================================================================================================== */
    /* EXCHANGE-RATE Variances (Also for Logistic Charges)                                                   */
    /* If the Receipt-ExchRate differs from the Invoice-ExchRate then APMatchingLnVarExchRateLC shoudl be    */
    /* filled and thus we should create an addtional PostingLine with the TC-amounts = 0 and an LC-amount    */
    /* filled to make sure the posting is also balanced in LC/SC (as it was already in TC) and store the     */
    /* PostingLine_ID in tAPMatchingLn.VarExchRatePostingLine_ID                                             */
    /* Fields tAPMatchingLn.APMatchingLnVarExchRateLC and tAPMatchingLn.APMatchingLnVarExchRateCC will get   */
    /* here as this applies once for LC and once for CC                                                      */
    /* ===================================================================================================== */
    
    
    /* ======================== */
    /* Set default ReturnStatus */
    /* ======================== */
    assign oiReturnStatus = -98.
    
    /* ============================================================================ */
    /* Elementary checks to avoid mis-usage of this method                          */
    /* First check whether everything is availablable what is supposed to be avail  */
    /* ============================================================================ */
    assign vcMsgAPMatching = "":U.
    if not available tqCInvoiceByMatchingInfo   or
       not available tAPMatching                or 
       not available tAPMatchingLn              or 
       not available tqPendingVoucherForMatchingAcc
    then assign oiReturnStatus  = -3
                vcMsgAPMatching = trim(substitute(#T-93'Internal error: information is missing.':255(49818)T-93#)) + chr(10) + 
                                  trim(substitute(#T-94'Available supplier invoice: &1.':234(53332)T-94#,available (tqCInvoiceByMatchingInfo))) + chr(10) + 
                                  trim(substitute(#T-95'Available matching header: &1.':234(49819)T-95#,available (tAPMatching))) + chr(10) + 
                                  trim(substitute(#T-96'Available matching details: &1.':234(49820)T-96#,available (tAPMatchingLn))) + chr(10) + 
                                  trim(substitute(#T-97'Available pending invoice details: &1.':234(49821)T-97#,available (tqPendingVoucherForMatchingAcc))) + chr(10) + 
                                  trim(substitute(#T-98'Technical details: &1.':222(55526)T-98#,"ExchRateVar/1":U)).
    if vcMsgAPMatching = "":U                            And
       ((tAPMatchingLn.APMatchingLnVarExchRateLC = 0 or 
         tAPMatchingLn.APMatchingLnVarExchRateLC = ?)    And  
        (tAPMatchingLn.APMatchingLnVarExchRateCC = 0 or 
         tAPMatchingLn.APMatchingLnVarExchRateCC = ?))
    then assign oiReturnStatus  = -3
                vcMsgAPMatching = trim(substitute(#T-108'Internal error: invalid call to the method that creates the posting line on the exchange rate variances for the finished pending invoices.':255(55813)T-108#)) + chr(10) + 
                                  (if ((tAPMatchingLn.APMatchingLnPvodExchRate2 / tAPMatchingLn.APMatchingLnPvodExchRate) = 
                                       (tAPMatching.tdCInvoiceExchangeRate * tAPMatching.tdCInvoiceRateScale)) or 
                                      tAPMatchingLn.APMatchingLnVarExchRateLC = 0 or 
                                      tAPMatchingLn.APMatchingLnVarExchRateLC = ?
                                   then trim(substitute(#T-151'Exchange-rate variance in BC: &1':255(999890939)T-151#,tAPMatchingLn.APMatchingLnVarExchRateLC)) + chr(10) + 
                                        trim(substitute(#T-109'TC-BC: Receipt exchange rate (&1 / &2). Invoice exchange rate (&3 * &4).':255(999890940)T-109#,string(tAPMatchingLn.APMatchingLnPvodExchRate2),string(tAPMatchingLn.APMatchingLnPvodExchRate),string(tAPMatching.tdCInvoiceExchangeRate),string(tAPMatching.tdCinvoiceRateScale)))  + chr(10)  
                                   else "":U) + 
                                  (if ((tAPMatchingLn.APMatchingLnPvodCCRate * tAPMatchingLn.APMatchingLnPvodCCScale) = 
                                       (tAPMatching.tdCInvoiceLCCCRate * tAPMatching.tdCInvoiceLCCCScale)) or
                                      tAPMatchingLn.APMatchingLnVarExchRateCC = 0 or 
                                      tAPMatchingLn.APMatchingLnVarExchRateCC = ?
                                   then trim(substitute(#T-152'Exchange-rate variance in SC: &1':255(999890938)T-152#,tAPMatchingLn.APMatchingLnVarExchRateCC)) + chr(10) + 
                                        trim(substitute(#T-136'TC-SC: Receipt exchange rate (&1 * &2). Invoice exchange rate (&3 * &4).':255(999890941)T-136#,string(tAPMatchingLn.APMatchingLnPvodCCRate),string(tAPMatchingLn.APMatchingLnPvodCCScale),string(tAPMatching.tdCInvoiceLCCCRate),string(tAPMatching.tdCInvoiceLCCCScale)))  + chr(10)  
                                   else "":U) + 
                                  trim(substitute(#T-110'Technical details: &1.':222(55526)T-110#,"ExchRateVar/3":U)).
    if vcMsgAPMatching = "":U and 
       /* Error when not balanced in TC */
       (tAPMatchingLn.APMatchingLnMatchAmtTC - tAPMatchingLn.APMatchingLnReceiptAmtTC - tAPMatchingLn.APMatchingLnVarUsageTC - tAPMatchingLn.APMatchingLnVarRateTC <> 0) and 
       /* Error when unbalanced in LC or CC and already balanced in TC */
       ((tAPMatchingLn.APMatchingLnMatchAmtLC - tAPMatchingLn.APMatchingLnReceiptAmtLC - tAPMatchingLn.APMatchingLnVarUsageLC - tAPMatchingLn.APMatchingLnVarRateLC = 0) OR
        (tAPMatchingLn.APMatchingLnMatchAmtCC - tAPMatchingLn.APMatchingLnReceiptAmtCC - tAPMatchingLn.APMatchingLnVarUsageCC - tAPMatchingLn.APMatchingLnVarRateCC = 0))
    then assign oiReturnStatus  = -3
                vcMsgAPMatching = trim(substitute(#T-112'Internal error: invalid call to the method that creates the posting line on the exchange rate variances for the finished pending invoices.':255(55813)T-112#)) + chr(10) + 
                                  trim(#T-117'Can only create an exchange rate line when the posting is balanced in TC, but not yet in BC or SC.':255(999890880)T-117#) + chr(10) + 
                                  trim(substitute(#T-113'Balance in TC: &1.':234(55816)T-113#,string(tAPMatchingLn.APMatchingLnMatchAmtTC - tAPMatchingLn.APMatchingLnReceiptAmtTC - tAPMatchingLn.APMatchingLnVarUsageTC - tAPMatchingLn.APMatchingLnVarRateTC)))  + chr(10) + 
                                  trim(substitute(#T-116'Balance in BC: &1.':234(55817)T-116#,string(tAPMatchingLn.APMatchingLnMatchAmtLC - tAPMatchingLn.APMatchingLnReceiptAmtLC - tAPMatchingLn.APMatchingLnVarUsageLC - tAPMatchingLn.APMatchingLnVarRateLC)))  + chr(10) + 
                                  trim(substitute(#T-137'Balance in SC: &1.':234(999890881)T-137#,string(tAPMatchingLn.APMatchingLnMatchAmtCC - tAPMatchingLn.APMatchingLnReceiptAmtCC - tAPMatchingLn.APMatchingLnVarUsageCC - tAPMatchingLn.APMatchingLnVarRateCC)))  + chr(10) + 
                                  trim(substitute(#T-114'Technical details: &1.':222(55526)T-114#,"ExchRateVar/4":U)).
    if vcMsgAPMatching <> "":U    
    then do :                            
        <M-111 run SetMessage (input  vcMsgAPMatching (icMessage), 
                     input  '':U (icArguments), 
                     input  '':U (icFieldName), 
                     input  '':U (icFieldValue), 
                     input  'E':U (icType), 
                     input  3 (iiSeverity), 
                     input  '':U (icRowid), 
                     input  'QadFin-5552':U (icFcMsgNumber), 
                     input  '':U (icFcExplanation), 
                     input  '':U (icFcIdentification), 
                     input  '':U (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        Return.
    end. /* if vcMsgAPMatching <> "":U */
    
    /* =============================================================================================== */
    /* Calculate the amount for the posting line that holds the LC-exch-rate variance                  */
    /* Get the correct accounting information (this can differ for gains and for losses)               */
    /* Create the posting line that balances the posting in LC - use the GL-Div-CC-PRJ as stated above */
    /* =============================================================================================== */
    if tAPMatchingLn.APMatchingLnVarExchRateLC <> 0 and 
       tAPMatchingLn.APMatchingLnVarExchRateLC <> ?
    then do :
        /* =============================================================================================== */
        /* Calculate the amount for the posting line that holds the LC-exch-rate variance                  */
        /* - Positive amounts (meaning a loss): posted on Debit                                            */
        /* - Negative amounts (meaning a gain): posted on Credit                                           */
        /* Create the posting line that balances the posting in LC - use the GL-Div-CC-PRJ as stated above */
        /* =============================================================================================== */
        assign vdDebitLC  = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                               tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                            then if tAPMatchingLn.APMatchingLnVarExchRateLC > 0 then tAPMatchingLn.APMatchingLnVarExchRateLC       else 0
                            else if tAPMatchingLn.APMatchingLnVarExchRateLC < 0 then tAPMatchingLn.APMatchingLnVarExchRateLC       else 0
               vdCreditLC = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                               tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                            then if tAPMatchingLn.APMatchingLnVarExchRateLC < 0 then tAPMatchingLn.APMatchingLnVarExchRateLC * -1  else 0
                            else if tAPMatchingLn.APMatchingLnVarExchRateLC > 0 then tAPMatchingLn.APMatchingLnVarExchRateLC * -1  else 0.
        /* ==================================================================================== */
        /* Find out the correct GL, Division and CostCentre that are used for this posting-line */
        /* in case of rate-variances (project will always be empty)                             */
        /* ==================================================================================== */
        <M-144 run AdditionalUpdatesAllLinesPLVarExchRateAccount
           (input  (if vdCreditLC <= 0 then false else true) (ilGetGainAccount), 
            output vcGLCode (ocGLCode), 
            output vcDivisionCode (ocDivisionCode), 
            output vcCostCentreCode (ocCostCentreCode), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
            
        If viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        If viFcReturnSuper <  0 then Return.
        /* ==================================================== */
        /* Check wether we have a G/L account by now            */
        /* If the Op Alloc Code is filled, the GL will be blank */
        /* ==================================================== */
        if (vcGLCode = "":U or 
            vcGLCode = ?) and
           (tAPMatchingLn.APMatchingLnOpAllocCode = "":U or
            tAPMatchingLn.APMatchingLnOpAllocCode = ?)
        then do:
            assign oiReturnStatus  = -3
                   vcMsgAPMatching = trim(substitute(#T-146'The system cannot find the required accounting information on the pending invoice details to create the exchange rate differences (Domain:&1, Pinv: &2, Pinv det: &3).':255(55822)T-146#,tAPMatchingLn.PvoDomain,string(tAPMatchingLn.PvoID),string(tAPMatchingLn.PvodLineID))).
            <M-145 run SetMessage (input  vcMsgAPMatching (icMessage), 
                         input  '':U (icArguments), 
                         input  '':U (icFieldName), 
                         input  '':U (icFieldValue), 
                         input  'E':U (icType), 
                         input  3 (iiSeverity), 
                         input  '':U (icRowid), 
                         input  'QadFin-9429':U (icFcMsgNumber), 
                         input  '':U (icFcExplanation), 
                         input  '':U (icFcIdentification), 
                         input  '':U (icFcContext), 
                         output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
            Return.
        end. /* if vcGLCode = "":U or */

        /* =============================================================================================== */
        /* Create the posting line that balances the posting in LC - use the GL-Div-CC-PRJ as stated above */
        /* =============================================================================================== */
        <M-133 run AdditionalUpdatesAllLinesPLAddPostingLine
           (input  icAPMatchingPostingRowidID (icAPMatchingPostingRowId), 
            input  vcGLCode (icGLCode), 
            input  vcDivisionCode (icDivisionCode), 
            input  vcCostCentreCode (icCostCentreCode), 
            input  tAPMatchingLn.APMatchingLnPvodPrjCode (icProjectCode), 
            input  '':U (icOpAllocCode), 
            input  0 (idDebitTC), 
            input  vdDebitLC (idDebitLC), 
            input  0 (idDebitCC), 
            input  0 (idCreditTC), 
            input  vdCreditLC (idCreditLC), 
            input  0 (idCreditCC), 
            input  icPostingText (icPostingText), 
            input  tAPMatching.tdCInvoiceExchangeRate (idTCLCExchangeRate), 
            input  tAPMatching.tdCinvoiceRateScale (idTCLCExchangeScale), 
            input  ? (idTCCCExchangeRate), 
            input  ? (idTCCCExchangeScale), 
            input  tDefaultSafsOperAPM (tDefaultSafsAPM), 
            output tAPMatchingLn.VarExchRatePostingLine_ID (oiPostingLineId), 
            input  true (ilisCallForVarianceOrTax), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        If viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper <  0 then Return.
    end. /* if tAPMatchingLn.APMatchingLnVarExchRateLC <> 0 and  */
    
    /* =============================================================================================== */
    /* Calculate the amount for the posting line that holds the CC-exch-rate variance                  */
    /* Get the correct accounting information (this can differ for gains and for losses)               */
    /* Create the posting line that balances the posting in CC - use the GL-Div-CC-PRJ as stated above */
    /* =============================================================================================== */
    if tAPMatchingLn.APMatchingLnVarExchRateCC <> 0 and 
       tAPMatchingLn.APMatchingLnVarExchRateCC <> ?
    then do :
        /* =============================================================================================== */
        /* Calculate the amount for the posting line that holds the CC-exch-rate variance                  */
        /* - Positive amounts (meaning a loss): posted on Debit                                            */
        /* - Negative amounts (meaning a gain): posted on Credit                                           */
        /* Create the posting line that balances the posting in CC - use the GL-Div-CC-PRJ as stated above */
        /* =============================================================================================== */
        assign vdDebitCC  = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                               tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                            then if tAPMatchingLn.APMatchingLnVarExchRateCC > 0 then tAPMatchingLn.APMatchingLnVarExchRateCC       else 0
                            else if tAPMatchingLn.APMatchingLnVarExchRateCC < 0 then tAPMatchingLn.APMatchingLnVarExchRateCC       else 0
               vdCreditCC = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                               tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                            then if tAPMatchingLn.APMatchingLnVarExchRateCC < 0 then tAPMatchingLn.APMatchingLnVarExchRateCC * -1  else 0
                            else if tAPMatchingLn.APMatchingLnVarExchRateCC > 0 then tAPMatchingLn.APMatchingLnVarExchRateCC * -1  else 0.
        /* ==================================================================================== */
        /* Find out the correct GL, Division and CostCentre that are used for this posting-line */
        /* in case of rate-variances (project will always be empty)                             */
        /* ==================================================================================== */
        <M-147 run AdditionalUpdatesAllLinesPLVarExchRateAccount
           (input  (if vdCreditCC <= 0 then false else true) (ilGetGainAccount), 
            output vcGLCode (ocGLCode), 
            output vcDivisionCode (ocDivisionCode), 
            output vcCostCentreCode (ocCostCentreCode), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
            
        If viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        If viFcReturnSuper <  0 then Return.
        /* ==================================================== */
        /* Check wether we have a G/L account by now            */
        /* If the Op Alloc Code is filled, the GL will be blank */
        /* ==================================================== */
        if (vcGLCode = "":U or 
            vcGLCode = ?) and
           (tAPMatchingLn.APMatchingLnOpAllocCode = "":U or
            tAPMatchingLn.APMatchingLnOpAllocCode = ?)
        then do:
            assign oiReturnStatus  = -3
                   vcMsgAPMatching = trim(substitute(#T-150'The system cannot find the required accounting information on the pending invoice details to create the exchange rate differences (Domain:&1, Pinv: &2, Pinv det: &3).':255(55822)T-150#,tAPMatchingLn.PvoDomain,string(tAPMatchingLn.PvoID),string(tAPMatchingLn.PvodLineID))).
            <M-148 run SetMessage (input  vcMsgAPMatching (icMessage), 
                         input  '':U (icArguments), 
                         input  '':U (icFieldName), 
                         input  '':U (icFieldValue), 
                         input  'E':U (icType), 
                         input  3 (iiSeverity), 
                         input  '':U (icRowid), 
                         input  'QadFin-9430':U (icFcMsgNumber), 
                         input  '':U (icFcExplanation), 
                         input  '':U (icFcIdentification), 
                         input  '':U (icFcContext), 
                         output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
            Return.
        end. /* if vcGLCode = "":U or */
        /* =============================================================================================== */
        /* Create the posting line that balances the posting in SC - use the GL-Div-CC-PRJ as stated above */
        /* =============================================================================================== */
        <M-149 run AdditionalUpdatesAllLinesPLAddPostingLine
           (input  icAPMatchingPostingRowidID (icAPMatchingPostingRowId), 
            input  vcGLCode (icGLCode), 
            input  vcDivisionCode (icDivisionCode), 
            input  vcCostCentreCode (icCostCentreCode), 
            input  tAPMatchingLn.APMatchingLnPvodPrjCode (icProjectCode), 
            input  '':U (icOpAllocCode), 
            input  0 (idDebitTC), 
            input  0 (idDebitLC), 
            input  vdDebitCC (idDebitCC), 
            input  0 (idCreditTC), 
            input  0 (idCreditLC), 
            input  vdCreditCC (idCreditCC), 
            input  icPostingText (icPostingText), 
            input  0 (idTCLCExchangeRate), 
            input  0 (idTCLCExchangeScale), 
            input  tAPMatching.tdCInvoiceCCRate (idTCCCExchangeRate), 
            input  tAPMatching.tdCInvoiceCCScale (idTCCCExchangeScale), 
            input  tDefaultSafsOperAPM (tDefaultSafsAPM), 
            output tAPMatchingLn.VarExchRatCCPostingLine_ID (oiPostingLineId), 
            input  true (ilisCallForVarianceOrTax), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        If viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper <  0 then Return.
    end. /* if tAPMatchingLn.APMatchingLnVarExchRateSC <> 0 and  */
    
    /* ======================== */
    /* Set ReturnStatus = OK    */
    /* ======================== */
    if oiReturnStatus = -98
    then assign oiReturnStatus = 0.