project QadFinancials > class BPaymentSelection > method UpdatesCInvoiceIsSelected

Description

update the selected flag of the cinvoices


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPaymentSelection.PostSave


program code (program5/bpaymentselection.p)

/* ====================================================================================================== */
/* This method sets the CInvoiceIsSelected indication to true/false in case we are creating/modifying or  */
/* deleting the payment selection. We use a WriteDirect as the invoice can be a cross-cy invoice and as   */
/* these activities don't change anything else to the CInvoice (or related) tables, so they don't need an */
/* instance of BCinvoice                                                                                  */
/* In case of Register/Uncofirm the correct value of this field will be set in the                        */
/* BCinvoice.CreateCInvoicemovements method, which handles it for both 'local' as crosscy invoices        */
/* ====================================================================================================== */
if vcActivityCode       <> {&PAYMENTSELECTIONACTIVITY-DELETE} and
   vcActivityCode       <> {&PAYMENTSELECTIONACTIVITY-CREATE} and
   vcActivityCode       <> {&PAYMENTSELECTIONACTIVITY-MODIFY}
then next.   

if not can-find (first tPaySelLine where
                       tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICE}        or
                       tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICECORR}    or
                       tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTE}     or
                       tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTECORR} or
                       tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENTINV}  or
                       tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-ADJUSTMENT})
then next.
                      

assign oiReturnStatus = -98.

assign vcWhereClauseTRUE  = ''
       vicntTRUE          = 0
       vcWhereClauseFALSE = ''
       vicntFALSE         = 0.
empty temp-table tSelectedCInvoicePaySel.
       
/* Start the Persistence layer of BCinvoice to allow a WriteDirect */     
<M-6 run StartPersistence
   (output vhFcComponent (ohPersistence), 
    output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>  
if viFcReturnSuper <> 0
then do :
    assign oiReturnStatus = viFcReturnSuper.           
    if oiReturnStatus < 0
    then return.
end. /* if viFcReturnSuper <> 0 */
           
/* Go through the lines and set the IsSelected correctly */           
for each tPaySelLine where
         tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICE}        or
         tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICECORR}    or
         tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTE}     or
         tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTECORR} or
         tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENTINV}  or
         tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-ADJUSTMENT} :
         
         
    if tPaySelLine.tc_Status <> "":U
    then do:
    
        find tSelectedCInvoicePaySel where
             tSelectedCInvoicePaySel.tiCInvoiceId = tPaySelLine.PaySelLineParentObject_ID
             no-error.
        if available tSelectedCInvoicePaySel 
        then next.

        create tSelectedCInvoicePaySel.
        assign tSelectedCInvoicePaySel.tiCInvoiceId = tPaySelLine.PaySelLineParentObject_ID.
    
    end. /* if tPaySelLine.tc_Status <> "":U */
    
    if(vcActivityCode = {&PAYMENTSELECTIONACTIVITY-CREATE} and tPaySelLine.tc_Status = 'N' and tPaySelLine.tlProposedLineIsSelected) or
      (vcActivityCode = {&PAYMENTSELECTIONACTIVITY-MODIFY} and tPaySelLine.tc_Status = 'N' and tPaySelLine.tlProposedLineIsSelected) or
      (vcActivityCode = {&PAYMENTSELECTIONACTIVITY-MODIFY} and tPaySelLine.tc_Status = 'C' and tPaySelLine.tlProposedLineIsSelected)
    then do :
        assign vicntTRUE          = vicntTRUE + 1
               vcWhereClauseTRUE = vcWhereClauseTRUE + " ":U + 
                                       (if vcWhereClauseTRUE = '':U
                                    then "for each CInvoice where ":U 
                                    else " or ":U ) + 
                                   "CInvoice.CInvoice_ID = ":U + string(tPaySelLine.PaySelLineParentObject_ID).
    end.
    else
    if vcActivityCode = {&PAYMENTSELECTIONACTIVITY-DELETE} or
      (vcActivityCode = {&PAYMENTSELECTIONACTIVITY-MODIFY} and tPaySelLine.tc_Status = 'D')
    then do :
        assign vicntFALSE         = vicntFALSE + 1
               vcWhereClauseFALSE = vcWhereClauseFALSE + " ":U + 
                                       (if vcWhereClauseFALSE = '':U
                                    then "for each CInvoice where ":U 
                                    else " or ":U ) + 
                                   "CInvoice.CInvoice_ID = ":U + string(tPaySelLine.PaySelLineParentObject_ID).
    end.
    
    /* Do the updates in chunks of 100 */
    if vicntTRUE = 100
    then do :        
        <M-52 run WriteDirect
           (input  'CInvoice':U (icTableName), 
            input  vcWhereClauseTRUE (icPrepare), 
            input  'CInvoiceIsSelected':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 */
    
    
    /* Do the updates in chunks of 100 */
    if vicntFALSE = 100
    then do :        
        <M-85 run WriteDirect
           (input  'CInvoice':U (icTableName), 
            input  vcWhereClauseFALSE (icPrepare), 
            input  'CInvoiceIsSelected':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. /* for each tPaySelLine */

/* Do the updates in chunks of 100 */
if vicntTRUE > 0
then do :        
    <M-87 run WriteDirect
       (input  'CInvoice':U (icTableName), 
        input  vcWhereClauseTRUE (icPrepare), 
        input  'CInvoiceIsSelected':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 */

/* Do the updates in chunks of 100 */
if vicntFALSE > 0
then do :        
    <M-53 run WriteDirect
       (input  'CInvoice':U (icTableName), 
        input  vcWhereClauseFALSE (icPrepare), 
        input  'CInvoiceIsSelected':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 oiReturnStatus = -98
then assign oiReturnStatus = 0.