project QadFinancials > class BDInvoice > method ValidateComponentAllLinkedInvoices
Description
This method is a submethod of ValidateComponentAll.
This method validates the Linked Invoice of the Debtor Invoice.
Parameters
blStart1 | input-output | logical | to see if we need to stop the query |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program5/bdinvoice.p)
/* validate link to invoice */
/* if no linked invoice then return*/
if t_sDInvoice.LinkedDInvoice_ID = 0 or
t_sDInvoice.LinkedDInvoice_ID = ?
then return.
/* Invoices and FinCharges cannot be linked */
if t_sDInvoice.DInvoiceType = {&INVOICETYPE-INVOICE} or
t_sDInvoice.DInvoiceType = {&INVOICETYPE-FINANCECHARGE}
then do:
assign vcMessage = trim(substitute(#T-8'Link To Invoice is not allowed for &1 and &2.':150(62674)T-8#, {&INVOICETYPE-INVOICE-TR}, {&INVOICETYPE-FINANCECHARGE-TR})) + chr(10) +
trim(substitute(#T-9'GL Calendar Year = &1; Period = &2; Daybook = &3; Voucher = &4.':500(62675)T-9#,string(t_sDInvoice.DInvoicePostingYear),string(t_sDInvoice.DInvoicePostingPeriod), t_sDInvoice.tcJournalCode, string(t_sDInvoice.DInvoiceVoucher)))
oiReturnStatus = -1.
<M-1 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input 'tDInvoice.DInvoiceType':U (icFieldName),
input t_sDInvoice.DInvoiceType (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sDInvoice.tc_Rowid (icRowid),
input 'QadFin-6402':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end. /* if t_sDInvoice.DInvoiceType = {&INVOICETYPE-INVOICE} or */
/* Find the customer invoice that the current invoice is linked to via field t_sDInvoice.LinkedDInvoice_ID */
/* Note we can either find it in our business-instance (btsDInvoice) or in the db (tqDInvoiceByDebtStatusCurr) */
/* After this block we either have a btsDInvoice, either a tqDInvoiceByDebtStatusCurr available */
find first btsDInvoice where
btsDInvoice.Company_ID = viCompanyId and
btsDInvoice.DInvoice_ID = t_sDInvoice.LinkedDInvoice_ID no-error.
if not available btsDInvoice
then do:
if blStart1 = false
then do:
<Q-59 run DInvoiceByDebtStatusCurr (Start) in BDInvoice >
assign blStart1 = true.
end. /* if blStart1 = false */
<Q-60 run DInvoiceByDebtStatusCurr (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input t_sDInvoice.LinkedDInvoice_ID, (DInvoiceId)
input t_sDInvoice.Debtor_ID, (DebtorId)
input ?, (DebtorCode)
input ?, (CurrencyId)
input ?, (CurrencyCode)
input ?, (DInvoiceIsOpen)
input ?, (DInvoiceIsSelected)
input ?, (DInvoiceBalanceDebitTC)
input ?, (SkipRowId)
input ?, (DInvoiceType)
output dataset tqDInvoiceByDebtStatusCurr) in BDInvoice >
find first tqDInvoiceByDebtStatusCurr where
tqDInvoiceByDebtStatusCurr.tiDInvoice_ID = t_sDInvoice.LinkedDInvoice_ID
no-error.
if not available tqDInvoiceByDebtStatusCurr
then do:
assign vcMessage = #T-62'The linked invoice is not defined in the system or is invalid. ':255(65725)T-62#
oiReturnStatus = -1.
<M-61 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input 'tDInvoice.DInvoiceType':U (icFieldName),
input t_sDInvoice.DInvoiceType (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sDInvoice.tc_Rowid (icRowid),
input 'QadFin-7383':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
return.
end. /* if not available tqDInvoiceByDebtStatusCurr */
end. /* if not available btsDInvoice */
/* Check if the invoice-type of the current invoice and the linked invoice are types that can be linked to each other */
if t_sDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTE} and
((available btsDInvoice and
btsDInvoice.DInvoiceType <> {&INVOICETYPE-INVOICE} and
btsDInvoice.DInvoiceType <> {&INVOICETYPE-FINANCECHARGE}) or
(tqDInvoiceByDebtStatusCurr.tcDInvoiceType <> {&INVOICETYPE-INVOICE} and
tqDInvoiceByDebtStatusCurr.tcDinvoiceType <> {&INVOICETYPE-FINANCECHARGE}))
then do:
assign vcMessage = #T-47'You can only link &1 and &2 to &3.':200(63195)T-47#
oiReturnStatus = -1.
<M-45 run SetMessage
(input vcMessage (icMessage),
input {&INVOICETYPE-INVOICE-TR},{&INVOICETYPE-FINANCECHARGE-TR},{&INVOICETYPE-CREDITNOTE-TR} (icArguments),
input 'tDInvoice.DInvoiceType':U (icFieldName),
input t_sDInvoice.DInvoiceType (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sDInvoice.tc_Rowid (icRowid),
input 'QadFin-7378':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end. /* if t_sDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTE} and */
if t_sDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} and
((available btsDInvoice and
btsDInvoice.DInvoiceType <> {&INVOICETYPE-CREDITNOTE}) or
(tqDInvoiceByDebtStatusCurr.tcDInvoiceType <> {&INVOICETYPE-CREDITNOTE}))
then do:
assign vcMessage = #T-65'You can only link &1 to &2.':200(63196)T-65#
oiReturnStatus = -1.
<M-63 run SetMessage
(input vcMessage (icMessage),
input {&INVOICETYPE-CREDITNOTE-TR},{&INVOICETYPE-CREDITNOTECORRECTION-TR} (icArguments),
input 'tDInvoice.DInvoiceType':U (icFieldName),
input t_sDInvoice.DInvoiceType (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sDInvoice.tc_Rowid (icRowid),
input 'QadFin-7385':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end. /* if t_sDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} and */
if t_sDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION} and
((available btsDInvoice and
btsDInvoice.DInvoiceType <> {&INVOICETYPE-INVOICE}) or
(tqDInvoiceByDebtStatusCurr.tcDInvoiceType <> {&INVOICETYPE-INVOICE}))
then do:
assign vcMessage = #T-67'You can only link &1 to &2.':200(63196)T-67#
oiReturnStatus = -1.
<M-66 run SetMessage
(input vcMessage (icMessage),
input {&INVOICETYPE-INVOICE-TR},{&INVOICETYPE-INVOICECORRECTION-TR} (icArguments),
input 'tDInvoice.DInvoiceType':U (icFieldName),
input t_sDInvoice.DInvoiceType (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sDInvoice.tc_Rowid (icRowid),
input 'QadFin-7386':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end. /* if t_sDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION} and */
/* Validate that the currency of the correction invoice and the linked invoice are the same */
if t_sDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} or
t_sDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then do :
if ((available btsDInvoice and
btsDInvoice.DInvoiceCurrency_ID <> t_sDinvoice.DinvoiceCurrency_ID) or
(available tqDInvoiceByDebtStatusCurr and
tqDInvoiceByDebtStatusCurr.tiDInvoiceCurrency_ID <> t_sDinvoice.DinvoiceCurrency_ID))
then do :
assign vcMessage = trim(substitute(#T-5'The correction currency (&1) must match the linked invoice currency (&2).':255(65105)T-5#,
t_sDInvoice.tcCurrencyCode,
(if available btsDInvoice
then btsDInvoice.tcCurrencyCode
else tqDInvoiceByDebtStatusCurr.tcCurrencyCode)))
oiReturnStatus = -1.
<M-11 run SetMessage
(input vcMessage (icMessage),
input '' (icArguments),
input 'tDInvoice.tcCurrencyCode':U (icFieldName),
input t_sDInvoice.tcCurrencyCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'qadfin-385999':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end. /* if ((available btsDInvoice and */
end. /* if t_sDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} or */
<Q-80 run JournalByJournalIDCodeType (all) (Read) (NoCache)
(input ?, (CompanyId)
input t_sDInvoice.Journal_ID, (JournalID)
input t_sDInvoice.tcJournalCode, (JournalCode)
input ?, (JournalTypeCode)
output dataset tqJournalByJournalIDCodeType) in BJournal>
find first tqJournalByJournalIDCodeType where
tqJournalByJournalIDCodeType.tiJournal_ID = t_sDInvoice.Journal_ID and
tqJournalByJournalIDCodeType.tcJournalCode = t_sDInvoice.tcJournalCode
no-lock no-error.
if available tqJournalByJournalIDCodeType
then assign vcDaybookControl = tqJournalByJournalIDCodeType.tcJournalControl.
/* Raise error in case the "Allow Closed Inv Corr" (on the SO-Control-file) is set to false and the linked invoice is no longer open */
<Q-98 run SOAccountingControlByDomain (all) (Read) (NoCache)
(input vcDomainCode, (Domain)
output dataset tqSOAccountingControlByDomain) in BMfgSOAccountingControl >
find first tqSOAccountingControlByDomain no-error.
if available tqSOAccountingControlByDomain and
tqSOAccountingControlByDomain.tisoc__qad03 <> 1 or vcDaybookControl = {&JOURNALCONTROL-FINANCIAL}
then do:
if t_sDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} or
t_sDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or
t_sDinvoice.DinvoiceType = {&INVOICETYPE-CREDITNOTE}
then do:
if ((t_sDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or t_sDinvoice.DinvoiceType = {&INVOICETYPE-CREDITNOTE}) and
((available btsDInvoice and
btsDInvoice.tc_Status <> "D":U and
(btsDInvoice.DInvoiceIsOpen <> true or
btsDInvoice.DInvoiceIsSelected <> false or
btsDInvoice.DInvoiceBalanceDebitTC < t_sDInvoice.DInvoiceOriginalDebitTC)
) or
(available tqDInvoiceByDebtStatusCurr and
(tqDInvoiceByDebtStatusCurr.tlDInvoiceIsOpen <> true or
tqDInvoiceByDebtStatusCurr.tlDInvoiceIsSelected <> false or
tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceDebitTC < t_sDinvoice.DinvoiceOriginalDebitTC)
)
)
) OR
(t_sDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} and
((available btsDInvoice and
btsDInvoice.tc_Status <> "D":U and
(btsDInvoice.DInvoiceIsOpen <> true or
btsDInvoice.DInvoiceIsSelected <> false or
btsDInvoice.DInvoiceBalanceDebitTC < t_sDInvoice.DInvoiceOriginalCreditTC)
) or
(available tqDInvoiceByDebtStatusCurr and
(tqDInvoiceByDebtStatusCurr.tlDInvoiceIsOpen <> true or
tqDInvoiceByDebtStatusCurr.tlDInvoiceIsSelected <> false or
tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceDebitTC < t_sDinvoice.DinvoiceOriginalCreditTC)
)
)
)
then do:
assign vcMessage = trim(#T-32'Invalid Link To Invoice.':150(62671)T-32#) + chr(10) +
trim(#T-96'You can only specify open and unselected invoices with an invoice amount greater than or equal to the credit note amount for the same customer.':150(62672)T-96#) + chr(10) +
trim(substitute(#T-20'Year = &1; Period = &2; Daybook = &3; Invoice = &4; Amount = &5.':500(62673)T-20#,string(t_sDInvoice.DInvoicePostingYear),string(t_sDInvoice.DInvoicePostingPeriod), t_sDInvoice.tcJournalCode, string(t_sDInvoice.DInvoiceVoucher),string(t_sDInvoice.DInvoiceOriginalDebitTC)))
oiReturnStatus = -1.
<M-89 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tDInvoice.DInvoiceType':U (icFieldName),
input t_sDInvoice.DInvoiceType (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sDInvoice.tc_Rowid (icRowid),
input 'qadfin-670411':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end. /* if (t_sDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION} and */
end. /* if t_sDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} or */
/* Validate that correction does not exceed linked invoice amount - in case the currency of the invoice and the linked invoice are the same */
if t_sDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} or
t_sDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or
t_sDinvoice.DinvoiceType = {&INVOICETYPE-CREDITNOTE}
then do :
if ((available btsDInvoice and
btsDInvoice.DInvoiceCurrency_ID = t_sDinvoice.DinvoiceCurrency_ID) or
(available tqDInvoiceByDebtStatusCurr and
tqDInvoiceByDebtStatusCurr.tiDInvoiceCurrency_ID = t_sDinvoice.DinvoiceCurrency_ID))
then do :
assign vdLinkedAmount = abs(tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceCreditTC - tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceDebitTC)
vdCorrectionAmount = abs(t_sDInvoice.DInvoiceBalanceCreditTC - t_sDInvoice.DInvoiceBalanceDebitTC).
if vdCorrectionAmount > vdLinkedAmount
then do:
assign oiReturnStatus = -1
vcMessage = trim(substitute(#T-85'The correction amount (&1 &2) exceeds the amount on the linked invoice (&3 &4).':255(977996378)T-85#,
trim(string(vdCorrectionAmount,">>>,>>>,>>>,>>9.99")),
tqDInvoiceByDebtStatusCurr.tcCurrencyCode,
trim(string(vdLinkedAmount,">>>,>>>,>>>,>>9.99")),
tqDInvoiceByDebtStatusCurr.tcCurrencyCode)).
<M-34 run SetMessage
(input vcMessage (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'qadfin-865139':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end. /* if vdCorrectionAmount > vdLinkedAmount */
end. /* if ((available btsDInvoice and */
end. /* if t_sDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} or */
end. /* if available tqSOAccountingControlByDomain and */