project QadFinancials > class BDivision > 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/bdivision.p)

/*
* It is not possible to change the Division Code value on the account
* as this is a key value that is used in MFG/PRO, the financials
* can handle these changes as they use the Division_ID for foreign key
* relationships but it will cause major data integrity problems 
* within MFG/PRO if this data is allowed to change.
*/ 

for each t_sDivision where 
         t_sDivision.tc_Status <> "D":U  and
        (t_sDivision.DivisionCode <> ?  and
         t_sDivision.DivisionCode <> "":U):
    assign t_sDivision.DivisionCode = trim(t_sDivision.DivisionCode).
end.
                                             
for each t_sDivision where t_sDivision.tc_status = "C":U:

    <Q-3 assign vlFcQueryRecordsAvailable = DivisionCodeChangedByID (NoCache)
       (input '', (CompanyId)
        input t_sDivision.Division_ID, (DivisionID)
        input t_sDivision.DivisionCode, (DivisionCode)) in BDivision >

    /*
    * If the query returned a record then we know that the key
    * field value must have been changed and as this is not allowed
    * we raise an error and return a validation error code.
    */
    if vlFcQueryRecordsAvailable <> false then do:
      
        assign
            vcMessageText  = #T-5'Cannot change key field value.':50(17933)T-5#
            oiReturnStatus = -1.
            
        <M-4 run SetMessage
           (input  vcMessageText (icMessage), 
            input  '' (icArguments), 
            input  'DivisionCode':U (icFieldName), 
            input  t_sDivision.DivisionCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sDivision.tc_Rowid (icRowid), 
            input  'QadFin-4973':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDivision>
       return.
   end. /* Key Field Value Changed */
   /* calculated fields empty, id values still exists in excel integeration. 
    * shuould remove it.*/
    if vcActivityCode = "ExcelIntegration":U then
    do:
        if t_sDivision.tcBudgetGroupCode = "":U or t_sDivision.tcBudgetGroupCode = ? then
            assign t_sDivision.BudgetGroup_ID = 0.
        if t_sDivision.DivisionDescription = ? then assign t_sDivision.DivisionDescription = "":U.
    end.
end. /* each Changed t_sDivision */

/* Validation on COA Mask Code */
<M-12 run ValidateComponentPreCOAMask  (output viFcReturnSuper (oiReturnStatus)) in BDivision>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus >= 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.

<ANCESTOR-CODE>

/* check if the code is used in an FDS of a budget  */
/* execute this check only when the code is changed */
for each t_sDivision where 
         t_sDivision.tc_Status = "C":U,
    each t_iDivision where
         t_iDivision.tc_Rowid  = t_sDivision.tc_Rowid:


    if t_iDivision.DivisionCode   <> t_sDivision.DivisionCode or 
       t_iDivision.BudgetGroup_ID <> t_sDivision.BudgetGroup_ID
    then do:
        assign vhFcComponent = ?.
        <M-2 run CheckBudgetFDSWBS
           (input  {&BUDGETFDSTYPE-DIVISION} (icFDSType), 
            input  t_sDivision.BudgetGroup_ID (iiNewFDSID), 
            input  t_sDivision.DivisionCode (icNewFDSCode), 
            input  t_iDivision.BudgetGroup_ID (iiOldFDSID), 
            input  t_iDivision.DivisionCode (icOldFDSCode), 
            output viFcReturnSuper (oiReturnStatus)) in BBudget>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus >= 0)
        then assign oiReturnStatus = viFcReturnSuper.
    end.

    /* Active flag  FIN-1706   Temporar workaround ============================= *
     * Active flag cannot be changed, if there is any posting in transient layer *
     * This is just workaround to ensure, once this posting is transferred from  *
     * transient layer into official one, GL account stays active. Today during  *
     * this transfer, no validation for active account is executed. Therefore we *
     * prevent user to change Activity flag in this case                         *
     * ========================================================================= */
    if t_sDivision.DivisionIsActive <> t_iDivision.DivisionIsActive and
       t_sDivision.DivisionIsActive <> true
    then do:
        <Q-14 assign vlFcQueryRecordsAvailable = PostingLineByLayerTypeGLDivCCPrj (NoCache)
           (input ?, (CompanyId)
            input {&LAYERTYPECODE-TRANSIENT}, (LayerTypes)
            input ?, (GLId)
            input t_sDivision.Division_ID, (DivisionId)
            input ?, (CostCentreId)
            input ?, (ProjectId)) in BPosting >
         
        if vlFcQueryRecordsAvailable <> false
        then do:
            assign vcMessage = #T-13'Sub-Account &1 cannot be deactivated, until there are pending postings in Transient layer which can be transferred into Official layer.':255(413920423)T-13#
                   vcMessage = substitute(vcMessage, t_sDivision.DivisionCode).
            
            <M-15 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tDivision.DivisionIsActive':U (icFieldName), 
                input  string(t_sDivision.DivisionIsActive) (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sDivision.tc_Rowid (icRowid), 
                input  'QadFin-9486':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BDivision>
            assign oiReturnStatus = -1.
        end.
    end.  /* t_sDivision.DivisionIsActive <> t_iDivision.DivisionIsActive and */
end.
if oiReturnStatus < 0 then return.