project QadFinancials > class BBusinessRelation > method ValidateComponentPostAddress


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBusinessRelation.ValidateComponent


program code (program1/bbusinessrelation.p)

assign oiReturnStatus = -98
       viLocalReturn  = 0.
       
<I-72 {bFcOpenInstance
        &CLASS           = "Session"}>
            
<M-90 run GetLogicalValue
   (input  'AvataxIsActive':U (icName), 
    output vlAvataxIsActive (olValue), 
    output viFcReturnSuper (oiReturnStatus)) in Session>

<M-62 run GetLogicalValue
   (input  'VerifyAvataxAddress':U (icName), 
    output vlVerifyAvataxAddress (olValue), 
    output viFcReturnSuper (oiReturnStatus)) in Session>   
    
                             
<I-42 {bFcCloseInstance
        &CLASS           = "Session"}>

if vlAvataxIsActive and vlVerifyAvataxAddress then         
    assign vcAvataxCountries = {&AVATAXCOUNTRIES}.          
       
MAIN_BLOCK:
          
for each t_sAddress where 
        (t_sAddress.tc_Status = "N":U or
         t_sAddress.tc_Status = "C":U)
        on error undo, leave:

    /* ======================================================================= */
    /* Validate state tax value against vat format of country                  */
    /* ======================================================================= */  
    if t_sAddress.AddressTaxIDState <> ?    and
       t_sAddress.Country_ID        <> 0    and
       t_sAddress.Country_ID        <> ?
    then do:         
        <Q-45 run CountryByCountry (all) (Read) (NoCache)
           (input t_sAddress.Country_ID, (CountryId)
            input '':U, (CountryCode)
            output dataset tqCountryByCountry) in BCountry >
        find first tqCountryByCountry where tqCountryByCountry.tlCountryIsEUCountry = true no-error.
        if available tqCountryByCountry
        then do: 
            /* this assignment is according to GuideLines Writting Busienss Logic v2.0 5.5, no need to start and stop instance  */
            /* this usage also was refered in description of CheckVatNumber class definition */
            Assign vhFcComponent = ?.
            <M-58 run ApiCheckVatNumber
               (input  t_sAddress.Country_ID (iiCountryId), 
                input  t_sAddress.tcCountryCode (icCountryCode), 
                input  t_sAddress.AddressTaxIDState (icVatNumber), 
                input  true (ilMessage), 
                output vcDummyVatNumberShort (ocVatNumberShort), 
                output vcDummyVatNumberLong (ocVatNumberLong), 
                output viFcReturnSuper (oiReturnStatus)) in BCountry>             
            if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
        end. /* end of if available tqCountryByCountry */
    end. /* end of if t_sAddress.AddressTaxIDState <> '':U and */
      
    /* =============================================================================== */    
    /* this will call ValidateTaxReport in the case that the user only changed address */
    /* but changed nothing of bus rel itself                                           */
    /* =============================================================================== */  
    if t_sAddress.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE} and
       vlTaxReportValidated         = false
    then do:        
        find first t_sBusinessRelation where 
                   t_sBusinessRelation.BusinessRelation_ID = t_sAddress.BusinessRelation_ID 
                   no-error.
        /* validate tax report related fields if it is a tax reporting business relation */
        if available t_sBusinessRelation 
        then do:
            if t_sBusinessRelation.BusinessRelationIsTaxRep = true
            then do:
                <M-22 run ValidateTaxReport
                   (input  t_sBusinessRelation.tc_Rowid (icRowID), 
                    output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
                    /* make sure the same validation only to be executed once */
                assign vlTaxReportValidated = true.
                if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
            end.
            /* validate tax report related fields if the related supplier is tax report supplier */
            else do:
                <Q-40 run AddressForCreditor (all) (Read) (NoCache)
                   (input '':U, (AddressCity)
                    input '':U, (AddressCountry)
                    input '':U, (AddressLine)
                    input '':U, (AddressSearchName)
                    input '':U, (AddressTypeCode)
                    input '':U, (AddressZip)
                    input '':U, (BusinessRelationName)
                    input viCompanyId, (CompanyId)
                    input '':U, (AddressName)
                    input t_sAddress.Address_ID, (AddressID)
                    output dataset tqAddressForCreditor) in BBusinessRelation >
                find first tqAddressForCreditor where 
                           tqAddressForCreditor.tlCreditorIsTaxReport = true and
                           tqAddressForCreditor.tlCreditorIsActive    = true no-error.
                if available tqAddressForCreditor
                then do:
                    <M-50 run ValidateTaxReport
                       (input  t_sBusinessRelation.tc_Rowid (icRowID), 
                        output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
                    /* make sure the same validation only to be executed once */
                    assign vlTaxReportValidated = true.
                    if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
                end.

            end.
        end.
    end.
    
    
    /* ======================================================================= *
     * Validate format of the Federal Tax ID, State Tax Id and Miscelenous     *
     * taxes are correct                                                       *
     * ======================================================================= */ 
    if t_sAddress.AddressIsTaxable
    then do:
        <M-15 run ValidateComponentPostAddressTax  (output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
        if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
    end.
    
    /* ======================================================================= */
    /* Add other address validations here ...                                  */
    /* ======================================================================= */    

    if vlAvataxIsActive and vlVerifyAvataxAddress then
    do:
         assign vlIsAvataxCountry = false.
         do viCounter = num-entries(vcAvataxCountries, chr(2)) to 2 by -2:
            if entry(viCounter, vcAvataxCountries, chr(2)) = t_sAddress.tcCountryCode
            then do:
                assign vlIsAvataxCountry = true.
                leave.
            end.
         end. 
         
         if vlIsAvataxCountry 
         then do:
                
             /* ======================================================================= */
            /* Check if Avatax key fields have changed                 */
            /* ======================================================================= */
            
            
            if t_sAddress.tc_Status = 'C':U 
            then do:
                 find first t_iAddress where
                     t_iAddress.tc_Rowid = t_sAddress.tc_Rowid
                     no-error.
            
                    if (trim(t_iAddress.AddressStreet1) <> trim(t_sAddress.AddressStreet1) or
                                trim(t_iAddress.AddressStreet2) <> trim(t_sAddress.AddressStreet2) or
                                trim(t_iAddress.AddressStreet3) <> trim(t_sAddress.AddressStreet3) or
                                trim(t_iAddress.AddressZip) <> trim(t_sAddress.AddressZip) or
                                trim(t_iAddress.AddressCity) <> trim(t_sAddress.AddressCity) or
                                trim(t_iAddress.tcStateCode) <> trim(t_sAddress.tcStateCode) or
                                trim(t_iAddress.tcCountryCode) <> trim(t_sAddress.tcCountryCode))     
                    then
                        assign vlAddressKeyFieldChanged = true.
             end. 
    
    
                     
             if vlAddressKeyFieldChanged or t_sAddress.tc_Status = 'N':U
             then do:
    
                    create tBusRelAvaReturnAddress.
                    assign
                            tBusRelAvaReturnAddress.tcAddressCode   = STRING(t_sAddress.Address_ID)
                            tBusRelAvaReturnAddress.tcLine1          =  t_sAddress.AddressStreet1        
                            tBusRelAvaReturnAddress.tcLine2          =  t_sAddress.AddressStreet2
                            tBusRelAvaReturnAddress.tcLine3          =  t_sAddress.AddressStreet3
                            tBusRelAvaReturnAddress.tcCity           =  t_sAddress.AddressCity
                            tBusRelAvaReturnAddress.tcRegion         = t_sAddress.tcStateCode
                            tBusRelAvaReturnAddress.tcPostalCode     = t_sAddress.AddressZip
                            tBusRelAvaReturnAddress.tcCountry        = ""
                            tBusRelAvaReturnAddress.tcTaxRegionId    = ""
                            tBusRelAvaReturnAddress.tcLatitude       = ""
                            tBusRelAvaReturnAddress.tcLongitude      = ""
                            tBusRelAvaReturnAddress.tcLine4          = ""
                            tBusRelAvaReturnAddress.tcCounty         = t_sAddress.AddressCounty
                            tBusRelAvaReturnAddress.tcfipscode       = ""
                            tBusRelAvaReturnAddress.tcCarrierRoute   = ""
                            tBusRelAvaReturnAddress.tcPostNet        = ""
                            tBusRelAvaReturnAddress.tcAddressType    = ""
                            tBusRelAvaReturnAddress.tcGeocodeType    = ""
                            tBusRelAvaReturnAddress.tcValidateStatus = "". 
                                                           
              end.
              
          end.
          else do:
              /* if country code is not apllicable to avatax then set code to blank*/
              assign t_sAddress.AddressExternalValidationCode = {&AVATAXVALIDATIONCODE-NOTSUBMITTED}.
          end. 
    end.

end.

if vlAvataxIsActive and vlVerifyAvataxAddress 
then do:
    find first tBusRelAvaReturnAddress no-lock no-error.
    if available tBusRelAvaReturnAddress 
    then do:
        <M-2 run ValidateComponentExternalAddress
           (input-output tBusRelAvaReturnAddress (tBusRelAvaReturnAddress), 
            output tBusRelAvaReturnMessage (tBusRelAvaReturnMessage), 
            output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation> 
    
        if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
    end.
end.

assign oiReturnStatus = viLocalReturn.