project QadFinancials > class BCInvoice > method ReverseCInvoiceUpdateLegalDocument
Description
Reverse of supplier invoice
Parameters
iiCInvoice_ID | input | integer | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program3/bcinvoice.p)
/* =================================================================================================== */
/* Method : ReverseCInvoiceUpdateLegalDocument */
/* Desc : This method updates Legal Document. When all invoices created for certain Legal */
/* document are reversed, then Legal document get's unposted. */
/* --------------------------------------------------------------------------------------------------- */
/* Params: (I) SupplierInvoiceID Reversed Supplier invoice ID */
/* =================================================================================================== */
define variable doGetLegalDocumentForCInvoice as com.qad.eefin.bmfglegaldocument.GetLegalDocumentForCInvoice no-undo.
define variable doGetLegalDocumentCInvoiceDetails as com.qad.eefin.bmfglegaldocument.GetLegalDocumentCInvoiceDetails no-undo.
UPDATE_BLOCK:
do on error undo, leave:
/* Check version of operational code */
if viMfgProMajorVersionBCI > 3 /* Meaning eB3 */ or
(viMfgProMajorVersionBCI = 3 /* Meaning eB3 */ and
viMfgProMinorVersionBCI >= 7 /* Meaning SP7 */)
then do:
/* First Get the Legal document, from which the invoice is created */
doGetLegalDocumentForCInvoice = new com.qad.eefin.bmfglegaldocument.GetLegalDocumentForCInvoice(?, iiCInvoice_ID, ?, ?, ?).
if doGetLegalDocumentForCInvoice:Available
then do:
assign vlVersion2014 = false.
/* Determine if the version of the ERP software is QAD2014. This needs to be passed to the data object below. */
if viMfgProMajorVersionBCI > 3 /* Meaning eB3 */ or
(viMfgProMajorVersionBCI = 3 /* Meaning eB3 */ and
viMfgProMinorVersionBCI >= 14 /* Meaning SP14 */)
then assign vlVersion2014 = true.
else do:
<Q-10 run PendingVoucherForAPIMatchLC (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input ?, (OrderNumber)
input ?, (OrderLine)
input ?, (ExternalReference)
input ?, (InternalReference)
input ?, (LcCharge)
input ?, (PvoID)
input ?, (PvodID)
input vcDomainCode, (DomainCode)
output dataset tqPendingVoucherForAPIMatchLC) in BMfgPendingVoucher>
find first tqPendingVoucherForAPIMatchLC where
tqPendingVoucherForAPIMatchLC.tcpvo_domain = vcDomainCode and
(num-entries(tqPendingVoucherForAPIMatchLC.tcpvo_external_ref, '::':U) = 9) and
tqPendingVoucherForAPIMatchLC.tcpvo_lc_charge <> '':U and
tqPendingVoucherForAPIMatchLC.tcpvo_internal_ref_type = '13':U
no-lock no-error.
if not available tqPendingVoucherForAPIMatchLC
then assign vlVersion2014 = false.
else assign vlVersion2014 = true.
end.
/* If there is available legal document which was used for invoice creation, then also *
* check, that there are no other not-reversed invoices */
doGetLegalDocumentCInvoiceDetails = new com.qad.eefin.bmfglegaldocument.GetLegalDocumentCInvoiceDetails(
doGetLegalDocumentForCInvoice:lgd_domain,
doGetLegalDocumentForCInvoice:lgd_nbr,
doGetLegalDocumentForCInvoice:lgd_shipfrom,
doGetLegalDocumentForCInvoice:lgd_effdate,
?,
{&APMATCHINGSTATUS-FINISHED},
vlVersion2014).
do while doGetLegalDocumentCInvoiceDetails:Available:
if doGetLegalDocumentCInvoiceDetails:CInvoice_ID <> iiCInvoice_ID
then return. /* There is still an unreversed invoices, we don't update Legal document */
doGetLegalDocumentCInvoiceDetails:next.
end.
/* If there is no any other invoice then update legal document */
/* Adapt the Posted flag on the legal document */
create tLegalDocumentUpdateFromCInv.
assign tLegalDocumentUpdateFromCInv.tcDomainCode = doGetLegalDocumentForCInvoice:lgd_domain
tLegalDocumentUpdateFromCInv.tcLegalDocumentNumber = doGetLegalDocumentForCInvoice:lgd_nbr
tLegalDocumentUpdateFromCInv.ttLegalDocumentEffectiveDate = doGetLegalDocumentForCInvoice:lgd_effdate
tLegalDocumentUpdateFromCInv.tcLegalDocumentShipFrom = doGetLegalDocumentForCInvoice:lgd_shipfrom
tLegalDocumentUpdateFromCInv.tcLegalDocumentShip = doGetLegalDocumentForCInvoice:lgd_ship
tLegalDocumentUpdateFromCInv.tiCInvoiceID = iiCInvoice_ID
tLegalDocumentUpdateFromCInv.tlLegalDocumentPostStatus = false.
end. /* if doGetLegalDocumentForCInvoice.Available */
end. /* if viMfgProMajorVersionBCI > 3 Meaning eB3 or */
/* free up all memory */
finally:
if valid-object(doGetLegalDocumentCInvoiceDetails) then delete object doGetLegalDocumentCInvoiceDetails no-error.
if valid-object(doGetLegalDocumentForCInvoice) then delete object doGetLegalDocumentForCInvoice no-error.
end finally.
end. /* if viMfgProMajorVersionBCI ......*/