project QadFinancials > class BDInvoice > method PostSave

Description

Actions to take after writing current instance to the database, and before final commit of the transaction.
Use the field tc_status to test the status of the updated records:
'' = unchanged
'N' = new
'C' = changed
'D' = deleted


Parameters


oiReturnStatusoutputinteger


Internal usage


unused


program code (program/bdinvoice.p)

<ANCESTOR-CODE>
    
/* ========================== */
/* Commit the voucher-numbers */
/* ========================== */
for each tDInvoice where 
         can-do(vcCommitNumber,tDInvoice.tc_Rowid) and
         tDInvoice.DInvoiceVoucher <> 0 and
         tDInvoice.DInvoiceVoucher <> ?:

    assign vhFcComponent = ?.
    <M-1 run CommitNumber
       (input  viCompanyId (iiCompanyID), 
        input  tDInvoice.DInvoicePostingYear (iiNumbrYear), 
        input  tDInvoice.tcJournalCode (icNumbrType), 
        input  tDInvoice.DInvoiceVoucher (iiNumbr), 
        input  viFcCurrentInstanceId (iiInstanceId), 
        input  vcFcComponentName (icClassName), 
        output viFcReturnSuper (oiReturnStatus)) in BNumber>

    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
    then assign oiReturnStatus = viFcReturnSuper.
    if oiReturnStatus < 0
    then return.

end. /* for each tDInvoice */

