project QadFinancials > class BPosting > method ValidateComponentPreAssignPostingLine

Description

Validate Component before Ancestor Tag - Fill fields in PostingLine (assign tcCurrencyCode, round LC amounts, ...)


Parameters


bcCurrencyCodeinput-outputcharacter
blCurrencyFetchedinput-outputlogical
bdExchangeRateinput-outputdecimalExchangeRate - if set for currency reuse that amount so we don't have to retrive currency again
bdExchangeRateScaleinput-outputdecimalExchangeRateScale - if set for currency reuse that amount so we don't have to retrive currency again
bdCCExchangeRateinput-outputdecimal
bdCCExchangeRateScaleinput-outputdecimal
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPosting.ValidateComponentPre


program code (program4/bposting.p)

/* ================================== */
/* Exception Handling                 */
/* ================================== */
assign oiReturnStatus      = -98
       viLocalReturnStatus = 0.

/* ================================== */
/* Assign t_sPostingLine.tcCurrencyCode */
/* ================================== */
if t_sPostingLine.tcCurrencyCode = "":U or 
   t_sPostingLine.tcCurrencyCode = ?
then assign t_sPostingLine.tcCurrencyCode = vcCompanyLC.

/* Check which data from other components are needed */
assign vlIsBCInvoiceNeeded = can-find(first t_sPostingLine where
                                            t_sPostingLine.tcGLTypeCode = {&GLTYPECODE-CRED}).

