project QadFinancials > class BDebtor > 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 BDebtor.ApiCheckCreditLimit
method BDebtor.ApiStdMaintainTT
method BDebtor.ApiUpdateDebtorHighCreditInfo
method BDebtor.ApiUpdateDebtorPaymentSales


program code (program/bdebtor.p)

MAIN_BLOCK:
do on error undo, leave MAIN_BLOCK:

    assign viLocalReturnStatus = 0
           oiReturnStatus      = -98.
    
    /* ================ */
    /* UpdateBankNumber */
    /* ================ */
    if  can-find (first tBankNumberRefDebtor where 
                           tBankNumberRefDebtor.tc_Status <> "":U) or
        can-find (first tDBankNumberPayCodeRef where 
                           tDBankNumberPayCodeRef.tc_Status <> "":U)                   
    then do:
        if viBBankNumber4ID = 0 or
           viBBankNumber4ID = ?
        then do:
            <I-13 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BBankNumber"}>
        end. /* if viBBankNumber4ID = 0 or */
        else if not valid-handle(vhBBankNumber4Inst)
        then do:
            <I-17 {bFcOpenInstance
            &CLASS           = "BBankNumber"}>
        end. /* not if viBBankNumber4ID = 0 or */
    
        /*first set corect tDBankNumberPayCodeRef.BankNumber_Id based on tc_Rowid <-> tc_ParentRowid relations*/
        for each tDBankNumberPayCodeRef:
            find first tBankNumberRefDebtor where
                            tBankNumberRefDebtor.tc_Rowid = tDBankNumberPayCodeRef.tc_ParentRowid no-error.
            if available tBankNumberRefDebtor
            then assign tDBankNumberPayCodeRef.BankNumber_ID  = tBankNumberRefDebtor.BankNumber_ID.

            <Q-30 run PayFormatCodebyGroupID (all) (Read) (NoCache)
               (input ?, (PayFormatCodeID)
                input tDBankNumberPayCodeRef.tcPayFormatCodeValue, (PayFormatCode)
                input tDBankNumberPayCodeRef.PayFormatGroup_ID, (PayFormatGroupID)
                output dataset tqPayFormatCodebyGroupID) in BPaymentFormat >

            for first tqPayFormatCodebyGroupID:
                if tqPayFormatCodebyGroupID.tiPayFormatCode_ID = 0 or 
                   tqPayFormatCodebyGroupID.tiPayFormatCode_ID = ?
                then assign tDBankNumberPayCodeRef.BankNumberPayCodeValue = tDBankNumberPayCodeRef.tcPayFormatCodeValue
                            tDBankNumberPayCodeRef.PayFormatCode_ID = ?
                            tDBankNumberPayCodeRef.tcPayFormatCode = "".
                else assign tDBankNumberPayCodeRef.tcPayFormatCode = tDBankNumberPayCodeRef.tcPayFormatCodeValue.
            end. /* for */
            if not available tqPayFormatCodebyGroupID 
            then assign tDBankNumberPayCodeRef.BankNumberPayCodeValue = tDBankNumberPayCodeRef.tcPayFormatCodeValue
                        tDBankNumberPayCodeRef.PayFormatCode_ID = ?
                        tDBankNumberPayCodeRef.tcPayFormatCode = "". 
        end. /* for each tDBankNumberPayCodeRef */
        
        <M-33 run UpdateBankNumberAndPayCode
           (input  tBankNumberRefDebtor (t_sBankNumberRef), 
            input  tDBankNumberPayCodeRef (t_sBankNumberPayCodeRef), 
            input  tBankNumberSectionRefDebtor (t_sBankNumberSectionRef), 
            output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
        if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
        if viLocalReturnStatus < 0 then leave MAIN_BLOCK.
    end. /* if can-find (first tBankNumberRefDebtor where  */
        
    /* ===================================================================================== *
     * Replicate to operationals                                                             *
     * ===================================================================================== */
    empty temp-table tDebtorsToReplicate.

    <M-57 run IsOperationalReplicationEnabled
       (output vlReplicationEnabled (olReplicationEnabled), 
        output viFcReturnSuper (oiReturnStatus)) in BDebtor>
    if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
    if viLocalReturnStatus < 0 then leave MAIN_BLOCK.          
    
    if vlReplicationEnabled = true
    then do:
        for each tDebtor:
            if tDebtor.tc_status = "N":U or tDebtor.tc_status = "D":U
            then do:
                create tDebtorsToReplicate.
                buffer-copy tDebtor to tDebtorsToReplicate.
            end.
            else if tDebtor.tc_status = "C":U
            then do:
                for first t_iDebtor where
                          t_iDebtor.tc_rowid = tDebtor.tc_rowid:

                    if t_iDebtor.tcCurrencyCode               <> tDebtor.tcCurrencyCode or 
                       t_iDebtor.tcDebtorTypeCode             <> tDebtor.tcDebtorTypeCode or
                       t_iDebtor.DebtorIsInvoiceByAuth        <> tDebtor.DebtorIsInvoiceByAuth or
                       t_iDebtor.tcBillToDebtorCode           <> tDebtor.tcBillToDebtorCode or
                       t_iDebtor.DebtorIsActive               <> tDebtor.DebtorIsActive or
                       t_iDebtor.tcBillToDebtorCode           <> tDebtor.tcBillToDebtorCode or
                       t_iDebtor.tcNormalPaymentConditionCode <> tDebtor.tcNormalPaymentConditionCode or
                       t_iDebtor.TxzTaxZone                   <> tDebtor.TxzTaxZone or
                       t_iDebtor.txclTaxcls                   <> tDebtor.txclTaxcls or
                       t_iDebtor.TxuTaxUsage                  <> tDebtor.TxuTaxUsage or
                       t_iDebtor.DebtorTaxIDFederal           <> tDebtor.DebtorTaxIDFederal or
                       t_iDebtor.DebtorTaxIDState             <> tDebtor.DebtorTaxIDState or
                       t_iDebtor.DebtorTaxIDMisc1             <> tDebtor.DebtorTaxIDMisc1 or
                       t_iDebtor.DebtorTaxIDMisc2             <> tDebtor.DebtorTaxIDMisc2 or
                       t_iDebtor.DebtorTaxIDMisc3             <> tDebtor.DebtorTaxIDMisc3 or
                       t_iDebtor.DebtorIsTaxable              <> tDebtor.DebtorIsTaxable or
                       t_iDebtor.DebtorIsTaxIncluded          <> tDebtor.DebtorIsTaxIncluded or
                       t_iDebtor.DebtorIsTaxInCity            <> tDebtor.DebtorIsTaxInCity
                    then do: 
                        create tDebtorsToReplicate.
                        buffer-copy tDebtor to tDebtorsToReplicate.
                    end. /* end values chaged*/
                end.  /* end for first t_iDebtor */
            end. /* end changed customer */
        end.
    
        if can-find(first tDebtorsToReplicate)
        then do:    
            if viBMfgCustomerID = 0 or
               viBMfgCustomerID = ?
            then do:            
                <I-23 {bFcStartAndOpenInstance
                &ADD-TO-TRANSACTION = "true"
                &CLASS              = "BMfgCustomer"}>     
            end.
            else do:
                <I-27 {bFcOpenInstance
                &CLASS           = "BMfgCustomer"}>    
            end.
            assign vlBMfgCustomerStarted = true.
                                          
            <M-56 run ApiReplicateFromFinancials
               (input  tDebtorsToReplicate (tDebtor), 
                input  '':U (icDomainCode), 
                input  vlIsKeepInstOpenBDebtor (ilIsKeepInstancesOpen), 
                output viFcReturnSuper (oiReturnStatus)) in BMfgCustomer>                          
            if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
            if viLocalReturnStatus < 0 then leave MAIN_BLOCK. 
        end.
    
        /* Actions for deleted debtors */
        if can-find (first tDebtor where
                           tDebtor.tc_Status = "D":U)
        then do :                       
            /* Start and open instance of DebtorShipto */
            if viBDebtorShiptoID = 0 or 
               viBDebtorShiptoID = ?
            then do:
                  <I-38 {bFcStartAndOpenInstance
                       &ADD-TO-TRANSACTION   = "true"
                       &CLASS                = "BDebtorShipTo"}>
            end.
            else do:
                <I-39 {bFcOpenInstance
                     &CLASS           = "BDebtorShipTo"}>
            end.    

            /* Start and open instance of DebtorEndUser */
            if viBDebtorEndUserID = 0 or 
               viBDebtorEndUserID = ?
            then do:
               <I-40 {bFcStartAndOpenInstance
                    &ADD-TO-TRANSACTION   = "true"
                    &CLASS                = "BDebtorEndUser"}>
            end.
            else do:
                 <I-41 {bFcOpenInstance
                      &CLASS           = "BDebtorEndUser"}>
            end.
            
            for each tDebtor where
                     tDebtor.tc_Status = "D":U:
                     
                /* Call BDebtorShipto: ApiDeleteShiptoForDebtor to delete record.*/
                <M-42 run ApiDeleteShiptoForDebtor
                   (input  tDebtor.Debtor_ID (iiDebtorId), 
                    input  vlIsKeepInstOpenBDebtor (ilIsKeepInstancesOpen), 
                    output viFcReturnSuper (oiReturnStatus)) in BDebtorShipTo>
                if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
                if viLocalReturnStatus < 0 then leave MAIN_BLOCK.
                    
                /* Delete DebtorEndUser record */
                <M-43 run ApiDeleteEndUserForDebtor
                   (input  tDebtor.Debtor_ID (iiDebtorId), 
                    input  vlIsKeepInstOpenBDebtor (ilIsKeepInstancesOpen), 
                    output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
                if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
                if viLocalReturnStatus < 0 then leave MAIN_BLOCK.

            end. /* for each tDebtor */
        end. /* if can-find (first tDebtor where */
    end. /* end vlreplicationenabled */
    
    if not vlIsKeepInstOpenBDebtor
    then do:
        if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
    end.
   
    /*
     * Note that processing of e-mail notifications must occur after any
     * other processing, such as replication to MFG/PRO tables, since
     * e-mails should only be sent if there were not errors encountered
     * (oiReturnStatus >= 0).
     */
    if viLocalReturnStatus >= 0 and 
       can-find (first tDebtor where 
                       tDebtor.tc_Status = "N":U)
    then do:
        /* Process newly created customers to send e-mail notifications */
        <I-32 {bFcStartAndOpenInstance
             &ADD-TO-TRANSACTION = "'false':U"
             &CLASS              = "MfgNotification"}>

        for each tDebtor where 
                 tDebtor.tc_Status = "N":U:
            <M-34 run ProcessMfgNotification
               (input  viCompanyId (iiComponentCompanyID), 
                input  'CUSTOMER':U (icComponentType), 
                input  tDebtor.DebtorCode + '(' + tDebtor.tcBusinessRelationName1 + ')' (icBusinessKeys), 
                output viFcReturnSuper (oiReturnStatus)) in MfgNotification>
            if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
            if viLocalReturnStatus < 0 then leave MAIN_BLOCK.
        end.
    end. /* if oiReturnStatus >= 0  and */
    
    /* ========================================================================== *
     * Execute ancestor code                                                      *
     * ========================================================================== */
    assign oiReturnStatus = 0.
    <ANCESTOR-CODE>
    if oiReturnStatus < 0 or oiReturnStatus > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = oiReturnStatus.
    assign oiReturnStatus = -98.
    if viLocalReturnStatus < 0 then leave MAIN_BLOCK.
end. /* of MAIN_BLOCK */    

/* ============================================================== *
 * Close opened instances - needed before save                    *
 * ============================================================== */

if valid-handle(vhMfgNotification6Inst)
then do:
    <I-10 {bFcCloseAndStopInstance
         &CLASS           = "MfgNotification"}>
end.

if not vlIsKeepInstOpenBDebtor
then do:
    <M-49 run CloseExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BDebtor>
    if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
end.

if viLocalReturnStatus < 0
then do:
    <M-44 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BDebtor>
end.

/* ======================== */
/* Set ReturnStatus = OK    */
/* ======================== */
assign oiReturnStatus = viLocalReturnStatus.