project QadFinancials > class BAPMatching > method AdditionalUpdatesAllLinesPLVarExchRateAccount

Description

AdditionalUpdatesAllLinesPLVarExchRateAccount; submethod of AdditionalUpdatesAllLinesPLVarExchRate 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


ilGetGainAccountinputlogicalIf you want this method to return you the account used for GAINS then pass true
If you want this method to return you the account used for LOSSES then pass false or unknown

FYI: if the CreditLC is postive then this means a Gain
ocGLCodeoutputcharacter
ocDivisionCodeoutputcharacter
ocCostCentreCodeoutputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.AdditionalUpdatesAllLinesPLVarExchRate


program code (program6/bapmatching.p)

/* ===================================================================================================== */
    /* This method will return the account-information for the calling method                                */
    /* 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-149'Internal error: information is missing.':255(49818)T-149#)) + chr(10) + 
                                  trim(substitute(#T-150'Available supplier invoice: &1.':234(53332)T-150#,available (tqCInvoiceByMatchingInfo))) + chr(10) + 
                                  trim(substitute(#T-151'Available matching header: &1.':234(49819)T-151#,available (tAPMatching))) + chr(10) + 
                                  trim(substitute(#T-152'Available matching details: &1.':234(49820)T-152#,available (tAPMatchingLn))) + chr(10) + 
                                  trim(substitute(#T-153'Available pending invoice details: &1.':234(49821)T-153#,available (tqPendingVoucherForMatchingAcc))) + chr(10) + 
                                  trim(substitute(#T-154'Technical details: &1.':222(55526)T-154#,"ExchRateVar/1":U)).
    if vcMsgAPMatching <> "":U    
    then do :                            
        <M-138 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-9408':U (icFcMsgNumber), 
                     input  '':U (icFcExplanation), 
                     input  '':U (icFcIdentification), 
                     input  '':U (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        Return.
    end. /* if vcMsgAPMatching <> "":U */
    
    /* ==================================================================================== */
    /* 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)                             */
    /* Case 1: Get the info from the DefAccountMstr-acdf (Gain + incl:prod-line)            */
    /* Case 2: Get the info from the DefAccountMstr-acdf (Gain + excl:prod-line)            */
    /* Case 3: Get the info from the system G/L-Account for 'Exchange - Unrealised Profit'  */
    /* Case 4: Get the info from the DefAccountMstr-acdf (Loss + incl:prod-line)            */
    /* Case 5: Get the info from the DefAccountMstr-acdf (Loss + excl:prod-line)            */
    /* Case 6: Get the info from the system G/L-Account for 'Exchange - Unrealised Loss'    */
    /* ==================================================================================== */
    /* Reset message-string and start a block; in case of a blocking error, we will leave the block */
    assign vcMsgAPMatching = "":U.
    FINDACCOUNTBLOCK: DO :
        if ilGetGainAccount = true /* CreditLC > 0 /* meaning a Gain */ */
        then do :
            /* Find acdf (account defaults): currency and prod-line */
            <Q-142 run AccountDefaultMasterByPrimKey (all) (Read) (Cache)
               (input tqPendingVoucherForMatchingAcc.tcpvo_domain, (DomainCode)
                input 'PO':U, (Module)
                input 'PUR_GAIN_ACCT':U, (Type)
                input tqPendingVoucherForMatchingAcc.tcpvo_curr, (Key1)
                input tqPendingVoucherForMatchingAcc.tcpt_prod_line, (Key2)
                input '':U, (Key3)
                input '':U, (Key4)
                input '':U, (Key5)
                input '':U, (Key6)
                output dataset tqAccountDefaultMasterByPrimKey) in BMfgAccountDefaultMaster >
            find tqAccountDefaultMasterByPrimKey where 
                 tqAccountDefaultMasterByPrimKey.tcacdf_domain = tqPendingVoucherForMatchingAcc.tcpvo_domain   and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key1   = tqPendingVoucherForMatchingAcc.tcpvo_curr     and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key2   = tqPendingVoucherForMatchingAcc.tcpt_prod_line and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key3   = "":U                                          and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key4   = "":U                                          and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key5   = "":U                                          and
                 tqAccountDefaultMasterByPrimKey.tcacdf_key6   = "":U
                 no-lock no-error.
            if available tqAccountDefaultMasterByPrimKey and tqAccountDefaultMasterByPrimKey.tcacdf_acct <> "":U
            then  /* === Case 1 === */
                  assign vcGLCode         = tqAccountDefaultMasterByPrimKey.tcacdf_acct
                         vcDivisionCode   = tqAccountDefaultMasterByPrimKey.tcacdf_sub
                         vcCostCentreCode = tqAccountDefaultMasterByPrimKey.tcacdf_cc.
            else do :
                /* Find acdf (account defaults): currency  */
                <Q-143 run AccountDefaultMasterByPrimKey (all) (Read) (Cache)
                   (input tqPendingVoucherForMatchingAcc.tcpvo_domain, (DomainCode)
                    input 'PO':U, (Module)
                    input 'PUR_GAIN_ACCT':U, (Type)
                    input tqPendingVoucherForMatchingAcc.tcpvo_curr, (Key1)
                    input '':U, (Key2)
                    input '':U, (Key3)
                    input '':U, (Key4)
                    input '':U, (Key5)
                    input '':U, (Key6)
                    output dataset tqAccountDefaultMasterByPrimKey) in BMfgAccountDefaultMaster >
                find tqAccountDefaultMasterByPrimKey where 
                     tqAccountDefaultMasterByPrimKey.tcacdf_domain = tqPendingVoucherForMatchingAcc.tcpvo_domain   and 
                     tqAccountDefaultMasterByPrimKey.tcacdf_key1   = tqPendingVoucherForMatchingAcc.tcpvo_curr     and 
                     tqAccountDefaultMasterByPrimKey.tcacdf_key2   = "":U                                          and 
                     tqAccountDefaultMasterByPrimKey.tcacdf_key3   = "":U                                          and 
                     tqAccountDefaultMasterByPrimKey.tcacdf_key4   = "":U                                          and 
                     tqAccountDefaultMasterByPrimKey.tcacdf_key5   = "":U                                          and
                     tqAccountDefaultMasterByPrimKey.tcacdf_key6   = "":U
                     no-lock no-error.
                if available tqAccountDefaultMasterByPrimKey and tqAccountDefaultMasterByPrimKey.tcacdf_acct <> "":U
                then  /* === Case 2 === */
                      assign vcGLCode         = tqAccountDefaultMasterByPrimKey.tcacdf_acct
                             vcDivisionCode   = tqAccountDefaultMasterByPrimKey.tcacdf_sub
                             vcCostCentreCode = tqAccountDefaultMasterByPrimKey.tcacdf_cc.
                else do :
                    if {&GLSYSTEMTYPE-EXCHANGEUNREALPROFIT} = "":U or 
                       {&GLSYSTEMTYPE-EXCHANGEUNREALPROFIT} = ?
                    then do :
                        assign vcMsgAPMatching = trim(substitute(#T-163'Internal error. The system cannot find the system GL account for exchange rate unrealized profit because the preprocessor for this type of account is not defined.':255(57305)T-163#,tqPendingVoucherForMatchingAcc.tcpvo_domain)) + chr(10) + 
                                                 trim(substitute(#T-164'Technical details: case: &1.':222(49764)T-164#,"ExchRateVar/10":U)).
                        Leave FINDACCOUNTBLOCK.
                    end. /* if {&GLSYSTEMTYPE-EXCHANGEUNREALPROFIT} = "":U or */
                    <Q-144 run GLByGLSystemType (all) (Read) (NoCache)
                       (input tAPMatching.Company_ID, (CompanyId)
                        input {&GLSYSTEMTYPE-EXCHANGEUNREALPROFIT}, (GLSystemTypeCode)
                        input {&GLTYPECODE-SYST}, (GlTypeCode)
                        input ?, (GlIsDivisionAccount)
                        output dataset tqGLByGLSystemType) in BGL >
                    find tqGLByGLSystemType where 
                         tqGLByGLSystemType.tcGLTypeCode = {&GLTYPECODE-SYST} 
                         no-lock no-error.
                    if not available tqGLByGLSystemType
                    then do:
                        assign vcMsgAPMatching = trim(substitute(#T-165'Internal error. The system cannot find the system GL account for exchange rate unrealized profit.':255(57308)T-165#,tqPendingVoucherForMatchingAcc.tcpvo_domain)) + chr(10) + 
                                                 trim(substitute(#T-166'Technical details: case: &1.':222(49764)T-166#,"ExchRateVar/11":U)).
                        Leave FINDACCOUNTBLOCK.      
                    end. /* if not available tqGLByGLSystemType */
                    /* === Case 3 */
                    assign vcGLCode         = tqGLByGLSystemType.tcGLCode
                           vcDivisionCode   = "":U
                           vcCostCentreCode = "":U.
                end. /* Not f available tqAccountDefaultMasterByPrimKey */
            end. /* if not avail tqAccountDefaultMasterByPrimKey */
        end. /* if ilGetGainAccount = true : vdCreditLC > 0 /* meaning a Gain */ */
        else do :
            /* Find acdf (account defaults): currency and prod-line */
            <Q-145 run AccountDefaultMasterByPrimKey (all) (Read) (Cache)
               (input tqPendingVoucherForMatchingAcc.tcpvo_domain, (DomainCode)
                input 'PO':U, (Module)
                input 'PUR_LOSS_ACCT':U, (Type)
                input tqPendingVoucherForMatchingAcc.tcpvo_curr, (Key1)
                input tqPendingVoucherForMatchingAcc.tcpt_prod_line, (Key2)
                input '':U, (Key3)
                input '':U, (Key4)
                input '':U, (Key5)
                input '':U, (Key6)
                output dataset tqAccountDefaultMasterByPrimKey) in BMfgAccountDefaultMaster >
            find tqAccountDefaultMasterByPrimKey where 
                 tqAccountDefaultMasterByPrimKey.tcacdf_domain = tqPendingVoucherForMatchingAcc.tcpvo_domain   and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key1   = tqPendingVoucherForMatchingAcc.tcpvo_curr     and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key2   = tqPendingVoucherForMatchingAcc.tcpt_prod_line and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key3   = "":U                                          and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key4   = "":U                                          and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key5   = "":U                                          and
                 tqAccountDefaultMasterByPrimKey.tcacdf_key6   = "":U
                 no-lock no-error.
            if available tqAccountDefaultMasterByPrimKey and tqAccountDefaultMasterByPrimKey.tcacdf_acct <> "":U
            then  /* === Case 4 === */
                  assign vcGLCode         = tqAccountDefaultMasterByPrimKey.tcacdf_acct
                         vcDivisionCode   = tqAccountDefaultMasterByPrimKey.tcacdf_sub
                         vcCostCentreCode = tqAccountDefaultMasterByPrimKey.tcacdf_cc.
            else do :
                /* Find acdf (account defaults): currency */
                <Q-146 run AccountDefaultMasterByPrimKey (all) (Read) (Cache)
                   (input tqPendingVoucherForMatchingAcc.tcpvo_domain, (DomainCode)
                    input 'PO':U, (Module)
                    input 'PUR_LOSS_ACCT':U, (Type)
                    input tqPendingVoucherForMatchingAcc.tcpvo_curr, (Key1)
                    input '':U, (Key2)
                    input '':U, (Key3)
                    input '':U, (Key4)
                    input '':U, (Key5)
                    input '':U, (Key6)
                    output dataset tqAccountDefaultMasterByPrimKey) in BMfgAccountDefaultMaster >
                find tqAccountDefaultMasterByPrimKey where 
                     tqAccountDefaultMasterByPrimKey.tcacdf_domain = tqPendingVoucherForMatchingAcc.tcpvo_domain   and 
                     tqAccountDefaultMasterByPrimKey.tcacdf_key1   = tqPendingVoucherForMatchingAcc.tcpvo_curr     and 
                     tqAccountDefaultMasterByPrimKey.tcacdf_key2   = "":U                                          and 
                     tqAccountDefaultMasterByPrimKey.tcacdf_key3   = "":U                                          and 
                     tqAccountDefaultMasterByPrimKey.tcacdf_key4   = "":U                                          and 
                     tqAccountDefaultMasterByPrimKey.tcacdf_key5   = "":U                                          and
                     tqAccountDefaultMasterByPrimKey.tcacdf_key6   = "":U
                     no-lock no-error.
                if available tqAccountDefaultMasterByPrimKey and tqAccountDefaultMasterByPrimKey.tcacdf_acct <> "":U
                then  /* === Case 5 === */
                      assign vcGLCode         = tqAccountDefaultMasterByPrimKey.tcacdf_acct
                             vcDivisionCode   = tqAccountDefaultMasterByPrimKey.tcacdf_sub
                             vcCostCentreCode = tqAccountDefaultMasterByPrimKey.tcacdf_cc.
                else do :
                    if {&GLSYSTEMTYPE-EXCHANGEUNREALLOSS} = "":U or 
                       {&GLSYSTEMTYPE-EXCHANGEUNREALLOSS} = ?
                    then do :
                        assign vcMsgAPMatching = trim(substitute(#T-167'Internal error. The system cannot find the system GL account for exchange rate unrealized loss because the preprocessor for this type of account is not defined.':255(57306)T-167#,tqPendingVoucherForMatchingAcc.tcpvo_domain)) + chr(10) + 
                                                 trim(substitute(#T-168'Technical details: case: &1.':222(49764)T-168#,"ExchRateVar/10":U)).
                        Leave FINDACCOUNTBLOCK.
                    end. /* if {&GLSYSTEMTYPE-EXCHANGEUNREALLOSS} = "":U or */
                    <Q-147 run GLByGLSystemType (all) (Read) (Cache)
                       (input tAPMatching.Company_ID, (CompanyId)
                        input {&GLSYSTEMTYPE-EXCHANGEUNREALLOSS}, (GLSystemTypeCode)
                        input {&GLTYPECODE-SYST}, (GlTypeCode)
                        input ?, (GlIsDivisionAccount)
                        output dataset tqGLByGLSystemType) in BGL >
                    find tqGLByGLSystemType where 
                         tqGLByGLSystemType.tcGLTypeCode = {&GLTYPECODE-SYST}
                         no-lock no-error.
                    if not available tqGLByGLSystemType
                    then do:
                        assign vcMsgAPMatching = trim(substitute(#T-169'Internal error. The system cannot find the system GL account for exchange rate unrealized loss.':255(57307)T-169#,tqPendingVoucherForMatchingAcc.tcpvo_domain)) + chr(10) + 
                                                 trim(substitute(#T-170'Technical details: case: &1.':222(49764)T-170#,"ExchRateVar/11":U)).
                        Leave FINDACCOUNTBLOCK.      
                    end. /* if not available tqGLByGLSystemType */
                    /* === Case 6 */
                    assign vcGLCode         = tqGLByGLSystemType.tcGLCode
                           vcDivisionCode   = "":U
                           vcCostCentreCode = "":U.
                end. /* Not f available tqAccountDefaultMasterByPrimKey */
            end. /* if not avail tqAccountDefaultMasterByPrimKey */
        end. /* if ilGetGainAccount <> true : vdCreditLC <= 0 /* meaning a Loss */ */
    END. /* FINDACCOUNTBLOCK: DO : */
    
    /* ====================================== */
    /* Check for errors in the previous block */
    /* ====================================== */
    if vcMsgAPMatching <> "":U
    then do :
        assign oiReturnStatus = -3.
        <M-136 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-9406':U (icFcMsgNumber), 
                     input  '':U (icFcExplanation), 
                     input  '':U (icFcIdentification), 
                     input  '':U (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        Return.
    end. /* if vcMsgAPMatching <> "":U */
        
    /* ===================================================== */
    /* Transfer the account-information to the output-params */
    /* ===================================================== */
    assign ocGLCode         = vcGLCode  
           ocDivisionCode   = vcDivisionCode
           ocCostCentreCode = vcCostCentreCode.
    
    /* ======================== */
    /* Set ReturnStatus = OK    */
    /* ======================== */
    if oiReturnStatus = -98
    then assign oiReturnStatus = 0.