project QadFinancials > class BDInvoice > method ValidateComponentPreValidateVat

Description

This method is submethod of ValidateComponentPre.

This method fills some necessary fields on Debtor Invoice Vat records.


Parameters


blStartCurrencyPriminput-outputlogicalis query tqCurrencyPrim already started or not ?
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDInvoice.ValidateComponentPre


program code (program5/bdinvoice.p)

/* ======================================================================== */
/* IMPORTANT: This method is run from ValidateComponentPreValidate          */
/* The code in this method is nested within the for each t_sDInvoice        */
/* This can only work when both methods are defined in the same segment (5) */
/* ======================================================================== */

    if  t_sDInvoice.DInvoiceCurrency_ID = 0
    then do:
        if not blStartCurrencyPrim
        then do:
            <Q-26 run CurrencyPrim  (Start) in BCurrency >
            assign blStartCurrencyPrim = true.
        end.

        <Q-23 run CurrencyPrim (all) (Read) (NoCache)
           (input t_sDInvoice.tcCurrencyCode, (CurrencyCode)
            input ?, (Currency_ID)
            output dataset tqCurrencyPrim) in BCurrency >
        find first tqCurrencyPrim no-error.
        if not available tqCurrencyPrim
        then do:
            assign vcMessage = trim(substitute(#T-24'The currency (&1) of the customer invoice is not defined in the system.':255(69498)T-24#,t_sDInvoice.tcCurrencyCode)).
            <M-25 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-8122':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
                assign oiReturnStatus = -1.
                return.
        end.
    end.   
    
    
    /* control whether tax point date or posting date is used to calculate ALL amounts on a CUSTOMER invoice */     
    if vlCompanyPropertyIsARUseTaxDate
    then assign vtExchangeRateDate = t_sDInvoice.DInvoiceTaxPointDate.
    else assign vtExchangeRateDate = t_sDInvoice.DinvoicePostingDate.
             
    /* ============================================================== */
    /* give some db fields the right value based on calculated fields */
    /* ============================================================== */
    for each t_sDInvoiceVat where
             t_sDInvoiceVat.tc_ParentRowid = t_sDInvoice.tc_Rowid and
             t_sDInvoiceVat.tc_Status = "N":U:
        
        if t_sDInvoice.tcCurrencyCode = vcCompanyLC
        then assign t_sDInvoiceVat.DInvoiceVatVatBaseDebitLC  = t_sDInvoiceVat.DInvoiceVatVatBaseDebitTC
                    t_sDInvoiceVat.DInvoiceVatVatBaseCreditLC = t_sDInvoiceVat.DInvoiceVatVatBaseCreditTC
                    t_sDInvoiceVat.DInvoiceVatVatDebitLC      = t_sDInvoiceVat.DInvoiceVatVatDebitTC
                    t_sDInvoiceVat.DInvoiceVatVatCreditLC     = t_sDInvoiceVat.DInvoiceVatVatCreditTC.
        else do:
            if t_sDInvoice.DInvoicePostingDate <> ? and 
              (t_sDInvoice.DInvoiceExchangeRate = 0 or 
               t_sDInvoice.DInvoiceExchangeRate = ? or 
               t_sDInvoice.DInvoiceRateScale    = 0 or
               t_sDInvoice.DInvoiceRateScale    = ?) 
            then do:
                <M-38 run GetExchangeRate
                   (input  t_sDInvoice.Company_ID (iiCompanyID), 
                    input  t_sDInvoice.DInvoiceCurrency_ID (iiFromCurrencyID), 
                    input  (if t_sDInvoice.DInvoiceCurrency_ID = 0 then t_sDInvoice.tcCurrencyCode else '':U) (icFromCurrencyCode), 
                    input  viCompanyLCId (iiToCurrencyID), 
                    input  ? (icToCurrencyCode), 
                    input  ? (iiExchangeRateTypeID), 
                    input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode), 
                    input  vtExchangeRateDate (itValidityDate), 
                    output vdDInvoiceExchangeRate (odExchangeRate), 
                    output vdDInvoiceExchangeRateScale (odExchangeScaleFactor), 
                    output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
                if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
                then assign oiReturnStatus = viFcReturnSuper.
            end.
            else assign vdDInvoiceExchangeRate      = t_sDInvoice.DInvoiceExchangeRate
                        vdDInvoiceExchangeRateScale = t_sDInvoice.DInvoiceRateScale.
            assign t_sDInvoiceVat.DInvoiceVatVatBaseDebitLC  = if (t_sDInvoiceVat.DInvoiceVatVatBaseDebitLC = 0 or
                                                                   t_sDInvoiceVat.DInvoiceVatVatBaseDebitLC = ?)
                                                               then <M-5 RoundAmount
                                                                       (input  t_sDInvoiceVat.DInvoiceVatVatBaseDebitTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                                        input  viCompanyLCId (iiCurrencyID), 
                                                                        input  vcCompanyLC (icCurrencyCode)) in business>
                                                               else t_sDInvoiceVat.DInvoiceVatVatBaseDebitLC
                   t_sDInvoiceVat.DInvoiceVatVatBaseCreditLC = if (t_sDInvoiceVat.DInvoiceVatVatBaseCreditLC = 0 or
                                                                   t_sDInvoiceVat.DInvoiceVatVatBaseCreditLC = ?)
                                                               then <M-6 RoundAmount
                                                                       (input  t_sDInvoiceVat.DInvoiceVatVatBaseCreditTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                                        input  viCompanyLCId (iiCurrencyID), 
                                                                        input  vcCompanyLC (icCurrencyCode)) in business>
                                                               else t_sDInvoiceVat.DInvoiceVatVatBaseCreditLC
                   t_sDInvoiceVat.DInvoiceVatVatDebitLC      = if (t_sDInvoiceVat.DInvoiceVatVatDebitLC = 0 or
                                                                   t_sDInvoiceVat.DInvoiceVatVatDebitLC = ?)
                                                               then <M-7 RoundAmount
                                                                       (input  t_sDInvoiceVat.DInvoiceVatVatDebitTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                                        input  viCompanyLCId (iiCurrencyID), 
                                                                        input  vcCompanyLC (icCurrencyCode)) in business>
                                                               else t_sDInvoiceVat.DInvoiceVatVatDebitLC
                   t_sDInvoiceVat.DInvoiceVatVatCreditLC     = if (t_sDInvoiceVat.DInvoiceVatVatCreditLC = 0 or
                                                                   t_sDInvoiceVat.DInvoiceVatVatCreditLC = ?)
                                                               then <M-8 RoundAmount
                                                                       (input  t_sDInvoiceVat.DInvoiceVatVatCreditTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                                        input  viCompanyLCId (iiCurrencyID), 
                                                                        input  vcCompanyLC (icCurrencyCode)) in business>
                                                               else t_sDInvoiceVat.DInvoiceVatVatCreditLC.            
        end.

        /* ================= */
        /* update cc amounts */
        /* ================= */
        if viCompanyCCId <> 0 and viCompanyCCId <> ?
        then do:                  
            if t_sDInvoice.tcCurrencyCode = vcCompanyCC
            then assign t_sDInvoiceVat.DInvoiceVatVatBaseDebitCC  = t_sDInvoiceVat.DInvoiceVatVatBaseDebitTC
                        t_sDInvoiceVat.DInvoiceVatVatBaseCreditCC = t_sDInvoiceVat.DInvoiceVatVatBaseCreditTC
                        t_sDInvoiceVat.DInvoiceVatVatDebitCC      = t_sDInvoiceVat.DInvoiceVatVatDebitTC
                        t_sDInvoiceVat.DInvoiceVatVatCreditCC     = t_sDInvoiceVat.DInvoiceVatVatCreditTC.
            else if vlDomainIsStatutory = false
            then assign t_sDInvoiceVat.DInvoiceVatVatBaseDebitCC  = t_sDInvoiceVat.DInvoiceVatVatBaseDebitLC
                        t_sDInvoiceVat.DInvoiceVatVatBaseCreditCC = t_sDInvoiceVat.DInvoiceVatVatBaseCreditLC
                        t_sDInvoiceVat.DInvoiceVatVatDebitCC      = t_sDInvoiceVat.DInvoiceVatVatDebitLC
                        t_sDInvoiceVat.DInvoiceVatVatCreditCC     = t_sDInvoiceVat.DInvoiceVatVatCreditLC.
            else do:
                if t_sDInvoice.DInvoicePostingDate <> ?
                then do:
                    if t_sDInvoice.DInvoiceCCRate  <> 0 and t_sDInvoice.DInvoiceCCRate  <> ? and
                       t_sDInvoice.DInvoiceCCScale <> 0 and t_sDInvoice.DInvoiceCCScale <> ?
                    then assign vdDInvoiceExchangeRate      = t_sDInvoice.DInvoiceCCRate
                                vdDInvoiceExchangeRateScale = t_sDInvoice.DInvoiceCCScale.
                    else do:
                        <M-87 run GetExchangeRate
                           (input  t_sDInvoice.Company_ID (iiCompanyID), 
                            input  ? (iiFromCurrencyID), 
                            input  t_sDInvoice.tcCurrencyCode (icFromCurrencyCode), 
                            input  viCompanyCCId (iiToCurrencyID), 
                            input  ? (icToCurrencyCode), 
                            input  ? (iiExchangeRateTypeID), 
                            input  {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode), 
                            input  vtExchangeRateDate (itValidityDate), 
                            output vdDInvoiceExchangeRate (odExchangeRate), 
                            output vdDInvoiceExchangeRateScale (odExchangeScaleFactor), 
                            output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
                        if viFcReturnSuper < 0 or 
                          (viFcReturnSuper > 0 and 
                           oiReturnStatus = 0)
                        then assign oiReturnStatus = viFcReturnSuper.  
                        
                        <M-78 run CheckExternalInvoiceCC
                           (input  t_sDInvoice.tc_Rowid (icInvoiceRowid), 
                            input-output vdDInvoiceExchangeRate (bdExchangeRate), 
                            input-output vdDInvoiceExchangeRateScale (bdRateScale), 
                            output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
                            
                        if viFcReturnSuper < 0 or 
                          (viFcReturnSuper > 0 and 
                           oiReturnStatus = 0)
                        then assign oiReturnStatus = viFcReturnSuper. 
                    end. /* else if t_sDInvoice.DInvoiceCCRate  <> 0 and t_sDInvoice.DInvoiceCCRate  <> ? and */

                      
                    assign t_sDInvoiceVat.DInvoiceVatVatBaseDebitCC  = if (t_sDInvoiceVat.DInvoiceVatVatBaseDebitCC = 0 or
                                                                           t_sDInvoiceVat.DInvoiceVatVatBaseDebitCC = ?)
                                                                       then <M-9 RoundAmount
                                                                               (input  t_sDInvoiceVat.DInvoiceVatVatBaseDebitTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                                                input  viCompanyCCId (iiCurrencyID), 
                                                                                input  vcCompanyCC (icCurrencyCode)) in business>
                                                                       else t_sDInvoiceVat.DInvoiceVatVatBaseDebitCC
                           t_sDInvoiceVat.DInvoiceVatVatBaseCreditCC = if (t_sDInvoiceVat.DInvoiceVatVatBaseCreditCC = 0 or
                                                                           t_sDInvoiceVat.DInvoiceVatVatBaseCreditCC = ?)
                                                                       then <M-10 RoundAmount
                                                                               (input  t_sDInvoiceVat.DInvoiceVatVatBaseCreditTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                                                input  viCompanyCCId (iiCurrencyID), 
                                                                                input  vcCompanyCC (icCurrencyCode)) in business>
                                                                       else t_sDInvoiceVat.DInvoiceVatVatBaseCreditCC
                           t_sDInvoiceVat.DInvoiceVatVatDebitCC      = if (t_sDInvoiceVat.DInvoiceVatVatDebitCC = 0 or
                                                                           t_sDInvoiceVat.DInvoiceVatVatDebitCC = ?)
                                                                       then <M-11 RoundAmount
                                                                               (input  t_sDInvoiceVat.DInvoiceVatVatDebitTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                                                input  viCompanyCCId (iiCurrencyID), 
                                                                                input  vcCompanyCC (icCurrencyCode)) in business>
                                                                       else t_sDInvoiceVat.DInvoiceVatVatDebitCC
                           t_sDInvoiceVat.DInvoiceVatVatCreditCC     = if (t_sDInvoiceVat.DInvoiceVatVatCreditCC = 0 or
                                                                           t_sDInvoiceVat.DInvoiceVatVatCreditCC = ?)
                                                                       then <M-12 RoundAmount
                                                                               (input  t_sDInvoiceVat.DInvoiceVatVatCreditTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                                                input  viCompanyCCId (iiCurrencyID), 
                                                                                input  vcCompanyCC (icCurrencyCode)) in business>
                                                                       else t_sDInvoiceVat.DInvoiceVatVatCreditCC.
                end.
            end.
        end.
    end. 

    /* give the total fields the right value */
if t_sDInvoice.tc_Status = 'N':U or
   t_sDInvoice.tc_Status = 'C':U
then do:
    for each t_sDInvoiceVat where
             t_sDInvoiceVat.tc_ParentRowid  = t_sDInvoice.tc_Rowid and
             t_sDInvoiceVat.tc_Status      <> "D":U :
         if t_sDInvoiceVat.DInvoiceVatSequence = 1
         then do:
             accumulate t_sDInvoiceVat.DInvoiceVatVatBaseDebitTC (TOTAL).
             accumulate t_sDInvoiceVat.DInvoiceVatVatBaseCreditTC (TOTAL).
             
         end.

         accumulate t_sDInvoiceVat.DInvoiceVatVatDebitTC (TOTAL).
         accumulate t_sDInvoiceVat.DInvoiceVatVatCreditTC (TOTAL).
         accumulate t_sDInvoiceVat.DInvoiceVatVatDebitLC (TOTAL).
         accumulate t_sDInvoiceVat.DInvoiceVatVatCreditLC (TOTAL).
         
    end.
   

  
    if t_sDInvoice.DInvoiceIsTaxExcluded = false
    then assign t_sDInvoice.DInvoiceVatBaseDebitTC   = accum total t_sDInvoiceVat.DInvoiceVatVatBaseDebitTC
                t_sDInvoice.DInvoiceVatBaseCreditTC  = accum total t_sDInvoiceVat.DInvoiceVatVatBaseCreditTC.
    else assign t_sDInvoice.DInvoiceOriginalCreditTC = if t_sDInvoice.DInvoiceType = {&INVOICETYPE-INVOICE} or t_sDInvoice.DInvoiceType = {&INVOICETYPE-FINANCECHARGE} or t_sDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                                                       then 0
                                                       else t_sDInvoice.tdDInvoiceOriginalTC + (accum total t_sDInvoiceVat.DInvoiceVatVatDebitTC) - (accum total t_sDInvoiceVat.DInvoiceVatVatCreditTC)
                t_sDInvoice.DInvoiceOriginalDebitTC  = if t_sDInvoice.DInvoiceType = {&INVOICETYPE-INVOICE} or t_sDInvoice.DInvoiceType = {&INVOICETYPE-FINANCECHARGE} or t_sDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                                                       then t_sDInvoice.tdDInvoiceOriginalTC + (accum total t_sDInvoiceVat.DInvoiceVatVatCreditTC) - (accum total t_sDInvoiceVat.DInvoiceVatVatDebitTC)
                                                       else 0
                t_sDInvoice.DInvoiceOriginalCreditLC =<M-79 RoundAmount
                                                                                    (input  t_sDInvoice.DInvoiceOriginalCreditTC * t_sDinvoice.DInvoiceExchangeRate * t_sDinvoice.DInvoiceRateScale (idUnroundedAmount), 
                                                                                     input  viCompanyLCId (iiCurrencyID), 
                                                                                     input  vcCompanyLC (icCurrencyCode)) in BDInvoice>
                
                t_sDInvoice.DInvoiceOriginalDebitLC  = <M-86 RoundAmount
                                                                                      (input  t_sDInvoice.DInvoiceOriginalDebitTC * t_sDinvoice.DInvoiceExchangeRate * t_sDinvoice.DInvoiceRateScale (idUnroundedAmount), 
                                                                                       input  viCompanyLCId (iiCurrencyID), 
                                                                                       input  vcCompanyLc (icCurrencyCode)) in BDInvoice> .
                                                                          
                        

    assign t_sDInvoice.DInvoiceVatDebitTC      = accum total t_sDInvoiceVat.DInvoiceVatVatDebitTC
           t_sDInvoice.DInvoiceVatCreditTC     = accum total t_sDInvoiceVat.DInvoiceVatVatCreditTC.

    if t_sDInvoice.tcCurrencyCode = vcCompanyLC
    then assign t_sDInvoice.DInvoiceVatBaseDebitLC  = t_sDInvoice.DInvoiceVatBaseDebitTC
                t_sDInvoice.DInvoiceVatBaseCreditLC = t_sDInvoice.DInvoiceVatBaseCreditTC
                t_sDInvoice.DInvoiceVatDebitLC      = t_sDInvoice.DInvoiceVatDebitTC
                t_sDInvoice.DInvoiceVatCreditLC     = t_sDInvoice.DInvoiceVatCreditTC.
    else do:
        if t_sDInvoice.DInvoiceDate <> ? and 
           (t_sDInvoice.DInvoiceExchangeRate = 0 or 
            t_sDInvoice.DInvoiceExchangeRate = ? or 
            t_sDInvoice.DInvoiceRateScale    = 0 or
            t_sDInvoice.DInvoiceRateScale    = ?) 
        then do :
            <M-88 run GetExchangeRate
               (input  t_sDInvoice.Company_ID (iiCompanyID), 
                input  t_sDInvoice.DInvoiceCurrency_ID (iiFromCurrencyID), 
                input  (if t_sDInvoice.DInvoiceCurrency_ID = 0 then t_sDInvoice.tcCurrencyCode else '':U) (icFromCurrencyCode), 
                input  viCompanyLCId (iiToCurrencyID), 
                input  ? (icToCurrencyCode), 
                input  ? (iiExchangeRateTypeID), 
                input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode), 
                input  vtExchangeRateDate (itValidityDate), 
                output vdDInvoiceExchangeRate (odExchangeRate), 
                output vdDInvoiceExchangeRateScale (odExchangeScaleFactor), 
                output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
            then assign oiReturnStatus = viFcReturnSuper.
        end. /* if t_sDInvoice.DInvoiceDate <> ? */
        else assign vdDInvoiceExchangeRate      = t_sDInvoice.DInvoiceExchangeRate
                    vdDInvoiceExchangeRateScale = t_sDInvoice.DInvoiceRateScale.
        assign t_sDInvoice.DInvoiceVatBaseDebitLC  = <M-13 RoundAmount
                                                        (input  t_sDInvoice.DInvoiceVatBaseDebitTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                         input  viCompanyLCId (iiCurrencyID), 
                                                         input  vcCompanyLC (icCurrencyCode)) in business>
               t_sDInvoice.DInvoiceVatBaseCreditLC = <M-14 RoundAmount
                                                        (input  t_sDInvoice.DInvoiceVatBaseCreditTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                         input  viCompanyLCId (iiCurrencyID), 
                                                         input  vcCompanyLC (icCurrencyCode)) in business>
               t_sDInvoice.DInvoiceVatDebitLC      = <M-15 RoundAmount
                                                        (input  t_sDInvoice.DInvoiceVatDebitTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                         input  viCompanyLCId (iiCurrencyID), 
                                                         input  vcCompanyLC (icCurrencyCode)) in business>
               t_sDInvoice.DInvoiceVatCreditLC     = <M-16 RoundAmount
                                                        (input  t_sDInvoice.DInvoiceVatCreditTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                         input  viCompanyLCId (iiCurrencyID), 
                                                         input  vcCompanyLC (icCurrencyCode)) in business>.
    end. /* Not if t_sDInvoice.tcCurrencyCode = vcCompanyLC */

    /* ================= */
    /* update cc amounts */
    /* ================= */
    if viCompanyCCId <> 0 and viCompanyCCId <> ?
    then do:
        if t_sDInvoice.tcCurrencyCode = vcCompanyCC
        then assign t_sDInvoice.DInvoiceVatBaseDebitCC   = t_sDInvoice.DInvoiceVatBaseDebitTC
                    t_sDInvoice.DInvoiceVatBaseCreditCC  = t_sDInvoice.DInvoiceVatBaseCreditTC
                    t_sDInvoice.DInvoiceVatDebitCC       = t_sDInvoice.DInvoiceVatDebitTC
                    t_sDInvoice.DInvoiceVatCreditCC      = t_sDInvoice.DInvoiceVatCreditTC
                    t_sDInvoice.DInvoiceOriginalDebitCC  = t_sDInvoice.DInvoiceOriginalDebitTC
                    t_sDInvoice.DInvoiceOriginalCreditCC = t_sDInvoice.DInvoiceOriginalCreditTC.
        else if vlDomainIsStatutory = false
        then assign t_sDInvoice.DInvoiceVatBaseDebitCC   = t_sDInvoice.DInvoiceVatBaseDebitLC
                    t_sDInvoice.DInvoiceVatBaseCreditCC  = t_sDInvoice.DInvoiceVatBaseCreditLC
                    t_sDInvoice.DInvoiceVatDebitCC       = t_sDInvoice.DInvoiceVatDebitLC
                    t_sDInvoice.DInvoiceVatCreditCC      = t_sDInvoice.DInvoiceVatCreditLC
                    t_sDInvoice.DInvoiceOriginalDebitCC  = t_sDInvoice.DInvoiceOriginalDebitLC
                    t_sDInvoice.DInvoiceOriginalCreditCC = t_sDInvoice.DInvoiceOriginalCreditLC.        
        else do:
            if t_sDInvoice.DInvoiceDate <> ?
            then do :
                if t_sDInvoice.DInvoiceCCRate  <> 0 and t_sDInvoice.DInvoiceCCRate  <> ? and
                   t_sDInvoice.DInvoiceCCScale <> 0 and t_sDInvoice.DInvoiceCCScale <> ?
                then assign vdDInvoiceExchangeRate      = t_sDInvoice.DInvoiceCCRate
                            vdDInvoiceExchangeRateScale = t_sDInvoice.DInvoiceCCScale.
                else do:
                    <M-91 run GetExchangeRate
                       (input  t_sDInvoice.Company_ID (iiCompanyID), 
                        input  ? (iiFromCurrencyID), 
                        input  t_sDInvoice.tcCurrencyCode (icFromCurrencyCode), 
                        input  viCompanyCCID (iiToCurrencyID), 
                        input  ? (icToCurrencyCode), 
                        input  ? (iiExchangeRateTypeID), 
                        input  {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode), 
                        input  vtExchangeRateDate (itValidityDate), 
                        output vdDInvoiceExchangeRate (odExchangeRate), 
                        output vdDInvoiceExchangeRateScale (odExchangeScaleFactor), 
                        output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
                    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
                    then assign oiReturnStatus = viFcReturnSuper.    
                    
                   /* value of vdDInvoiceExchangeRate is set to the value entered by the user while
                    coming from customer opening balance create */
                   /* APIGetExchangeRate gets the exchange rate default exchange rate and not the rate entered by the user */
                    if (t_sDInvoice.DInvoiceCCRate = 0 or t_sDInvoice.DInvoiceCCRate = ?) and
                       (t_sDInvoice.DInvoiceOriginalDebitCC <> 0 and t_sDInvoice.DInvoiceOriginalDebitCC <> ?)
                    then assign vdDInvoiceExchangeRate      = absolute(round((t_sDInvoice.DInvoiceOriginalDebitCC - 
                                                                              t_sDInvoice.DInvoiceOriginalCreditCC) / 
                                                                             (t_sDInvoice.DInvoiceOriginalDebitTC - t_sDInvoice.DInvoiceOriginalCreditTC), 10))
                                vdDInvoiceExchangeRateScale = 1.
                                                    
                    <M-20 run CheckExternalInvoiceCC
                       (input  t_sDInvoice.tc_Rowid (icInvoiceRowid), 
                        input-output vdDInvoiceExchangeRate (bdExchangeRate), 
                        input-output vdDInvoiceExchangeRateScale (bdRateScale), 
                        output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
                        
                    if viFcReturnSuper < 0 or 
                      (viFcReturnSuper > 0 and 
                       oiReturnStatus = 0)
                    then assign oiReturnStatus = viFcReturnSuper. 
                end. /* if t_sDInvoice.DInvoiceCCRate  <> 0 and t_sDInvoice.DInvoiceCCRate  <> ? and */
                
                assign t_sDInvoice.DInvoiceVatBaseDebitCC   =  <M-28 RoundAmount
                                                                  (input  t_sDInvoice.DInvoiceVatBaseDebitTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                                   input  viCompanyCCId (iiCurrencyID), 
                                                                   input  vcCompanyCC (icCurrencyCode)) in business>
                       t_sDInvoice.DInvoiceVatBaseCreditCC  = <M-29 RoundAmount
                                                                 (input  t_sDInvoice.DInvoiceVatBaseCreditTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                                  input  viCompanyCCId (iiCurrencyID), 
                                                                  input  vcCompanyCC (icCurrencyCode)) in business>
                       t_sDInvoice.DInvoiceVatDebitCC       =  <M-30 RoundAmount
                                                                  (input  t_sDInvoice.DInvoiceVatDebitTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                                   input  viCompanyCCId (iiCurrencyID), 
                                                                   input  vcCompanyCC (icCurrencyCode)) in business>
                       t_sDInvoice.DInvoiceVatCreditCC      =  <M-31 RoundAmount
                                                                  (input  t_sDInvoice.DInvoiceVatCreditTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                                   input  viCompanyCCId (iiCurrencyID), 
                                                                   input  vcCompanyCC (icCurrencyCode)) in business>
                   

                       t_sDInvoice.DInvoiceOriginalDebitCC  =    <M-32 RoundAmount
                                                                    (input   t_sDInvoice.DInvoiceOriginalDebitTC * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                                     input  viCompanyCCId (iiCurrencyID), 
                                                                     input  vcCompanyCC (icCurrencyCode)) in business>
                       t_sDInvoice.DInvoiceOriginalCreditCC = <M-33 RoundAmount
                                                                 (input  t_sDInvoice.DInvoiceOriginalCreditT * vdDInvoiceExchangeRate * vdDInvoiceExchangeRateScale (idUnroundedAmount), 
                                                                  input  viCompanyCCId (iiCurrencyID), 
                                                                  input  vcCompanyCC (icCurrencyCode)) in business>.
            end.
        end.
    end.
end.