project QadFinancials > class BDDocument > method AdditionalUpdatesPostingXrefDI
Description
When the checkbox 'Suspend until Paid status' is ticked, the following functions have to behave for all Payment Instruments in the same way like the Customer Drafts currently do.
Parameters
idAmount | input | decimal | |
icPostingRowid | input | character | |
blStart6 | input-output | logical | |
blStart7 | input-output | logical | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program5/bddocument.p)
/****************************************************************************************/
/* Pre-requisite : tDDocumentInvoiceXref must be available */
/****************************************************************************************/
assign oiReturnStatus = -98.
/* Get Invoice info */
if not blStart7
then do:
<Q-7 run DInvoiceByID (Start) in BDInvoice >
assign blStart7 = true.
end.
<Q-44 run DInvoiceVatForSuspTax (all) (Read) (NoCache)
(input ?, (CompanyId)
input tDDocumentInvoiceXref.DInvoice_ID, (DInvoiceId)
input ?, (DInvoiceVatIsSuspDel)
output dataset tqDInvoiceVatForSuspTax) in BDInvoice >
find first tqDInvoiceVatForSuspTax where
tqDInvoiceVatForSuspTax.tiDInvoice_ID = tDDocumentInvoiceXref.DInvoice_ID
no-error.
if not available tqDInvoiceVatForSuspTax
then do:
<M-9 run SetMessage
(input trim(#T-12'The customer invoice or customer credit note (ID: $1) is not defined in the system.':250(1640)T-12#) (icMessage),
input tDDocumentInvoiceXref.DInvoice_ID (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tDDocumentInvoiceXref.tc_Rowid (icRowid),
input 'QADFIN-2581':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
assign oiReturnStatus = -1.
return.
end. /* if not available DInvoiceVatForSuspTax */
/* =========================================================================================== *
* Calculate movement amount *
* =========================================================================================== */
assign vlIsUndoPayment = tDDocument.tc_Status = 'D':U or
(tDDocument.tc_Status = 'C':U and
(t_iDDocument.DDocumentStatus = {&DOCUMENTSTATUS-ACCEPT} or
t_iDDocument.DDocumentStatus = {&DOCUMENTSTATUS-DISCONT} or
t_iDDocument.DDocumentStatus = {&DOCUMENTSTATUS-INCASSO} or
t_iDDocument.DDocumentStatus = {&DOCUMENTSTATUS-PORTFOLIO} or
t_iDDocument.DDocumentStatus = {&DOCUMENTSTATUS-PAIDCON} or
t_iDDocument.DDocumentStatus = {&DOCUMENTSTATUS-PAID}) and
(tDDocument.DDocumentStatus = {&DOCUMENTSTATUS-VOID} or
tDDocument.DDocumentStatus = {&DOCUMENTSTATUS-BOUNCED} or
tDDocument.DDocumentStatus = {&DOCUMENTSTATUS-INIT}))
vdAmount = if tDDocumentInvoiceXref.tc_Status = "N":U
then tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC
else if vlIsUndoPayment
then - t_iDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC
else tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC -
t_iDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC.
/* Create DInvoice Movement */
if vdAmount <> 0
then do:
create tDIMovementDDoc.
assign tDIMovementDDoc.tiDInvoiceId = tDDocumentInvoiceXref.DInvoice_ID
tDIMovementDDoc.tcGLAccountDivisionCode = tqDInvoiceVatForSuspTax.tcDivisionCode
tDIMovementDDoc.tcPostingRowId = icPostingRowId
tDIMovementDDoc.tlMovementIsForDraft = (tDDocument.DDocumentType = {&DOCUMENTTYPE-DRAFT})
tDIMovementDDoc.tiDDocumentId = tDDocument.DDocument_ID
tDIMovementDDoc.tlIsUndoPayment = vlIsUndoPayment.
if tDIMovementDDoc.tlMovementIsForDraft <> true
then do:
<Q-68 run CompanyPropertyBySuspDelTax (all) (Read) (Cache)
(input tqDInvoiceVatForSuspTax.tiCompany_ID, (CompanyId)
input ?, (DelTax)
input ?, (SuspTax)
output dataset tqCompanyPropertyBySuspDelTax) in BCompanyProperty>
find first tqCompanyPropertyBySuspDelTax where
tqCompanyPropertyBySuspDelTax.tiCompany_ID = tqDInvoiceVatForSuspTax.tiCompany_ID
no-error.
if available tqCompanyPropertyBySuspDelTax
then do:
if (tqCompanyPropertyBySuspDelTax.tlCompanyPropertyIsSuspPaid = true and
tqCompanyPropertyBySuspDelTax.tcCompanyPropertySuspTax <> {&SUSPDELAYTAX-NOTAPPLICABLE})
then assign tDIMovementDDoc.tlMovementIsForDraft = true.
end. /* if available tqCompanyPropertyBySuspDelTax */
end. /* if tDIMovementDDoc.tlMovementIsForDraft <> true */
/* Prepayment */
if tqDInvoiceVatForSuspTax.tcDInvoiceType = {&INVOICETYPE-PREPAYMENT}
then if tDDocumentInvoiceXref.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-CREDIT}
then if vdAmount > 0
then assign tDIMovementDDoc.tdAmountCreditTC = vdAmount.
else assign tDIMovementDDoc.tdAmountDebitTC = - vdAmount.
else if vdAmount > 0
then assign tDIMovementDDoc.tdAmountDebitTC = vdAmount.
else assign tDIMovementDDoc.tdAmountCreditTC = - vdAmount.
else do:
if tqDInvoiceVatForSuspTax.tcDInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or
tqDInvoiceVatForSuspTax.tcDInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}
then do:
/* invoice */
if tqDInvoiceVatForSuspTax.tdDInvoiceOriginalDebitTC <> 0 and
tqDInvoiceVatForSuspTax.tdDInvoiceOriginalDebitTC <> ?
then if tDDocumentInvoiceXref.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-CREDIT}
then if vlIsUndoPayment
then assign tDIMovementDDoc.tdAmountDebitTC = - vdAmount.
else assign tDIMovementDDoc.tdAmountCreditTC = vdAmount.
else if vlIsUndoPayment
then assign tDIMovementDDoc.tdAmountCreditTC = - vdAmount.
else assign tDIMovementDDoc.tdAmountDebitTC = vdAmount.
/* Credit note */
else if tDDocumentInvoiceXref.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then if vlIsUndoPayment
then assign tDIMovementDDoc.tdAmountCreditTC = - vdAmount.
else assign tDIMovementDDoc.tdAmountDebitTC = vdAmount.
else if vlIsUndoPayment
then assign tDIMovementDDoc.tdAmountDebitTC = - vdAmount.
else assign tDIMovementDDoc.tdAmountCreditTC = vdAmount.
end.
else do:
/* invoice */
if tqDInvoiceVatForSuspTax.tdDInvoiceOriginalDebitTC <> 0 and
tqDInvoiceVatForSuspTax.tdDInvoiceOriginalDebitTC <> ?
then if tDDocumentInvoiceXref.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-CREDIT}
then if vdAmount > 0
then assign tDIMovementDDoc.tdAmountCreditTC = vdAmount. /* payment create */
else assign tDIMovementDDoc.tdAmountDebitTC = - vdAmount. /* payment undo/decrease */
else if vdAmount > 0
then assign tDIMovementDDoc.tdAmountDebitTC = vdAmount.
else assign tDIMovementDDoc.tdAmountCreditTC = - vdAmount.
/* Credit note */
else if tDDocumentInvoiceXref.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then if vdAmount > 0
then assign tDIMovementDDoc.tdAmountDebitTC = vdAmount. /* payment create */
else assign tDIMovementDDoc.tdAmountCreditTC = - vdAmount. /* payment undo/decrease */
else if vdAmount > 0
then assign tDIMovementDDoc.tdAmountCreditTC = vdAmount.
else assign tDIMovementDDoc.tdAmountDebitTC = - vdAmount.
end. /* end else if tqDInvoiceVatForSuspTax.tcDInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or */
end.
end.
/* when you change status of a 'Draft' payment to paid, then the posting lines to balance the */
/* suspended tax posting lines to normal tax posting lines must be created. */
if tqDInvoiceVatForSuspTax.tlDInvoiceVatIsSuspDel = true
then do:
<Q-77 run CompanyPropertyBySuspDelTax (all) (Read) (Cache)
(input tqDInvoiceVatForSuspTax.tiCompany_ID, (CompanyId)
input ?, (DelTax)
input ?, (SuspTax)
output dataset tqCompanyPropertyBySuspDelTax) in BCompanyProperty>
find first tqCompanyPropertyBySuspDelTax where
tqCompanyPropertyBySuspDelTax.tiCompany_ID = tqDInvoiceVatForSuspTax.tiCompany_ID
no-error.
if available tqCompanyPropertyBySuspDelTax
then do:
if tDDocument.DDocumentType = {&DOCUMENTTYPE-DRAFT} or
(tqCompanyPropertyBySuspDelTax.tlCompanyPropertyIsSuspPaid = true and
tqCompanyPropertyBySuspDelTax.tcCompanyPropertySuspTax <> {&SUSPDELAYTAX-NOTAPPLICABLE})
then do:
for each tqDInvoiceVatForSuspTax where
tqDInvoiceVatForSuspTax.tiCompany_ID = tqCompanyPropertyBySuspDelTax.tiCompany_ID :
<M-42 run AdditionalUpdatesPostingXrefDISuspTax
(input icPostingRowid (icPostingRowId),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
end.
end. /* if tDDocument.DDocumentType = {&DOCUMENTTYPE-DRAFT} and */
end. /* if available tqCompanyPropertyBySuspDelTax */
find first tqDInvoiceVatForSuspTax no-error.
end.
/* ==================================================================================== *
* Create Posting on Discount Account *
* ==================================================================================== */
<M-45 run AdditionalUpdatesPostingXrefDIDisc
(input icPostingRowid (icPostingRowid),
input tqDInvoiceVatForSuspTax.tcDInvoiceType (icDInvoiceType),
input vlIsUndoPayment (ilIsUndoPayment),
output vdMovementDiscountTC (odMovementDiscountTC),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
<M-28 run AdditionalUpdatesPostingXrefDIInt
(input icPostingRowID (icPostingRowid),
input vlIsUndoPayment (ilIsUndoPayment),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
if vdMovementDiscountTC <> 0 and available tDIMovementDDoc
then assign tDIMovementDDoc.tdMovementDiscountTC = vdMovementDiscountTC.
if oiReturnStatus = -98
then assign oiReturnStatus = 0.