/* ============================================================================================================================= */
/* 1- Assign LC Amounts                                                                                                          */
/* ============================================================================================================================= */
ASSIGNLCBLOCK:
do:    
    /* =========================================== */
    /* Go through all new / changed posting-lines  */
    /* =========================================== */
    if t_sPosting.tc_Status          <> "D":U and
       t_sPostingLine.tcCurrencyCode <> "":U  and 
       t_sPostingLine.tcCurrencyCode <> ?
    then do:       
        /* ================================================================= */
        /* Skip the changed ones wherefor the TC-amount has not been changed */
        /* ================================================================= */
        if t_sPostingLine.tc_Status      = "C":U and 
           not can-find (t_iPostingLine where 
                         t_iPostingLine.tc_Rowid = t_sPostingLine.tc_Rowid and 
                         (t_iPostingLine.PostingLineCreditTC <> t_sPostingLine.PostingLineCreditTC or 
                          t_iPostingLine.PostingLineDebitTC  <> t_sPostingLine.PostingLineDebitTC))
        then leave ASSIGNLCBLOCK.
                            
        /* ====================================== */
        /* Default the scale amounts to 1         */
        /* ====================================== */
         if (t_sPosting.PostingIsSkipAutoAssignLC = false and 
             (t_sPostingLine.PostingLineRateScale = 0 or t_sPostingLine.PostingLineRateScale = ?)) 
         then assign t_sPostingLine.PostingLineRateScale = 1.
         
         if (vlDomainIsStatutory = true and 
             (t_sPostingLine.PostingLineCCScale = 0 or t_sPostingLine.PostingLineCCScale = ?)) 
         then assign t_sPostingLine.PostingLineCCScale = 1.
        
        if t_sPostingLine.tcCurrencyCode        = vcCompanyLC                            and 
           t_sPosting.PostingIsSkipAutoAssignLC = false                                  and
          (vcActivityCode                       = "JournalEntryTransExcelIntegration":U  or
           vcActivityCode                       = "JournalEntryExcelIntegrationRepair":U or
           vcActivityCode                       = "ExcelIntegration")
        then assign t_sPostingLine.PostingLineCreditLC     = t_sPostingLine.PostingLineCreditTC
                    t_sPostingLine.PostingLineDebitLC      = t_sPostingLine.PostingLineDebitTC
                    t_sPostingLine.PostingLineExchangeRate = 1
                    t_sPostingLine.PostingLineRateScale    = 1.
         
        /* ====================================== */
        /* Assign the LC-amounts & Rates          */
        /* This is not done for external postings */
        /* And also postings created by YEAR END  */
        /* ====================================== */
        if t_sPosting.PostingIsSkipAutoAssignLC = false                       and
           t_sPosting.tcJournalTypeCode       <> {&JOURNALTYPE-YEARLYCLOSING} and  
           ((t_sPostingLine.PostingLineDebitTC  <> 0  and
             t_sPostingLine.PostingLineDebitTC  <> ?  and
            (t_sPostingLine.PostingLineDebitLC   = 0  or
             t_sPostingLine.PostingLineDebitLC   = ?))     or
            (t_sPostingLine.PostingLineCreditTC <> 0  and
             t_sPostingLine.PostingLineCreditTC <> ?  and
            (t_sPostingLine.PostingLineCreditLC  = 0  or
             t_sPostingLine.PostingLineCreditLC  = ?)))
        then do:
            if t_sPostingLine.tcCurrencyCode = vcCompanyLC
            then assign t_sPostingLine.PostingLineCreditLC     = t_sPostingLine.PostingLineCreditTC
                        t_sPostingLine.PostingLineDebitLC      = t_sPostingLine.PostingLineDebitTC
                        t_sPostingLine.PostingLineExchangeRate = 1
                        t_sPostingLine.PostingLineRateScale    = 1.
            else do:
                                  
                if (t_sPostingLine.tcCurrencyCode <> bcCurrencyCode or
                    t_sPostingLine.PostingLineExchangeRate <> bdExchangeRate or
                    t_sPostingLine.PostingLineRateScale <> bdExchangeRateScale) 
                then do:
                    if (t_sPostingLine.PostingLineExchangeRate <> 0 and t_sPostingLine.PostingLineExchangeRate <> ?)             
                    then do: 
                            assign bdExchangeRate      = t_sPostingLine.PostingLineExchangeRate
                                   bdExchangeRateScale = t_sPostingLine.PostingLineRateScale.
                    end.
                    else do:
                        <M-53 run GetExchangeRate
                           (input  t_sPosting.Company_ID (iiCompanyID), 
                            input  ? (iiFromCurrencyID), 
                            input  t_sPostingLine.tcCurrencyCode (icFromCurrencyCode), 
                            input  viCompanyLCId (iiToCurrencyID), 
                            input  ? (icToCurrencyCode), 
                            input  ? (iiExchangeRateTypeID), 
                            input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode), 
                            input  t_sPosting.PostingDate (itValidityDate), 
                            output bdExchangeRate (odExchangeRate), 
                            output bdExchangeRateScale (odExchangeScaleFactor), 
                            output viFcReturnSuper (oiReturnStatus)) in BPosting>
                        if viFcReturnSuper <> 0 and
                           viLocalReturnStatus  >= 0
                        then assign viLocalReturnStatus = viFcReturnSuper.
                        if viFcReturnSuper < 0
                        then leave ASSIGNLCBLOCK.                                                                
                    end. /* else do */                   
                end. /* if */ 
                
                if t_sPostingLine.PostingLineDebitTC <> 0 and
                   t_sPostingLine.PostingLineDebitTC <> ?
                then assign t_sPostingLine.PostingLineDebitLC = <M-17 RoundAmount
                                                                   (input  t_sPostingLine.PostingLineDebitTC * bdExchangeRate * bdExchangeRateScale (idUnroundedAmount), 
                                                                    input  viCompanyLCId (iiCurrencyID), 
                                                                    input  vcCompanyLC (icCurrencyCode)) in business>.                
                                                                    
                if t_sPostingLine.PostingLineCreditTC <> 0 and
                   t_sPostingLine.PostingLineCreditTC <> ?
                then assign t_sPostingLine.PostingLineCreditLC = <M-18 RoundAmount
                                                                    (input  t_sPostingLine.PostingLineCreditTC * bdExchangeRate * bdExchangeRateScale (idUnroundedAmount), 
                                                                     input  viCompanyLCId (iiCurrencyID), 
                                                                     input  vcCompanyLC (icCurrencyCode)) in business>. 
                                                                     
                assign t_sPostingLine.PostingLineExchangeRate = bdExchangeRate
                       t_sPostingLine.PostingLineRateScale    = bdExchangeRateScale.
            end. /* else do */
        end. /* t_sPosting.PostingIsSkipAutoAssignLC = false  and */
        else do:
            if  (t_sPosting.PostingIsSkipAutoAssignLC = false and
                ((t_sPostingLine.PostingLineDebitLC <> 0 and t_sPostingLine.PostingLineDebitLC  <> ?) or
                (t_sPostingLine.PostingLineCreditLC <> 0 and t_sPostingLine.PostingLineCreditLC <> ?)) and
               ((t_sPostingLine.PostingLineDebitTC  <> 0 and t_sPostingLine.PostingLineDebitTC  <> ?) or 
                (t_sPostingLine.PostingLineCreditTC <> 0 and t_sPostingLine.PostingLineCreditTC <> ?)))
            then do:                
                /*
                   If LC and exchange rate is set - use exchange rate from xml otherwise calculate it
                */
                if (t_sPostingLine.PostingLineExchangeRate = 0 or t_sPostingLine.PostingLineExchangeRate = ?)
                then do:
                   assign t_sPostingLine.PostingLineExchangeRate =                 
                    ((if t_sPostingLine.PostingLineDebitLC  = ? then 0 else t_sPostingLine.PostingLineDebitLC) - 
                     (if t_sPostingLine.PostingLineCreditLC = ? then 0 else t_sPostingLine.PostingLineCreditLC)) 
                     /
                    ((if t_sPostingLine.PostingLineDebitTC  = ? then 0 else t_sPostingLine.PostingLineDebitTC) - 
                     (if t_sPostingLine.PostingLineCreditTC = ? then 0 else t_sPostingLine.PostingLineCreditTC)) no-error.                    
                /* check the error status */
                if error-status:error 
                then do:
                    assign vcMsgExplanation = <M-86 GetErrorExplanation
                                                 (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                                  input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                                                  output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                                                   
                    assign vcMessage  = trim(substitute(#T-28'Error calculating exchange rate from BC and TC amounts':255(88263408)T-28#))  + chr(10) +
                                    trim(substitute(#T-57'TC Credit Amount in invoice: &1.':255(210144214)T-57#, trim(string(t_sPostingLine.PostingLineCreditTC)))) + chr(10) + 
                                    trim(substitute(#T-30'TC Debit Amount in invoice: &1.':255(602977159)T-30#, trim(string(t_sPostingLine.PostingLineDebitTC)))) + chr(10) + 
                                    trim(substitute(#T-96'BC Credit Amount in invoice: &1.':255(920191623)T-96#, trim(string(t_sPostingLine.PostingLineCreditLC)))) + chr(10) + 
                                    trim(substitute(#T-61'BC Debit Amount in invoice: &1.':255(956484826)T-61#, trim(string(t_sPostingLine.PostingLineDebitLC)))).                                        
                    viLocalReturnStatus = -1.
                   <M-32 run SetMessage
                      (input  vcMessage (icMessage), 
                       input  '':U (icArguments), 
                       input  't_sPostingLine.PostingLineExchangeRate':U (icFieldName), 
                       input  string(t_sPostingLine.PostingLineExchangeRate) (icFieldValue), 
                       input  'E':U (icType), 
                       input  3 (iiSeverity), 
                       input  '':U (icRowid), 
                       input  'qadfin-553852':U (icFcMsgNumber), 
                       input  vcMsgExplanation (icFcExplanation), 
                       input  '' (icFcIdentification), 
                       input  '' (icFcContext), 
                       output viFcReturnSuper (oiReturnStatus)) in BPosting>
                    leave ASSIGNLCBLOCK.
                 end.  /* if error-status:error */                    
                end. /* if (t_sPostingLine.PostingLineExchangeRate */    
                
                assign bdExchangeRate      = t_sPostingLine.PostingLineExchangeRate
                       bdExchangeRateScale = t_sPostingLine.PostingLineRateScale.
                       
            end. /* if (t_sPosting.PostingIsSkipAutoAssignLC = false */
        end. /*else do */
        
        assign bcCurrencyCode = t_sPostingLine.tcCurrencyCode.

        /* ====================================================== */
        /* Validation-errors:                                     */
        /*  When LC is empty and Rate is filled                   */
        /*  When LC is filled and  TC is filled and Rate is empty */
        /* ====================================================== */
        assign vcMessage = "":U.
        if (t_sPostingLine.tcCurrencyCode <> vcCompanyLC and 
            ((t_sPostingLine.PostingLineCreditLC  = 0  or
              t_sPostingLine.PostingLineCreditLC  = ?) and 
             (t_sPostingLine.PostingLineDebitLC   = 0  or
              t_sPostingLine.PostingLineDebitLC   = ?))      and 
            ((t_sPostingLine.PostingLineExchangeRate <> 0 and 
              t_sPostingLine.PostingLineExchangeRate <> ?) Or
             (t_sPostingLine.PostingLineRateScale    <> 0 and 
              t_sPostingLine.PostingLineRateScale    <> ?)))
        then do :
            /* This can be a valid situation when TC is filled and the Rate is filled and LC is */
            /* zero but only in case LC has become zero due to rounding of the LC amount        */
            assign vdAmountLCCalculated  = <M-5 RoundAmount
                                              (input  (t_sPostingLine.PostingLineCreditTC - t_sPostingLine.PostingLineDebitTC) * t_sPostingLine.PostingLineExchangeRate * t_sPostingLine.PostingLineRateScale (idUnroundedAmount), 
                                               input  viCompanyLCId (iiCurrencyID), 
                                               input  ? (icCurrencyCode)) in BPosting>.
                                                                                              
            if vdAmountLCCalculated <> t_sPostingLine.PostingLineCreditLC - t_sPostingLine.PostingLineDebitLC
            then assign vcMessage = trim(substitute(#T-72'Exchange inconsistency: the exchange rate or rate scale is specified, but the base currency amount is blank.':255(57502)T-72#)) + chr(10) + 
                                    trim(substitute(#T-76'Exchange Rate: &1':255(31323)T-76#,string(t_sPostingLine.PostingLineExchangeRate))) + chr(10) +
                                    trim(substitute(#T-94'Rate Scale factor: &1':255(31325)T-94#,string(t_sPostingLine.PostingLineRateScale))) + chr(10) +
                                    trim(substitute(#T-54'BC Credit Amount: &1':255(31327)T-54#,string(t_sPostingLine.PostingLineCreditLC)))  + chr(10) +
                                    trim(substitute(#T-23'BC Debit Amount: &1':255(31328)T-23#,string(t_sPostingLine.PostingLineDebitLC))).
                                    
        end. /* if (t_sPostingLine.tcCurrencyCode <> vcCompanyLC and  */
        
        if vcMessage = "":U                                  and 
           ((t_sPostingLine.PostingLineCreditLC <> 0  and
             t_sPostingLine.PostingLineCreditLC <> ?) or 
            (t_sPostingLine.PostingLineDebitLC  <> 0  and
             t_sPostingLine.PostingLineDebitLC  <> ?))       and 
           ((t_sPostingLine.PostingLineCreditTC <> 0  and
             t_sPostingLine.PostingLineCreditTC <> ?) or 
            (t_sPostingLine.PostingLineDebitTC  <> 0  and
             t_sPostingLine.PostingLineDebitTC  <> ?))       and 
           (t_sPostingLine.PostingLineExchangeRate = 0 or
            t_sPostingLine.PostingLineExchangeRate = ? or
            t_sPostingLine.PostingLineRateScale    = 0 or
            t_sPostingLine.PostingLineRateScale    = ?)
        then assign vcMessage = trim(substitute(#T-55'Exchange inconsistency: the transaction and base currency amounts are specified, but the exchange rate or rate scale is blank.':255(57503)T-55#)) + chr(10) + 
                                trim(substitute(#T-88'Exchange Rate: &1':255(31323)T-88#,string(t_sPostingLine.PostingLineExchangeRate))) + chr(10) +
                                trim(substitute(#T-68'Rate Scale factor: &1':255(31325)T-68#,string(t_sPostingLine.PostingLineRateScale))) + chr(10) +
                                trim(substitute(#T-62'BC Credit Amount: &1':255(31327)T-62#,string(t_sPostingLine.PostingLineCreditLC)))  + chr(10) +
                                trim(substitute(#T-79'BC Debit Amount: &1':255(31328)T-79#,string(t_sPostingLine.PostingLineDebitLC))).
        if vcMessage <> "":U 
        then do :
            assign vcMsgExplanation = <M-67 GetErrorExplanation
                                         (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                          input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                                          output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
            <M-95 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tPostingLine.PostingLineExchangeRate':U (icFieldName), 
                input  string(t_sPostingLine.PostingLineExchangeRate) (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sPosting.tc_Rowid (icRowid), 
                input  'QadFin-936155':U (icFcMsgNumber), 
                input  vcMsgExplanation (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
            assign viLocalReturnStatus = -1.
            leave ASSIGNLCBLOCK.
        end. /* if vcMessage */
        
    end. /* t_sPostingLine.Currency_ID <> 0 ... */
    
end. /* ASSIGNLCBLOCK */

/* ================================== */                                        
/* Properly round LC amounts          */
/* ================================== */
if t_sPostingLine.PostingLineDebitLC <> 0 and
   t_sPostingLine.PostingLineDebitLC <> ?
then assign t_sPostingLine.PostingLineDebitLC = <M-51 RoundAmount
                                                   (input  t_sPostingLine.PostingLineDebitLC (idUnroundedAmount), 
                                                    input  viCompanyLCId (iiCurrencyID), 
                                                    input  vcCompanyLC (icCurrencyCode)) in BPosting>.

if t_sPostingLine.PostingLineCreditLC <> 0 and
   t_sPostingLine.PostingLineCreditLC <> ?
then assign t_sPostingLine.PostingLineCreditLC = <M-44 RoundAmount
                                                    (input  t_sPostingLine.PostingLineCreditLC (idUnroundedAmount), 
                                                     input  viCompanyLCId (iiCurrencyID), 
                                                     input  vcCompanyLC (icCurrencyCode)) in BPosting>.   
                                                     
/* ======================================================= */                                                     
/* Make sure the LC amounts are not left as unknown values */
/* This will cause problems with calculating the balance.  */
/* ======================================================= */
if t_sPostingLine.PostingLineDebitLC  = ? then assign t_sPostingLine.PostingLineDebitLC  = 0.
if t_sPostingLine.PostingLineCreditLC = ? then assign t_sPostingLine.PostingLineCreditLC = 0.                                                    


/* ============================================================================================================================= */
/* 2- Assign CC Amounts                                                                                                          */
/* ============================================================================================================================= */
ASSIGNCCBLOCK:
do:

    /* ================================= */
    /* Go through all undeleted postings */
    /* ================================= */
    if t_sPosting.tc_Status               <> "D":U and
       t_sPostingLine.tcCurrencyCode      <> "":U  and 
       t_sPostingLine.tcCurrencyCode      <> ? 
    then do:
    
         /* ======================================================================== */	 
         /* Do a proper rounding of the CC amounts when originated from MfgPro (OTP) */	 
         /* ======================================================================== */	 
         if t_sPosting.PostingOriginIsExternal = true and
            t_sPostingLine.tc_Status = "N":U
         then do :	                       
    
             /* Be sure the Amounts are rounded correctly */
             if t_sPostingLine.PostingLineDebitCC <> 0 and t_sPostingLine.PostingLineDebitCC <> ?
             then assign t_sPostingLine.PostingLineDebitCC = <M-40 RoundAmount
                                                                (input  t_sPostingLine.PostingLineDebitCC (idUnroundedAmount), 
                                                                 input  viCompanyCCId (iiCurrencyID), 
                                                                 input  vcCompanyCC (icCurrencyCode)) in BPosting>.
                  
             if t_sPostingLine.PostingLineCreditCC <> 0 and t_sPostingLine.PostingLineCreditCC <> ?
             then assign t_sPostingLine.PostingLineCreditCC =  <M-73 RoundAmount
                                                                  (input  t_sPostingLine.PostingLineCreditCC (idUnroundedAmount), 
                                                                   input  viCompanyCCId (iiCurrencyID), 
                                                                   input  vcCompanyCC (icCurrencyCode)) in BPosting>.
         end. /* Round CC */                                                                   
                                                                           
         /* ======================================================================================================== */	 
         /* No re-calculations of the CC-amounts is needed in case it concerns IC-transactions from MfgPro           */	 
         /* However, when the TC- and the CC-amounts are filled and the currency <> CC then we overwrite the CC-rate */	 
         /* ======================================================================================================== */	 
         if t_sPosting.PostingOriginIsExternal = true  and	 
            t_sPosting.PostingOriginTransType  = 'IC':U	 
         then do :	 
             if t_sPostingLine.tc_Status          = "N":U        and	 
                t_sPostingLine.tcCurrencyCode     <> vcCompanyCC and	 
                ((t_sPostingLine.PostingLineDebitCC <> 0 and	 
                  t_sPostingLine.PostingLineDebitCC <> ?) or	 
                 (t_sPostingLine.PostingLineCreditCC <> 0 and	 
                  t_sPostingLine.PostingLineCreditCC <> ?))      and	 
                ((t_sPostingLine.PostingLineDebitTC <> 0 and	 
                  t_sPostingLine.PostingLineDebitTC <> ?) or	 
                 (t_sPostingLine.PostingLineCreditTC <> 0 and	 
                  t_sPostingLine.PostingLineCreditTC <> ?))      and	 
                t_sPostingLine.PostingLineDebitTC <> t_sPostingLine.PostingLineCreditTC /* to avoid division by zero in the next assignment */	 
             then assign t_sPostingLine.PostingLineCCScale = 1	 
                         t_sPostingLine.PostingLineCCRate  = absolute((t_sPostingLine.PostingLineDebitCC - t_sPostingLine.PostingLineCreditCC) / (t_sPostingLine.PostingLineDebitTC - t_sPostingLine.PostingLineCreditTC)).	 
                         
             leave ASSIGNCCBLOCK. /* For external ones with type IC there should not be any recaultation of the CC-amounts */	 
 	 
         end. /* if t_sPosting.PostingOriginIsExternal = true  and */    
    
        /* ================================================================= */
        /* Skip the changed ones wherefor the TC-amount has not been changed */
        /* ================================================================= */
        if t_sPostingLine.tc_Status = "C":U and 
           not can-find (t_iPostingLine where 
                         t_iPostingLine.tc_Rowid = t_sPostingLine.tc_Rowid and 
                         (t_iPostingLine.PostingLineCreditTC <> t_sPostingLine.PostingLineCreditTC or 
                          t_iPostingLine.PostingLineDebitTC  <> t_sPostingLine.PostingLineDebitTC  or
                          t_iPostingLine.PostingLineCreditLC <> t_sPostingLine.PostingLineCreditLC or 
                          t_iPostingLine.PostingLineDebitLC  <> t_sPostingLine.PostingLineDebitLC))
        then leave ASSIGNCCBLOCK.

        /* ================================================================= */
        /* Skip the postings, which were created by Year-End closing         */
        /* Becuase of the various rounding errors, CC amount cannot be       */
        /* recalculated                                                      */
        /* ================================================================= */
        if t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-YEARLYCLOSING}
        then leave ASSIGNCCBLOCK.

        if t_sPostingLine.PostingLineDebitCC = ? and 
           t_sPostingLine.PostingLineDebitLC = 0 and 
           t_sPostingLine.PostingLineDebitTC = 0
        then assign t_sPostingLine.PostingLineDebitCC = 0.
        if t_sPostingLine.PostingLineCreditCC = ? and 
           t_sPostingLine.PostingLineCreditLC = 0 and 
           t_sPostingLine.PostingLineCreditTC = 0
        then assign t_sPostingLine.PostingLineCreditCC = 0.

        if  ((t_sPostingLine.PostingLineDebitTC  <> 0 and
              t_sPostingLine.PostingLineDebitTC  <> ?)    and
             (t_sPostingLine.PostingLineDebitCC   = 0 or
              t_sPostingLine.PostingLineDebitCC   = ?))      Or
            ((t_sPostingLine.PostingLineCreditTC  <> 0 and
              t_sPostingLine.PostingLineCreditTC  <> ?)   and
             (t_sPostingLine.PostingLineCreditCC   = 0 or
              t_sPostingLine.PostingLineCreditCC   = ?)) 
        then do :
            /*****CA707537*/  
            /* FIN-1865 */
            /* first check that the ccrates/scale are already defined, if so use those */
            /* if the TC and CC values are set, use those to calculate the rate */
            if blCurrencyFetched = false and 
               (t_sPostingLine.PostingLineCCRate <> 0 and t_sPostingLine.PostingLineCCRate <> ?)
            then assign bdCCExchangeRate      = t_sPostingLine.PostingLineCCRate
                        bdCCExchangeRateScale = t_sPostingLine.PostingLineCCScale
                        blCurrencyFetched     = true.   
            else assign bdCCExchangeRate      = 0
                        bdCCExchangeRateScale = 0
                        blCurrencyFetched     = false .              
                                     
            <M-7 run CalculateCCAmount
               (input  t_sPosting.Company_ID (iiCompanyID), 
                input  t_sPostingLine.PostingLineCreditLC (idPostingLineCreditLC), 
                input  t_sPostingLine.PostingLineCreditTC (idPostingLineCreditTC), 
                input  t_sPostingLine.PostingLineDebitLC (idPostingLineDebitLC), 
                input  t_sPostingLine.PostingLineDebitTC (idPostingLineDebitTC), 
                input  t_sPosting.PostingDate (itPostingDate), 
                input  t_sPostingLine.tcCurrencyCode (icCurrencyCode), 
                input  t_sPosting.PostingDate (itInvoiceExchangeRateDate), 
                input-output bdCCExchangeRate (bdCCExchangeRate), 
                input-output bdCCExchangeRateScale (bdCCExchangeRateScale), 
                input-output blCurrencyFetched (blCurrencyFetched), 
                output t_sPostingLine.PostingLineCreditCC (odPostingLineCreditCC), 
                output t_sPostingLine.PostingLineDebitCC (odPostingLineDebitCC), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
                
            assign t_sPostingLine.PostingLineCCRate = bdCCExchangeRate
                   t_sPostingLine.PostingLineCCScale= bdCCExchangeRateScale.
                   
            if viFcReturnSuper <> 0 and
               viLocalReturnStatus  >= 0
            then assign viLocalReturnStatus = viFcReturnSuper.                        
            if viFcReturnSuper < 0
            then leave ASSIGNCCBLOCK.
            
        end. /* if  ((t_sPostingLine.PostingLineDebitTC  <> 0 and */
        else 
            if ((t_sPostingLine.PostingLineDebitCC  <> 0 and t_sPostingLine.PostingLineDebitCC  <> ?) or
                (t_sPostingLine.PostingLineCreditCC <> 0 and t_sPostingLine.PostingLineCreditCC <> ?)) and
               ((t_sPostingLine.PostingLineDebitTC  <> 0 and t_sPostingLine.PostingLineDebitTC  <> ?) or 
                (t_sPostingLine.PostingLineCreditTC <> 0 and t_sPostingLine.PostingLineCreditTC <> ?)) and
               (blCurrencyFetched = false) 
            then do:
                /*  If CC & LC are set then calculate rate/scale using those values */
                assign bdCCExchangeRate         = t_sPostingLine.PostingLineCCRate
                       bdCCExchangeRateScale    = t_sPostingLine.PostingLineCCScale.
                if t_sPostingLine.PostingLineCCRate = 0 or 
                   t_sPostingLine.PostingLineCCRate = ?
                then do:                             
                   assign bdCCExchangeRate = ((if t_sPostingLine.PostingLineDebitCC  = ? then 0 else t_sPostingLine.PostingLineDebitCC) - 
                                              (if t_sPostingLine.PostingLineCreditCC = ? then 0 else t_sPostingLine.PostingLineCreditCC))  /
                                             ((if t_sPostingLine.PostingLineDebitTC  = ? then 0 else t_sPostingLine.PostingLineDebitTC) - 
                                              (if t_sPostingLine.PostingLineCreditTC = ? then 0 else t_sPostingLine.PostingLineCreditTC)) 
                                             no-error.
                    /* check the error status */
                    if error-status:error 
                    then do:
                        assign vcMsgExplanation = <M-83 GetErrorExplanation
                                                     (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                                      input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                                                      output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                                                   
                        assign vcMessage  = trim(substitute(#T-97'Error calculating exchange rate from SC and TC amounts':255(35986646)T-97#))  + chr(10) +
                                            trim(substitute(#T-37'TC Credit Amount in invoice: &1.':255(210144214)T-37#, trim(string(t_sPostingLine.PostingLineCreditTC)))) + chr(10) + 
                                            trim(substitute(#T-70'TC Debit Amount in invoice: &1.':255(602977159)T-70#, trim(string(t_sPostingLine.PostingLineDebitTC)))) + chr(10) + 
                                            trim(substitute(#T-90'BC Credit Amount in invoice: &1.':255(920191623)t-90#, trim(string(t_sPostingLine.PostingLineCreditCC)))) + chr(10) + 
                                            trim(substitute(#T-9'BC Debit Amount in invoice: &1.':255(956484826)t-9#, trim(string(t_sPostingLine.PostingLineDebitCC)))).                                        
                               viLocalReturnStatus = -1.
                        <M-315 run SetMessage
                           (input  vcMessage (icMessage), 
                            input  '':U (icArguments), 
                            input  't_sPostingLine.PostingLineCCRate':U (icFieldName), 
                            input  string(t_sPostingLine.PostingLineCCRate) (icFieldValue), 
                            input  'E':U (icType), 
                            input  3 (iiSeverity), 
                            input  '':U (icRowid), 
                            input  'qadfin-328907':U (icFcMsgNumber), 
                            input  vcMsgExplanation (icFcExplanation), 
                            input  '' (icFcIdentification), 
                            input  '' (icFcContext), 
                            output viFcReturnSuper (oiReturnStatus)) in BPosting>
                        leave ASSIGNCCBLOCK.
                    end.  /* if error-status:error */ 
                    assign blCurrencyFetched = true.
                end. /* if t_sPostingLine.PostingLineCCRate = 0 or  */
            end. /* if ((t_sPostingLine.PostingLineDebitCC  <> 0 and t_sPostingLine.PostingLineDebitCC  <> ?) or */
            
            /* ============================================================================= */
            /* Set the CC-Rate:                                                              */
            /* If there is not StatCurr then just use the TCLC rate                          */
            /* If not (TCAmts and CCAmts and CCRate is filled) then use the bdCCExchangeRate */
            /* ============================================================================= */
            if vlDomainIsStatutory = false
            then assign t_sPostingLine.PostingLineCCRate  = t_sPostingLine.PostingLineExchangeRate
                        t_sPostingLine.PostingLineCCScale = t_sPostingLine.PostingLineRateScale.
            else if NOT (t_sPostingLine.PostingLineCCRate  <> 0 and 
                         t_sPostingLine.PostingLineCCRate  <> ? and 
                         t_sPostingLine.PostingLineCCScale <> 0 and 
                         t_sPostingLine.PostingLineCCScale <> ? and 
                         ((t_sPostingLine.PostingLineDebitCC <> 0 and	 
                           t_sPostingLine.PostingLineDebitCC <> ?) or	 
                          (t_sPostingLine.PostingLineCreditCC <> 0 and	 
                           t_sPostingLine.PostingLineCreditCC <> ?)) and	 
                         ((t_sPostingLine.PostingLineDebitTC <> 0 and	 
                           t_sPostingLine.PostingLineDebitTC <> ?) or	 
                          (t_sPostingLine.PostingLineCreditTC <> 0 and	 
                           t_sPostingLine.PostingLineCreditTC <> ?))   )
                 then assign t_sPostingLine.PostingLineCCRate  = bdCCExchangeRate
                             t_sPostingLine.PostingLineCCScale = bdCCExchangeRateScale.
                
    end. /* Go through all undeleted postings */        
end. /* ASSIGNCCBLOCK */
  
/* ======================= */
/* Assign Redundant fields */
/* ======================= */
assign t_sPostingLine.Period_ID         = t_sPosting.Period_ID
       t_sPostingLine.PostingYearPeriod = t_sPosting.PostingYearPeriod
       t_sPostingLine.PostingDate       = t_sPosting.PostingDate.
if t_sPostingLine.Company_ID = 0 or
   t_sPostingLine.Company_ID = ?
then assign t_sPostingLine.Company_ID = t_sPosting.Company_ID.

if vlIsBCInvoiceNeeded              and
  (t_sPostingLine.tcGLCode  = ?     or
   t_sPostingLine.tcGLCode  = "":U) and
  (t_sPostingLine.tc_Status = "N":U or
   t_sPostingLine.tc_Status = "C":U)
then do:
    assign vcMsgExplanation = <M-50 GetErrorExplanation
                                 (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                  input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                                  output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
    <M-21 run SetMessage
       (input  trim(#T-84'GL Account is mandatory.':255(48280175)T-84#) (icMessage), 
        input  '':U (icArguments), 
        input  't_sPostingLine.tcGLCode':U (icFieldName), 
        input  string(t_sPostingLine.tcGLCode) (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'qadfin-633388':U (icFcMsgNumber), 
        input  vcMsgExplanation (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>
    assign oiReturnStatus = -1.
    return.
end.

/* ================================== */
/* Assign RKBF for GL for new records */
/* ================================== */
if t_sPostingLine.tc_Status = "N":U
then do:
    
        <Q-39 run GLForProfileLink (all) (Read) (Cache)
           (input t_sPosting.Company_ID, (CompanyId)
            input 0, (GLId)
            input '':U, (SharedSetCode)
            input t_sPostingLine.tcGLCode, (GLCode)
            output dataset tqGLForProfileLink) in BGL>
        
    find tqGLForProfileLink where
         tqGLForProfileLink.tcGLCode = t_sPostingLine.tcGLCode
         no-error.   
    if available tqGLForProfileLink
    then assign t_sPostingLine.tcGLDescription        = tqGLForProfileLink.tcGLDescription
                t_sPostingLine.tlGLIsAutomaticAccount = tqGLForProfileLink.tlGLIsAutomaticAccount
                t_sPostingLine.tlGLIsDebitAccount     = tqGLForProfileLink.tlGLIsDebitAccount
                t_sPostingLine.tcGLTypeCode           = tqGLForProfileLink.tcGLTypeCode
                t_sPostingLine.tcUnitCode             = tqGLForProfileLink.tcUnitCode.        
end. /* if t_sPostingLine.tc_Status = "N":U */   

/* ======================================================================== *
 * Update cross company link for the posting lines created from operational *
 * ======================================================================== */
<M-58 run ValidateComponentPreAssignPostingLineCross  (output viFcReturnSuper (oiReturnStatus)) in BPosting>
if viFcReturnSuper <> 0 and viLocalReturnStatus  >= 0 then assign viLocalReturnStatus = viFcReturnSuper.                        


/* ================================== */
/* Exception Handling                 */
/* ================================== */
assign oiReturnStatus = viLocalReturnStatus.