project QadFinancials > class BDebtorEndUser > method Calculate

Description

Add code here to initialize the calculated fields of the class temp-tables after loading existing records from the application database.


Parameters


oiReturnStatusoutputinteger


Internal usage


unused


program code (program/bdebtorenduser.p)

/* When doing multiple dataloads without clearing the instance, the code within the loop is performed much too many times. */
/* We will add the possibility to run the calculate method logic only once to gain performance.                            */
/* An example of this can be seen in DataLoadByInput.  Setting the class data item will determine whether to run the logic */

assign oiReturnStatus = -98
       viLocalStatus  = 0.

if vlCalculateSkip = false
then do:

    <ANCESTOR-CODE>
            
    for each tDebtorEnduser:   
    
        if vlDataLoadKeepPrevious and 
           can-find (tAlreadyCalculatedRecords where
                     tAlreadyCalculatedRecords.tcTableName = "DebtorEndUser" and
                     tAlreadyCalculatedRecords.tc_Rowid    = tDebtorEndUser.tc_Rowid)
        then next.

            /* Get the Businress Relation id for the Debtor and store it in the calculate field */
            <Q-5 run DebtorPrim (all) (Read) (Cache)
               (input viCompanyID, (CompanyId)
                input '', (DebtorCode)
                input tDebtorEnduser.debtor_id, (Debtor_ID)
                output dataset tqDebtorPrim) in BDebtor >
                   
    
            for first tqDebtorPrim:
                assign tDebtorEnduser.tiDebtorBusinessRelation_ID = tqDebtorPrim.tiBusinessRelation_ID.
            end.
     
            /* store the rowid of the current address if there is one*/
            if tDebtorEnduser.Address_id <> 0
            then do:               
                 <Q-50 run AddressPrim (all) (Read) (NoCache)
                    (input ?, (AddressCity)
                     input ?, (AddressStreet1)
                     input ?, (AddressStreet2)
                     input ?, (AddressZip)
                     input ?, (AddressTypeCode)
                     input tDebtorEndUser.address_id, (AddressID)
                     input ?, (BusinessRelationID)
                     input ?, (BusinessRelationCode)
                     input ?, (AddressTypeID)
                     input ?, (AddressStreet3)
                     output dataset tqAddressPrim) in BBusinessRelation >
                
                for first tqAddressPrim:
                    assign tDebtorEnduser.tcAddress_rowid = tqAddressPrim.tc_rowid.
                end.
             end.
             
            <Q-7 run ContactByAddress (all) (Read) (Cache)
               (input tDebtorEndUser.Address_ID, (AddressId)
                output dataset tqContactByAddress) in BBusinessRelation >
            for each tqContactByAddress where
                     tqContactbyAddress.tiAddress_id = tDebtorEndUser.Address_ID:
                if not can-find(tDebtorEndUserContact where tDebtorEndUserContact.Contact_ID = tqContactByAddress.tiContact_ID)
                then do:
                    create tDebtorEndUserContact.
                    <M-8 run BufferCopy
                       (input  buffer tqContactByAddress:handle (ihFrom), 
                        input  buffer tDebtorEndUserContact:handle (ihTo), 
                        output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
                    assign tDebtorEndUserContact.tc_ParentRowid = tDebtorEndUser.tc_Rowid.
                    if viFcReturnSuper <  0 or 
                       viFcReturnSuper <> 0 and 
                       viLocalStatus   =  0
                    then assign viLocalStatus = viFcReturnSuper.
                end.   
            end.
            
            /* Populate the tlAddressIsShared field - this indicates if the address is in use by other end users or not */           
            <Q-95 assign vlFcQueryRecordsAvailable = DebtorEndUserByAddress (NoCache)
               (input ?, (CompanyId)
                input tDebtorEndUser.address_ID, (AddressID)
                input tDebtorEndUser.DebtorEndUser_ID, (DebtorEndUserIDDifferentFro)) in BDebtorEndUser >
            if vlFcQueryRecordsAvailable <> false
            then
               assign tDebtorEndUser.tlAddressIsShared = true.
            
    end.

end. /* if vlCalculateSkip = false */

assign oiReturnStatus = viLocalStatus.