project QadFinancials > class BDebtor > method CalculateBalances


Parameters


iiDebtorIdinputinteger
icDebtorCodeinputcharacter
icCurrencyCodeinputcharacter
ilSalesOrdersinputlogical
ilOpenItemsinputlogical
ilDraftsinputlogicalinclude drafts ?
ilCreditOnTurnoverinputlogical
idPercentageOfTurnoverinputdecimal
odSOBalanceoutputdecimal
odOIBalanceoutputdecimal
odDraftBalanceoutputdecimal
odCreditOnTurnoveroutputdecimal
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDebtor.ApiCheckCreditLimit
method BDebtor.ApiGetARBalance
method BDebtor.ApiGetCreditDataV01
method BDebtorReport.DebtorMasterCard


program code (program9/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 or
    ilSalesOrders
then do:

    <Q-67 run DebtorForUpdate (all) (Read) (NoCache)
       (input if iiDebtorId = 0 then viCompanyId else ?, (CompanyId)
        input iiDebtorId, (DebtorID)
        input icDebtorCode, (DebtorCode)
        output dataset tqDebtorForUpdate) in BDebtor>

    find first tqDebtorForUpdate where
               tqDebtorForUpdate.tiDebtor_ID       = (if iiDebtorId = 0
                                                     then tqDebtorForUpdate.tiDebtor_ID
                                                     else iiDebtorId)                   and
               tqDebtorForUpdate.tcDebtorCode      = (if iiDebtorId = 0
                                                     then icDebtorCode
                                                     else Tqdebtorforupdate.tcDebtorCode)
               no-error.

    if not available tqDebtorForUpdate
    then return.

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

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

if iiDebtorId = 0
then return.

if ilSalesOrders
then do:
      
    if not available tqDebtorForUpdate 
    then return.

    if tqDebtorForUpdate.tcCurrencyCode = icCurrencyCode
    then assign odSOBalance = tqDebtorForUpdate.tdDebtorSalesOrderBalance.
    else do:
        <M-11 run CalculateBalanceSalesOrders
           (input  iiDebtorId (iiDebtorId), 
            input  icDebtorCode (icDebtorCode), 
            input  icCurrencyCode (icCurrencyCode), 
            output odSOBalance (odBalance), 
            output viFcReturnSuper (oiReturnStatus)) in BDebtor>
        if viFcReturnSuper < 0 or
        oiReturnStatus  = 0
        then assign oiReturnStatus = viFcReturnSuper.

        if oiReturnStatus < 0
        then return.
    end.
end.

if ilOpenItems
then do:

    <M-4 run CalculateBalanceOpenItems
       (input  iiDebtorId (iiDebtorId), 
        input  icDebtorCode (icDebtorCode), 
        input  icCurrencyCode (icCurrencyCode), 
        output odOIBalance (odBalance), 
        output viFcReturnSuper (oiReturnStatus)) in BDebtor>

    if viFcReturnSuper < 0 or
       oiReturnStatus  = 0
    then assign oiReturnStatus = viFcReturnSuper.

    if oiReturnStatus < 0
    then return.
end.

if ilDrafts
then do:
    <M-10 run CalculateBalanceDrafts
       (input  iiDebtorId (iiDebtorId), 
        input  icDebtorCode (icDebtorCode), 
        input  icCurrencyCode (icCurrencyCode), 
        output odDraftBalance (odBalance), 
        output viFcReturnSuper (oiReturnStatus)) in BDebtor>
    if viFcReturnSuper < 0 or oiReturnStatus  = 0
    then assign oiReturnStatus = viFcReturnSuper.
    if oiReturnStatus < 0 then return.
end.

if ilCreditOnTurnover
then do:
    <M-5 run CalculateCreditOnTurnover
       (input  iiDebtorId (iiDebtorId), 
        input  icDebtorCode (icDebtorCode), 
        input  icCurrencyCode (icCurrencyCode), 
        input  idPercentageOfTurnover (idPercentageOfTurnover), 
        output odCreditOnTurnover (odCreditOnTurnover), 
        output viFcReturnSuper (oiReturnStatus)) in BDebtor>

    if viFcReturnSuper < 0 or
       oiReturnStatus  = 0
    then assign oiReturnStatus = viFcReturnSuper.

    if oiReturnStatus < 0
    then return.
end.