Send Invoice from invoices billing page.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 21 May 2019 20:12:35 +0000 (16:12 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 21 May 2019 20:12:35 +0000 (16:12 -0400)
Working on the send invoice part.

models/admin/billing/invoices.php
views/admin/billing/invoices.html

index f26d6e6..c87876f 100644 (file)
@@ -141,6 +141,61 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
             $option = $_REQUEST['option'];
         }
 
+        // Special case for option 'delete'
+        if ( $option == 'delete' ) {
+            $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+            if ( isset( $_REQUEST['invoice_id'] ) && $invoice_id = filter_var( $_REQUEST['invoice_id'], FILTER_VALIDATE_INT ) ) {
+                $deleteNumber = $BillingSupport->removeInvoiceById( $invoice_id );
+            }
+
+            if ( $deleteNumber ) {
+                $invoiceDeleted = true;
+            } else {
+                $invoiceDeleteError = true;
+            }
+        }
+
+        // Special case for option 'send_invoice'
+        if ( $option == 'send_invoice' ) {
+            $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+
+            $invoice_id = false;
+            $member_id  = false;
+            $account_id = false;
+
+            $type = $this->config['transaction_numb']['Invoice'];
+
+            // Get invoice method for a member account
+            if ( isset( $_REQUEST['invoice_id'] ) ) {
+                $invoice_id = filter_var( $_REQUEST['invoice_id'], FILTER_VALIDATE_INT );
+            }
+            if ( isset( $_REQUEST['member_id'] ) ) {
+                $member_id = filter_var( $_REQUEST['member_id'], FILTER_VALIDATE_INT );
+            }
+            if ( isset( $_REQUEST['account_id'] ) ) {
+                $account_id = filter_var( $_REQUEST['account_id'], FILTER_VALIDATE_INT );
+            }
+
+            if ( $invoice_id && $member_id && $account_id ) {
+                $Notifications = new GlmNotifications( $this->wpdb, $this->config );
+                $invoice       = $BillingSupport->getInvoiceById( $invoice_id );
+                $invoice_total = $invoice['balance'];
+                $data = array(
+                    'type'    => $type,
+                    'type_id' => $invoice_id,
+                    'account' => $account_id,
+                    'amount'  => $invoice_total,
+                    'payment' => 0,
+                );
+                $notices = $Notifications->getNotificationsWithSendByAction( $type );
+                foreach ( $notices as $notice ) {
+                    $Notifications->sendEmailNotification( $notice['id'], $account_id, $data );
+                }
+            }
+            echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+            $invoiceSent = true;
+        }
+
         // Do selected option
         switch ($option) {
 
@@ -533,57 +588,6 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
 
             break;
 
-        case 'delete':
-            $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
-            if ( isset( $_REQUEST['invoice_id'] ) && $invoice_id = filter_var( $_REQUEST['invoice_id'], FILTER_VALIDATE_INT ) ) {
-                $deleteNumber = $BillingSupport->removeInvoiceById( $invoice_id );
-            }
-
-            if ( $deleteNumber ) {
-                $invoiceDeleted = true;
-            } else {
-                $invoiceDeleteError = true;
-            }
-
-        case 'send_invoice':
-            $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
-
-            $invoice_id = false;
-            $member_id  = false;
-            $account_id = false;
-
-            $type = $this->config['transaction_numb']['Invoice'];
-
-            // Get invoice method for a member account
-            if ( isset( $_REQUEST['invoice_id'] ) ) {
-                $invoice_id = filter_var( $_REQUEST['invoice_id'], FILTER_VALIDATE_INT );
-            }
-            if ( isset( $_REQUEST['member_id'] ) ) {
-                $member_id = filter_var( $_REQUEST['member_id'], FILTER_VALIDATE_INT );
-            }
-            if ( isset( $_REQUEST['account_id'] ) ) {
-                $account_id = filter_var( $_REQUEST['account_id'], FILTER_VALIDATE_INT );
-            }
-
-            if ( $invoice_id && $member_id && $account_id ) {
-                $Notifications = new GlmNotifications( $this->wpdb, $this->config );
-                $invoice       = $BillingSupport->getInvoiceById( $invoice_id );
-                $invoice_total = $invoice['balance'];
-                $data = array(
-                    'type'    => $type,
-                    'type_id' => $invoice_id,
-                    'account' => $account_id,
-                    'amount'  => $invoice_total,
-                    'payment' => 0,
-                );
-                $notices = $Notifications->getNotificationsWithSendByAction( $type );
-                foreach ( $notices as $notice ) {
-                    $Notifications->sendEmailNotification( $notice['id'], $account_id, $data );
-                }
-            }
-            // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
-            $invoiceSent = true;
-
         case 'list':
         default:
 
index 4a62b8e..2c26f58 100644 (file)
@@ -31,7 +31,7 @@
             <div class="billing-search-form-container">
                 <label>Invoice #:&nbsp;</label>
                 <input id="member-invoice-id" type="hidden" name="filterInvoice" value="{$filterInvoices}">
-                <input id="invoice_id" name="searchInvoice" value="" />
+                <input id="invoiceId" name="searchInvoice" value="" />
             </div>
             <div class="billing-search-form-container">
                 <label>
                                     {/if}
                                 </span>
                                 <span class="account-dashboard-link">
-                                    <a onClick="return confirm('This will delete the invoice. This cannot be undone. Are you Sure?');" href="{$thisUrl}?page={$thisPage}&glm_action=invoices&option=delete&invoice_id={$t.id}">Delete</a>
+                                    <a onClick="return confirm('This will delete the invoice. This cannot be undone. Are you Sure?');"
+                                        href="{$thisUrl}?page={$thisPage}&glm_action=invoices&option=delete&invoice_id={$t.id}">Delete</a>
                                 </span>
                             </td>
                         </tr>
             { label: "{$m.id} ( {$m.member_name|unescape:'html'|replace:'"':''} )", value: "{$m.id|unescape:'html'|replace:'"':''}", id: '{$m.id}' },
         {/foreach}
         ]
-        $('#invoice_id').autocomplete({
+        $('#invoiceId').autocomplete({
             source: availableInvoices,
             select: function( event, ui ){
                 $('#member-invoice-id').val( ui.item.id );
-                $('#invoice_id').val( ui.item.id );
+                $('#invoiceId').val( ui.item.id );
                 // console.log( 'selected invoice id: ', ui.item.id );
                 $('#searchForm').submit();
             },