project QadFinancials > class BDInvoice > method ValidateComponentAllTax

Description

This method is a submethod of ValidateComponentAll.

This method validates the tax lines of the debtor invoice.


Parameters


blStartMfgTaxCodeByTaxCodeinput-outputlogicalis query tqMfgTaxCodeByTaxCode already started or not ?
blStartCompPropBySuspDelTaxinput-outputlogicalis query tqCompanyPropertyBySuspDelTax already started or not ?
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDInvoice.ValidateComponentAll


program code (program5/bdinvoice.p)

/* ======================================================================== */
/* IMPORTANT: This method is run from ValidateComponentAll                  */
/* 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) */
/* ======================================================================== */

/* there must always be at least one tax line */
if ((t_sDInvoice.tc_Status = "C":U and
    (t_iDInvoice.DInvoiceIsTaxable     <> t_sDInvoice.DInvoiceIsTaxable or
     t_iDInvoice.DInvoiceIsTaxExcluded <> t_sDInvoice.DInvoiceIsTaxExcluded)) or
     t_sDInvoice.tc_Status = "N":U) and
     not can-find(first t_sDInvoiceVat where
                        t_sDInvoiceVat.tc_ParentRowid = t_sDInvoice.tc_Rowid and
                        t_sDInvoiceVat.tc_Status     <> "D":U)
