Description
Sub-method that finds the pending vouchers attached to a legal document.
Parameters
icDomainCode | input | character | Filtering parameter: domain code. |
icSupplier | input | character | Filtering parameter: supplier codes. |
icSupplierFrom | input | character | Filtering parameter: start value for the supplier codes. |
icSupplierTo | input | character | Filtering parameter: end value for the supplier codes. |
icSite | input | character | |
icSiteFrom | input | character | Filtering parameter: start value for the site codes. |
icSiteTo | input | character | Filtering parameter: end value for the site codes. |
icReceiver | input | character | Filtering parameter: receiver number. |
icReceiverFrom | input | character | Filtering parameter: start value for the receiver number. |
icReceiverTo | input | character | Filtering parameter: end value for the receiver number. |
itReceiptDate | input | date | Filtering parameter: receipt dates. |
itReceiptDateFrom | input | date | Filtering parameter: beginng date of the receipt dates. |
itReceiptDateTo | input | date | Filtering parameter: endign date of the receipt dates. |
icLegalDocument | input | character | |
icLegalDocumentFrom | input | character | |
icLegalDocumentTo | input | character | Filtering parameter: end value for the legal document number. |
itEffIssueDate | input | date | Filtering parameter: beginng date of the effective issue dates. |
itEffIssueDateFrom | input | date | Filtering parameter: beginng date of the effective issue dates. |
itEffIssueDateTo | input | date | Filtering parameter: ending date of the effective issue dates. |
tERSProcessorRef | output | temp-table | Output temp-table: used to store the pending vouchers being considered for ERS Processing. |
tERSProcessorLogRef | output | temp-table | Output temp-table: used to log status information for the pending vouchers being considered by the ERS Processor. |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program5/bersprocessor.p)
/* =================================================================================================== *
* Retrieve pending vouchers which can be processed by ERS processor and for which Legal documents *
* exist *
* =================================================================================================== */
define buffer btqLegalDocPendVoucherForERS for tqLegalDocumentPendVoucherForERS.
/* =================================================================================================== */
/* Query database */
/* =================================================================================================== */
<Q-40 run LegalDocumentPendVoucherForERS (all) (Read) (NoCache)
(input icDomainCode, (Domain)
input icSupplier, (Supplier)
input icSupplierFrom, (SupplierFrom)
input icSupplierTo, (SupplierTo)
input icSite, (Site)
input icSiteFrom, (SiteFrom)
input icSiteTo, (SiteTo)
input icReceiver, (Receiver)
input icReceiverFrom, (ReceiverFrom)
input icReceiverTo, (ReceiverTo)
input itReceiptDate, (ReceiptDate)
input itReceiptDateFrom, (ReceiptDateFrom)
input itReceiptDateTo, (ReceiptDateTo)
input icLegalDocument, (LegalDoc)
input icLegalDocumentFrom, (LegalDocFrom)
input icLegalDocumentTo, (LegalDocTo)
input itEffIssueDate, (EffDate)
input itEffIssueDateFrom, (EffDateFrom)
input itEffIssueDateTo, (EffDateTo)
output dataset tqLegalDocumentPendVoucherForERS) in BMFGLegalDocument>
/* =================================================================================================== */
/* Remove pending vouchers, that were incorrectly read. We cannot have that directly doen in the query */
/* because of complexity */
/* =================================================================================================== */
assign vcDateFormat = session:date-format
session:date-format = "ymd".
for each tqLegalDocumentPendVoucherForERS:
/* Remove duplicate records */
if can-find(first btqLegalDocPendVoucherForERS where
btqLegalDocPendVoucherForERS.tclgd_domain = tqLegalDocumentPendVoucherForERS.tclgd_domain and
btqLegalDocPendVoucherForERS.tclgd_nbr = tqLegalDocumentPendVoucherForERS.tclgd_nbr and
btqLegalDocPendVoucherForERS.ttlgd_effdate = tqLegalDocumentPendVoucherForERS.ttlgd_effdate and
btqLegalDocPendVoucherForERS.tcpvo_supplier = tqLegalDocumentPendVoucherForERS.tcpvo_supplier and
btqLegalDocPendVoucherForERS.tipvo_id = tqLegalDocumentPendVoucherForERS.tipvo_id and
btqLegalDocPendVoucherForERS.tipvod_id_line = tqLegalDocumentPendVoucherForERS.tipvod_id_line and
recid(btqLegalDocPendVoucherForERS) <> recid(tqLegalDocumentPendVoucherForERS))
then do:
delete tqLegalDocumentPendVoucherForERS.
next.
end.
if tqLegalDocumentPendVoucherForERS.tllgd_posted = true
then do:
delete tqLegalDocumentPendVoucherForERS.
next.
end.
assign vcInvoiceReference = trim(tqLegalDocumentPendVoucherForERS.tclgd_nbr) + ',':U +
string(tqLegalDocumentPendVoucherForERS.ttlgd_effdate).
if tqLegalDocumentPendVoucherForERS.tcpvo_external_ref <> vcInvoiceReference
then do:
delete tqLegalDocumentPendVoucherForERS.
next.
end.
/* Remove records from APMatching which are in Initial status */
<Q-60 assign vlFcQueryRecordsAvailable = APMatchingLnByStatusPvod (NoCache)
(input ?, (CompanyId)
input tqLegalDocumentPendVoucherForERS.tclgd_domain, (PvoDomain)
input tqLegalDocumentPendVoucherForERS.tipvo_id, (PvoID)
input tqLegalDocumentPendVoucherForERS.tipvod_id_line, (PvodLineID)
input {&APMATCHINGSTATUS-INITIAL}, (APMatchingStatus)
input ?, (SkipAPMatchingLnRowid)) in BAPMatching>
if vlFcQueryRecordsAvailable <> FALSE
then do:
delete tqLegalDocumentPendVoucherForERS.
next.
end.
end. /* for each tqLegalDocumentPendVoucherForERS where */
assign session:date-format = vcDateFormat.
/* =================================================================================================== */
/* Go through pending vouchers and and created records for ERS processor grid */
/* =================================================================================================== */
for each tqLegalDocumentPendVoucherForERS
break by tqLegalDocumentPendVoucherForERS.tclgd_domain
by tqLegalDocumentPendVoucherForERS.tclgd_nbr
by tqLegalDocumentPendVoucherForERS.ttlgd_effdate
by tqLegalDocumentPendVoucherForERS.tcpvo_supplier
by tqLegalDocumentPendVoucherForERS.tclgdd_order
by tqLegalDocumentPendVoucherForERS.tilgdd_order_line
by tqLegalDocumentPendVoucherForERS.tipvo_id
by tqLegalDocumentPendVoucherForERS.tipvod_id_line:
/* Get details for Legal document header */
if first-of(tqLegalDocumentPendVoucherForERS.tcpvo_supplier)
then do:
/* Read legal document data only when not yet done */
if not(can-find(first tLgddDetMatForAPMERS where
tLgddDetMatForAPMERS.tclgd_domain = tqLegalDocumentPendVoucherForERS.tclgd_domain and
tLgddDetMatForAPMERS.tclgd_nbr = tqLegalDocumentPendVoucherForERS.tclgd_nbr and
tLgddDetMatForAPMERS.ttlgd_effdate = tqLegalDocumentPendVoucherForERS.ttlgd_effdate and
tLgddDetMatForAPMERS.tclgd_shipfrom = tqLegalDocumentPendVoucherForERS.tcpvo_supplier)) and
not(can-find(first tLgddDetLCForAPMERS where
tLgddDetLCForAPMERS.tclgd_domain = tqLegalDocumentPendVoucherForERS.tclgd_domain and
tLgddDetLCForAPMERS.tclgd_nbr = tqLegalDocumentPendVoucherForERS.tclgd_nbr and
tLgddDetLCForAPMERS.ttlgd_effdate = tqLegalDocumentPendVoucherForERS.ttlgd_effdate and
tLgddDetLCForAPMERS.tclgd_shipfrom = tqLegalDocumentPendVoucherForERS.tcpvo_supplier))
then do:
/* instantiate method */
if viBMFGLegalDocumentID = 0 or
viBMFGLegalDocumentID = ?
then do:
<I-13 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "no"
&CLASS = "BMFGLegalDocument"}>
end.
else if not valid-handle(vhBMFGLegalDocumentInst)
then do:
<I-69 {bFcOpenInstance
&CLASS = "BMFGLegalDocument"}>
end.
/* Retrieve all legal document lines for one legal document */
<M-68 run GetLegalDocumentDetForAPMatching
(input tqLegalDocumentPendVoucherForERS.tclgd_domain (icLgdDomain),
input tqLegalDocumentPendVoucherForERS.tclgd_nbr (icLgdNbr),
input tqLegalDocumentPendVoucherForERS.tcpvo_supplier (icLgdSuppl),
input tqLegalDocumentPendVoucherForERS.ttlgd_effdate (itLgdEffDate),
input ? (icInvSuppl),
input ? (iiLgddLine),
input ? (icLgddDocType),
input ? (icLgddOrder),
input ? (iiLgddOrderLine),
output tLgddDetMatForAPMERS (tLgddDetMatForAPM),
output tLgddDetLCForAPMERS (tLgddDetLCForAPM),
output tLgddDetLCDistForAPMERS (tLgddDetLCDistForAPM),
output tLgddDetTaxForAPMERS (tLgddDetTaxForAPM),
output viFcReturnSuper (oiReturnStatus)) in BMFGLegalDocument>
if viFcReturnSuper < 0 or viFcReturnSuper > 0 and oiReturnStatus = 0 then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
end. /* if not-can find(first tLgddDetMatForAPMERS where */
end. /* if first-of(tqLegalDocumentPendVoucherForERS.tcpvo_supplier) */
/* Get details for Legal document line grouped by the Purchase Order Line */
if first-of(tqLegalDocumentPendVoucherForERS.tilgdd_order_line)
then do:
find first tLgddDetMatForAPMERS where
tLgddDetMatForAPMERS.tclgd_domain = tqLegalDocumentPendVoucherForERS.tclgd_domain and
tLgddDetMatForAPMERS.tclgd_nbr = tqLegalDocumentPendVoucherForERS.tclgd_nbr and
tLgddDetMatForAPMERS.ttlgd_effdate = tqLegalDocumentPendVoucherForERS.ttlgd_effdate and
tLgddDetMatForAPMERS.tcSupplier = tqLegalDocumentPendVoucherForERS.tcpvo_supplier and
tLgddDetMatForAPMERS.tclgdd_order = tqLegalDocumentPendVoucherForERS.tclgdd_order and
tLgddDetMatForAPMERS.tilgdd_order_line = tqLegalDocumentPendVoucherForERS.tilgdd_order_line
no-error.
if not available tLgddDetMatForAPMERS
then do:
assign vcMessage = #T-10'No record found.':255(295224748)T-10#
vcContext = "lgd_domain=&1|lgd_nbr=&2|lgd_effdate=&3|lgd_ship=&4|lgdd_order=&5|lgdd_order_line=&6":U
vcContext = substitute(vcContext, tqLegalDocumentPendVoucherForERS.tclgd_domain,
tqLegalDocumentPendVoucherForERS.tclgd_nbr,
tqLegalDocumentPendVoucherForERS.ttlgd_effdate,
tqLegalDocumentPendVoucherForERS.tcpvo_supplier,
tqLegalDocumentPendVoucherForERS.tclgdd_order,
tqLegalDocumentPendVoucherForERS.tilgdd_order_line)
vcContext = replace(vcContext, "|":U, chr(2)).
<M-98 run SetMessage
(input vcMessage (icMessage),
input ? (icArguments),
input ? (icFieldName),
input ? (icFieldValue),
input 'S':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'qadfin-507364':U (icFcMsgNumber),
input ? (icFcExplanation),
input ? (icFcIdentification),
input vcContext (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
assign oiReturnStatus = -1.
return.
end. /* if not available tLgddDetMatForAPMERS */
/* =========================================================================================== *
* Quantity distribution from the Legal document lines for one Purchase order line is normally *
* done to keep received quantity. But there are situations, when the allocated quantity for *
* the last receipt is zero. And this is not supported. *
* Example: Legal document line qty = 5 pcs *
* Purchase receipt 1 qty = 5 pcs *
* Purchase receipt 2 qty = 1 pcs *
* So in this case the system would calculated matched qty for 2nd receipt as 0. So in this *
* case we will do qty pro-rata. Which we normally try to limit because of rounding issues. *
* =========================================================================================== */
<M-70 run GetERSLegalDocumentsNoLCQtyDist
(input tqLegalDocumentPendVoucherForERS.tclgd_domain (icDomainCode),
input tqLegalDocumentPendVoucherForERS.tclgd_nbr (icLegalDocumentNumber),
input tqLegalDocumentPendVoucherForERS.ttlgd_effdate (itEffectiveDate),
input tqLegalDocumentPendVoucherForERS.tcpvo_supplier (icSupplier),
input tqLegalDocumentPendVoucherForERS.tclgdd_order (icPurchaseOrder),
input tqLegalDocumentPendVoucherForERS.tilgdd_order_line (iiPurchaseOrderLine),
output vcQtyDistMethod (ocQtyDistMethod),
output viQtyPrecission (oiMaxPrecission),
output vdTotalReceiptQuantity (odTotalReceiptQuantity),
output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
if viLocalReturn < 0 or viLocalReturn > 0 and oiReturnStatus = 0 then assign oiReturnStatus = viLocalReturn.
if oiReturnStatus < 0 then return.
end. /* if first-of(tqLegalDocumentPendVoucherForERS.tilgdd_order_line) */
/* Calculate quantity */
/* If this his purchase order return, take quantity from the pending voucher */
if tLgddDetMatForAPMERS.tlIsPOReturn = true
then assign vdInvoiceQuantity = tqLegalDocumentPendVoucherForERS.tdpvod_trans_qty.
/* If there is only one receipt for the Legal document line, take quantity from the legal document */
/* if there are multiple receipts, total invoiced quantity at the end must match legal document quantity */
else do:
if first-of(tqLegalDocumentPendVoucherForERS.tilgdd_order_line)
then assign vdTotalInvoiceQuantity = tLgddDetMatForAPMERS.tdlgdd_qty_item_po_uom.
assign vdInvoiceQuantity = if vcQtyDistMethod = {&ERSPROCESSOR-QTY-DIST-BASED-RECEIPT}
then tqLegalDocumentPendVoucherForERS.tdpvod_trans_qty
else round(tqLegalDocumentPendVoucherForERS.tdpvod_trans_qty * tLgddDetMatForAPMERS.tdlgdd_qty_item_po_uom / vdTotalReceiptQuantity , viQtyPrecission + 1)
vdTotalInvoiceQuantity = vdTotalInvoiceQuantity - vdInvoiceQuantity.
if last-of(tqLegalDocumentPendVoucherForERS.tilgdd_order_line)
then assign vdInvoiceQuantity = vdInvoiceQuantity + vdTotalInvoiceQuantity
vdTotalInvoiceQuantity = 0.
end. /* else if tLgddDetMatForAPMERS.tlIsPOReturn = true */
/* Construct invoice reference in format "Lgd_nbr,Lgd_effDate" */
assign vcDateFormat = session:date-format
session:date-format = "ymd".
assign vcInvoiceReference = trim(tqLegalDocumentPendVoucherForERS.tclgd_nbr) + ',':U +
string(tqLegalDocumentPendVoucherForERS.ttlgd_effdate).
assign session:date-format = vcDateFormat.
/* create record in resulting temporary table */
create tERSProcessorRef.
assign tERSProcessorRef.tiPvoId = tqLegalDocumentPendVoucherForERS.tipvo_id
tERSProcessorRef.tiPvodLineId = tqLegalDocumentPendVoucherForERS.tipvod_id_line
tERSProcessorRef.tcCInvoiceCurrencyCode = tqLegalDocumentPendVoucherForERS.tcpvo_curr
tERSProcessorRef.tcCInvoiceReference = vcInvoiceReference
tERSProcessorRef.tcDomainCode = tqLegalDocumentPendVoucherForERS.tclgd_domain
tERSProcessorRef.tcPurchaseOrderNbr = tqLegalDocumentPendVoucherForERS.tclgdd_order
tERSProcessorRef.tcReceiverNbr = tqLegalDocumentPendVoucherForERS.tcpvo_internal_ref
tERSProcessorRef.tdAPMatchingLnMatchQty = vdInvoiceQuantity
tERSProcessorRef.tdAPMatchingLnMatchUnitPriceLC = tLgddDetMatForAPMERS.tdlgdd_price_po_uom
- (if tLgddDetMatForAPMERS.tlIsPOReturn = true
then 0
else tLgddDetMatForAPMERS.tdlgdd_dsc_amt / tLgddDetMatForAPMERS.tdlgdd_qty_item_po_uom)
tERSProcessorRef.tdAPMatchingLnMatchUnitPriceTC = tERSProcessorRef.tdAPMatchingLnMatchUnitPriceLC * tLgddDetMatForAPMERS.tdlgd_ex_rate / tLgddDetMatForAPMERS.tdlgd_ex_rate2
tERSProcessorRef.tdAPMLnMatchUnitPriceBaseTC = tLgddDetMatForAPMERS.tdlgdd_price_base_po_uom * tLgddDetMatForAPMERS.tdlgd_ex_rate / tLgddDetMatForAPMERS.tdlgd_ex_rate2
tERSProcessorRef.tdAPMatchingLnExtendedCostLC = (tERSProcessorRef.tdAPMatchingLnMatchQty *
tERSProcessorRef.tdAPMatchingLnMatchUnitPriceLC)
tERSProcessorRef.tdAPMatchingLnExtendedCostLC = <M-54 RoundAmount
(input tERSProcessorRef.tdAPMatchingLnExtendedCostLC (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BERSProcessor>
tERSProcessorRef.tdAPMatchingLnExtendedCostTC = tERSProcessorRef.tdAPMatchingLnMatchQty *
tERSProcessorRef.tdAPMatchingLnMatchUnitPriceTC
tERSProcessorRef.tdAPMatchingLnExtendedCostTC = <M-75 RoundAmount
(input tERSProcessorRef.tdAPMatchingLnExtendedCostTC (idUnroundedAmount),
input ? (iiCurrencyID),
input tERSProcessorRef.tcCInvoiceCurrencyCode (icCurrencyCode)) in BERSProcessor>
tERSProcessorRef.tiPurchaseOrderLineNbr = tqLegalDocumentPendVoucherForERS.tilgdd_order_line
tERSProcessorRef.tlIsLogCharge = false
tERSProcessorRef.tlIsSelected = true
tERSProcessorRef.tlIsProcessed = false
tERSProcessorRef.tcFcRowid = tLgddDetMatForAPMERS.tc_Rowid +
string(tqLegalDocumentPendVoucherForERS.tipvo_id) + "|":U +
string(tqLegalDocumentPendVoucherForERS.tipvod_id_line)
tERSProcessorRef.tiERSStatus = tqLegalDocumentPendVoucherForERS.tipvo_ers_status
tERSProcessorRef.tiERSOpt = tqLegalDocumentPendVoucherForERS.tipvo_ers_opt
tERSProcessorRef.tiERSPriceListOption = tqLegalDocumentPendVoucherForERS.tipvo_ers_price_lst_opt
tERSProcessorRef.tcLegalDocNbr = tqLegalDocumentPendVoucherForERS.tclgd_nbr
tERSProcessorRef.tcLegalDocType = tqLegalDocumentPendVoucherForERS.tclgd_doc_type
tERSProcessorRef.tcPOProjectCode = tqLegalDocumentPendVoucherForERS.tcpo_project1
tERSProcessorRef.ttEffectiveIssueDate = tqLegalDocumentPendVoucherForERS.ttlgd_effdate
tERSProcessorRef.tcSupplier = tLgddDetMatForAPMERS.tcSupplier
tERSProcessorRef.tcShipToSite = tqLegalDocumentPendVoucherForERS.tclgd_shipto_site
tERSProcessorRef.tcShipFrom = tLgddDetMatForAPMERS.tclgd_shipfrom
tERSProcessorRef.tlIsReturn = (tLgddDetMatForAPMERS.tlIsPOReturn = true).
/* calculate Receipt ERS option and Price list option */
if tERSProcessorRef.tiERSOpt = ? or
tERSProcessorRef.tiERSOpt = 0
then do:
assign vcSiteCode = if tLgddDetMatForAPMERS.tlIsPOReturn
then tLgddDetMatForAPMERS.tclgd_shipfrom
else tqLegalDocumentPendVoucherForERS.tclgd_ship.
<M-65 run GetERSPendingVouchersERSOpt
(input tERSProcessorRef.tcSupplier (icCreditorCode),
input vcSiteCode (icSiteCode),
input tqLegalDocumentPendVoucherForERS.tcpvo_part (icPartCode),
input-output tERSProcessorRef.tiERSOpt (biERSOption),
input-output tERSProcessorRef.tiERSPriceListOption (biERSPriceListOption),
output viLocalReturn (oiReturnStatus)) in BERSProcessor>
if viLocalReturn < 0 or viLocalReturn > 0 and oiReturnStatus = 0 then assign oiReturnStatus = viLocalReturn.
if oiReturnStatus < 0 then return.
end.
/* if any error occured during processing of receipt -> remove it from processing */
if viLocalReturn < 0 then assign tERSProcessorRef.tiERSStatus = {&PVO_ERS_STATUS_ERROR_PROCESS}.
/* Copy all errors into the receipt line */
<M-81 run CopyToReceiptErrors
(input tERSProcessorRef.tcFcRowid (icReceiptRowId),
input true (ilDeleteSystemErrors),
output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
end. /* for each tqLegalDocumentPendVoucherForERS where */