project QadFinancials > class BDebtorShipTo > method AdditionalUpdates

Description

This empty method allows to do additional updates on class temp-tables after records were received (and validated) from outside, using method SetPublicTables.
You can start instances of other business classes to do those updates.


Parameters


oiReturnStatusoutputinteger


Internal usage


QadFinancials
method BDebtorShipTo.ApiCreateDebtorShipto
method BDebtorShipTo.ApiDeleteShiptoForDebtor
method BDebtorShipTo.ApiMaintainDebtorShipto


program code (program/bdebtorshipto.p)

MAIN_BLOCK:
do on error undo, leave MAIN_BLOCK:

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

    assign viLocalReturnStatus = 0
           oiReturnStatus      = -98.
    
    /* ======================================================================== *
     * Replication of the addresses                                             *
     *   is needed only, when the new address is created, in this case a new    *
     *   address has to be created in the Operational database                  *
     *   But if the ship-to address is linked to another Customer or to         *
     *   another ship-to or another End-user, then address records in Operatio- *
     *   nal database exists already                                            *
     * ======================================================================== */
    if can-find(first tDebtorShipTo where
                      tDebtorShipTo.DebtorShipToIsDebtor <> false or
                      (tDebtorShipTo.Debtor_ID           <> 0 and
                       tDebtorShipTo.Debtor_ID           <> ?))
    then do:
        /* open/start the BMfgAddress component */
        if viBMfgAddress2ID = 0 or
           viBMfgAddress2ID = ?
        then do:    
            <I-1 {bFcStartAndOpenInstance
                    &ADD-TO-TRANSACTION = "true"
                    &CLASS              = "BMfgAddress"}>    
            assign vlIsBMfgAddressStartedHr = true
                   vlIsBMfgAddressOpenedHr  = true.
        end.
        else if not valid-handle(vhBMfgAddress2Inst)
        then do:
            <I-6 {bFcOpenInstance
                 &CLASS           = "BMfgAddress"}>
            assign vlIsBMfgAddressOpenedHr = true.
        end.
        <M-54 run ApiReplicateFromFinancialsShipTo
           (input  tDebtorShipTo (tDebtorShiptosToUpdate), 
            input  ? (icDomainCode), 
            input  viBBusinessRelation1ID (iiBBusinessRelationID), 
            input  vhBBusinessRelation1Inst (ihBBusinessRelationInst), 
            output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
        if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then leave MAIN_BLOCK.
    end.
    
    /* Replicate Address list table */
    if viBMfgAddressListDetail6ID = 0 or
       viBMfgAddressListDetail6ID = ?
    then do:
        <I-7 {bFcStartAndOpenInstance
                &ADD-TO-TRANSACTION = "true"
                &CLASS              = "BMfgAddressListDetail"}>
        assign vlIsBMfgAddressListStartedHr = true
               vlIsBMfgAddressListOpenedHr  = true.
    end.
    else if not valid-handle(vhBMfgAddressListDetail6Inst)
    then do:
        <I-8 {bFcOpenInstance
             &CLASS           = "BMfgAddressListDetail"}>
        assign vlIsBMfgAddressListOpenedHr  = true.
    end.
    <M-32 run ApiReplicateFromFinancialsShipTo
       (input  tDebtorShipTo (tDebtorShiptosToUpdate2), 
        input  ? (icDomainCode), 
        output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>

    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 tApiShiptoAddress.
    empty temp-table tApiShiptoContact.

    shipto:
    for each tDebtorShipto where 
             (tDebtorShipto.tc_Status = "D" or tDebtorShipto.tc_status = "C") and
             not tDebtorShipto.DebtorShiptoIsDebtor                           and
             (tDebtorShipTo.DebtorEndUser_ID = 0 or tDebtorShipTo.DebtorEndUser_ID = ?):
        if tDebtorShipto.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_iDebtorShipto where t_iDebtorShipto.tc_rowid = tDebtorShipto.tc_rowid no-error.
            if not available (t_iDebtorShipto)
            then do:
                assign 
                   vcMessageText = #T-66'Cannot load original shipto record':255(132766020)T-66#
                   oireturnstatus = -1.
                    <M-48 run SetMessage
                       (input  vcMessageText (icMessage), 
                        input  '' (icArguments), 
                        input  '' (icFieldName), 
                        input  '' (icFieldValue), 
                        input  'E' (icType), 
                        input  3 (iiSeverity), 
                        input  tDebtorShipto.tc_rowid (icRowid), 
                        input  'qadfin-270617':U (icFcMsgNumber), 
                        input  '' (icFcExplanation), 
                        input  '' (icFcIdentification), 
                        input  '' (icFcContext), 
                        output viFcReturnsuper (oiReturnStatus)) in BDebtorShipTo>
                    return.
            end.   /* end of if t_iDebtgor#Shipto */    
            if t_iDebtorShipto.address_id = tDebtorShipTo.Address_ID
            then next shipto.            
            assign viAddressToDelete =  t_iDebtorShipTo.Address_ID.            
        end.
        else assign viAddressToDelete = tDebtorShipTo.Address_ID.        

        /* check to see if the address is in use by another end user */
        <Q-24 assign vlFcQueryRecordsAvailable = DebtorShiptoByAddress (NoCache)
           (input viCompanyId, (CompanyId)
            input viAddressToDelete, (AddressID)
            input tDebtorShipTo.DebtorShipTo_ID, (DebtorShiptoIDDifferentFrom)) in BDebtorShipTo>    
                
        /* If its not in use then go ahead and delete the address */
        if vlFcQueryRecordsAvailable = false
        then do:
            /* is there address to delete*/
            create tApiShiptoAddress.
            assign tApiShiptoAddress.BusinessRelation_ID = tDebtorShipto.tiBusinessRelation_ID
                   tApiShiptoAddress.Address_ID          = viAddressToDelete
                   tApiShiptoAddress.tc_Status           = "D".
       end.
    end.
    
    /* if we have a least one address to delete then call the api */
    if can-find (first tApiShiptoAddress)
    then do:
        /* Set a variable so the business relation component knows it can delete an enduser address */
        <I-80 {bFcOpenInstance
             &CLASS           = "Session"}>
        <M-75 run SetLogicalValue
           (input  'ShiptoAddressDelete':U (icName), 
            input  true (ilValue), 
            output viFcReturnSuper (oiReturnStatus)) in Session>
         
        if viBBusinessRelation1ID = 0 or
           viBBusinessRelation1ID = ?
        then do: 
            <I-26 {bFcStartAndOpenInstance
                 &ADD-TO-TRANSACTION   = "true"
                 &CLASS                = "BBusinessRelation"}>
            assign vlIsBBusinessRelationStartedHr = true
                   vlIsBBusinessRelationOpenedHr  = true.
        end.
        else if not valid-handle(vhBBusinessRelation1Inst)
        then do:
            <I-51 {bFcOpenInstance
                 &CLASS           = "BBusinessRelation"}>
            assign vlIsBBusinessRelationOpenedHr = true.
        end.  /* end if viBBusinessRelation1ID */


        empty temp-table tApiShiptoBusinessRelation.
        
        for each tApiShiptoAddress
            break by tApiShiptoAddress.BusinessRelation_ID: 
            
            if first-of(tApiShiptoAddress.BusinessRelation_ID)
            then do:
                create tApiShiptoBusinessRelation.
                assign tApiShiptoBusinessRelation.BusinessRelation_ID = tApiShiptoAddress.BusinessRelation_ID
                       tApiShiptoBusinessRelation.tc_Rowid            = string(tApiShiptoAddress.BusinessRelation_ID)
                       tApiShiptoAddress.tc_ParentRowid               = tApiShiptoBusinessRelation.tc_Rowid.                
            end.                   
        end. 
        
        /* Create/update the address in the Businress Relation */
        <M-5 run MaintainAddressMulti
           (input-output tApiShiptoBusinessRelation (tApiBusinessRelation), 
            input-output tApiShiptoAddress (tApiAddress), 
            input-output tApiShiptoContact (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-22 run SetLogicalValue
           (input  'ShiptoAddressDelete' (icName), 
            input  false (ilValue), 
            output viFcReturnSuper (oiReturnStatus)) in Session>
    end.

    
    /*Call MFG/PRO API to delete Supplier Profile in Operational Side*/
    for each tDebtorShipto where tDebtorShipto.tc_Status = "D":U:
        
        /*Get Domain List for using the same Customer Sharedset*/
        <Q-90 run DomainByDomainSharedSet (all) (Read) (NoCache)
           (input ?, (DomainID)
            input tDebtorShipTo.SharedSet_ID, (SharedSetID)
            input ?, (SharedSetCode)
            input ?, (SharedSetType)
            output dataset tqDomainByDomainSharedSet) in BDomain>

        for each tqDomainByDomainSharedSet:
            if viPMFGProfile11ID = 0 or 
                viPMFGProfile11ID = ?
            then do:
                <I-83 {bFcStartAndOpenInstance
                     &CLASS                = "PMFGProfile"}>
            end.
            else if not valid-handle(vhPMFGProfile11Inst)
            then do:
                <I-35 {bFcOpenInstance
                     &CLASS           = "PMFGProfile"}>
            end. 
            
            <M-86 run DeleteDebtorProfile
               (input  tDebtorShipTo.tcDebtorCode (icDebtorCode), 
                input  tDebtorShipTo.DebtorShipToCode (icDebtorShipTo), 
                input  tqDomainByDomainSharedSet.tcDomainCode (icCurrentDomain), 
                output viFcReturnSuper (oiReturnStatus)) in PMFGProfile>
            if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
            if viLocalReturnStatus < 0 then leave MAIN_BLOCK.
        end.
    end.
     
end.  /* of MAIN_BLOCK */

/* ============================================================== *
 * Close opened instances - needed before save                    *
 * ============================================================== */
if valid-handle(vhPMFGProfile11Inst)
then do:
<I-12 {bFcCloseAndStopInstance
     &CLASS           = "PMFGProfile"}> 
end.

if valid-handle(vhSessionInst)
then do:
    <I-21 {bFcCloseInstance
         &CLASS           = "Session"}>
end.

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

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

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