project QadFinancials > class BFixedAssetDepreciation > method ValidateComponent

Description

Write here all tests on database update (new / modify / delete) that cannot be coded with a validation mask.
The type of update can be found in tc_status (N/C/D).
If you find incorrect data, you must write an entry in tFcMessages (using SetMessage) and set the return status of this method to either +1 or -1.
Return status +1 = data will still be accepted.
Return status -1 = data will not be accepted.
This method is run from SetPublicTables, before transferring the received data into the class temp-tables.


Parameters


oiReturnStatusoutputinteger


Internal usage


unused


program code (program/bfixedassetdepreciation.p)

<M-21 run StopExternalInstances
   (output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
if viFcReturnSuper < 0 or
   oiReturnStatus  = 0
then assign oiReturnStatus = viFcReturnSuper.

if oiReturnStatus < 0
then return.

/*
/* Convert Saf Code + Saf Concept Code to Saf ID */
<Q-1 run SafPrim (Start) in BSaf >

for each t_sFADepreciationDetSaf:
    if t_sFADepreciationDetSaf.tcSafCode <> "":U
    then do:
        <Q-2 run SafPrim (all) (Read) (Cache)
          (input ?, (SafID)
           input t_sFADepreciationDetSaf.tcSafCode, (SafCode)
           input ?, (SafConceptCode)
           output dataset tqSafPrim) in BSaf >
        find first tqSafPrim where
                   tqSafPrim.tcSafCode        = t_sFADepreciationDetSaf.tcSafCode and
                   tqSafPrim.tcSafConceptCode = t_sFADepreciationDetSaf.tcSafConceptCode
                   no-error.
        if not available tqSafPrim
        then find first tqSafPrim where
                        tqSafPrim.tcSafCode = t_sFADepreciationDetSaf.tcSafCode
                        no-error.
        assign t_sFADepreciationDetSaf.Saf_ID = if available tqSafPrim
                                                then tqSafPrim.tiSaf_ID
                                                else -1.
    end.
end.

<Q-3 run SafPrim (Stop) in BSaf >
*/

Depreciation_block:
for each t_sFADepreciation
         break by t_sFADepreciation.FAAssetBook_ID:
    
    if first-of(t_sFADepreciation.FAAssetBook_ID)
    then do:
        <Q-5 run FAAssetByAssetBookCodeId (all) (Read) (NoCache)
          (input t_sFADepreciation.Company_ID, (CompanyId)
           input t_sFADepreciation.FAAssetBook_ID, (FAAssetBookId)
           input ?, (FAAssetBookCode)
           output dataset tqFAAssetByAssetBookCodeId) in BFixedAssetAsset >
    end.    

    /* No verification needed */
    if t_sFADepreciation.tc_Status = '':U and
       not can-find(first t_sFADepreciationDet where
                          t_sFADepreciationDet.tc_ParentRowid = t_sFADepreciation.tc_Rowid and
                          t_sFADepreciationDet.tc_Status <> '':U) and
       not can-find(first t_sFADepreciationDetSaf where
                          t_sFADepreciationDetSaf.tc_ParentRowid = t_sFADepreciation.tc_Rowid and
                          t_sFADepreciationDetSaf.tc_Status <> '':U)
    then next.

    find first tqFAAssetByAssetBookCodeId no-error.        
    if available tqFAAssetByAssetBookCodeId
    then do:
        if t_sFADepreciation.tc_Status = 'D':U
        then do:
            /* Depreciations cannot be deleted */
            assign vcMessage = trim(substitute(#T-14'You cannot delete depreciation records (asset: &1).':255(2029)t-14#, trim(tqFAAssetByAssetBookCodeId.tcFAAssetCode))).
            <M-7 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  t_sFADepreciation.tc_Rowid (icRowid),
                     input  'QADFIN-2908':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
            assign oiReturnStatus = -1.
            next.
        end.

        else if t_sFADepreciation.tc_Status <> '':U
        then do:
            /* Not Capitalized assets cannot be depreciated */
            if not tqFAAssetByAssetBookCodeId.tlFAAssetIsCapitalized
            then do:
                assign vcMessage = trim(substitute(#T-15'An asset can only be depreciated if it is capitalized (asset: &1).':255(2030)T-15#, trim(tqFAAssetByAssetBookCodeId.tcFAAssetCode))).
                <M-6 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  t_sFADepreciation.tc_Rowid (icRowid),
                     input  'QADFIN-2907':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
                assign oiReturnStatus = -1.
            end.    
            
            /* If the Asset Book is not With the Depreciations, then no depreciations can be done on such Asset Book */
            if not tqFAAssetByAssetBookCodeId.tlFAAssetBookIsWithDepr
            then do:
                assign vcMessage = trim(substitute(#T-16'An asset can only be depreciated if the asset book is marked for depreciation (asset: &1, asset book: &2).':255(2031)T-16#, trim(tqFAAssetByAssetBookCodeId.tcFAAssetCode), trim(tqFAAssetByAssetBookCodeId.tcFAAssetBookCode))).
                <M-8 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  t_sFADepreciation.tc_Rowid (icRowid),
                     input  'QADFIN-2909':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
                assign oiReturnStatus = -1.
            end.
            
            /* If the Asset Book is already disposed, then no depreciations can be done on such Asset Book */
            if tqFAAssetByAssetBookCodeId.tlFAAssetBookIsDisposed
            then do:
                assign vcMessage = trim(substitute(#T-17'An asset can only be depreciated if the asset book is not yet disposed (asset: &1, asset book: &2).':255(2032)T-17#, trim(tqFAAssetByAssetBookCodeId.tcFAAssetCode), trim(tqFAAssetByAssetBookCodeId.tcFAAssetBookCode))).
                <M-9 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  t_sFADepreciation.tc_Rowid (icRowid),
                     input  'QADFIN-2910':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
                assign oiReturnStatus = -1.
            end.
            
            /* There is nothing to depreciate on this investment */
            if tqFAAssetByAssetBookCodeId.tdFAAssetBookAmountLC - tqFAAssetByAssetBookCodeId.tdFAAssetBookDeprAmountLC - tqFAAssetByAssetBookCodeId.tdFAAssetBookSalvageAmountLC <=0
            then do:
                assign vcMessage = trim(substitute(#T-18'The net book value is lower than the salvage value: unable to execute depreciations for this asset (asset: &1, asset book: &2).':255(2033)T-18#, trim(tqFAAssetByAssetBookCodeId.tcFAAssetCode), trim(tqFAAssetByAssetBookCodeId.tcFAAssetBookCode))).
                <M-12 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  t_sFADepreciation.tc_Rowid (icRowid),
                     input  'QADFIN-2934':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
                assign oiReturnStatus = -1.
            end.
        end.    
    end.

    for each t_sFADepreciationDet where
             t_sFADepreciationDet.tc_ParentRowid = t_sFADepreciation.tc_Rowid:
        if t_sFADepreciationDet.tc_Status = 'D':U
        then do:
            /* Depreciation Detail records cannot be deleted */
            assign vcMessage = trim(substitute(#T-19'You cannot delete depreciation detail records (asset: &1).':255(2034)t-19#, trim(tqFAAssetByAssetBookCodeId.tcFAAssetCode))).
            <M-10 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  t_sFADepreciation.tc_Rowid (icRowid),
                     input  'QADFIN-2911':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
            assign oiReturnStatus = -1.
            next Depreciation_block.
        end.
    end.
    
    for each t_sFADepreciationDetSaf where
             t_sFADepreciationDetSaf.tc_ParentRowid = t_sFADepreciation.tc_Rowid:
        if t_sFADepreciationDetSaf.tc_Status = 'D':U
        then do:
            /* Depreciation Detail Saf records cannot be deleted */
            assign vcMessage = trim(substitute(#T-20'You cannot delete depreciation detail SAF records (asset: &1).':255(2035)t-20#, trim(tqFAAssetByAssetBookCodeId.tcFAAssetCode))).
            <M-11 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  t_sFADepreciation.tc_Rowid (icRowid),
                     input  'QADFIN-2912':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
            assign oiReturnStatus = -1.
            next Depreciation_block.
        end.
    end.
end.
    
<ANCESTOR-CODE>

<M-4 run PostValidateComponent (output viFcReturnSuper (oiReturnStatus)) in BFixedAssetDepreciation>
assign oiReturnStatus = if (oiReturnStatus  > 0 and 
                            viFcReturnSuper = 0) or 
                            oiReturnStatus  < 0
                        then oiReturnStatus
                        else viFcReturnSuper.