project QadFinancials > class BBusinessRelation > method AdditionalUpdates

Description

This method is part of the SetPublicTables flow.
When executed, data in the input class tables (prefix t_s) is validated and found correct, and copied into the class tables (prefix t_o).
This method can be extended to do updates that do not require a validation or that involve running business methods of other business classes. These classes should be started with ADD-TO-TRANSACTION = 'true'. Also make sure to add these classes in method StopExternalInstances.


Parameters


oiReturnStatusoutputinteger


Internal usage


QadFinancials
method BBusinessRelation.ApiMaintainAddressForEI
method BBusinessRelation.ApiStdMaintainTT
method BBusinessRelation.ApiSynchronise
method BBusinessRelation.ValidateBCAndAdditionalUpdates


program code (program/bbusinessrelation.p)

    /* ====================================================================================== */
    /* extra validations :                                                                    */
    /* * The head office address must always be defined for a business relation !!            */
    /* * only one address can be specified for head office, invoice, remittance, reminder     */
    /* ====================================================================================== */
    <M-1 run AdditionalUpdatesValidate  (output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
    if viFcReturnSuper < 0 or 
      (viFcReturnSuper > 0 and oiReturnStatus = 0)
    then assign oiReturnStatus = viFcReturnSuper.
    if oiReturnStatus < 0 
    then return.

    /* ========================================================================================= */
    /* Combination of IdentityCountry_ID and VatNumberIdentity must be unique, otherwise warning */
    /* ========================================================================================= */
    for each tVatNumber where
             tVatNumber.tc_Status = "C":U or
             tVatNumber.tc_Status = "N":U, 
        each tBusinessRelation where
             tBusinessRelation.tc_Rowid   = tVatNumber.tc_ParentRowid and 
             tBusinessRelation.tc_Status <> "D":U :
        /* Skip the unchanged records */
        if tVatNumber.tc_Status = "C":U and 
           can-find (first t_iVatNumber where
                           t_iVatNumber.tc_Rowid           = tVatNumber.tc_Rowid           and
                           t_iVatNumber.IdentityCountry_ID = tVatNumber.IdentityCountry_ID and
                           t_iVatNumber.VatNumberIdentity  = tVatNumber.VatNumberIdentity)
        then next.
        /* Reset loop variables */
        assign vcDuplicateBusinessRelationCode = "":U.
        /* Go through the instance for similar vat-numbers */
        for each btVatNumber where
                 btVatNumber.IdentityCountry_ID  = tVatNumber.IdentityCountry_ID and
                 btVatNumber.VatNumberIdentity   = tVatNumber.VatNumberIdentity  and
                 btVatNumber.tc_RowId           <> tVatNumber.tc_Rowid and
                 btVatNumber.tc_status          <> "D":U,
            each btBusinessRelation where
                 btBusinessRelation.tc_Rowid   = btVatNumber.tc_ParentRowid and 
                 btBusinessRelation.tc_Status <> "D":U :
            assign vcDuplicateBusinessRelationCode = btBusinessRelation.BusinessRelationCode.
            leave.
        end. /* for each btVatNumber where */
        /* Go through the db for similar vat-numbers */
        if vcDuplicateBusinessRelationCode = "":U
        then do : 
            <Q-4 run VatNumberByBusinessRelation (first) (Read) (NoCache)
               (input ?, (BusinessRelationId)
                input tVatNumber.VatNumber_ID, (VatNumberIDToSkip)
                input tVatNumber.IdentityCountry_ID, (IdentityCountryID)
                input tVatNumber.VatNumberIdentity, (VatNumberIdentity)
                input tBusinessRelation.BusinessRelation_ID, (BusinessRelationIDToSkip)
                output dataset tqVatNumberByBusinessRelation) in BBusinessRelation >
            find first tqVatNumberByBusinessRelation where
                       tqVatNumberByBusinessRelation.tiBusinessRelation_ID <> tVatNumber.BusinessRelation_ID and
                       tqVatNumberByBusinessRelation.tiVatNumber_ID        <> tVatNumber.VatNumber_ID        and
                       tqVatNumberByBusinessRelation.tiIdentityCountry_ID   = tVatNumber.IdentityCountry_ID  and
                       tqVatNumberByBusinessRelation.tcVatNumberIdentity    = tVatNumber.VatNumberIdentity
                       no-lock no-error.
            if available tqVatNumberByBusinessRelation
            then assign vcDuplicateBusinessRelationCode = tqVatNumberByBusinessRelation.tcBusinessRelationCode.
        end. /* if vcDuplicateBusinessRelationCode = "":U */
        /* Check for errors */
        if vcDuplicateBusinessRelationCode <> "":U
        then do:
            assign vcMessage      = trim(#T-5'The country tax identification and the tax identification number are already linked to another business relation.':255(847)t-5#) + chr(10) + 
                                    trim(substitute(#T-6'Current business relation: &1.':255(848)T-6#,tBusinessRelation.BusinessRelationCode)) + chr(10) + 
                                    trim(substitute(#T-7'Duplicate business relation = &1.':255(849)T-7#,vcDuplicateBusinessRelationCode)) + chr(10) + 
                                    trim(substitute(#T-8'Country VAT Identification = &1':255(850)T-8#,tVatNumber.tcIdentityCountryCode)) + chr(10) +  
                                    trim(substitute(#T-9'Tax identification number: &1.':255(851)t-9#,tVatNumber.VatNumberIdentity))
                   oiReturnStatus = +1. /* warning */
             <M-3 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-250':U (icFcMsgNumber), 
                 input  '' (icFcExplanation), 
                 input  '' (icFcIdentification), 
                 input  '' (icFcContext), 
                 output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
         end. /* if vcDuplicateBusinessRelationCode <> "":U */
    end. /* for each tVatNumber where */

    for each tContact 
        where tContact.tc_Status = "D" :
        find first bContact where 
            bContact.Address_ID          = tContact.Address_ID and 
            bContact.BusinessRelation_ID = tContact.BusinessRelation_ID and
            bContact.ContactName         = tContact.ContactName and
            bContact.tc_status           = 'N':U 
        no-error.
        if available bContact
        then do:
            buffer-copy bContact except
            tc_Rowid 
            tc_ParentRowid 
            tc_status 
            Contact_ID to tContact.
            assign 
            tContact.tc_status  = 'C'.
            delete bContact.  
        end.                      
    end. /* for each tContact */

/* ===================================================================================== */
/*Ensure that if a tContact record is new/deleted/modified that the associated tAddress record
  is also marked for update if it is currently marked as unchanged. 
  The Address is the owner of the Contact data and triggers the replication
  to MfgPro*/
/* ===================================================================================== */  
for each tContact
where tContact.tc_Status NE "":U :
    for each tAddress
    where tAddress.Address_ID = tContact.Address_ID
    and tAddress.tc_Status EQ "":U:    
        assign 
            tAddress.tc_Status = "C":U.
    end.
end.

/* when a new Business Relation is created*/
for each tBusinessRelation 
    where tBusinessRelation.tc_status = "N":
          
    /* If the buisness relation name or search name has been updated then we need to update headoffice address with those values */ 
     for first tAddress
         where tAddress.tc_ParentRowid = tBusinessRelation.tc_rowid
              and tAddress.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}:
        assign 
            tAddress.AddressName = tBusinessRelation.BusinessRelationName1
            tAddress.AddressSearchName = tBusinessRelation.BusinessRelationSearchName.
     end.   
end.

for each tBusinessRelation 
    where tBusinessRelation.tc_status = "C",
    first t_iBusinessRelation
        where t_iBusinessRelation.tc_rowid  = tBusinessRelation.tc_rowid 
           and ( t_iBusinessRelation.BusinessRelationName1 <> tBusinessRelation.BusinessRelationName1
                 or t_iBusinessRelation.BusinessRelationSearchName <> tBusinessRelation.BusinessRelationSearchName):
          
    /* If the buisness relation name or search name has been updated then we need to update headoffice address with those values */ 
     for first tAddress
         where tAddress.tc_ParentRowid = tBusinessRelation.tc_rowid
              and tAddress.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}:
        assign 
            tAddress.AddressName = tBusinessRelation.BusinessRelationName1
            tAddress.AddressSearchName = tBusinessRelation.BusinessRelationSearchName
            tAddress.tc_status = "C".
     end.   
             
end.
    
/********************************************************************* */
/* Update the Langusge Code and SearchName to the cm_mstr and vd_mstr  */
/********************************************************************* */
for each tAddress where
         tAddress.tc_status = "C" and
         tAddress.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE},
    first t_iAddress where 
          t_iAddress.tc_rowid  = tAddress.tc_rowid and 
          (t_iAddress.tcLngCode <> tAddress.tcLngCode or
           t_iAddress.AddressSearchName <> tAddress.AddressSearchName):

        /* ===================================================== */
        /* Supplier Side                                         */
        /* ===================================================== */
        if viBMfgSupplierFromBBusRelID = 0 or
           viBMfgSupplierFromBBusRelID = ?
        then do:   
            <I-40 {bFcStartAndOpenInstance
                 &ADD-TO-TRANSACTION   = "true"
                 &CLASS                = "BMfgSupplier"}>
        end.
        else do:
            <I-41 {bFcOpenInstance
                 &CLASS           = "BMfgSupplier"}>
        end.
        
        /* call to BMfgSupplier method for updation */
        <M-42 run UpdateSupplierLanguageSearchName
           (input  tAddress.BusinessRelation_ID (iiBusinessRelation_ID), 
            input  tAddress.tcLngCode (icLngCode), 
            input  tAddress.AddressSearchName (icSearchName), 
            output viExternalReturnStatus (oiReturnStatus)) in BMfgSupplier>
          
         /* Close instance of BMfgSupplier*/         
         <I-43 {bFcCloseInstance
              &CLASS           = "BMfgSupplier"}>
        
       
        /* ===================================================== */
        /* Customer Side                                         */
        /* ===================================================== */
        if viBMfgCustomerFromBBusRelID = 0 or
           viBMfgCustomerFromBBusRelID = ?
        then do:   
            <I-44 {bFcStartAndOpenInstance
                 &ADD-TO-TRANSACTION   = "true"
                 &CLASS                = "BMfgCustomer"}>
        end.
        else do:
            <I-45 {bFcOpenInstance
                 &CLASS           = "BMfgCustomer"}>
        end.
        
        /* call to BMfgCustomer method for updation */ 
         <M-46 run UpdateCustomerLanguageSearchName
            (input  tAddress.BusinessRelation_ID (iiBusinessRelation_ID), 
             input  tAddress.tcLngCode (icLngCode), 
             input  tAddress.AddressSearchName (icSearchName), 
             output viExternalReturnStatus (oiReturnStatus)) in BMfgCustomer>
        
        /* Close instance of BMfgCustomer*/
         <I-47 {bFcCloseInstance
              &CLASS           = "BMfgCustomer"}>
               
        /* error handling*/
        if viExternalReturnStatus <> 0 
        then assign oiReturnStatus = viExternalReturnStatus.
        
        if viExternalReturnStatus < 0 
        then do :
            <M-48 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
            Return.
        end. /* if viExternalReturnStatus < 0  */

end. /* for each tBusinessRelation */
                        
/* ===================================================================================== */
/* Hold the current return-status because the ancestor-code will override oiReturnStatus */
/* ===================================================================================== */
assign viLocalReturnStatus = oiReturnStatus.

<ANCESTOR-CODE>

/* ====================================================================================== */
/* If the return of the ancestor was 0 or if it returned a warnign and we already had an  */
/* error; Assign oiReturnStatus with the return-status as it was before the ancestor-code */
/* ====================================================================================== */
if oiReturnStatus = 0 or
   (viLocalReturnStatus < oiReturnStatus)
then assign oiReturnStatus = viLocalReturnStatus.


/* ====================================================================================== */
/* Propagete changes of the business relation also into the Operational tables            */
/* Ship Ship-to and End-user addresses, as they are replicated by their Components        */
/* If this business relation is alterred from the Ship_to or End-user maintenance, then   */
/* no replication should be triggered from the business relation.                         */
/* ====================================================================================== */
assign vlIsReplicationNeeded = false.
for each tBusinessRelation where
         tBusinessRelation.tc_Status <> "D",
    each tAddress where
         tAddress.tc_ParentRowid    = tBusinessRelation.tc_Rowid        and
         tAddress.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}:
    
    if tAddress.tc_Status = "C":U or
       tAddress.tc_Status = "D":U
    then do:
        assign vlIsReplicationNeeded = true.
        leave.
    end.

    if can-find(first tContact where
                      tContact.tc_ParentRowid = tAddress.tc_Rowid and
                      tContact.tc_Status     <> "":U)
   then do:
        assign vlIsReplicationNeeded = true.
        leave.
   end.
end.

if vlIsReplicationNeeded
then do:
    if viBMfgAddress6ID = 0 or
       viBMfgAddress6ID = ?
    then do:   
        <I-10 {bFcStartAndOpenInstance
             &ADD-TO-TRANSACTION = "true"
             &CLASS              = "BMfgAddress"}>
    end.
    else do:
         <I-14 {bFcOpenInstance
              &CLASS           = "BMfgAddress"}>
    end.
                                  
    <M-77 run ApiReplicateFromFinancialsBusRel
       (input  tAddress (tAddressesToUpdate), 
        input  tContact (tContactsToUpdate), 
        output viLocalReturnStatus (oiReturnStatus)) in BMfgAddress>

    <I-12 {bFcCloseInstance
         &CLASS           = "BMfgAddress"}>

    if viLocalReturnStatus <> 0 then assign oiReturnStatus = viLocalReturnStatus.
    if viLocalReturnStatus < 0 
    then do :
        <M-16 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
        Return.
    end. /* if viLocalReturnStatus < 0  */
end. /* of if vlIsReplicationNeeded */

/* ======================== */
/* Set ReturnStatus = OK    */
/* ======================== */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.