project QadFinancials > class BBankEntry > method GetPostingAmount


Parameters


iiBJournalEntryIdinputinteger
iiPostingIdinputinteger
odPostingAmountLCoutputdecimal
odPostingAmountTCoutputdecimal
ocCurrencyCodeoutputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program3/bbankentry.p)

    /* ======================================================================================== */
    /* If an instance of BJournalEntry is started, then the instance contains all information   */
    /* If no instance of BJournalEntry is started yet, then we retrieve the information from db */
    /* Only 1 of both options can be used at the same time!                                     */
    /* ======================================================================================== */
    
    /* ====================== */
    /* replace unknown values */
    /* ====================== */
    if iiBJournalEntryId = ? then assign iiBJournalEntryId = 0.
    if iiPostingId = ? then assign iiPostingId = 0.
    assign viBJournalEntryBEID = iiBJournalEntryId.

    /* =========================== */
    /* if no posting id, then zero */
    /* =========================== */
    if iiPostingId = 0
    then do:
        assign odPostingAmountLC = 0
               odPostingAmountTC = 0
               ocCurrencyCode  = "":U.
        return.
    end.
    
    /* ================= */
    /* Get info from DB  */
    /* ================= */
    if viBJournalEntryBEID = 0 
    then do :
        <Q-60 run PostingLineByPostingId (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input iiPostingId, (PostingId)
            input ?, (GLSystemTypeCode)
            input ?, (GLTypeCode)
            output dataset tqPostingLineByPostingId) in BPosting >
        
        assign vcCurrencyCode =  "":U.
        
        /* loop to check if all posting lines have same currency else return blank*/
        for each tqPostingLineByPostingId : 

          if vcCurrencyCode <> tqPostingLineByPostingId.tcCurrencyCode and
             vcCurrencyCode <> "":U
          then do:
              assign vcCurrencyCode = "":U.
              leave.
          end.    

          assign vcCurrencycode = tqPostingLineByPostingId.tcCurrencyCode.
        
        end.



        for each tqPostingLineByPostingId : 
                            
            accumulate tqPostingLineByPostingId.tdPostingLineDebitLC(TOTAL).
            accumulate tqPostingLineByPostingId.tdPostingLineCreditLC(TOTAL).
            accumulate tqPostingLineByPostingId.tdPostingLineDebitTC(TOTAL).
            accumulate tqPostingLineByPostingId.tdPostingLineCreditTC(TOTAL).

        end.
        
        
        assign odPostingAmountLC = (accum total tqPostingLineByPostingId.tdPostingLineDebitLC) - (accum total tqPostingLineByPostingId.tdPostingLineCreditLC)
               odPostingAmountTC = (accum total tqPostingLineByPostingId.tdPostingLineDebitTC) - (accum total tqPostingLineByPostingId.tdPostingLineCreditTC).
               ocCurrencyCode    = vcCurrencyCode.
        return.
    end. /* if viBJournalEntryBEID = 0 */
    
    /* ======================= */
    /* Get info from Instance  */
    /* ======================= */
    <I-61 {bFcOpenInstance
         &CLASS           = "BJournalEntry"}>
    <M-63 run GetPostingAmount
       (input  iiPostingId (iiPostingId), 
        output vdPostingAmountDebitLC (odPostingAmountDebitLC), 
        output vdPostingAmountCreditLC (odPostingAmountCreditLC), 
        output vdPostingAmountCreditTC (odPostingAmountCreditTC), 
        output vdDummy (odPostingAmountCreditCC), 
        output vdPostingAmountDebitTC (odPostingAmountDebitTC), 
        output vdDummy (odPostingAmountDebitCC), 
        output ocCurrencyCode (ocCurrencyCode), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    <I-40 {bFcCloseInstance
         &CLASS           = "BJournalEntry"}>
    if viFcReturnSuper <> 0
    then assign oiReturnStatus = viFcReturnSuper.
    if oiReturnStatus < 0 
    then do :
        assign vcMessage      = trim(substitute(#T-35'An error occurred when retrieving the posting amount: &1.':200(323)T-35#, string(viFcReturnSuper)))
               oiReturnStatus = -1. 
        <M-74 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'qadfin-31075':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
        return.
    end.
    if vdPostingAmountCreditLC <> ? and 
       vdPostingAmountDebitLC  <> ? and
       vdPostingAmountCreditTC <> ? and
       vdPostingAmountDebitTC  <> ?
    then assign odPostingAmountLC = vdPostingAmountDebitLC - vdPostingAmountCreditLC
                odPostingAmountTC = vdPostingAmountDebitTC - vdPostingAmountCreditTC.