project QadFinancials > class BFixedAssetDepreciation > method DepreciationTypeDBSL

Description

Execute Depreciations for the Type '1.5 Declining Balances / Switch to Straight Line' (DB15SL), '2.0 Declining Balances / Switch to Straight Line' (DB20SL), '2.5 Declining Balances / Switch to Straight Line' (DB25SL)


Parameters


icFAAssetBookCalculationTypeinputcharacter
iiFAAssetBookLifeCycleinputinteger
iiFAAssetBookPeriodsDepreciatedinputinteger
itFAAssetBookStartDateinputdate
itFAAssetBookNextPostingDateinputdate
iiDepreciationYearinputinteger
iiDepreciationPeriodinputinteger
idFAAssetBookCapitalAmountLCinputdecimal
idFAAssetBookDeprecAmountLCinputdecimal
idFAAssetBookSalvageAmountLCinputdecimal
idFAAssetBookDisposalAmountLCinputdecimal
idFAAssetBookDisposalDepAmountLCinputdecimal
idFactorinputdecimal
tNewDepreciationoutputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BFixedAssetDepreciation.DepreciationTypes


program code (program1/bfixedassetdepreciation.p)

empty temp-table tNewDepreciation.

<M-1 run DepreciationTypeSL1 (input  icFAAssetBookCalculationType (icFAAssetBookCalculationType), 
                              input  iiFAAssetBookLifeCycle (iiFAAssetBookLifeCycle), 
                              input  iiFAAssetBookPeriodsDepreciated (iiFAAssetBookPeriodsDepreciated), 
                              input  itFAAssetBookStartDate (itFAAssetBookStartDate), 
                              input  itFAAssetBookNextPostingDate (itFAAssetBookNextPostingDate), 
                              input  iiDepreciationYear (iiDepreciationYear), 
                              input  iiDepreciationPeriod (iiDepreciationPeriod), 
                              input  idFAAssetBookCapitalAmountLC (idFAAssetBookCapitalAmountLC), 
                              input  idFAAssetBookDeprecAmountLC (idFAAssetBookDeprecAmountLC), 
                              input  idFAAssetBookSalvageAmountLC (idFAAssetBookSalvageAmountLC), 
                              input  idFAAssetBookDisposalAmountLC (idFAAssetBookDisposalAmountLC), 
                              input  idFAAssetBookDisposalDepAmountLC (idFAAssetBookDisposalDepAmountLC), 
                              output vdNewDeprSL1AmountLC (odNewDeprAmountSL1LC), 
                              output vdNewDeprSL1StartAmountLC (odNewDeprAmountSL1StartLC), 
                              output tNewDepreciation (tNewDepreciation), 
                              output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
assign oiReturnStatus = if (oiReturnStatus  > 0 and 
                            viFcReturnSuper = 0) or 
                            oiReturnStatus  < 0
                        then oiReturnStatus
                        else viFcReturnSuper.

find first tNewDepreciation no-error.

if oiReturnStatus < 0 or 
   not available tNewDepreciation
then return.

empty temp-table tNewDepreciation.

case icFAAssetBookCalculationType:
    when {&BOOKCALCULATIONTYPE-FULLYEAR}
    then do:
        do viCounter = ((year(itFAAssetBookNextPostingDate) * 12) + month(itFAAssetBookNextPostingDate)) to ((iiDepreciationYear * 12) + iiDepreciationPeriod):
            if viCounter = ((year(itFAAssetBookNextPostingDate) * 12) + month(itFAAssetBookNextPostingDate))
            then do:
                do viCounterStart = 1 to month(itFAAssetBookStartDate):
                    create tNewDepreciation.
                    assign tNewDepreciation.tdNewDeprAmountLC = maximum((((idFAAssetBookCapitalAmountLC - idFAAssetBookDisposalAmountLC + idFAAssetBookDisposalDepAmountLC - <M-9 GetCumulDeprAmountLC () in BFixedAssetDepreciation>) * idFactor / iiFAAssetBookLifeCycle)), if viCounter = 1 then vdNewDeprSL1StartAmountLC else vdNewDeprSL1AmountLC)
                           vdNewDeprStartAmountLC = vdNewDeprStartAmountLC + tNewDepreciation.tdNewDeprAmountLC.
                end.
        
                empty temp-table tNewDepreciation.
            end.
            
            create tNewDepreciation.
            assign tNewDepreciation.tiNewDeprYear     = integer(truncate(viCounter / 12,0)) - (if viCounter mod 12 = 0 then 1 else 0)
                   tNewDepreciation.tiNewDeprMonth    = if viCounter mod 12 = 0 then 12 else viCounter mod 12
                   tNewDepreciation.tdNewDeprAmountLC = if viCounter = ((year(itFAAssetBookStartDate) * 12) + month(itFAAssetBookStartDate))
                                                        then maximum(vdNewDeprStartAmountLC, vdNewDeprSL1StartAmountLC * month(itFAAssetBookStartDate))
                                                        else maximum((((idFAAssetBookCapitalAmountLC - idFAAssetBookDisposalAmountLC + idFAAssetBookDisposalDepAmountLC - idFAAssetBookDeprecAmountLC - <M-2 GetCumulDeprAmountLC () in BFixedAssetDepreciation>) * idFactor / iiFAAssetBookLifeCycle)), vdNewDeprSL1AmountLC).
        end.
    end.
    when {&BOOKCALCULATIONTYPE-TEMPORIS}
    then do viCounter = ((year(itFAAssetBookNextPostingDate) * 12) + month(itFAAssetBookNextPostingDate)) to ((iiDepreciationYear * 12) + iiDepreciationPeriod):
        create tNewDepreciation.
        assign tNewDepreciation.tiNewDeprYear     = integer(truncate(viCounter / 12,0)) - (if viCounter mod 12 = 0 then 1 else 0)
               tNewDepreciation.tiNewDeprMonth    = if viCounter mod 12 = 0 then 12 else viCounter mod 12
               tNewDepreciation.tdNewDeprAmountLC = maximum(((idFAAssetBookCapitalAmountLC - idFAAssetBookDisposalAmountLC + idFAAssetBookDisposalDepAmountLC - idFAAssetBookDeprecAmountLC - <M-4 GetCumulDeprAmountLC () in BFixedAssetDepreciation>) * idFactor / iiFAAssetBookLifeCycle), if viCounter = ((year(itFAAssetBookStartDate) * 12) + month(itFAAssetBookStartDate)) then vdNewDeprSL1StartAmountLC else vdNewDeprSL1AmountLC).
               
        if tNewDepreciation.tdNewDeprAmountLC <= 0
        then return.                                                                     
    end.
    when {&BOOKCALCULATIONTYPE-FULLYEARTEMPORIS} /* NextPostingDate to Set = the last date of the month of the starting date if the asset is not yet depreciated */
    then  do viCounter = ((year(itFAAssetBookNextPostingDate) * 12) + month(itFAAssetBookNextPostingDate)) to ((iiDepreciationYear * 12) + iiDepreciationPeriod):
        if viCounter = ((year(itFAAssetBookNextPostingDate) * 12) + month(itFAAssetBookNextPostingDate)) and
                         year(itFAAssetBookNextPostingDate) = year(itFAAssetBookStartDate)
        then do:
            do viCounterStart = 1 to 12:
                create tNewDepreciation.
                assign tNewDepreciation.tdNewDeprAmountLC = maximum(((idFAAssetBookCapitalAmountLC - idFAAssetBookDisposalAmountLC + idFAAssetBookDisposalDepAmountLC - <M-7 GetCumulDeprAmountLC () in BFixedAssetDepreciation>) * idFactor / iiFAAssetBookLifeCycle), if viCounter = ((year(itFAAssetBookStartDate) * 12) + month(itFAAssetBookStartDate)) then vdNewDeprSL1StartAmountLC else vdNewDeprSL1AmountLC)
                       vdNewDeprStartAmountLC = vdNewDeprStartAmountLC + tNewDepreciation.tdNewDeprAmountLC.
            end.
        
            assign vdNewDeprStartAmountLC = vdNewDeprStartAmountLC / (12 - month(itFAAssetBookStartDate) + 1).
            
            empty temp-table tNewDepreciation.
        end.

        create tNewDepreciation.
        assign tNewDepreciation.tiNewDeprYear     = integer(truncate(viCounter / 12,0)) - (if viCounter mod 12 = 0 then 1 else 0)
               tNewDepreciation.tiNewDeprMonth    = if viCounter mod 12 = 0 then 12 else viCounter mod 12
               tNewDepreciation.tdNewDeprAmountLC = if tNewDepreciation.tiNewDeprYear = year(itFAAssetBookStartDate)
                                                    then vdNewDeprStartAmountLC
                                                    else maximum(((idFAAssetBookCapitalAmountLC - idFAAssetBookDisposalAmountLC + idFAAssetBookDisposalDepAmountLC - idFAAssetBookDeprecAmountLC - <M-6 GetCumulDeprAmountLC () in BFixedAssetDepreciation>) * idFactor / iiFAAssetBookLifeCycle), if viCounter = ((year(itFAAssetBookStartDate) * 12) + month(itFAAssetBookStartDate)) then vdNewDeprSL1StartAmountLC else vdNewDeprSL1AmountLC).

        if tNewDepreciation.tdNewDeprAmountLC <= 0
        then return.                                                                     
    end.
    when {&BOOKCALCULATIONTYPE-TEMPORISDAILY}
    then do:
        if iiFAAssetBookPeriodsDepreciated = 0
        then do viCounter = ((year(itFAAssetBookStartDate) * 12) + month(itFAAssetBookStartDate)) to ((iiDepreciationYear * 12) + iiDepreciationPeriod):
            create tNewDepreciation.
            assign tNewDepreciation.tiNewDeprYear     = integer(truncate(viCounter / 12,0)) - (if viCounter mod 12 = 0 then 1 else 0)
                   tNewDepreciation.tiNewDeprMonth    = if viCounter mod 12 = 0 then 12 else viCounter mod 12.
                   
            if viCounter = ((year(itFAAssetBookStartDate) * 12) + month(itFAAssetBookStartDate))
            then assign tNewDepreciation.tdNewDeprAmountLC = maximum((((idFAAssetBookCapitalAmountLC - idFAAssetBookDisposalAmountLC + idFAAssetBookDisposalDepAmountLC - idFAAssetBookDeprecAmountLC - <M-10 GetCumulDeprAmountLC () in BFixedAssetDepreciation>) * idFactor / iiFAAssetBookLifeCycle) /
                                                                    (<M-11 GetTotalDaysOfMonth (input  itFAAssetBookStartDate (itDate)) in BFixedAssetDepreciation>) * ((<M-12 GetTotalDaysOfMonth (input  itFAAssetBookStartDate (itDate)) in BFixedAssetDepreciation>) - day(itFAAssetBookStartDate) + 1)), if viCounter = ((year(itFAAssetBookStartDate) * 12) + month(itFAAssetBookStartDate)) then vdNewDeprSL1StartAmountLC else vdNewDeprSL1AmountLC).
            else assign tNewDepreciation.tdNewDeprAmountLC = maximum(((idFAAssetBookCapitalAmountLC - idFAAssetBookDisposalAmountLC + idFAAssetBookDisposalDepAmountLC - idFAAssetBookDeprecAmountLC - <M-13 GetCumulDeprAmountLC () in BFixedAssetDepreciation>) * idFactor / iiFAAssetBookLifeCycle), if viCounter = ((year(itFAAssetBookStartDate) * 12) + month(itFAAssetBookStartDate)) then vdNewDeprSL1StartAmountLC else vdNewDeprSL1AmountLC).
        end.
        else if iiFAAssetBookPeriodsDepreciated <> 0
        then do viCounter = ((year(itFAAssetBookNextPostingDate) * 12) + month(itFAAssetBookNextPostingDate)) to ((iiDepreciationYear * 12) + iiDepreciationPeriod):
            create tNewDepreciation.
            assign tNewDepreciation.tiNewDeprYear     = integer(truncate(viCounter / 12,0)) - (if viCounter mod 12 = 0 then 1 else 0)
                   tNewDepreciation.tiNewDeprMonth    = if viCounter mod 12 = 0 then 12 else viCounter mod 12
                   tNewDepreciation.tdNewDeprAmountLC = maximum(((idFAAssetBookCapitalAmountLC - idFAAssetBookDisposalAmountLC + idFAAssetBookDisposalDepAmountLC - idFAAssetBookDeprecAmountLC - <M-14 GetCumulDeprAmountLC () in BFixedAssetDepreciation>) * idFactor / iiFAAssetBookLifeCycle), if viCounter = ((year(itFAAssetBookStartDate) * 12) + month(itFAAssetBookStartDate)) then vdNewDeprSL1StartAmountLC else vdNewDeprSL1AmountLC).
                   
            if tNewDepreciation.tdNewDeprAmountLC <= 0
            then return.                                                                     
        end.    
    end.                                                
end.