project QadFinancials > class BBankEntry > method GetPossibleAllocationsCInvoiceCrossCy
Description
Calculate correct amount for the invoice allocation if the invoice comes from the differnet entity then entity of banking entry.
Parameters
iiCompanyID | input | integer | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program6/bbankentry.p)
/* ====================================================================================== *
* Method : GetPossibleAllocationsCInvoiceCrossCy *
* Description : Calculate correct amount for the invoice allocation if the invoice *
* comes from the differnet entity then entity of banking entry. *
* -------------------------------------------------------------------------------------- *
* THIS METHOD HAS TO BE IN THE SAME SEGMENT AS PARENT METHOD *
* ====================================================================================== */
assign oiReturnStatus = -98
viLocalReturn = 0.
MAIN_BLOCK:
do on error undo, return:
/* ====================================================================================== *
* Precondition block *
* ====================================================================================== */
if not available tPossibleBankStateAlloc
then do:
assign vcMessage = #T-47'Missing record':255(69247)T-47#
vcContext = "available tPossibleBankStateAlloc = &1":U
vcContext = substitute(vcContext, available tPossibleBankStateAlloc).
<M-95 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-935207':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input vcContext (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
assign viLocalReturn = -1.
leave MAIN_BLOCK.
end.
/* This method can be executed only for Supplier invoice allocation */
if tPossibleBankStateAlloc.CInvoice_ID = 0 or
tPossibleBankStateAlloc.CInvoice_ID = ?
then do:
assign vcMessage = #T-87'This method can be used only for allocation of supplier invoice.':255(850665507)T-87#.
<M-5 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-335434':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
assign viLocalReturn = -1.
leave MAIN_BLOCK.
end.
/* ====================================================================================== *
* Get company's exchange rate shared set ID *
* ====================================================================================== */
<M-29 run StartCacher
(output vhFcComponent (ohCacher),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave MAIN_BLOCK.
<M-65 run GetIntegerValueFromSession
(input viSessionID (iiSessionId),
input 'SharedSetForEXCHANGERATE':U (icDataItemName),
output viExchangeRateSharedSetId (oiValue),
output viFcReturnSuper (oiReturnStatus)) in Cacher>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
assign vcMessage = #T-80'System cannot get ID of the Exchange Rate Shared Set.':255(588817158)T-80#.
<M-72 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'viExchangeRateSharedSetId':U (icFieldName),
input string(viExchangeRateSharedSetId) (icFieldValue),
input 'S':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-789612':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
leave MAIN_BLOCK.
end.
/* ====================================================================================== *
* Get supplier invoice details *
* ====================================================================================== */
/* Get invoice details */
<Q-74 run CInvoiceForPayment (all) (Read) (NoCache)
(input ?, (CompanyId)
input tPossibleBankStateAlloc.CInvoice_ID, (CInvoiceId)
output dataset tqCInvoiceForPayment) in BCInvoice >
find tqCInvoiceForPayment where
tqCInvoiceForPayment.tiCInvoice_ID = tPossibleBankStateAlloc.CInvoice_ID
no-error.
if not available tqCInvoiceForPayment
then do:
assign vcMessage = #T-11'Cannot find the supplier invoice based on its ID &1.':255(999890415)T-11#
vcMessage = substitute(vcMessage, tPossibleBankStateAlloc.CInvoice_ID).
<M-8 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tPossibleBankStateAlloc.CInvoice_ID':U (icFieldName),
input tPossibleBankStateAlloc.CInvoice_ID (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tPossibleBankStateAlloc.tc_Rowid (icRowid),
input 'qadfin-446752':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
assign viLocalReturn = -1.
leave MAIN_BLOCK.
end.
/* ================================================================================================ *
* Calculate exchange rate only when it goes over the border of the domain. In this case following *
* situations can happend *
* - Currencies are the same/different but the system is using different exchange rate shared set *
* - Currencies are different even the same exchange rate shared set is used *
* ================================================================================================ */
if tqCInvoiceForPayment.tiLCCurrency_ID = viCompanyLCId and
tqCInvoiceForPayment.tiStatutoryCurrency_ID = viCompanyCCId and
tqCInvoiceForPayment.tiExchangeRateSharedSet_ID = viExchangeRateSharedSetId
then leave MAIN_BLOCK.
/* ================================================================================================ *
* Calculate LC exchange rate which will be used for allocation posting *
* 1. If local currency of invoice entity and payment entity are the same, take it from Invoice *
* 2. In all other cases calculate exchange rate valid in the entity payment is executed *
* ================================================================================================ */
/* If local currency of the invoice are the same as local currency of the payment and *
* transactional currencies are also the same */
if tqCInvoiceForPayment.tcCInvoiceCurrencyCode = tPossibleBankStateAlloc.tcCurrencyCode and
tqCInvoiceForPayment.tiLCCurrency_ID = viCompanyLCId
then assign tPossibleBankStateAlloc.tdDocExchangeRate = tqCInvoiceForPayment.tdCInvoiceExchangeRate
tPossibleBankStateAlloc.tdDocExchangeRateScale = tqCInvoiceForPayment.tdCInvoiceRateScale.
/* In all other cases calculate the exchange rate */
else do:
<M-42 run GetExchangeRate
(input iiCompanyID (iiCompanyID),
input tqCInvoiceForPayment.tiCInvoiceCurrency_ID (iiFromCurrencyID),
input ? (icFromCurrencyCode),
input viCompanyLCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode),
input tqCInvoiceForPayment.ttCInvoicePostingDate (itValidityDate),
output tPossibleBankStateAlloc.tdDocExchangeRate (odExchangeRate),
output tPossibleBankStateAlloc.tdDocCCExchangeRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave MAIN_BLOCK.
end.
/* ================================================================================================ *
* Calculate CC exchange rate which will be used for allocation posting *
* 1. If statutory currency of invoice entity and exchange rate shared set of the invoice and *
* and payment entity are the same, take it from Invoice *
* 2. In all other cases calculate exchange rate valid in the entity payment is executed *
* ================================================================================================ */
/* If statutory currency of the invoice are the same as statutory currency of the payment and *
* both entities are using the same Exchange Rate Shared set, take it from the invoice */
if tqCInvoiceForPayment.tcCInvoiceCurrencyCode = tPossibleBankStateAlloc.tcCurrencyCode and
tqCInvoiceForPayment.tiStatutoryCurrency_ID = viCompanyCCId and
tqCInvoiceForPayment.tiExchangeRateSharedSet_ID = viExchangeRateSharedSetId
then assign tPossibleBankStateAlloc.tdDocCCExchangeRate = tqCInvoiceForPayment.tdCInvoiceCCRate
tPossibleBankStateAlloc.tdDocCCExchangeRateScale = tqCInvoiceForPayment.tdCInvoiceCCScale.
/* If statutory currencies are different, take current exchange rate between TC and LC */
else do:
<M-10 run GetExchangeRate
(input iiCompanyID (iiCompanyID),
input tqCInvoiceForPayment.tiCInvoiceCurrency_ID (iiFromCurrencyID),
input ? (icFromCurrencyCode),
input viCompanyCCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode),
input tqCInvoiceForPayment.ttCInvoicePostingDate (itValidityDate),
output tPossibleBankStateAlloc.tdDocCCExchangeRate (odExchangeRate),
output tPossibleBankStateAlloc.tdDocCCExchangeRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave MAIN_BLOCK.
end.
end. /* MAIN_BLOCK */
/* Error handling */
assign oiReturnStatus = viLocalReturn.