project QadFinancials > class BDDocument > method CalcAllDDocumentByDebtor

query calculated fields procedure

Description

Assign a value to query calculated fields


Parameters


iiCompanyIdinputintegerCompany id
iiDebtorIDinputinteger
itPaymentStartDateinputdate
itPaymentEndDateinputdate
ilDocumentIsOpeninputlogical
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
query DDocumentByDebtor


program code (program1/bddocument.p)

if vcPaymentFormatPayInstruments = ? or
   vcPaymentFormatPayInstruments = '':U
then assign vcPaymentFormatPayInstruments = {&PAYFORMATPAYINSTRUMENTS-AR}.

create query vhQuery in widget-pool "non-persistent".
vhQuery:set-buffers(ih_Buffer).
vhQuery:query-prepare("for each ":U + ih_Buffer:table).
vhQuery:query-open().
vhQuery:get-first().
do while not vhQuery:query-off-end:

    /* Get translation for document type */
    assign vcType = "":U.
    do viA = num-entries(vcPaymentFormatPayInstruments, chr(2)) to 1 by -2:
        if entry(viA, vcPaymentFormatPayInstruments, chr(2)) = {&tcDDocumentType}
        then do:
            assign vcType = entry(viA - 1, vcPaymentFormatPayInstruments, chr(2)).
            leave.
        end.
    end.
    
    assign {&tcDInvoiceNumber}   =  string({&tiDInvoicePostingYear}) + "/":U + {&tcJournalCode} +  "/":U + string({&tiDInvoiceVoucher},"999999999":U)
           {&tdOpenAmountLC}     = {&tdDInvoiceBalanceDebitLC}  - {&tdDInvoiceBalanceCreditLC}
           {&tdOpenAmountTC}     = {&tdDInvoiceBalanceDebitTC}  - {&tdDInvoiceBalanceCreditTC}
           {&tdOpenAmountCC}     = {&tdDInvoiceBalanceDebitCC}  - {&tdDInvoiceBalanceCreditCC}
           {&tdOriginalAmountLC} = {&tdDInvoiceOriginalDebitLC} - {&tdDInvoiceOriginalCreditLC}
           {&tdOriginalAmountTC} = {&tdDInvoiceOriginalDebitTC} - {&tdDInvoiceOriginalCreditTC}
           {&tdOriginalAmountCC} = {&tdDInvoiceOriginalDebitCC} - {&tdDInvoiceOriginalCreditCC}
           {&tdPaymentOriginalAmountTC} = {&tdDDocumentOriginalDebitTC} - {&tdDDocumentOriginalCreditTC}.

    assign {&tcDocumentNumber} =  string({&tiDDocumentYear}) + "/":U 
                               + vcType + "/":U 
                               + string({&tiDDocumentNumber},"999999999").

    if {&ttDInvoiceDueDate} <> ?
    then do:
        if {&ttDDocumentCreationDate} - {&ttDInvoiceDueDate} >= 0 
        then assign {&tiOverdueDays} = {&ttDDocumentCreationDate} - {&ttDInvoiceDueDate}.
        else assign {&tiOverdueDays} = 0.
    end.

    assign vttempdate = date(1,1,year({&ttDDocumentCreationDate})) + (2 - weekday(date(1,1,year({&ttDDocumentCreationDate})))).
    if weekday(date(1,1,year({&ttDDocumentCreationDate}))) >= 6 then 
        vttempdate = vttempdate + 7.
    
    assign {&tiWeekNumbers} = truncate(((date({&ttDDocumentCreationDate}) - vttempdate) + 7) / 7 , 0).
    
    if {&tiWeekNumbers} > 52 
    then do:
        assign vttempdate = date(1,1,year({&ttDDocumentCreationDate}) + 1) + (2 - weekday(date(1,1,year({&ttDDocumentCreationDate}) + 1))).
        if weekday(date(1,1,year({&ttDDocumentCreationDate}) + 1)) >= 6 then 
            vttempdate = vttempdate + 7.
        if {&ttDDocumentCreationDate} < vttempdate then
             {&tiWeekNumbers} = 52.           
    end.
    vhQuery:get-next().
end.
vhQuery:query-close().
delete object vhQuery.