then do:
    assign vcMessage      = trim(#T-5'You must specify at least one tax line.':255(64062)T-5#) + chr(10) +
                            trim(substitute(#T-6'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-6#,string(t_sDInvoice.DInvoicePostingYear),string(t_sDInvoice.DInvoicePostingPeriod), t_sDInvoice.tcJournalCode, string(t_sDInvoice.DInvoiceVoucher)))
           oiReturnStatus = -1.  
    <M-4 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  'tDInvoice.DInvoiceIsTaxable':U (icFieldName), 
        input  t_sDInvoice.DInvoiceIsTaxable (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  t_sDInvoice.tc_Rowid (icRowid), 
        input  'QadFin-6628':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end. /* if ((t_sDInvoice.tc_Status = "C":U .... */

/* when taxable on dinvoice is set to false, then you cannot have tax lines with taxable on true */
if (t_sDInvoice.tc_Status = "N":U or
    t_sDInvoice.tc_Status = "C":U) and
    t_sDInvoice.DInvoiceIsTaxable = false
then do:
    if can-find(first t_sDInvoiceVat where
                      t_sDInvoiceVat.tc_ParentRowid       = t_sDInvoice.tc_Rowid and
                      t_sDInvoiceVat.tc_Status           <> "D":U and
                      t_sDInvoiceVat.DInvoiceVatIsTaxable = true)
    then do:
        assign vcMessage      = trim(#T-1'You cannot select the Tax Lines with Taxable field when the Taxable field of the customer invoice is cleared.':255(56430)T-1#) + chr(10) +
                                trim(substitute(#T-2'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-2#,string(t_sDInvoice.DInvoicePostingYear),string(t_sDInvoice.DInvoicePostingPeriod), t_sDInvoice.tcJournalCode, string(t_sDInvoice.DInvoiceVoucher)))
               oiReturnStatus = -1.  
        <M-3 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tDInvoice.DInvoiceIsTaxable':U (icFieldName), 
            input  t_sDInvoice.DInvoiceIsTaxable (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sDInvoice.tc_Rowid (icRowid), 
            input  'QadFin-5670':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    end.   /* if can-find(first t_sDInvoiceVat .... */
end.       /* if (t_sDInvoice.tc_Status = "N":U ... */

/* all tax lines must have the same value for discount tax at payment or discount tax at invoice */
if t_sDInvoice.tc_Status = "N":U or
   t_sDInvoice.tc_Status = "C":U 
then do:
    assign viCount = 0
           vlError = false.
    for each t_sDInvoiceVat where
             t_sDInvoiceVat.tc_ParentRowid  = t_sDInvoice.tc_Rowid and
             t_sDInvoiceVat.tc_Status       <> "D":U :

        if t_sDInvoiceVat.TxtyTaxType <> {&VATTAXTYPE-NONTAX}
        then do:
            assign viCount = viCount + 1.
            if not blStartMfgTaxCodeByTaxCode
            then do:
                <Q-17 run MfgTaxCodeByTaxCode  (Start) in BMfgTaxCode >
                assign blStartMfgTaxCodeByTaxCode = true.
            end. /* if not blStartMfgTaxCodeByTaxCode */
    
            <Q-7 run MfgTaxCodeByTaxCode (all) (Read) (NoCache)
               (input t_sDInvoiceVat.tcVatCode, (TaxCode)
                input t_sDInvoiceVat.tcDomainCode, (DomainCode)
                input ?, (DiscountAtPayment)
                input ?, (IsTaxByLine)
                output dataset tqMfgTaxCodeByTaxCode) in BMfgTaxCode>
            find first tqMfgTaxCodeByTaxCode where
                       tqMfgTaxCodeByTaxCode.tctx2_tax_code = t_sDInvoiceVat.tcVatCode and
                       tqMfgTaxCodeByTaxCode.tctx2_domain   = t_sDInvoiceVat.tcDomainCode
                       no-error.
            if not available tqMfgTaxCodeByTaxCode
            then do:
                assign vcMessage  = trim(substitute(#T-9'Tax code &1 is not defined in domain &2.':255(65341)T-9#, t_sDInvoiceVat.tcVatCode, t_sDInvoiceVat.tcDomainCode)) + chr(10) +
                                    trim(substitute(#T-10'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-10#,string(t_sDInvoice.DInvoicePostingYear),string(t_sDInvoice.DInvoicePostingPeriod), t_sDInvoice.tcJournalCode, string(t_sDInvoice.DInvoiceVoucher)))
                   oiReturnStatus = -1.  
                <M-8 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tDInvoiceVat.tcVatCode':U (icFieldName), 
                    input  t_sDInvoiceVat.tcVatCode (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sDInvoiceVat.tc_Rowid (icRowid), 
                    input  'QadFin-7004':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            end. /* if not available tqMfgTaxCodeByTaxCode */
            else do:
                if viCount = 1
                then assign vlDiscountTaxAtPayment = tqMfgTaxCodeByTaxCode.tltx2_pmt_disc
                            vlDiscountTaxAtInvoice = tqMfgTaxCodeByTaxCode.tltx2_inv_disc.
                else do:
                    if vlDiscountTaxAtPayment <> tqMfgTaxCodeByTaxCode.tltx2_pmt_disc or
                       vlDiscountTaxAtInvoice <> tqMfgTaxCodeByTaxCode.tltx2_inv_disc
                    then do:
                         assign vlError = true.
                         leave.
                    end.    /* if vlDiscountTaxAtPayment <> tqMfgTaxCodeByTaxCode.tltx2_pmt_disc */
                end.        /* if viCount = 1                                                    */
            end.            /* end available tqMfgTaxCodeByTaxCode                               */
        end.                /* t_sDInvoiceVat.TxtyTaxType <> {&VATTAXTYPE-NONTAX}                */

         /* Validate the Suspended tax flag on entity */
        if t_sDInvoiceVat.DInvoiceVatIsSuspDel = true
        then do:
            if not blStartCompPropBySuspDelTax
            then do:
                <Q-18 run CompanyPropertyBySuspDelTax  (Start) in BCompanyProperty >
                assign blStartCompPropBySuspDelTax = true.
            end. /* if not blStartCompPropBySuspDelTax */
            <Q-15 run CompanyPropertyBySuspDelTax (all) (Read) (NoCache)
               (input t_sDInvoice.Company_ID, (CompanyId)
                input ?, (DelTax)
                input {&SUSPDELAYTAX-NOTAPPLICABLE}, (SuspTax)
                output dataset tqCompanyPropertyBySuspDelTax) in BCompanyProperty >
            find first tqCompanyPropertyBySuspDelTax no-error.
            if not available tqCompanyPropertyBySuspDelTax or tqCompanyPropertyBySuspDelTax.tcCompanyPropertySuspTax = '':U
            then do:
                assign vcMessage = trim(subst(#T-14'You cannot specify a Suspended or Delayed tax rate when the Suspended Tax field on the entity (&1) of the invoice (&2) is set to Not Applicable.':255(70241)T-14#,string(t_sDInvoice.Company_ID),string(t_sDInvoice.DInvoiceDescription)))
                       oiReturnStatus = -1.
                <M-16 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-8297':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    
            end. /* if not available tqCompanyPropertyBySuspDelTax */
        end.     /* if t_sDInvoiceVat.DInvoiceVatIsSuspDel = true  */
    end.         /* for each t_sDInvoiceVat where                  */

    if vlError
    then do:
         assign vcMessage  = trim(#T-12'All Tax Lines must have the same settings for Discount Tax At Payment and Discount Tax At Invoice':255(65342)T-12#) + chr(10) +
                            trim(substitute(#T-13'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-13#,string(t_sDInvoice.DInvoicePostingYear),string(t_sDInvoice.DInvoicePostingPeriod), t_sDInvoice.tcJournalCode, string(t_sDInvoice.DInvoiceVoucher)))
           oiReturnStatus = -1.  
        <M-11 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tDInvoiceVat.tcVatCode':U (icFieldName), 
            input  t_sDInvoiceVat.tcVatCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sDInvoiceVat.tc_Rowid (icRowid), 
            input  'QadFin-7005':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    end. /* if vlError */
    else assign t_sDInvoice.DInvoiceIsDiscTaxAtPaym = vlDiscountTaxAtPayment
                t_sDInvoice.DInvoiceIsDiscTaxAtInv  = vlDiscountTaxAtInvoice.
end. /* if t_sDInvoice.tc_Status = "N":U or .... */