Description
Calculate matching price of receipt.
Parameters
icERSProcessorRefRowId | input | character | |
odInvoicePrice | output | decimal | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program5/bersprocessor.p)
/* =================================================================================================== */
/* Method : ERSProcessAPMatchingPrice */
/* Desc : Calculate matching price of receipt */
/* --------------------------------------------------------------------------------------------------- */
/* Params: (I) icERSProcessorRefRowId Row Id of record in temporary table */
/* =================================================================================================== */
assign oiReturnStatus = -98.
find bERSProcessorRef where
bERSProcessorRef.tcFcRowid = icERSProcessorRefRowId
no-error.
/* =================================================================================================== */
/* Default output values */
/* =================================================================================================== */
assign vdGLCost = 0
odInvoicePrice = 0.
/* =================================================================================================== */
/* Normalize input parameters */
/* =================================================================================================== */
if icERSProcessorRefRowId = '':U then assign icERSProcessorRefRowId = ?.
/* =================================================================================================== */
/* Validate input parameters */
/* =================================================================================================== */
if icERSProcessorRefRowId = ? or
not available bERSProcessorRef or
not available tqPendingVoucherForERSDetail
then do:
assign vcMessage = #T-2'The specified input parameters are invalid.':255(70371)T-2#
vcContext = 'icERSProcessorRefRowId=&1|available bERSProcessorRef=&2|available tqPendingVoucherForERSDetail=&3':U
vcContext = substitute(vcContext, icERSProcessorRefRowId, available bERSProcessorRef, available tqPendingVoucherForERSDetail).
<M-1 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-8503':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input vcContext (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
assign oiReturnStatus = -1.
return.
end.
/* =================================================================================================== */
/* Fixed price on purchase order */
/* =================================================================================================== */
if tqPendingVoucherForERSDetail.tlpod_fix_pr
then assign odInvoicePrice = tqPendingVoucherForERSDetail.tdprh_curr_amt
* (if tqPendingVoucherForERSDetail.tdpod_um_conv = ?
then 1
else tqPendingVoucherForERSDetail.tdpod_um_conv).
/* =================================================================================================== */
/* Get price from price list */
/* =================================================================================================== */
else do:
if tqPendingVoucherForERSDetail.tcpo_pr_list <> '':U or /* Discrete order discount table */
tqPendingVoucherForERSDetail.tcpo_pr_list2 <> '':U /* Discrete order price table */
then do:
/* Calculate effective date for price calculation */
assign vtEffectiveDate = ?.
case bERSProcessorRef.tiERSPriceListOption:
when 1 then assign vtEffectiveDate = tqPendingVoucherForERSDetail.ttprh_rcp_date.
when 2 then assign vtEffectiveDate = tqPendingVoucherForERSDetail.ttprh_ship_date.
otherwise assign vtEffectiveDate = tqPendingVoucherForERSDetail.ttpo_ord_date.
end case.
/* Price list */
assign vcPriceList = (if tqPendingVoucherForERSDetail.tcpod_pr_list <> '':U
then tqPendingVoucherForERSDetail.tcpod_pr_list
else tqPendingVoucherForERSDetail.tcpo_pr_list2).
/* Get price from price list */
if not valid-handle(vhBMfgPriceListInst)
then do:
if viBMfgPriceListID = 0 or
viBMfgPriceListID = ?
then do:
<I-3 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "false"
&CLASS = "BMfgPriceList"}>
end.
else do:
<I-4 {bFcOpenInstance
&CLASS = "BMfgPriceList"}>
end.
end.
if vcPriceList <> "":U and
vcPriceList <> ?
then do:
<M-5 run GetPrice
(input tqPendingVoucherForERSDetail.tcpod_part (icPart),
input vdPriceQty (idQty),
input tqPendingVoucherForERSDetail.tcpod_um (icUoM),
input tqPendingVoucherForERSDetail.tdpod_um_conv (idUoMConv),
input bERSProcessorRef.tcCInvoiceCurrencyCode (icCurrency),
input vcPriceList (icPriceList),
input vtEffectiveDate (itDate),
input 'L':U (icIncAmountType),
input '':U (icExcAmountType),
output vdListPrice (odPrice),
output vdDummy (odDiscountPct),
output vcAmountType (ocAmountType),
input if tqPendingVoucherForERSDetail.tcpod_type = 'M':U then true else false (ilPodTypeIsMemo),
output viFcReturnSuper (oiReturnStatus)) in BMfgPriceList>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-23 {bFcCloseInstance
&CLASS = "BMfgPriceList"}>
return.
end.
end. /* if vcPriceList <> "":U and */
/* PWI TODO : undo comment-out of the new program code and remove the call to BMfgPriceList:GetPrice).
*
* <I-20 {bFcStartAndOpenInstance
* &ADD-TO-TRANSACTION = "false"
* &CLASS = "PMfgProGetPricePriceList"}>
*
* assign vcAmountType = "L":U.
*
* <M-22 run GetPriceFromPriceList
* (input {&TARGETPROCEDURE} (ihCallerHandle),
* input ? (icDomainCode),
* input ? (iiDomainID),
* input ? (icUserLogin),
* input ? (icGlobalLanguage),
* input tqPendingVoucherForERSDetail.tcpod_part (icPart),
* input vdPriceQty (idQuantity),
* input tqPendingVoucherForERSDetail.tcpod_um (icUnitOfMeasure),
* input bERSProcessorRef.tcCInvoiceCurrencyCode (icCurrencyCode),
* input vcPriceList (icPriceList),
* input vtEffectiveDate (itDate),
* input-output vcAmountType (bcAmountType),
* output vdListPrice (odPrice),
* output vdDummy (odDiscountPercentage),
* output viExternalReturnStatus (oiReturnStatus)) in PMfgProGetPricePriceList>
*
* <I-21 {bFcCloseAndStopInstance
* &CLASS = "PMfgProGetPricePriceList"}>
*
* if viExternalReturnStatus <> 0 then assign oiReturnStatus = viExternalReturnStatus.
* if viExternalReturnStatus < 0 then return.
*
* PWI */
/* =================================================================================================== */
/* We don't have price from price list, let's take real cost registered in the system */
/* =================================================================================================== */
if vdListPrice = 0
then do:
if tqPendingVoucherForERSDetail.tlpo_sched
then do:
/* get cost from cost simulation records */
if not valid-handle(vhBMfgCostingInst)
then do:
if viBMfgCostingID = ? or
viBMfgCostingID = 0
then do:
<I-12 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "false"
&CLASS = "BMfgCosting"}>
end.
else do:
<I-13 {bFcOpenInstance
&CLASS = "BMfgCosting"}>
end.
end.
<M-14 run ApiGetCostingDetails
(input tqPendingVoucherForERSDetail.tcpod_site (icSite),
input tqPendingVoucherForERSDetail.tcpod_part (icPart),
output vcDummy (ocGLCostSet),
output vcDummy (ocGLCostMethod),
output vdGLCost (odGLCost),
output vcDummy (ocCurrentCostSet),
output vcDummy (ocCurrentCostMethod),
output vdDummy (odCurrentCost),
output viFcReturnSuper (oiReturnStatus)) in BMfgCosting>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-24 {bFcCloseInstance
&CLASS = "BMfgCosting"}>
return.
end.
/* price retrieved from costing module is for stock UoM -> recalculate *
* to Purchase UoM and in local currency */
assign vdGLCost = vdGLCost
* tqPendingVoucherForERSDetail.tdpod_um_conv
* tqPendingVoucherForERSDetail.tdpvod_ex_rate
/ tqPendingVoucherForERSDetail.tdpvod_ex_rate2.
end. /* if tqPendingVoucherForERSDetail.tlpo_sched */
else assign vdGLCost = tqPendingVoucherForERSDetail.tdpod_pur_cost.
assign vdListPrice = vdGLCost.
end. /* if vdListPrice = 0 */
end. /* if tqPendingVoucherForERSDetail.tcpo_pr_list <> '':U or */
/* =================================================================================================== */
/* Apply discount from price list */
/* =================================================================================================== */
if (tqPendingVoucherForERSDetail.tcpo_pr_list <> '':U and
not tqPendingVoucherForERSDetail.tlpo_sched) or
(tqPendingVoucherForERSDetail.tcpod_pr_list <> '':U and
tqPendingVoucherForERSDetail.tlpo_sched)
then do:
/* Calculate effective date for price calculation */
assign vtEffectiveDate = ?.
case bERSProcessorRef.tiERSPriceListOption:
when 1 then assign vtEffectiveDate = tqPendingVoucherForERSDetail.ttprh_rcp_date.
when 2 then assign vtEffectiveDate = tqPendingVoucherForERSDetail.ttprh_ship_date.
otherwise assign vtEffectiveDate = tqPendingVoucherForERSDetail.ttpo_ord_date.
end case.
/* Apply discount to calculated amount */
assign vcAmountType = ?
vdPriceQty = (if tqPendingVoucherForERSDetail.tlpo_sched
then tqPendingVoucherForERSDetail.tdprh_rcvd
else tqPendingVoucherForERSDetail.tdpod_qty_ord)
vcPriceList = (if tqPendingVoucherForERSDetail.tlpo_sched
then tqPendingVoucherForERSDetail.tcpod_pr_list
else tqPendingVoucherForERSDetail.tcpo_pr_list).
if not valid-handle(vhBMfgPriceListInst)
then do:
if viBMfgPriceListID = 0 or
viBMfgPriceListID = ?
then do:
<I-71 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "false"
&CLASS = "BMfgPriceList"}>
end.
else do:
<I-86 {bFcOpenInstance
&CLASS = "BMfgPriceList"}>
end.
end.
<M-9 run GetPrice
(input tqPendingVoucherForERSDetail.tcpod_part (icPart),
input vdPriceQty (idQty),
input tqPendingVoucherForERSDetail.tcpod_um (icUoM),
input tqPendingVoucherForERSDetail.tdpod_um_conv (idUoMConv),
input bERSProcessorRef.tcCInvoiceCurrencyCode (icCurrency),
input vcPriceList (icPriceList),
input vtEffectiveDate (itDate),
input '':U (icIncAmountType),
input 'L':U (icExcAmountType),
output vdPrice (odPrice),
output vdDiscount (odDiscountPct),
output vcAmountType (ocAmountType),
input if tqPendingVoucherForERSDetail.tcpod_type = 'M':U then true else false (ilPodTypeIsMemo),
output viFcReturnSuper (oiReturnStatus)) in BMfgPriceList>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
if vdListPrice = 0
then do:
if tqPendingVoucherForERSDetail.tlpo_sched
then do:
/* get cost from cost simulation records */
if not valid-handle(vhBMfgCostingInst)
then do:
if viBMfgCostingID = ? or
viBMfgCostingID = 0
then do:
<I-93 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "false"
&CLASS = "BMfgCosting"}>
end.
else do:
<I-70 {bFcOpenInstance
&CLASS = "BMfgCosting"}>
end.
end.
<M-65 run ApiGetCostingDetails
(input tqPendingVoucherForERSDetail.tcpod_site (icSite),
input tqPendingVoucherForERSDetail.tcpod_part (icPart),
output vcDummy (ocGLCostSet),
output vcDummy (ocGLCostMethod),
output vdGLCost (odGLCost),
output vcDummy (ocCurrentCostSet),
output vcDummy (ocCurrentCostMethod),
output vdDummy (odCurrentCost),
output viFcReturnSuper (oiReturnStatus)) in BMfgCosting>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-29 {bFcCloseInstance
&CLASS = "BMfgCosting"}>
return.
end.
/* price retrieved from costing module is for stock UoM -> recalculate *
* to Purchase UoM and in local currency */
if tqPendingVoucherForERSDetail.tcpod_type = 'M':U and
vdGLCost = 0
then assign vdGLCost = tqPendingVoucherForERSDetail.tdpod_pur_cost.
else assign vdGLCost = vdGLCost
* tqPendingVoucherForERSDetail.tdpod_um_conv
* tqPendingVoucherForERSDetail.tdpvod_ex_rate
/ tqPendingVoucherForERSDetail.tdpvod_ex_rate2.
end. /* if tqPendingVoucherForERSDetail.tlpo_sched */
assign vdListPrice = vdGLCost.
end. /* if vdListPrice = 0 */
case vcAmountType:
when 'P':U then assign vdListPrice = vdPrice
* ((100 - tqPendingVoucherForERSDetail.tdpo_disc_pct) / 100).
when 'D':U then assign vdListPrice = vdListPrice
* ((100 - vdDiscount) / 100).
when 'M':U then assign vdListPrice = tqPendingVoucherForERSDetail.tdpod_pur_cost
* ((100 + vdDiscount) / 100)
* ((100 - tqPendingVoucherForERSDetail.tdpo_disc_pct) / 100).
end case.
end. /* if (tqPendingVoucherForERSDetail.tcpo_pr_list <> '':U and */
/* =================================================================================================== */
/* Store price */
/* =================================================================================================== */
assign odInvoicePrice = vdListPrice.
end. /* else if tqPendingVoucherForERSDetail.tlpod_fix_pr */
/* =================================================================================================== */
/* If still we don't have price, let's try to get it from supplier item definition */
/* =================================================================================================== */
if odInvoicePrice = 0 and
tqPendingVoucherForERSDetail.tcpo_pr_list = '':U and
tqPendingVoucherForERSDetail.tcpo_pr_list2 = '':U and
tqPendingVoucherForERSDetail.tcpod_pr_list = '':U
then do:
if not vlIsStartedtqItemWithVendDet
then do:
<Q-10 run ItemByItemWithVendDet (Start) in BMfgItem >
assign vlIsStartedtqItemWithVendDet = true.
end.
<Q-11 run ItemByItemWithVendDet (all) (Read) (NoCache)
(input tqPendingVoucherForERSDetail.tcpvo_domain, (Domain)
input tqPendingVoucherForERSDetail.tcpod_part, (Part)
input ?, (Vendor)
input ?, (VendorPart)
output dataset tqItemByItemWithVendDet) in BMfgItem>
if tqPendingVoucherForERSDetail.tcpod_vpart = "":U
then
find first tqItemByItemWithVendDet where
tqItemByItemWithVendDet.tcpt_domain = tqPendingVoucherForERSDetail.tcpvo_domain and
tqItemByItemWithVendDet.tcpt_part = tqPendingVoucherForERSDetail.tcpod_part and
tqItemByItemWithVendDet.tcvp_vend = tqPendingVoucherForERSDetail.tcpo_vend
no-error.
else
find first tqItemByItemWithVendDet where
tqItemByItemWithVendDet.tcpt_domain = tqPendingVoucherForERSDetail.tcpvo_domain and
tqItemByItemWithVendDet.tcpt_part = tqPendingVoucherForERSDetail.tcpod_part and
tqItemByItemWithVendDet.tcvp_vend = tqPendingVoucherForERSDetail.tcpo_vend and
tqItemByItemWithVendDet.tcvp_vend_part = tqPendingVoucherForERSDetail.tcpod_vpart
no-error.
if not available tqItemByItemWithVendDet
then
find first tqItemByItemWithVendDet where
tqItemByItemWithVendDet.tcpt_domain = tqPendingVoucherForERSDetail.tcpvo_domain and
tqItemByItemWithVendDet.tcpt_part = tqPendingVoucherForERSDetail.tcpod_part
no-error.
if available tqItemByItemWithVendDet
then do:
/* Get quantity used for price definition */
assign vdPriceQty = (if tqPendingVoucherForERSDetail.tlpo_sched
then tqPendingVoucherForERSDetail.tdprh_rcvd
else tqPendingVoucherForERSDetail.tdpod_qty_ord).
/* Item UoM is the same as UoM of Vendor Item definition */
if tqItemByItemWithVendDet.tcvp_um = tqItemByItemWithVendDet.tcpt_um and
tqItemByItemWithVendDet.tcvp_curr = tqPendingVoucherForERSDetail.tcpo_curr and
tqItemByItemWithVendDet.tdvp_q_qty <= vdPriceQty and
tqItemByItemWithVendDet.tdvp_q_price > 0
then assign odInvoicePrice = tqItemByItemWithVendDet.tdvp_q_price * tqPendingVoucherForERSDetail.tdpod_um_conv.
/* Puchase UoM is the same as UoM of Vendor Item definition */
else if tqItemByItemWithVendDet.tcvp_um <> tqItemByItemWithVendDet.tcpt_um and
tqItemByItemWithVendDet.tcvp_um = tqPendingVoucherForERSDetail.tcpod_um and
tqItemByItemWithVendDet.tcvp_curr = tqPendingVoucherForERSDetail.tcpo_curr and
tqItemByItemWithVendDet.tdvp_q_qty <= vdPriceQty and
tqItemByItemWithVendDet.tdvp_q_price > 0
then odInvoicePrice = tqItemByItemWithVendDet.tdvp_q_price.
/* Completely different UOM, try to lookup for conversion factor */
else if tqItemByItemWithVendDet.tcvp_um <> tqItemByItemWithVendDet.tcpt_um and
tqItemByItemWithVendDet.tcvp_um <> tqPendingVoucherForERSDetail.tcpod_um and
tqItemByItemWithVendDet.tcvp_curr = tqPendingVoucherForERSDetail.tcpo_curr and
tqItemByItemWithVendDet.tdvp_q_qty <= vdPriceQty and
tqItemByItemWithVendDet.tdvp_q_price > 0
then do:
/* Get conversion factor */
if not valid-handle(vhBMfgUoMConvInst)
then do:
if viBMfgUoMConvID = ? or
viBMfgUoMConvID = 0
then do:
<I-15 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "false"
&CLASS = "BMfgUoMConv"}>
end.
else do:
<I-16 {bFcOpenInstance
&CLASS = "BMfgUoMConv"}>
end.
end.
<M-17 run ApiGetConversionFactor
(input tqItemByItemWithVendDet.tcpt_part (icItemCode),
input tqItemByItemWithVendDet.tcvp_um (icFromUoMCode),
input tqPendingVoucherForERSDetail.tcpod_um (icToUoMCode),
output vdConversionFactor (odConversionFactor),
output viFcReturnSuper (oiReturnStatus)) in BMfgUoMConv>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
if vdConversionFactor <> ? and
vdConversionFactor <> 0 and
vdPriceQty > tqItemByItemWithVendDet.tdvp_q_qty * vdConversionFactor
then assign odInvoicePrice = tqItemByItemWithVendDet.tdvp_q_price / vdConversionFactor.
end.
end. /* if available tqItemByItemWithVendDet */
end. /* if vdListPric =0 and */
if odInvoicePrice = 0
then do:
if tqPendingVoucherForERSDetail.tlpo_sched
then do:
/* get cost from cost simulation records */
if not valid-handle(vhBMfgCostingInst)
then do:
if viBMfgCostingID = ? or
viBMfgCostingID = 0
then do:
<I-32 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "false"
&CLASS = "BMfgCosting"}>
end.
else do:
<I-57 {bFcOpenInstance
&CLASS = "BMfgCosting"}>
end.
end.
<M-95 run ApiGetCostingDetails
(input tqPendingVoucherForERSDetail.tcpod_site (icSite),
input tqPendingVoucherForERSDetail.tcpod_part (icPart),
output vcDummy (ocGLCostSet),
output vcDummy (ocGLCostMethod),
output vdGLCost (odGLCost),
output vcDummy (ocCurrentCostSet),
output vcDummy (ocCurrentCostMethod),
output vdDummy (odCurrentCost),
output viFcReturnSuper (oiReturnStatus)) in BMfgCosting>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-74 {bFcCloseInstance
&CLASS = "BMfgCosting"}>
return.
end.
/* price retrieved from costing module is for stock UoM -> recalculate *
* to Purchase UoM and in local currency */
if tqPendingVoucherForERSDetail.tcpod_type = 'M':U and
vdGLCost = 0
then assign vdGLCost = tqPendingVoucherForERSDetail.tdpod_pur_cost.
else assign vdGLCost = vdGLCost
* tqPendingVoucherForERSDetail.tdpod_um_conv
* tqPendingVoucherForERSDetail.tdpvod_ex_rate
/ tqPendingVoucherForERSDetail.tdpvod_ex_rate2.
end. /* if tqPendingVoucherForERSDetail.tlpo_sched */
else assign vdGLCost = tqPendingVoucherForERSDetail.tdpod_pur_cost.
assign odInvoicePrice = vdGLCost.
end. /* if vdListPrice = 0 */
/* =================================================================================================== */
/* Validate, whether we have the price for the matching */
/* =================================================================================================== */
if odInvoicePrice = 0
then do:
assign vcMessage = #T-18'Calculated invoice price for receipt &1 was calculated as zero, but invoice price can not be zero.':255(70767)T-18#
vcMessage = substitute(vcMessage, bERSProcessorRef.tcReceiverNbr)
vcContext = "pod_fix_pr=&1|pvod_pur_cost=&2|pod_um_conv=&3|tdpvod_ex_rate=&4|pvod_ex_rate2=&5|po_pr_list=&6|po_pr_list2=&7|pod_pr_list=&8|ERSPriceListOption=&9|":U
vcContext = subst(vcContext, tqPendingVoucherForERSDetail.tlpod_fix_pr, tqPendingVoucherForERSDetail.tdpvod_pur_cost, tqPendingVoucherForERSDetail.tdpod_um_conv,
tqPendingVoucherForERSDetail.tdpvod_ex_rate, tqPendingVoucherForERSDetail.tdpvod_ex_rate2, tqPendingVoucherForERSDetail.tcpo_pr_list,
tqPendingVoucherForERSDetail.tcpo_pr_list2, tqPendingVoucherForERSDetail.tcpod_pr_list, bERSProcessorRef.tiERSPriceListOption)
vcContext = vcContext + "pod_part=&10|pod_um=&11|pod_site=&12|po_sched=&13":U
vcContext = subst(vcContext, tqPendingVoucherForERSDetail.tcpod_part, tqPendingVoucherForERSDetail.tcpod_um, tqPendingVoucherForERSDetail.tcpod_site,
tqPendingVoucherForERSDetail.tlpo_sched)
vcContext = replace(vcContext, "|":U, chr(2)).
<M-19 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8505':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input vcContext (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
assign oiReturnStatus = -1.
return.
end.
/* =================================================================================================== */
/* Return */
/* =================================================================================================== */
if oiReturnStatus = -98 then assign oiReturnStatus = 0.