project QadFinancials > class BJournalEntryMultiCy > method ApiCreateCrossCyPostings

Description

This is the method which is run when excel integration form is saved from the UI. This method receives the temptables used to create cross-company Journal Entries.

The method performs the following:
1. Defaulting
2. Validation
3. Create cross company posting lines
4. Posting cross company postings, on transaction at a time.


Parameters


tPostingHeaderMultiCyinput-outputtemp-table
tPostingMultiCyinputtemp-table
tPostingLineMultiCyinputtemp-table
tPostingSafMultiCyinputtemp-table
tPostingVatMultiCyinputtemp-table
tPostingVatDelayMultiCyinputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program9/bjournalentrymulticy.p)

/* ================================================================ */
/* This method receives the temptables used to create cross-company */
/* Journal Entries.                                                 */
/* The method performs the following:                               */
/*    1. Defaulting                                                 */
/*    2. Validation                                                 */
/*    3. Create cross company posting lines                         */
/*    4. Posting cross company postings                             */
/* ================================================================ */

/* ===================================================================== */
/* 1. Default the data from header-record to detail-records where needed */
/* ===================================================================== */
<M-69 run ApiCreateCrossCyPostingsApplyCCyDefaults  (output viFcReturnSuper (oiReturnStatus)) in BJournalEntryMultiCy>
if viFcReturnSuper <> 0 
then assign oiReturnStatus = viFcReturnSuper.

/* =================================================================== */
/*  2. Process the incoming data                                       */
/* =================================================================== */    
<M-75 run ApiProcessIncomingData  (output viFcReturnSuper (oiReturnStatus)) in BJournalEntryMultiCy>
if viFcReturnSuper <> 0 
then do:
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
    then assign oiReturnStatus = viFcReturnSuper.
end.    
if oiReturnStatus < 0
then return.

/* ============================================================================= */
/* 3. Finally, call the method to post the transactions - the transaction scope  */
/* is at the level of posting header.                                            */
/* ============================================================================= */
for each tPostingHeaderMultiCy where
         tPostingHeaderMultiCy.tlPostingHeaderIsPosted = false 
         on error undo, throw:

   /* ==================================================================== */
   /* 3.1 Copy the data from the input tables into the BPosting tables     */
   /* ==================================================================== */
    empty temp-table tPostingOneTrx.
    empty temp-table tPostingLineOneTrx.
    empty temp-table tPostingSafOneTrx.
    empty temp-table tPostingVatOneTrx.
    empty temp-table tPostingVatDelayOneTrx.     
    empty temp-table tCompaniesInvolved.
    
    for each tPostingMultiCy where
             tPostingMultiCy.tc_parentrowid = tPostingHeaderMultiCy.tc_rowid 
             on error undo, throw:

        create tPostingOneTrx.
        buffer-copy tPostingMultiCy to tPostingOneTrx.
       
        /* ================================================================ */
        /* build up a list of companies in the postings - this will be used */
        /* in CreateMultiCyPostings to ensure the first posting is the one  */
        /* for the current entity                                           */
        /* ================================================================ */
        find first tCompaniesInvolved where 
                   tCompaniesInvolved.tiCompanyId = tPostingOneTrx.Company_ID 
                   no-error.
        if not available tCompaniesInvolved
        then do:
            create tCompaniesInvolved.
            assign tCompaniesInvolved.tiCompanyId = tPostingOneTrx.Company_ID
                   tCompaniesInvolved.tcCompanyCode = tPostingMultiCy.tcCompanyCode
                   tCompaniesInvolved.tiCompanySort = if tCompaniesInvolved.tiCompanyId = viCompanyId 
                                                      then 1
                                                      else 0.
         end. /* if not available tCompaniesInvolved */
        
        /* ================================================================ */
        /* copy all the child tables                                        */
        /* ================================================================ */
        for each tPostingLineMultiCy where
                 tPostingLineMultiCy.tc_parentrowid = tPostingMultiCy.tc_rowid 
                 on error undo, throw:

            create tPostingLineOneTrx.
            buffer-copy tPostingLineMultiCy to tPostingLineOneTrx. 
           
            for each tPostingSafMultiCy where
                     tPostingSafMultiCy.tc_parentrowid = tPostingLineMultiCy.tc_rowid 
                     on error undo, throw:
                create tPostingSafOneTrx.
                buffer-copy tPostingSafMultiCy to tPostingSafOneTrx.                   
            end. /* for each tPostingSafMultiCy */
           
            for each tPostingVatMultiCy where
                     tPostingVatMultiCy.tc_parentrowid = tPostingLineMultiCy.tc_rowid 
                     on error undo, throw:
                create tPostingVatOneTrx.
                buffer-copy tPostingVatMultiCy to tPostingVatOneTrx.
            end. /* for each tPostingVatMultiCy */            
           
            for each tPostingVatDelayMultiCy where
                     tPostingVatDelayMultiCy.tc_parentrowid = tPostingLineMultiCy.tc_rowid 
                     on error undo, throw:
                create tPostingVatDelayOneTrx.
                buffer-copy tPostingVatDelayMultiCy to tPostingVatDelayOneTrx.
            end. /* for each tPostingVatDelayMultiCy */

        end. /* for each tPostingLineMultiCy */
       
    end. /* for each tPostingMultiCy */
    
   /* ==================================================================== */
   /* 3.2 Call method to create the postings for each transaction          */
   /* ==================================================================== */
    <M-1 run CreateMultiCyPostings
       (input  tPostingOneTrx (tPostingOneTrx), 
        input  tPostingLineOneTrx (tPostingLineOneTrx), 
        input  tPostingSafOneTrx (tPostingSafOneTrx), 
        input  tPostingVatOneTrx (tPostingVatOneTrx), 
        input  tPostingVatDelayOneTrx (tPostingVatDelayOneTrx), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntryMultiCy>
    if viFcReturnSuper <> 0 
    then do:
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
        then assign oiReturnStatus = viFcReturnSuper.
    end. /* if viFcReturnSuper <> 0 */ 

    assign tPostingHeaderMultiCy.tlPostingHeaderIsPosted = if viFcReturnSuper < 0 
                                                           then false
                                                           else true.

end. /* for each tPostingHeaderMultiCy */

finally:
    empty temp-table tPostingOneTrx.
    empty temp-table tPostingLineOneTrx.
    empty temp-table tPostingSafOneTrx.
    empty temp-table tPostingVatOneTrx.
    empty temp-table tPostingVatDelayOneTrx.     
    empty temp-table tCompaniesInvolved.
end finally.