project QadFinancials > class BCInvoice > method ValidateComponentPreWHT

validation procedure

Description

This method is used to calculate withholding tax amounts


Parameters


idCInvoiceExchangeRateinputdecimalCInvoice Exchange Rate TC to CC
idCInvoiceRateScaleinputdecimalCInvoice Rate Scale from TC to CC
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.ValidateComponentPre


program code (program5/bcinvoice.p)

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

/***************************************************/
/* Update the wht flag on the invoice if necessary */
/***************************************************/
if can-find(first t_sCInvoiceWHT where
                  t_sCInvoiceWHT.tc_ParentRowid  = t_sCInvoice.tc_Rowid and
                  t_sCInvoiceWHT.tc_Status      <> "D":U)
then assign t_sCInvoice.CInvoiceIsWHT = true.
else assign t_sCInvoice.CInvoiceIsWHT = false. 

/* ========================================= */
/* Go through all modified / new WHT-details */
/* ========================================= */
for each t_sCInvoiceWHT where
         t_sCInvoiceWHT.tc_ParentRowid = t_sCInvoice.tc_Rowid and
         (t_sCInvoiceWHT.tc_Status = "C":U or 
          t_sCInvoiceWHT.tc_Status = "N":U) :
    
    /* ============================================================================================================================================= */
    /* Make sure CInvoiceWHT.CInvoiceWHTIsOrigFromAPM and CInvoiceWHTIsUpdAllow get set to false in the valdiations in case it has the unknown value */
    /* ============================================================================================================================================= */
    if t_sCInvoiceWHT.CInvoiceWHTIsOrigFromAPM = ?
    then assign t_sCInvoiceWHT.CInvoiceWHTIsOrigFromAPM = false. 
    if t_sCInvoiceWHT.CInvoiceWHTIsUpdAllow = ?
    then assign t_sCInvoiceWHT.CInvoiceWHTIsUpdAllow = false.     
    
    /* =================================================================================================================================================================== */
    /* In case only the expense-amount is filled and the VatCode is empty then make sure the Vat-related fields get emptied as well                                        */
    /* If we do not empty these fields then we run into the problem that the generated code will try to assign the VatID based upon the VatCode, VatInOut and tcDomainCode */
    /* =================================================================================================================================================================== */
    if ((t_sCInvoiceWHT.CInvoiceWHTExpenseCreditTC <> 0 and 
         t_sCInvoiceWHT.CInvoiceWHTExpenseCreditTC <> ?)  Or
        (t_sCInvoiceWHT.CInvoiceWHTExpenseDebitTC  <> 0 and 
         t_sCInvoiceWHT.CInvoiceWHTExpenseDebitTC  <> ?))   And
       (t_sCInvoiceWHT.CInvoiceWHTFeeCreditTC = 0 or 
        t_sCInvoiceWHT.CInvoiceWHTFeeCreditTC = ?)          And
       (t_sCInvoiceWHT.CInvoiceWHTFeeDebitTC = 0 or
        t_sCInvoiceWHT.CInvoiceWHTFeeDebitTC = ?)           And 
       (t_sCInvoiceWHT.tcVatCode = "":U or 
        t_sCInvoiceWHT.tcVatCode = ?)
    then assign t_sCInvoiceWHT.tcVatInOut       = "":U
                t_sCInvoiceWHT.tcDomainCode     = "":U
                t_sCInvoiceWHT.tcVatDescription = "":U.
    
    /* =============== */
    /* Fill CC amounts */
    /* =============== */
    if t_sCInvoice.tcCurrencyCode = vcCompanyCC
    then assign t_sCInvoiceWHT.CInvoiceWHTTaxFeeDebitCC  = t_sCInvoiceWHT.CInvoiceWHTTaxFeeDebitTC
                t_sCInvoiceWHT.CInvoiceWHTTaxFeeCreditCC = t_sCInvoiceWHT.CInvoiceWHTTaxFeeCreditTC
                t_sCInvoiceWHT.CInvoiceWHTAmtDebitCC     = t_sCInvoiceWHT.CInvoiceWHTAmtDebitTC
                t_sCInvoiceWHT.CInvoiceWHTAmtCreditCC    = t_sCInvoiceWHT.CInvoiceWHTAmtCreditTC.
    else if vlDomainIsStatutory = false
         then assign t_sCInvoiceWHT.CInvoiceWHTTaxFeeDebitCC  = t_sCInvoiceWHT.CInvoiceWHTTaxFeeDebitLC
                     t_sCInvoiceWHT.CInvoiceWHTTaxFeeCreditCC = t_sCInvoiceWHT.CInvoiceWHTTaxFeeCreditLC
                     t_sCInvoiceWHT.CInvoiceWHTAmtDebitCC     = t_sCInvoiceWHT.CInvoiceWHTAmtDebitLC
                     t_sCInvoiceWHT.CInvoiceWHTAmtCreditCC    = t_sCInvoiceWHT.CInvoiceWHTAmtCreditLC.
         else do:
             if idCInvoiceExchangeRate = ?
             then do:
                 <M-85 run GetExRateByEntityInvoiceFlag
                    (input  t_sCInvoice.CInvoiceDate (itCInvoiceDate), 
                     input  t_sCInvoice.CInvoicePostingDate (itCInvoicePostingDate), 
                     input  0 (iiFromCurrencyId), 
                     input  t_sCInvoice.tcCurrencyCode (icFromCurrencyCode), 
                     input  viCompanyCCId (iiToCurrencyId), 
                     input  vcCompanyCC (icToCurrencyCode), 
                     input  0 (iiExchangeRateTypeId), 
                     input  {&EXCHANGERATETYPE-VAT} (icExchangeRateTypeCode), 
                     output idCInvoiceExchangeRate (odCInvoiceExchangeRate), 
                     output idCInvoiceRateScale (odCInvoiceRateScale), 
                     output viFcReturnSuper (oiReturnStatus)) in BCInvoice>       
                 if viFcReturnSuper <> 0 or oiReturnStatus  >= 0
                 then assign oiReturnStatus = viFcReturnSuper.
                 <M-95 run CheckLinkedInvoiceCC
                    (input  t_sCInvoice.tc_Rowid (icInvoiceRowid), 
                     input-output idCInvoiceExchangeRate (bdExchangeRate), 
                     input-output idCInvoiceRateScale (bdRateScale), 
                     output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
                 if viFcReturnSuper <> 0 or oiReturnStatus  >= 0
                 then assign oiReturnStatus = viFcReturnSuper.
             end. /* if idCInvoiceExchangeRate = ? */
             assign t_sCInvoiceWHT.CInvoiceWHTTaxFeeDebitCC  = <M-78 RoundAmount
                                                                  (input  t_sCInvoiceWHT.CInvoiceWHTTaxFeeDebitTC * idCInvoiceExchangeRate * idCInvoiceRateScale (idUnroundedAmount), 
                                                                   input  viCompanyCCId (iiCurrencyID), 
                                                                   input  vcCompanyCC (icCurrencyCode)) in BApplicationProperty>
                    t_sCInvoiceWHT.CInvoiceWHTTaxFeeCreditCC = <M-20 RoundAmount
                                                                  (input  t_sCInvoiceWHT.CInvoiceWHTTaxFeeCreditTC * idCInvoiceExchangeRate * idCInvoiceRateScale (idUnroundedAmount), 
                                                                   input  viCompanyCCId (iiCurrencyID), 
                                                                   input  vcCompanyCC (icCurrencyCode)) in BApplicationProperty>
                    t_sCInvoiceWHT.CInvoiceWHTAmtDebitCC     = <M-91 RoundAmount
                                                                  (input  t_sCInvoiceWHT.CInvoiceWHTAmtDebitTC * idCInvoiceExchangeRate * idCInvoiceRateScale (idUnroundedAmount), 
                                                                   input  viCompanyCCId (iiCurrencyID), 
                                                                   input  vcCompanyCC (icCurrencyCode)) in BApplicationProperty>
                    t_sCInvoiceWHT.CInvoiceWHTAmtCreditCC    = <M-1 RoundAmount
                                                                  (input  t_sCInvoiceWHT.CInvoiceWHTAmtCreditTC * idCInvoiceExchangeRate * idCInvoiceRateScale (idUnroundedAmount), 
                                                                   input  viCompanyCCId (iiCurrencyID), 
                                                                   input  vcCompanyCC (icCurrencyCode)) in BApplicationProperty>.
         end. /* else do: */    
end. /* for each t_sCInvoiceWHT where */

/*****************************************/
/* Fill the wht total fields on CInvoice */
/*****************************************/
if t_sCInvoice.tc_Status  <> "D":U
then do:
    for each t_sCInvoiceWHT where
             t_sCInvoiceWHT.tc_ParentRowid = t_sCInvoice.tc_Rowid and
             t_sCInvoiceWHT.tc_Status <> "D":U:
        accumulate t_sCInvoiceWHT.CInvoiceWHTTaxFeeDebitTC   (total)
                   t_sCInvoiceWHT.CInvoiceWHTTaxFeeDebitLC   (total)
                   t_sCInvoiceWHT.CInvoiceWHTTaxFeeDebitCC   (total)
                   t_sCInvoiceWHT.CInvoiceWHTTaxFeeCreditTC  (total)
                   t_sCInvoiceWHT.CInvoiceWHTTaxFeeCreditLC  (total)
                   t_sCInvoiceWHT.CInvoiceWHTTaxFeeCreditCC  (total)
                   t_sCInvoiceWHT.CInvoiceWHTAmtDebitTC      (total)
                   t_sCInvoiceWHT.CInvoiceWHTAmtDebitLC      (total)
                   t_sCInvoiceWHT.CInvoiceWHTAmtDebitCC      (total)
                   t_sCInvoiceWHT.CInvoiceWHTAmtCreditTC     (total)
                   t_sCInvoiceWHT.CInvoiceWHTAmtCreditLC     (total)
                   t_sCInvoiceWHT.CInvoiceWHTAmtCreditCC     (total).
    end. /* end for each t_sCInvoiceWHT ... */
    assign t_sCInvoice.CInvoiceWHTBaseAmtDebitTC  = accum total t_sCInvoiceWHT.CInvoiceWHTTaxFeeDebitTC
           t_sCInvoice.CInvoiceWHTBaseAmtDebitLC  = accum total t_sCInvoiceWHT.CInvoiceWHTTaxFeeDebitLC
           t_sCInvoice.CInvoiceWHTBaseAmtDebitCC  = accum total t_sCInvoiceWHT.CInvoiceWHTTaxFeeDebitCC
           t_sCInvoice.CInvoiceWHTBaseAmtCreditTC = accum total t_sCInvoiceWHT.CInvoiceWHTTaxFeeCreditTC
           t_sCInvoice.CInvoiceWHTBaseAmtCreditLC = accum total t_sCInvoiceWHT.CInvoiceWHTTaxFeeCreditLC
           t_sCInvoice.CInvoiceWHTBaseAmtCreditCC = accum total t_sCInvoiceWHT.CInvoiceWHTTaxFeeCreditCC
           t_sCInvoice.CInvoiceWHTTotAmtDebitTC   = accum total t_sCInvoiceWHT.CInvoiceWHTAmtDebitTC
           t_sCInvoice.CInvoiceWHTTotAmtDebitLC   = accum total t_sCInvoiceWHT.CInvoiceWHTAmtDebitLC
           t_sCInvoice.CInvoiceWHTTotAmtDebitCC   = accum total t_sCInvoiceWHT.CInvoiceWHTAmtDebitCC
           t_sCInvoice.CInvoiceWHTTotAmtCreditTC  = accum total t_sCInvoiceWHT.CInvoiceWHTAmtCreditTC
           t_sCInvoice.CInvoiceWHTTotAmtCreditLC  = accum total t_sCInvoiceWHT.CInvoiceWHTAmtCreditLC
           t_sCInvoice.CInvoiceWHTTotAmtCreditCC  = accum total t_sCInvoiceWHT.CInvoiceWHTAmtCreditCC.
end. /* if t_sCInvoice.tc_Status  <> "D":U */