project QadFinancials > class BCInvoice > method ValidateComponentPostTax

Description

This method is a submethod of ValidateComponentPost.

This method validates the tax lines of the creditor invoice.


Parameters


iiMfgProMajorVersioninputinteger
iiMfgProMinorVersioninputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.ValidateComponentPost


program code (program5/bcinvoice.p)

    /* There must always be at least one tax line */
    if ((t_sCInvoice.tc_Status = "C":U and
        (t_iCInvoice.CInvoiceIsTaxable     <> t_sCInvoice.CInvoiceIsTaxable or
         t_iCInvoice.CInvoiceIsTaxExcluded <> t_sCInvoice.CInvoiceIsTaxExcluded)) or
        t_sCInvoice.tc_Status = "N":U) and
       not can-find(first t_sCInvoiceVat where
                          t_sCInvoiceVat.tc_ParentRowid = t_sCInvoice.tc_Rowid and
                          t_sCInvoiceVat.tc_Status     <> "D":U)
    then do:
        assign vcMessage      = trim(#T-4'You must specify at least one tax line.':255(64062)T-4#) + chr(10) +
                                trim(subst(#T-7'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-7#, string(t_sCInvoice.CInvoicePostingYear), string(t_sCInvoice.CInvoicePostingPeriod), t_sCInvoice.tcJournalCode, string(t_sCInvoice.CInvoiceVoucher)))
               oiReturnStatus = -1.    
        <M-6 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tCInvoice.CInvoiceIsTaxable':U (icFieldName), 
            input  t_sCInvoice.CInvoiceIsTaxable (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sCInvoice.tc_Rowid (icRowid), 
            input  'QadFin-6679':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    end.
    
    /* When taxable on invoice is set to false, then you cannot have tax lines with taxable on true */
    if (t_sCInvoice.tc_Status          = "N":U                          or
        t_sCInvoice.tc_Status          = "C":U                          and
        t_sCInvoice.CInvoiceIsTaxable <> t_iCInvoice.CInvoiceIsTaxable) and
        t_sCInvoice.CInvoiceIsTaxable  = false                          and
        can-find(first t_sCInvoiceVat where
                       t_sCInvoiceVat.tc_ParentRowid       = t_sCInvoice.tc_Rowid and
                       t_sCInvoiceVat.tc_Status           <> "D":U                and
                       t_sCInvoiceVat.CInvoiceVatIsTaxable = true)
    then do:
        assign vcMessage      = trim(#T-1'You cannot select the Tax Lines with Taxable field when the Taxable field of the supplier invoice is cleared.':255(56436)T-1#) + chr(10) +
                                trim(subst(#T-2'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-2#, string(t_sCInvoice.CInvoicePostingYear), string(t_sCInvoice.CInvoicePostingPeriod), t_sCInvoice.tcJournalCode, string(t_sCInvoice.CInvoiceVoucher)))
               oiReturnStatus = -1.
    
        <M-3 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tCInvoice.CInvoiceIsTaxable':U (icFieldName), 
            input  t_sCInvoice.CInvoiceIsTaxable (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sCInvoice.tc_Rowid (icRowid), 
            input  'QadFin-5672':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    end.
    
    /* All tax lines must have the same value for discount tax at payment or discount tax at invoice */
    assign viCount = 0
           vlError = false.
    
    for each t_sCInvoiceVat where
             t_sCInvoiceVat.tc_ParentRowid = t_sCInvoice.tc_Rowid and
             t_sCInvoiceVat.tc_Status     <> "D":U:
        assign viCount = viCount + 1.
           
        <Q-12 run MfgTaxCodeByTaxCode (all) (Read) (Cache)
           (input t_sCInvoiceVat.tcVatCode, (TaxCode)
            input t_sCInvoiceVat.tcDomainCode, (DomainCode)
            input ?, (DiscountAtPayment)
            input ?, (IsTaxByLine)
            output dataset tqMfgTaxCodeByTaxCode) in BMfgTaxCode>
    
        find first tqMfgTaxCodeByTaxCode where
                   tqMfgTaxCodeByTaxCode.tctx2_tax_code = t_sCInvoiceVat.tcVatCode and
                   tqMfgTaxCodeByTaxCode.tctx2_domain   = t_sCInvoiceVat.tcDomainCode
                   no-error.
    
        if not available tqMfgTaxCodeByTaxCode
        then do:
            assign  vcMessage       = trim(subst(#T-8'Tax code &1 is not defined in domain &2.':255(65341)T-8#, t_sCInvoiceVat.tcVatCode, t_sCInvoiceVat.tcDomainCode)) + chr(10) +
                                      trim(subst(#T-9'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-9#, string(t_sCInvoice.CInvoicePostingYear), string(t_sCInvoice.CInvoicePostingPeriod), t_sCInvoice.tcJournalCode, string(t_sCInvoice.CInvoiceVoucher)))
                    oiReturnStatus  = -1.
            <M-14 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tCInvoiceVat.tcVatCode':U (icFieldName), 
                input  t_sCInvoiceVat.tcVatCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sCInvoiceVat.tc_Rowid (icRowid), 
                input  'QadFin-7007':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        end. /* if not available tqMfgTaxCodeByTaxCode */
        else do:
            if viCount = 1
            then assign vlDiscountTaxAtPayment = tqMfgTaxCodeByTaxCode.tltx2_pmt_disc
                        vlDiscountTaxAtInvoice = tqMfgTaxCodeByTaxCode.tltx2_inv_disc.
            else
            if vlDiscountTaxAtPayment <> tqMfgTaxCodeByTaxCode.tltx2_pmt_disc or
               vlDiscountTaxAtInvoice <> tqMfgTaxCodeByTaxCode.tltx2_inv_disc
            then do:
                assign vlError = true.
                leave.
            end.
        end. /* else if not available tqMfgTaxCodeByTaxCode */
    
        /* Validate the Delayed tax flag on entity */
        if t_sCInvoiceVat.CInvoiceVatIsSuspDel = true
        then do:           
            <Q-17 run CompanyPropertyBySuspDelTax (all) (Read) (NoCache)
               (input t_sCInvoice.Company_ID, (CompanyId)
                input {&SUSPDELAYTAX-NOTAPPLICABLE}, (DelTax)
                input ?, (SuspTax)
                output dataset tqCompanyPropertyBySuspDelTax) in BCompanyProperty >
            find first tqCompanyPropertyBySuspDelTax no-error.
            if not available tqCompanyPropertyBySuspDelTax or tqCompanyPropertyBySuspDelTax.tcCompanyPropertyDelTax = '':U
            then do:
                assign vcMessage = trim(subst(#T-18'You cannot specify a Delayed tax rate if the Delayed tax field on the entity(&1) of the invoice(&2) is set to Not Applicable.':255(70240)T-18#,string(t_sCInvoice.Company_ID),string(t_sCInvoice.CInvoiceReference)))
                       oiReturnStatus = -1.
                 <M-19 run SetMessage
                    (input  vcMessage (icMessage), 
                     input  '':U (icArguments), 
                     input  '':U (icFieldName), 
                     input  '':U (icFieldValue), 
                     input  'E':U (icType), 
                     input  1 (iiSeverity), 
                     input  '':U (icRowid), 
                     input  'QadFin-8296':U (icFcMsgNumber), 
                     input  '':U (icFcExplanation), 
                     input  '':U (icFcIdentification), 
                     input  '':U (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    
            end.
        end.
        
        if iiMfgProMajorVersion >= 3
        and iiMfgProMinorVersion > 6
        then do:
        
             /* Tax type cannot be enabled for withholding tax */
            <Q-66 run MfgTaxTypeByTaxTypeV01 (first) (Read) (Cache)
               (input tqMfgTaxCodeByTaxCode.tctx2_tax_type, (TaxTypeCode)
                input true, (TaxTypeIsWHT)
                output dataset tqMfgTaxTypeByTaxTypeV01) in BMfgTaxType>
            Find first tqMfgTaxTypeByTaxTypeV01 where 
                       tqMfgTaxTypeByTaxTypeV01.tctxty_tax_type = tqMfgTaxCodeByTaxCode.tctx2_tax_type and 
                       tqMfgTaxTypeByTaxTypeV01.tltxty_wt_type  = true
                       no-lock no-error.
            if available tqMfgTaxTypeByTaxTypeV01
            then do:
                assign  vcMessage       = trim(subst(#T-78'Tax code &1 cannot used for normal tax purposes because its tax type &2 is designated for withholding tax purposes':255(35413264)T-78#, tqMfgTaxCodeByTaxCode.tctx2_tax_code, tqMfgTaxCodeByTaxCode.tctx2_tax_type))
                        oiReturnStatus  = -1.
                <M-52 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'Tax Type':U (icFieldName), 
                    input  tqMfgTaxCodeByTaxCode.tctx2_tax_type (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sCInvoiceVAT.tc_Rowid (icRowid), 
                    input  'qadfin-623298':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
            end. /* if available tqMfgTaxTypeByTaxType */
            
        end.
        
        assign t_sCInvoiceVat.tc_Status = (if t_sCInvoiceVat.tc_Status = "":U then "C":U else t_sCInvoiceVat.tc_Status).   
        
    end. /* for each t_sCInvoiceVat where */
    
    if vlError
    then do:
        assign vcMessage  = trim(#T-13'All Tax Lines must have the same settings for Discount Tax At Payment and / or Discount Tax At Invoice':255(645552569)T-13#) + chr(10) +
                            trim(subst(#T-11'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-11#, string(t_sCInvoice.CInvoicePostingYear), string(t_sCInvoice.CInvoicePostingPeriod), t_sCInvoice.tcJournalCode, string(t_sCInvoice.CInvoiceVoucher)))
               oiReturnStatus = -1.
    
        <M-15 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tCInvoiceVat.tcVatCode':U (icFieldName), 
            input  t_sCInvoiceVat.tcVatCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sCInvoiceVat.tc_Rowid (icRowid), 
            input  'QadFin-7008':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    end.
    else
    if t_sCInvoice.CInvoiceIsDiscTaxAtPaym <> vlDiscountTaxAtPayment or
       t_sCInvoice.CInvoiceIsDiscTaxAtInv  <> vlDiscountTaxAtInvoice
    then do:
        assign t_sCInvoice.CInvoiceIsDiscTaxAtPaym = vlDiscountTaxAtPayment
               t_sCInvoice.CInvoiceIsDiscTaxAtInv  = vlDiscountTaxAtInvoice.
    
        if t_sCInvoice.tc_Status = "":U
        then assign t_sCInvoice.tc_Status = "C":U.
    end.
    
    /* =================================================================================================== */
    /* All Tax-Lines of a SupplierInvoice should have the same value for AccrueTaxAtReceipt -              */
    /* If not, then you would get an incorrect MatchingPosting for SupplierInvoices with FinancialMatching */
    /* and some taxes of the invoice with AccrueAtReceipt=yes and other taxes with AccrueAtReceipt=no      */
    /* =================================================================================================== */
    if can-find (first t_sCInvoiceVat where
                       t_sCInvoiceVat.tc_ParentRowid          = t_sCInvoice.tc_Rowid and
                       t_sCInvoiceVat.tc_Status              <> "D":U                and 
                       t_sCInvoiceVat.CInvoiceVatIsAccrRcpUs  = true) And
       can-find (first t_sCInvoiceVat where
                       t_sCInvoiceVat.tc_ParentRowid          = t_sCInvoice.tc_Rowid and
                       t_sCInvoiceVat.tc_Status              <> "D":U                and 
                       t_sCInvoiceVat.CInvoiceVatIsAccrRcpUs  = false)
    then do :
        assign vcMessage      = trim(#T-37'All Tax Lines of an invoice must have the same setting for Accrue At Receipt/Usage.':255(647786559)T-37#) + chr(10) +
                                trim(subst(#T-36'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-36#, string(t_sCInvoice.CInvoicePostingYear), string(t_sCInvoice.CInvoicePostingPeriod), t_sCInvoice.tcJournalCode, string(t_sCInvoice.CInvoiceVoucher)))
               oiReturnStatus = -1.
        <M-71 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tCInvoice.CInvoiceIsTaxable':U (icFieldName), 
            input  string(t_sCInvoice.CInvoiceIsTaxable) (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sCInvoice.tc_Rowid (icRowid), 
            input  'qadfin-418913':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    end. /* if can-find (first t_sCInvoiceVat where */