project QadFinancials > class BCInvoice > method ValidateCInvoiceMovementCrossCy
Parameters
iiPostingLine_ID | input | integer | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program7/bcinvoice.p)
/* In Cross Company Daemon, it will recalculate the LC and CC amount by the invoice rate. It is not necessary to check LC balance
Therefore, the logic for LC is removed on 2014.
*/
assign oiReturnStatus = -98.
empty temp-table tPostingPostingLineInfoCIJE.
assign vdCInvoiceBalanceCreditTC = 0
vdCInvoiceBalanceDebitTC = 0.
create tPostingPostingLineInfoCIJE.
assign tPostingPostingLineInfoCIJE.tiPostingLine_ID = iiPostingLine_ID.
<M-33 run GetPostingInfoByPostingLineIDTT
(input-output tPostingPostingLineInfoCIJE (tPostingPostingLineInfo),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
if can-find(first tPostingPostingLineInfoCIJE where
tPostingPostingLineInfoCIJE.tiPostingLine_ID = iiPostingLine_ID and
tPostingPostingLineInfoCIJE.ttPostingDate < tqCInvoiceByCyIDYearJrnlVchr.ttCInvoicePostingDate)
then do:
vcDatetemp = <M-38 DisplayDate (input tqCInvoiceByCyIDYearJrnlVchr.ttCInvoicePostingDate (itDate)) in BCInvoice>.
<M-29 run SetMessage
(input #T-51'Date of an AP Movement can not be earlier then the Customer Invoice Posting Date.':255(96634314)T-51# (icMessage),
input '':U (icArguments),
input 'tCInvoice.CInvoicepostingDate' (icFieldName),
input vcDatetemp (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-445008':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
assign oiReturnStatus = -1.
end. /* if can-find(first tPostingPostingLineInfoDIJE where */
/* Update temporary balance fields; */
assign vdCInvoiceBalanceDebitTC = tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceDebitTC
vdCInvoiceBalanceCreditTC = tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceCreditTC.
if tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceDebitTC <> ? and tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceDebitTC <> 0
then assign vdCInvoiceBalanceDebitTC = tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceDebitTC - tMovement.tdAmountCreditTC + tMovement.tdAmountDebitTC.
else do:
if tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceCreditTC <> ? and tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceCreditTC <> 0
then assign vdCInvoiceBalanceCreditTC = vdCInvoiceBalanceCreditTC + tMovement.tdAmountCreditTC - tMovement.tdAmountDebitTC.
/* The invoice has been fully allocated, it is not the last movement. */
else assign vdCInvoiceBalanceDebitTC = tMovement.tdAmountDebitTC /* set the invoice back to the last movement */
vdCInvoiceBalanceCreditTC = tMovement.tdAmountCreditTC.
end.
/* The below validation is also done in ValidateComponentBalances for non cross company payments*/
/* =================================================================================== */
/* This method validates the new balance of any CInvoice. The rule is as follows : */
/* The Balance of an invoice of any type should follow the same sign as type as */
/* the original amount of the invoice */
/* example: */
/* - an AP Invoice will have OriginalDebit = 0 and OriginalCredit > 0, so the */
/* BalanceDebit must always be <> 0 and the Balancecredit must always be > 0 */
/* - an AP Credit Note will have OriginalDebit > 0 and OriginalCredit = 0, so the */
/* BalanceDebit must always be > 0 and the Balancecredit must always be = 0 */
/* - an AP Invoice Note Correction will have OriginalDebit = 0 and OriginalCredit < 0 */
/* so the BalanceDebit must always be = 0 and the Balancecredit must always be < 0 */
/* =================================================================================== */
/* Note there is no test that the balance of an invoice gets 'higher' than the original*/
/* amount. Probably this is not a real business case, but just know the system does */
/* support this. */
/* =================================================================================== */
/**************************************************************************/
/* For AP invoices, there can never be a debit balance */
/* Only t_sCInvoice.CInvoiceBalanceCreditTC can have a value which is > 0 */
/**************************************************************************/
assign vcMessage = vcCompanyCode + '/' +
string ( tqCInvoiceByCyIDYearJrnlVchr.tiCInvoicePostingYear) + '/' +
string ( tqCInvoiceByCyIDYearJrnlVchr.tiCInvoiceVoucher) + ' ' +
tqCInvoiceByCyIDYearJrnlVchr.tcCInvoiceType + ' TC:' +
string ( tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceOriginalDebitTC) + ' ' +
string ( tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceOriginalCreditTC) + '; ' +
string (vdCInvoiceBalanceDebitTC) + ' ' +
string (vdCInvoiceBalanceCreditTC).
if tqCInvoiceByCyIDYearJrnlVchr.tcCInvoiceType = {&INVOICETYPE-INVOICE} and
(vdCInvoiceBalanceCreditTC < 0 or vdCInvoiceBalanceDebitTC <> 0)
then do:
<M-21 run SetMessage
(input #T-24'A supplier invoice can never have or get a debit balance.':255(985908664)T-24# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-762093':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input vcMessage (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
assign oiReturnStatus = -1.
end.
/* ********************************************************************* */
/* AP credit notes can never have a credit balance */
/* Only t_sCInvoice.CInvoiceBalanceDebitTC can have a value which is > 0 */
/*************************************************************************/
if tqCInvoiceByCyIDYearJrnlVchr.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} and
(vdCInvoiceBalanceCreditTC <> 0 or vdCInvoiceBalanceDebitTC < 0)
then do:
<M-52 run SetMessage
(input #T-30'A supplier credit note can never have or get a credit balance.':255(548911721)T-30# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-519542':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input vcMessage (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
assign oiReturnStatus = -1.
end.
else
/*************************************************************************************************************/
/* For all other invoice types, the balance field should follow the same sign and type as the original field */
/*************************************************************************************************************/
if tqCInvoiceByCyIDYearJrnlVchr.tcCInvoiceType <> {&INVOICETYPE-INVOICE} and
tqCInvoiceByCyIDYearJrnlVchr.tcCInvoiceType <> {&INVOICETYPE-CREDITNOTE}
then do:
/* Check in TC */
if ( tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceOriginalDebitTC > 0 and (vdCInvoiceBalanceDebitTC < 0 or vdCInvoiceBalanceCreditTC <> 0)) or
( tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceOriginalDebitTC < 0 and (vdCInvoiceBalanceDebitTC > 0 or vdCInvoiceBalanceCreditTC <> 0)) or
( tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceOriginalCreditTC > 0 and (vdCInvoiceBalanceCreditTC < 0 or vdCInvoiceBalanceDebitTC <> 0)) or
( tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceOriginalCreditTC < 0 and (vdCInvoiceBalanceCreditTC > 0 or vdCInvoiceBalanceDebitTC <> 0))
then do:
<M-42 run SetMessage
(input #T-86'A supplier invoice of type '$1' can not be overallocated. The balance should be the same sign (pos/neg) or type (Dt/Cr) as the original amount.':255(259045209)T-86# (icMessage),
input tqCInvoiceByCyIDYearJrnlVchr.tcCInvoiceType (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-707471':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input vcMessage (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
assign oiReturnStatus = -1.
end.
end.
if oiReturnStatus = -98
then assign oiReturnStatus = 0.