project QadFinancials > class BRoundingMethod > 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/broundingmethod.p)

<ANCESTOR-CODE>

assign viLocalReturnStatus = oiReturnStatus
       oiReturnStatus      = -98.

<M-23 run StopExternalInstances
   (output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>
                      
for each t_sRoundingMethod where
         t_sRoundingMethod.tc_Status <> 'D':U:
         
    /* ============================================================== */                                                                  
    /* Error: Rounding Unit can not exceed 9,999.999                  */
    /* ============================================================== */
    if t_sRoundingMethod.RoundingMethodUnit > 9999.999
    then do:
        assign vcMessage           = trim(#T-1'The rounding unit cannot exceed 9,999.999.':100(48988)t-1#)
               viLocalReturnStatus = -1. 
        <M-2 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tRoundingMethod.RoundingMethodUnit':U (icFieldName), 
            input  string(t_sRoundingMethod.RoundingMethodUnit) (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sRoundingMethod.tc_Rowid (icRowid), 
            input  'QadFin-5195':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>               
    end. /* if t_sRoundingMethod.RoundingMethodUnit > 9999.9999 */
    
    /* ============================================================== */                                                                    
    /* Error: Rounding Unit can not have more than three decimals     */
    /* ============================================================== */
    if t_sRoundingMethod.RoundingMethodUnit - trunc(t_sRoundingMethod.RoundingMethodUnit, 3) <> 0
    then do:
        assign vcMessage           = trim(#T-5'The rounding threshold cannot have more than 3 decimals.':100(48990)t-5#)
               viLocalReturnStatus = -1.
        <M-6 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tRoundingMethod.RoundingMethodUnit':U (icFieldName), 
            input  string(t_sRoundingMethod.RoundingMethodUnit) (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sRoundingMethod.tc_Rowid (icRowid), 
            input  'QadFin-5198':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>                         
    end. /* if t_sRoundingMethod.RoundingMethodUnit - trunc(t_sRoundingMethod.RoundingMethodUnit, 3) <> 0 */
        
    /* ============================================================== */                                                                    
    /* Error: Rounding Unit must be a positive number                 */
    /* ============================================================== */
    if t_sRoundingMethod.RoundingMethodUnit < 0
    then do:
        assign vcMessage           = trim(#T-9'The rounding unit must be a positive number.':100(48992)t-9#)
               viLocalReturnStatus = -1.
        <M-10 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tRoundingMethod.RoundingMethodUnit':U (icFieldName), 
            input  string(t_sRoundingMethod.RoundingMethodUnit) (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sRoundingMethod.tc_Rowid (icRowid), 
            input  'QadFin-5211':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>                         
    end. /* if t_sRoundingMethod.RoundingMethodUnit < 0 */
    
    /* ============================================================== */
    /* Error: Rounding Threshold can not exceed 9,999.9999            */
    /* ============================================================== */
    if t_sRoundingMethod.RoundingMethodThreshold > 9999.9999
    then do:
        assign vcMessage           = trim(#T-4'The rounding threshold cannot exceed 9,999.9999.':100(48989)t-4#)
               viLocalReturnStatus = -1.
        <M-3 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tRoundingMethod.RoundingMethodThreshold':U (icFieldName), 
            input  string(t_sRoundingMethod.RoundingMethodThreshold) (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sRoundingMethod.tc_Rowid (icRowid), 
            input  'QadFin-5196':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>                   
    end. /* if t_sRoundingMethod.RoundingMethodThreshold > 9999.9999 */
    
    /* ============================================================== */
    /* Error: Rounding Threshold can not have more than four decimals */
    /* ============================================================== */
    if t_sRoundingMethod.RoundingMethodThreshold - trunc(t_sRoundingMethod.RoundingMethodThreshold, 4) <> 0
    then do:
        assign vcMessage           = trim(#T-7'The rounding threshold cannot have more than 4 decimals.':100(48991)t-7#)
               viLocalReturnStatus = -1.
        <M-8 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tRoundingMethod.RoundingMethodThreshold':U (icFieldName), 
            input  string(t_sRoundingMethod.RoundingMethodThreshold) (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sRoundingMethod.tc_Rowid (icRowid), 
            input  'QadFin-5199':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>               
    end. /* if t_sRoundingMethod.RoundingMethodThreshold - trunc(t_sRoundingMethod.RoundingMethodThreshold, 4) <> 0 */
    
    /* ============================================================== */                                                                    
    /* Error: Rounding Threshold must be a positive number            */
    /* ============================================================== */
    if t_sRoundingMethod.RoundingMethodThreshold < 0
    then do:
        assign vcMessage           = trim(#T-12'The rounding threshold must be a positive number.':100(48993)t-12#)
               viLocalReturnStatus = -1.
        <M-11 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tRoundingMethod.RoundingMethodThreshold':U (icFieldName), 
            input  string(t_sRoundingMethod.RoundingMethodThreshold) (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sRoundingMethod.tc_Rowid (icRowid), 
            input  'QadFin-5212':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>
    end. /* if t_sRoundingMethod.RoundingMethodThreshold < 0 */                     
                         
    /* ============================================================== */                                                                    
    /* Error: The Rounding Threshold can not exceed the Rounding Unit */
    /* ============================================================== */
    if t_sRoundingMethod.RoundingMethodThreshold > t_sRoundingMethod.RoundingMethodUnit
    then do:
        assign vcMessage           = trim(substitute(#T-13'The Rounding Threshold (&1) cannot exceed the Rounding Unit (&2).':100(48994)T-13#, trim(string(t_sRoundingMethod.RoundingMethodThreshold)), trim(string(t_sRoundingMethod.RoundingMethodUnit)) ))
               viLocalReturnStatus = -1.
        <M-14 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tRoundingMethod.RoundingMethodThreshold':U (icFieldName), 
            input  string(t_sRoundingMethod.RoundingMethodThreshold) (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sRoundingMethod.tc_Rowid (icRowid), 
            input  'QadFin-5213':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>        
    end. /* if t_sRoundingMethod.RoundingMethodThreshold > t_sRoundingMethod.RoundingMethodUnit */
    
    /* ============================================================== */                                                                    
    /* Error: Rounding Code can not be updated                        */
    /* Warning: Unit & Treshold changed when method already used      */
    /* ============================================================== */
    if t_sRoundingMethod.tc_Status = 'C':U
    then do:
        find t_iRoundingMethod where
             t_iRoundingMethod.tc_Rowid = t_sRoundingMethod.tc_Rowid
             no-lock no-error.
        if available t_iRoundingMethod and
           t_sRoundingMethod.RoundingMethodCode <> t_iRoundingMethod.RoundingMethodCode
        then do:
            assign vcMessage           = trim(#T-15'The rounding method code cannot be updated.':100(48995)T-15#) + chr(10) +
                                         trim(substitute(#T-16'The previous code was &1. The new code is &2.':100(48996)t-16#, t_iRoundingMethod.RoundingMethodCode, t_sRoundingMethod.RoundingMethodCode))
                   viLocalReturnStatus = -1.
            <M-17 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tRoundingMethod.RoundingMethodCode':U (icFieldName), 
                input  t_sRoundingMethod.RoundingMethodCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sRoundingMethod.tc_Rowid (icRowid), 
                input  'QadFin-5214':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>                   
        end. /* if available t_iRoundingMethod and ... */
        
        if available t_iRoundingMethod and
           (t_iRoundingMethod.RoundingMethodUnit      <> t_sRoundingMethod.RoundingMethodUnit or
            t_iRoundingMethod.RoundingMethodThreshold <> t_sRoundingMethod.RoundingMethodThreshold)
        then do:
            <Q-18 assign vlFcQueryRecordsAvailable = CurrencyByCurrRoundingMethod (NoCache)
               (input 0, (CurrencyID)
                input '':U, (CurrencyCode)
                input t_sRoundingMethod.RoundingMethodCode, (RoundingMethodCode)) in BCurrency >
            if vlFcQueryRecordsAvailable <> false
            then do:
                assign vcMessage           = trim(#T-19'This rounding method is already linked to a currency.':100(49011)T-19#) + chr(10) +
                                             trim(#T-20'The rounding logic for existing amounts differs from the rounding logic for future amounts.':100(49012)t-20#).
                       if viLocalReturnStatus >= 0
                       then assign viLocalReturnStatus = 1.
                <M-21 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tRoundingMethod.RoundingMethodUnit':U (icFieldName), 
                    input  t_sRoundingMethod.RoundingMethodUnit (icFieldValue), 
                    input  'W':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sRoundingMethod.tc_Rowid (icRowid), 
                    input  'QadFin-5221':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>                                              
            end. /* if vlFcQueryRecordsAvailable <> false */
        end. /* Unit or Threshold changed */            
    end. /* if t_sRoundingMethod.tc_Status = 'C':U */    
end. /* for each t_sRoundingMethod where ... */

assign oiReturnStatus = viLocalReturnStatus.