project QadFinancials > class BDebtor > method CalculateBSOForCompany


Parameters


iiDebtorIdinputinteger
icDebtorCodeinputcharacter
icCurrencyCodeinputcharacter
odBalanceoutputdecimal
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program6/bdebtor.p)

if iiDebtorId     = ? then assign iiDebtorId     = 0.
if icDebtorCode   = ? then assign icDebtorCode   = "":U.
if icCurrencyCode = ? then assign icCurrencyCode = "":U.

if iiDebtorId   = 0 and
   icDebtorCode = "":U
then return.

if iiDebtorId     = 0 or
   icCurrencyCode = "":U
then do:
    <Q-22 run DebtorByDebtor (all) (Read) (NoCache)
       (input if iiDebtorId = 0 then viCompanyId else ?, (CompanyId)
        input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
        input if iiDebtorId = 0 then ? else iiDebtorId, (DebtorId)
        input if iiDebtorId = 0 then icDebtorCode else ?, (DebtorCode)
        output dataset tqDebtorByDebtor) in BDebtor >

    find first tqDebtorByDebtor where
               tqDebtorByDebtor.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE} and
               tqDebtorByDebtor.tiDebtor_ID       = (if iiDebtorId = 0
                                                     then tqDebtorByDebtor.tiDebtor_ID
                                                     else iiDebtorId)                   and
               tqDebtorByDebtor.tcDebtorCode      = (if iiDebtorId = 0
                                                     then icDebtorCode
                                                     else tqDebtorByDebtor.tcDebtorCode)
               no-error.

    if not available tqDebtorByDebtor
    then return.

    if iiDebtorId = 0
    then assign iiDebtorId = tqDebtorByDebtor.tiDebtor_ID.

    if icCurrencyCode = "":U
    then assign icCurrencyCode = tqDebtorByDebtor.tcCurrencyCode.
end.

if iiDebtorId = 0
then return.

<Q-18 run DebtorForCreditData (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input ?, (DebtorID)
    input icDebtorCode, (DebtorCode)
    output dataset tqDebtorForCreditData) in BDebtor >
find first tqDebtorForCreditData no-error.
if available tqDebtorForCreditData
then do:    
    assign odBalance = tqDebtorForCreditData.tdDebtorSalesOrderBalance.
    
    /* If the currency of the customer changed recaculate the Sales Order balance */
    if tqDebtorForCreditData.tcCurrencyCode <> icCurrencyCode
    then do:
        <M-1 run GetExchangeRate
           (input  viCompanyId (iiCompanyID), 
            input  ? (iiFromCurrencyID), 
            input  tqDebtorForCreditData.tcCurrencyCode (icFromCurrencyCode), 
            input  ? (iiToCurrencyID), 
            input  icCurrencyCode (icToCurrencyCode), 
            input  ? (iiExchangeRateTypeID), 
            input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode), 
            input  today (itValidityDate), 
            output vdRate (odExchangeRate), 
            output vdRateScale (odExchangeScaleFactor), 
            output viFcReturnSuper (oiReturnStatus)) in BDebtor>
        if viFcReturnSuper < 0 or
           oiReturnStatus  = 0
        then assign oiReturnStatus = viFcReturnSuper.

        if oiReturnStatus < 0
        then return.

        odBalance =  <M-20 RoundAmount
                        (input  odBalance * vdRate * vdRateScale (idUnroundedAmount), 
                         input  0 (iiCurrencyID), 
                         input  icCurrencyCode (icCurrencyCode)) in BDebtor>.
    end.
end.