project QadFinancials > class BAPMatching > method DefaultValuesInvoiceAmount
Description
this is a remoting-enabled method that returns the amounts to match of the invoice
Parameters
iiCInvoiceID | input | integer | |
iiAPMatchingID | input | integer | |
iiOldReasonID | input | integer | OldReasonID: Reason-ID of the invoice before it is matched |
biNewReasonID | input-output | integer | NewReasonID: Default value for the new reason-id of the invoice once it is matched |
bcNewReasonCode | input-output | character | NewReasonCode: Default value for the new reason-code of the invoice once it is matched |
ocCurrency | output | character | This will contain the currenciy used in the CI. |
odAmountToMatchTC | output | decimal | |
odAmountToMatchLC | output | decimal | |
odTaxAcrueReceiptRecovTC | output | decimal | Tax arruet at receipt, recoverable |
odTaxAcrueReceiptNonRecovTC | output | decimal | |
odTaxAcrueInvoiceRecovTC | output | decimal | |
odTaxAcrueInvoiceNonRecovTC | output | decimal | |
odInvoiceDiscountPercentage | output | decimal | |
ilBCInvoiceIsAlreadyOpen | input | logical | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program7/bapmatching.p)
/* ===================================================================== */
/* Default Values */
/* ===================================================================== */
assign odTaxAcrueInvoiceNonRecovTC = 0
odTaxAcrueInvoiceRecovTC = 0
odTaxAcrueReceiptNonRecovTC = 0
odTaxAcrueReceiptRecovTC = 0.
/* ===================================================================== */
/* Return in case no CInvoice-ID is passed */
/* Exception handling */
/* ===================================================================== */
if iiCInvoiceID = 0 or
iiCInvoiceID = ?
then Return.
assign oiReturnStatus = -98.
/* ============================================================================= */
/* There is need on UI to display Warning, when the invoice is already used */
/* in other matching in whatever status (Initial of Final) */
/* ============================================================================= */
<Q-2 run APMatchingByCInvoice (all) (Read) (NoCache)
(input ?, (CompanyId)
input iiCInvoiceID, (CInvoiceId)
input ?, (CInvoiceYear)
input ?, (CInvoiceJournalCode)
input ?, (CInvoiceVoucher)
output dataset tqAPMatchingByCInvoice) in BAPMatching >
if can-find( first tAPMatching where
tAPMatching.CInvoice_ID = iiCInvoiceID and
tAPMatching.APMatching_ID <> iiAPMatchingID and
tAPMatching.tc_Status <> "D":U) or
can-find( first tqAPMatchingByCInvoice where
tqAPMatchingByCInvoice.tiAPMatching_ID <> iiAPMatchingID)
then do:
assign oiReturnStatus = +1
vcMessage = trim(#T-3'This supplier invoice has already been used in another receiver matching.':100(999890414)T-3#).
<M-4 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tiCInvoiceVoucher':U (icFieldName),
input '':U (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-6525':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
end. /* if available tqAPMatchingByCInvoice */
/* =========================================================================================== *
* Get details about Supplier invoice. First try to get this information from Supplier invoice *
* component, which can be started already. If failed, then get this information from database *
* =========================================================================================== */
assign vlIsCInvoiceInMemory = false
viLocalReturn = 0.
if viBCInvoiceAPMID <> 0 and
viBCInvoiceAPMID <> ?
then do:
if ilBCInvoiceIsAlreadyOpen <> true
then do :
<I-23 {bFcOpenInstance
&CLASS = "BCInvoice"}>
end. /* if ilBCInvoiceIsAlreadyOpen <> true */
<M-20 run GetInvoiceAmount
(input iiCInvoiceID (iiCInvoiceId),
output vlIsCInvoiceInMemory (olIsCInvoiceLoaded),
output ocCurrency (ocCurrencyCode),
output odAmountToMatchTC (odAmountTC),
output odAmountToMatchLC (odAmountLC),
output odInvoiceDiscountPercentage (odDiscountPercentage),
output odTaxAcrueReceiptRecovTC (odTaxAcrueReceiptRecovTC),
output odTaxAcrueReceiptNonRecovTC (odTaxAcrueReceiptNonRecovTC),
output odTaxAcrueInvoiceRecovTC (odTaxAcrueInvoiceRecovTC),
output odTaxAcrueInvoiceNonRecovTC (odTaxAcrueInvoiceNonRecovTC),
output vdTaxAcrueReceiptRecovLC (odTaxAcrueReceiptRecovLC),
output vdTaxAcrueReceiptNonRecovLC (odTaxAcrueReceiptNonRecovLC),
output vdTaxAcrueInvoiceRecovLC (odTaxAcrueInvoiceRecovLC),
output vdTaxAcrueInvoiceNonRecovLC (odTaxAcrueInvoiceNonRecovLC),
output viCInvoiceReasonId (oiReasonId),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
if ilBCInvoiceIsAlreadyOpen <> true
then do :
<I-24 {bFcCloseInstance
&CLASS = "BCInvoice"}>
end. /* if ilBCInvoiceIsAlreadyOpen <> true */
if viLocalReturn <> 0 then assign oiReturnStatus = viLocalReturn.
if viLocalReturn < 0 then return.
end. /* if viBCInvoiceAPMID <> 0 and */
if not vlIsCInvoiceInMemory
then do:
/* ======================================================================================================================== */
/* Call a query that will return the CInvoice and CInvoiceVat information. The result-set can contain multiple records for */
/* a single invoice if there is more then one CInvoiceVat for a single CInvoice. Note that the query has an outer-join from */
/* CInvoice to CInvoiceVat: it will thus be possible that the CInvoiceVat-field have the unknown-value */
/* ======================================================================================================================== */
<Q-14 run CInvoiceVatForAPMSelection (all) (Read) (NoCache)
(input ?, (CompanyId)
input iiCInvoiceID, (CInvoiceID)
output dataset tqCInvoiceVatForAPMSelection) in BCInvoice >
find first tqCInvoiceVatForAPMSelection where /* first is needed as there can be multiple due to the jion from CInvoice to CInvoiceVat */
tqCInvoiceVatForAPMSelection.tiCInvoice_ID = iiCInvoiceID
no-lock no-error.
if not available tqCInvoiceVatForAPMSelection
then do :
assign oiReturnStatus = -1
vcMessage = trim(substitute(#T-16'Cannot find the supplier invoice based on its ID &1.':255(999890415)T-16#,string(iiCInvoiceID))).
<M-15 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tiCInvoiceVoucher':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-7679':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
Return.
end. /* if not av tqCInvoiceVatForAPMSelection */
/* ===================================================================== */
/* Calculate taxes on the invoice */
/* ===================================================================== */
for each tqCInvoiceVatForAPMSelection where
tqCInvoiceVatForAPMSelection.tiCInvoice_ID = iiCInvoiceID and
tqCInvoiceVatForAPMSelection.tcVatCode <> ? /* needed as there is an outer-join between CInvoice and CInvoiceVat */
no-lock :
if tqCInvoiceVatForAPMSelection.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or
tqCInvoiceVatForAPMSelection.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}
then assign vdNonRecTaxAmtTC = tqCInvoiceVatForAPMSelection.tdCInvoiceVatNonRecTaxAmtTC * -1.
else assign vdNonRecTaxAmtTC = tqCInvoiceVatForAPMSelection.tdCInvoiceVatNonRecTaxAmtTC.
if tqCInvoiceVatForAPMSelection.tlCInvoiceVatIsAccrRcpUs
then assign odTaxAcrueReceiptRecovTC = odTaxAcrueReceiptRecovTC
+ tqCInvoiceVatForAPMSelection.tdCInvoiceVatVatDebitTC
- tqCInvoiceVatForAPMSelection.tdCInvoiceVatVatCreditTC
- vdNonRecTaxAmtTC
odTaxAcrueReceiptNonRecovTC = odTaxAcrueReceiptNonRecovTC
+ vdNonRecTaxAmtTC.
else assign odTaxAcrueInvoiceRecovTC = odTaxAcrueInvoiceRecovTC
+ tqCInvoiceVatForAPMSelection.tdCInvoiceVatVatDebitTC
- tqCInvoiceVatForAPMSelection.tdCInvoiceVatVatCreditTC
- vdNonRecTaxAmtTC
odTaxAcrueInvoiceNonRecovTC = odTaxAcrueInvoiceNonRecovTC
+ vdNonRecTaxAmtTC.
end. /* for each tqCInvoiceVatForAPMSelection: */
/* ===================================================================== */
/* Set the Currency, PaymentCondition and the Cirec-amount to be matched */
/* ===================================================================== */
find first tqCInvoiceVatForAPMSelection where
tqCInvoiceVatForAPMSelection.tiCInvoice_ID = iiCInvoiceID
no-lock no-error.
/* First-option is needed as there can be multiple due to the join from CInvoice to CInvoiceVat */
/* No need to check on a the availability as this has been chekked on by the first find in this method */
/* We need to re-find the tqCInvoiceVatForAPMSelection because we had a find on this table followed by a for each on this table */
assign odInvoiceDiscountPercentage = tqCInvoiceVatForAPMSelection.tdPaymentConditionPercentage
ocCurrency = tqCInvoiceVatForAPMSelection.tcCurrencyCode
viCInvoiceReasonId = tqCInvoiceVatForAPMSelection.tiReason_ID
odAmountToMatchTC = tqCInvoiceVatForAPMSelection.tdCInvoiceOriginalCreditTC - tqCInvoiceVatForAPMSelection.tdCInvoiceOriginalDebitTC - odTaxAcrueInvoiceRecovTC
odAmountToMatchLC = <M-18 RoundAmount
(input odAmountToMatchTC * tqCInvoiceVatForAPMSelection.tdCInvoiceExchangeRate * tqCInvoiceVatForAPMSelection.tdCInvoiceRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input ? (icCurrencyCode)) in BAPMatching>.
end. /* if not vlIsCInvoiceInMemory */
/* ===================================================================== */
/* Query the default reason-code for the invoice once it becomes matched */
/* Only neede in case the new reason-code was not yet specified */
/* ===================================================================== */
if (bcNewReasonCode = "":U or
bcNewReasonCode = ?) and
(biNewReasonID = 0 or
biNewReasonID = ?)
then do :
/* if the old-reason-id is not yet stated, then query the cinvoice for it */
if iiOldReasonID = 0 or
iiOldReasonID = ?
then assign iiOldReasonID = viCInvoiceReasonId.
/* Get the new reason-code based upon the eixtsing (old) one */
if iiOldReasonID <> 0 and
iiOldReasonID <> ?
then do :
<Q-22 run ReasonForMatching (all) (Read) (NoCache)
(input iiOldReasonID, (ReasonID)
input ?, (ReasonCode)
input true, (ReasonIsLogisticMatching)
input true, (ReasonIsActive)
input ?, (ReasonIsInitialStatus)
output dataset tqReasonForMatching) in BReason >
find first tqReasonForMatching where
tqReasonForMatching.tiReason_ID = iiOldReasonID
no-lock no-error.
if available tqReasonForMatching
then assign bcNewReasonCode = tqReasonForMatching.tcMatchingReasonCode
biNewReasonID = tqReasonForMatching.tiMatchingReason_ID.
end. /* if iiOldReasonID <> 0 and */
end. /* if (bcNewReasonCode = "":U or */
/* ===================================================================== */
/* Exception handling */
/* ===================================================================== */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.