project QadFinancials > class BAPMatching > method ValidateComponentPostAPM2
validation procedure
Parameters
blStartAPMatchingByCInvoiceID | input-output | logical | |
blStartCInvoiceForAPMSelection | input-output | logical | Started query CInvoiceForSelection |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program4/bapmatching.p)
/* ============================================================================================= */
/* Note: this method is executed for all t_sAPMatching regardless their value of tc_status */
/* ============================================================================================= */
/* ============================================================================================== */
/* Manualy define a buffer on t_sAPMatching as this is not possible via the data-item maintenance */
/* ============================================================================================== */
define buffer btsAPMatching for t_sAPMatching.
/* ========================== */
/* Set default return-status */
/* ========================== */
assign oiReturnStatus = -98.
/* ========================================================== */
/* Check for record-availability */
/* If not available: major error and return */
/* ========================================================== */
if not available t_sAPMatching
then do :
assign oiReturnStatus = -3
vcMsgAPMatching = trim(substitute(#T-149'Internal error: no AP matching record is available.':255(999890416)T-149#)).
<M-134 run SetMessage
(input vcMsgAPMatching (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-6727':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
Return.
end. /* if not available t_sAPMatching */
/* ========================================================== */
/* Get the initial values - at the moment the data was loaded */
/* If not available: major error and return */
/* ========================================================== */
if can-do("C,D":U, t_sAPMatching.tc_Status)
then do:
find t_iAPMatching where
t_iAPMatching.tc_Rowid = t_sAPMatching.tc_Rowid
no-error.
if not available t_iAPMatching
then do:
assign vcMsgAPMatching = trim(substitute(#T-150'Internal error. The system cannot find the initial values for the AP matching record with row ID &1.':250(999890417)T-150#,t_sAPmatching.tc_Rowid))
oiReturnStatus = -3.
<M-136 run SetMessage
(input vcMsgAPMatching (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input '':U (icType),
input '':U (iiSeverity),
input t_sAPMatching.tc_Rowid (icRowid),
input 'QadFin-6729':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
Return.
end. /* if not available t_iAPMatching */
end. /* if can-do("C,D":U, t_sAPMatching.tc_Status) */
/* ================================================= */
/* An invoice can only be used once in an APMatching */
/* Check the instance and the db for this */
/* ================================================= */
if t_sAPMatching.tc_Status = "N":U or
(t_sAPMatching.tc_Status = "C":U and
t_sAPMatching.CInvoice_ID <> 0 and
t_sAPMatching.CInvoice_ID <> ? and
t_sAPMatching.CInvoice_ID <> t_iAPMatching.CInvoice_ID)
then do :
find first btsAPMatching where
btsAPMatching.tc_status <> "D":U and
btsAPMatching.tc_rowid <> t_sAPMatching.tc_Rowid and
btsAPMatching.CInvoice_ID = t_sAPMatching.CInvoice_ID
no-lock no-error.
if available btsAPMatching
then do :
assign vcMsgAPMatching = trim(substitute(#T-153'A single supplier invoice (&1/&2/&3) can only be used once in a Receiver Matching':250(999890418)T-153#,string(t_sAPMatching.tiCInvoicePostingYear),t_sAPMatching.tcCInvoiceJournalCode,string(t_sAPMatching.tiCInvoiceVoucher))) + chr(10) +
trim(substitute(#T-154'First receiver matching on this invoice: Date: &1 - Posting: &1 / &2 / &3.':253(56065)T-154#,string(t_sAPMatching.APMatchingDate),string(t_sAPMatching.tiPeriodYear),string(t_sAPMatching.tcJournalCode),string(t_sAPMatching.tiPostingVoucher))) + Chr(10) +
trim(substitute(#T-155'Second Receiver Matching on this invoice (in the instance): Date: &1 - Posting: &1 / &2 / &3.':253(56068)T-155#,string(btsAPMatching.APMatchingDate),string(btsAPMatching.tiPeriodYear),string(btsAPMatching.tcJournalCode),string(btsAPMatching.tiPostingVoucher)))
viLocalReturnStatus = -1.
<M-124 run SetMessage
(input vcMsgAPMatching (icMessage),
input '':U (icArguments),
input 'tAPMatching.tiCInvoiceVoucher':U (icFieldName),
input string(t_sAPMatching.tiCInvoiceVoucher) (icFieldValue),
input '':U (icType),
input '':U (iiSeverity),
input t_sAPMatching.tc_Rowid (icRowid),
input 'QadFin-6723':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
end. /* if avail btsAPMatching */
else do :
if blStartAPMatchingByCInvoiceID = false
then do :
<Q-118 run APMatchingByCInvoiceIDRowidID
(Start) in BAPMatching >
assign blStartAPMatchingByCInvoiceID = true.
end. /* if blStartAPMatchingByCInvoiceID = false */
<Q-117 run APMatchingByCInvoiceIDRowidID (all) (Read) (Cache)
(input t_sAPMatching.Company_ID, (CompanyId)
input t_sAPMatching.CInvoice_ID, (CInvoiceID)
input (if t_sAPMatching.tc_status = 'N':U then ? else t_sAPMatching.tc_Rowid), (SkipAPMatchingRowid)
output dataset tqAPMatchingByCInvoiceIDRowidID) in BAPMatching >
find first tqAPMatchingByCInvoiceIDRowidID no-lock no-error.
if available tqAPMatchingByCInvoiceIDRowidID
then do :
assign vcMsgAPMatching = trim(substitute(#T-156'A single supplier invoice (&1/&2/&3) can only be used once in a Receiver Matching':250(56064)T-156#,string(t_sAPMatching.tiCInvoicePostingYear),t_sAPMatching.tcCInvoiceJournalCode,string(t_sAPMatching.tiCInvoiceVoucher))) + chr(10) +
trim(substitute(#T-157'First receiver matching on this invoice: Date: &1 - Posting: &1 / &2 / &3.':253(56065)T-157#,string(t_sAPMatching.APMatchingDate),string(t_sAPMatching.tiPeriodYear),string(t_sAPMatching.tcJournalCode),string(t_sAPMatching.tiPostingVoucher))) + Chr(10) +
trim(substitute(#T-158'Second Receiver Matching on this invoice (in the database): Date: &1 - Posting: &1 / &2 / &3.':253(999890419)T-158#,string(tqAPMatchingByCInvoiceIDRowidID.ttAPMatchingDate),string(tqAPMatchingByCInvoiceIDRowidID.tiPostingYear),string(tqAPMatchingByCInvoiceIDRowidID.tcJournalCode),string(tqAPMatchingByCInvoiceIDRowidID.tiPostingVoucher)))
viLocalReturnStatus = -1.
<M-119 run SetMessage
(input vcMsgAPMatching (icMessage),
input '':U (icArguments),
input 'tAPMatching.tiCInvoiceVoucher':U (icFieldName),
input string(t_sAPMatching.tiCInvoiceVoucher) (icFieldValue),
input '':U (icType),
input '':U (iiSeverity),
input t_sAPMatching.tc_Rowid (icRowid),
input 'QadFin-6719':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
end. /* if available tqAPMatchingByCInvoiceIDRowidID */
end. /* Not if avail btsAPMatching */
end. /* if if t_sAPMatching.tc_Status = "N":U or */
/* ==================================================================== */
/* Get all Cirec- postinglines of the CI - validations: */
/* - they should all have the same currency as the invoice */
/* - the amount on these lines should equal the amount in APMatching */
/* The discount-percentage in the CI should equal the value APMatching */
/* ==================================================================== */
if t_sAPMatching.tc_Status = "N":U or
(t_sAPMatching.tc_Status = "C":U and
(t_sAPMatching.CInvoice_ID <> t_iAPMatching.CInvoice_ID or
t_sAPMatching.APMatchingTotalAmountTC <> t_iAPMatching.APMatchingTotalAmountTC or
t_sAPMatching.APMatchingTotalAmountLC <> t_iAPMatching.APMatchingTotalAmountLC or
t_sAPMatching.APMatchingCInvoiceDiscPct <> t_iAPMatching.APMatchingCInvoiceDiscPct or
t_sAPMatching.APMatchingARRecTaxTC <> t_iAPMatching.APMatchingARRecTaxTC or
t_sAPMatching.APMatchingARNRecTaxTC <> t_iAPMatching.APMatchingARNRecTaxTC or
t_sAPMatching.APMatchingAIRecTaxTC <> t_iAPMatching.APMatchingAIRecTaxTC or
t_sAPMatching.APMatchingAINRecTaxTC <> t_iAPMatching.APMatchingAINRecTaxTC))
then do :
<M-180 run CheckCICirecAmountAgainstMatched
(input t_sAPMatching.APMatching_ID (iiAPMatchingID),
input t_sAPMatching.CInvoice_ID (iiCInvoiceID),
input t_sAPMatching.Reason_ID (iiReasonID),
input t_sAPMatching.tcReasonCode (icReasonCode),
input t_sAPMatching.tiCInvoicePostingYear (iiCIPostingYear),
input t_sAPMatching.tcCInvoiceJournalCode (icCIJournalCode),
input t_sAPMatching.tiCInvoiceVoucher (iiCIVoucher),
input t_sAPMatching.APMatchingTotalAmountTC (idAPMatchingTotalAmountTC),
input t_sAPMatching.APMatchingTotalAmountLC (idAPMatchingTotalAmountLC),
input t_sAPMatching.APMatchingAIRecTaxTC (idAPMatchingAIRecTaxTC),
output vdCirecCInvoiceAmountTC (odCirecCInvoiceAmountTC),
output vdCirecCInvoiceAmountLC (odCirecCInvoiceAmountLC),
output vdAPMatchingARRecTaxTC (odAPMatchingARRecTaxTC),
output vdAPMatchingARNRecTaxTC (odAPMatchingARNRecTaxTC),
output vdAPMatchingAIRecTaxTC (odAPMatchingAIRecTaxTC),
output vdAPMatchingAINRecTaxTC (odAPMatchingAINRecTaxTC),
output vdInvoiceDiscountPercentage (odInvoiceDiscountPercentage),
input false (ilBCInvoiceIsAlreadyOpen),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper < 0 or
viLocalReturnStatus >= 0
then assign viLocalReturnStatus = viFcReturnSuper.
if t_sAPMatching.APMatchingCInvoiceDiscPct <> vdInvoiceDiscountPercentage or
t_sAPMatching.APMatchingARRecTaxTC <> vdAPMatchingARRecTaxTC or
t_sAPMatching.APMatchingARNRecTaxTC <> vdAPMatchingARNRecTaxTC or
t_sAPMatching.APMatchingAIRecTaxTC <> vdAPMatchingAIRecTaxTC or
t_sAPMatching.APMatchingAINRecTaxTC <> vdAPMatchingAINRecTaxTC
then do :
assign vcMsgAPMatching = trim(substitute(#T-166'The discount percentage or the tax details specified in the invoice (&1/&2/&3) do not equal the corresponding values in the receiver matching.':255(65458)T-166#, string(t_sAPMatching.tiCInvoicePostingYear), string(t_sAPMatching.tcCInvoiceJournalCode), string(t_sAPMatching.tiCInvoiceVoucher))) + chr(10) +
trim(substitute(#T-167'Discount percentage specified in the invoice: &1.':255(65442)T-167#,string(vdInvoiceDiscountPercentage))) + chr(10) +
trim(substitute(#T-168'Discount percentage specified on the matching header: &1.':255(65443)T-168#,string(t_sAPMatching.APMatchingCInvoiceDiscPct))) + chr(10) +
trim(substitute(#T-169'Tax (AccrueAtInvoice and recoverable) on invoice: &1.':255(999890370)T-169#,string(vdAPMatchingAIRecTaxTC))) + chr(10) +
trim(substitute(#T-170'Tax (AccrueAtInvoice and recoverable) on the matching header: &1.':255(999890371)T-170#,string(t_sAPMatching.APMatchingAIRecTaxTC))) + chr(10) +
trim(substitute(#T-171'Tax (AccrueAtInvoice and non-recoverable) on invoice: &1.':255(999890372)T-171#,string(vdAPMatchingAINRecTaxTC))) + chr(10) +
trim(substitute(#T-172'Tax (AccrueAtInvoice and non-recoverable) on the matching header: &1.':255(999890373)T-172#,string(t_sAPMatching.APMatchingAINRecTaxTC))) + chr(10) +
trim(substitute(#T-173'Tax (AccrueAtReceipt and recoverable) on invoice: &1.':255(999890374)T-173#,string(vdAPMatchingARRecTaxTC))) + chr(10) +
trim(substitute(#T-174'Tax (AccrueAtReceipt and recoverable) on the matching header: &1.':255(999890375)T-174#,string(t_sAPMatching.APMatchingARRecTaxTC))) + chr(10) +
trim(substitute(#T-175'Tax (AccrueAtReceipt and non-recoverable) on invoice: &1.':255(999890376)T-175#,string(vdAPMatchingARNRecTaxTC))) + chr(10) +
trim(substitute(#T-176'Tax (AccrueAtReceipt and non-recoverable) on the matching header: &1.':255(999890377)T-176#,string(t_sAPMatching.APMatchingARNRecTaxTC))).
viLocalReturnStatus = -1.
<M-165 run SetMessage
(input vcMsgAPMatching (icMessage),
input ? (icArguments),
input 'tAPMatching.APMatchingCInvoiceDiscPct':U (icFieldName),
input string(t_sAPMatching.APMatchingCInvoiceDiscPct) (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-7056':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
end. /* if t_sAPMatching.APMatchingTotalAmountTC or */
end. /* if t_sAPMatching.tc_Status = "N":U or */
/* ======================================================================== */
/* Check whether the main readonly-RKBF of the Invocie are correct */
/* ======================================================================== */
if t_sAPMatching.tc_Status = "N":U or
(t_sAPMatching.tc_Status = "C":U and
(t_sAPMatching.CInvoice_ID <> t_iAPMatching.CInvoice_ID or
t_sAPMatching.tcBusinessRelationCode <> t_iAPMatching.tcBusinessRelationCode or
t_sAPMatching.tcBusinessRelationICCode <> t_iAPMatching.tcBusinessRelationICCode or
t_sAPMatching.tcCreditorCode <> t_iAPMatching.tcCreditorCode or
t_sAPMatching.tdCInvoiceExchangeRate <> t_iAPMatching.tdCInvoiceExchangeRate or
t_sAPMatching.tdCinvoiceRateScale <> t_iAPMatching.tdCinvoiceRateScale or
t_sAPMatching.tdCInvoiceCCRate <> t_iAPMatching.tdCInvoiceCCRate or
t_sAPMatching.tdCinvoiceCCScale <> t_iAPMatching.tdCinvoiceCCScale or
t_sAPMatching.ttCInvoiceDate <> t_iAPMatching.ttCInvoiceDate or
t_sAPMatching.tcCInvoiceReference <> t_iAPMatching.tcCInvoiceReference))
then do :
if not blStartCInvoiceForAPMSelection
then do :
<Q-127 run CInvoiceForAPMSelection (Start) in BCInvoice>
assign blStartCInvoiceForAPMSelection = true.
end. /* if not blStartCInvoiceForAPMSelection */
<Q-126 run CInvoiceForAPMSelection (all) (Read) (NoCache)
(input ?, (CompanyId)
input ?, (CInvoicePostingYear)
input ?, (JournalCode)
input ?, (CInvoiceVoucher)
input t_sAPMatching.CInvoice_ID, (CInvoiceId)
input ?, (CreditorCode)
input ?, (CInvoiceReference)
input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
input ?, (CInvoiceRegistrationNr)
output dataset tqCInvoiceForAPMSelection) in BCInvoice>
find first tqCInvoiceForAPMSelection where
tqCInvoiceForAPMSelection.tiCInvoice_ID = t_sAPMatching.CInvoice_ID no-error.
if available tqCInvoiceForAPMSelection /* not available has been checked by the ancestor-code */ and
(t_sAPMatching.tcBusinessRelationCode <> tqCInvoiceForAPMSelection.tcBusinessRelationCode or
t_sAPMatching.tcBusinessRelationICCode <> tqCInvoiceForAPMSelection.tcBusinessRelationICCode or
t_sAPMatching.tcCreditorCode <> tqCInvoiceForAPMSelection.tcCreditorCode or
t_sAPMatching.tdCInvoiceExchangeRate <> tqCInvoiceForAPMSelection.tdCInvoiceExchangeRate or
t_sAPMatching.tdCinvoiceRateScale <> tqCInvoiceForAPMSelection.tdCInvoiceRateScale or
t_sAPMatching.tdCInvoiceCCRate <> tqCInvoiceForAPMSelection.tdCInvoiceCCRate or
t_sAPMatching.tdCinvoiceCCScale <> tqCInvoiceForAPMSelection.tdCInvoiceCCScale or
t_sAPMatching.ttCInvoiceDate <> tqCInvoiceForAPMSelection.ttCInvoiceDate or
t_sAPMatching.tcCInvoiceReference <> tqCInvoiceForAPMSelection.tcCInvoiceReference or
t_sAPMatching.tiCInvoiceRegistrationNr <> tqCInvoiceForAPMSelection.tiCInvoiceRegistrationNr)
then do :
assign vcMsgAPMatching = trim(substitute(#T-142'The invoice-related values in the matching for invoice (&1/&2/&3) do not equal the values of the invoice itself.':254(56732)T-142#, string(t_sAPMatching.tiCInvoicePostingYear), string(t_sAPMatching.tcCInvoiceJournalCode), string(t_sAPMatching.tiCInvoiceVoucher))) + chr(10) +
trim(substitute(#T-143'Business Relation code; Matching:&1, Invoice: &2.':255(999890134)T-143#,t_sAPMatching.tcBusinessRelationCode,tqCInvoiceForAPMSelection.tcBusinessRelationCode)) + chr(10) +
trim(substitute(#T-178'Business Relation IC-code; Matching:&1, Invoice: &2.':255(999890133)T-178#,t_sAPMatching.tcBusinessRelationICCode,tqCInvoiceForAPMSelection.tcBusinessRelationICCode)) + chr(10) +
trim(substitute(#T-144'Supplier code; Matching: &1, Invoice: &2.':243(56734)T-144#,t_sAPMatching.tcCreditorCode,tqCInvoiceForAPMSelection.tcCreditorCode)) + chr(10) +
trim(substitute(#T-145'Exchange rate; Matching: &1, Invoice: &2.':243(56742)T-145#,t_sAPMatching.tdCInvoiceExchangeRate,tqCInvoiceForAPMSelection.tdCInvoiceExchangeRate)) + chr(10) +
trim(substitute(#T-146'Rate Scale; Matching: &1, Invoice: &2.':243(56743)T-146#,t_sAPMatching.tdCinvoiceRateScale,tqCInvoiceForAPMSelection.tdCinvoiceRateScale)) + chr(10) +
trim(substitute(#T-181'Exchange rate; Matching: &1, Invoice: &2.':243(56742)t-181#,t_sAPMatching.tdCInvoiceCCRate,tqCInvoiceForAPMSelection.tdCInvoiceCCRate)) + chr(10) +
trim(substitute(#T-182'Rate Scale; Matching: &1, Invoice: &2.':243(56743)t-182#,t_sAPMatching.tdCinvoiceCCScale,tqCInvoiceForAPMSelection.tdCinvoiceCCScale)) + chr(10) +
trim(substitute(#T-147'Invoice date; Matching: &1, Invoice: &2.':243(56744)T-147#,t_sAPMatching.ttCInvoiceDate,tqCInvoiceForAPMSelection.ttCInvoiceDate)) + chr(10) +
trim(substitute(#T-148'Invoice reference; Matching: &1, Invoice: &2.':243(56740)T-148#,t_sAPMatching.tcCInvoiceReference,tqCInvoiceForAPMSelection.tcCInvoiceReference)) + chr(10) +
trim(substitute(#T-177'Invoice registration number; Matching:&1, Invoice: &2.':243(69202)T-177#,t_sAPMatching.tiCInvoiceRegistrationNr,tqCInvoiceForAPMSelection.tiCInvoiceRegistrationNr)).
viLocalReturnStatus = -1.
<M-125 run SetMessage
(input vcMsgAPMatching (icMessage),
input ? (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-6724':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
end. /* if available tqCInvoiceForAPMSelection */
end. /* if t_sAPMatching.tc_Status = "N":U or */
/* ======================================================================== */
/* Set return-status = OK or any other value from within the previous code */
/* ======================================================================== */
assign oiReturnStatus = viLocalReturnStatus.