project QadFinancials > class BDebtorEndUser > method AdditionalUpdates

Description

This method calls MaintainData in BMfgEndUser to replicate data to the eu_mstr and eud_det tables in mfg/pro.

If we are deleting an DebtorEndUser record delete the correpsonding address record in the business relation if it is not in use by another DebtorEndUser record.

If we a re creating a DebtorEndUser record, call ProcessMfgNotification in BMfgNotificiation. This will nodify any users who are associated with the EndUserNofify role that a new End User has been created.


Parameters


oiReturnStatusoutputinteger


Internal usage


QadFinancials
method BDebtorEndUser.ApiCreateDebtorEndUser
method BDebtorEndUser.ApiDeleteEndUserForDebtor
method BDebtorEndUser.ApiStdMaintainTT


program code (program/bdebtorenduser.p)

MAIN_BLOCK:
do on error undo, leave MAIN_BLOCK:

    <ANCESTOR-CODE>
    if oiReturnStatus < 0 then leave MAIN_BLOCK.

    assign viLocalReturnStatus = 0
           oiReturnStatus      = -98.

    /* Call the MaintainDataend User  in BMFGAddress to update the ad_mstr in mfgpro */
    if viBMfgEndUserID = 0 or
       viBMfgEndUserID = ?
    then do:
        <I-11 {bFcStartAndOpenInstance
                &ADD-TO-TRANSACTION = "true"
                &CLASS              = "BMfgEndUser"}>
        assign vlIsBMfgEndUserStartedHr = true
               vlIsBMfgEndUserOpenedHr  = true.
    end. /* if viBMfgEndUserID = 0 or ... */
    else if not valid-handle(vhBMfgAddress9Inst)
    then do:
        <I-12 {bFcOpenInstance
                &CLASS           = "BMfgEndUser"}>
        assign vlIsBMfgEndUserOpenedHr = true.
    end.  /* end if viBMfgAddress2ID */

    <M-86 run ApiReplicateFromFinancials
       (input  tDebtorEndUser (tDebtorEndUser), 
        input  '':U (icDomainCode), 
        input  viBBusinessRelation6ID (iiBBusinessRelationID), 
        input  vhBBusinessRelation6Inst (ihBBusinessRelationInst), 
        input  vlIsKeepInstancesOpen (ilIsKeepInstancesOpen), 
        output viFcReturnSuper (oiReturnStatus)) in BMfgEndUser>
    if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 then leave MAIN_BLOCK.
          
    /* Cleanup address if not used by any other end user.*/
    empty temp-table tApiEnduserAddress.
    empty temp-table tApiEnduserContact.

    enduser:
    for each t_sDebtorEndUser
        where   (t_sDebtorEndUser.tc_Status = "D" or t_sDebtorEndUser.tc_status = "C")
        and not t_sDebtorEndUser.DebtorEndUserIsDebtor 
        and not t_sDebtorEndUser.DebtorEndUserIsShipTo:

         if t_sDebtorEndUser.tc_status = "C"
         then do:
            /* If we are modifying a shipto we only want to clean up the old address if we have changed to a new address */
            find first t_iDebtorEndUser where t_iDebtorEndUser.tc_rowid = t_sDebtorEndUser.tc_rowid no-error.
            if not available (t_iDebtorEndUser)
            then do:
                assign 
                   vcMessageText = #T-55'Cannot load original end user record':255(957667740)T-55#
                   oireturnstatus = -1.
                <M-37 run SetMessage
                   (input  vcMessageText (icMessage), 
                    input  '' (icArguments), 
                    input  '' (icFieldName), 
                    input  '' (icFieldValue), 
                    input  'E' (icType), 
                    input  3 (iiSeverity), 
                    input  t_sDebtorEndUser.tc_rowid (icRowid), 
                    input  'qadfin-878556':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnsuper (oiReturnStatus)) in BDebtorEndUser>
                return.
            end.   /* end of if t_iDebtgor#Shipto */    

            if t_iDebtorEndUser.address_id = t_sDebtorEndUser.address_id 
            then next enduser.    
            
            assign viAddressToDelete =  t_iDebtorEndUser.address_id.                                

        end. /* if t_sDebtorEndUser.tc_status = "C" */
        else assign viAddressToDelete = t_sDebtorEndUser.address_id.
                      
        <Q-40 assign vlFcQueryRecordsAvailable = DebtorEndUserForDelete (NoCache)
           (input t_sDebtorEndUser.DebtorEndUser_Id, (iDebtorEndUserID)
            input viCompanyId, (CompanyID)
            input viAddressToDelete, (iiAddressID)) in BDebtorEndUser >
                        
        /* Check to see if the address is in use by another end user */
        for first bDebtorEndUser
            where bDebtorEndUser.address_id        = viAddressToDelete
            and   bDebtorEndUser.DebtorEndUser_ID <> t_sDebtorEndUser.DebtorEndUser_ID:
        end. /* for first bDebtorEndUser */

        /* If its not in use then go ahead and delete the address */
        if vlFcQueryRecordsAvailable = false 
            and not available(bDebtorEndUser)
        then do:

            /* Is there address to delete*/
            create tApiEndUserAddress.
            assign
                tApiEnduserAddress.BusinessRelation_ID = t_sDebtorEndUser.tiAddressBusinessRelation_ID
                tApiEndUserAddress.address_id          = viAddressToDelete
                tApiEnduserAddress.tcAddressTypeCode   = {&ADDRESSTYPECODESYSTEM-ENDUSER}
                tApiEndUserAddress.tc_status           = "D".

        end. /* if vlFcQueryRecordsAvailable = false */                  
    end.     /* for each t_sDebtorEndUser            */

    /* If we have a least one end user address to delete then call the api */
    if can-find (first tApiEndUserAddress)
    then do:
        /* Set a variable so the business relation component knows it can delete an enduser address */
        if not valid-handle(vhSessionInst)
        then do:
            <I-28 {bFcOpenInstance
                 &CLASS           = "Session"}>
        end. /* if not valid-handle(vhSessionInst) */

        <M-29 run SetLogicalValue
           (input  'EndUserAddressDelete' (icName), 
            input  true (ilValue), 
            output viFcReturnSuper (oiReturnStatus)) in Session>
        
        if viBBusinessRelation6ID = 0 or
           viBBusinessRelation6ID = ?
        then do: 
            <I-19 {bFcStartAndOpenInstance
                 &ADD-TO-TRANSACTION   = "true"
                 &CLASS                = "BBusinessRelation"}>
            assign vlIsBBusinessRelationStartedHr = true
                   vlIsBBusinessRelationOpenedHr  = true.
        end. /* if viBBusinessRelation6ID = 0 or */
        else if not valid-handle(vhBBusinessRelation6Inst)
        then do:         
            <I-90 {bFcOpenInstance
                 &CLASS           = "BBusinessRelation"}>
            assign vlIsBBusinessRelationOpenedHr  = true.
        end.  /* end if viBBusinessRelation1ID */    

        empty temp-table tApiEndUserBusinessRelation.
        
        for each tApiEndUserAddress
            break by tApiEndUserAddress.BusinessRelation_ID: 
            
            if first-of(tApiEndUserAddress.BusinessRelation_ID)
            then do:
         
                create tApiEndUserBusinessRelation.
                assign                
                    tApiEndUserBusinessRelation.BusinessRelation_id = tApiEndUserAddress.BusinessRelation_ID
                    tApiEndUserBusinessRelation.tc_rowid = string(tApiEndUserAddress.BusinessRelation_ID).
                           
                assign tApiEndUserAddress.tc_ParentRowid = tApiEndUserBusinessRelation.tc_Rowid.                
                 
            end. /* if first-of(tApiEndUserAddress.BusinessRelation_ID) */
        end.     /* for each tApiEndUserAddress                         */

        /* Create/update the address in the Businress Relation */
        <M-74 run MaintainAddressMulti
           (input-output tApiEndUserBusinessRelation (tApiBusinessRelation), 
            input-output tApiEndUserAddress (tApiAddress), 
            input-output tApiEndUserContact (tApiContact), 
            output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
        if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then leave MAIN_BLOCK.   
        
       /* Reset the end user address delete variable */
        <M-32 run SetLogicalValue
           (input  'EndUserAddressDelete' (icName), 
            input  false (ilValue), 
            output viFcReturnSuper (oiReturnStatus)) in Session>
    end. /* End address to delete */

    /* ================================================================== *
     * 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
    then do:
        /* Send e-mail notifications for newly created end users */
        <I-18 {bFcStartAndOpenInstance
                &ADD-TO-TRANSACTION = "'no':U"
                &CLASS              = "MfgNotification"}>
            
        for each tDebtorEndUser where 
                 tDebtorEndUser.tc_Status = "N":U:
                
            <M-20 run ProcessMfgNotification
               (input  viCompanyId (iiComponentCompanyID), 
                input  'ENDUSER':U (icComponentType), 
                input  tDebtorEndUser.DebtorEndUserCode (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. /* for each tDebtorEndUser where */
    end.     /* if viLocalReturnStatus >= 0   */
end.         /* of MAIN_BLOCK                 */
    
/* ============================================================== *
 * Close opened instances - needed before save                    *
 * ============================================================== */
if valid-handle(vhSessionInst)
then do:
    <I-97 {bFcCloseInstance
         &CLASS           = "Session"}>
end. /* if valid-handle(vhSessionInst) */
    
if valid-handle(vhMfgNotification8Inst)
then do:
    <I-54 {bFcCloseAndStopInstance
            &CLASS           = "MfgNotification"}>        
end. /* if valid-handle(vhMfgNotification8Inst) */

if not vlIsKeepInstancesOpen
then do:
    <M-17 run CloseExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
    if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
end. /* if not vlIsKeepInstancesOpen */

if viLocalReturnStatus < 0
then do:
    <M-13 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
end. /* if viLocalReturnStatus < 0 */

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