Description
CreateAndOrUpdateWHTSubFee: sub-method of CreateAndOrUpdateWHTSub that will create and/or update the WHT records based on input temp-table that differs from the class-table
Parameters
idCInvoiceTotalWHTAmtTC | input | decimal | |
idProRataAllocatedWHT | input | decimal | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program7/bwithholdingtax.p)
/* ============================================================================================================== */
/* This method is a submethod of CreateAndOrUpdateWHTSub that is a submethod of CreateAndOrUpdateWHT */
/* - see that method for all details */
/* ============================================================================================================== */
/* By now, we have loaded all instance-datas and created the new instances and filled there logical key */
/* Now we will assign the other fields for the WHT-records that represent a Fee */
/* ============================================================================================================== */
/* ==================================== */
/* Exception Handling - Initialisation */
/* ==================================== */
assign oiReturnStatus = -98
viLocalReturnStatus = 0.
/* =========== */
/* Start block */
/* =========== */
FEEBLOCK: DO :
/* ================================================================ */
/* Check that everything that that should be available is available */
/* ================================================================ */
assign vcMessage = "":U.
if not available tInvoiceWHTPayment
then assign vcMessage = trim(substitute(#T-76'Internal error: A record of table &2 should be available but this is not the case. Method:=&1.':255(566293675)T-76#,"BWithholdingTax:CreateAndOrUpdateWHTSub":U,"tInvoiceWHTPayment":U)).
if vcMessage = "":U and
not available tqCInvoiceWHTForWHTCreation
then assign vcMessage = trim(substitute(#T-9'Internal error: A record of table &2 should be available but this is not the case. Method:=&1.':255(566293675)T-9#,"BWithholdingTax:CreateAndOrUpdateWHTSub":U,"tqCInvoiceWHTForWHTCreation":U)).
if vcMessage = "":U and
not available tWHT
then assign vcMessage = trim(substitute(#T-20'Internal error: A record of table &2 should be available but this is not the case. Method:=&1.':255(566293675)T-20#,"BWithholdingTax:CreateAndOrUpdateWHTSub":U,"tWHT":U)).
if vcMessage <> "":U
then do :
assign viLocalReturnStatus = -3.
<M-67 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-64814':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BWithholdingTax>
leave FEEBLOCK.
end. /* if vcMessage <> "":U*/
/* ================================================================ */
/* Assign all main fields of the WHT record that represents the Fee */
/* ================================================================ */
assign /* Fill the ID fields - that aren't part of the logical key as those are already filled (tWHT.Company_ID - tWHT.CInvoiceWHT_ID - tWHT.BankStateAlloc_ID - tWHT.CDocumentInvoiceXref_ID - tWHT.WHTChargeType - tWHT.OIAdjustLn_ID - tWHT.CACInvoice_ID) */
tWHT.Vat_ID = tqCInvoiceWHTForWHTCreation.tiVat_ID
tWHT.CInvoice_ID = tqCInvoiceWHTForWHTCreation.tiCInvoice_ID
/* Fill in the upd RKBF */
tWHT.tcCreditorCode = tqCInvoiceWHTForWHTCreation.tcCreditorCode
tWHT.tcGLCode = tqCInvoiceWHTForWHTCreation.tcGLCode
tWHT.tcDivisionCode = tqCInvoiceWHTForWHTCreation.tcDivisionCode
tWHT.tcCostCentreCode = tqCInvoiceWHTForWHTCreation.tcCostCentreCode
tWHT.tcProjectCode = tqCInvoiceWHTForWHTCreation.tcProjectCode
tWHT.tcWHTCertFormatCode = tqCInvoiceWHTForWHTCreation.tcWHTCertFormatCode
tWHT.tcCurrencyCode = tInvoiceWHTPayment.tcCurrencyCode
/* Fill in the status of the WHT */
tWHT.WHTStatus = tInvoiceWHTPayment.tcWHTStatus
/* Fill in the redundantly stored WHT fields */
tWHT.WHTPeriodYear = tInvoiceWHTPayment.tiPaymentAccountingYear
tWHT.WHTPeriodPeriod = tInvoiceWHTPayment.tiPaymentAccountingPeriod
tWHT.WHTTaxType = tqCInvoiceWHTForWHTCreation.tctx2_tax_type
tWHT.WHTCreditorCode = tqCInvoiceWHTForWHTCreation.tcCreditorCode
tWHT.WHTCreditorSharedSetCode = tqCInvoiceWHTForWHTCreation.tcSharedSetCode
tWHT.WHTCompanyCode = tqCInvoiceWHTForWHTCreation.tcCompanyCode
tWHT.WHTCompanyLCCurrencyCode = tqCInvoiceWHTForWHTCreation.tcLocalCurrencyCurrencyCode.
/* ================================================================ */
/* Assign amounts of the WHT record that represents the Fee */
/* ================================================================ */
if tInvoiceWHTPayment.tlCreateWHT = true or
tInvoiceWHTPayment.tlUpdateAllAmounts = true
then do :
assign /* Store the discounts in data-items as they are used later on in the assignements */
vdDiscountDebitTC = if tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or
tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}
then (tInvoiceWHTPayment.tdDiscountAmountTC *
tqCInvoiceWHTForWHTCreation.tdCInvoiceWHTFeeDebitTC /
(tqCInvoiceWHTForWHTCreation.tdCInvoiceOriginalDebitTC - tqCInvoiceWHTForWHTCreation.tdCInvoiceVatCreditTC - tqCInvoiceWHTForWHTCreation.tdCInvoiceNonDiscAmtTC))
else 0
vdDiscountCreditTC = if tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then (tInvoiceWHTPayment.tdDiscountAmountTC *
tqCInvoiceWHTForWHTCreation.tdCInvoiceWHTFeeCreditTC /
(tqCInvoiceWHTForWHTCreation.tdCInvoiceOriginalCreditTC - tqCInvoiceWHTForWHTCreation.tdCInvoiceVatDebitTC - tqCInvoiceWHTForWHTCreation.tdCInvoiceNonDiscAmtTC))
else 0
/* Fill in the normal WHT fields */
tWHT.WHTPercentage = tqCInvoiceWHTForWHTCreation.tdtx2_tax_pct
tWHT.WHTCInvoicePostingDate = tqCInvoiceWHTForWHTCreation.ttCInvoicePostingDate
tWHT.WHTPaymentDate = tInvoiceWHTPayment.ttPostingDate
tWHT.WHTPaymentReference = tInvoiceWHTPayment.tcPaymentReference
tWHT.WHTCInvoiceReference = substring(string(tqCInvoiceWHTForWHTCreation.tiCInvoicePostingYear) + "/":U +
tqCInvoiceWHTForWHTCreation.tcJournalCode + "/":U +
string(tqCInvoiceWHTForWHTCreation.tiCInvoiceVoucher, "999999999":U) + "/":U +
tqCInvoiceWHTForWHTCreation.tcCInvoiceReference,
1,50,'Character':U)
tWHT.WHTIsPrinted = false
tWHT.WHTChargeType = {&WHTCHARGETYPE-FEE}
tWHT.WHTChargeAmtDebitTC = tqCInvoiceWHTForWHTCreation.tdCInvoiceWHTFeeDebitTC * idProRataAllocatedWHT
tWHT.WHTChargeAmtCreditTC = tqCInvoiceWHTForWHTCreation.tdCInvoiceWHTFeeCreditTC * idProRataAllocatedWHT
tWHT.WHTTaxableFeesDebitTC = if tWHT.tc_Status = "N":U and
(tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or
tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION})
then (tqCInvoiceWHTForWHTCreation.tdCInvoiceWHTTaxFeeDebitTC * idProRataAllocatedWHT)
else 0
tWHT.WHTTaxableFeesCreditTC = if tWHT.tc_Status = "N":U and
(tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICECORRECTION})
then (tqCInvoiceWHTForWHTCreation.tdCInvoiceWHTTaxFeeCreditTC * idProRataAllocatedWHT)
else 0
tWHT.WHTTaxableFeesDebitTC = <M-93 RoundAmount
(input tWHT.WHTTaxableFeesDebitTC (idUnroundedAmount),
input ? (iiCurrencyID),
input tInvoiceWHTPayment.tcCurrencyCode (icCurrencyCode)) in BWithholdingTax>
tWHT.WHTTaxableFeesCreditTC = <M-42 RoundAmount
(input tWHT.WHTTaxableFeesCreditTC (idUnroundedAmount),
input ? (iiCurrencyID),
input tInvoiceWHTPayment.tcCurrencyCode (icCurrencyCode)) in BWithholdingTax>
tWHT.WHTAmtDebitTC = if tWHT.tc_Status = "N":U and
(tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or
tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION})
then <M-83 RoundAmount
(input (tInvoiceWHTPayment.tdWHTAmountTC * abs(tqCInvoiceWHTForWHTCreation.tdCInvoiceWHTAmtDebitTC - tqCInvoiceWHTForWHTCreation.tdCInvoiceWHTAmtCreditTC) / idCInvoiceTotalWHTAmtTC) (idUnroundedAmount),
input ? (iiCurrencyID),
input tInvoiceWHTPayment.tcCurrencyCode (icCurrencyCode)) in BWithholdingTax>
else 0
tWHT.WHTAmtCreditTC = if tWHT.tc_Status = "N":U and
(tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICECORRECTION})
then <M-36 RoundAmount
(input (tInvoiceWHTPayment.tdWHTAmountTC * abs(tqCInvoiceWHTForWHTCreation.tdCInvoiceWHTAmtDebitTC - tqCInvoiceWHTForWHTCreation.tdCInvoiceWHTAmtCreditTC) / idCInvoiceTotalWHTAmtTC) (idUnroundedAmount),
input ? (iiCurrencyID),
input tInvoiceWHTPayment.tcCurrencyCode (icCurrencyCode)) in BWithholdingTax>
else 0
tWHT.WHTAmtDebitTC = <M-65 RoundAmount
(input tWHT.WHTAmtDebitTC (idUnroundedAmount),
input ? (iiCurrencyID),
input tInvoiceWHTPayment.tcCurrencyCode (icCurrencyCode)) in BWithholdingTax>
tWHT.WHTAmtCreditTC = <M-4 RoundAmount
(input tWHT.WHTAmtCreditTC (idUnroundedAmount),
input ? (iiCurrencyID),
input tInvoiceWHTPayment.tcCurrencyCode (icCurrencyCode)) in BWithholdingTax>
tWHT.WHTRetainedAmtDebitTC = if tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then (tWHT.WHTAmtCreditTC + vdDiscountCreditTC)
else 0
tWHT.WHTRetainedAmtCreditTC = if tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then 0
else (tWHT.WHTAmtDebitTC + vdDiscountDebitTC)
tWHT.WHTVATAmtDebitTC = if tWHT.tc_Status = "N":U and
(tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or
tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}) and
tqCInvoiceWHTForWHTCreation.tdCInvoiceVatCreditTC <> 0
then (tqCInvoiceWHTForWHTCreation.tdCInvoiceVatCreditTC * tWHT.WHTChargeAmtDebitTC /
tqCInvoiceWHTForWHTCreation.tdCInvoiceVatBaseCreditTC)
else 0
tWHT.WHTVATAmtCreditTC = if tWHT.tc_Status = "N":U and
(tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}) and
tqCInvoiceWHTForWHTCreation.tdCInvoiceVatDebitTC <> 0
then (tqCInvoiceWHTForWHTCreation.tdCInvoiceVatDebitTC * tWHT.WHTChargeAmtCreditTC /
tqCInvoiceWHTForWHTCreation.tdCInvoiceVatBaseDebitTC)
else 0
tWHT.WHTVATAmtDebitTC = <M-78 RoundAmount
(input tWHT.WHTVATAmtDebitTC (idUnroundedAmount),
input ? (iiCurrencyID),
input tInvoiceWHTPayment.tcCurrencyCode (icCurrencyCode)) in BWithholdingTax>
tWHT.WHTVATAmtCreditTC = <M-46 RoundAmount
(input tWHT.WHTVATAmtCreditTC (idUnroundedAmount),
input ? (iiCurrencyID),
input tInvoiceWHTPayment.tcCurrencyCode (icCurrencyCode)) in BWithholdingTax>
/* If The CI holds retained-amounts then the vat amount must both be zero in thw WHT - ticket FIN-4018 */
tWHT.WHTVATAmtDebitTC = if tqCInvoiceWHTForWHTCreation.tdCInvoiceVatDebitTC <> 0 and
tqCInvoiceWHTForWHTCreation.tdCInvoiceVatCreditTC <> 0
then 0
else tWHT.WHTVATAmtDebitTC
tWHT.WHTVATAmtCreditTC = if tqCInvoiceWHTForWHTCreation.tdCInvoiceVatDebitTC <> 0 and
tqCInvoiceWHTForWHTCreation.tdCInvoiceVatCreditTC <> 0
then 0
else tWHT.WHTVATAmtCreditTC
tWHT.WHTTotAmtDebitTC = tWHT.WHTChargeAmtDebitTC + tWHT.WHTVATAmtDebitTC
tWHT.WHTTotAmtCreditTC = tWHT.WHTChargeAmtCreditTC + tWHT.WHTVATAmtCreditTC
tWHT.WHTPaidAmtDebitTC = if tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then (tWHT.WHTTotAmtCreditTC - tWHT.WHTRetainedAmtDebitTC)
else 0
tWHT.WHTPaidAmtCreditTC = if tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then 0
else (tWHT.WHTTotAmtDebitTC - tWHT.WHTRetainedAmtCreditTC)
no-error. /* Needed as we are doing complex calculations in the previous large assign statement */
/* Check for Progress-errors and raise error when needed */
if error-status:error
then do :
assign viLocalReturnStatus = -3
vcMessage = trim(substitute(#T-17'Internal error occured while assigning the details of the Withholding Taxes.':255(206547406)T-17#),"1":U).
if error-status:num-messages > 0
then assign vcMessage = vcMessage + chr(10) +
trim(substitute(#T-57'Detailed info: &1 (&2)':252(49824)T-57#,error-status:Get-Message(1),string(error-status:Get-Number(1)))).
<M-28 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-665815':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BWithholdingTax>
leave FEEBLOCK.
end. /* if error-status:error */
end. /* if tInvoiceWHTPayment.tlCreateWHT = true or */
END. /* FEEBLOCK */
/* ================== */
/* Exception Handling */
/* ================== */
assign oiReturnStatus = viLocalReturnStatus.