project QadFinancials > class BAPMatching > method ValidateComponentPreAPMLn1
Description
ValidateComponentPreValidateAPMLn1: submethod of ValidateComponentPreValidate
Parameters
blBCostingOpenedForCostMethod | input-output | logical | blBCostingStartedForCostMethod |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program4/bapmatching.p)
/* ========================= */
/* Set default return-status */
/* ========================= */
assign oiReturnStatus = -98.
/* ============================= */
/* Check for record-availability */
/* ============================= */
assign vcMsgAPMatching = "":U.
if not available t_sAPMatching
then assign vcMsgAPMatching = trim(substitute(#T-15'Internal error: no AP matching record is available.':255(56009)T-15#)).
if vcMsgAPMatching = "":U and
not available t_sAPMatchingLn
then assign vcMsgAPMatching = trim(substitute(#T-31'Internal error: no AP matching line record is available.':255(56010)T-31#,string(t_sAPMatching.tiCInvoicePostingYear),t_sAPMatching.tcCInvoiceJournalCode,string(t_sAPMatching.tiCInvoiceVoucher))) .
if vcMsgAPMatching <> "":U
then do:
assign oiReturnStatus = -1.
<M-11 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-5612':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
Return.
end. /* if not available t_sAPMatching */
/* ===================================================================== */
/* backwards compatibility : fill all mandatory fields if not filled yet */
/* ===================================================================== */
if t_sAPMatchingLn.tc_Status = "N":U or
t_sAPMatchingLn.tc_Status = "C":U
then do :
if t_sAPMatchingLn.APMatchingLnPvodIsTaxIncl = ?
then assign t_sAPMatchingLn.APMatchingLnPvodIsTaxIncl = false.
if t_sAPMatchingLn.APMatchingLnMatchIsTaxIncl = ?
then assign t_sAPMatchingLn.APMatchingLnMatchIsTaxIncl = false.
end. /* if t_sAPMatchingLn.tc_Status = "N":U or */
/* ================================================================================================================ */
/* Fill in the Read-only RKBF on the costing-methods of PVOD in case they are unknown and the PVOD-ID is filled */
/* This is done here as from this point onwards we expect these fields to be filled but we can hardly expect all */
/* callers (like external parties) to provide us this detail information on a PVOD. They should thus simply */
/* provide unknown values for these detail-fields and provide correct information for the key-fields of the PVOD */
/* This is separated from the previous block as this information cannot be retrieved by executing a query */
/* ================================================================================================================ */
if /* Base for the calculation */
t_sAPMatchingLn.APMatchingLnPvodSite <> "":U and
t_sAPMatchingLn.APMatchingLnPvodSite <> ? and
t_sAPMatchingLn.APMatchingLnPvodItem <> "":U and
t_sAPMatchingLn.APMatchingLnPvodItem <> ?
then do :
if t_sAPMatchingLn.APMatchingLnPvodCostMtdCur = ? and
t_sAPMatchingLn.APMatchingLnPvodCostMtdGL = ?
then do :
/* =================================================================================================== */
/* Start&Open BCosting as it is used in the block / classs will be closed after the block */
/* This is the most performing way to run an api-method repetitively in this loop */
/* =================================================================================================== */
if t_sAPMatchingLn.APMatchingLnPvodOrderType = {&APMATCHINGLNPVODORDERTYPE-PURCHASE} and
t_sAPMatchingLn.APMatchingLnPvodItemType <> {&APMATCHINGLNPVODITEMTYPE-MEMO}
then do :
if blBCostingOpenedForCostMethod = false
then do :
if viBMfgCostingAPMID <> 0 and
viBMfgCostingAPMID <> ?
then do :
<I-40 {bFcOpenInstance
&CLASS = "BMfgCosting"}>
end. /* if viBMfgPendingVoucherAPMID <> 0 and */
else do :
<I-41 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "false"
&CLASS = "BMfgCosting"}>
assign vlBMfgCostingStart = true.
end. /* Not if viBMfgPendingVoucherAPMID <> 0 and */
assign blBCostingOpenedForCostMethod = true.
end. /* if blBCostingOpenedForCostMethod = false */
/* Call method in BCosting the returns the costing methods */
<M-21 run ApiGetCostingMethod
(input t_sAPMatchingLn.APMatchingLnPvodSite (icSite),
input t_sAPMatchingLn.APMatchingLnPvodItem (icPart),
output vcDummy (ocGLCostSet),
output t_sAPMatchingLn.APMatchingLnPvodCostMtdGL (ocGLCostMethod),
output vcDummy (ocCurrentCostSet),
output t_sAPMatchingLn.APMatchingLnPvodCostMtdGL (ocCurrentCostMethod),
output viFcReturnSuper (oiReturnStatus)) in BMfgCosting>
if viFcReturnSuper < 0 /* only catch errors here */
then do:
assign oiReturnStatus = viFcReturnSuper.
Return.
end. /* if viFcReturnSuper < 0 */
end. /* if t_sAPMatchingLn.APMatchingLnPvodOrderType = {&APMATCHINGLNPVODORDERTYPE-PURCHASE} */
else assign t_sAPMatchingLn.APMatchingLnPvodCostMtdGL = {&COSTMETHOD-NONE}
t_sAPMatchingLn.APMatchingLnPvodCostMtdCur = {&COSTMETHOD-NONE}.
end. /* if t_sAPMatchingLn.APMatchingLnPvodCostMtdCur = ? and */
end. /* if Upd */
/* ================================================================================================================ */
/* Fill in the Read-only RKBF on the costing-methods of PVOD in case they are unknown and the PVOD-ID is filled */
/* This is done here as from this point onwards we expect these fields to be filled but we can hardly expect all */
/* callers (like external parties) to provide us this detail information on a PVOD. They should thus simply */
/* provide unknown values for these detail-fields and provide correct information for the key-fields of the PVOD */
/* This is separated from the previous block as this information cannot be retrieved by executing a query */
/* ================================================================================================================ */
if /* Base for finding the PLI-key */
t_sAPMatchingLn.PvoDomain <> "":U and
t_sAPMatchingLn.PvoDomain <> ? and
t_sAPMatchingLn.PvoID <> 0 and
t_sAPMatchingLn.PvoID <> ? and
/* Unknown values that will be filled */
t_sAPMatchingLn.APMatchingLnPvodPliKeyId = ? and
t_sAPMatchingLn.APMatchingLnPvodPlidLine = ?
then do :
<Q-37 run PLInvoiceDetailForMatching (all) (Read) (NoCache)
(input t_sAPMatchingLn.PvoDomain, (DomainCode)
input t_sAPMatchingLn.PvoID, (PvoID)
input ?, (POShipperInvoice)
output dataset tqPLInvoiceDetailForMatching) in BMfgPLInvoice >
find first tqPLInvoiceDetailForMatching no-lock no-error. /* Multiples might be returned but the all have the same value for the field we will use */
if available tqPLInvoiceDetailForMatching
then assign t_sAPMatchingLn.APMatchingLnPvodPliKeyId = tqPLInvoiceDetailForMatching.tipli_keyid
t_sAPMatchingLn.APMatchingLnPvodPlidLine = tqPLInvoiceDetailForMatching.tiplid_line.
end. /* if Base for finding the PLI-key */
/* ================================================== */
/* Fill in the some values based on some other fields */
/* ================================================== */
if /* Base for the calculation of amounts */
t_sAPMatchingLn.APMatchingLnIsPvodFinished <> ? and
t_sAPMatchingLn.APMatchingLnPvodIsLgCharge <> ? and
t_sAPMatchingLn.APMatchingLnPvodOpenQty <> ? and
t_sAPMatchingLn.APMatchingLnPvodUnitPrice <> ? and
t_sAPMatchingLn.APMatchingLnMatchQty <> ? and
t_sAPMatchingLn.APMatchingLnMatchUnitPrice <> ?
then do:
/*Check for logistics charges*/
if t_sAPMatchingLn.APMatchingLnPvodIsLgCharge = true
then do:
if t_sAPMatchingLn.APMatchingLnPvodOpenAmtTC <> t_sAPMatchingLn.APMatchingLnMatchAmtTC and
t_sAPMatchingLn.APMatchingLnIsPvodFinished <> true
then
assign t_sAPMatchingLn.APMatchingLnReceiptAmtTC = t_sAPMatchingLn.APMatchingLnMatchAmtTC
t_sAPMatchingLn.APMatchingLnVarRateTC = 0.
else
assign t_sAPMatchingLn.APMatchingLnReceiptAmtTC = t_sAPMatchingLn.APMatchingLnPvodOpenAmtTC
t_sAPMatchingLn.APMatchingLnVarRateTC =
<M-55 RoundAmount
(input t_sAPMatchingLn.APMatchingLnMatchUnitPrice * t_sAPMatchingLn.APMatchingLnMatchQty (idUnroundedAmount),
input ? (iiCurrencyID),
input t_sAPMatching.tcCurrencyCode (icCurrencyCode)) in BAPMatching> -
<M-61 RoundAmount
(input t_sAPMatchingLn.APMatchingLnPvodUnitPrice * t_sAPMatchingLn.APMatchingLnMatchQty (idUnroundedAmount),
input ? (iiCurrencyID),
input t_sAPMatching.tcCurrencyCode (icCurrencyCode)) in BAPMatching> .
/* Fill-in the allocated amount-LC */
assign t_sAPMatchingLn.APMatchingLnMatchAmtLC =
<M-82 RoundAmount
(input t_sAPMatchingLn.APMatchingLnMatchAmtTC * t_sAPMatching.tdCInvoiceExchangeRate * t_sAPMatching.tdCinvoiceRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input t_sAPMatching.tcCurrencyCode (icCurrencyCode)) in BAPMatching>
/* Fill-in the Var-Rate-LC */
t_sAPMatchingLn.APMatchingLnVarRateLC =
<M-10 RoundAmount
(input t_sAPMatchingLn.APMatchingLnVarRateTC * t_sAPMatching.tdCInvoiceExchangeRate * t_sAPMatching.tdCinvoiceRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input t_sAPMatching.tcCurrencyCode (icCurrencyCode)) in BAPMatching>
/* Fill-in the receipt-amount-LC */
t_sAPMatchingLn.APMatchingLnReceiptAmtLC =
<M-47 RoundAmount
(input t_sAPMatchingLn.APMatchingLnReceiptAmtTC * t_sAPMatchingLn.APMatchingLnPvodExchRate2 / t_sAPMatchingLn.APMatchingLnPvodExchRate (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input ? (icCurrencyCode)) in BAPMatching>
/* Fill-in the Var-Usage-LC */
t_sAPMatchingLn.APMatchingLnVarUsageLC =
(if t_sAPMatchingLn.APMatchingLnIsPvodFinished <> true
then 0
else <M-53 RoundAmount
(input t_sAPMatchingLn.APMatchingLnVarUsageTC * t_sAPMatching.tdCInvoiceExchangeRate * t_sAPMatching.tdCinvoiceRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input ? (icCurrencyCode)) in BAPMatching>).
/* Fill-in the receipt-amount-CC */
if vcCompanyCC <> t_sAPMatchingLn.APMatchingLnPvodCurrency
then assign t_sAPMatchingLn.APMatchingLnReceiptAmtCC = <M-18 RoundAmount
(input t_sAPMatchingLn.APMatchingLnReceiptAmtLC * t_sAPMatchingLn.APMatchingLnPvodCCRate * t_sAPMatchingLn.APMatchingLnPvodCCScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input ? (icCurrencyCode)) in BAPMatching>.
else assign t_sAPMatchingLn.APMatchingLnReceiptAmtCC = t_sAPMatchingLn.APMatchingLnReceiptAmtTC.
assign /* Fill-in the allocated amount-CC */
t_sAPMatchingLn.APMatchingLnMatchAmtCC =
<M-59 RoundAmount
(input t_sAPMatchingLn.APMatchingLnMatchAmtTC * t_sAPMatching.tdCInvoiceCCRate * t_sAPMatching.tdCinvoiceCCScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input ? (icCurrencyCode)) in BAPMatching>
/* Fill-in the Var-Rate-CC */
t_sAPMatchingLn.APMatchingLnVarRateCC =
<M-73 RoundAmount
(input t_sAPMatchingLn.APMatchingLnVarRateTC * t_sAPMatching.tdCInvoiceCCRate * t_sAPMatching.tdCinvoiceCCScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input ? (icCurrencyCode)) in BAPMatching>
/* Fill-in the Var-Usage-CC */
t_sAPMatchingLn.APMatchingLnVarUsageCC =
(if t_sAPMatchingLn.APMatchingLnIsPvodFinished <> true
then 0
else <M-88 RoundAmount
(input t_sAPMatchingLn.APMatchingLnVarUsageTC * t_sAPMatching.tdCInvoiceCCRate * t_sAPMatching.tdCinvoiceCCScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input ? (icCurrencyCode)) in BAPMatching>)
/* Fill-in the ExchangeRate-LC */
t_sAPMatchingLn.APMatchingLnVarExchRateLC =
(t_sAPMatchingLn.APMatchingLnMatchAmtLC
- t_sAPMatchingLn.APMatchingLnReceiptAmtLC
- t_sAPMatchingLn.APMatchingLnVarUsageLC
- t_sAPMatchingLn.APMatchingLnVarRateLC).
if t_sAPMatching.tdCInvoiceCCRate * t_sAPMatching.tdCInvoiceCCScale <> t_sAPMatchingLn.APMatchingLnPvodCCRate * t_sAPMatchingLn.APMatchingLnPvodCCScale
then assign /* Fill-in the ExchangeRate-CC */
t_sAPMatchingLn.APMatchingLnVarExchRateCC =
(t_sAPMatchingLn.APMatchingLnMatchAmtCC
- t_sAPMatchingLn.APMatchingLnReceiptAmtCC
- t_sAPMatchingLn.APMatchingLnVarUsageCC
- t_sAPMatchingLn.APMatchingLnVarRateCC).
end. /*if t_sAPMatchingLn.APMatchingLnPvodIsLgCharge = true*/
else do: /* Non logistic charges */
/* Fill-in the allocated amount-TC */
assign t_sAPMatchingLn.APMatchingLnMatchAmtTC =
<M-22 RoundAmount
(input t_sAPMatchingLn.APMatchingLnMatchQty * t_sAPMatchingLn.APMatchingLnMatchUnitPrice (idUnroundedAmount),
input ? (iiCurrencyID),
input t_sAPMatching.tcCurrencyCode (icCurrencyCode)) in business>
/* Fill-in the allocated amount-LC */
t_sAPMatchingLn.APMatchingLnMatchAmtLC =
<M-23 RoundAmount
(input t_sAPMatchingLn.APMatchingLnMatchAmtTC * t_sAPMatching.tdCInvoiceExchangeRate * t_sAPMatching.tdCinvoiceRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input ? (icCurrencyCode)) in business>
/* Fill-in the allocated amount-CC */
t_sAPMatchingLn.APMatchingLnMatchAmtCC =
<M-46 RoundAmount
(input t_sAPMatchingLn.APMatchingLnMatchAmtTC * t_sAPMatching.tdCInvoiceCCRate * t_sAPMatching.tdCinvoiceCCScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input ? (icCurrencyCode)) in business>
/* Fill-in the receipt-amount-TC */
t_sAPMatchingLn.APMatchingLnReceiptAmtTC =
<M-24 RoundAmount
(input t_sAPMatchingLn.APMatchingLnPvodUnitPrice * (if t_sAPMatchingLn.APMatchingLnIsPvodFinished = true then t_sAPMatchingLn.APMatchingLnPvodOpenQty else t_sAPMatchingLn.APMatchingLnMatchQty) (idUnroundedAmount),
input ? (iiCurrencyID),
input t_sAPMatching.tcCurrencyCode (icCurrencyCode)) in business>
/* Fill-in the receipt-amount-LC */
t_sAPMatchingLn.APMatchingLnReceiptAmtLC =
<M-25 RoundAmount
(input t_sAPMatchingLn.APMatchingLnReceiptAmtTC * t_sAPMatchingLn.APMatchingLnPvodExchRate2 / t_sAPMatchingLn.APMatchingLnPvodExchRate (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input ? (icCurrencyCode)) in business>.
/* Fill-in the receipt-amount-CC */
/* NOTE; The CC-value posted on the receipt-account should be calculated based upon the rounded LC-value */
/* Mathematically it should be more correct to start the caluclation of the CC-value based upon the rounded LC-value but as the operational side starts the calculation from the rounded-amoutn, we have to act the same here as we would otherwise have a difference we cannot get rid off */
/* See also FIN-2072 as this change was made based upon that ticket */
/* Note that a similar change is made in method AdditionalUpdatesAllLinesPLReceiptPvod*/
if vcCompanyCC <> t_sAPMatchingLn.APMatchingLnPvodCurrency
then assign t_sAPMatchingLn.APMatchingLnReceiptAmtCC = <M-48 RoundAmount
(input t_sAPMatchingLn.APMatchingLnReceiptAmtLC * t_sAPMatchingLn.APMatchingLnPvodCCRate * t_sAPMatchingLn.APMatchingLnPvodCCScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input ? (icCurrencyCode)) in BAPMatching>.
else assign t_sAPMatchingLn.APMatchingLnReceiptAmtCC = t_sAPMatchingLn.APMatchingLnReceiptAmtTC.
assign
/* Fill-in the Var-Rate-TC */
t_sAPMatchingLn.APMatchingLnVarRateTC =
<M-42 RoundAmount
(input t_sAPMatchingLn.APMatchingLnMatchUnitPrice * t_sAPMatchingLn.APMatchingLnMatchQty (idUnroundedAmount),
input ? (iiCurrencyID),
input t_sAPMatching.tcCurrencyCode (icCurrencyCode)) in BAPMatching> -
<M-43 RoundAmount
(input t_sAPMatchingLn.APMatchingLnPvodUnitPrice * t_sAPMatchingLn.APMatchingLnMatchQty (idUnroundedAmount),
input ? (iiCurrencyID),
input t_sAPMatching.tcCurrencyCode (icCurrencyCode)) in BAPMatching>
/* Fill-in the Var-Rate-LC */
t_sAPMatchingLn.APMatchingLnVarRateLC =
<M-26 RoundAmount
(input t_sAPMatchingLn.APMatchingLnVarRateTC * t_sAPMatching.tdCInvoiceExchangeRate * t_sAPMatching.tdCinvoiceRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input ? (icCurrencyCode)) in business>
/* Fill-in the Var-Rate-CC */
t_sAPMatchingLn.APMatchingLnVarRateCC =
<M-50 RoundAmount
(input t_sAPMatchingLn.APMatchingLnVarRateTC * t_sAPMatching.tdCInvoiceCCRate * t_sAPMatching.tdCinvoiceCCScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input ? (icCurrencyCode)) in business>
/* Fill-in the Var-Usage-TC */
t_sAPMatchingLn.APMatchingLnVarUsageTC =
(if t_sAPMatchingLn.APMatchingLnIsPvodFinished <> true
then 0
else <M-44 RoundAmount
(input t_sAPMatchingLn.APMatchingLnMatchQty * t_sAPMatchingLn.APMatchingLnPvodUnitPrice (idUnroundedAmount),
input ? (iiCurrencyID),
input t_sAPMatching.tcCurrencyCode (icCurrencyCode)) in BAPMatching> -
<M-45 RoundAmount
(input t_sAPMatchingLn.APMatchingLnPvodOpenQty * t_sAPMatchingLn.APMatchingLnPvodUnitPrice (idUnroundedAmount),
input ? (iiCurrencyID),
input t_sAPMatching.tcCurrencyCode (icCurrencyCode)) in BAPMatching> )
/* Fill-in the Var-Usage-LC */
t_sAPMatchingLn.APMatchingLnVarUsageLC =
(if t_sAPMatchingLn.APMatchingLnIsPvodFinished <> true
then 0
else <M-27 RoundAmount
(input t_sAPMatchingLn.APMatchingLnVarUsageTC * t_sAPMatching.tdCInvoiceExchangeRate * t_sAPMatching.tdCinvoiceRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input ? (icCurrencyCode)) in business>)
/* Fill-in the Var-Usage-CC */
t_sAPMatchingLn.APMatchingLnVarUsageCC =
(if t_sAPMatchingLn.APMatchingLnIsPvodFinished <> true
then 0
else <M-49 RoundAmount
(input t_sAPMatchingLn.APMatchingLnVarUsageTC * t_sAPMatching.tdCInvoiceCCRate * t_sAPMatching.tdCinvoiceCCScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input ? (icCurrencyCode)) in business>)
/* Fill-in the ExchangeRate-LC */
t_sAPMatchingLn.APMatchingLnVarExchRateLC =
(t_sAPMatchingLn.APMatchingLnMatchAmtLC
- t_sAPMatchingLn.APMatchingLnReceiptAmtLC
- t_sAPMatchingLn.APMatchingLnVarUsageLC
- t_sAPMatchingLn.APMatchingLnVarRateLC).
if t_sAPMatching.tdCInvoiceCCRate * t_sAPMatching.tdCInvoiceCCScale <> t_sAPMatchingLn.APMatchingLnPvodCCRate * t_sAPMatchingLn.APMatchingLnPvodCCScale
then assign /* Fill-in the ExchangeRate-CC */
t_sAPMatchingLn.APMatchingLnVarExchRateCC =
(t_sAPMatchingLn.APMatchingLnMatchAmtCC
- t_sAPMatchingLn.APMatchingLnReceiptAmtCC
- t_sAPMatchingLn.APMatchingLnVarUsageCC
- t_sAPMatchingLn.APMatchingLnVarRateCC).
end. /* of else do: Non logistic charges */
end. /* if Base for the calculation */
/* ===================================================================================== */
/* Make sure tAPMatchingLn.APMatchingLnIsVarGLPosting gets assigned to 'true' as default */
/* ===================================================================================== */
if t_sAPMatchingLn.APMatchingLnIsVarGLPosting = ?
then assign t_sAPMatchingLn.APMatchingLnIsVarGLPosting = true.
/* ====================== */
/* Set Return status = OK */
/* ====================== */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.