Description
Validations done before convertin the SC.
Parameters
icDomainCode | input | character | |
icNewSCCode | input | character | |
ilDomainIsStatutoryCurrency | input | logical | |
ilPerformUpdatesAnyway | input | logical | |
ocErrorMessage | output | character | ErrorMessage |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program1/tsetstatutorycurrency.p)
assign oiReturnStatus = -98
viLocalReturnStatus = 0.
/* =========== */
/* Definitions */
/* =========== */
define buffer bACExchangeRateType for ExchangeRateType.
define buffer bSCExchangeRateType for ExchangeRateType.
define buffer bTXExchangeRateType for ExchangeRateType.
define buffer bOldSCCurrency for Currency.
define buffer bNewSCCurrency for Currency.
define buffer bBaseCurrency for Currency.
/* ================ */
/* Validation Block */
/* ================ */
VALIDATEBLOCK:
do:
/* ================================= */
/* Read the required exch-rate-types */
/* ================================= */
/* Accounting */
find bACExchangeRateType where
bACExchangeRateType.ExchangeRateTypeCode = {&EXCHANGERATETYPE-ACCOUNTING} and
bACExchangeRateType.ExchangeRateTypeIsActive = true
no-lock no-error.
if not available bACExchangeRateType
then do :
assign viLocalReturnStatus = -130
ocErrorMessage = "The accounting exchange rate type is missing from the system or is inactive".
leave VALIDATEBLOCK.
end. /* if not available bACExchangeRateType */
else assign viACExchangeRateTypeID = bACExchangeRateType.ExchangeRateType_ID.
/* Statutory */
find bSCExchangeRateType where
bSCExchangeRateType.ExchangeRateTypeCode = {&EXCHANGERATETYPE-STATUTORY} and
bSCExchangeRateType.ExchangeRateTypeIsActive = true
no-lock no-error.
if not available bSCExchangeRateType
then do :
assign viLocalReturnStatus = -131
ocErrorMessage = "The statutory exchange rate type is missing from the system or is inactive".
leave VALIDATEBLOCK.
end. /* if not available bACExchangeRateType */
else assign viSCExchangeRateTypeID = bSCExchangeRateType.ExchangeRateType_ID
vlSCIsFallBack = bSCExchangeRateType.ExchangeRateTypeIsFallBack.
/* Vat */
find bTXExchangeRateType where
bTXExchangeRateType.ExchangeRateTypeCode = {&EXCHANGERATETYPE-VAT} and
bTXExchangeRateType.ExchangeRateTypeIsActive = true
no-lock no-error.
if not available bTXExchangeRateType
then do :
assign viLocalReturnStatus = -132
ocErrorMessage = "The tax exchange rate type is missing from the system or is inactive".
leave VALIDATEBLOCK.
end. /* if not available bTXExchangeRateType */
else assign viTXExchangeRateTypeID = bTXExchangeRateType.ExchangeRateType_ID.
/* ===================================== */
/* Validate the required input is filled */
/* ===================================== */
/* DomainCode */
if icDomainCode = "":U or
icDomainCode = ?
then do :
assign viLocalReturnStatus = -110
ocErrorMessage = "The domain was not specified: please specify the domain".
leave VALIDATEBLOCK.
end. /* if icDomainCode = "":U or */
/* New SC Code */
if icNewSCCode = "":U or
icNewSCCode = ?
then do :
assign viLocalReturnStatus = -111
ocErrorMessage = "The new statutory-currency was not specified: please specify the new statutory-currency".
leave VALIDATEBLOCK.
end. /* if icNewSCCode = "":U or */
/* ================== */
/* Domain Validations */
/* ================== */
find Domains where
Domains.DomainCode = icDomainCode
no-lock no-error.
if not available Domains
then do:
assign viLocalReturnStatus = -100
ocErrorMessage = substitute("Unable to get the Domain with code &1", icDomainCode).
leave VALIDATEBLOCK.
end. /* if not available Domains */
find DomainProperty where
DomainProperty.Domain_ID = Domains.Domain_ID
no-lock no-error.
if not available DomainProperty
then do :
assign viLocalReturnStatus = -101
ocErrorMessage = substitute("Unable to get the DomainProperty for code &1", icDomainCode).
leave VALIDATEBLOCK.
end. /* if not available DomainProperty */
else do :
if DomainProperty.DomainPropertyIsSetupCompl <> true
then do :
assign viLocalReturnStatus = -120
ocErrorMessage = substitute("Domain is not yet marked as 'Setup completed'; you should thus use the normal domain-maintenance to make any chnage to the domain.", icDomainCode).
leave VALIDATEBLOCK.
end. /* if DomainProperty.DomainPropertyIsSetupCompl <> true */
/* The history-daemon should have completed its requests first */
for each company where
company.domain_id = domains.domain_id
no-lock,
first qpostingline where
qpostingline.company_id = company.company_id
no-lock :
assign viLocalReturnStatus = -121
ocErrorMessage = substitute("The history-daemon should finish all its requests before this routine can be started. There still are some requests for Entity &1 in Domain &2.", Company.CompanyCode, icDomainCode).
leave VALIDATEBLOCK.
end. /* for each company where */
/* Invoice Certification validation */
if DomainProperty.DomainPropertyIsInvCertific = true
then do:
find Currency where
CurrencyCode = "EUR"
no-lock no-error.
if available currency and
DomainProperty.Currency_ID <> Currency.Currency_ID and
icNewSCCode <> "EUR"
then do:
assign viLocalReturnStatus = -122
ocErrorMessage = substitute("This domain (&1) was set up for Invoice Certification. Since the base currency is not EUR, the Statutory Currency Code has to be EUR.", icDomainCode).
leave VALIDATEBLOCK.
end. /* if DomainProperty.DomainPropertyIsInvCert = true */
end. /* if DomainProperty.DomainPropertyIsInvCert = true */
end. /* if available DomainProperty */
/* ==================== */
/* Currency Validations */
/* ==================== */
/* Find original Statutory Currency */
find bOldSCCurrency where
bOldSCCurrency.Currency_ID = DomainProperty.StatutoryCurrency_ID
no-lock no-error.
if not available bOldSCCurrency
then do :
assign viLocalReturnStatus = -102
ocErrorMessage = substitute("Unable to get the current statutory-currency of Domain &1 based on its ID &2", icDomainCode, DomainProperty.StatutoryCurrency_ID).
leave VALIDATEBLOCK.
end. /* if not available bOldSCCurrency */
/* Find original Base Currency */
find bBaseCurrency where
bBaseCurrency.Currency_ID = DomainProperty.Currency_ID
no-lock no-error.
if not available bBaseCurrency
then do :
assign viLocalReturnStatus = -103
ocErrorMessage = substitute("Unable to get the base-currency of Domain &1 based on its ID &2", icDomainCode, DomainProperty.StatutoryCurrency_ID).
leave VALIDATEBLOCK.
end. /* if not available bBaseCurrency */
else assign viLocalCurrencyID = bBaseCurrency.Currency_ID.
/* Find new Staturoy Currency */
find bNewSCCurrency where
bNewSCCurrency.CurrencyCode = icNewSCCode
no-lock no-error.
if not available bNewSCCurrency
then do :
assign viLocalReturnStatus = -104
ocErrorMessage = substitute("Unable to get the new statutory-currency for Domain &1 based on its code &2", icDomainCode, icNewSCCode).
leave VALIDATEBLOCK.
end. /* if not available bNewSCCurrency */
else if bNewSCCurrency.CurrencyIsActive <> true
then do :
assign viLocalReturnStatus = -105
ocErrorMessage = substitute("The new statutory-currency &2 for Domain &1 is inactive", icDomainCode, icNewSCCode).
leave VALIDATEBLOCK.
end. /* if bNewSCCurrency.CurrencyIsActive <> true */
else assign viNewSCID = bNewSCCurrency.Currency_ID.
/* SC needs to differ from Base Currency, when using SC */
if bNewSCCurrency.CurrencyCode = bBaseCurrency.CurrencyCode and
ilDomainIsStatutoryCurrency = true
then do:
assign viLocalReturnStatus = -106
ocErrorMessage = substitute("Statutory Currency can only be enabled if the Statutory Currency (&1) is different from the Base Currency (&2).", bNewSCCurrency.CurrencyCode, bBaseCurrency.CurrencyCode ).
leave VALIDATEBLOCK.
end. /* if bNewSCCurrency.Currency_ID = bBaseCurrency.Currency_ID and */
/* SC needs to be equal to Base currency when not using SC */
if bNewSCCurrency.CurrencyCode <> bBaseCurrency.CurrencyCode and
ilDomainIsStatutoryCurrency = false
then do:
assign viLocalReturnStatus = -107
ocErrorMessage = substitute("The Base Currency (&1) needs to be equal to the Statutory Currency (&2) when statutory currency is not enabled for the domain.", bBaseCurrency.CurrencyCode, bNewSCCurrency.CurrencyCode ).
leave VALIDATEBLOCK.
end. /* if bNewSCCurrency.Currency_ID = bBaseCurrency.Currency_ID and */
/* New SC needs to differ from old SC, unless it is overruled */
if bOldSCCurrency.CurrencyCode = bNewSCCurrency.CurrencyCode and
ilPerformUpdatesAnyway <> true
then do:
assign viLocalReturnStatus = -108
ocErrorMessage = substitute("The New Statutory Currency (&1) needs to be different from the existing Statutory Currency (&2) when the Force Update was not flagged.", bNewSCCurrency.CurrencyCode, bOldSCCurrency.CurrencyCode ).
leave VALIDATEBLOCK.
end. /* if bOldSCCurrency.CurrencyCode <> bNewSCCurrency.CurrencyCode and */
/* Retrieve Rounding Information for the new SC Currency */
find RoundingMethod where
RoundingMethod.RoundingMethod_ID = bNewSCCurrency.RoundingMethod_ID
no-lock no-error.
if not available RoundingMethod
then do:
assign viLocalReturnStatus = -109
ocErrorMessage = substitute("No Rounding Method record could be found for the New Statutory Currency (&1).", bNewSCCurrency.CurrencyCode).
leave VALIDATEBLOCK.
end. /* find RoundingMethod where */
assign vdRoundingMethodUnit = RoundingMethod.RoundingMethodUnit
vdRoundingMethodThreshold = RoundingMethod.RoundingMethodThreshold.
/* ================================================================================================================ */
/* Validate if we have at least a single exchange-rate in case we need to get exchange-rates further on in the flow */
/* ================================================================================================================ */
if bNewSCCurrency.Currency_ID <> bBaseCurrency.Currency_ID
then do :
for each domains where
domains.domain_id = domainproperty.domain_id
no-lock,
each domainsharedset where
domainsharedset.domain_id = domains.domain_id
no-lock,
each sharedset where
sharedset.sharedset_id = domainsharedset.sharedset_id and
sharedset.sharedsettype = {&SHAREDSETTYPE-EXCHANGERATE}
no-lock,
each company where
company.domain_id = domains.domain_id
no-lock:
find first Posting where
Posting.Company_ID = Company.Company_ID
use-index CyPostingDate
no-lock no-error.
if available Posting
then do :
find first ExchangeRate where
ExchangeRate.SharedSet_ID = SharedSet.SharedSet_ID and
ExchangeRate.ExchangeRateType_ID = BSCExchangeRateType.ExchangeRateType_ID and
ExchangeRate.ExchangeRateValidDateFrom <= Posting.PostingDate and
ExchangeRate.ExchangeRateValidDateTill >= Posting.PostingDate and
(ExchangeRate.FromCurrency_ID = bNewSCCurrency.Currency_ID or
ExchangeRate.ToCurrency_ID = bNewSCCurrency.Currency_ID)
no-lock no-error.
if not available ExchangeRate
then do:
find first ExchangeRate where
ExchangeRate.SharedSet_ID = SharedSet.SharedSet_ID and
ExchangeRate.ExchangeRateType_ID = BACExchangeRateType.ExchangeRateType_ID and
ExchangeRate.ExchangeRateValidDateFrom <= Posting.PostingDate and
ExchangeRate.ExchangeRateValidDateTill >= Posting.PostingDate and
(ExchangeRate.FromCurrency_ID = bNewSCCurrency.Currency_ID or
ExchangeRate.ToCurrency_ID = bNewSCCurrency.Currency_ID)
no-lock no-error.
if not available ExchangeRate
then do :
assign viLocalReturnStatus = -140
ocErrorMessage = substitute("Unable to get an exchange-rate (Statutory/Accounting) using the statutory-currency &1 on the first posting-date &2 in entity &3 of domain &4", bNewSCCurrency.CurrencyCode, Posting.PostingDate, Company.CompanyCode, icDomainCode).
leave VALIDATEBLOCK.
end. /* if not available ExchangeRate */
end. /* if not available ExchangeRate */
end. /* if available Posting */
find last Posting where
Posting.Company_ID = Company.Company_ID
use-index CyPostingDate
no-lock no-error.
if available Posting
then do :
find first ExchangeRate where
ExchangeRate.SharedSet_ID = SharedSet.SharedSet_ID and
ExchangeRate.ExchangeRateType_ID = BACExchangeRateType.ExchangeRateType_ID and
ExchangeRate.ExchangeRateValidDateFrom <= Posting.PostingDate and
ExchangeRate.ExchangeRateValidDateTill >= Posting.PostingDate and
(ExchangeRate.FromCurrency_ID = bNewSCCurrency.Currency_ID or
ExchangeRate.ToCurrency_ID = bNewSCCurrency.Currency_ID)
no-lock no-error.
if not available ExchangeRate
then do :
find first ExchangeRate where
ExchangeRate.SharedSet_ID = SharedSet.SharedSet_ID and
ExchangeRate.ExchangeRateType_ID = BSCExchangeRateType.ExchangeRateType_ID and
ExchangeRate.ExchangeRateValidDateFrom <= Posting.PostingDate and
ExchangeRate.ExchangeRateValidDateTill >= Posting.PostingDate and
(ExchangeRate.FromCurrency_ID = bNewSCCurrency.Currency_ID or
ExchangeRate.ToCurrency_ID = bNewSCCurrency.Currency_ID)
no-lock no-error.
if not available ExchangeRate
then do :
assign viLocalReturnStatus = -142
ocErrorMessage = substitute("Unable to get an accounting exchange-rate (Statutory/Accounting) using the statutory-currency &1 on the last posting-date &2 in entity &3 of domain &4", bNewSCCurrency.CurrencyCode, Posting.PostingDate, Company.CompanyCode, icDomainCode).
leave VALIDATEBLOCK.
end. /* if not available ExchangeRate */
end. /* if not available ExchangeRate */
end. /* if available Posting */
end. /* for each domains of domainproperty no-lock, */
/* ======================================= */
/* Check if we have a rounding account */
/* Check the Shared Set for Exchange Rates */
/* ======================================= */
assign viExchangeRateSharedSetID = 0
viDomainGLSharedSetID = 0.
for each domainsharedset where
domainsharedset.domain_id = domainproperty.domain_id
no-lock:
find sharedset where
sharedset.sharedset_id = domainsharedset.sharedset_id
no-lock no-error.
if available sharedset
then do:
if sharedset.sharedsettype = {&SHAREDSETTYPE-GL}
then assign viDomainGLSharedSetID = sharedset.sharedset_id.
if sharedset.sharedsettype = {&SHAREDSETTYPE-EXCHANGERATE}
then assign viExchangeRateSharedSetID = sharedset.sharedset_id.
if sharedset.sharedsettype = {&SHAREDSETTYPE-DIVISION}
then assign viDomainDivisionSharedSetID = sharedset.sharedset_id.
if sharedset.sharedsettype = {&SHAREDSETTYPE-COSTCENTRE}
then assign viDomainCostCentreSharedSetID = sharedset.sharedset_id.
end.
end. /* for each domainsharedset where */
if viExchangeRateSharedSetID = 0
then do:
assign viLocalReturnStatus = -152
ocErrorMessage = substitute("No Exchange Rate Shared Set could be found for domain &1.", icDomainCode).
leave VALIDATEBLOCK.
end. /* if not available domainsharedset */
if viDomainDivisionSharedSetID = 0
then do:
assign viLocalReturnStatus = -155
ocErrorMessage = substitute("No Division Shared Set could be found for domain &1.", icDomainCode).
leave VALIDATEBLOCK.
end. /* if not available domainsharedset */
if viDomainCostCentreSharedSetID = 0
then do:
assign viLocalReturnStatus = -156
ocErrorMessage = substitute("No CostCentre Shared Set could be found for domain &1.", icDomainCode).
leave VALIDATEBLOCK.
end. /* if not available domainsharedset */
if viDomainGLSharedSetID = 0
then do:
assign viLocalReturnStatus = -150
ocErrorMessage = substitute("No GL Shared Set could be found for domain &1.", icDomainCode).
leave VALIDATEBLOCK.
end. /* if not available domainsharedset */
find first gl where
gl.sharedset_id = viDomainGLSharedSetID and
gl.glsystemtype = {&GLSYSTEMTYPE-ROUND}
no-lock no-error.
if not available gl
then do:
assign viLocalReturnStatus = -151
ocErrorMessage = substitute("No Rounding account was found for domain &1.", icDomainCode).
leave VALIDATEBLOCK.
end. /* if not available gl */
else assign viRoundGLID = gl.gl_id.
find first gl where
gl.sharedset_id = viDomainGLSharedSetID and
gl.glsystemtype = {&GLSYSTEMTYPE-EXCHANGEREALLOSS}
no-lock no-error.
if not available gl
then do:
assign viLocalReturnStatus = -153
ocErrorMessage = substitute("No Exchnage rate loss account was found for domain &1.", icDomainCode).
leave VALIDATEBLOCK.
end. /* if not available gl */
else assign viExchRealLossGLID = gl.gl_id.
find first gl where
gl.sharedset_id = viDomainGLSharedSetID and
gl.glsystemtype = {&GLSYSTEMTYPE-EXCHANGEREALPROFIT}
no-lock no-error.
if not available gl
then do:
assign viLocalReturnStatus = -154
ocErrorMessage = substitute("No Exchnage rate profit account was found for domain &1.", icDomainCode).
leave VALIDATEBLOCK.
end. /* if not available gl */
else assign viExchRealProfitGLID = gl.gl_id.
find first gl where
gl.sharedset_id = viDomainGLSharedSetID and
gl.glsystemtype = {&GLSYSTEMTYPE-EXCHANGEUNREALLOSS}
no-lock no-error.
if not available gl
then do:
assign viLocalReturnStatus = -153
ocErrorMessage = substitute("No unrealized Excgnage rate loss account was found for domain &1.", icDomainCode).
leave VALIDATEBLOCK.
end. /* if not available gl */
else assign viExchUnrealLossGLID = gl.gl_id.
find first gl where
gl.sharedset_id = viDomainGLSharedSetID and
gl.glsystemtype = {&GLSYSTEMTYPE-EXCHANGEUNREALPROFIT}
no-lock no-error.
if not available gl
then do:
assign viLocalReturnStatus = -154
ocErrorMessage = substitute("No unrealized Exchnage rate profit account was found for domain &1.", icDomainCode).
leave VALIDATEBLOCK.
end. /* if not available gl */
else assign viExchUnrealProfitGLID = gl.gl_id.
end. /* If bNewSCCurrency.Currency_ID <> bBaseCurrency.Currency_ID */
/* If SC needs to be calculated, then the daemons should have processed all records */
for each company where
company.domain_id = domains.domain_id
no-lock:
/* History Daemon */
if can-find(first QPostingLine where
QPostingLine.Company_id = Company.Company_id)
then do:
assign viLocalReturnStatus = -161
ocErrorMessage = "The History Daemon should have processed all records successfully before Statutory Currency can be set.".
leave VALIDATEBLOCK.
end. /* if can-find(first QPostingLine where */
/* Cross Company Daemon */
if can-find(first QCrossCyPosting where
QCrossCyPosting.Company_id = Company.Company_id)
then do:
assign viLocalReturnStatus = -161
ocErrorMessage = "The Cross Company Daemon should have processed all records successfully before Statutory Currency can be set.".
leave VALIDATEBLOCK.
end. /* if can-find(first QCrossCyPosting where */
/* Balance Daemon */
if can-find(first QCInvoiceMovement where
QCInvoiceMovement.Company_id = Company.Company_id) or
can-find(first QDInvoiceMovement where
QDInvoiceMovement.Company_id = Company.Company_id)
then do:
assign viLocalReturnStatus = -161
ocErrorMessage = "The Balance Daemon should have processed all records successfully before Statutory Currency can be set.".
leave VALIDATEBLOCK.
end. /* if can-find(first QCInvoiceMovement where */
end. /* for each company where */
end. /* VALIDATEBLOCK */
assign oiReturnStatus = viLocalReturnStatus.