Parameters
icAssetAssetCode | input | character | |
icAssetBookType | input | character | |
idAssetBookAmountLC | input | decimal | |
idAssetBookSalvageAmountLC | input | decimal | |
idAssetBookDeprAmountLC | input | decimal | |
icAssetBookDepreciationType | input | character | |
icAssetBookCalculationType | input | character | |
itAssetBookStartDate | input | date | |
itAssetBookNextPostingDate | input | date | |
iiAssetBookLifeCycle | input | integer | |
iiAssetBookPeriodsDepr | input | integer | |
tDepreciationSimul | output | temp-table | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program3/bfixedassetdepreciation.p)
/* Correct wrong input parameters */
if idAssetBookAmountLC = ? then assign idAssetBookAmountLC = 0.
if idAssetBookDeprAmountLC = ? then assign idAssetBookDeprAmountLC = 0.
if idAssetBookSalvageAmountLC = ? then assign idAssetBookSalvageAmountLC = 0.
if iiAssetBookLifeCycle = ? then assign iiAssetBookLifeCycle = 0.
if iiAssetBookPeriodsDepr = ? then assign iiAssetBookPeriodsDepr = 0.
if icAssetBookCalculationType = ? or icAssetBookCalculationType = "?":U then assign icAssetBookCalculationType = "":U.
if icAssetBookDepreciationType = ? or icAssetBookDepreciationType = "?":U then assign icAssetBookDepreciationType = "":U.
/* Capitalization Amount has to be filled in */
if idAssetBookAmountLC <= 0
then do:
<M-2 run SetMessage
(input #T-11'You specified an invalid capitalization amount for this asset.':255(2017)t-11# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-2954':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
assign oiReturnStatus = -1.
end.
/* Salvage Amount has not to be negative */
if idAssetBookSalvageAmountLC < 0
then do:
<M-3 run SetMessage
(input #T-12'The salvage amount cannot be negative.':255(2018)t-12# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-2955':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
assign oiReturnStatus = -1.
end.
/* Depreciated Amount has not to be negative */
if idAssetBookDeprAmountLC < 0
then do:
<M-4 run SetMessage
(input #T-13'The depreciated amount cannot be negative.':255(2019)t-13# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-2956':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
assign oiReturnStatus = -1.
end.
/* The depreciation type is mandatory */
if icAssetBookDepreciationType = '':U
then do:
<M-6 run SetMessage
(input #T-14'Invalid depreciation type for this asset book.':255(2020)t-14# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-2958':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
assign oiReturnStatus = -1.
end.
/* The calculation type is mandatory */
if icAssetBookCalculationType = '':U
then do:
<M-5 run SetMessage
(input #T-15'Invalid calculation type for this asset book.':255(2021)t-15# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-2957':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
assign oiReturnStatus = -1.
end.
/* The start date is mandatory */
if itAssetBookStartDate = ?
then do:
<M-7 run SetMessage
(input #T-16'Invalid start date for this asset book.':255(2022)t-16# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-2959':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
assign oiReturnStatus = -1.
end.
/* The Life Cycle is mandatory */
if iiAssetBookLifeCycle <= 0
then do:
<M-8 run SetMessage
(input #T-17'Invalid life cycle for this asset book.':255(2023)t-17# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-2960':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
assign oiReturnStatus = -1.
end.
/* The Count of Periods Depreciated is mandatory */
if iiAssetBookPeriodsDepr < 0
then do:
<M-9 run SetMessage
(input #T-18'Invalid count of periods depreciated for this asset book.':255(2024)t-18# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-2961':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
assign oiReturnStatus = -1.
end.
if oiReturnStatus < 0
then return.
/* For user defined depreciations we need "real" investment */
if icAssetAssetCode <> ? and
icAssetAssetCode <> "":U and
icAssetAssetCode <> "?":U and
icAssetBookType <> ? and
icAssetBookType <> "":U and
icAssetBookType <> "?":U
then do:
<Q-21 run FAAssetBookByAssetCodeBookType (all) (Read) (NoCache)
(input icAssetAssetCode, (FAAssetCode)
input icAssetBookType, (FAAssetBookType)
input viCompanyId, (CompanyId)
input ?, (FAAssetID)
output dataset tqFAAssetBookByAssetCodeBookType) in BFixedAssetAsset >
find first tqFAAssetBookByAssetCodeBookType no-error.
end.
/* In case there were no depreciations yet, set the next posting date */
if can-do({&DEPRECIATIONTYPE-CZTAXSTRAIGHT} + ",":U +
{&DEPRECIATIONTYPE-CZTAXACCELERATED}, icAssetBookDepreciationType)
then do:
assign viNextPeriodYear = if itAssetBookNextPostingDate = ?
then year(itAssetBookStartDate)
else year(itAssetBookNextPostingDate).
assign itAssetBookNextPostingDate = <M-29 CalcLastDateOfAccYear (input viNextPeriodYear (iiAccYear),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>.
end.
else if itAssetBookNextPostingDate = ?
then assign itAssetBookNextPostingDate = date(if month(itAssetBookStartDate) = 12 then 1 else month(itAssetBookStartDate) + 1, 1, if month(itAssetBookStartDate) >= 12 then year(itAssetBookStartDate) + 1 else year(itAssetBookStartDate)) - 1.
if itAssetBookNextPostingDate = ?
then do:
<M-23 run SetMessage
(input #T-24'Cannot set the next posting date.':200(16573)t-24# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-4038':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
assign oiReturnStatus = -1.
return.
end.
/* Execute Simulation Depreciation */
empty temp-table tDepreciationSimul.
SIMULATIONBLOCK:
do while true:
assign viFADepreciationYear = year(itAssetBookNextPostingDate)
viFADepreciationPeriod = month(itAssetBookNextPostingDate).
<M-10 run DepreciationTypes (input icAssetBookDepreciationType (icFAAssetBookDepreciationType),
input icAssetBookCalculationType (icFAAssetBookCalculationType),
input iiAssetBookLifeCycle (iiFAAssetBookLifeCycle),
input iiAssetBookPeriodsDepr (iiFAAssetBookPeriodsDepr),
input itAssetBookStartDate (itFAAssetBookStartDate),
input itAssetBookNextPostingDate (itFAAssetBookNextPostingDate),
input viFADepreciationYear (iiFADepreciationYear),
input viFADepreciationPeriod (iiFADepreciationPeriod),
input idAssetBookAmountLC (idFAAssetBookAmountLC),
input idAssetBookDeprAmountLC (idFAAssetBookDeprAmountLC),
input idAssetBookSalvageAmountLC (idFAAssetBookSalvageAmountLC),
input 0 (idFAAssetBookDisposalAmountLC),
input 0 (idFAAssetBookDisposalDepAmountLC),
input 0 (idFAAssetBookAmountCC),
input 0 (idFAAssetBookDeprAmountCC),
input 0 (idFAAssetBookSalvageAmountCC),
input 0 (idFAAssetBookDisposalAmountCC),
input 0 (idFAAssetBookDisposalDepAmountCC),
input if available tqFAAssetBookByAssetCodeBookType then tqFAAssetBookByAssetCodeBookType.tiFAAssetBook_ID else ? (iiFAAssetBookId),
output tNewDepreciation (tNewDepreciation),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
assign oiReturnStatus = if (oiReturnStatus > 0 and
viFcReturnSuper = 0) or
oiReturnStatus < 0
then oiReturnStatus
else viFcReturnSuper.
if oiReturnStatus < 0
then return.
for each tNewDepreciation:
if tNewDepreciation.tdNewDeprAmountLC <= 0
then next.
/* When calculation type is FULL-YEAR or FULL-YEAR-PRORATA-TEMPORIS, the first depreciation is per 1st till start-date periods */
assign iiAssetBookPeriodsDepr = iiAssetBookPeriodsDepr +
(if iiAssetBookPeriodsDepr = 0 and
can-do({&BOOKCALCULATIONTYPE-FULLYEAR} + ",":U +
{&BOOKCALCULATIONTYPE-FULLYEARTEMPORIS}, icAssetBookCalculationType) and
tNewDepreciation.tiNewDeprYear = year(itAssetBookStartDate) and
tNewDepreciation.tiNewDeprMonth = month(itAssetBookStartDate)
then tNewDepreciation.tiNewDeprMonth
else 1).
/* Do we have still anything to depreciate? or is the LifeCycle reached? */
/* For the 'Declining Balances' the open amount will remain when reached the lifecycle */
if not can-do({&DEPRECIATIONTYPE-ACT1} + ",":U +
{&DEPRECIATIONTYPE-USER1}, icAssetBookDepreciationType)
then if (not can-do({&DEPRECIATIONTYPE-DB15} + ",":U +
{&DEPRECIATIONTYPE-DB20} + ",":U +
{&DEPRECIATIONTYPE-DB25} + ",":U +
{&DEPRECIATIONTYPE-DB15SL} + ",":U +
{&DEPRECIATIONTYPE-DB20SL} + ",":U +
{&DEPRECIATIONTYPE-DB25SL} + ",":U +
{&DEPRECIATIONTYPE-YD15SL} + ",":U +
{&DEPRECIATIONTYPE-YD20SL} + ",":U +
{&DEPRECIATIONTYPE-YD25SL} + ",":U +
{&DEPRECIATIONTYPE-SL1ZERO} + ",":U +
{&DEPRECIATIONTYPE-CZTAXSTRAIGHT} + ",":U +
{&DEPRECIATIONTYPE-CZTAXACCELERATED}, icAssetBookDepreciationType) and
iiAssetBookPeriodsDepr >= iiAssetBookLifeCycle) or
(idAssetBookAmountLC - /* including + idFAAssetBookDisposedDeprLC - idFAAssetBookDisposedLC */
idAssetBookSalvageAmountLC -
idAssetBookDeprAmountLC -
tNewDepreciation.tdNewDeprAmountLC < 0)
then assign tNewDepreciation.tdNewDeprAmountLC = idAssetBookAmountLC -
idAssetBookSalvageAmountLC -
idAssetBookDeprAmountLC.
if tNewDepreciation.tdNewDeprAmountLC <> 0
then do:
create tDepreciationSimul.
assign tNewDepreciation.tdNewDeprAmountLC = /*round(tNewDepreciation.tdNewDeprAmountLC, viCompanyLCDec)*/
<M-31 RoundAmount
(input tNewDepreciation.tdNewDeprAmountLC (idUnroundedAmount),
input viCompanyLCid (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in business>
idAssetBookDeprAmountLC = idAssetBookDeprAmountLC + tNewDepreciation.tdNewDeprAmountLC
tDepreciationSimul.tiAssetBookDeprecYear = tNewDepreciation.tiNewDeprYear
tDepreciationSimul.tiAssetBookDeprecPeriod = tNewDepreciation.tiNewDeprMonth
tDepreciationSimul.tdAssetBookDeprecAmountLC = tNewDepreciation.tdNewDeprAmountLC
tDepreciationSimul.tdAssetBookCumulDeprecAmountLC = idAssetBookDeprAmountLC
tDepreciationSimul.tdAssetBookNetBookValueLC = idAssetBookAmountLC - tDepreciationSimul.tdAssetBookCumulDeprecAmountLC.
end.
if idAssetBookAmountLC - /* including + idFAAssetBookDisposedDeprLC - idFAAssetBookDisposedLC */
idAssetBookSalvageAmountLC -
idAssetBookDeprAmountLC <= 0
then leave SIMULATIONBLOCK.
if not can-do({&DEPRECIATIONTYPE-ACT1} + ",":U +
{&DEPRECIATIONTYPE-CZTAXSTRAIGHT} + ",":U +
{&DEPRECIATIONTYPE-CZTAXACCELERATED} + ",":U +
{&DEPRECIATIONTYPE-USER1} + ",":U +
{&DEPRECIATIONTYPE-SL1ZERO}, icAssetBookDepreciationType) and
iiAssetBookPeriodsDepr >= iiAssetBookLifeCycle
then leave SIMULATIONBLOCK.
end.
/* If there still remains something to depreciate on the investment, let's set the next posting date, else leave the last previous posting date */
/* For CZ Tax methods */
assign vtNextPostingDateCZTax = ?.
if can-do({&DEPRECIATIONTYPE-CZTAXSTRAIGHT} + ",":U +
{&DEPRECIATIONTYPE-CZTAXACCELERATED}, icAssetBookDepreciationType)
then do:
if idAssetBookAmountLC - /* including + idFAAssetBookDisposedDeprLC - idFAAssetBookDisposedLC */
idAssetBookSalvageAmountLC -
idAssetBookDeprAmountLC <> 0
then do:
assign vtNextPostingDateCZTax = <M-30 CalcLastDateOfAccYear (input year(itAssetBookNextPostingDate) + 1 (iiAccYear),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>.
if vtNextPostingDateCZTax = ?
then do:
<M-26 run SetMessage
(input #T-27'The system cannot set the next posting date.':200(16574)t-27# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-4039':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
assign oiReturnStatus = -1.
return.
end.
else assign itAssetBookNextPostingDate = vtNextPostingDateCZTax.
end.
else assign itAssetBookNextPostingDate = date(1,1,integer({&DEPRECIATIONPERIOD-YEARMAX}) + 1).
end.
/* Set the next booking date to the end of next month */
else assign itAssetBookNextPostingDate = <M-28 CalcLastDate (input year(itAssetBookNextPostingDate) (iiYear),
input month(itAssetBookNextPostingDate) (iiMonth),
input 1 (iiMonthPos)) in BFixedAssetDepreciation>.
if itAssetBookNextPostingDate > date(12,31,integer({&DEPRECIATIONPERIOD-YEARMAX}))
then leave SIMULATIONBLOCK.
end.
Sample code: how to call this method through RPCRequestService (QXtend Inbound)
define temp-table ttContext no-undo
field propertyQualifier as character
field propertyName as character
field propertyValue as character
index entityContext is primary unique
propertyQualifier
propertyName
index propertyQualifier
propertyQualifier.
define dataset dsContext for ttContext.
define variable vhContextDS as handle no-undo.
define variable vhExceptionDS as handle no-undo.
define variable vhServer as handle no-undo.
define variable vhInputDS as handle no-undo.
define variable vhInputOutputDS as handle no-undo.
define variable vhOutputDS as handle no-undo.
define variable vhParameter as handle no-undo.
/* Create context */
create ttContext.
assign ttContext.propertyName = "programName"
ttContext.propertyValue = "BFixedAssetDepreciation".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "APIDepreciationSimul".
create ttContext.
assign ttContext.propertyName = "applicationId"
ttContext.propertyValue = "fin".
create ttContext.
assign ttContext.propertyName = "entity"
ttContext.propertyValue = "1000".
create ttContext.
assign ttContext.propertyName = "userName"
ttContext.propertyValue = "mfg".
create ttContext.
assign ttContext.propertyName = "password"
ttContext.propertyValue = "".
/* Create input dataset */
create dataset vhInputDS.
vhInputDS:read-xmlschema("file", "xml/bfixedassetdepreciation.apidepreciationsimul.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icAssetAssetCode = <parameter value>
vhParameter::icAssetBookType = <parameter value>
vhParameter::idAssetBookAmountLC = <parameter value>
vhParameter::idAssetBookSalvageAmountLC = <parameter value>
vhParameter::idAssetBookDeprAmountLC = <parameter value>
vhParameter::icAssetBookDepreciationType = <parameter value>
vhParameter::icAssetBookCalculationType = <parameter value>
vhParameter::itAssetBookStartDate = <parameter value>
vhParameter::itAssetBookNextPostingDate = <parameter value>
vhParameter::iiAssetBookLifeCycle = <parameter value>
vhParameter::iiAssetBookPeriodsDepr = <parameter value>.
/* Connect the AppServer */
create server vhServer.
vhServer:connect("-URL <appserver-url>").
if not vhServer:connected()
then do:
message "Could not connect AppServer" view-as alert-box error title "Error".
return.
end.
/* Run */
assign vhContextDS = dataset dsContext:handle.
run program/rpcrequestservice.p on vhServer
(input-output dataset-handle vhContextDS by-reference,
output dataset-handle vhExceptionDS,
input dataset-handle vhInputDS by-reference,
input-output dataset-handle vhInputOutputDS by-reference,
output dataset-handle vhOutputDS).
/* Handle output however you want, in this example, we dump it to xml */
if valid-handle(vhExceptionDS)
then vhExceptionDS:write-xml("file", "Exceptions.xml", true).
if valid-handle(vhOutputDS)
then vhOutputDS:write-xml("file", "Output.xml", true).
/* Cleanup */
vhServer:disconnect().
assign vhServer = ?.
if valid-handle(vhInputDS)
then delete object vhInputDS.
if valid-handle(vhOutputDS)
then delete object vhOutputDS.
if valid-handle(vhExceptionDS)
then delete object vhExceptionDS.