Description
This method add 2 postinglines one to reverse the existing suspended tax account, and one to create new line for the normal tax account. Also update the tax records of the invoice
Parameters
iiBJournalEntryID | input | integer | Instance Id of Journal Entry |
tMoveSuspendedTax | input | temp-table | |
ilIsInstanceBJEAlreadyOpened | input | logical | Is the instance of bjournalentry already opened or not ? |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program6/bdinvoice.p)
/* =================================================================================================== */
/* Method : MoveSuspendedTax */
/* Desc : This method add 2 postinglines one to reverse the existing suspended tax account, and */
/* one to create new line for the normal tax account. Also update the tax records of the */
/* invoice */
/* --------------------------------------------------------------------------------------------------- */
/* Params: (I) tMoveSuspendedTax */
/* (I) iiJournalEntryId Instance Id of the Started JournalEntry */
/* =================================================================================================== */
if ilIsInstanceBJEAlreadyOpened = ? then assign ilIsInstanceBJEAlreadyOpened = false.
assign oiReturnStatus = -98.
find first tMoveSuspendedTax no-error.
if not available tMoveSuspendedTax
then do:
assign vcMessage = trim(#T-12'You must define the input for the method that moves Suspended tax account to Normal tax account':200(70337)T-12#)
oiReturnStatus = -1.
<M-13 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-8363':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
return.
end.
/* Start the query before the loop */
<Q-1 run DInvoicePostingForSuspTax (Start) in BDInvoice >
/* OPen the same instance */
if iiBJournalEntryID <> 0 and iiBJournalEntryID <> ?
then assign viBJournalEntryDIID = iiBJournalEntryID.
if viBJournalEntryDIID <> 0 and viBJournalEntryDIID <> ?
then do:
if ilIsInstanceBJEAlreadyOpened = false
then do:
<I-2 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
end.
end.
else do:
<I-3 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BJournalEntry"}>
assign vlBJEIsStartedFromDI = true.
end.
FOREACHMOVESUSPENDEDTAX: DO:
for each tMoveSuspendedTax:
/* replace unknown values */
if tMoveSuspendedTax.tcPostingRowId = ? then assign tMoveSuspendedTax.tcPostingRowId ='':U.
if tMoveSuspendedTax.tdSuspTaxAmountTC = ? then assign tMoveSuspendedTax.tdSuspTaxAmountTC = 0.
if tMoveSuspendedTax.tiDInvoiceId = ? then assign tMoveSuspendedTax.tiDInvoiceId = 0.
if tMoveSuspendedTax.tiDInvoiceId = 0
then do:
assign vcMessage = trim(#T-15'You must enter the invoice number.':200(70338)T-15#)
oiReturnStatus = -1.
<M-16 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-8366':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
leave FOREACHMOVESUSPENDEDTAX.
end.
if tMoveSuspendedTax.tdSuspTaxAmountTC = 0
then do:
assign vcMessage = trim(#T-17'You must enter the transaction amount for the suspended tax account.':255(70369)T-17#)
oiReturnStatus = -1.
<M-18 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-8367':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
leave FOREACHMOVESUSPENDEDTAX.
end.
<Q-4 run DInvoicePostingForSuspTax (all) (Read) (NoCache)
(input ?, (CompanyId)
input tMoveSuspendedTax.tiDInvoiceId, (DInvoiceId)
input true, (DInvoiceVatIsSuspDel)
output dataset tqDInvoicePostingForSuspTax) in BDInvoice >
if not can-find(first tqDInvoicePostingForSuspTax where
tqDInvoicePostingForSuspTax.tiDInvoice_ID = tMoveSuspendedTax.tiDInvoiceId and
tqDInvoicePostingForSuspTax.tlDInvoiceVatIsSuspDel = true and
tqDInvoicePostingForSuspTax.tiPostingVat_ID <> ? and
tqDInvoicePostingForSuspTax.tiPostingVat_ID <> 0)
then do:
assign vcMessage = trim(#T-27'This invoice is created with suspended tax prior to converting to QAD2008.':255(71078)T-27#) +
trim(#T-28'The system does not have enough information for posting to the normal tax account.':255(71079)T-28#) + chr(10) +
trim(#T-29'You have to do this manually with a zero total invoice that posts to the normal tax account and backs out the suspended tax account.':255(71080)T-29#).
oiReturnStatus = +1.
<M-26 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8599':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
leave FOREACHMOVESUSPENDEDTAX.
end.
for each tqDInvoicePostingForSuspTax where
tqDInvoicePostingForSuspTax.tiDInvoice_ID = tMoveSuspendedTax.tiDInvoiceId and
tqDInvoicePostingForSuspTax.tlDInvoiceVatIsSuspDel = true and
tqDInvoicePostingForSuspTax.tiDInvoiceVat_ID = tMoveSuspendedTax.tiDInvoiceVatId :
/* if Suspended Delayed tax can only be posted in the same company as the invoice*/
if viCompanyId <> tqDInvoicePostingForSuspTax.tiCompany_ID
then do:
next.
end.
assign vdVatDebitTC = if tqDInvoicePostingForSuspTax.tcDInvoiceType = {&INVOICETYPE-INVOICE} or
tqDInvoicePostingForSuspTax.tcDInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then 0
else tMoveSuspendedTax.tdSuspTaxAmountTC
vdVatCreditTC= if tqDInvoicePostingForSuspTax.tcDInvoiceType = {&INVOICETYPE-INVOICE} or
tqDInvoicePostingForSuspTax.tcDInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then tMoveSuspendedTax.tdSuspTaxAmountTC
else 0
vdVatDebitLC = <M-24 RoundAmount
(input vdVatDebitTC * tqDInvoicePostingForSuspTax.tdPostingLineExchangeRate * tqDInvoicePostingForSuspTax.tdPostingLineRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in business>
vdVatCreditLC= <M-25 RoundAmount
(input vdVatCreditTC * tqDInvoicePostingForSuspTax.tdPostingLineExchangeRate * tqDInvoicePostingForSuspTax.tdPostingLineRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in business>.
/* get tax rate date type form CompanyProperty table */
<Q-30 run CompanyPropertyBySuspDelTax (all) (Read) (NoCache)
(input tqDInvoicePostingForSuspTax.tiCompany_ID, (CompanyId)
input ?, (DelTax)
input ?, (SuspTax)
output dataset tqCompanyPropertyBySuspDelTax) in BCompanyProperty>
find first tqCompanyPropertyBySuspDelTax no-error.
if available tqCompanyPropertyBySuspDelTax
then do:
assign vcTaxRateType = tqCompanyPropertyBySuspDelTax.tcCompanyPropertySusTaxDateType.
end.
/* if tax rate type is '' or ? then assign it to INVOICEDATE */
if vcTaxRateType = ? or vcTaxRateType = ''
then do:
assign vcTaxRateType = {&TAXDATETYPE-INVOICEDATE}.
end.
<M-6 run AddPostingLineTaxForSuspDel
(input tMoveSuspendedTax.tcPostingRowId (icPostingTcRowid),
input tMoveSuspendedTax.ttPaymentTaxPointDate (itPaymentTaxPointDate),
input tqDInvoicePostingForSuspTax.ttDInvoiceTaxPointDate (itInvoiceTaxPointDate),
input tqDInvoicePostingForSuspTax.tcDInvoiceDIText (icPostingLineText),
input tqDInvoicePostingForSuspTax.tcCurrencyCode (icCurrencyCode),
input tqDInvoicePostingForSuspTax.tcSuspTaxGLCode (icSuspDelTaxGLCode),
input tqDInvoicePostingForSuspTax.tcSuspTaxDivisionCode (icSuspDelTaxDivisionCode),
input tqDInvoicePostingForSuspTax.tcNormalTaxGLCode (icNormalTaxGLCode),
input tqDInvoicePostingForSuspTax.tcNormalTaxDivisionCode (icNormalTaxDivisionCode),
input tqDInvoicePostingForSuspTax.tcPostingVatInOut (icPostingVatInOut),
input tqDInvoicePostingForSuspTax.tcVatCode (icPostingVatCode),
input tqDInvoicePostingForSuspTax.tcDomainCode (icPostingVatDomain),
input tqDInvoicePostingForSuspTax.tdPostingLineExchangeRate (idExchangeRate),
input tqDInvoicePostingForSuspTax.tdPostingLineRateScale (idExchangeRateScale),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType),
input tqDInvoicePostingForSuspTax.tcPostingVatTransType (icTransactionType),
input tqDInvoicePostingForSuspTax.tcPostingVatTaxTransType (icTaxTransactionType),
input tqDInvoicePostingForSuspTax.tdPostingVatBaseDebitTC (idBaseDebitTC),
input tqDInvoicePostingForSuspTax.tdPostingVatBaseCreditTC (idBaseCreditTC),
input tqDInvoicePostingForSuspTax.tdPostingVatBaseDebitLC (idBaseDebitLC),
input tqDInvoicePostingForSuspTax.tdPostingVatBaseCreditLC (idBaseCreditLC),
input tqDInvoicePostingForSuspTax.tdPostingVatBaseDebitCC (idBaseDebitCC),
input tqDInvoicePostingForSuspTax.tdPostingVatBaseCreditCC (idBaseCreditCC),
input vdVatDebitTC (idVatDebitTC),
input vdVatCreditTC (idVatCreditTC),
input vdVatDebitLC (idVatDebitLC),
input vdVatCreditLC (idVatCreditLC),
input ? (idVatDebitCC),
input ? (idVatCreditCC),
input tqDInvoicePostingForSuspTax.tcFromTxzTaxZone (icFromTaxZone),
input tqDInvoicePostingForSuspTax.tcToTxzTaxZone (icToTaxZone),
input tqDInvoicePostingForSuspTax.tcTxenvTaxEnv (icTaxEnv),
input tqDInvoicePostingForSuspTax.tlDInvoiceVatIsTaxable (ilIsTaxable),
input tqDInvoicePostingForSuspTax.tcTxclTaxCls (icTaxClass),
input tqDInvoicePostingForSuspTax.tcTxuTaxUsage (icTaxUsage),
input tqDInvoicePostingForSuspTax.tcTxtyTaxType (icTaxType),
input tqDInvoicePostingForSuspTax.tlPostingVatIsReverseCharge (ilIsRevCharge),
input ? (iiTaxAddressID),
input tqDInvoicePostingForSuspTax.tcPostingVatTaxIDFeder (icTaxIDFederal),
input tqDInvoicePostingForSuspTax.tcPostingVatOwnTaxIDState (icTaxIDState),
input tqDInvoicePostingForSuspTax.tcPostingVatTaxIDMisc1 (icTaxIDMisc1),
input tqDInvoicePostingForSuspTax.tcPostingVatTaxIDMisc2 (icTaxIDMisc2),
input tqDInvoicePostingForSuspTax.tcPostingVatTaxIDMisc3 (icTaxIDMisc3),
input ? (iiOwnAddressID),
input tqDInvoicePostingForSuspTax.tcPostingVatOwnTaxIDFeder (icOwnTaxIDFedral),
input tqDInvoicePostingForSuspTax.tcPostingVatOwnTaxIDState (icOwnTaxIDState),
input tqDInvoicePostingForSuspTax.tcPostingVatOwnTaxIDMisc1 (icOwnTaxIDMisc1),
input tqDInvoicePostingForSuspTax.tcPostingVatOwnTaxIDMisc2 (icOwnTaxIDMisc2),
input tqDInvoicePostingForSuspTax.tcPostingVatOwnTaxIDMisc3 (icOwnTaxIDMisc3),
input tqDInvoicePostingForSuspTax.tiPostingVatOwnTaxDeclarat (iiOwnTaxDecl),
input tqDInvoicePostingForSuspTax.ttDInvoicePostingDate (itInvoicePostingDate),
input vcTaxRateType (icTaxRateType),
input no (ilIsDelayedTax),
input ? (itInvoiceExchangeRateDate),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then leave FOREACHMOVESUSPENDEDTAX.
/* Create records to update tax records of invoice */
create tUpdateDInvoiceVat.
assign tUpdateDInvoiceVat.tiDInvoiceId = tMoveSuspendedTax.tiDInvoiceId
tUpdateDInvoiceVat.tiDInvoiceVatId = tqDInvoicePostingForSuspTax.tiDInvoiceVat_ID
tUpdateDInvoiceVat.tdSuspTaxAmountTC = tMoveSuspendedTax.tdSuspTaxAmountTC.
end. /* for each tqDInvoicePostingForSuspTax */
end. /* for each tMoveSuspendedTax */
end. /* FOREACHMOVESUSPENDEDTAX */
if ilIsInstanceBJEAlreadyOpened = false
then. /* ========================================================================================================= */
/* Normally we would here close BJournalEntry we will not do it for performance */
/* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it. */
/* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the */
/* appserver that is executed after each call to the appserver */
/* ========================================================================================================= */
/* Stop the query */
<Q-7 run DInvoicePostingForSuspTax (Stop) in BDInvoice >
if can-find (first tUpdateDInvoiceVat)
then do:
<M-19 run UpdateDInvoiceVat
(input tUpdateDInvoiceVat (tUpdateDInvoiceVat),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
end.
if oiReturnStatus = -98 then assign oiReturnStatus = 0.