Description
Add purchase order line to Supplier Invoice
Parameters
tCInvoicePOUpdate | input | temp-table | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program6/bcinvoice.p)
/* =================================================================================================== */
/* Method : AddCInvoicePO */
/* Desc : Add PO lines to supplier invoice */
/* This method is called from BCInvoiceAPMatching after the tCInvoice-records are created */
/* in the instance and before the validations on this class are executed. */
/* --------------------------------------------------------------------------------------------------- */
/* Params: (I) tCInvoicePOUpdate Temporary table with Purchase order lines to be added */
/* =================================================================================================== */
assign oiReturnStatus = -98.
/* ============================================== */
/* Create list of Supplier Invoices to be Loaded */
/* ============================================== */
assign vcCInvoiceIDs = '':U.
for each tCInvoicePOUpdate:
find tCInvoice where
tCInvoice.CInvoice_ID = tCInvoicePOUpdate.CInvoice_ID
no-error.
if not available tCInvoice and
lookup(string(tCInvoicePOUpdate.CInvoice_ID),vcCInvoiceIDs, chr(4)) = 0
then assign vcCInvoiceIDs = if vcCInvoiceIDs = "":U
then string(tCInvoicePOUpdate.CInvoice_ID)
else vcCInvoiceIDs + chr(4) + string(tCInvoicePOUpdate.CInvoice_ID).
end. /* for each tPendingVoucherUpdate */
/* ====================================== */
/* Perform DataLoad */
/* ====================================== */
if vcCInvoiceIDs <> '':U
then do:
<M-2 run DataLoad
(input '':U (icRowids),
input vcCInvoiceIDs (icPkeys),
input '':U (icObjectIds),
input '':U (icFreeform),
input false (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
assign vcMessage = trim(substitute(#T-1'Internal error in &1. Method &2 failed with primary keys &3.':255(56653)t-1#,"BMfgPUpdatePendingVoucherFromAPMatching":U,"Dataload":U,vcCInvoiceIDs)).
<M-3 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-8522':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
return.
end. /* if viFcReturnSuper < 0 */
end. /* if vcPvoIDs <> '':U */
/* ============================================== */
/* Go through the input records tCInvoicePOUpdate */
/* ============================================== */
for each tCInvoicePOUpdate
break by tCInvoicePOUpdate.CInvoice_ID:
/* ======================================================== */
/* Default the Domain on the CInvoicePO in case it is empty */
/* ======================================================== */
if tCInvoicePOUpdate.CInvoicePOPoDomain = "":U or
tCInvoicePOUpdate.CInvoicePOPoDomain = ?
then assign tCInvoicePOUpdate.CInvoicePOPoDomain = vcDomainCode.
/* ========================================================== */
/* For the first PO of the invoice: */
/* - Find the invoice in the instance */
/* - Update some data based on the first PO of the invoice */
/* ========================================================== */
if first-of (tCInvoicePOUpdate.CInvoice_ID)
then do:
/* ========================================================== */
/* Find the invoice in the instance */
/* ========================================================== */
find tCInvoice where
tCInvoice.CInvoice_ID = tCInvoicePOUpdate.CInvoice_ID
no-error.
if not available tCInvoice
then do:
assign vcMessage = #T-6'Missing record.':255(70965)T-6#
vcContext = 'CInvoice_ID=&1':U
vcContext = substitute(vcContext, tCInvoicePOUpdate.CInvoice_ID).
<M-4 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-8528':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input vcContext (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
return.
end. /* if not available tCInvoice */
/* =============================================================== */
/* Update some instance-data based on the first PO of the invoice */
/* =============================================================== */
SHIPTOADDRESSBLOCK: DO :
/* Stop in case no PO-info is available */
if tCInvoicePOUpdate.CInvoicePOPoDomain = "":U or
tCInvoicePOUpdate.CInvoicePOPoDomain = ? or
tCInvoicePOUpdate.CInvoicePOPoNbr = "":U or
tCInvoicePOUpdate.CInvoicePOPoNbr = ?
then Leave SHIPTOADDRESSBLOCK.
/* Find the PO */
<Q-68 run PurchaseOrderByDomainNbrVend (all) (Read) (NoCache)
(input tCInvoicePOUpdate.CInvoicePOPoDomain, (DomainCode)
input tCInvoicePOUpdate.CInvoicePOPoNbr, (PONbr)
input ?, (POVendor)
input ?, (POCurrency)
input ?, (POType)
output dataset tqPurchaseOrderByDomainNbrVend) in BMfgPO>
find tqPurchaseOrderByDomainNbrVend where
tqPurchaseOrderByDomainNbrVend.tcpo_domain = tCInvoicePOUpdate.CInvoicePOPoDomain and
tqPurchaseOrderByDomainNbrVend.tcpo_nbr = tCInvoicePOUpdate.CInvoicePOPoNbr
no-error.
if not available tqPurchaseOrderByDomainNbrVend or
tqPurchaseOrderByDomainNbrVend.tcpo_ship = "":U or
tqPurchaseOrderByDomainNbrVend.tcpo_ship = ?
then Leave SHIPTOADDRESSBLOCK.
/* Find the address of the PO */
<Q-59 run AdMstrByAddress (all) (Read) (NoCache)
(input tqPurchaseOrderByDomainNbrVend.tcpo_domain, (Domain)
input tqPurchaseOrderByDomainNbrVend.tcpo_ship, (Code)
output dataset tqAdMstrByAddress) in BMfgAddress>
find first tqAdMstrByAddress where
tqAdMstrByAddress.tcad_domain = tqPurchaseOrderByDomainNbrVend.tcpo_domain and
tqAdMstrByAddress.tcad_addr = tqPurchaseOrderByDomainNbrVend.tcpo_ship
no-lock no-error.
if available tqAdMstrByAddress
then assign tCInvoice.tcShipToAddressCity = tqAdMstrByAddress.tcAddressCity
tCInvoice.tcShipToAddressState = tqAdMstrByAddress.tcAddressState
tCInvoice.tcShipToAddressStreet1 = tqAdMstrByAddress.tcAddressStreet1
tCInvoice.tcShipToAddressStreet2 = tqAdMstrByAddress.tcAddressStreet2
tCInvoice.tcShipToAddressStreet3 = tqAdMstrByAddress.tcAddressStreet3
tCInvoice.tcShipToAddressTypeCode = tqAdMstrByAddress.tcAddressTypeCode
tCInvoice.tcShipToAddressZip = tqAdMstrByAddress.tcAddressZip
tCInvoice.tcShipToCountryCode = tqAdMstrByAddress.tcCountryCode
tCInvoice.tcShipToBusinessRelationCode = tqAdMstrByAddress.tcBusinessRelationCode
tCInvoice.tlShipToCountryIsEUCountry = tqAdMstrByAddress.tlCountryIsEUCountry
tCInvoice.tcShipToTaxZone = tqAdMstrByAddress.tcTxzTaxZone
tCInvoice.ShipToAddress_ID = tqAdMstrByAddress.tiAddress_ID.
END. /* SHIPTOADDRESSBLOCK */
end. /* if first-of (tCInvoicePOUpdate.CInvoice_ID) */
/* ========================================================== */
/* Add the CInvoicePO */
/* ========================================================== */
<M-7 run AddDetailLine
(input 'CInvoicePO':U (icTable),
input tCInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
/* ========================================================== */
/* Fill in the PO-info on CInvoice and on CInvoicePO */
/* ========================================================== */
assign tCInvoicePO.CInvoicePOPoDomain = tCInvoicePOUpdate.CInvoicePOPoDomain
tCInvoicePO.CInvoicePOPoNbr = tCInvoicePOUpdate.CInvoicePOPoNbr.
if tCInvoice.CInvoicePoNbr = "":U or
tCInvoice.CInvoicePoNbr = ?
then do :
assign tCInvoice.CInvoicePoDomain = tCInvoicePO.CInvoicePOPoDomain
tCInvoice.CInvoicePoNbr = tCInvoicePO.CInvoicePOPoNbr .
if tCInvoice.tc_Status = "":U
then assign tCInvoice.tc_Status = "C":U.
end. /* f tCInvoice.CInvoicePoNbr = "":U or */
end. /* for each tCInvoicePOUpdate */
/* ====== */
/* Return */
/* ====== */
if oiReturnStatus = -98 then assign oiReturnStatus = 0.