project QadFinancials > class BBill > 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/bbill.p)

<ANCESTOR-CODE>
if vcActivityCode = "Create" or 
   vcActivityCode = "SetBillDate" or
   vcActivityCode = "Modify" or
   vcActivityCode = "Delete" 
then do:
    for each tBill no-lock:
        <M-54 run StartPersistence
           (output vhFcComponent (ohPersistence), 
            output viFcReturnSuper (oiReturnStatus)) in BBill>
        if viFcReturnSuper <> 0
        then do :
            assign oiReturnStatus = viFcReturnSuper.
            if oiReturnStatus < 0
            then return.
        end.
        assign vhPersistanceViaFcComponent = vhFcComponent. 
        
        
        
        if tBill.tc_Status = 'N':U then
        do:                        
            for each tDInvoiceToBillForSave no-lock where tDInvoiceToBillForSave.tlDInvoiceIsSelected = yes and
                                                          tDInvoiceToBillForSave.tiBill_ID = tBill.Bill_ID:
                assign vcForEachClause = "for each DInvoice where DInvoice.DInvoice_ID = ":U + string(tDInvoiceToBillForSave.tiDInvoice_ID)
                       vcFieldList = "Bill_ID,DInvoiceDueDate,DInvoiceBillDate":U
                       vcFieldListDataTypes = "i,t,t":U
                       vcValueList = string(tBill.Bill_ID) + chr(02) + string(tDInvoiceToBillForSave.ttDInvoiceDueDate) + chr(02) + string(tDInvoiceToBillForSave.ttDInvoiceBillDate).
                
                assign vhFcComponent = vhPersistanceViaFcComponent.
                <M-43 run WriteDirect
                   (input  'DInvoice':U (icTableName), 
                    input  vcForEachClause (icPrepare), 
                    input  vcFieldList (icFieldList), 
                    input  vcFieldListDataTypes (icFieldListDataTypes), 
                    input  vcValueList (icAbsolute), 
                    input  '':U (icIncremental), 
                    input  {&TARGETPROCEDURE} (ihClass), 
                    input  vcUserLogin (icUserLogin), 
                    output viFcReturnSuper (oiReturnStatus)) in Progress>
             
                if viFcReturnSuper <> 0
                then do :
                    assign oiReturnStatus = viFcReturnSuper.
                    if oiReturnStatus < 0
                    then do:
                        assign vhFcComponent = ?.
                        <M-23 run ReleaseNumber
                           (input  tBill.Company_ID (iiCompanyId), 
                            input  tBill.BillYear (iiNumbrYear), 
                            input  'BILLING' (icNumbrType), 
                            input  tBill.BillNumber (iiNumbr), 
                            input  viFcCurrentInstanceId (iiInstanceId), 
                            input  vcFcComponentName (icClassName), 
                            output viFcReturnSuper (oiReturnStatus)) in BNumber>
                        return.   
                    end.             
                end.            
            end. /* end for each tDInvoiceToBill no-lock where tDInvoiceToBill.tlDInvoiceIsSelected */  
            
            assign vhFcComponent = ?.
            <M-49 run CommitNumber
               (input  tBill.Company_ID (iiCompanyID), 
                input  tBill.BillYear (iiNumbrYear), 
                input  'BILLING' (icNumbrType), 
                input  tBill.BillNumber (iiNumbr), 
                input  viFcCurrentInstanceId (iiInstanceId), 
                input  vcFcComponentName (icClassName), 
                output viFcReturnSuper (oiReturnStatus)) in BNumber>                
        end. /* if tBill.tc_Status = 'N':U */
        else if tBill.tc_Status = 'C':U or tBill.tc_Status = '':U then
        do:       
            <Q-29 run DInvoiceByBillId (all) (Read) (NoCache)
               (input tBill.Company_ID, (CompanyId)
                input tBill.Bill_ID, (Bill_ID)
                output dataset tqDInvoiceByBillId) in BDInvoice> 
            /* add or update invoices */
            for each tDInvoiceToBillForSave where 
                tDInvoiceToBillForSave.tlDInvoiceIsSelected = yes and tDInvoiceToBillForSave.tiDInvoice_ID <> 0:
                find first tqDInvoiceByBillId 
                     where tqDInvoiceByBillId.tiDInvoice_ID = tDInvoiceToBillForSave.tiDInvoice_ID no-error.
                if not available tqDInvoiceByBillId then
                do:
                    assign vcForEachClause = "for each DInvoice where DInvoice.DInvoice_ID = ":U + string(tDInvoiceToBillForSave.tiDInvoice_ID)
                    vcFieldList = "Bill_ID,DInvoiceBillDate":U
                    vcFieldListDataTypes = "i,t":U
                    vcValueList = string(tBill.Bill_ID) + chr(02) + string(tDInvoiceToBillForSave.ttDInvoiceBillDate).
                     
                    assign vhFcComponent = vhPersistanceViaFcComponent. 
                    <M-74 run WriteDirect
                       (input  'DInvoice':U (icTableName), 
                        input  vcForEachClause (icPrepare), 
                        input  vcFieldList (icFieldList), 
                        input  vcFieldListDataTypes (icFieldListDataTypes), 
                        input  vcValueList (icAbsolute), 
                        input  '':U (icIncremental), 
                        input  {&TARGETPROCEDURE} (ihClass), 
                        input  vcUserLogin (icUserLogin), 
                        output viFcReturnSuper (oiReturnStatus)) in Progress>
                    if viFcReturnSuper <> 0
                    then do :
                        assign oiReturnStatus = viFcReturnSuper.
                        if oiReturnStatus < 0
                        then return.
                    end.
                end. /* end  if not available tqDInvoiceByBillId */ 
            end. /* end for each tDInvoiceToBill */
        
            find first tDInvoiceToBillForSave no-error.
            if tDInvoiceToBillForSave.tlBillScheduleIsUpdInvByBill then
            do:
    
                for each tDInvoiceToBillForSave where 
                    tDInvoiceToBillForSave.tlDInvoiceIsSelected = yes:
    
                    assign vcForEachClause = "for each DInvoice where DInvoice.DInvoice_ID = ":U + string(tDInvoiceToBillForSave.tiDInvoice_ID).
    
                    assign vhFcComponent = vhPersistanceViaFcComponent.
                    <M-44 run WriteDirect
                       (input  'DInvoice':U (icTableName), 
                        input  vcForEachClause (icPrepare), 
                        input  'DInvoiceDueDate':U (icFieldList), 
                        input  't':U (icFieldListDataTypes), 
                        input  string(tBill.BillDueDate) (icAbsolute), 
                        input  '':U (icIncremental), 
                        input  {&TARGETPROCEDURE} (ihClass), 
                        input  vcUserLogin (icUserLogin), 
                        output viFcReturnSuper (oiReturnStatus)) in Progress>
                    if viFcReturnSuper <> 0
                    then do :
                        assign oiReturnStatus = viFcReturnSuper.
                        if oiReturnStatus < 0
                        then return.
                    end. 
                end.             
            end.
        
            /* delete invoice */
            for each tqDInvoiceByBillId:
                find first tDInvoiceToBillForSave 
                    where tDInvoiceToBillForSave.tiDInvoice_ID = tqDInvoiceByBillId.tiDInvoice_ID and
                          tDInvoiceToBillForSave.tlDInvoiceIsSelected = yes no-error.
                if not available tDInvoiceToBillForSave then
                do:
                    assign vcForEachClause = "for each DInvoice where DInvoice.DInvoice_ID = ":U + string(tqDInvoiceByBillId.tiDInvoice_ID)
                    vcFieldList = "Bill_ID,DInvoiceBillDate":U
                    vcFieldListDataTypes = "i,t":U
                    vcValueList = "0" + chr(02) + "?".
                      
                    assign vhFcComponent = vhPersistanceViaFcComponent.  
                    <M-70 run WriteDirect
                       (input  'DInvoice':U (icTableName), 
                        input  vcForEachClause (icPrepare), 
                        input  vcFieldList (icFieldList), 
                        input  vcFieldListDataTypes (icFieldListDataTypes), 
                        input  vcValueList (icAbsolute), 
                        input  '':U (icIncremental), 
                        input  {&TARGETPROCEDURE} (ihClass), 
                        input  vcUserLogin (icUserLogin), 
                        output viFcReturnSuper (oiReturnStatus)) in Progress>
                    if viFcReturnSuper <> 0
                    then do :
                        assign oiReturnStatus = viFcReturnSuper.
                        if oiReturnStatus < 0
                        then return.
                    end.
    
                end. 
            end. /* for each tqDInvoiceByBillGroupInfo */
        end. /* else if tBill.tc_Status = 'C':U */ 
        else if tBill.tc_Status = 'D':U then
        do:
                  
            assign vcForEachClause = "for each DInvoice where DInvoice.Bill_ID = ":U + string(tBill.Bill_ID)
                   vcFieldList = "Bill_ID,DInvoiceBillDate":U
                   vcFieldListDataTypes = "i,t":U
                   vcValueList = "0" + chr(02) + "?".
            assign vhFcComponent = vhPersistanceViaFcComponent.   
            <M-64 run WriteDirect
               (input  'DInvoice':U (icTableName), 
                input  vcForEachClause (icPrepare), 
                input  vcFieldList (icFieldList), 
                input  vcFieldListDataTypes (icFieldListDataTypes), 
                input  vcValueList (icAbsolute), 
                input  '':U (icIncremental), 
                input  {&TARGETPROCEDURE} (ihClass), 
                input  vcUserLogin (icUserLogin), 
                output viFcReturnSuper (oiReturnStatus)) in Progress>
            if viFcReturnSuper <> 0
            then do :
                assign oiReturnStatus = viFcReturnSuper.
                if oiReturnStatus < 0
                then return.
            end.
        end. 
    end. /* for each tBill */       
end. /* if vcActivityCode = "Create" */