project QadFinancials > class BPaymentSelection > method FillProDataSetPayment

Description

Fill ProDataSet Payment


Parameters


iiPaySel_IDinputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPaymentSelection.FillProDataSet


program code (program7/bpaymentselection.p)

if oiReturnStatus = 0
then assign oiReturnStatus = -98.

empty temp-table tCDocumentPaySel.
empty temp-table tCDocumentInvoiceXRefPaySel.
empty temp-table tPaySelLinePaySel.
empty temp-table tPaymentBankBusRel.

<Q-71 run CDocumentByIDAllInfo  (Start) in BCDocument >
<Q-73 run CDInvoiceXrefByIDAllInfo  (Start) in BCDocument >
<Q-79 run CurrencyByIDAllInfo  (Start) in BCurrency >
<Q-84 run CInvoiceByAllInfo  (Start) in BCInvoice >

/* Fill the PaySel ProDataSet */               
for each tPaySel where tPaySel.PaySel_ID = iiPaySel_ID:
    /* Fill data to temp table tCDocumentPaySel */ 
    <Q-2 run CDocumentByIDAllInfo (all) (Read) (NoCache)
       (input tPaySel.Company_ID, (CompanyId)
        input tPaySel.PaySel_ID, (PaySel_ID)
        output dataset tqCDocumentByIDAllInfo) in BCDocument >
    find first tqCDocumentByIDAllInfo no-error.
    if not available tqCDocumentByIDAllInfo 
    then do:
        <M-35 run SetMessage
           (input  #T-36'No supplier payment record is available.':50(999890603)T-36# (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'D':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-5348':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
        assign oiReturnStatus = -1.
        return.
    end. /* end of if not available tqCDocumentAllInfo */
    else do:
        assign vhBufferForProDataSet = dataset tqCDocumentByIDAllInfo:get-buffer-handle(1).
        for each tqCDocumentByIDAllInfo 
                 no-lock:
            find first tCDocumentPaySel where 
                       tCDocumentPaySel.CDocument_ID = tqCDocumentByIDAllInfo.tiCDocument_ID 
                       no-error.
            if not available tCDocumentPaySel
            then do: /* avoid duplicate key issue */
                create tCDocumentPaySel.
                <M-4 run BufferCopy
                   (input  vhBufferForProDataSet (ihFrom), 
                    input  buffer tCDocumentPaySel:handle (ihTo), 
                    output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
                if viFcReturnSuper <> 0 
                then assign oiReturnStatus = viFcReturnSuper.
                if viFcReturnSuper < 0
                then return.
             end. /* end if not available tCDocumentPaySel */
        end. /* for each tqCDocumentByIDAllInfo */
    end. /* tqCDocumentByIDAllInfo else do */

    /* Buffer copy temp table tCDocumentPaySel to tPayment */
    for each tCDocumentPaySel:
        create tPayment.
        buffer-copy tCDocumentPaySel to tPayment.
        assign tPayment.tdPaymentAmountBaseCurr = tCDocumentPaySel.CDocumentOriginalCreditLC
               tPayment.tdPaymentAmountTCurr    = tCDocumentPaySel.CDocumentOriginalCreditTC
               tPayment.tdNetPaymentAmount = ?
               tPayment.tlBankChargeIsTaxable = ?
               tPayment.tlBankChargeIsTaxIncluded = ?
               tPayment.tlBankChargeIsValid = ?
               tPayment.tlBankChargeRateIsFound = ?
               tPayment.tiOwnBankNumberId = ?
               tPayment.tlOwnBankIsBankChargeEnable = ?
               tPayment.tdBankChargeOriginalAmount = ?.
    end. /* end for each tCDocumentPaySel */
          
    for each tCDocumentPaySel:
        /* Fill data to temp table tCDocumentInvoiceXRefPaySel */ 
        <Q-8 run CDInvoiceXrefByIDAllInfo (all) (Read) (NoCache)
           (input tCDocumentPaySel.CDocument_ID, (CDocument_ID)
            output dataset tqCDInvoiceXrefByIDAllInfo) in BCDocument >
        find first tqCDInvoiceXrefByIDAllInfo no-error.
        if not available tqCDInvoiceXrefByIDAllInfo
        then do:
            <M-37 run SetMessage
               (input  #T-38'No CDocumentInvoiceXRef record is available':50(999890604)T-38# (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'D':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-5350':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
                if viFcReturnSuper <> 0 
                then assign oiReturnStatus = viFcReturnSuper.
                if viFcReturnSuper < 0
                then return.
        end.
        else do:
            assign vhBufferForProDataSet = dataset tqCDInvoiceXrefByIDAllInfo:get-buffer-handle(1).
            for each tqCDInvoiceXrefByIdAllInfo:
                create tCDocumentInvoiceXRefPaySel.
                <M-109 run BufferCopy
                   (input  vhBufferForProDataSet (ihFrom), 
                    input  buffer tCDocumentInvoiceXRefPaySel:handle (ihTo), 
                    output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
                if viFcReturnSuper <> 0 
                then assign oiReturnStatus = viFcReturnSuper.
                if viFcReturnSuper < 0
                then return.
            end. /* for each tqCDocumentInvoiceXrefAllInfo */
        end. /* tqCDocumentInvoiceXrefAllInfo else do */
    end. /* for each tqCDocumentPaySel */

    <Q-1 run PaySelByIDAllInfo (all) (Read) (NoCache)
       (input ?, (CompanyId)
        input tPaySel.PaySel_ID, (PaySel_ID)
        output dataset tqPaySelByIDAllInfo) in BPaymentSelection >

    for each tCDocumentInvoiceXRefPaySel:
        find first tqPaySelByIDAllInfo where 
                   tqPaySelByIDAllInfo.tiPaySelLine_ID = tCDocumentInvoiceXRefPaySel.PaySelLine_ID.
        if available tqPaySelByIDAllInfo 
        then do:
            create tPaySelLinePaySel.
            <M-96 run BufferCopy
               (input  buffer tqPaySelByIDAllInfo:handle (ihFrom), 
                input  buffer tPaySelLinePaySel:handle (ihTo), 
                output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
            if viFcReturnSuper <> 0 
            then assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then return.
        end. /* if available */
    end. /* for each tCDocumentInvoiceXRefPaySel */ 

    for each tPayment,
        first tCDocumentInvoiceXRefPaySel where 
              tCDocumentInvoiceXRefPaySel.CDocument_ID = tPayment.CDocument_ID,
        first tPaySelLinePaySel where 
              tPaySelLinePaySel.PaySelLine_ID = tCDocumentInvoiceXRefPaySel.PaySelLine_ID:
        assign tPayment.BankNumber_ID = tPaySelLinePaySel.BankNumber_ID.
    end. /* end for each tpayment */

    /* Fill data to temp table tPaymentPaySel */ 
    create tPaymentPaySel.
    buffer-copy tPaySel to tPaymentPaySel.
    for each tCDocumentPaySel where  
             tCDocumentPaySel.PaySel_ID =tPaySel.PaySel_ID 
        break by tCDocumentPaySel.CDocument_ID 
              by tCDocumentPaySel.CDocumentOriginalCreditLC 
              by tCDocumentPaySel.CDocumentOriginalCreditTC:
        accumulate tCDocumentPaySel.CDocument_ID(count).
        if last-of(tCDocumentPaySel.CDocument_ID) 
        then assign tPaymentPaySel.tiNumberOfPayments = accum count tCDocumentPaySel.CDocument_ID.       

        accumulate tCDocumentPaySel.CDocumentOriginalCreditTC (total).
        
        if last-of( tCDocumentPaySel.CDocumentOriginalCreditTC )
        then assign tPaymentPaySel.tdTotalAmountLocalCurrency = accum total  tCDocumentPaySel.CDocumentOriginalCreditTC .  /* Transation Currency accumulate  */
           
        accumulate tCDocumentPaySel.CDocumentOriginalCreditLC(total).
        
        if last-of(tCDocumentPaySel.CDocumentOriginalCreditLC) 
        then assign tPaymentPaySel.tdTotalAmountBaseCurrency = accum total tCDocumentPaySel.CDocumentOriginalCreditLC.      /* Local currency accumulate */
    end. /* for each tCDocumentPaySel */

     <M-110 run FillProdataSetPaymentBankNumber
        (output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
        
    for each tCDocumentPaySel:
        find first tCurrencyOfPayment where 
                   tCurrencyOfPayment.Currency_ID = tCDocumentPaySel.Currency_ID 
                   no-error.
        if not available tCurrencyOfPayment and 
           tCDocumentPaySel.Currency_ID <> 0
        then do:
            <Q-22 run CurrencyByIDAllInfo (all) (Read) (NoCache)
               (input tCDocumentPaySel.Currency_ID, (Currency_ID)
                output dataset tqCurrencyByIDAllInfo) in BCurrency >
            find first tqCurrencyByIDAllInfo no-error.
            if not available tqCurrencyByIDAllInfo 
            then do:
                <M-43 run SetMessage
                   (input  #T-44'No currency record is available.':50(999890606)T-44# (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'D':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'QadFin-5354':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
                assign oiReturnStatus = -1.
                return.
            end. /* end of if not available tqCurrencyByIDAllInfo */
            else do:
                assign vhBufferForProDataSet = dataset tqCurrencyByIDAllInfo:get-buffer-handle(1).
                for each tqCurrencyByIDAllInfo:
                    find first tCurrencyOfPayment where 
                               tCurrencyOfPayment.Currency_ID = tqCurrencyByIDAllInfo.tiCurrency_ID 
                               no-error.
                    if not available tCurrencyOfPayment
                    then do: /* avoid duplicate key issue */
                        create tCurrencyOfPayment.
                        <M-24 run BufferCopy
                           (input  vhBufferForProDataSet (ihFrom), 
                            input  buffer tCurrencyOfPayment:handle (ihTo), 
                            output oiReturnStatus (oiReturnStatus)) in BPaymentSelection>
                        if viFcReturnSuper <> 0 
                        then assign oiReturnStatus = viFcReturnSuper.
                        if viFcReturnSuper < 0
                        then return. 
                    end. /* end if not available tCurrencyOfPayment */
                end. /* for each tqCurrencyByIDAllInfo */
            end. /* tqCurrencyBYIDAllInfo else do */
        end. /* if not available tCurrencyOfPayment and tCurrencyOfPayment.Currency_ID <> 0 */
    end. /* for each tCDocumentPaySel */
    
    /* Assign the CCollection_ID of tPaymentPaySel so that the ProdataSet can add relation between CCollection and PaySel */
    for each tPaymentPaySel,
        each tCDocumentPaySel where 
             tPaymentPaySel.PaySel_ID = tCDocumentPaySel.PaySel_ID:
        assign tPaymentPaySel.tiPaySelCCollection_ID = tCDocumentPaySel.CCollection_ID.
    end. /* for each tPaymentPaySel */
    
    assign viIDCounter = 1.
    for each tCDocumentPaySel where 
             tCDocumentPaySel.PaySel_ID = tPaySel.PaySel_ID,
        each tCDocumentInvoiceXRefPaySel where  
             tCDocumentInvoiceXRefPaySel.CDocument_ID = tCDocumentPaySel.CDocument_ID,
        each tPaySelLinePaySel where 
             tPaySelLinePaySel.PaySelLine_ID =  tCDocumentInvoiceXRefPaySel.PaySelLine_ID:
            
        assign viIDCounter = viIDCounter + 1.

        <Q-32 run CInvoiceByAllInfo (all) (Read) (NoCache)
           (input ?, (CompanyId)
            input tCDocumentInvoiceXRefPaySel.CInvoice_ID, (CInvoice_ID)
            output dataset tqCInvoiceByAllInfo) in BCInvoice >

        find first tqCInvoiceByAllInfo no-error.
        if not available tqCinvoiceByAllInfo
        then do:
            <M-45 run SetMessage
               (input  #T-45'No supplier invoice record is available.':50(999890607)T-45# (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'D':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-5356':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
            assign oiReturnStatus = -1.
            return.
        end.
        else do:
            assign vhBufferForProDataSet = dataset tqCInvoiceByAllInfo:get-buffer-handle(1).

            for first tqCInvoiceByAllInfo no-lock:

                assign tqCInvoiceByAllInfo.tc_rowid = String(viIDCounter).
                create tPaymentCInvoice.
                
                <M-33 run BufferCopy
                   (input  vhBufferForProDataSet (ihFrom), 
                    input  buffer tPaymentCInvoice:handle (ihTo), 
                    output oiReturnStatus (oiReturnStatus)) in BPaymentSelection>

                if viFcReturnSuper <> 0 
                then assign oiReturnStatus = viFcReturnSuper.
                if viFcReturnSuper < 0
                then return.  

                assign tPaymentCInvoice.tiCDocument_ID    = tCDocumentPaySel.CDocument_ID
                       tPaymentCInvoice.tdCInvoicePaidTC  = tPaySelLinePaySel.PaySelLineAmountTC
                       tPaymentCInvoice.tdCInvoiceIntTC   = tPaySelLinePaySel.PaySelLineIntAmtTC.

                /* if sepa payment format, then remove all blanks from the payment reference */    
                <Q-91 assign vlFcQueryRecordsAvailable = CInvoiceBankForSEPA (NoCache)
                   (input tPaymentCInvoice.CInvoice_ID, (CInvoiceID)
                    input true, (PayFormatTypeIsSEPA)) in BCInvoice>
                if vlFcQueryRecordsAvailable = ? or vlFcQueryRecordsAvailable = true        
                then assign tPaymentCInvoice.CInvoiceTSMNumber = replace(tPaymentCInvoice.CInvoiceTSMNumber, ' ', '').

                /* Call query to get all the stages */
                <Q-74 run PaySelLineStageByPaySelLine (all) (Read) (NoCache)
                   (input tPaySelLinePaySel.PaySelLine_ID, (PaySelLineID)
                    output dataset tqPaySelLineStageByPaySelLine) in BPaymentSelection>
                    
                /* for each stage - create a record tPaymentCInvoiceStage */
                for each tqPaySelLineStageByPaySelLine 
                    no-lock:
                    vhBufferForProDataSet = dataset tqPaySelLineStageByPaySelLine:get-buffer-handle(1).
                    if tqPaySelLineStageByPaySelLine.tdPaySelLineStagePaymAmntTC > 0
                    then do:
                        create tPaymentCInvoiceStage.
                        
                        <M-13 run BufferCopy
                           (input  vhBufferForProDataSet (ihFrom), 
                            input  buffer tPaymentCInvoiceStage:handle (ihTo), 
                            output oiReturnStatus (oiReturnStatus)) in BPaymentSelection>.                                                          
                                                                         
                        assign tPaymentCInvoiceStage.tdCInvoiceStagePaidTC = tqPaySelLineStageByPaySelLine.tdPaySelLineStagePaymAmntTC
                               tPaymentCInvoiceStage.tdCinvoiceStageIntTC  = tqPaySelLineStageByPaySelLine.tdPaySelLineStageIntAmtTC.                                                
                     end. /* if tqPaySelLineStageByPaySelLine.tdPaySelLineStagePaymAmntTC */
                end.                                 

                <Q-64 run CurrencyByIDAllInfo (all) (Read) (NoCache)
                   (input tqCInvoiceByAllInfo.tiCInvoiceCurrency_ID, (Currency_ID)
                    output dataset tqCurrencyByIDAllInfo) in BCurrency>
                find first tqCurrencyByIDAllInfo 
                           no-error.
                if available tqCurrencyByIDAllInfo
                then assign tPaymentCInvoice.tcCurrencyCode = tqCurrencyByIDAllInfo.tcCurrencyCode.


                <Q-112 run JournalPrim (all) (Read) (NoCache)
                   (input tPaymentCInvoice.Company_ID, (CompanyId)
                    input ?, (JournalCode)
                    input tPaymentCInvoice.Journal_ID, (JournalID)
                    output dataset tqJournalPrim) in BJournal >
                find first tqJournalPrim 
                     no-error.
                if available tqJournalPrim 
                then tPaymentCInvoice.tcJournalCode = tqJournalPrim.tcJournalCode.
                 
                if tPaymentCInvoice.BLWIGroup_ID <> 0 and
                   tPaymentCInvoice.BLWIGroup_ID <> ?
                then do:
                    <Q-75 run BLWIGroupPrim (all) (Read) (Cache)
                       (input tPaymentCInvoice.BLWIGroup_ID, (BLWIGroupId)
                        input ?, (BLWIGroupCode)
                        output dataset tqBLWIGroupPrim) in BBLWIGroup>
                    find first tqBLWIGroupPrim where 
                              tqBLWIGroupPrim.tiBLWIGroup_ID = tPaymentCInvoice.BLWIGroup_ID
                              no-error.
                    if available tqBLWIGroupPrim
                    then assign tPaymentCInvoice.tcBLWIGroupCode = tqBLWIGroupPrim.tcBLWIGroupCode.
                    else assign tPaymentCInvoice.tcBLWIGroupCode = "":U.
                end. /* tPaymentCInvoice.BLWIGroup_ID <> 0*/	        
 	  	    end. /* for first tqCInvoiceByAllInfo */
        end. /* tqCInvoiceByAllInfo else do */
    end. /* for each tCDocumentPaySel */  
end. /* for each tPaySel */

<Q-98 run CDocumentByIDAllInfo  (Stop) in BCDocument >
<Q-99 run CDInvoiceXrefByIDAllInfo  (Stop) in BCDocument >

<Q-106 run CurrencyByIDAllInfo  (Stop) in BCurrency >
<Q-108 run CInvoiceByAllInfo  (Stop) in BCInvoice > 

/* ========================= */
/* Set default return status */
/* ========================= */
if oiReturnStatus = -98 
then assign oiReturnstatus = 0.