project QadFinancials > class BFixedAssetDepreciation > method DepreciationApply

Description

Method run on Apply button select


Parameters


icFABookTypeCodeinputcharacter
iiFADepreciationYearinputinteger
iiFADepreciationPeriodinputinteger
icFAAssetTypeCodeinputcharacter
icFAAssetCodeinputcharacter
iiPeriodYearinputinteger
iiPeriodPeriodinputinteger
icPostingTextinputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program1/bfixedassetdepreciation.p)

<M-25 run DepreciationClear (output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>

if icFABookTypeCode <> '':U
then do:
    <Q-1 run FABookTypeByIDCodeActOff (all) (Read) (NoCache)
          (input viCompanyId, (CompanyId)
           input ?, (FABookTypeID)
           input icFABookTypeCode, (FABookTypeCode)
           input ?, (FABookTypeIsActive)
           input ?, (FABookTypeIsOfficial)
           output dataset tqFABookTypeByIDCodeActOff) in BFixedAssetBookType >
    find first tqFABookTypeByIDCodeActOff where
               tqFABookTypeByIDCodeActOff.tcFABookTypeCode = icFABookTypeCode
               no-error.
end.

if (available tqFABookTypeByIDCodeActOff and
    not tqFABookTypeByIDCodeActOff.tlFABookTypeIsActive) or
   icFABookTypeCode = '':U
then do:
    /* Valid, active book type */
    assign vcMessage = if icFABookTypeCode = '':U 
                       then trim(#T-26'The Book Type field requires an active and valid book type.':255(14366)T-26#)
                       else trim(substitute(#T-18'The Book Type field requires an active and valid book type (book type: &1).':255(2009)T-18#, trim(icFABookTypeCode))).
    <M-2 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-2915':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
    assign oiReturnStatus = -1.
end.

if iiFADepreciationYear = 0 or
   iiFADepreciationYear = ? or
   iiFADepreciationPeriod = 0 or
   iiFADepreciationPeriod = ?
then do:
    /* Depreciation Year and Depreciation Period has to be filled-in */
    assign vcMessage = trim(substitute(#T-19'You must enter a depreciation year and depreciation period (book type: &1, asset type: &2, asset code: &3).':255(2010)t-19#, trim(icFABookTypeCode), trim(icFAAssetTypeCode), trim(icFAAssetCode))).
    <M-3 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-2917':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
    assign oiReturnStatus = -1.
end.
else do:
    if iiFADepreciationYear <> 0 and
       iiFADepreciationYear <> ? 
    then do:        
        if iiFADepreciationYear < integer({&DEPRECIATIONPERIOD-YEARMIN}) or 
           iiFADepreciationYear > integer({&DEPRECIATIONPERIOD-YEARMAX})
        then do:
            /* Depreciation Year has to be in between 1950 and 2050 */            
            assign vcMessage = trim(substitute(#T-20'The depreciation year should be between &1 and &2 (book type: &3, asset type: &4, asset code: &5).':255(2011)T-20#, {&DEPRECIATIONPERIOD-YEARMIN}, {&DEPRECIATIONPERIOD-YEARMAX}, trim(icFABookTypeCode), trim(icFAAssetTypeCode), trim(icFAAssetCode))).
            <M-4 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-2918':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
            assign oiReturnStatus = -1.
        end.   
    end.
    if iiFADepreciationPeriod <> 0 and
       iiFADepreciationPeriod <> ? 
    then do:        
        if iiFADepreciationPeriod < integer({&DEPRECIATIONPERIOD-PERIODMIN}) or 
           iiFADepreciationPeriod > integer({&DEPRECIATIONPERIOD-PERIODMAX})
        then do:
            /* Depreciation Period has to be in between 1 and 12 */
            assign vcMessage = trim(substitute(#T-21'The depreciation period should be between &1 and &2 (book type: &3, asset type: &4, asset code: &5).':255(2012)T-21#, {&DEPRECIATIONPERIOD-PERIODMIN}, {&DEPRECIATIONPERIOD-PERIODMAX}, trim(icFABookTypeCode), trim(icFAAssetTypeCode), trim(icFAAssetCode))).
            <M-5 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-2919':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
            assign oiReturnStatus = -1.
        end.   
    end.
end.    


/* Asset Code, if filled-in, has to be an active asset code */
if icFAAssetCode <> '':U and
   icFAAssetCode <> '?':U and
   icFAAssetCode <> ?
then do:
    <Q-10 run FAAssetByAssetCodeId (all) (Read) (NoCache)
          (input viCompanyId, (CompanyId)
           input icFAAssetCode, (FAAssetCode)
           input ?, (FAAssetId)
           output dataset tqFAAssetByAssetCodeId) in BFixedAssetAsset >
    find first tqFAAssetByAssetCodeId where
               tqFAAssetByAssetCodeId.tcFAAssetCode = icFAAssetCode
               no-error.
/* THERE'S NO ACTIVITY FLAG FOR THE MOMENT ON ASSET    
    if available tqAssetByAssetCodeId and
       not tqAssetByAssetCodeId.tlFAAsset..........
    then do:
        assign vcMessage = trim(substitute('Asset Code should be filled with an active, valid asset code. (Asset Code: &1)':L256, trim(icFAAssetCode))).
        <M-11 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-2916':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
        assign oiReturnStatus = -1.
    end.
*/    
end.

/* Asset Type, if filled-in, has to be an active asset type */
if icFAAssetTypeCode <> '':U and
   icFAAssetTypeCode <> '?':U and
   icFAAssetTypeCode <> ?
then do:
    <Q-6 run FAAssetTypeByIDCodeActive (all) (Read) (NoCache)
          (input viCompanyId, (CompanyId)
           input icFAAssetTypeCode, (FAAssetTypeCode)
           input ?, (FAAssetTypeID)
           input ?, (FAAssetTypeIsActive)
           output dataset tqFAAssetTypeByIDCodeActive) in BFixedAssetAssetType >
    find first tqFAAssetTypeByIDCodeActive where
               tqFAAssetTypeByIDCodeActive.tcFAAssetTypeCode = icFAAssetTypeCode
               no-error.
    if available tqFAAssetTypeByIDCodeActive and
       not tqFAAssetTypeByIDCodeActive.tlFAAssetTypeIsActive
    then do:
        assign vcMessage = trim(substitute(#T-22'The Asset Type field requires an active and valid asset type (asset type: &1).':255(2013)T-22#, trim(icFAAssetTypeCode))).
        <M-7 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-2920':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
        assign oiReturnStatus = -1.
    end.
    
    /* Asset Code has to be of the passed Asset Type */
    if icFAAssetCode <> '':U and
       icFAAssetCode <> '?':U and
       icFAAssetCode <> ?
    then do:
        if available tqFAAssetByAssetCodeId 
        then do:
            if tqFAAssetByAssetCodeId.tcFAAssetTypeCode <> icFAAssetTypeCode
            then do:
                assign vcMessage = trim(substitute(#T-23'The depreciated asset must be of the asset type you want to depreciate (asset code: &1, asset type: &2).':255(2014)T-23#, trim(icFAAssetCode), trim(icFAAssetTypeCode))).
                <M-12 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-2921':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
                assign oiReturnStatus = -1.
            end.
            
            /* Asset Type / Asset Code has be in line with the selected book type */
            <Q-17 assign vlFcQueryRecordsAvailable = FAAssetBookByAssetCodeType (NoCache)  (input viCompanyId, (CompanyId) 
                                                                     input icFAAssetTypeCode, (FAAssetTypeCode) 
                                                                     input icFAAssetCode, (FAAssetCode) 
                                                                     input icFABookTypeCode, (FABookTypeCode)) in BFixedAssetAsset >
                                          
            if not vlFcQueryRecordsAvailable                       
            then do:
                assign vcMessage = trim(substitute(#T-24'This combination of asset code and asset type is not valid for this book type (asset code: &1, asset type: &2, book type: &3).':255(2015)T-24#, trim(icFAAssetCode), trim(icFAAssetTypeCode), trim(icFABookTypeCode))).
                <M-15 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-2922':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
                assign oiReturnStatus = -1.
            end.
        end.    
    end.
end.

if oiReturnStatus < 0 
then return.

/* Execute Depreciation */
<M-16 run DepreciationMain (input  icFABookTypeCode (icFABookTypeCode), 
                            input  iiFADepreciationYear (iiFADepreciationYear), 
                            input  iiFADepreciationPeriod (iiFADepreciationPeriod), 
                            input  icFAAssetTypeCode (icFAAssetTypeCode), 
                            input  icFAAssetCode (icFAAssetCode), 
                            input  iiPeriodYear (iiPeriodYear), 
                            input  iiPeriodPeriod (iiPeriodPeriod), 
                            input  icPostingText (icPostingText), 
                            output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
assign oiReturnStatus = if (oiReturnStatus  > 0 and 
                            viFcReturnSuper = 0) or 
                            oiReturnStatus  < 0
                        then oiReturnStatus
                        else viFcReturnSuper.