project QadFinancials > class BJournalEntry > method CalcAllSelectPostingVat

query calculated fields procedure

Description

Assign a value to query calculated fields


Parameters


iiCompanyIdinputintegerCompany id
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
query SelectPostingVat


program code (program1/bjournalentry.p)

if vcListJOURNALTYPECODES = "":U then assign vcListJOURNALTYPECODES = {&JOURNALTYPES}.

    create query vhQuery in widget-pool "non-persistent".
    vhQuery:set-buffers(ih_Buffer).
    vhQuery:query-prepare("for each ":U + ih_Buffer:table + " where ":U + 
                           ih_buffer:buffer-field("tiPosting_ID":U):name + " <> ? and ":U + 
                           ih_buffer:buffer-field("tiPosting_ID":U):name + " <> 0 ":U).
    vhQuery:query-open().
    vhQuery:get-first().
    
    
    do while not vhQuery:query-off-end:
        
        
        if {&tcJournalTypeCode} = {&JOURNALTYPE-CREDITORINVOICE}            or 
           {&tcJournalTypeCode} = {&JOURNALTYPE-CREDITORINVOICECORRECT}     or 
           {&tcJournalTypeCode} = {&JOURNALTYPE-CREDITORCREDITNOTE}         or 
           {&tcJournalTypeCode} = {&JOURNALTYPE-CREDITORCREDITNOTECORRECT}  or 
           {&tcJournalTypeCode} = {&JOURNALTYPE-CREDITORADJUSTMENT} or
           ({&tcJournalTypeCode} = {&JOURNALTYPE-JOURNALENTRY} and
            {&tcJournalControl} = {&JOURNALCONTROL-LOGISTIC})
        then do :
            if ({&tcJournalTypeCode} = {&JOURNALTYPE-JOURNALENTRY} and 
                {&tcJournalControl} = {&JOURNALCONTROL-LOGISTIC})
            then do:
                <Q-9 run CreditorPrim (all) (Read) (NoCache)
                   (input ?, (CompanyId)
                    input ?, (CreditorId)
                    input {&tcPostingOriginAddressCode}, (CreditorCode)
                    output dataset tqCreditorPrim) in BCreditor >

                find first tqCreditorPrim no-error.
                if available tqCreditorPrim then
                    assign {&tcCreditorCode} = tqCreditorPrim.tcCreditorCode.                    
            end.
            else do:
                if not vlStartedQueryCInvoicePosting
                then do :
                    <Q-2 run CInvoicePostingByCIPostingID
                       (Start) in BCInvoice >
                    assign vlStartedQueryCInvoicePosting = true.
                end. /* if not vlStartedQueryCInvoicePosting */
                <Q-1 run CInvoicePostingByCIPostingID (all) (Read) (NoCache)
                    (input ?, (CompanyId)
                     input {&tiPosting_ID}, (PostingID)
                     input ?, (CInvoiceID)
                     output dataset tqCInvoicePostingByCIPostingID) in BCInvoice >
                find first tqCInvoicePostingByCIPostingID where 
                           tqCInvoicePostingByCIPostingID.tiPosting_ID = {&tiPosting_ID}
                           no-lock no-error.
                if available tqCInvoicePostingByCIPostingID
                then assign {&tcCreditorCode} = tqCInvoicePostingByCIPostingID.tcCreditorCode.
            end.
        end. /* if {&tcJournalTypeCode} = {&JOURNALTYPE-CREDITORINVOICE} or */
        
        
        if {&tcJournalTypeCode} = {&JOURNALTYPE-DEBTORINVOICE}              or 
           {&tcJournalTypeCode} = {&JOURNALTYPE-DEBTORINVOICECORRECT}       or 
           {&tcJournalTypeCode} = {&JOURNALTYPE-DEBTORCREDITNOTE}           or 
           {&tcJournalTypeCode} = {&JOURNALTYPE-DEBTORCREDITNOTECORRECT}    or 
           {&tcJournalTypeCode} = {&JOURNALTYPE-DEBTORADJUSTMENT}           or
           {&tcJournalTypeCode} = {&JOURNALTYPE-DEBTORFINANCECHARGE} or
           ({&tcJournalTypeCode} = {&JOURNALTYPE-JOURNALENTRY} and
            {&tcJournalControl} = {&JOURNALCONTROL-LOGISTIC})           
        then do :
            if ({&tcJournalTypeCode} = {&JOURNALTYPE-JOURNALENTRY} and 
                {&tcJournalControl} = {&JOURNALCONTROL-LOGISTIC})
            then do:
                <Q-11 run DebtorPrim (all) (Read) (NoCache)
                   (input ?, (CompanyId)
                    input {&tcPostingOriginAddressCode}, (DebtorCode)
                    input ?, (Debtor_ID)
                    output dataset tqDebtorPrim) in BDebtor >
                    
                find first tqDebtorPrim no-error.
                if available tqDebtorPrim then
                    assign {&tcDebtorCode} = tqDebtorPrim.tcDebtorCode.                    
            end.
            else do:        
                if not vlStartedQueryDInvoicePosting
                then do :
                    <Q-6 run DInvoicePostingByDIPostingID
                       (Start) in BDInvoice >
                    assign vlStartedQueryDInvoicePosting = true.
                end. /* if not vlStartedQueryDInvoicePosting */
                <Q-7 run DInvoicePostingByDIPostingID (all) (Read) (NoCache)
                   (input {&tiPosting_ID}, (PostingID)
                    input ?, (DInvoiceID)
                    input ?, (CompanyId)
                    output dataset tqDInvoicePostingByDIPostingID) in BDInvoice >
                find first tqDInvoicePostingByDIPostingID where 
                           tqDInvoicePostingByDIPostingID.tiPosting_ID = {&tiPosting_ID}
                           no-lock no-error.
                if available tqDInvoicePostingByDIPostingID
                then assign {&tcDebtorCode} = tqDInvoicePostingByDIPostingID.tcDebtorCode.
            end.
        end. /* if {&tcJournalTypeCode} = {&JOURNALTYPE-DEBTORINVOICE} or */
        
        /* start of zhc 10132-3384 */
        assign {&tcJournalTypeCodeTr} = "?":U.
        do viCounter = num-entries(vcListJOURNALTYPECODES, chr(2)) to 1 by -2 :
            if entry(viCounter, vcListJOURNALTYPECODES, chr(2)) = {&tcJournalTypeCode}
            then do :
                assign {&tcJournalTypeCodeTr} = entry(viCounter - 1, vcListJOURNALTYPECODES, chr(2)) no-error.
                leave.
            end. /* if entry(viCounter, vcListJOURNALTYPECODES, chr(2)) */
        end. /* do viCounter = num-entries(vcListJOURNALTYPECODES, chr(2)) */
        /* end of zhc 10132-3384 */
        
        vhQuery:get-next().
        
    end. /* do while not vhQuery:query-off-end: */
    
    
    vhQuery:query-close().
    delete object vhQuery.
    
    if vlStartedQueryCInvoicePosting
    then do :
        <Q-3 run CInvoicePostingByCIPostingID
           (Stop) in BCInvoice >
    end. /* if not vlStartedQueryCInvoicePosting */
    
    if not vlStartedQueryDInvoicePosting
    then do :
        <Q-8 run DInvoicePostingByDIPostingID
           (Stop) in BDInvoice >
        assign vlStartedQueryDInvoicePosting = true.
    end. /* if not vlStartedQueryDInvoicePosting */