project QadFinancials > class BDPaymentSelection > method AdditionalUpdatesDInvoice

Description

update the customer invoice to indicate it is included in a payment selection
* We will do this using 'writedirect' as it is the only field that needs to be updated and it will improve performance
* We only need to do this for payment selections of type initial. For collection/paid payment selections will reset the flag
* anyway as the invoices are being paid


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDPaymentSelection.AdditionalUpdates


program code (program1/bdpaymentselection.p)

/* Check to see if we have any due date records to update */
if can-find (first tDInvoiceToUpdate)
then do:
    if viBDInvoice9ID = 0 or viBDInvoice9ID = ?
    then do:
          <I-32 {bFcStartAndOpenInstance
               &ADD-TO-TRANSACTION   = "true"
               &CLASS                = "BDInvoice"}>
    end.
    else do:
          <I-59 {bFcOpenInstance
               &CLASS           = "BDInvoice"}>
    end.
        
    /* always want to set selected to true here as if the status is N or C we have to
        update isSelected - cannot update the same record using writedirect below 
        */    
    <M-1 run UpdateDInvoiceDueDate
       (input  tDInvoiceToUpdate (tDInvoiceToChange), 
        input  tDInvoiceStageToUpdate (tDInvoiceStageToChange), 
        input  'ModifyDueDate' (icActivityCode), 
        input  true (ilSetSelected), 
        output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        
    if viFcReturnSuper < 0
    then do:
       assign 
          oiReturnStatus = -1
          vcMessageText = #T-67'Invoice Due Date(s) could not be updated':255(932776076)T-67#.
       <M-86 run SetMessage
          (input  vcMessageText (icMessage), 
           input  '' (icArguments), 
           input  '' (icFieldName), 
           input  '' (icFieldValue), 
           input  'E' (icType), 
           input  3 (iiSeverity), 
           input  '' (icRowid), 
           input  'qadfin-350103':U (icFcMsgNumber), 
           input  '' (icFcExplanation), 
           input  '' (icFcIdentification), 
           input  '' (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>        
    end.    
    
    <I-2 {bFcCloseInstance
         &CLASS           = "BDInvoice"}>
    
end.

/* if there has been an error at this point then return */            
if oiReturnStatus < 0
then return.

/* update the customer invoice to indicate it is included in a payment selection 
* We will do this using 'writedirect' as it is the only field that needs to be updated and it will improve performance 
* We only need to do this for payment selections of type initial.  For collection/paid payment selections will reset the flag
* anyway as the invoices are being paid
*/        
if not can-find (first tDPaySelLine where
                       tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICE}        or
                       tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICECORR}    or
                       tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTE}     or
                       tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTECORR} or
                       tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENTINV}  or
                       tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-ADJUSTMENT})
then next.

assign vcWhereClauseTRUE  = ''
       vicntTRUE          = 0
       vcWhereStgClauseTRUE = ''
       vicntStgTRUE     = 0.
      
empty temp-table tSelectedDInvoiceDPaySel.
empty temp-table tSelectedDInvoiceStageDPaySel.

assign vcWhereClauseFALSE  = ''
       vicntFALSE          = 0
       vcWhereStgClauseFALSE = ''
       vicntStgFALSE     = 0.
  
empty temp-table tSelectedDInvoiceDPaySelDelete.
empty temp-table tSelectedDInvStageDPaySelDel.
        
