report procedure
Parameters
icLanguageCode | input | character | |
tFilter | input | temp-table | |
dcrMatchingVariance | output | dataset | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program7/bapmatchingreport.p)
empty temp-table tqMatchingVariance.
<M-1 run GetReportLabels
(input 'MatchingVariance':U (icReportName),
input icLanguageCode (icLanguageCode),
input tFilter (tFilter),
output tqHeader (tqHeader),
output tqFilter (tqFilter),
output tqText (tqText),
output viFcReturnSuper (oiReturnStatus)) in BAPMatchingReport>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus >= 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
<M-2 run SetDataItemsBasedOnFilterTT
(output viFcReturnSuper (oiReturnStatus)) in BAPMatchingReport>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus >= 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
/* Validation of 'Sort By' */
if vcSortingFilter = ?
then do:
assign
vcErrorMessage = #T-28'The sorting sequence should be 'Item' or 'Buyer'.':100(68542)T-28#.
<M-29 run SetMessage
(input vcErrorMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-7677':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output oiReturnStatus (oiReturnStatus)) in BAPMatchingReport>
assign oiReturnStatus = -1.
return.
end.
assign vlIsLgCharge = false.
if vlIncludeInventory = ? then assign vlIncludeInventory = false.
if vlIncludeSubcontracted = ? then assign vlIncludeSubcontracted = false.
if vlIncludeMemo = ? then assign vlIncludeMemo = false.
if vlIncludeReturn = ? then assign vlIncludeReturn = false.
if vlShowPostingDetailsFilter = ? then assign vlShowPostingDetailsFilter = false.
if vlShowPostingDetailsFilter then
do:
<Q-18 run SelectGL (all) (Read) (NoCache)
(input ?, (CompanyId)
output dataset tqSelectGL) in BGL >
<Q-19 run SelectDivision (all) (Read) (NoCache)
(input ?, (CompanyId)
output dataset tqSelectDivision) in BDivision >
<Q-20 run SelectCostCentre (all) (Read) (NoCache)
(input ?, (CompanyId)
output dataset tqSelectCostCentre) in BCostCentre >
<Q-23 run SelectProject (all) (Read) (NoCache)
(input ?, (CompanyId)
output dataset tqSelectProject) in BProject >
<Q-21 run SelectCurrency (all) (Read) (NoCache) (output dataset tqSelectCurrency) in BCurrency >
end. /*if vlShowPostingDetailsFilter then*/
<Q-37 run CurrencyByCode (all) (Read) (NoCache)
(input ?, (CurrencyCode)
output dataset tqCurrencyByCode) in BCurrency >
<Q-3 run CInvoiceForMatchingVariance (all) (Read) (NoCache)
(input vcCreditorCodeFromFilter, (FromCreditorCode)
input vcCreditorCodeToFilter, (ToCreditorCode)
input vcCompanyFilter, (CompanyCode)
input vcFromLgChargeFilter, (FromLogisticCharge)
input ?, (CompanyId)
input vcFromPurchaseOrderFilter, (FromPurchaseOrder)
input vcToPurchaseOrderFilter, (ToPurchaseOrder)
input vcFromItemFilter, (FromItem)
input vcToItemFilter, (ToItem)
input vtFromInvoiceDateFilter, (FromInvoiceDate)
input vtToInvoiceDateFilter, (ToInvoiceDate)
input vcSiteFilter, (ReceiptSite)
input vcCurrFilter, (CurrencyCode)
input vcToLgChargeFilter, (ToLogisticCharge)
input vlIsLgCharge, (IsLgCharge)
input vtFromInvoicePostDateFilter, (FromInvoicePostingDt)
input vtToInvoicePostDateFilter, (ToInvoicePostingDt)
input ?, (OrderType)
input viDomainID, (DomainId)
output dataset tqCInvoiceForMatchingVariance) in BAPMatchingReport>
for each tqCInvoiceForMatchingVariance where
(if vlIncludeInventory then
true else
tqCInvoiceForMatchingVariance.tcAPMatchingLnPvodItemType <> {&APMATCHINGLNPVODITEMTYPE-NORMAL}) and
(if vlIncludeSubcontracted then
true else
tqCInvoiceForMatchingVariance.tcAPMatchingLnPvodItemType <> {&APMATCHINGLNPVODITEMTYPE-SUBCONTRACT}) and
(if vlIncludeMemo then
true else
tqCInvoiceForMatchingVariance.tcAPMatchingLnPvodItemType <> {&APMATCHINGLNPVODITEMTYPE-MEMO}) and
(if vlIncludeReturn then
true else
tqCInvoiceForMatchingVariance.tdAPMatchingLnPvodReceiptQty > 0):
create tGetMatchingVariance.
buffer-copy tqCInvoiceForMatchingVariance to tGetMatchingVariance.
end. /*for each tqCInvoiceForMatchingVariance where*/
<Q-9 run PendingVoucherByAPMatchingLn
(Start) in BAPMatchingReport >
<Q-24 run PostingLineByPostingLnId (Start) in BPosting >
for each tGetMatchingVariance break by tGetMatchingVariance.tiCInvoice_ID:
<Q-4 run PendingVoucherByAPMatchingLn (all) (Read) (NoCache)
(input tGetMatchingVariance.tcPvoDomain, (PvoDomain)
input tGetMatchingVariance.tiPvoID, (PvoId)
input tGetMatchingVariance.tiPvodLineID, (PvoLineId)
input vtFromPODateFilter, (FromPODate)
input vtToPODateFilter, (ToPODate)
input vcBuyerFilter, (Buyer)
input vcFromInternalRefFilter, (FromInternalRef)
input vcToInternalRefFilter, (ToInternalRef)
output dataset tqPendingVoucherByAPMatchingLn) in BAPMatchingReport >
find first tqPendingVoucherByAPMatchingLn no-error.
if available tqPendingVoucherByAPMatchingLn then
do:
for first tqPendingVoucherByAPMatchingLn:
assign vdQtyReceipt = tGetMatchingVariance.tdAPMatchingLnPvodReceiptQty
vdQtyToMatch = tGetMatchingVariance.tdAPMatchingLnPvodOpenQty
vdQtyInvoiced = tGetMatchingVariance.tdAPMatchingLnMatchQty
vdQtyUsageVariance = (if tGetMatchingVariance.tlAPMatchingLnIsPvodFinished then
0 else
(tGetMatchingVariance.tdAPMatchingLnMatchQty -
tGetMatchingVariance.tdAPMatchingLnPvodOpenQty)).
case vcRateCostRef:
when "POCOST":U then
assign vdInvoiceCostUoM = tqPendingVoucherByAPMatchingLn.tdpvod_pur_cost.
when "STDCOST":U then
do:
case tGetMatchingVariance.tcAPMatchingLnPvodItemType:
when {&APMATCHINGLNPVODITEMTYPE-NORMAL} then
assign vdInvoiceCostUoM = tqPendingVoucherByAPMatchingLn.tdpvod_pur_std.
/* start --- defect 10132-3224 zhc */
when {&APMATCHINGLNPVODITEMTYPE-SUBCONTRACT} then do:
/*assign vdInvoiceCostUoM = tqPendingVoucherByAPMatchingLn.tdpvod_sub_std.*/
<Q-64 run WorkOrderRoutingByApMatchingLn (all) (Read) (NoCache)
(input vcDomainCode, (Domain)
input tqPendingVoucherByAPMatchingLn.tcpod_wo_lot, (Lot)
input tqPendingVoucherByAPMatchingLn.tipod_op, (Operation)
output dataset tqWorkOrderRoutingByApMatchingLn) in BAPMatchingReport>
find first tqWorkOrderRoutingByApMatchingLn where
tqWorkOrderRoutingByApMatchingLn.tcwr_lot = tqPendingVoucherByAPMatchingLn.tcpod_wo_lot and
tqWorkOrderRoutingByApMatchingLn.tiwr_op = tqPendingVoucherByAPMatchingLn.tipod_op and
tqWorkOrderRoutingByApMatchingLn.tcwr_domain = vcDomainCode no-error.
assign vdInvoiceCostUoM = if available tqWorkOrderRoutingByApMatchingLn then tqWorkOrderRoutingByApMatchingLn.tdwr_sub_cost
else 0.
end.
/* end --- defect 10132-3224 zhc */
when {&APMATCHINGLNPVODITEMTYPE-MEMO} then
assign vdInvoiceCostUoM = 0.
end case.
end.
/* start --- defect 10132-3224 zhc */
when "STDCOSTOVH":U then do:
/*assign vdInvoiceCostUoM = tqPendingVoucherByAPMatchingLn.tdpvod_mtl_std.*/
if tGetMatchingVariance.tcAPMatchingLnPvodItemType = {&APMATCHINGLNPVODITEMTYPE-SUBCONTRACT}
then do:
<Q-51 run WorkOrderRoutingByApMatchingLn (all) (Read) (NoCache)
(input vcDomainCode, (Domain)
input tqPendingVoucherByAPMatchingLn.tcpod_wo_lot, (Lot)
input tqPendingVoucherByAPMatchingLn.tipod_op, (Operation)
output dataset tqWorkOrderRoutingByApMatchingLn) in BAPMatchingReport>
find first tqWorkOrderRoutingByApMatchingLn where
tqWorkOrderRoutingByApMatchingLn.tcwr_lot = tqPendingVoucherByAPMatchingLn.tcpod_wo_lot and
tqWorkOrderRoutingByApMatchingLn.tiwr_op = tqPendingVoucherByAPMatchingLn.tipod_op and
tqWorkOrderRoutingByApMatchingLn.tcwr_domain = vcDomainCode no-error.
assign vdInvoiceCostUoM = if available tqWorkOrderRoutingByApMatchingLn then tqWorkOrderRoutingByApMatchingLn.tdwr_sub_cost
else 0.
end.
end.
/* end --- defect 10132-3224 zhc */
end case. /*case vcRateCostRef*/
if vcCurrfilter = ?
then assign vdInvoiceUnitPrice = tGetMatchingVariance.tdAPMatchingLnMatchUnitPrice * tGetMatchingVariance.tdCInvoiceExchangeRate * tGetMatchingVariance.tdCInvoiceRateScale
/* vdInvoiceUnitPrice = round(vdInvoiceUnitPrice, 5) */
/* vdInvoiceCostUoM = round(vdInvoiceCostUoM, 5) */
vdInvoiceCostUoM = vdInvoiceCostUoM * tqPendingVoucherByAPMatchingLn.tdprh_um_conv.
else assign vdInvoiceCostUoM = (if tqPendingVoucherByAPMatchingLn.tdprh_um_conv = ?
then 1
else tqPendingVoucherByAPMatchingLn.tdprh_um_conv) *
tqPendingVoucherByAPMatchingLn.tdpvod_ex_rate /
tqPendingVoucherByAPMatchingLn.tdpvod_ex_rate2 *
vdInvoiceCostUoM
/* vdInvoiceCostUoM = round(vdInvoiceCostUoM, 5) */
vdInvoiceUnitPrice = tGetMatchingVariance.tdAPMatchingLnMatchUnitPrice.
/* vdInvoiceUnitPrice = round(vdInvoiceUnitPrice, 5) */
assign vdVarRate = vdInvoiceUnitPrice - vdInvoiceCostUoM
vdExtendedInvoiceCost = vdQtyInvoiced * vdInvoiceUnitPrice.
if tGetMatchingVariance.tlAPMatchingLnIsPvodFinished
then assign vdExtendedReceiptCost = vdInvoiceCostUoM * vdQtyToMatch.
else assign vdExtendedReceiptCost = vdInvoiceCostUoM * vdQtyInvoiced.
assign vdExtendedVarRate = vdExtendedInvoiceCost - vdExtendedReceiptCost
vdExtendedVarRate = <M-36 RoundAmount
(input vdExtendedVarRate (idUnroundedAmount),
input ? (iiCurrencyID),
input tGetMatchingVariance.tcCurrencyCode (icCurrencyCode)) in BAPMatchingReport>.
case tGetMatchingVariance.tcAPMatchingLnPvodItemType:
when {&APMATCHINGLNPVODITEMTYPE-NORMAL} then
assign vcItemType = {&APMATCHINGLNPVODITEMTYPE-NORMAL-TR}.
when {&APMATCHINGLNPVODITEMTYPE-SUBCONTRACT} then
assign vcItemType = {&APMATCHINGLNPVODITEMTYPE-SUBCONTRACT-TR}.
when {&APMATCHINGLNPVODITEMTYPE-MEMO} then
assign vcItemType = {&APMATCHINGLNPVODITEMTYPE-MEMO-TR}.
end case. /* case tGetMatchingVariance.tcAPMatchingLnPvodItemType*/
/* defect 10299-0151 */
/* get number of decimals of currencycode */
find first tqCurrencyByCode where tqCurrencyByCode.tcCurrencyCode = tGetMatchingVariance.tcCurrencyCode no-error.
if available tqCurrencyByCode
then assign viNumberOfCurrencyDecimal = tqCurrencyByCode.tiCurrencyNumberOfDecimals.
assign vlIncludeInReport = true.
if vdShowVarOverPerFilter <> 0 and vdShowVarOverPerFilter <> ? and
((vdExtendedVarRate * 100 / vdExtendedReceiptCost) <= vdShowVarOverPerFilter) then
assign vlIncludeInReport = false.
if vdShowVarOverAmtFilter <> 0 and vdShowVarOverAmtFilter <> ? and
(vdVarRate <= vdShowVarOverAmtFilter) then
assign vlIncludeInReport = false.
if vdShowVarOverPerFilter = ? and vlShowOnlyVar = true and
vdExtendedVarRate = 0 then
assign vlIncludeInReport = false.
if vlIncludeInReport
then do:
create tqMatchingVariance.
assign
tqMatchingVariance.tcCInvoiceCreditorCode = tGetMatchingVariance.tcCreditorCode
tqMatchingVariance.tcCinvoiceJournal = tGetMatchingVariance.tcCinvoiceJournal
tqMatchingVariance.tiCinvoiceVoucher = tGetMatchingVariance.tiCInvoiceVoucher
tqMatchingVariance.tiCInvoicePeriod = tGetMatchingVariance.tiPeriodYear
tqMatchingVariance.tcCinvoiceReference = tGetMatchingVariance.tcCInvoiceReference
tqMatchingVariance.tcCInvoiceCompanyCode = tGetMatchingVariance.tcCompanyCode
tqMatchingVariance.tcCInvoiceCurrency = tGetMatchingVariance.tcCurrencyCode
tqMatchingVariance.tcPurchaseOrderNbr = tGetMatchingVariance.tcAPMatchingLnPvodOrder
tqMatchingVariance.tiPurchaseOrderLnNbr = tGetMatchingVariance.tiAPMatchingLnPvodOrderLnNbr
tqMatchingVariance.tcPurchaseOrderBuyer = tqPendingVoucherByAPMatchingLn.tcpvo_buyer
tqMatchingVariance.tcCreditorCode = tqPendingVoucherByAPMatchingLn.tcpvo_supplier
tqMatchingVariance.tcReceiptItem = tGetMatchingVariance.tcAPMatchingLnPvodItem
tqMatchingVariance.tcReceiptItemType = vcItemType
tqMatchingVariance.tlIsPvodFinished = tGetMatchingVariance.tlAPMatchingLnIsPvodFinished
tqMatchingVariance.tcItemDescription = tGetMatchingVariance.tcAPMatchingLnPvodItemDescr1
tqMatchingVariance.tcLogisticChargeCode = tGetMatchingVariance.tcAPMatchingLnPvodLgCharge
tqMatchingVariance.tcReceiptSite = tGetMatchingVariance.tcAPMatchingLnPvodSite
tqMatchingVariance.tdQtyReceipt = vdQtyReceipt
tqMatchingVariance.tdQtyInvoiced = vdQtyInvoiced
tqMatchingVariance.tdInvoiceUnitPrice = vdInvoiceUnitPrice
tqMatchingVariance.tcUnitofMeasure = tGetMatchingVariance.tcAPMatchingLnPvodUoM
tqMatchingVariance.tdInvoiceCostUoM = vdInvoiceCostUoM
tqMatchingVariance.tdVarUsage = vdVarUsage
tqMatchingVariance.tdVarRate = vdVarRate
tqMatchingVariance.tdVarExchangeRate = vdVarExchangeRate
tqMatchingVariance.tdExtendedInvoiceCost = vdExtendedInvoiceCost
tqMatchingVariance.tdExtendedReceiptCost = vdExtendedReceiptCost
tqMatchingVariance.tdExtendedVarRate = vdExtendedVarRate
tqMatchingVariance.tiCInvoice_ID = tGetMatchingVariance.tiCInvoice_ID
tqMatchingVariance.tcSortBy = vcSortingFilter
tqMatchingVariance.tiPostingType = 0
tqMatchingVariance.tiCurrencyNumberOfDecimals = viNumberOfCurrencyDecimal.
if vlShowPostingDetailsFilter then
do:
do viCount = 1 to 4:
case viCount:
when 1 then assign viPostingLine_ID = tGetMatchingVariance.tiPvoPostingLine_ID.
when 2 then assign viPostingLine_ID = tGetMatchingVariance.tiVarExchRatePostingLine_ID.
when 3 then assign viPostingLine_ID = tGetMatchingVariance.tiVarRatePostingLine_ID.
when 4 then assign viPostingLine_ID = tGetMatchingVariance.tiVarUsagePostingLine_ID.
end case.
if viPostingLine_ID <> ? and viPostingLine_ID <> 0 then
do:
<Q-22 run PostingLineByPostingLnId (all) (Read) (NoCache)
(input ?, (CompanyId)
input viPostingLine_ID, (PostingLine_ID)
output dataset tqPostingLineByPostingLnId) in BPosting >
find first tqPostingLineByPostingLnId no-error.
if available tqPostingLineByPostingLnId then
do:
create tqMatchingVariance.
buffer-copy tqPostingLineByPostingLnId to tqMatchingVariance.
assign tqMatchingVariance.tiPostingType = 1.
end. /*if available tqPostingLineByPostingLnId then*/
end. /*if viPostingLine_ID <> ? and viPostingLine_ID <> 0 then*/
end. /*repeat viCount = 1 to 4:*/
end. /*if vlShowPostingDetailsFilter then*/
end. /* if vlIncludeInReport then */
end. /*for first tqPendingVoucherByAPMatchingLn*/
end. /*if available tqPendingVoucherByAPMatchingLn then*/
end. /*for each tGetMatchingVariance:*/
<Q-25 run PostingLineByPostingLnId (Stop) in BPosting >
<Q-12 run PendingVoucherByAPMatchingLn
(Stop) in BAPMatchingReport >
for each tqMatchingVariance where
tqMatchingVariance.tiPostingType = 1 and
tqMatchingVariance.tiGL_ID <> 0 and
tqMatchingVariance.tiGL_ID <> ?
break by
tqMatchingVariance.tiGL_ID:
if first-of(tqMatchingVariance.tiGL_ID) then
do:
assign vcGLCode = ?.
for first tqSelectGL where tqSelectGL.tiGL_ID = tqMatchingVariance.tiGL_ID:
assign vcGLCode = tqSelectGL.tcGLCode.
end.
end. /*if first-of(tqMatchingVariance.tiGL_ID) then*/
assign tqMatchingVariance.tcGLCode = vcGLCode.
end.
for each tqMatchingVariance where
tqMatchingVariance.tiPostingType = 1 and
tqMatchingVariance.tiDivision_ID <> 0 and
tqMatchingVariance.tiDivision_ID <> ?
break by
tqMatchingVariance.tiDivision_ID:
if first-of(tqMatchingVariance.tiDivision_ID) then
do:
assign vcDivisionCode = ?.
for first tqSelectDivision where tqSelectDivision.tiDivision_ID = tqMatchingVariance.tiDivision_ID:
assign vcDivisionCode = tqSelectDivision.tcDivisionCode.
end.
end. /*if first-of(tqMatchingVariance.tiGL_ID) then*/
assign tqMatchingVariance.tcDivisionCode = vcDivisionCode.
end.
for each tqMatchingVariance where
tqMatchingVariance.tiPostingType = 1 and
tqMatchingVariance.tiCostCentre_ID <> 0 and
tqMatchingVariance.tiCostCentre_ID <> ?
break by
tqMatchingVariance.tiCostCentre_ID:
if first-of(tqMatchingVariance.tiCostCentre_ID) then
do:
assign vcCostCentreCode = ?.
for first tqSelectCostCentre where tqSelectCostCentre.tiCostCentre_ID = tqMatchingVariance.tiCostCentre_ID:
assign vcCostCentreCode = tqSelectCostCentre.tcCostCentreCode.
end.
end. /*if first-of(tqMatchingVariance.tiGL_ID) then*/
assign tqMatchingVariance.tcCostCentreCode = vcCostCentreCode.
end.
for each tqMatchingVariance where
tqMatchingVariance.tiPostingType = 1 and
tqMatchingVariance.tiProject_ID <> 0 and
tqMatchingVariance.tiProject_ID <> ?
break by
tqMatchingVariance.tiProject_ID:
if first-of(tqMatchingVariance.tiProject_ID) then
do:
assign vcProjectCode = ?.
for first tqSelectProject where tqSelectProject.tiProject_ID = tqMatchingVariance.tiProject_ID:
assign vcProjectCode = tqSelectProject.tcProjectCode.
end.
end. /*if first-of(tqMatchingVariance.tiGL_ID) then*/
assign tqMatchingVariance.tcProjectCode = vcProjectCode.
end.
for each tqMatchingVariance where
tqMatchingVariance.tiPostingType = 1 and
tqMatchingVariance.tiCurrency_ID <> 0 and
tqMatchingVariance.tiCurrency_ID <> ?
break by
tqMatchingVariance.tiCurrency_ID:
if first-of(tqMatchingVariance.tiCurrency_ID) then
do:
assign vcCurrencyCode = ?.
for first tqSelectCurrency where tqSelectCurrency.tiCurrency_ID = tqMatchingVariance.tiCurrency_ID:
assign vcCurrencyCode = tqSelectCurrency.tcCurrencyCode.
end.
end. /*if first-of(tqMatchingVariance.tiGL_ID) then*/
assign tqMatchingVariance.tcPLCurrencyCode = vcCurrencyCode.
end.