project QadFinancials > class BBankEntry > method CalcAllSelectBankState

query calculated fields procedure

Description

Assign a value to query calculated fields


Parameters


iiCompanyIdinputintegerCompany id
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
query SelectBankState


program code (program1/bbankentry.p)

assign vcBankNumber = "":U
       viGLID       = 0
       vlStart1     = false.
assign vcBANKSTATESTATUSES ={&BANKSTATESTATUSES}.

create query vhQuery in widget-pool "non-persistent".
vhQuery:set-buffers(ih_Buffer).
vhQuery:query-prepare("for each ":U + ih_Buffer:table + " by ":U + ih_buffer:buffer-field("tiGL_ID":U):name).
vhQuery:query-open().
vhQuery:get-first().

do while not vhQuery:query-off-end:
    if not vlStart1
    then do:
        <Q-1 run BankNumberByParentCompany
           (Start) in BBankNumber >
       vlStart1 = true.
    end.

    if {&tiGL_ID} <> viGLID
    then do:
        <Q-24 run BankNumberByParentID (all) (Read) (NoCache)
           (input {&tiGL_ID}, (ParentObjectId)
            input ?, (BankNumberParentType)
            input ?, (BankNumberIsDefault)
            input iiCompanyID, (CompanyId)
            output dataset tqBankNumberByParentID) in BBankNumber>
            /*JBA extra conditions added plus a new search 'mechanism' implemented
            first try to find a default bank account 
            if no default bank account exists take the fist one*/
            find first tqBankNumberByParentID where 
                       tqBankNumberByParentID.tiParentObject_ID = {&tiGL_ID} and
                       tqBankNumberByParentID.tiCompany_ID = iiCompanyID     and 
                       tqBankNumberByParentID.tlBankNumberIsDefault = true no-error.
            if not available tqBankNumberByParentID
            then find first tqBankNumberByParentID where 
                       tqBankNumberByParentID.tiParentObject_ID = {&tiGL_ID} and
                       tqBankNumberByParentID.tiCompany_ID = iiCompanyID no-error.
    
            if available tqBankNumberByParentID
            then assign vcBankNumber = if tqBankNumberByParentID.tcBankNumberFormatted <> ? and 
                                            tqBankNumberByParentID.tcBankNumberFormatted <> "":U 
                                         then tqBankNumberByParentID.tcBankNumberFormatted 
                                         else tqBankNumberByParentID.tcBankNumber.
                        viGLID       = {&tiGL_ID}.
    end.

    assign {&tcBankNumber}            = vcBankNumber
           {&tcBankStateStatusSelect} = entry(lookup({&tcBankStateStatus}, vcBANKSTATESTATUSES, chr(2)) - 1, vcBANKSTATESTATUSES, chr(2)).

    vhQuery:get-next().
end.

vhQuery:query-close().
delete object vhQuery.

if vlStart1
then do:
    <Q-3 run BankNumberByParentCompany
       (Stop) in BBankNumber >
end.