/* ====================================================================================== */
/* Update some fields in Debtor table. We use a WriteDirect for performance reasons       */   
/* as the fields are pure for informational purposes only and do not have anny validation */
/* ====================================================================================== */
/* Return in case there is nothing to do */
if can-find (first tUpdateDebtorPaymentSalesDI ) 
then do :
    
    /* ================================================================================================== */
    /* Start the persistance - hold the returned hanlde to in anothe data-item as we need ti repetitively */
    /* ================================================================================================== */
    <M-98 run StartPersistence
       (output vhFcComponent (ohPersistence), 
        output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    if viFcReturnSuper <> 0
    then do :
        assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0
        then return.
    end. /* if viFcReturnSuper <> 0 */
    assign vhPersistanceViaFcComponent = vhFcComponent.
    
    /* ================================================================================================== */
    /* Go through all tUpdateDebtorPaymentSalesDI record and update some fields in the debtor record      */
    /* ================================================================================================== */
    for each tUpdateDebtorPaymentSalesDI 
        break by tUpdateDebtorPaymentSalesDI.tiDebtorID   : 
    
        /* ========================================== */
        /* Reset the values in case of a new customer */
        /* ========================================== */    
        if first-of (tUpdateDebtorPaymentSalesDI.tiDebtorID)
        then assign vcFieldList                     = ""
                    vcFieldListDataTypes            = ""
                    vcValueList                     = ""
                    vcFieldListIncremental          = ""
                    vcFieldListDataTypesIncremental = ""
                    vcValueListIncremental          = "".
        
        /* ========================================== */    
        /* see if smth needs to be changed - absolute */
        /* ========================================== */                    
        if tUpdateDebtorPaymentSalesDI.ttDebtorLastPayment <> ?
        then assign vcFieldList          = vcFieldList  + (if vcFieldList = '' then '' else ',') + "DebtorLastPayment" 
                    vcFieldListDataTypes = vcFieldListDataTypes + (if vcFieldListDataTypes = '' then '' else ',') + "t" 
                    vcValueList          = vcValueList + (if vcValueList = '' then '' else chr(2)) + string(tUpdateDebtorPaymentSalesDI.ttDebtorLastPayment).
        if tUpdateDebtorPaymentSalesDI.ttDebtorLastSale <> ?
        then assign vcFieldList          = vcFieldList  + (if vcFieldList = '' then '' else ',') + "DebtorLastSale" 
                    vcFieldListDataTypes = vcFieldListDataTypes + (if vcFieldListDataTypes = '' then '' else ',') + "t" 
                    vcValueList          = vcValueList + (if vcValueList = '' then '' else chr(2)) + string(tUpdateDebtorPaymentSalesDI.ttDebtorLastSale).
    
        /* ============================================ */    
        /* see if smth needs to be changed - Incremental*/
        /* ============================================ */                                  
        if tUpdateDebtorPaymentSalesDI.tdInvoicetotal <> ?
        then assign vcFieldListIncremental          = vcFieldListIncremental  + (if vcFieldListIncremental = '' then '' else ',') + "DebtorSalesOrderBalance" 
                    vcFieldListDataTypesIncremental = vcFieldListDataTypesIncremental + (if vcFieldListDataTypesIncremental = '' then '' else ',') + "d" 
                    vcValueListIncremental          = vcValueListIncremental + (if vcValueListIncremental = '' then '' else chr(2)) + string(tUpdateDebtorPaymentSalesDI.tdInvoicetotal * -1).
        if tUpdateDebtorPaymentSalesDI.tiDebtorNbrOfInvoices <> ?
        then assign vcFieldListIncremental          = vcFieldListIncremental  + (if vcFieldListIncremental = '' then '' else ',') + "DebtorTotalNbrOfInvoices" 
                    vcFieldListDataTypesIncremental = vcFieldListDataTypesIncremental + (if vcFieldListDataTypesIncremental = '' then '' else ',') + "i" 
                    vcValueListIncremental          = vcValueListIncremental + (if vcValueListIncremental = '' then '' else chr(2)) + string(tUpdateDebtorPaymentSalesDI.tiDebtorNbrOfInvoices).
        if tUpdateDebtorPaymentSalesDI.tiDebtorDaysLate <> ?
        then assign vcFieldListIncremental          = vcFieldListIncremental  + (if vcFieldListIncremental = '' then '' else ',') + "DebtorTotalDaysLate" 
                    vcFieldListDataTypesIncremental = vcFieldListDataTypesIncremental + (if vcFieldListDataTypesIncremental = '' then '' else ',') + "i" 
                    vcValueListIncremental          = vcValueListIncremental + (if vcValueListIncremental = '' then '' else chr(2)) + string(tUpdateDebtorPaymentSalesDI.tiDebtorDaysLate ).
        
        /* ========================================== */                
        /* do the update                              */                
        /* ========================================== */    
        if last-of (tUpdateDebtorPaymentSalesDI.tiDebtorID) 
        then do:

            if vcFieldList <> ''
            then do :
                /* Reset vhFcComponent and build-up the where-clause */
                assign vhFcComponent = vhPersistanceViaFcComponent
                       vcWhereClause = "for each debtor where debtor.debtor_ID = ":U + string(tUpdateDebtorPaymentSalesDI.tiDebtorID).
                /* Use write-driect to do the update */
                <M-9 run WriteDirect
                   (input  'debtor':U (icTableName), 
                    input  vcWhereClause (icPrepare), 
                    input  vcFieldList (icFieldList), 
                    input  vcFieldListDataTypes (icFieldListDataTypes), 
                    input  vcValueList (icAbsolute), 
                    input  '':U (icIncremental), 
                    input  {&TARGETPROCEDURE} (ihClass), 
                    input  vcUserLogin (icUserLogin), 
                    output viFcReturnSuper (oiReturnStatus)) in persistence>
                if viFcReturnSuper <> 0
                then do :
                    assign oiReturnStatus = viFcReturnSuper.
                    if oiReturnStatus < 0
                    then return.
                end. /* if viFcReturnSuper <> 0 */
            end. /* vcFieldList */

            if vcFieldListIncremental <> ''
            then do :
                /* Reset vhFcComponent and build-up the where-clause */
                assign vhFcComponent = vhPersistanceViaFcComponent
                       vcWhereClause = "for each debtor where debtor.debtor_ID = ":U + string(tUpdateDebtorPaymentSalesDI.tiDebtorID).
                /* Use write-driect to do the update */
                <M-39 run WriteDirect
                   (input  'debtor':U (icTableName), 
                    input  vcWhereClause (icPrepare), 
                    input  vcFieldListIncremental (icFieldList), 
                    input  vcFieldListDataTypesIncremental (icFieldListDataTypes), 
                    input  '':U (icAbsolute), 
                    input  vcValueListIncremental (icIncremental), 
                    input  {&TARGETPROCEDURE} (ihClass), 
                    input  vcUserLogin (icUserLogin), 
                    output viFcReturnSuper (oiReturnStatus)) in persistence>
                if viFcReturnSuper <> 0
                then do :
                    assign oiReturnStatus = viFcReturnSuper.
                    if oiReturnStatus < 0
                    then return.
                end. /* if viFcReturnSuper <> 0 */
            end. /* vcFieldListIncremental */     

        end. /* last-of (tUpdateDebtorPaymentSalesDI */
                
    end. /* for each tDebtorHighCreditWriteDirect :  */
    
    /* =================================================== */
    /* empty temp-tbale as the content is no longer needed */
    /* =================================================== */
    empty temp-table tUpdateDebtorPaymentSalesDI.

end. /* if can-find (first tUpdateDebtorPaymentSalesDI )  */

/* ====================================================================================================================== */
/* IMPORTANT NOTE:                                                                                                        */
/* The normal process is that updates towards other classes are done through the normal approach with Starting&Opening    */
/* the external instance and then call a method in there. But as that decreases the performance to much for frequently    */
/* used actions like the creation of the QDInvoiceMovement-records, we will here do the creation of these                 */
/* records here via dynamic buffers.                                                                                      */
/* The temp-tables records of tQDInvoiceMovementToCreate are still created in AdditionalUpdatesAllQDInvoiceMovement       */
/* ====================================================================================================================== */
<M-79 run PostSaveDynamicCreations
   (output viDummyCount (oiNbrOfCreatedQDInvoiceMovement), 
    output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.