project QadFinancials > class BCInvoice > method AdditionalUpdatesAllCreateCAVal

Description

submethod of AdditionalUpdatesAllCreateCA : this method will check if the exchange rates of the original invoice and linked invoice are the same and some other validations


Parameters


olSwitchDebitCreditoutputlogicalThis parameter indicates if the compensating posting lines should switch the debit and the credit.
If false then the debit will remain the debit (and credit will remain credit) but the values will be multiplies with -1.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.AdditionalUpdatesAllCreateCA


program code (program8/bcinvoice.p)

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

/* =========== */
/* Start Block */
/* =========== */
VALBLOCK: DO:
    
    /* =========================================================== */
    /* Go though all invoices that hold a link, are new or changed */
    /* =========================================================== */
    for each tCInvoice where
             tCInvoice.LinkedCInvoice_ID <> 0                         and 
             tCInvoice.LinkedCInvoice_ID <> ?                         and
             (tCInvoice.tc_Status = "N":U  or
              tCInvoice.tc_Status = "C":U)                            and
             (tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICE}            or
              tCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTE}         or
              tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICECORRECTION}  or
              tCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}) :
        
        /* ======================= */
        /* Read the linked invoice */
        /* ======================= */
        if tCInvoice.tc_Status = 'C':U
        then do :
            find first t_iCInvoice where
                       t_iCInvoice.tc_Rowid = tCInvoice.tc_Rowid
                       no-error.
            if not available t_iCInvoice
            then next.
        end.

        /* ======================= */
        /* Read the linked invoice */
        /* ======================= */
        <Q-2 run CInvoiceByIDForCA (all) (Read) (NoCache)
           (input ?, (CompanyId)
            input tCInvoice.LinkedCInvoice_ID, (CInvoiceID)
            output dataset tqCInvoiceByIDForCA) in BCInvoice>
        find first tqCInvoiceByIDForCA where
                   tqCInvoiceByIDForCA.tiCInvoice_ID = tCInvoice.LinkedCInvoice_ID
                   no-error.
        if not available tqCInvoiceByIDForCA
        then do:
            assign vcMessage            = trim(#T-3'The system encountered an error when retrieving the linked invoice.':255(65735)T-3#)
                   viLocalReturnStatus  = -1.
             <M-4 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-9764':U (icFcMsgNumber), 
                 input  '':U (icFcExplanation), 
                 input  '':U (icFcIdentification), 
                 input  '':U (icFcContext), 
                 output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
             leave VALBLOCK.
        end. /* if not available tqCInvoiceByIDForCA */
        
        /* ============================================================= */
        /* 1- Make sure the exchange-rates of both invoices are the same */
        /* ============================================================= */
        if (tCInvoice.tc_Status = 'N':U) or
           (tCInvoice.tc_Status = 'C':U and
            (tCInvoice.CInvoiceExchangeRate <> t_iCInvoice.CInvoiceExchangeRate or
             tCInvoice.CInvoiceRateScale    <> t_iCInvoice.CInvoiceRateScale or
             tCInvoice.CInvoiceCCRate       <> t_iCInvoice.CInvoiceCCRate or
             tCInvoice.CInvoiceCCScale      <> t_iCInvoice.CInvoiceCCScale))
        then do:
            if tCInvoice.CInvoiceExchangeRate <> tqCInvoiceByIDForCA.tdCInvoiceExchangeRate  or
               tCInvoice.CInvoiceRateScale    <> tqCInvoiceByIDForCA.tdCInvoiceRateScale     or
               tCInvoice.CInvoiceCCRate       <> tqCInvoiceByIDForCA.tdCInvoiceCCRate        or
               tCInvoice.CInvoiceCCScale      <> tqCInvoiceByIDForCA.tdCInvoiceCCScale
            then do:

                /* to make sure that the translatable value of the invoice type is shown */
                assign vcPreprocessorInvoiceTypes = {&INVOICETYPES}.
                do viCounter = num-entries(vcPreprocessorInvoiceTypes,chr(2)) to 1 by -2 :
                    if entry(viCounter,vcPreprocessorInvoiceTypes,chr(2)) = tCInvoice.CInvoiceType
                    then assign vcCInvoiceTypeTrans = entry(viCounter - 1,vcPreprocessorInvoiceTypes,chr(2)) no-error.
                    if entry(viCounter,vcPreprocessorInvoiceTypes,chr(2)) = tqCInvoiceByIDForCA.tcCInvoiceType
                    then assign vcLinkedCInvoiceTypeTrans = entry(viCounter - 1,vcPreprocessorInvoiceTypes,chr(2)) no-error.
                    if vcCInvoiceTypeTrans       <> "":U and 
                       vcCInvoiceTypeTrans       <> ?    and 
                       vcLinkedCInvoiceTypeTrans <> "":U and 
                       vcLinkedCInvoiceTypeTrans <> ?
                    then Leave.
                end. /* do viCounter = num-entries */   
                assign vcMessage            = trim(substitute(#T-5'The exchange-rates on the &1 (&2) should match the exchange-rates on the linked &3 (&4).':255(617126916)T-5#,
                                                              vcCInvoiceTypeTrans, 
                                                              string(tCInvoice.CInvoicePostingYear) + "/":U + tCInvoice.tcJournalCode + "/":U + string(tCInvoice.CInvoiceVoucher), 
                                                              vcLinkedCInvoiceTypeTrans, 
                                                              string(tqCInvoiceByIDForCA.tiCInvoicePostingYear) + "/":U + tqCInvoiceByIDForCA.tcJournalCode + "/":U + string(tqCInvoiceByIDForCA.tiCInvoiceVoucher))) + chr(10) + 
                                              trim(substitute(#T-6'Base-Currency rate of the &1 : &2, &3':255(413957962)T-6#, vcCInvoiceTypeTrans, tCInvoice.CInvoiceExchangeRate, tCInvoice.CInvoiceRateScale)) + chr(10) + 
                                              trim(substitute(#T-7'Base-Currency rate of the &1 : &2, &3':255(413957962)T-7#, vcLinkedCInvoiceTypeTrans, tqCInvoiceByIDForCA.tdCInvoiceExchangeRate, tqCInvoiceByIDForCA.tdCInvoiceRateScale)) + chr(10) + 
                                              trim(substitute(#T-8'Statutory-Currency rate of the &1 : &2, &3':255(591281008)T-8#, vcCInvoiceTypeTrans, tCInvoice.CInvoiceCCRate, tCInvoice.CInvoiceCCScale)) + chr(10) + 
                                              trim(substitute(#T-9'Statutory-Currency rate of the &1 : &2, &3':255(591281008)T-9#, vcLinkedCInvoiceTypeTrans, tqCInvoiceByIDForCA.tdCInvoiceCCRate, tqCInvoiceByIDForCA.tdCInvoiceCCScale))
                       viLocalReturnStatus  = -1.
                <M-10 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-9765':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
                 leave VALBLOCK.

            end. /* if tCInvoice.CInvoiceExchangeRate <> tqCInvoiceByIDForCA.tdCInvoiceExchangeRate  or */

        end.  /* if */

        /* ================================================================================================ */
        /* 2- Make sure the WHT percentage of the CInvoice and the WHT percentage of the LinkedCInvoice are */
        /* are the same as otherwise the CA-posting becomes unbalanced.                                     */
        /* So you can have a CInvoice of 100 with 10 WHT linked to a CInvoice of 5000 with 500 WHT but      */
        /* you cannot have a CInvoice of 100 with 10 WHT linked to a CInvoice of 5000 with 100 WHT          */
        /* Note that we allow a margin of 1 % as this can be cause by our dividing to get a percentage      */
        /* ================================================================================================ */
        if (tCInvoice.tc_Status = 'N':U) or
           (tCInvoice.tc_Status = 'C':U and
            (tCInvoice.CInvoiceWHTTotAmtDebitTC  <> t_iCInvoice.CInvoiceWHTTotAmtDebitTC or
             tCInvoice.CInvoiceWHTTotAmtCreditTC <> t_iCInvoice.CInvoiceWHTTotAmtCreditTC or
             tCInvoice.CInvoiceOriginalDebitTC   <> t_iCInvoice.CInvoiceOriginalDebitTC or
             tCInvoice.CInvoiceOriginalCreditTC  <> t_iCInvoice.CInvoiceOriginalCreditTC))
        then do:

            assign vdCInvoiceWHTPercentage       = Absolute(tCInvoice.CInvoiceWHTTotAmtDebitTC - tCInvoice.CInvoiceWHTTotAmtCreditTC) / 
                                                   Absolute(tCInvoice.CInvoiceOriginalDebitTC - tCInvoice.CInvoiceOriginalCreditTC)
                   vdLinkedCInvoiceWHTPercentage = Absolute(tqCInvoiceByIDForCA.tdCInvoiceWHTTotAmtDebitTC - tqCInvoiceByIDForCA.tdCInvoiceWHTTotAmtCreditTC) / 
                                                   Absolute(tqCInvoiceByIDForCA.tdCInvoiceOriginalDebitTC - tqCInvoiceByIDForCA.tdCInvoiceOriginalCreditTC).

            if vdCInvoiceWHTPercentage < vdLinkedCInvoiceWHTPercentage * 0.99 Or
               vdCInvoiceWHTPercentage > vdLinkedCInvoiceWHTPercentage * 1.01
            then do :
                /* to make sure that the translatable value of the invoice type is shown */
                if vcCInvoiceTypeTrans       = "":U or
                   vcCInvoiceTypeTrans       = ?    or 
                   vcLinkedCInvoiceTypeTrans = "":U or 
                   vcLinkedCInvoiceTypeTrans = ?
                then do :
                    assign vcPreprocessorInvoiceTypes = {&INVOICETYPES}.
                    do viCounter = num-entries(vcPreprocessorInvoiceTypes,chr(2)) to 1 by -2 :

                        if entry(viCounter,vcPreprocessorInvoiceTypes,chr(2)) = tCInvoice.CInvoiceType
                        then assign vcCInvoiceTypeTrans = entry(viCounter - 1,vcPreprocessorInvoiceTypes,chr(2)) no-error.

                        if entry(viCounter,vcPreprocessorInvoiceTypes,chr(2)) = tqCInvoiceByIDForCA.tcCInvoiceType
                        then assign vcLinkedCInvoiceTypeTrans = entry(viCounter - 1,vcPreprocessorInvoiceTypes,chr(2)) no-error.

                        if vcCInvoiceTypeTrans       <> "":U and 
                           vcCInvoiceTypeTrans       <> ?    and 
                           vcLinkedCInvoiceTypeTrans <> "":U and 
                           vcLinkedCInvoiceTypeTrans <> ?
                        then Leave.

                    end. /* do viCounter = num-entries */ 

                end. /* if vcCInvoiceTypeTrans       = "":U or */  

                assign vcMessage            = trim(substitute(#T-28'The WHT-percentage on the &1 (&2) should match the WHT-percentage on the linked &3 (&4).':255(68992322)T-28#,
                                                              vcCInvoiceTypeTrans, 
                                                              string(tCInvoice.CInvoicePostingYear) + "/":U + tCInvoice.tcJournalCode + "/":U + string(tCInvoice.CInvoiceVoucher), 
                                                              vcLinkedCInvoiceTypeTrans, 
                                                              string(tqCInvoiceByIDForCA.tiCInvoicePostingYear) + "/":U + tqCInvoiceByIDForCA.tcJournalCode + "/":U + string(tqCInvoiceByIDForCA.tiCInvoiceVoucher))) + chr(10) + 
                                              trim(substitute(#T-42'WHT-percentage of the &1 : &2':255(961488532)T-42#, vcCInvoiceTypeTrans, vdCInvoiceWHTPercentage * 100)) + chr(10) + 
                                              trim(substitute(#T-36'WHT-percentage of the &1 : &2':255(163406922)T-36#, vcLinkedCInvoiceTypeTrans, vdLinkedCInvoiceWHTPercentage * 100))
                       viLocalReturnStatus  = -1.

                <M-69 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-609557':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>

                 leave VALBLOCK.

            end. /* if vdCInvoiceWHTPercentage < vdLinkedCInvoiceWHTPercentage * 0.99 Or */

        end. /* if */

        /* ============================================================================================= */
        /* 3- Verify if the type of the invoice and type of the linked invoice make a valid combination  */
        /* ============================================================================================= */
        if (tCInvoice.tc_Status = 'N':U) or
           (tCInvoice.tc_Status = 'C':U and tCInvoice.Cinvoicetype <> t_iCInvoice.CInvoiceType)
        then do:    
            assign vcMessage = "":U.

            if vcMessage                           = "":U                       and 
               tCInvoice.CInvoiceType              = {&INVOICETYPE-INVOICE}     and 
               tqCInvoiceByIDForCA.tcCInvoiceType <> {&INVOICETYPE-CREDITNOTE}  and 
               tqCInvoiceByIDForCA.tcCInvoiceType <> {&INVOICETYPE-PREPAYMENT}  and 
               tqCInvoiceByIDForCA.tcCInvoiceType <> {&INVOICETYPE-INVOICECORRECTION}
            then assign vcMessage = trim(substitute(#T-43'An invoice of type &1 can only be linked to an invoice of type &2, &3 or &4.':255(455789087)T-43#,
                                                    {&INVOICETYPE-INVOICE-TR}, {&INVOICETYPE-CREDITNOTE-TR}, {&INVOICETYPE-PREPAYMENT-TR}, {&INVOICETYPE-INVOICECORRECTION-TR})).
            if vcMessage                           = "":U                                and 
               tCInvoice.CInvoiceType              = {&INVOICETYPE-CREDITNOTE}           and 
               tqCInvoiceByIDForCA.tcCInvoiceType <> {&INVOICETYPE-CREDITNOTECORRECTION} and 
               tqCInvoiceByIDForCA.tcCInvoiceType <> {&INVOICETYPE-INVOICE}
            then assign vcMessage = trim(substitute(#T-52'An invoice of type &1 can only be linked to an invoice of type &2 or &3.':255(30547212)T-52#,
                                                    {&INVOICETYPE-CREDITNOTE-TR}, {&INVOICETYPE-CREDITNOTECORRECTION-TR}, {&INVOICETYPE-INVOICE-TR})).
            if vcMessage                           = "":U                             and 
               tCInvoice.CInvoiceType              = {&INVOICETYPE-INVOICECORRECTION} and 
               tqCInvoiceByIDForCA.tcCInvoiceType <> {&INVOICETYPE-INVOICE}           and 
               tqCInvoiceByIDForCA.tcCInvoiceType <> {&INVOICETYPE-CREDITNOTECORRECTION}
            then assign vcMessage = trim(substitute(#T-58'An invoice of type &1 can only be linked to an invoice of type &2 or &3.':255(30547212)T-58#,
                                                    {&INVOICETYPE-INVOICECORRECTION-TR}, {&INVOICETYPE-INVOICE-TR}, {&INVOICETYPE-CREDITNOTECORRECTION-TR})).
            if vcMessage                           = "":U                                and 
               tCInvoice.CInvoiceType              = {&INVOICETYPE-CREDITNOTECORRECTION} and 
               tqCInvoiceByIDForCA.tcCInvoiceType <> {&INVOICETYPE-CREDITNOTE}           and 
               tqCInvoiceByIDForCA.tcCInvoiceType <> {&INVOICETYPE-INVOICECORRECTION}
            then assign vcMessage = trim(substitute(#T-80'An invoice of type &1 can only be linked to an invoice of type &2 or &3.':255(30547212)T-80#,
                                                    {&INVOICETYPE-CREDITNOTECORRECTION-TR}, {&INVOICETYPE-CREDITNOTE-TR}, {&INVOICETYPE-INVOICECORRECTION-TR})).

            if vcMessage <> "":U
            then do :
                assign viLocalReturnStatus  = -1.
                <M-33 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-695277':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
                Leave VALBLOCK.
            end. /* if vcMessage <> "":U */
        end. /* if */

        /* ===================================================================================== */
        /* 4- Compare the amount on tCInvoice against the open-balance of tqCInvoiceByIDForCA:   */ 
        /* In absolute terms the amount on tCInvoice cannot be more than the Open-Balance        */
        /* of tqCInvoiceByIDForCA subtracted with the Pending-WHT of tqCInvoiceByIDForCA         */
        /* ===================================================================================== */
        if (tCInvoice.tc_Status = 'N':U) or
           (tCInvoice.tc_Status = 'C':U and 
             (tCInvoice.CInvoiceOriginalDebitTC  <> t_iCInvoice.CInvoiceOriginalDebitTC or
              tCInvoice.CInvoiceOriginalCreditTC <> t_iCInvoice.CInvoiceOriginalCreditTC))
        then do :
            assign vdPendingWHTAmountTC = 0.

            if tqCInvoiceByIDForCA.tlCInvoiceIsWHT
            then do :
                <Q-18 run WHTByCInvoice (all) (Read) (NoCache)
                   (input ?, (CompanyId)
                    input tqCInvoiceByIDForCA.tiCInvoice_ID, (CInvoiceId)
                    input ?, (WHTStatusDiffersFrom)
                    input {&WHTSTATUS-INIT}, (WHTStatus)
                    output dataset tqWHTByCInvoice) in BWithholdingTax>
                assign vdPendingWHTAmountTC = 0.
                for each tqWHTByCInvoice where
                         tqWHTByCInvoice.tiCInvoice_ID = tqCInvoiceByIDForCA.tiCInvoice_ID and 
                         tqWHTByCInvoice.tcWHTStatus   = {&WHTSTATUS-INIT}
                         no-lock :
                    assign vdPendingWHTAmountTC = vdPendingWHTAmountTC + abs(tqWHTByCInvoice.tdWHTAmtDebitTC - tqWHTByCInvoice.tdWHTAmtCreditTC).
                end.  /* end for each tqWHTByCInvoice .. */
            end. /* if tqCInvoiceByIDForCA.tlCInvoiceIsWHT */

            if Absolute(tCInvoice.CInvoiceOriginalDebitTC - tCInvoice.CInvoiceOriginalCreditTC) > Absolute(tqCInvoiceByIDForCA.tdCInvoiceBalanceDebitTC - tqCInvoiceByIDForCA.tdCInvoiceBalanceCreditTC) - vdPendingWHTAmountTC
            then do :   
                /* to make sure that the translatable value of the invoice type is shown */
                if vcCInvoiceTypeTrans       = "":U or
                   vcCInvoiceTypeTrans       = ?    or 
                   vcLinkedCInvoiceTypeTrans = "":U or 
                   vcLinkedCInvoiceTypeTrans = ?
                then do :
                    assign vcPreprocessorInvoiceTypes = {&INVOICETYPES}.

                    do viCounter = num-entries(vcPreprocessorInvoiceTypes,chr(2)) to 1 by -2 :

                        if entry(viCounter,vcPreprocessorInvoiceTypes,chr(2)) = tCInvoice.CInvoiceType
                        then assign vcCInvoiceTypeTrans = entry(viCounter - 1,vcPreprocessorInvoiceTypes,chr(2)) no-error.

                        if entry(viCounter,vcPreprocessorInvoiceTypes,chr(2)) = tqCInvoiceByIDForCA.tcCInvoiceType
                        then assign vcLinkedCInvoiceTypeTrans = entry(viCounter - 1,vcPreprocessorInvoiceTypes,chr(2)) no-error.

                        if vcCInvoiceTypeTrans       <> "":U and 
                           vcCInvoiceTypeTrans       <> ?    and 
                           vcLinkedCInvoiceTypeTrans <> "":U and 
                           vcLinkedCInvoiceTypeTrans <> ?
                        then Leave.

                    end. /* do viCounter = num-entries */ 
                end. /* if vcCInvoiceTypeTrans       = "":U or */  

                assign vcMessage            = trim(substitute(#T-31'The amount on the &1 (&2) cannot be more than the open-balance of the linked &3 (&4) minus its WHT.':255(802102773)T-31#,
                                                              vcCInvoiceTypeTrans, 
                                                              string(tCInvoice.CInvoicePostingYear) + "/":U + tCInvoice.tcJournalCode + "/":U + string(tCInvoice.CInvoiceVoucher), 
                                                              vcLinkedCInvoiceTypeTrans, 
                                                              string(tqCInvoiceByIDForCA.tiCInvoicePostingYear) + "/":U + tqCInvoiceByIDForCA.tcJournalCode + "/":U + string(tqCInvoiceByIDForCA.tiCInvoiceVoucher))) + chr(10) + 
                                              trim(substitute(#T-64'Amount of the &1 : &2':255(997069175)T-64#, vcCInvoiceTypeTrans, Absolute(tCInvoice.CInvoiceOriginalDebitTC - tCInvoice.CInvoiceOriginalCreditTC))) + chr(10) + 
                                              trim(substitute(#T-73'Open-balance of the &1 : &2':255(207127399)T-73#, vcLinkedCInvoiceTypeTrans, Absolute(tqCInvoiceByIDForCA.tdCInvoiceBalanceDebitTC - tqCInvoiceByIDForCA.tdCInvoiceBalanceCreditTC))) + chr(10) + 
                                              trim(substitute(#T-92'WHT-amount of the &1 : &2':255(546801047)T-92#, vcLinkedCInvoiceTypeTrans, vdPendingWHTAmountTC))
                       viLocalReturnStatus  = -1.

                <M-41 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-756933':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
                 leave VALBLOCK.

            end. /* if Absolute((tCInvoice.CInvoiceOriginalDebitTC - tCInvoice.CInvoiceOriginalCreditTC) > Absolute(tqCInvoiceByIDForCA.tdCInvoiceBalanceDebitTC - tqCInvoiceByIDForCA.tdCInvoiceBalanceCreditTC) - vdPendingWHTAmountTC */

        end. /* if */

        /* ==================================================================================================================================================== */
        /* The movements etc for the invoice and for the linked-invoice are very similar as the rates, the movement-amount and the wht are the same:            */
        /* The only difference between them is that either the credit and debit are switched, either the sign (+ or -) differs depending upon the invoice-types */
        /* ==================================================================================================================================================== */
        /* This is the overview of possible combination and what is the difference between the invoice and the linked-invoice:                                  */
        /*    InvoiceType	      Linked-InvoiceType	  Difference Invoice - LinkedInvoice                                                                    */
        /*      Invoice	            CreditNote	                SwitchCredDeb                                                                                   */
        /*      Invoice             InvoiceCorr	                SwitchSign                                                                                      */
        /*      CreditNote	        Invoice	                    SwitchCredDeb                                                                                   */
        /*      CreditNote	        CreditNoteCorr	            SwitchSign                                                                                      */
        /*      InvoiceCorr	        Invoice	                    SwitchSign                                                                                      */
        /*      InvoiceCorr	        CreditNoteCorr	            SwitchCredDeb                                                                                   */
        /*      CreditNoteCorr	    CreditNote	                SwitchSign                                                                                      */
        /*      CreditNoteCorr	    InvoiceCorr	                SwitchCredDeb                                                                                   */
        /* Note that a prepayment is considered the same as a CreditNote                                                                                        */
        /* ==================================================================================================================================================== */
        if (tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICE}                 and tqCInvoiceByIDForCA.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE})           Or
           (tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICE}                 and tqCInvoiceByIDForCA.tcCInvoiceType = {&INVOICETYPE-PREPAYMENT})           Or
           (tCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTE}              and tqCInvoiceByIDForCA.tcCInvoiceType = {&INVOICETYPE-INVOICE})              Or
           (tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICECORRECTION}       and tqCInvoiceByIDForCA.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}) Or
           (tCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}    and tqCInvoiceByIDForCA.tcCInvoiceType = {&INVOICETYPE-INVOICECORRECTION})
        then assign olSwitchDebitCredit = true.
        else assign olSwitchDebitCredit = false.
        
    end. /* for each tCInvoice */
    
END. /* VALBLOCK */

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