Parameters
| oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program4/bapmatching.p)
/* ============================================================================== */
/* Set default return-status */
/* ============================================================================== */
assign oiReturnStatus = -98.
/* ======================================================================================================== */
/* Make sure the inst-dep class data-item 'ListAccessibleCompanyCodes' that holds the list of company-codes */
/* that can be accessed by the current user based on the 'entity-securoty' mechnaism of MfgPro. */
/* This field can contain a comma-separated list of the CompanyCodes you have acces to the APMathcing. */
/* If the value of this parameter is *, then this means you have acces to all companies of the domain. */
/* ======================================================================================================== */
if vcListAccessibleCompanyCodes = ? or vcListAccessibleCompanyCodes = "?":U /* this means it was not yet filled */
then do :
<I-75 {bFcOpenInstance
&CLASS = "Session"}>
<M-76 run GetCompanyListForUserAndDomain
(input vcUserLogin (icUserLogin),
input viDomainID (iiDomainID),
output vcListAccessibleCompanyCodes (ocCompanyCodeList),
output viExternalReturnStatus (oiReturnStatus)) in Session>
<I-77 {bFcCloseInstance
&CLASS = "Session"}>
if viExternalReturnStatus <> 0 then assign viExternalReturnStatus = viFcReturnSuper.
if viExternalReturnStatus < 0
then Return.
end. /* if vcListAccessibleCompanyCodes = ? */
/* ============================================================================================= */
/* Start a block: all error/warning-situations in the block are catched by viBlockReturnStatus */
/* Thi is done to be able to start/stop the queries correctly and to have a default return-stat */
/* Queries are started conditionaly during this method and conditionaly stopped at the end */
/* ============================================================================================= */
assign vlStartPeriodByStartEndDateStat = false
vlStartAPMatchingByCInvoiceID = false
vlStartAPMatchingLnByStatusPvod = false
vlStartCInvoiceForAPMSelection = false.
GLOBALVALIDATIONBLOCK : DO :
/* ============================================================================================= */
/* Go through all matchings (including the unchanged as they may have changed lines) */
/* ============================================================================================= */
for each t_sAPMatching :
/* ========================================================================================================= */
/* Call two submethods that will do all checks on the t_sAPMatching records (code was to large for 1 method) */
/* ========================================================================================================= */
if t_sAPMatching.tc_Status <> "":U and
t_sAPMatching.APMatchingStatus <> {&APMATCHINGSTATUS-CANCEL}
then do :
<M-49 run ValidateComponentPostAPM1
(input-output vlStartPeriodByStartEndDateStat (blStartPeriodByStartEndDateStat),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper <> 0
then assign viBlockReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave GLOBALVALIDATIONBLOCK.
<M-79 run ValidateComponentPostAPM2
(input-output vlStartAPMatchingByCInvoiceID (blStartAPMatchingByCInvoiceID),
input-output vlStartCInvoiceForAPMSelection (blStartCInvoiceForAPMSelection),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper <> 0
then assign viBlockReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave GLOBALVALIDATIONBLOCK.
end. /* if t_sAPMatching.tc_Status <> "":U */
/* ===================================================================== */
/* Call a submethod that will do all checks towards PO shipper */
/* ===================================================================== */
if t_sAPMatching.tc_Status <> "D":U and
t_sAPMatching.APMatchingStatus <> {&APMATCHINGSTATUS-CANCEL}
then do :
<M-60 run ValidateComponentPostAPM3PLI (output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper <> 0
then assign viBlockReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave GLOBALVALIDATIONBLOCK.
end. /* if t_sAPMatching.tc_Status <> "":U */
/* ===================================================================== */
/* Call a submethod that will do all checks for Logistic-charges */
/* ===================================================================== */
if t_sAPMatching.tc_Status <> "D":U and
t_sAPMatching.APMatchingStatus <> {&APMATCHINGSTATUS-CANCEL}
then do :
<M-82 run ValidateComponentPostAPM4LogCharge (output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper <> 0
then assign viBlockReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave GLOBALVALIDATIONBLOCK.
end. /* if t_sAPMatching.tc_Status <> "":U */
/* =========================================================== */
/* Go throuhg all new/changed Lines of the non-deleted Headers */
/* Also include the unchanged ones as we calculate the sum */
/* =========================================================== */
if t_sAPMatching.tc_Status <> "D":U and
t_sAPMatching.APMatchingStatus <> {&APMATCHINGSTATUS-CANCEL}
then do :
/* ====================================================================================================== */
/* Reste the data-item that holds the sum of all allocated-amounts of the lines of a single APMatching */
/* ====================================================================================================== */
assign vdSumAllLinesMatchAmtTC = 0
vdSumAllLinesARRecTaxTC = 0
vdSumAllLinesARNRecTaxTC = 0
vdSumAllLinesAINRecTaxTC = 0
vdSumManualJELinesAmountTC = 0
vdSumAPMatchingCostAmountTC = 0.
/* =========================================================== */
/* Go throuhg all new/changed Lines of the non-deleted Headers */
/* Also include the unchanged ones as we calculate the sum */
/* 2 method are needed as the program-code is to big for one */
/* =========================================================== */
for each t_sAPMatchingLn where
t_sAPMatchingLn.tc_ParentRowid = t_sAPMatching.tc_Rowid and
t_sAPMatchingLn.tc_Status <> "D":U :
<M-50 run ValidateComponentPostAPMLn1 (output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper <> 0
then assign viBlockReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave GLOBALVALIDATIONBLOCK.
<M-80 run ValidateComponentPostAPMLn2
(input-output vlStartAPMatchingLnByStatusPvod (blStartAPMatchingLnByStatusPvod),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper <> 0
then assign viBlockReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave GLOBALVALIDATIONBLOCK.
/* ===================================================================================== */
/* Assign the sum data-items for later check in this method */
/* ===================================================================================== */
assign vdSumAllLinesMatchAmtTC = vdSumAllLinesMatchAmtTC + t_sAPMatchingLn.APMatchingLnMatchAmtTC
vdSumAllLinesARRecTaxTC = vdSumAllLinesARRecTaxTC + t_sAPMatchingLn.tdAPMatchingLnARRecTaxTC
vdSumAllLinesARNRecTaxTC = vdSumAllLinesARNRecTaxTC + t_sAPMatchingLn.tdAPMatchingLnARNRecTaxTC
vdSumAllLinesAINRecTaxTC = vdSumAllLinesAINRecTaxTC + t_sAPMatchingLn.tdAPMatchingLnAINRecTaxTC.
/* ===================================================================================== */
/* Do not count the ones that are marked as retained-tax and that are accrued-at-receipt */
/* Subtract these amounts from the vdSumAllLinesARRecTaxTC and vdSumAllLinesARNRecTaxTC */
/* ===================================================================================== */
for each t_sAPMatchingLnTax where
t_sAPMatchingLnTax.tc_ParentRowid = t_sAPMatchingLn.tc_Rowid and
t_sAPMatchingLnTax.tc_Status <> "D":U and
t_sAPMatchingLnTax.APMatchingLnTaxIsAbsRet = true and
t_sAPMatchingLnTax.APMatchingLnTaxIsAccrRcp = true :
assign vdSumAllLinesARRecTaxTC = vdSumAllLinesARRecTaxTC - t_sAPMatchingLnTax.APMatchingLnTaxARRecTaxTC
vdSumAllLinesARNRecTaxTC = vdSumAllLinesARNRecTaxTC - t_sAPMatchingLnTax.APMatchingLnTaxARNRecTaxTC.
end. /* for each t_sAPMatchingLnTax where */
end. /* for each t_sAPMatchingLn where */
/* ===================================================================================== */
/* Error: Check if the amount on the header equals the sum of the MatchTC on the lines + */
/* the sum of all taxes except the ones with AccrueAtInvoice and receverable */
/* Note that in case manual JE-lines were entered, we shoudl include them in the check */
/* ===================================================================================== */
if viBJournalEntryAPMID <> ? and
viBJournalEntryAPMID <> 0 and
t_sAPMatching.Posting_ID <> ? and
t_sAPMatching.Posting_ID <> 0
then do :
<I-66 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
<M-68 run GetPostingAmount
(input t_sAPMatching.Posting_ID (iiPostingId),
output vdDummy (odPostingAmountDebitLC),
output vdDummy (odPostingAmountCreditLC),
output vdSumManualJELinesCreditTC (odPostingAmountCreditTC),
output vdDummy (odPostingAmountCreditCC),
output vdSumManualJELinesDebitTC (odPostingAmountDebitTC),
output vdDummy (odPostingAmountDebitCC),
output vcDummy (ocCurrencyCode),
output viExternalReturnStatus (oiReturnStatus)) in BJournalEntry>
<I-67 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
if viExternalReturnStatus <> 0
then do :
assign vcMsgAPMatching = trim(#T-70'An internal error occurred while retrieving the amounts on the manually entered journal entry lines.':254(57521)T-70#) + Chr(10) +
trim(substitute(#T-72'Instance ID of the journal entry: &1.':251(57512)T-72#,string(viBJournalEntryAPMID))) + chr(10) +
trim(substitute(#T-73'Posting ID of the journal entry: &1.':251(57513)T-73#,string(t_sAPMatching.Posting_ID))) + chr(10) +
trim(substitute(#T-71'Date and Invoice of the matching: &1 - &2 / &3 / &4.':251(56745)T-71#,string(t_sAPMatching.APMatchingDate),string(t_sAPMatching.tiCInvoicePostingYear),t_sAPMatching.tcCInvoiceJournalCode,string(t_sAPMatching.tiCInvoiceVoucher)))
viBlockReturnStatus = -1.
<M-69 run SetMessage
(input vcMsgAPMatching (icMessage),
input '':U (icArguments),
input 'tAPMatching.Posting_ID':U (icFieldName),
input string(t_sAPMatching.Posting_ID) (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sAPMatching.tc_Rowid (icRowid),
input 'QadFin-5907':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
end. /* if viExternalReturnStatus <> 0 */
assign vdSumManualJELinesAmountTC = vdSumManualJELinesDebitTC - vdSumManualJELinesCreditTC.
end. /* if viBJournalEntryAPMID <> ? and */
for each t_sAPMatchingCost where
t_sAPMatchingCost.tc_ParentRowid = t_sAPMatching.tc_Rowid and
t_sAPMatchingCost.tc_Status <> 'D':
assign vdSumAPMatchingCostAmountTC = vdSumAPMatchingCostAmountTC + t_sAPMatchingCost.tdDebitTC - t_sAPMatchingCost.tdCreditTC.
end.
if t_sAPMatching.APMatchingTotalAmountTC <> vdSumAllLinesMatchAmtTC + vdSumAllLinesARRecTaxTC + vdSumAllLinesARNRecTaxTC + vdSumAllLinesAINRecTaxTC + vdSumManualJELinesAmountTC + vdSumAPMatchingCostAmountTC
then do :
assign vcMsgAPMatching = trim(substitute(#T-52'The total allocated amount on the header (&1) must equal the sum of allocated amounts on the detail lines (&2), all taxes accrued at receipt (&3), non-recoverable taxes accrued at invoice (&4), manual journal entry amounts (&5) and cost lines (&6).':255(934883304)T-52#,string(t_sAPMatching.APMatchingTotalAmountTC),string(vdSumAllLinesMatchAmtTC), string(vdSumAllLinesARRecTaxTC + vdSumAllLinesARNRecTaxTC), string(vdSumAllLinesAINRecTaxTC), string(vdSumManualJELinesAmountTC), string(vdSumAPMatchingCostAmountTC))) + Chr(10) +
trim(substitute(#T-56'Date and Invoice of the matching: &1 - &2 / &3 / &4.':251(56745)T-56#,string(t_sAPMatching.APMatchingDate),string(t_sAPMatching.tiCInvoicePostingYear),t_sAPMatching.tcCInvoiceJournalCode,string(t_sAPMatching.tiCInvoiceVoucher)))
viBlockReturnStatus = (if t_sAPMatching.APMatchingStatus = {&APMATCHINGSTATUS-INITIAL}
then +1
else -1).
<M-51 run SetMessage
(input vcMsgAPMatching (icMessage),
input '':U (icArguments),
input 'tAPMatching.APMatchingTotalAmountTC':U (icFieldName),
input string(t_sAPMatching.APMatchingTotalAmountTC) (icFieldValue),
input (if t_sAPMatching.APMatchingStatus = {&APMATCHINGSTATUS-INITIAL} then 'W':U else 'E':U) (icType),
input 3 (iiSeverity),
input t_sAPMatching.tc_Rowid (icRowid),
input 'QadFin-5692':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
end. /* if t_sAPMatching.APMatchingTotalAmountTC <> */
if t_sAPMatching.APMatchingStatus = {&APMATCHINGSTATUS-FINISHED}
then do:
assign viMatchingYearPeriod = (t_sAPMatching.tiPeriodYear * 100) + t_sAPMatching.tiPeriodPeriod.
<Q-89 run CInvoiceBySelected (all) (Read) (NoCache)
(input t_sAPMatching.Company_ID, (CompanyId)
input t_sAPMatching.CInvoice_ID, (CInvoiceID)
output dataset tqCInvoiceBySelected) in BCInvoice>
find first tqCInvoiceBySelected where
tqCInvoiceBySelected.tiCompany_ID = t_sAPMatching.Company_ID and
tqCInvoiceBySelected.tiCInvoice_ID = t_sAPMatching.CInvoice_ID
no-error.
if available tqCInvoiceBySelected and
tqCInvoiceBySelected.tiCInvoicePostingYearPeriod <> viMatchingYearPeriod
then do:
vcMsgAPMatching = trim(substitute(#T-64'The Year/Period (&1) of SI Posting and Year/Period (&2) of Matching Posting are different.':150(348631990)T-64#,string(tqCInvoiceBySelected.tiCInvoicePostingYearPeriod),viMatchingYearPeriod)).
viBlockReturnStatus = 1.
<M-45 run SetMessage
(input vcMsgAPMatching (icMessage),
input '':U (icArguments),
input 'viMatchingYearPeriod':U (icFieldName),
input string(viMatchingYearPeriod) (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input t_sAPMatching.tc_Rowid (icRowid),
input 'qadfin-875385':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
end. /*if available tqCInvoiceBySelected and */
end. /* if t_sAPMatching.APMatchingStatus = {&APMATCHINGSTATUS-FINISHED} */
end. /* if t_sAPMatching.tc_Status <> "D":U */
end. /* for each t_sAPMatching */
END. /* GLOBALVALIDATIONBLOCK */
/* =============================================== */
/* Stop all queries that were started in the loop */
/* =============================================== */
if vlStartAPMatchingByCInvoiceID = true
then do :
<Q-26 run APMatchingByCInvoiceIDRowidID (Stop) in BAPMatching >
end. /* if vlStartAPMatchingByCInvoiceID */
if vlStartAPMatchingLnByStatusPvod = true
then do :
<Q-48 run APMatchingLnByStatusPvod (Stop) in BAPMatching >
end. /* if vlStartAPMatchingLnByStatusPvod = false */
if vlStartCInvoiceForAPMSelection
then do :
<Q-55 run CInvoiceForAPMSelection (Stop) in BCInvoice>
end. /* if vlStartCInvoiceForAPMSelection */
/* ============================= */
/* Check for errors in the block */
/* ============================= */
if viBlockReturnStatus <> 0
then assign oiReturnStatus = viBlockReturnStatus.
if viBlockReturnStatus < 0
then Return.
/* ============================= */
/* Set return-status = OK */
/* ============================= */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.