Description
Creates new FAReval, FARevalDet and FARevalDetSaf records based on the input parameters.
Use GetPublicTables on UI to retrieve the newly created records.
NOTE: All these RevaluationCreate... methods should be in one segment
Parameters
icFAAssetCode | input | character | Asset Code |
icFAAssetTypeCode | input | character | Asset type |
icFABookTypeCode | input | character | Book type |
ilIsRevalChildren | input | logical | Indicates whether to revaluate asset children too |
icFARevalType | input | character | Revaluation type |
idFARevalPercentage | input | decimal | Revaluation percentage |
icFARevalIndexType | input | character | Index revaluation type |
idFARevalAmountLC | input | decimal | Revaluation Amount in LC |
iiAccPeriodYear | input | integer | Accounting Year |
iiAccPeriodPeriod | input | integer | accounting period |
itPostingDate | input | date | PostingDate |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program3/bfixedassetrevaluation.p)
assign icFAAssetCode = if icFAAssetCode = ? then "":U else icFAAssetCode
icFAAssetTypeCode = if icFAAssetTypeCode = ? then "":U else icFAAssetTypeCode
icFABookTypeCode = if icFABookTypeCode = ? then "":U else icFABookTypeCode
icFARevalIndexType = if icFARevalIndexType = ? then "":U else icFARevalIndexType
icFARevalType = if icFARevalType = ? then "":U else icFARevalType
idFARevalAmountLC = if idFARevalAmountLC = ? then 0 else idFARevalAmountLC
idFARevalPercentage = if idFARevalPercentage = ? then 0 else idFARevalPercentage
iiAccPeriodPeriod = if iiAccPeriodPeriod = ? then 0 else iiAccPeriodPeriod
iiAccPeriodYear = if iiAccPeriodYear = ? then 0 else iiAccPeriodYear
ilIsRevalChildren = if ilIsRevalChildren = ? then false else ilIsRevalChildren.
/*Validate input parameters*/
<M-1 run RevaluationCreateVal (input icFAAssetCode (icFAAssetCode),
input icFAAssetTypeCode (icFAAssetTypeCode),
input icFABookTypeCode (icFABookTypeCode),
input ilIsRevalChildren (ilIsRevalChildren),
input icFARevalType (icFARevalType),
input idFARevalPercentage (idFARevalPercentage),
input icFARevalIndexType (icFARevalIndexType),
input idFARevalAmountLC (idFARevalAmountLC),
input iiAccPeriodYear (iiAccPeriodYear),
input iiAccPeriodPeriod (iiAccPeriodPeriod),
input itPostingDate (itPostingDate),
output viFAAssetId (oiFAAssetId),
output viFAAssetTypeId (oiFAAssetTypeId),
output viFABookTypeId (oiFABookTypeId),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetRevaluation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
return.
end.
/*Clear the instance*/
empty temp-table tNoFAAssetSaf.
empty temp-table tNoFAAssetGLSaf.
<M-2 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BFixedAssetRevaluation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
return.
end.
/*Run a query on FAAssetBook to select the AssetBooks*/
assign viParentFAAssetId = if ilIsRevalChildren then viFAAssetId else ?.
<Q-3 run FAAssetByFARevalCreate (all) (Read) (Cache)
(input viCompanyId, (CompanyId)
input viFAAssetId, (FAAssetId)
input viParentFAAssetId, (ParentFAAssetId)
input viFAAssetTypeId, (FAAssetTypeId)
input viFABookTypeId, (FABookTypeId)
output dataset tqFAAssetByFARevalCreate) in BFixedAssetAsset >
/*Message: When nothing within the selection can be revaluated*/
if not can-find (first tqFAAssetByFARevalCreate)
then do:
assign vcMessage = trim(#T-8'No assets to revaluate have been found for your selection.':200(14038)T-8#)
oiReturnStatus = 1.
<M-7 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-3161':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetRevaluation>
return.
end.
/*Get Exchange rate between LC and CC for the selected posting date, relevant only if CC is specified*/
assign vdRate = ?
vdScale = ?.
if viCompanyCCId > 0
then do:
<M-80 run GetExchangeRate
(input ? (iiCompanyID),
input viCompanyLCId (iiFromCurrencyID),
input ? (icFromCurrencyCode),
input viCompanyCCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode),
input itPostingDate (itValidityDate),
output vdRate (odExchangeRate),
output vdScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetRevaluation>
end.
/*Create tFAReval record for each query result record*/
for each tqFAAssetByFARevalCreate
group by tqFAAssetByFARevalCreate.tiFAAsset_ID:
/*add detail line*/
<M-4 run AddDetailLine (input 'FAReval':U (icTable),
input '':U (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetRevaluation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
return.
end.
assign tFAReval.FAAssetBook_ID = tqFAAssetByFARevalCreate.tiFAAssetBook_ID
tFAReval.tcFAAssetBookCode = tqFAAssetByFARevalCreate.tcFAAssetBookCode
tFAReval.tcFAAssetCode = tqFAAssetByFARevalCreate.tcFAAssetCode
tFAReval.ttFAAssetBookNextPostingDate = tqFAAssetByFARevalCreate.ttFAAssetBookNextPostingDate
tFAReval.tcRevaluationJournalCode = tqFAAssetByFARevalCreate.tcRevaluationJournalCode
tFAReval.tlFABookTypeIsOfficial = tqFAAssetByFARevalCreate.tlFABookTypeIsOfficial
tFAReval.tdFAAssetBookAmountLC = tqFAAssetByFARevalCreate.tdFAAssetBookAmountLC
tFAReval.tdFAAssetBookAmountCC = tqFAAssetByFARevalCreate.tdFAAssetBookAmountCC
tFAReval.tdFAAssetBookDeprAmountLC = tqFAAssetByFARevalCreate.tdFAAssetBookDeprAmountLC
tFAReval.tdFAAssetBookDeprAmountCC = tqFAAssetByFARevalCreate.tdFAAssetBookDeprAmountCC
tFAReval.tdFAAssetBookSalvageAmountLC = tqFAAssetByFARevalCreate.tdFAAssetBookSalvageAmountLC
tFAReval.tdFAAssetBookSalvageAmountCC = tqFAAssetByFARevalCreate.tdFAAssetBookSalvageAmountCC
tFAReval.tiFAAssetBookPeriodsDepr = tqFAAssetByFARevalCreate.tiFAAssetBookPeriodsDepr
tFAReval.tcFAAssetBookDepreciationType = tqFAAssetByFARevalCreate.tcFAAssetBookDeprType
tFAReval.tdFAAssetBookDisposedLC = tqFAAssetByFARevalCreate.tdFAAssetBookDisposedLC
tFAReval.tdFAAssetBookDisposedDeprLC = tqFAAssetByFARevalCreate.tdFAAssetBookDisposedDeprLC
tFAReval.FARevalType = icFARevalType
tFAReval.FARevalIndexType = icFARevalIndexType
tFAReval.FARevalPercentage = idFARevalPercentage
tFAReval.FARevalAmountLC = idFARevalAmountLC
tFAReval.tdFARevalNetBookLC = tFAReval.tdFAAssetBookAmountLC -
tFAReval.tdFAAssetBookDeprAmountLC -
tFAReval.tdFAAssetBookDisposedLC +
tFAReval.tdFAAssetBookDisposedDeprLC.
/*get the last sequence and calc the date of the last revaluetion of the AssetBook*/
<Q-32 run FARevalByAssetBook (last) (Read) (NoCache)
(input tFAReval.FAAssetBook_ID, (FAAssetBookId)
output dataset tqFARevalByAssetBook) in BFixedAssetRevaluation >
find first tqFARevalByAssetBook no-error.
assign tFAReval.FARevalSequence = if available tqFARevalByAssetBook
then tqFARevalByAssetBook.tiFARevalSequence + 1
else 1
tFAReval.ttFARevalLastDate = if available tqFARevalByAssetBook
then tqFARevalByAssetBook.ttFARevalDate
else ?.
/*calculate lC amount*/
case tFAReval.FARevalType:
when {&FAREVALTYPE-PERCENTAGE}
then case tFAReval.FARevalIndexType:
when {&FAREVALINDEXTYPE-CAPITALISATION}
then assign tFAReval.FARevalAmountLC = tFAReval.tdFAAssetBookAmountLC * tFAReval.FARevalPercentage / 100.
when {&FAREVALINDEXTYPE-NETBOOK}
then assign tFAReval.FARevalAmountLC = tFAReval.tdFARevalNetBookLC * tFAReval.FARevalPercentage / 100.
when {&FAREVALINDEXTYPE-ACCUMDEPREC}
then assign tFAReval.FARevalAmountLC = tFAReval.tdFAAssetBookAmountLC * tFAReval.FARevalPercentage / 100
tFAReval.tdFAAssetBookDeprAmountLC = tFAReval.tdFAAssetBookDeprAmountLC * tFAReval.FARevalPercentage / 100.
end.
end case.
/*calculate CC amount, relevant only if CC is specified*/
if viCompanyCCId > 0
then do:
assign tFAReval.FARevalAmountCC = tFAReval.FARevalAmountLC * vdRate * vdScale.
if tFAReval.FARevalIndexType = {&FAREVALINDEXTYPE-ACCUMDEPREC}
then assign tFAReval.tdFAAssetBookDeprAmountCC = tFAReval.tdFAAssetBookDeprAmountLC * vdRate * vdScale.
end.
/*extra validations, only one message for a certain asset*/
if first-of (tqFAAssetByFARevalCreate.tiFAAsset_ID) and
tqFAAssetByFARevalCreate.tiGL_ID = 0 or tqFAAssetByFARevalCreate.tiGL_ID = ?
then do:
assign vcMessage = trim(subst(#T-33'No fixed asset account was defined for the asset '&1'.':200(14259)T-33#,
trim(tFAReval.tcFAAssetCode)))
oiReturnStatus = -1.
<M-36 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-3236':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetRevaluation>
end.
else do:
/*Check Revaluation Journal,
NOTE: this check is not needed anymore as the Revaluation journal is mandatory*/
/*
if tFAReval.tcRevaluationJournalCode = "":U or
tFAReval.tcRevaluationJournalCode = ?
then do:
assign vcMessage = trim(subst(#T-39'No revaluation daybook has been defined for the book type &1.':200(14216)T-39#,
trim(tFAReval.tcFABookTypeCode)))
oiReturnStatus = -1.
<M-38 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-3238':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetRevaluation>
end.
*/
/*Create tFARevalDet record for posting on the Fixed Asset account*/
assign vcPostingText = (if tFAReval.tlFABookTypeIsOfficial
then trim(#T-26'Off Reval':20(14360)T-26#)
else trim(#T-40'Unoff Reval':20(14361)T-40#)) + " ":U +
trim(tFAReval.tcFAAssetCode) + " ":U +
trim(tFAReval.tcFAAssetBookCode).
<M-25 run RevaluationCreateDet (input tFAReval.tc_Rowid (icParentRowid),
input tqFAAssetByFARevalCreate.tiGL_ID (iiGLId),
input tqFAAssetByFARevalCreate.tiDivision_ID (iiDivisionId),
input tqFAAssetByFARevalCreate.tiCostCentre_ID (iiCostCentreId),
input tqFAAssetByFARevalCreate.tiProject_ID (iiProjectId),
input tFAReval.FARevalAmountLC (idFARevalDetAmountLC),
input tFAReval.FARevalAmountCC (idFARevalDetAmountCC),
input vcPostingText (icFARevalDetPostingText),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetRevaluation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
return.
end.
/*Create the tFARevalDetSaf records based on the tFAAssetSaf records*/
<M-28 run RevaluationCreateDetSafForFAAccount (input tFARevalDet.tc_Rowid (icParentRowid),
input tqFAAssetByFARevalCreate.tiFAAsset_ID (iiFAAssetId),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetRevaluation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
return.
end.
end.
/*Create a tFARevalDet record for posting on the Revaluation account*/
assign vcFAAssetGLType = {&ASSETGLTYPE-REVAL}.
find first tqFAAssetGLByFAReval where
tqFAAssetGLByFAReval.tiFAAsset_ID = tqFAAssetByFARevalCreate.tiFAAsset_ID and
tqFAAssetGLByFAReval.tcFAAssetGLType = vcFAAssetGLType no-error.
if not available tqFAAssetGLByFAReval
then do:
<Q-18 run FAAssetGLByFAReval (all) (Read) (Cache)
(input tqFAAssetByFARevalCreate.tiFAAsset_ID, (FAAssetId)
input vcFAAssetGLType, (FAAssetGLType)
output dataset tqFAAssetGLByFAReval) in BFixedAssetAsset >
find first tqFAAssetGLByFAReval where
tqFAAssetGLByFAReval.tiFAAsset_ID = tqFAAssetByFARevalCreate.tiFAAsset_ID and
tqFAAssetGLByFAReval.tcFAAssetGLType = vcFAAssetGLType no-error.
end.
/*error:No revaluation account is defined, only one message for a certain asset*/
if first-of (tqFAAssetByFARevalCreate.tiFAAsset_ID) and
not available tqFAAssetGLByFAReval
then do:
assign vcMessage = trim(subst(#T-35'No revaluation account was defined for the asset '&1'.':200(14260)T-35#,
trim(tFAReval.tcFAAssetCode)))
oiReturnStatus = -1.
<M-37 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-3237':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetRevaluation>
end.
else do:
<M-27 run RevaluationCreateDet (input tFAReval.tc_Rowid (icParentRowid),
input tqFAAssetGLByFAReval.tiGL_ID (iiGLId),
input tqFAAssetGLByFAReval.tiDivision_ID (iiDivisionId),
input tqFAAssetGLByFAReval.tiCostCentre_ID (iiCostCentreId),
input tqFAAssetGLByFAReval.tiProject_ID (iiProjectId),
input -1 * tFAReval.FARevalAmountLC (idFARevalDetAmountLC),
input -1 * tFAReval.FARevalAmountCC (idFARevalDetAmountCC),
input vcPostingText (icFARevalDetPostingText),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetRevaluation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
return.
end.
/*Create tFARevalDetSaf records for the revaluation account*/
<M-41 run RevaluationCreateDetSafForRevalAccount (input tFARevalDet.tc_Rowid (icParentRowid),
input tqFAAssetGLByFAReval.tiFAAssetGL_ID (iiFAAssetGLId),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetRevaluation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
return.
end.
end.
end.