project QadFinancials > class BDCollection > method FillProDataSet

Description

This procedure we fill data for a ProDataSet based on bank driver's requirement. And the data in this ProDataSet will be exported in xml files.


Parameters


iiDCollectionIDinputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDCollection.BuildProDataSet


program code (program3/bdcollection.p)

if oiReturnStatus = 0 then assign oiReturnStatus = -98.

<Q-7 run AddressTypeByCode (all) (Read) (NoCache)
   (input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
    output dataset tqAddressTypeByCode) in BAddressType >

find first tqAddressTypeByCode no-error.
if not available tqAddressTypeByCode 
then do:
    <M-8 run SetMessage
          (input  #T-9'The Head Office address type is not defined in the system.':100(49190)t-9# (icMessage), 
           input  '' (icArguments), 
           input  '' (icFieldName), 
           input  '' (icFieldValue), 
           input  'E':U (icType), 
           input  3 (iiSeverity), 
           input  '' (icRowid), 
           input  'QadFin-5378':U (icFcMsgNumber), 
           input  '' (icFcExplanation), 
           input  '' (icFcIdentification), 
           input  '' (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BDCollection>
    assign oiReturnStatus = -1.
    return.
end.

collection:
for each tDCollectionAllInfo where 
         tDCollectionAllInfo.DCollection_ID = iiDCollectionID:
         
    <M-11 run FillProDataSetCompany
       (input  tDCollectionAllInfo.Company_ID (iiCompanyID), 
        input  tqAddressTypeByCode.tiAddressType_ID (iiAddressTypeID), 
        output viFcReturnSuper (oiReturnStatus)) in BDCollection>

    <M-12 run FillProDataSetGL
       (input  tDCollectionAllInfo.GL_ID (iiGL_ID), 
        input  iiDCollectionID (iiDCollectionId), 
        output viFcReturnSuper (oiReturnStatus)) in BDCollection>
 
    <Q-28 run DPaySelPayCodeByDPaySelID (all) (Read) (NoCache)
       (input tDCollectionAllInfo.DPaySel_ID, (DPaySelID)
        output dataset tqDPaySelPayCodeByDPaySelID) in BDPaymentSelection >
        
    for each tqDPaySelPayCodeByDPaySelID:
        create tHeaderAttribute.
        assign tHeaderAttribute.tcAttributeName = tqDPaySelPayCodeByDPaySelID.tcPayFormatGroupCode
               tHeaderAttribute.tiDCollectionID = iiDCollectionID.
        if tqDPaySelPayCodeByDPaySelID.tiPayFormatCode_ID <> 0
        then do:
            <Q-14 run PayFormatCodePrim (all) (Read) (NoCache)
               (input tqDPaySelPayCodebyDPaySelID.tiPayFormatCode_ID, (PayFormatCodeID)
                input ?, (PayFormatCode)
                output dataset tqPayFormatCodePrim) in BPaymentFormat >
            find first tqPayFormatCodePrim no-error.
            if available tqPayFormatCodePrim
            then assign tHeaderAttribute.tcAttributeValue = tqPayFormatCodePrim.tcPayFormatCode.
        end.
        else do:
            assign tHeaderAttribute.tcAttributeValue = tqDPaySelPayCodeByDPaySelID.tcDPaySelPayCodeValue.
        end. 
        
        if tqDPaySelPayCodeByDPaySelID.tcPayFormatGroupDataType = "DATE"
        then do:
             assign tHeaderAttribute.tcAttributeValue = string(year(date(tHeaderAttribute.tcAttributeValue)),"9999":U) +
                                                        "-":U                                                          +
                                                        string(month(date(tHeaderAttribute.tcAttributeValue)),"99":U)  +
                                                        "-":U                                                          +
                                                        string(day(date(tHeaderAttribute.tcAttributeValue)),"99":U).
                                              
        end. /* IF tqDPaySelPayCodeByDPaySelID.tcPayFormatGroupDataType = "DATE" */
        
    end. /* for each tqPaySelPayCodeByPaySelID */


    /* Fill new DPaySel temp-table */    
    <Q-29 run DPaySelCodeByPaySelID (all) (Read) (NoCache)
       (input tDCollectionAllInfo.Company_ID, (CompanyId)
        input tDCollectionAllInfo.DPaySel_ID, (DPaySelID)
        output dataset tqDPaySelCodeByPaySelID) in BDPaymentSelection >
     
    find first tqDPaySelCodeByPaySelID no-error.
    if available tqDPaySelCodeByPaySelID
    then do:
        create tDPaySel.
        vhBufferForDPaySel = dataset tqDPaySelCodeByPaySelID:get-buffer-handle(1).
        <M-30 run BufferCopy
           (input  vhBufferForDPaySel (ihFrom), 
            input  buffer tDPaySel:handle (ihTo), 
            output viFcReturnSuper (oiReturnStatus)) in BDCollection>
        if viFcReturnSuper < 0
        then do:
            assign oiReturnStatus = viFcReturnSuper.
            return.
        end.
        else if viFcReturnSuper > 0
        then do:
            if oiReturnStatus = -98 or oiReturnStatus >= 0 
            then assign oiReturnStatus = viFcReturnSuper.
        end.   
               
    end. /* if available tqDPaySelCodeByPaySelID */

    assign viDocumentNum = 0
           vdBankNumberSum = 0
           vdBaseCurrencySum = 0
           vdLocalCurrencySum = 0.

    assign vcDocumentStatus =  {&DOCUMENTSTATUS-INCASSO}
           vcDocumentStatus =  vcDocumentStatus + ',':U + {&DOCUMENTSTATUS-DISCONT}.  
               
    if available tDPAySel and tDPaySel.DPaySelStatus = {&DOCUMENTSTATUS-INIT}
    then do:
       <M-34 run RetrievePaySelInitial
          (input  tDCollectionAllInfo.DPaySel_ID (iiPaySelID), 
           input  tDCollectionAllInfo.Company_ID (iiCompanyID), 
           input  iiDCollectionID (iiDCollectionID), 
           input  tDCollectionAllInfo.CreationUsr_ID (iiCreationUserID), 
           output viDocumentNum (oiDocumentNum), 
           output vdLocalCurrencySum (odLocalCurrencySum), 
           output vdBaseCurrencySum (odBaseCurrencySum), 
           output viFcReturnSuper (oiReturnStatus)) in BDCollection>  
         if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
         if viFcReturnSuper < 0 then leave collection.      
           
     end.
     else do:                      
      
      <Q-61 run DDocumentAllInfoByCollectionID (all) (Read) (NoCache)
         (input tDCollectionAllInfo.Company_ID, (CompanyId)
          input iiDCollectionID, (CollectionID)
          input vcDocumentStatus, (DocumentStatus)
          output dataset tqDDocumentAllInfoByCollectionID) in BDDocument>                 
          
        assign vhBufferForProDataSet = dataset tqDDocumentAllInfoByCollectionID:get-buffer-handle(1).
        for each tqDDocumentAllInfoByCollectionID:
            create tDDocument.
            <M-3 run BufferCopy
               (input  vhBufferForProDataSet (ihFrom), 
                input  buffer tDDocument:handle (ihTo), 
                output viFcReturnSuper (oiReturnStatus)) in BDCollection>
            if viFcReturnSuper < 0 
            then do:
                assign oiReturnStatus = viFcReturnSuper.
                return.
            end.
            else if viFcReturnSuper > 0 
            then do:
                if oiReturnStatus = -98 or oiReturnStatus >=0 
                then assign oiReturnStatus = viFcReturnSuper.
            end.
      
            <M-10 run FillProDataSetDocument
               (input  tDDocument.DDocument_ID (iiDDocumentID), 
                input  tqAddressTypeByCode.tiAddressType_ID (iiAddressTypeID), 
                output viFcReturnSuper (oiReturnStatus)) in BDCollection>
            assign viDocumentNum = viDocumentNum + 1
                   vdLocalCurrencySum = vdLocalCurrencySum + tDDocument.DDocumentOriginalDebitTC
                   vdBaseCurrencySum = vdBaseCurrencySum + tDDocument.DDocumentOriginalDebitTC * tDDocument.DDocumentExchangeRate
                   vdBankNumberSum = vdBankNumberSum + tDDocument.tdBankNumberSum.    
           
           /* viBankNumberSum = viBankNumber */        
        end. /* end of each tqDDocumentAllInfoByCollectionID */
    end. /* end not initial */

    /*fill the tPaymentAttribute temp table */
    for each tDDocument:
        for each tDInvoice where
            tDInvoice.tiDDocumentID = tDDocument.DDocument_ID:

            <Q-97 run DInvoiceBankPayCodeByDIBankID (all) (Read) (NoCache)
               (input {&PAYFORMATGROUPLEVEL-PAYMENT}, (PayFormatGroupLevel)
                input tDInvoice.DInvoice_ID, (DInvoiceId)
                input ?, (BankNumberId)
                output dataset tqDInvoiceBankPayCodeByDIBankID) in BDInvoice>
        
            for each tqDInvoiceBankPayCodeByDIBankID where 
                tqDInvoiceBankPayCodeByDIBankID.tiDInvoice_ID          = tDInvoice.DInvoice_ID  and
                tqDInvoiceBankPayCodeByDIBankID.tcPayFormatGroupLevel = {&PAYFORMATGROUPLEVEL-PAYMENT} :
                find first tPaymentAttribute where 
                       tPaymentAttribute.tiDDocumentID        = tDDocument.DDocument_ID                              and 
                       tPaymentAttribute.tcAttributeName      = tqDInvoiceBankPayCodeByDIBankID.tcPayformatGroupCode 
                        no-error.
                if not available tPaymentAttribute
                then do:
                    create tPaymentAttribute.
                    assign tPaymentAttribute.tcAttributeName = tqDInvoiceBankPayCodeByDIBankID.tcPayformatGroupCode
                        tPaymentAttribute.tiDDocumentID   = tDDocument.DDocument_ID.
                    if tqDInvoiceBankPayCodeByDIBankID.tiPayFormatCode_ID <> 0
                    then do:
                        <Q-55 run PayFormatCodePrim (all) (Read) (NoCache)
                           (input tqDInvoiceBankPayCodeByDIBankID.tiPayFormatCode_ID, (PayFormatCodeID)
                            input ?, (PayFormatCode)
                            output dataset tqPayFormatCodePrim) in BPaymentFormat>
                        find first tqPayFormatCodePrim no-error.
                        if available tqPayFormatCodePrim
                            then assign tPaymentAttribute.tcAttributeValue = tqPayFormatCodePrim.tcPayFormatCode.
                    end. /*if tqDInvoiceBankPayCodeByDIBankID.tiPayFormatCode_ID<>0*/
                    else do:
                        tPaymentAttribute.tcAttributeValue = tqDInvoiceBankPayCodeByDIBankID.tcDInvoiceBankPayCodeValue.
                    end.
                end. /* if not available tpaymentAttribute*/        
            end. /* for each tqDInvoiceBankPayCodeByDIBankID*/
        end. /*for each tDInvoice*/
    end. /*for each tDDocument */

    /* fill the tDInvoiceAttribute temp table */
    for each tDDocument:
        for each tDInvoice where 
                 tDInvoice.tiDDocumentID = tDDocument.DDocument_ID:
            <Q-23 run DInvoiceBankPayCodeByDIBankID (all) (Read) (NoCache)
               (input ?, (PayFormatGroupLevel)
                input tDInvoice.DInvoice_ID, (DInvoiceId)
                input tDDocument.BankNumber_ID, (BankNumberId)
                output dataset tqDInvoiceBankPayCodeByDIBankID) in BDInvoice >
            for each tqDInvoiceBankPayCodeByDIBankID:
                find first tDInvoiceAttribute where 
                           tDInvoiceAttribute.tcAttributeName = tqDInvoiceBankPayCodeByDIBankID.tcPayFormatGroupCode and
                           tDInvoiceAttribute.tiDInvoiceID    = tDInvoice.DInvoice_ID                                and
                           tDInvoiceAttribute.tiDDocumentID   = tDInvoice.tiDDocumentID 
                           no-error.
                if not available tDInvoiceAttribute and 
                   tqDInvoiceBankPayCodeByDIBankID.tcPayFormatGroupLevel = {&PAYFORMATGROUPLEVEL-INVOICE}
                then do:
                    create tDInvoiceAttribute.
                    assign tDInvoiceAttribute.tcAttributeName = tqDInvoiceBankPayCodeByDIBankID.tcPayFormatGroupCode
                           tDInvoiceAttribute.tiDInvoiceId = tDInvoice.DInvoice_ID
                           tDInvoiceAttribute.tiDDocumentID = tDInvoice.tiDDocumentID.
                    if tqDInvoiceBankPayCodeByDIBankID.tiPayFormatCode_ID<>0
                    then do:
                        <Q-24 run PayFormatCodePrim (all) (Read) (NoCache)
                           (input tqDInvoiceBankPayCodeByDIBankID.tiPayFormatCode_ID, (PayFormatCodeID)
                            input ?, (PayFormatCode)
                            output dataset tqPayFormatCodePrim) in BPaymentFormat >
                        find first tqPayFormatCodePrim no-error.
                        if available tqPayFormatCodePrim
                        then assign tDInvoiceAttribute.tcAttributeValue = tqPayFormatCodePrim.tcPayFormatCode.
                    end. /*if tqDInvoiceBankPayCodeByDIBankID.tiPayFormatCode_ID<>0*/
                    else do:
                         tDInvoiceAttribute.tcAttributeValue = tqDInvoiceBankPayCodeByDIBankID.tcDInvoiceBankPayCodeValue.
                    end.
                end.
            end. /*for each tqDInvoiceBankPayCodeByDIBankID:*/
        end. /* for each tDInvoice */ 
    end. /* for each tDDocument */
    
    assign tDCollectionAllInfo.tiNumberOfPayments = viDocumentNum
           tDCollectionAllInfo.tdTotalAmountBaseCurrency = vdBaseCurrencySum
           tDCollectionAllInfo.tdTotalAmountLocalCurrency = vdLocalCurrencySum
           tDCollectionAllInfo.tcBankNumberSum = string(vdBankNumberSum).
end. /* end of for each tDCollection */

assign oiReturnStatus = viLocalReturn.