project QadFinancials > class BBusinessRelation > method ValidateComponentPre


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBusinessRelation.ValidateComponent


program code (program5/bbusinessrelation.p)

/* initial flag which be used to avoid multiple calling of a same validation */
assign vlTaxReportValidated = false. 

for each t_sBusinessRelation where
         t_sBusinessRelation.tc_Status <> '':U:
    if  t_sBusinessRelation.tc_Status <> "D":U and 
       (t_sBusinessRelation.BusinessRelationCode <> ? and
        t_sBusinessRelation.BusinessRelationCode <> "":U) 
    then assign t_sBusinessRelation.BusinessRelationCode = trim(t_sBusinessRelation.BusinessRelationCode).
           
    find t_iBusinessRelation where
         t_iBusinessRelation.tc_Rowid = t_sBusinessRelation.tc_Rowid
         no-error.

    if t_sBusinessRelation.tc_Status <> 'D':U
    then do:
        <M-1 run ValidateComponentSystemOrDomain  (output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
        if viFcReturnSuper <> 0 and oiReturnStatus >= 0
        then assign oiReturnStatus = viFcReturnSuper.
    end. /* if t_sBusinessRelation.tc_Status <> 'D':U */

    if t_sBusinessRelation.tc_Status = "C":U
    then do:
        /* It is not possible to change the Business Relation Code */                          
        if available t_iBusinessRelation and
           t_iBusinessRelation.BusinessRelationCode <> t_sBusinessRelation.BusinessRelationCode
        then do:
            assign vcMessage      = trim(#T-11'Cannot change key field value.':50(17933)T-11#)
                   oiReturnStatus = -1.
            <M-2 run SetMessage
               (input  vcMessage (icMessage), 
                input  '' (icArguments), 
                input  'BusinessRelationCode':U (icFieldName), 
                input  t_sBusinessRelation.BusinessRelationCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sBusinessRelation.tc_rowid (icRowid), 
                input  'QadFin-8257':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcreturnsuper (oiReturnStatus)) in BBusinessRelation>      
            return.
        end.    
    
        /* Don't allow setting Internal Entity to false if business relation is associated with a company. */        
        if available t_iBusinessRelation and
          (t_sBusinessRelation.BusinessRelationIsInComp = false and
           t_iBusinessRelation.BusinessRelationIsInComp = true) 
        then do:
            <Q-3 run CompanyBusinessRelation (all) (Read) (NoCache)
               (input ?, (CompanyId)
                output dataset tqCompanyBusinessRelation) in BCompany >
            find first tqCompanyBusinessRelation where
                       tqCompanyBusinessRelation.tiBusinessRelation_ID = t_sBusinessRelation.BusinessRelation_ID
                       no-error.
            if available tqCompanyBusinessRelation
            then do:
                assign vcMessage   = trim(#T-12'You cannot clear the Internal Entity field for a business relation that is associated with an entity.':255(65271)T-12#)
                    oiReturnStatus = -1.
                <M-4 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '' (icArguments), 
                    input  'tBusinessRelation.BusinessRelationIsInComp':U (icFieldName), 
                    input  t_sBusinessRelation.BusinessRelationIsInComp (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  '' (icRowid), 
                    input  'QadFin-8258':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
                return.
            end. /* if available tqCompanyBusinessRelation */
        end. /* if(not t_sBusinessRelation.BusinessRelationIsInComp) */
        
        if available t_iBusinessRelation and 
                     t_iBusinessRelation.BusinessRelationICCode <> t_sBusinessRelation.BusinessRelationICCode 
        then do :
            
            <Q-40 run PostingLineByIntercoBRid (first) (Read) (NoCache)
               (input ?, (CompanyId)
                input t_sBusinessRelation.BusinessRelation_ID, (BusinessRelation_ID)
                output dataset tqPostingLineByIntercoBRid) in BPosting>
             find first tqPostingLineByIntercoBRid where
                   tqPostingLineByIntercoBRid.tiIntercoBusinessRelation_ID = t_sBusinessRelation.BusinessRelation_ID 
                   no-error .   
             if  available tqPostingLineByIntercoBRid  
             then  do : 
                 assign vcMessage      = trim(#T-49'Can not modify Intercompany Code as transaction already exists with this Business Relation.':255(112088505)T-49#) 
                        oiReturnStatus = -1.
                    <M-14 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '' (icArguments), 
                        input  't_sBusinessRelation.BusinessRelationICCode' (icFieldName), 
                        input  t_sBusinessRelation.BusinessRelationICCode (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  '' (icRowid), 
                        input  'qadfin-274587':U (icFcMsgNumber), 
                        input  '' (icFcExplanation), 
                        input  '' (icFcIdentification), 
                        input  '' (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>  
             end.                              
        end.             
    end. /* tc_status = "C":U */

    if t_sBusinessRelation.tc_status = "D":U
    then do:
        /* Validate if its ok to delete the business relation */
        <M-5 run ValidateComponentDelete
           (input  0 (iiAddressID), 
            input  t_sBusinessRelation.BusinessRelation_ID (iiBusinessRelationID), 
            output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
        if viFcReturnSuper <> 0
        then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper <  0 
        then return.
    end. /* if t_sBusinessRelation.tc_status = "D":U: */

    /* 1099 fields cannot be populated unless the Internal Company field is checked. */
    /* The user then has the choice of checking the Internal Company flag or clearing out the 1099 fields. */
    if t_sBusinessRelation.tc_Status = "N":U or 
       t_sBusinessRelation.tc_Status = "C":U
    then do:
        /* Fill in Code automatically */
        if t_sBusinessRelation.tc_Status = "N":U and
           (t_sBusinessRelation.BusinessRelationCode = '':U or
            t_sBusinessRelation.BusinessRelationCode = ?)
        then do:
            assign vhFcComponent = ?.
            <M-6 run GetAutoNumber
               (input  t_sBusinessRelation.tc_Rowid (icRowid), 
                output t_sBusinessRelation.BusinessRelationCode (ocBusinessRelationCode), 
                output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
            if viFcReturnSuper <> 0
            then assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then return.
        end.
        
        if t_sBusinessRelation.BusinessRelationIsInComp = false
        then do:
            if t_sBusinessRelation.BusinessRelationNameCtrl   <> ''  or 
               t_sBusinessRelation.BusinessRelationIsTaxRep   = true or
               t_sBusinessRelation.BusinessRelationIsLastFill = true
            then do:
                assign vcMessage      = trim(#T-13'You cannot specify values in the Tax Report, Name Control, and Last Filing fields unless the Internal Entity field is selected.':109(45667)T-13#)
                       oiReturnStatus = -1.
                <M-7 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '' (icArguments), 
                    input  'Internal Entity':U (icFieldName), 
                    input  t_sBusinessRelation.BusinessRelationIsInComp (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sBusinessRelation.tc_Rowid (icRowid), 
                    input  'QadFin-8259':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>           
                return.
            end.
        end. 
    end. /* tc_status = "N" or "C" */
end. /* for each t_sBusinessRelation */

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

for each t_sBusRelationSafDefault:
    if t_sBusRelationSafDefault.tcSafCode <> "":U
    then do:
        <Q-9 run SafPrim (all) (Read) (Cache)
           (input ?, (SafID)
            input t_sBusRelationSafDefault.tcSafCode, (SafCode)
            input ?, (SafConceptCode)
            output dataset tqSafPrim) in BSaf >
        find first tqSafPrim where
                   tqSafPrim.tcSafCode        = t_sBusRelationSafDefault.tcSafCode and
                   tqSafPrim.tcSafConceptCode = t_sBusRelationSafDefault.tcSafConceptCode
                   no-error.
        if not available tqSafPrim
        then find first tqSafPrim where
                        tqSafPrim.tcSafCode = t_sBusRelationSafDefault.tcSafCode
                        no-error.
        assign t_sBusRelationSafDefault.Saf_ID = if available tqSafPrim
                                                 then tqSafPrim.tiSaf_ID
                                                 else -1.
    end.
end.
for each t_sAddress where 
    (t_sAddress.tc_Status = "C":U or t_sAddress.tc_Status = "N") and
    (t_sAddress.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-ENDUSER} or 
     t_sAddress.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-DELIVERY} or 
     t_sAddress.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}) :
    if length(t_sAddress.AddressFax,"CHARACTER":U) > 20 or length (t_sAddress.AddressTelephone,"CHARACTER":U) > 20 
    then do:
         
         assign vcMessage = #T-68'This field will be truncated to 20 characters on reports and operational screens':255(479694606)T-68#
                oiReturnStatus = 1.
                if length(t_sAddress.AddressFax,"CHARACTER":U) > 20 then 
                    vcFieldName = "tAddress.AddressFax":U.
                if length (t_sAddress.AddressTelephone,"CHARACTER":U) > 20 then do:
                    if vcFieldName = "" then 
                        vcFieldName = "tAddress.AddressTelephone":U. 
                    else vcFieldName = vcFieldName + " ":U + "tAddress.AddressTelephone":U.
                end.
         <M-86 run SetMessage
            (input  vcMessage (icMessage), 
             input  ? (icArguments), 
             input  vcFieldName (icFieldName), 
             input  ? (icFieldValue), 
             input  'W':U (icType), 
             input  4 (iiSeverity), 
             input  ? (icRowid), 
             input  'qadfin-465153':U (icFcMsgNumber), 
             input  'As operational Screens supports only upto 20 characters':U (icFcExplanation), 
             input  ? (icFcIdentification), 
             input  ? (icFcContext), 
             output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation> 
    end.
end.
/* ===================================================================================== */
/* Fill up the field AddressLogicKeyString                                               */
/* ===================================================================================== */
for each t_sAddress: 
    if t_sAddress.AddressLogicKeyString = "":U 
    then assign t_sAddress.AddressLogicKeyString = string(t_sAddress.Address_ID).

    if (t_sAddress.tc_Status = "C":U or t_sAddress.tc_Status ="N") and 
       (t_sAddress.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-ENDUSER} or t_sAddress.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-DELIVERY})
    then do:
        assign vlAddressFound = false.

        find first t_sBusinessRelation where t_sBusinessRelation.tc_rowid = t_sAddress.tc_parentrowid no-error.
        if not available (t_sBusinessRelation)
        then do:                                
            assign 
                vcMessage =  #T-59'Unable to find business relation':255(531318899)T-59#
                oiReturnStatus = -1.
                <M-48 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '' (icArguments), 
                    input  '' (icFieldName), 
                    input  '' (icFieldValue), 
                    input  'E' (icType), 
                    input  3 (iiSeverity), 
                    input  t_sAddress.tc_rowid (icRowid), 
                    input  'qadfin-374894':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
        end.

         /* Check to see if the address already exists in the instance */
        if can-find (first bValAddress 
                where bValAddress.AddressCity = t_sAddress.AddressCity
                  and bValAddress.AddressStreet1 = t_sAddress.AddressStreet1
                  and bValAddress.AddressStreet2 = t_sAddress.AddressStreet2
                  and bValAddress.AddressStreet3 = t_sAddress.AddressStreet3
                  and bValAddress.AddressZip = t_sAddress.AddressZip
                  and bValAddress.tcAddressTypeCode = t_sAddress.tcAddressTypeCode
                  and bValAddress.tc_parentrowid= t_sAddress.tc_parentrowid
                  and bValAddress.Address_id <> t_sAddress.address_id) 
         then
            assign vlAddressFound = true.

        if not (vlAddressFound)
        then do: 
            /* Check to see if the address already exists in the db */
             <Q-61 run AddressPrim (all) (Read) (NoCache)
                (input t_sAddress.AddressCity, (AddressCity)
                 input t_sAddress.AddressStreet1, (AddressStreet1)
                 input t_sAddress.AddressStreet2, (AddressStreet2)
                 input t_sAddress.AddressZip, (AddressZip)
                 input t_sAddress.tcAddressTypeCode, (AddressTypeCode)
                 input ?, (AddressID)
                 input ?, (BusinessRelationID)
                 input t_sBusinessRelation.businessrelationcode, (BusinessRelationCode)
                 input ?, (AddressTypeID)
                 input t_sAddress.AddressStreet3, (AddressStreet3)
                 output dataset tqAddressPrim) in BBusinessRelation >
        
              if can-find(first tqAddressPrim 
                    where tqAddressPrim.tcAddressCity = t_sAddress.AddressCity
                      and tqAddressPrim.tcAddressStreet1 = t_sAddress.AddressStreet1
                      and tqAddressPrim.tcAddressStreet2 = t_sAddress.AddressStreet2
                      and tqAddressPrim.tcAddressStreet3 = t_sAddress.AddressStreet3
                      and tqAddressPrim.tcAddressZip = t_sAddress.AddressZip
                      and tqAddressPrim.tcAddressTypeCode = t_sAddress.tcAddressTypeCode
                      and tqAddressPrim.tcBusinessRelationCode = t_sBusinessRelation.businessrelationcode
                      and tqAddressPrim.tiAddress_id <> t_sAddress.address_id)
              then 
                assign vlAddressFound = true.
          end. /* end not vlAddressFound */

          if vlAddressFound 
          then do:
             if (t_sAddress.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-ENDUSER})             
             then assign vcMessage =  #T-63'The address below already exists - To assign an end user to an existing address use the 'Link to end user address', $1, $2, $3, $4, $5, $6':255(143844118)T-63#.
             else
                assign vcMessage =    #T-66'This address below already exists - To assign a ship-to to an existing address use the 'Link to ship-to address' ,$1, $2, $3, $4, $5, $6':255(393182381)T-66#.
             
             assign oiReturnStatus = -1.
             <M-42 run SetMessage
                (input  vcMessage (icMessage), 
                 input  t_sAddress.AddressStreet1 + chr(2) + t_sAddress.AddressStreet2 + chr(2) + t_sAddress.AddressStreet3 + chr(2) + t_sAddress.AddressCity + chr(2) + t_sAddress.AddressZip  + chr(2) + t_sBusinessRelation.BusinessRelationCode (icArguments), 
                 input  'AddressStreet1' (icFieldName), 
                 input  t_sAddress.AddressStreet1 (icFieldValue), 
                 input  'E' (icType), 
                 input  3 (iiSeverity), 
                 input  t_sAddress.tc_rowid (icRowid), 
                 input  'qadfin-896241':U (icFcMsgNumber), 
                 input  '' (icFcExplanation), 
                 input  '' (icFcIdentification), 
                 input  '' (icFcContext), 
                 output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
              return.
          end.
     end. /* end of ENDUSER type */  
end. 

/* ===================================================================================== */
/* Fill up the BusRel_ID field on the contact table to improve performance on dataload   */
/* ===================================================================================== */
for each t_sContact where 
         (t_sContact.tc_Status = "N":U or
          t_sContact.tc_Status = "C":U),
    each t_sAddress where
         t_sAddress.tc_Rowid   = t_sContact.tc_ParentRowid and 
         t_sAddress.tc_status <> "D":U,
    each t_sBusinessRelation where
         t_sBusinessRelation.tc_Rowid  = t_sAddress.tc_ParentRowid and
         t_sBusinessRelation.tc_Status <> "D":U:
    assign t_sContact.BusinessRelation_ID = t_sBusinessRelation.BusinessRelation_ID.       
end. /* for each t_sContact where */   

for each t_sAddress 
    where t_sAddress.tc_Status = "D":U:
       /* Validate if its ok to delete the business relation */
    <M-10 run ValidateComponentDelete
       (input  t_sAddress.address_ID (iiAddressID), 
        input  0 (iiBusinessRelationID), 
        output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
        if viFcReturnSuper <> 0
        then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper <  0 
        then return.
end.

/* Give an error if Language Code for Headoffice address is blank */
for each t_sAddress where 
    (t_sAddress.tc_Status = "C":U or t_sAddress.tc_Status = "N") and
     t_sAddress.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}:
    if t_sAddress.tcLngCode = "":U or
       t_sAddress.tcLngCode = ?
    then do:
        assign vcMessage      = trim(#T-41'You must enter this field':255(829534818)T-41#)
               oiReturnStatus = -1.
        <M-47 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'Language Code':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'qadfin-90373':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
        return.
    end.
end.