/* Start the Persistence layer of BCinvoice to allow a WriteDirect */     
<M-11 run StartPersistence
   (output vhFcComponent (ohPersistence), 
    output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>  
if viFcReturnSuper <> 0
then do :
    assign oiReturnStatus = viFcReturnSuper.           
    if oiReturnStatus < 0
    then return.
end. /* if viFcReturnSuper <> 0 */

invoice:            
for each tDPaySel where tDPaySel.DPaySelStatus = {&DOCUMENTSTATUS-INIT},
    each tDPaySelLine where tDPaySelLine.tc_parentrowid =  tDPaySel.tc_rowid 
    and (tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICE}        or
         tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICECORR}    or
         tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTE}     or
         tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTECORR} or
         tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENTINV}  or
         tDPaySelLine.DPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-ADJUSTMENT}) and
         (tDPaySelLine.tc_status = "N" or tDPaySelLine.tc_status = "C" or tDPaySelLine.tc_status = "D") on error undo, throw:

    /* check to see if the invoice has already been updated in updateDueDate method above */   
    find first tDInvoiceToUpdate 
          where tDInvoiceToUpdate.tiDInvoiceId = tDPaySelLine.DPaySelLineParentObject_ID  no-error.
    if available tDInvoiceToUpdate    
    then next invoice.    
        
    /* adding new lines */     
    if   tDPaySelLine.DPaySelLineStatus = {&PAYSEL-LINE-STATUS-NEW} and 
         tDPaySelLine.tc_status = "N"
    then do:        
        stage:     
        /* Mark the stages included as paid - if the stages were moved their tc_status = N but*/      
        for each tDPaySelLineStg 
           where tDPaySelLineStg.tc_parentrowid = tDPaySelLine.tc_rowid
             and tDPaySelLineStg.tc_status = "N" and tDPaySelLineStg.DPaySelLineStgStatus = {&PAYSEL-LINE-STATUS-NEW}             
             and tDPaySelLineStg.DPaySelLineStgPaymAmtTC <> 0 on error undo, throw:
       
            /* check to see if the invoice has already been updated in updateDueDate method above */            
            find first tDInvoiceStageToUpdate 
                  where tDInvoiceStageToUpdate.tiDInvoiceStageId = tDPaySelLineStg.DInvoiceStage_ID no-error.   
            if available tDInvoiceStageToUpdate
            then next stage.
             /* Only update the invoice one */
            find tSelectedDInvoiceStageDPaySel where
                 tSelectedDInvoiceStageDPaySel.tiDInvoiceStageId = tDPaySelLineStg.DInvoiceStage_ID                 
                 no-error.
            if available tSelectedDInvoiceStageDPaySel 
            then next stage.        

            create tSelectedDInvoiceStageDPaySel.
            assign 
                tSelectedDInvoiceStageDPaySel.tiDInvoiceStageId = tDPaySelLineStg.DInvoiceStage_ID
                tSelectedDInvoiceStageDPaySel.tiDInvoiceID = tDPaySelLine.DPaySelLineParentObject_ID   
                vicntStgTRUE         = vicntStgTRUE + 1
                vcWhereStgClauseTRUE = vcWhereStgClauseTRUE + " ":U + 
                               (if vcWhereStgClauseTRUE = '':U then "for each DInvoiceStage where ":U 
                                else " or ":U ) + 
                                "DInvoiceStage.DInvoiceStage_ID = ":U + string(tDPaySelLineStg.DInvoiceStage_ID).               
             /* Do the updates in chunks of 100 */
            if vicntStgTRUE = 100
            then do :                   
                <M-35 run WriteDirect
                   (input  'DInvoiceStage':U (icTableName), 
                    input  vcWhereStgClauseTRUE (icPrepare), 
                    input  'DInvoiceStageIsSelected':U (icFieldList), 
                    input  'L':U (icFieldListDataTypes), 
                    input  'true':U (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. /* if viFcReturnSuper <> 0 */
                
                assign vcWhereStgClauseTRUE  = ''
                       vicntStgTRUE          = 0.                
                       
            end. /* if vicntTRUE = 100 */
        end.    /* for each tDPaySelLineStg end of stages */       
        /* don't mark the flag on the invoice if we are marking the flag at stage level */          
        if can-find (first tDPaySelLineStg where tDPaySelLineStg.tc_parentrowid = tDPaySelLine.tc_rowid)
        then next invoice.
        /* Only update the invoice once */     
        find tSelectedDInvoiceDPaySel where
             tSelectedDInvoiceDPaySel.tiDInvoiceId = tDPaySelLine.DPaySelLineParentObject_ID
             no-error.
        if available tSelectedDInvoiceDPaySel 
        then next invoice.

        create tSelectedDInvoiceDPaySel.
        assign 
            tSelectedDInvoiceDPaySel.tiDInvoiceId = tDPaySelLine.DPaySelLineParentObject_ID    
            vicntTRUE         = vicntTRUE + 1
            vcWhereClauseTRUE = vcWhereClauseTRUE + " ":U + 
                               (if vcWhereClauseTRUE = '':U then "for each DInvoice where ":U 
                                else " or ":U ) + 
                                "DInvoice.DInvoice_ID = ":U + string(tDPaySelLine.DPaySelLineParentObject_ID).            
        /* Do the updates in chunks of 100 */
        if vicntTRUE = 100
        then do :                     
            <M-85 run WriteDirect
               (input  'DInvoice':U (icTableName), 
                input  vcWhereClauseTRUE (icPrepare), 
                input  'DInvoiceIsSelected':U (icFieldList), 
                input  'L':U (icFieldListDataTypes), 
                input  'true':U (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. /* if viFcReturnSuper <> 0 */
            
            assign vcWhereClauseTRUE  = ''
                   vicntTRUE          = 0.                   
        end. /* if vicntTRUE = 100 */                
    end.   /*  tDPaySelLine.DPaySelLineStatus = {&PAYSEL-LINE-STATUS-NEW} */                
    /************ DELETED/CANCELLED LINES/STAGES *************************/    
    /* have any records been cancelled (executed) or deleted (not-executed)? 
        if so set selected to false 
        if one stage has been removed then the status of the line can be C */
     else if (tDPaySelLine.tc_status = "C" or tDPaySelLine.tc_status = "D")
     then do:           
        /* Start the Persistence layer of BCinvoice to allow a WriteDirect */     
        <M-38 run StartPersistence
           (output vhFcComponent (ohPersistence), 
            output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>  
        if viFcReturnSuper <> 0
        then do :
            assign oiReturnStatus = viFcReturnSuper.           
            if oiReturnStatus < 0
            then return.
        end. /* if viFcReturnSuper <> 0 */                                          
       /* invoice2: */
        stage2:     
        /* Mark the stages included as paid */             
        for each tDPaySelLineStg 
           where tDPaySelLineStg.tc_parentrowid = tDPaySelLine.tc_rowid
             and ( tDPaySelLineStg.DPaySelLineStgStatus = {&PAYSEL-LINE-STATUS-CANCEL} or 
                   ( tDPaySelLineStg.tc_status = "D" and tDPaySelLineStg.DPaySelLineStgStatus <> {&PAYSEL-LINE-STATUS-MODIFIED} )
                   or ( tDPaySelLine.tc_status = "D" and tDPaySelLineStg.DPaySelLineStgStatus <> {&PAYSEL-LINE-STATUS-MODIFIED} ))
                   on error undo, throw:                     

             /* Only update the invoice one */     
            find tSelectedDInvStageDPaySelDel where
                 tSelectedDInvStageDPaySelDel.tiDInvoiceStageId = tDPaySelLineStg.DInvoiceStage_ID                 
                 no-error.
            if available tSelectedDInvStageDPaySelDel 
            then next stage2.

            create tSelectedDInvStageDPaySelDel.
            assign 
                tSelectedDInvStageDPaySelDel.tiDInvoiceStageId = tDPaySelLineStg.DInvoiceStage_ID
                tSelectedDInvStageDPaySelDel.tiDInvoiceID = tDPaySelLine.DPaySelLineParentObject_ID   
                vicntStgFALSE         = vicntStgFALSE + 1
                vcWhereStgClauseFALSE = vcWhereStgClauseFALSE + " ":U + 
                               (if vcWhereStgClauseFALSE = '':U then "for each DInvoiceStage where ":U 
                                else " or ":U ) + 
                                "DInvoiceStage.DInvoiceStage_ID = ":U + string(tDPaySelLineStg.DInvoiceStage_ID).                
             /* Do the updates in chunks of 100 */
            if vicntStgFALSE = 100
            then do :                    
                <M-3 run WriteDirect
                   (input  'DInvoiceStage':U (icTableName), 
                    input  vcWhereStgClauseFALSE (icPrepare), 
                    input  'DInvoiceStageIsSelected':U (icFieldList), 
                    input  'L':U (icFieldListDataTypes), 
                    input  'false':U (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. /* if viFcReturnSuper <> 0 */
                
                assign vcWhereStgClauseFALSE  = ''
                       vicntStgFALSE          = 0.                           
            end. /* if vicntTRUE = 100 */
        end.    /* end of stages */       
        /* don't mark the flag on the invoice if we are marking the flag at stage level or if the invoice
            is not cancelled */          
        if can-find (first tSelectedDInvStageDPaySelDel 
          where tSelectedDInvStageDPaySelDel.tiDInvoiceId = tDPaySelLine.DPaySelLineParentObject_ID) 
        then next invoice.
        
        /* Only update the invoice one */     
        find tSelectedDInvStageDPaySelDel where
             tSelectedDInvStageDPaySelDel.tiDInvoiceId = tDPaySelLine.DPaySelLineParentObject_ID              
             no-error.
        if available tSelectedDInvStageDPaySelDel 
        then next invoice.                  
                          
        /* only update the invoice if it's cancelled */
        if tDPaySelLine.DPaySelLineStatus = {&PAYSEL-LINE-STATUS-CANCEL} or tDPaySelLine.tc_status = "D"
        then do:            
            create tSelectedDInvStageDPaySelDel.
            assign 
                tSelectedDInvStageDPaySelDel.tiDInvoiceId = tDPaySelLine.DPaySelLineParentObject_ID    
                vicntFALSE         = vicntFALSE + 1
                vcWhereClauseFALSE = vcWhereClauseFALSE + " ":U + 
                                   (if vcWhereClauseFALSE = '':U then "for each DInvoice where ":U 
                                    else " or ":U ) + 
                                    "DInvoice.DInvoice_ID = ":U + string(tDPaySelLine.DPaySelLineParentObject_ID).            
            /* Do the updates in chunks of 100 */
            if vicntFALSE = 100
            then do :                    
                <M-40 run WriteDirect
                   (input  'DInvoice':U (icTableName), 
                    input  vcWhereClauseFALSE (icPrepare), 
                    input  'DInvoiceIsSelected':U (icFieldList), 
                    input  'L':U (icFieldListDataTypes), 
                    input  'false':U (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. /* if viFcReturnSuper <> 0 */                
                assign vcWhereClauseFALSE  = ''
                       vicntFALSE          = 0.
                       
            end. /* if vicntFALSE = 100 */
        end. /* if tDPaySelLine.DPaySelLineStatus = {&PAYSEL-LINE-STATUS-CANCEL} */              
     end.   /* else if (tDPaySelLine.tc_status = "C" */   
end. /* if for each */     

/* Do the updates in chunks of 100 */
if vicntTRUE > 0
then do :        
    <M-65 run WriteDirect
       (input  'DInvoice':U (icTableName), 
        input  vcWhereClauseTRUE (icPrepare), 
        input  'DInvoiceIsSelected':U (icFieldList), 
        input  'L':U (icFieldListDataTypes), 
        input  'true':U (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. /* if viFcReturnSuper <> 0 */
end. /* if vicntTRUE > 0 */

if vicntStgTRUE > 0
then do :        
    <M-95 run WriteDirect
       (input  'DInvoiceStage':U (icTableName), 
        input  vcWhereStgClauseTRUE (icPrepare), 
        input  'DInvoiceStageIsSelected':U (icFieldList), 
        input  'L':U (icFieldListDataTypes), 
        input  'true':U (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. /* if viFcReturnSuper <> 0 */
    
    assign vcWhereStgClauseTRUE  = ''
           vicntStgTRUE          = 0.
 end. /* if vicntStgTRUE > 0 */    
 
/* Do the updates in chunks of 100 */
if vicntFALSE > 0
then do :               
    <M-98 run WriteDirect
       (input  'DInvoice':U (icTableName), 
        input  vcWhereClauseFALSE (icPrepare), 
        input  'DInvoiceIsSelected':U (icFieldList), 
        input  'L':U (icFieldListDataTypes), 
        input  'false':U (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. /* if viFcReturnSuper <> 0 */
end. /* if vicntFALSE > 0 */
if vicntStgFALSE > 0
then do :        
    <M-21 run WriteDirect
       (input  'DInvoiceStage':U (icTableName), 
        input  vcWhereStgClauseFALSE (icPrepare), 
        input  'DInvoiceStageIsSelected':U (icFieldList), 
        input  'L':U (icFieldListDataTypes), 
        input  'false':U (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. /* if viFcReturnSuper <> 0 */
    
    assign vcWhereStgClauseFALSE  = ''
           vicntStgFALSE          = 0.
 end. /* vicntStgFALSE > 0 */