Description
This is a remoting-enabled method that returns a bunch of information of the invoice.
Parameters
| icAPMatchingTcRowid | input | character | Field tc_rowid of the tAPMatching record these defaults are retrieved for. |
| biInvoiceYear | input-output | integer | |
| bcInvoiceJournal | input-output | character | |
| biInvoiceVoucher | input-output | integer | |
| bcInvoiceReference | input-output | character | |
| biInvoiceRegistrationNr | input-output | integer | |
| bcCreditorCode | input-output | character | |
| iiOldReasonID | input | integer | Reason-id of the invoice before the invoice 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 |
| oiBusinessRelationID | output | integer | ID of business relation |
| ocBusinessRelationCode | output | character | |
| ocBusinessRelationICCode | output | character | BusinessRelationICCode |
| ocCurrencyCode | output | character | |
| odAmountToMatchTC | output | decimal | |
| odAmountToMatchLC | output | decimal | |
| oiCInvoiceId | output | integer | |
| odCInvoiceExchangeRate | output | decimal | |
| odCInvoiceRateScale | output | decimal | |
| odCInvoiceCCRate | output | decimal | CInvoiceCCRate: ExchangeRate between TC and SC as specified on the invoice |
| odCInvoiceCCScale | output | decimal | CInvoiceCCScale: Exchange-rate Scale between TC and SC as specified on the invoice |
| odCInvoiceLCCCRate | output | decimal | Rate between LC and SC at the moment of the invoice (type: Statutory - optional: accounting) |
| odCInvoiceLCCCScale | output | decimal | Scale between LC and SC at the moment of the invoice (type: Statutory - optional: accounting) |
| otCInvoiceDate | output | date | |
| otCInvoicePostingDate | output | date | PostingDate of the invoice |
| otCInvoiceTaxPointDate | output | date | Taxpoint date of the invoice |
| ocCInvoiceType | output | character | Type of the invoice (credit-note, invoice, ...) |
| ocCInvoicePaymentCondition | output | character | Payment Condition of the Invoice |
| olCInvoiceIsInitialStatus | output | logical | |
| odTaxAcrueReceiptRecovTC | output | decimal | |
| odTaxAcrueReceiptNonRecovTC | output | decimal | |
| odTaxAcrueInvoiceRecovTC | output | decimal | |
| odTaxAcrueInvoiceNonRecovTC | output | decimal | |
| odInvoiceDiscountPercentage | output | decimal | |
| ocCreditorAddrTaxIDFederal | output | character | |
| ocCreditorAddrTaxIDState | output | character | |
| ocCreditorAddrTaxIDMisc1 | output | character | |
| ocCreditorAddrTaxIDMisc2 | output | character | |
| ocCreditorAddrTaxIDMisc3 | output | character | |
| olCreditorAddrIsTaxInCity | output | logical | |
| olCreditorAddrIsEUCountry | output | logical | |
| ocCreditorAddrCountryCode | output | character | |
| oiCreditorAddrID | output | integer | Head Office Address ID of the Creditor |
| ocShipToAddrTaxIDFederal | output | character | |
| ocShipToAddrTaxIDState | output | character | |
| ocShipToAddrTaxIDMisc1 | output | character | |
| ocShipToAddrTaxIDMisc2 | output | character | |
| ocShipToAddrTaxIDMisc3 | output | character | |
| oiShipToAddrTaxDeclarat | output | integer | |
| olShipToAddrIsTaxInCity | output | logical | |
| olShipToAddrIsEUCountry | output | logical | |
| ocShipToAddrCountryCode | output | character | |
| oiOriginalAPMatchingID | output | integer | |
| tOrderFilterAPM | output | temp-table | Temp-table containing the matching-scope of the invocie |
| otPostingDate | output | date | Posting Date |
| oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program7/bapmatching.p)
/* ============================ */
/* Exception handling */
/* ============================ */
assign oiReturnStatus = -98
oiCInvoiceId = ?.
/* ========================== */
/* Validate input parameters */
/* ========================== */
if biInvoiceYear = 0 then assign biInvoiceYear = ?.
if bcInvoiceJournal = '':U then assign bcInvoiceJournal = ?.
if biInvoiceVoucher = 0 then assign biInvoiceVoucher = ?.
if bcInvoiceReference = '':U then assign bcInvoiceReference = ?.
if biInvoiceRegistrationNr = 0 then assign biInvoiceRegistrationNr = ?.
if bcCreditorCode = '':U then assign bcCreditorCode = ?.
if (bcInvoiceReference = ? and
biInvoiceRegistrationNr = ? and
(biInvoiceYear = ? or
bcInvoiceJournal = ? or
biInvoiceVoucher = ?))
then do:
assign oiReturnStatus = 0.
return.
end.
find tAPMatching where
tAPMatching.tc_Rowid = icAPMatchingTcRowid
no-error.
if not available tAPMatching
then do :
assign vcMessage = trim(substitute(#T-6'The system cannot find the matching based upon its row ID (&1)':255(999890413)T-6#,icAPMatchingTcRowid))
oiReturnStatus = -3.
<M-7 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-7678':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
Return.
end. /* if not available tAPMatching */
/* ============================ */
/* Query the invoice */
/* ============================ */
<Q-1 run CInvoiceForAPMSelection (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input biInvoiceYear, (CInvoicePostingYear)
input bcInvoiceJournal, (JournalCode)
input biInvoiceVoucher, (CInvoiceVoucher)
input ?, (CInvoiceId)
input bcCreditorCode, (CreditorCode)
input bcInvoiceReference, (CInvoiceReference)
input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
input biInvoiceRegistrationNr, (CInvoiceRegistrationNr)
output dataset tqCInvoiceForAPMSelection) in BCInvoice>
find tqCInvoiceForAPMSelection no-error.
if not available tqCInvoiceForAPMSelection
then do:
assign oiReturnStatus = 0.
return.
end. /* if not available tqCInvoiceForAPMSelection */
/* ============================ */
/* Check CI-properties */
/* ============================ */
<M-4 run ValCInvoice
(input String(tqCInvoiceForAPMSelection.tiCInvoiceRegistrationNr) (icTargetField),
input 'tAPMatching.tiCInvoiceRegistrationNr':U (icTargetFieldName),
input icAPMatchingTcRowid (icRowid),
input string(tqCInvoiceForAPMSelection.tiCInvoicePostingYear) + '/':U + tqCInvoiceForAPMSelection.tcJournalCode + '/':U + string(tqCInvoiceForAPMSelection.tiCInvoiceVoucher,'999999999':U) (icYearJournalVoucher),
input tqCInvoiceForAPMSelection.tcCInvoiceType (icCInvoiceType),
input tqCInvoiceForAPMSelection.tlCInvoiceIsLogisticMatching (ilCInvoiceIsLogisticMatching),
input tqCInvoiceForAPMSelection.tcCInvoiceAllocationStatus (icCInvoiceAllocationStatus),
input tqCInvoiceForAPMSelection.tlCInvoiceIsInvoiceApproved (ilCInvoiceIsInvoiceApproved),
input tqCInvoiceForAPMSelection.tiCompany_ID (iiCInvoiceCompanyID),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then Return.
/* ============================ */
/* Assign output-params */
/* ============================ */
assign biInvoiceYear = tqCInvoiceForAPMSelection.tiCInvoicePostingYear
bcInvoiceJournal = tqCInvoiceForAPMSelection.tcJournalCode
biInvoiceVoucher = tqCInvoiceForAPMSelection.tiCInvoiceVoucher
bcInvoiceReference = tqCInvoiceForAPMSelection.tcCInvoiceReference
biInvoiceRegistrationNr = tqCInvoiceForAPMSelection.tiCInvoiceRegistrationNr
bcCreditorCode = tqCInvoiceForAPMSelection.tcCreditorCode
oiBusinessRelationID = tqCInvoiceForAPMSelection.tiBusinessRelation_ID
ocBusinessRelationCode = tqCInvoiceForAPMSelection.tcBusinessRelationCode
ocBusinessRelationICCode = tqCInvoiceForAPMSelection.tcBusinessRelationICCode
ocCurrencyCode = tqCInvoiceForAPMSelection.tcCurrencyCode
oiCInvoiceId = tqCInvoiceForAPMSelection.tiCInvoice_ID
odCInvoiceExchangeRate = round(tqCInvoiceForAPMSelection.tdCInvoiceExchangeRate,10)
odCInvoiceRateScale = tqCInvoiceForAPMSelection.tdCInvoiceRateScale
odCInvoiceCCRate = round(tqCInvoiceForAPMSelection.tdCInvoiceCCRate,10)
odCInvoiceCCScale = tqCInvoiceForAPMSelection.tdCInvoiceCCScale
otCInvoiceDate = tqCInvoiceForAPMSelection.ttCInvoiceDate
otCInvoicePostingDate = tqCInvoiceForAPMSelection.ttCInvoicePostingDate
odInvoiceDiscountPercentage = tqCInvoiceForAPMSelection.tdPaymentConditionPercentage
otCInvoiceTaxPointDate = tqCInvoiceForAPMSelection.ttCInvoiceTaxPointDate
ocCInvoiceType = tqCInvoiceForAPMSelection.tcCInvoiceType
ocCInvoicePaymentCondition = tqCInvoiceForAPMSelection.tcPaymentConditionCode
olCInvoiceIsInitialStatus = tqCInvoiceForAPMSelection.tlCInvoiceIsInitialStatus
viReplaceCInvoiceID = tqCInvoiceForAPMSelection.tiReplacedCInvoice_ID.
/* ========================================================================================================================= */
/* Fields tAPMatching.tdCInvoiceLCCCRate and tAPMatching.tdCInvoiceLCCCScale represent the rate and scale between LC and SC */
/* at the moment of the invoice (type: Statutory - optional: accounting) but these fields are not stored on the CInvoice as */
/* we do not need that information on the invoice itself. BUT; the pvod use this value to assign the CC-amounts based upon */
/* the LC-amounts in the PO-receipt-posting and we store that rate here to be able to compare the values. */
/* In fact, we do not use these values for making calculations: they are information-only */
/* ========================================================================================================================= */
if viCompanyCCId = viCompanyLCId
then assign odCInvoiceLCCCRate = 1
odCInvoiceLCCCScale = 1.
else do :
<M-73 run GetExchangeRate
(input tAPMatching.Company_ID (iiCompanyID),
input viCompanyLCId (iiFromCurrencyID),
input ? (icFromCurrencyCode),
input viCompanyCCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode),
input otCInvoicePostingDate (itValidityDate),
output odCInvoiceLCCCRate (odExchangeRate),
output odCInvoiceLCCCScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then Return.
end. /* not if viCompanyCCId = viCompanyLCId */
<Q-66 run PeriodByStartEndDate (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input tqCInvoiceForAPMSelection.ttCInvoicePostingDate, (Date)
output dataset tqPeriodByStartEndDate) in BPeriod >
find first tqPeriodByStartEndDate where
tqPeriodByStartEndDate.tcPeriodStatus = {&PERIODSTATUS-OPEN} and
tqPeriodByStartEndDate.ttPeriodStartDate <= tqCInvoiceForAPMSelection.ttCInvoicePostingDate and
tqPeriodByStartEndDate.ttPeriodEndDate >= tqCInvoiceForAPMSelection.ttCInvoicePostingDate
no-error.
if available tqPeriodByStartEndDate
then assign otPostingDate = tqCInvoiceForAPMSelection.ttCInvoicePostingDate.
else assign otPostingDate = Today.
/* ============================================= */
/* Call submethod for the invoice-amount details */
/* ============================================= */
<M-2 run DefaultValuesInvoiceAmount
(input tqCInvoiceForAPMSelection.tiCInvoice_ID (iiCInvoiceID),
input tAPMatching.APMatching_ID (iiAPMatchingID),
input tqCInvoiceForAPMSelection.tiReason_ID (iiOldReasonID),
input-output biNewReasonID (biNewReasonID),
input-output bcNewReasonCode (bcNewReasonCode),
output vcDummy (ocCurrency),
output odAmountToMatchTC (odAmountToMatchTC),
output odAmountToMatchLC (odAmountToMatchLC),
output odTaxAcrueReceiptRecovTC (odTaxAcrueReceiptRecovTC),
output odTaxAcrueReceiptNonRecovTC (odTaxAcrueReceiptNonRecovTC),
output odTaxAcrueInvoiceRecovTC (odTaxAcrueInvoiceRecovTC),
output odTaxAcrueInvoiceNonRecovTC (odTaxAcrueInvoiceNonRecovTC),
output odInvoiceDiscountPercentage (odInvoiceDiscountPercentage),
input false (ilBCInvoiceIsAlreadyOpen),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then Return.
/* ==================================================================== */
/* Store all the output parameters also in the tAPMatching record */
/* Store all address-details as well as we need them when GTM is called */
/* ==================================================================== */
assign tAPMatching.APMatchingTotalAmountTC = odAmountToMatchTC
tAPMatching.APMatchingTotalAmountLC = odAmountToMatchLC
tAPMatching.APMatchingAIRecTaxTC = odTaxAcrueInvoiceRecovTC
tAPMatching.APMatchingAINRecTaxTC = odTaxAcrueInvoiceNonRecovTC
tAPMatching.APMatchingARRecTaxTC = odTaxAcrueReceiptRecovTC
tAPMatching.APMatchingARNRecTaxTC = odTaxAcrueReceiptNonRecovTC
tAPMatching.APMatchingCInvoiceDiscPct = odInvoiceDiscountPercentage
tAPMatching.ttCInvoiceTaxPointDate = otCInvoiceTaxPointDate
tAPMatching.tcCInvoiceType = ocCInvoiceType
tAPMatching.tcCInvoicePaymentConditionCode = ocCInvoicePaymentCondition
tAPMatching.tcCurrencyCode = ocCurrencyCode
tAPMatching.tdCInvoiceExchangeRate = odCInvoiceExchangeRate
tAPMatching.tdCInvoiceRateScale = odCInvoiceRateScale
tAPMatching.tdCInvoiceCCRate = odCInvoiceCCRate
tAPMatching.tdCInvoiceCCScale = odCInvoiceCCScale
tAPMatching.tlCInvoiceIsInitialStatus = olCInvoiceIsInitialStatus
tAPMatching.tiCInvoiceRegistrationNr = biInvoiceRegistrationNr
tAPMatching.CInvoice_ID = oiCInvoiceId
tAPMatching.tiBusinessRelationID = oiBusinessRelationID
tAPMatching.tcBusinessRelationCode = ocBusinessRelationCode
tAPMatching.tcBusinessRelationICC = ocBusinessRelationICCode
tAPMatching.ttCInvoicePostingDate = otCInvoicePostingDate
tAPMatching.tdCInvoiceLCCCRate = odCInvoiceLCCCRate
tAPMatching.tdCInvoiceLCCCScale = odCInvoiceLCCCScale
ocCreditorAddrTaxIDFederal = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDFederal
ocCreditorAddrTaxIDState = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDState
ocCreditorAddrTaxIDMisc1 = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDMisc1
ocCreditorAddrTaxIDMisc2 = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDMisc2
ocCreditorAddrTaxIDMisc3 = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDMisc3
olCreditorAddrIsTaxInCity = tqCInvoiceForAPMSelection.tlCreditorAddrTaxInCity
olCreditorAddrIsEUCountry = tqCInvoiceForAPMSelection.tlCreditorAddrIsEUCountry
ocCreditorAddrCountryCode = tqCInvoiceForAPMSelection.tcCreditorAddrCountryCode
oiCreditorAddrID = tqCInvoiceForAPMSelection.tiCreditorAddr_ID
ocShipToAddrTaxIDFederal = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDFederal
ocShipToAddrTaxIDState = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDState
ocShipToAddrTaxIDMisc1 = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDMisc1
ocShipToAddrTaxIDMisc2 = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDMisc2
ocShipToAddrTaxIDMisc3 = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDMisc3
oiShipToAddrTaxDeclarat = tqCInvoiceForAPMSelection.tiShipToAddrTaxDeclarat
olShipToAddrIsTaxInCity = tqCInvoiceForAPMSelection.tlShipToAddrIsTaxInCity
olShipToAddrIsEUCountry = tqCInvoiceForAPMSelection.tlShipToAddrIsEUCountry
ocShipToAddrCountryCode = tqCInvoiceForAPMSelection.tcShipToAddrCountryCode
tAPMatching.tcCreditorAddrTaxIDFederal = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDFederal
tAPMatching.tcCreditorAddrTaxIDState = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDState
tAPMatching.tcCreditorAddrTaxIDMisc1 = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDMisc1
tAPMatching.tcCreditorAddrTaxIDMisc2 = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDMisc2
tAPMatching.tcCreditorAddrTaxIDMisc3 = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDMisc3
tAPMatching.tlCreditorAddrIsTaxInCity = tqCInvoiceForAPMSelection.tlCreditorAddrTaxInCity
tAPMatching.tlCreditorAddrIsEUCountry = tqCInvoiceForAPMSelection.tlCreditorAddrIsEUCountry
tAPMatching.tcCreditorAddrCountryCode = tqCInvoiceForAPMSelection.tcCreditorAddrCountryCode
tAPMatching.tiCreditorAddr_ID = tqCInvoiceForAPMSelection.tiCreditorAddr_ID
tAPMatching.tcShipToAddrTaxIDFederal = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDFederal
tAPMatching.tcShipToAddrTaxIDState = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDState
tAPMatching.tcShipToAddrTaxIDMisc1 = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDMisc1
tAPMatching.tcShipToAddrTaxIDMisc2 = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDMisc2
tAPMatching.tcShipToAddrTaxIDMisc3 = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDMisc3
tAPMatching.tiShipToAddrTaxDeclaration = tqCInvoiceForAPMSelection.tiShipToAddrTaxDeclarat
tAPMatching.tlShipToAddrIsTaxInCity = tqCInvoiceForAPMSelection.tlShipToAddrIsTaxInCity
tAPMatching.tlShipToAddrIsEUCountry = tqCInvoiceForAPMSelection.tlShipToAddrIsEUCountry
tAPMatching.tcShipToAddrCountryCode = tqCInvoiceForAPMSelection.tcShipToAddrCountryCode
tAPMatching.tiShipToAddress_ID = tqCInvoiceForAPMSelection.tiShipToAddress_ID
tAPMatching.tcCreditorCode = tqCInvoiceForAPMSelection.tcCreditorCode.
/* ================================================== */
/* Get Original APmatching ID for replaced CInvoice */
/* ================================================== */
assign oiOriginalAPMatchingID = 0.
if viReplaceCInvoiceID <> 0 and viReplaceCInvoiceID <> ?
then do:
<Q-9 run APMatchingByCInvoice (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input viReplaceCInvoiceID, (CInvoiceId)
input ?, (CInvoiceYear)
input ?, (CInvoiceJournalCode)
input ?, (CInvoiceVoucher)
output dataset tqAPMatchingByCInvoice) in BAPMatching >
find first tqAPMatchingByCInvoice where
tqAPMatchingByCInvoice.tiCInvoice_ID = viReplaceCInvoiceID no-error.
if available tqAPMatchingByCInvoice
then assign oiOriginalAPMatchingID = tqAPMatchingByCInvoice.tiAPMatching_ID.
end. /* if viReplaceCInvoiceID <> 0 and */
/* ================================================== */
/* Call query on CInvoicePO to get the matching-scope */
/* ================================================== */
<Q-5 run CInvoicePOByCInvoicePO (all) (Read) (NoCache)
(input tqCInvoiceForAPMSelection.tiCInvoice_ID, (CInvoiceID)
input ?, (PODomain)
input ?, (PONbr)
output dataset tqCInvoicePOByCInvoicePO) in BCInvoice >
empty temp-table tOrderFilterAPM.
for each tqCInvoicePOByCInvoicePO :
create tOrderFilterAPM.
assign tOrderFilterAPM.tcPONbr = tqCInvoicePOByCInvoicePO.tcCInvoicePOPoNbr.
end. /* for each tqCInvoicePOByCInvoicePO */
/* ============================ */
/* Exception handling */
/* ============================ */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.