project QadFinancials > class BBankNumber > method ValidateComponentIsDefault

Description

Validates the Default flag in the set of Bank Number records for a Creditor, Debtor etc:
a) only one can be default
b) at least one must be default
Note: work with t_s buffer


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankNumber.ValidateComponentBeforeAncestor


program code (program1/bbanknumber.p)

define buffer b_sBankNumber for t_sBankNumber.
    
    /* Calculate number of default bank numbers to one Parent Object which are already in instance of component */
    assign viCount = 0.
    for each b_sBankNumber where
             b_sBankNumber.CompanySharedSet_ID  = t_sBankNumber.CompanySharedSet_ID  and
             b_sBankNumber.ParentObject_ID      = t_sBankNumber.ParentObject_ID      and
             b_sBankNumber.BankNumberParentType = t_sBankNumber.BankNumberParentType and
             b_sBankNumber.tcCompanyCode        = t_sBankNumber.tcCompanyCode        and
             b_sBankNumber.BankNumberIsDefault  = true                               and
             b_sBankNumber.tc_Status           <> "D":U:
        assign viCount = viCount + 1.
    end. /* for each b_sBankNumber where */
   
    /* Look also into database, there can be also other bank numbers, which are linked to the same parent object */
    if viCount <=1
    then do:
        /* if bank number type is gl then company shared set is available*/
        if t_sBankNumber.BankNumberParentType = {&BANKNUMBERPARENTTYPE-GL} 
        then do:
            <Q-12 run BankNumberByParentID (all) (Read) (NoCache)
               (input t_sBankNumber.ParentObject_ID, (ParentObjectId)
                input t_sBankNumber.BankNumberParentType, (BankNumberParentType)
                input true, (BankNumberIsDefault)
                input ?, (CompanyId)
                output dataset tqBankNumberByParentID) in BBankNumber >

            /* error: only one Bank Number can be default (check on DB level needed 
            as we work with Ref table e.g. in UpdateBankNumber method and 
            in that case UI returns only those Ref records that were created, modified or deleted and
            unchanged records are not known here then) */        
            for each tqBankNumberByParentID where 
                     tqBankNumberByParentID.tiCompanySharedSet_ID  = t_sBankNumber.CompanySharedSet_ID and
                     tqBankNumberByParentID.tiParentObject_ID      = t_sBankNumber.ParentObject_ID     and
                     tqBankNumberByParentID.tcBankNumberParentType = t_sBankNumber.BankNumberParentType:
        
                /*check whether there is another tq record that is Default, 
                  is not in the buffer b_s and the b_s already contains one Default bank Number*/
                find first b_sBankNumber where 
                           b_sBankNumber.BankNumber_ID = tqBankNumberByParentID.tiBankNumber_ID and
                           b_sBankNumber.tc_Status    <> "D":U
                           no-error.
                
                if not available b_sBankNumber    
                then assign viCount = viCount + 1.             
            end. 
         end.         
         else do:
             /* different query to get the company id from the bank pay format since supplier and customer*/
             /* bank number do not have  company shared set id set*/
             <Q-13 run BankNumberForCustomerSupplier (all) (Read) (NoCache)
                (input t_sBankNumber.ParentObject_ID, (ParentObjectId)
                 input t_sBankNumber.BankNumberParentType, (BankNumberParentType)
                 input true, (BankNumberIsDefault)
                 input viCompanyId, (CompanyId)
                 output dataset tqBankNumberForCustomerSupplier) in BBankNumber >             
                 
             for each tqBankNumberForCustomerSupplier where 
                      tqBankNumberForCustomerSupplier.tiParentObject_ID      = t_sBankNumber.ParentObject_ID      and
                      tqBankNumberForCustomerSupplier.tcBankNumberParentType = t_sBankNumber.BankNumberParentType and
                      tqBankNumberForCustomerSupplier.tcCompanyCode          = (if (t_sBankNumber.tcCompanyCode = "":U or
                                                                                    t_sBankNumber.tcCompanyCode = ?)
                                                                                then vcCompanyCode
                                                                                else t_sBankNumber.tcCompanyCode) and
                      tqBankNumberForCustomerSupplier.tlBankNumberIsDefault  = true:

                 /* check whether there is another tq record that is Default, 
                    is not in the buffer b_s and the b_s already contains one Default bank Number*/
                 find first b_sBankNumber where 
                            b_sBankNumber.BankNumber_ID = tqBankNumberForCustomerSupplier.tiBankNumber_ID 
                            no-error.
                 if not available b_sBankNumber    
                 then do:                                        
                     /*if vcActivityCode <> "ExcelIntegration"
                     then assign viCount = viCount + 1.*/
                     assign viCount = viCount + 1.

                     /* change of default is required only through excel import*/                    
                     /*if vcActivityCode = "ExcelIntegration" and viCount = 1*/
                     if (vcActivityCode = "SupplierBankNumberExcelIntegration"  or
                         vcActivityCode = "CustomerBankNumberExcelIntegration") and
                         vicount = 2
                     then do:
                         assign viCount = viCount - 1.
                         <M-14 run DataLoad
                            (input  '':U (icRowids), 
                             input  string(tqbanknumberforcustomersupplier.tibanknumber_id) (icPkeys), 
                             input  '':U (icObjectIds), 
                             input  '':U (icFreeform), 
                             input  true (ilKeepPrevious), 
                             output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
                         
                                  
                          if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
                          then assign oiReturnStatus = viFcReturnSuper.
                                
                          find tBankNumber where
                               tBankNumber.BankNumber_ID = tqBankNumberForCustomerSupplier.tiBankNumber_ID
                               no-error.
                   
                          if not available tBankNumber
                          then do:
                              assign oiReturnStatus = -1
                                     vcMessage      = trim(substitute(#T-10'Unable to find the bank number based on its ID (&1).':255(999890672)T-10#,string(t_sBankNumber.BankNumber))).
                              
                              <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-9183':U (icFcMsgNumber),
                                 input  '' (icFcExplanation),
                                 input  '' (icFcIdentification),
                                 input  '' (icFcContext),
                                 output viFcReturnSuper (oiReturnStatus)) in BBankNumber>                                
                           end.      
                           else do:                                    
                               assign  oiReturnStatus = (if oiReturnStatus < 0 then oiReturnStatus else +1).
                                       vcMessage      = trim(substitute(#T-11'The default bank number  (&1) will be replaced by new default bank number (&2)':255(999890673)T-11#,string(tqBankNumberForCustomerSupplier.tcBankNumber),string(t_sBankNumber.BankNumber))).
                         
                               <M-16 run SetMessage
                                   (input  vcMessage (icMessage), 
                                    input  '':U (icArguments), 
                                    input  '':U (icFieldName), 
                                    input  '':U (icFieldValue), 
                                    input  'W':U (icType), 
                                    input  3 (iiSeverity), 
                                    input  '':U (icRowid), 
                                    input  'QadFin-9184':U (icFcMsgNumber), 
                                    input  '' (icFcExplanation), 
                                    input  '' (icFcIdentification), 
                                    input  '' (icFcContext), 
                                    output viFcReturnSuper (oiReturnStatus)) in BBankNumber> 
                                  
                               assign tBankNumber.BankNumberIsDefault = false
                                      tBankNumber.tc_Status = 'C':U.
                           end.
                       end. /* vicount*/
                   end. /* if not available b_sBanknumber */
              end.   /* for each bank number by customer supplier*/
        end. /* bank number type*/        
    end.     /* if vicount <=1 */

    /*error: only one Bank Number can be default 
    JBA 15/12/2004 based on mail from KatBra and WouAnt from 14/12/2004 this is valid only for GL 
    Creditors and Debtors can have more than 1 default bank account */
    if viCount > 1 
    then do:
        assign vcMessage = trim(#T-6'Only one bank number can be marked as default':200(391)t-6#).
        
        if t_sBankNumber.tcCompanyCode <> "":U and
           t_sBankNumber.tcCompanyCode <> ?
        then assign vcMessage = vcMessage + ", ":U + trim(substitute(#T-7'Entity: &1.':200(392)T-7#,
                                                        trim(t_sBankNumber.tcCompanyCode))).
        else assign vcMessage = vcMessage + ".":U.
        
        assign vcMessage      = vcMessage + chr(10) + program-name(1)
               oiReturnStatus = -1.
        <M-1 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-340':U (icFcMsgNumber),
                         input  '' (icFcExplanation),
                         input  '' (icFcIdentification),
                         input  '' (icFcContext),
                         output viFcReturnSuper (oiReturnStatus)) in BBankNumber>    
    end.
    /*error: at least one Bank Number must be default*/
    if viCount < 1
    then do:
        assign vcMessage = trim(#T-8'One bank account number must be marked as default.':200(73423182)T-8#).
        
        if t_sBankNumber.tcCompanyCode <> "":U and
           t_sBankNumber.tcCompanyCode <> ?
        then assign vcMessage = vcMessage + ", ":U + trim(substitute(#T-9'Entity: &1.':200(392)T-9#,
                                                        trim(t_sBankNumber.tcCompanyCode))).
        else assign vcMessage = vcMessage + ".":U.
        
        assign vcMessage      = vcMessage + chr(10) + program-name(1)
               oiReturnStatus = -1.
        <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-341':U (icFcMsgNumber),
                         input  '' (icFcExplanation),
                         input  '' (icFcIdentification),
                         input  '' (icFcContext),
                         output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
    end.