Description
ERS processor sub-method: used to create temp-table records: each temp-table record will be used to create one supplier invoice.
Parameters
| icERSProcessorRefRowId | input | character | Rowid input parameter: contains the unique rowid number of the temp-table record holding the pending voucher information. |
| idAPMatchingLnRecTotAmt | input | decimal | |
| oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program5/bersprocessor.p)
/* =================================================================================================== */
/* Method : ERSProcessCInvoice */
/* Desc : Create record for creation of supplier invoice */
/* --------------------------------------------------------------------------------------------------- */
/* Params: (I) ERSProcessorRefRowId Row id of record in temporary table with list of receipts */
/* =================================================================================================== */
assign oiReturnStatus = -98.
if idAPMatchingLnRecTotAmt <> 0 or
idAPMatchingLnRecTotAmt <> ?
then
assign vdAPMatchingLnRecTotAmt = idAPMatchingLnRecTotAmt.
find bERSProcessorRef where
bERSProcessorRef.tcFcRowid = icERSProcessorRefRowId
no-error.
/* =================================================================================================== */
/* Initial validation: input parameters and temp-table records. */
/* =================================================================================================== */
if icERSProcessorRefRowId = ? or
icERSProcessorRefRowId = '':U or
not available bERSProcessorRef or
(not available tqPendingVoucherForERSDetail and vcGroupBy = {&ERSPROCESSORINVGROUP-RECEIVER}) or
(not available tqLegalDocumentPendVoucherDetail and vcGroupBy = {&ERSPROCESSORINVGROUP-LEGALDOC} and not bERSProcessorRef.tlIsLogCharge) or
(not available tqLogAcctPendingVoucherForERS and vcGroupBy = {&ERSPROCESSORINVGROUP-LEGALDOC} and bERSProcessorRef.tlIsLogCharge)
then do:
assign vcMessage = #T-1'The specified input parameters are invalid.':255(70371)t-1#
vcContext = 'icERSProcessorRefRowId=&1|available bERSProcessorRef=&2|available tqPendingVoucherForERSDetail=&3':U
vcContext = replace(vcContext, '|':U, chr(2))
vcContext = substitute(vcContext, icERSProcessorRefRowId, available bERSProcessorRef, available tqPendingVoucherForERSDetail).
<M-2 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'S':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8383':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input vcContext (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
assign oiReturnStatus = -1.
return.
end.
/* =================================================================================================== */
/* Check the GL Correction Control to get the value for accounts payable flag */
/* If the accounts payable flag is set to "yes" in GL correction control, */
/* ERS should create a supplier invoice of invoice type invoice correction. */
/* =================================================================================================== */
<Q-18 run GLCorrectionControlByDomain (all) (Read) (NoCache)
(input vcDomainCode, (DomainCode)
output dataset tqGLCorrectionControlByDomain) in BMFGGLCorrectionControl>
find first tqGLCorrectionControlByDomain where
tqGLCorrectionControlByDomain.tcglcor_domain = vcDomainCode no-error.
assign vlGLCorrAp = false.
if available tqGLCorrectionControlByDomain
then assign vlGLCorrAp = tqGLCorrectionControlByDomain.tlglcor_ap.
/* =================================================================================================== */
/* Create record for invoice creation */
/* =================================================================================================== */
if vcGroupBy = {&ERSPROCESSORINVGROUP-LEGALDOC}
then do:
find first tCInvoiceRefERS where
tCInvoiceRefERS.tc_Rowid = bERSProcessorRef.tcCInvoiceReference + ',':U + bERSProcessorRef.tcSupplier
no-error.
if not available tCInvoiceRefERS
then do:
create tCInvoiceRefERS.
assign tCInvoiceRefERS.tcCInvoiceReference = bERSProcessorRef.tcCInvoiceReference
tCInvoiceRefERS.tcCInvoiceDescription = bERSProcessorRef.tcCInvoiceReference
tCInvoiceRefERS.tcCompanyCode = vcCompanyCode
tCInvoiceRefERS.tcCreditorCode = bERSProcessorRef.tcSupplier
tCInvoiceRefERS.tcCurrencyCode = bERSProcessorRef.tcCInvoiceCurrencyCode
tCInvoiceRefERS.tdCInvoiceAmountTC = 0
tCInvoiceRefERS.tlIsInitialStatus = (bERSProcessorRef.tiERSOpt = {&ERS_OPT_CI_INIT})
tCInvoiceRefERS.tlAPMatchingIsStatusFinal = not tCInvoiceRefERS.tlIsInitialStatus
tCInvoiceRefERS.ttCInvoiceDiscountDueDate = ?
tCInvoiceRefERS.tlCInvoiceIsERS = true
tCInvoiceRefERS.tcAPMatchingJournalCode = vcAPMatchingJournalCode
tCInvoiceRefERS.tcCInvoiceBatchNumber = vcBatchNumber
tCInvoiceRefERS.tcCInvoiceType = (if vdAPMatchingLnRecTotAmt >= 0
then {&INVOICETYPE-INVOICE}
else if vlGLCorrAp = true
then {&INVOICETYPE-INVOICECORRECTION}
else {&INVOICETYPE-CREDITNOTE})
tCInvoiceRefERS.tc_Rowid = bERSProcessorRef.tcCInvoiceReference + ',':U + bERSProcessorRef.tcSupplier.
if bERSProcessorRef.tlIsLogCharge
then do:
assign tCInvoiceRefERS.tcNormalPaymentConditionCode = tqLegalDocumentPendVoucherLCForE.tclgd_cr_terms
tCInvoiceRefERS.tcShipToBusinessRelationCode = tqLegalDocumentPendVoucherLCForE.tclgd_ship
tCInvoiceRefERS.tdExchangeRate = 1
tCInvoiceRefERS.tdRateScale = 1
tCInvoiceRefERS.tlCInvoiceIsTaxable = tqLegalDocumentPendVoucherLCForE.tllgd_taxable
tCInvoiceRefERS.ttCInvoiceDueDate = tqLegalDocumentPendVoucherLCForE.ttlgd_due_date
tCInvoiceRefERS.ttCInvoiceDate = tqLegalDocumentPendVoucherLCForE.ttlgd_effdate
tCInvoiceRefERS.ttPostingDate = tqLegalDocumentPendVoucherLCForE.ttlgd_receive_date
tCInvoiceRefERS.ttTaxPointDate = tqLegalDocumentPendVoucherLCForE.ttlgd_tax_date.
assign vhFcComponent = ?
vcSite = if (tqLogAcctPendingVoucherForERS.tcpvo_order_type = {&PENDINGVOUCHER-ORDERTYPE-SO} OR
tqLogAcctPendingVoucherForERS.tcpvo_order_type = {&PENDINGVOUCHER-ORDERTYPE-DO})
then tqLogAcctPendingVoucherForERS.tcpvo_shipfrom
else tqLogAcctPendingVoucherForERS.tcpvo_shipto.
/* Inbound from PO, outbound - default daybook set from Supplier Data Mainteannce - vd_mstr.vd_daybookset (logistic) */
<M-75 run ApiGetDaybookCodeByType
(input tqLogAcctPendingVoucherForERS.tcvd_daybookset (icDaybookSetCode),
input vcSite (icSite),
input '2':U (icDaybookSetType),
input tCInvoiceRefERS.tcCInvoiceType (icInvoiceType),
output tCInvoiceRefERS.tcCInvoiceJournalCode (ocDaybookCode),
output oiReturnStatus (oiReturnStatus)) in BMfgDaybookSet>
if oiReturnStatus <> 0 then return.
end.
else do:
assign tCInvoiceRefERS.tcNormalPaymentConditionCode = tqLegalDocumentPendVoucherDetail.tclgd_cr_terms
tCInvoiceRefERS.tcShipToBusinessRelationCode = tqLegalDocumentPendVoucherDetail.tclgd_ship
tCInvoiceRefERS.tdExchangeRate = tqLegalDocumentPendVoucherDetail.tdlgd_ex_rate2 / tqLegalDocumentPendVoucherDetail.tdlgd_ex_rate
tCInvoiceRefERS.tdRateScale = 1
tCInvoiceRefERS.tlCInvoiceIsTaxable = tqLegalDocumentPendVoucherDetail.tlpo_taxable
tCInvoiceRefERS.ttCInvoiceDueDate = tqLegalDocumentPendVoucherDetail.ttlgd_due_date
tCInvoiceRefERS.ttCInvoiceDate = tqLegalDocumentPendVoucherDetail.ttlgd_effdate
tCInvoiceRefERS.ttPostingDate = tqLegalDocumentPendVoucherDetail.ttlgd_receive_date
tCInvoiceRefERS.ttTaxPointDate = tqLegalDocumentPendVoucherDetail.ttlgd_tax_date.
assign vhFcComponent = ?.
<M-20 run ApiGetDaybookCodeByType
(input tqLegalDocumentPendVoucherDetail.tcpo_daybookset (icDaybookSetCode),
input tqLegalDocumentPendVoucherDetail.tcpo_site (icSite),
input '2':U (icDaybookSetType),
input tCInvoiceRefERS.tcCInvoiceType (icInvoiceType),
output tCInvoiceRefERS.tcCInvoiceJournalCode (ocDaybookCode),
output oiReturnStatus (oiReturnStatus)) in BMfgDaybookSet>
if oiReturnStatus <> 0 then return.
end.
end.
end. /* if vcGroupBy = {&ERSPROCESSORINVGROUP-LEGALDOC} */
/* Purchase order receipt */
else do:
create tCInvoiceRefERS.
assign tCInvoiceRefERS.tcCInvoiceReference = bERSProcessorRef.tcCInvoiceReference
tCInvoiceRefERS.tcCInvoiceDescription = bERSProcessorRef.tcCInvoiceReference
tCInvoiceRefERS.tcCompanyCode = vcCompanyCode
tCInvoiceRefERS.tcCreditorCode = bERSProcessorRef.tcSupplier
tCInvoiceRefERS.tcCurrencyCode = bERSProcessorRef.tcCInvoiceCurrencyCode
tCInvoiceRefERS.tcNormalPaymentConditionCode = tqPendingVoucherForERSDetail.tcpo_cr_terms
tCInvoiceRefERS.tcShipToBusinessRelationCode = tqPendingVoucherForERSDetail.tcpo_ship
tCInvoiceRefERS.tdCInvoiceAmountTC = 0
tCInvoiceRefERS.tdExchangeRate = ? /* take exchange rate of posting date */
tCInvoiceRefERS.tdRateScale = ?
tCInvoiceRefERS.tlCInvoiceIsTaxable = tqPendingVoucherForERSDetail.tlpo_taxable
tCInvoiceRefERS.tlIsInitialStatus = (bERSProcessorRef.tiERSOpt = {&ERS_OPT_CI_INIT})
tCInvoiceRefERS.tlAPMatchingIsStatusFinal = not tCInvoiceRefERS.tlIsInitialStatus
tCInvoiceRefERS.ttCInvoiceDiscountDueDate = ?
tCInvoiceRefERS.ttCInvoiceDueDate = ?
tCInvoiceRefERS.ttCInvoiceDate = (if tqPendingVoucherForERSDetail.tlpvo_consignment
then tqPendingVoucherForERSDetail.ttpvo_eff_date
else if tqAccountsPayableCtrlByDomain.tiapc_ers_vo_tp = 1
then tqPendingVoucherForERSDetail.ttprh_ship_date
else tqPendingVoucherForERSDetail.ttprh_rcp_date)
tCInvoiceRefERS.ttPostingDate = today
tCInvoiceRefERS.ttTaxPointDate = (if tqPendingVoucherForERSDetail.ttpo_tax_date <> ?
then tqPendingVoucherForERSDetail.ttpo_tax_dat
else tCInvoiceRefERS.ttPostingDate)
tCInvoiceRefERS.tlCInvoiceIsERS = true
tCInvoiceRefERS.tcCInvoiceType = (if vdAPMatchingLnRecTotAmt >= 0
then {&INVOICETYPE-INVOICE}
else if vlGLCorrAp = true
then {&INVOICETYPE-INVOICECORRECTION}
else {&INVOICETYPE-CREDITNOTE})
tCInvoiceRefERS.tcAPMatchingJournalCode = vcAPMatchingJournalCode
tCInvoiceRefERS.tcCInvoiceBatchNumber = vcBatchNumber
tCInvoiceRefERS.tc_Rowid = tCInvoiceRefERS.tcCInvoiceReference.
assign vhFcComponent = ?.
<M-12 run ApiGetDaybookCodeByType
(input tqPendingVoucherForERSDetail.tcpo_daybookset (icDaybookSetCode),
input tqPendingVoucherForERSDetail.tcpo_site (icSite),
input '2':U (icDaybookSetType),
input tCInvoiceRefERS.tcCInvoiceType (icInvoiceType),
output tCInvoiceRefERS.tcCInvoiceJournalCode (ocDaybookCode),
output oiReturnStatus (oiReturnStatus)) in BMfgDaybookSet>
if oiReturnStatus <> 0 then return.
end. /* NOT if vcGroupBy = {&ERSPROCESSORINVGROUP-LEGALDOC} */
/* =================================================================================================== *
* During one run two different supplier invoices can be created. But there is restriction which *
* prevents creation of two invoices of same supplier with same reference *
* =================================================================================================== */
if bERSProcessorRef.tiERSOpt = {&ERS_OPT_CI_INIT} and
can-find(first tERSProcessorRef where
tERSProcessorRef.tcDomainCode = bERSProcessorRef.tcDomainCode and
tERSProcessorRef.tcReceiverNbr = bERSProcessorRef.tcReceiverNbr and
tERSProcessorRef.tiERSOpt = {&ERS_OPT_CI_FINAL})
then assign tCInvoiceRefERS.tcCInvoiceReference = tCInvoiceRefERS.tcCInvoiceReference + ' 1':U
tCInvoiceRefERS.tc_Rowid = tCInvoiceRefERS.tc_Rowid + ' 1':U.
/* =================================================================================================== */
/* Return */
/* =================================================================================================== */
if oiReturnStatus = -98 then assign oiReturnStatus = 0.