WIP for edit invoices
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 7 Dec 2018 21:55:41 +0000 (16:55 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 7 Dec 2018 21:55:41 +0000 (16:55 -0500)
Getting line items.

models/admin/billing/invoices.php
todo.txt
views/admin/billing/editInvoice.html
views/admin/billing/invoices.html

index 2f04706..4a3e053 100644 (file)
@@ -93,6 +93,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
 
         $option             = 'list';
         $this->invoice_id   = false;
+        $lineItems          = false;
         $haveInvoices       = false;
         $invoiceUpdated     = false;
         $invoiceUpdateError = false;
@@ -177,6 +178,33 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
 
             break;
 
+        case 'edit':
+            // Should have an id here
+            if ( isset( $_REQUEST['id'] ) ) {
+                $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+                $this->invoice_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT );
+                $invoices         = $this->editEntry( $this->invoice_id );
+                // echo '<pre>$invoices: ' . print_r( $invoices, true ) . '</pre>';
+                $view            = 'editInvoice';
+                $InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config );
+                $invoiceTypes    = $InvoiceTypesObj->getList();
+                $lineItems       = $BillingSupport->getLineItemsForInvoice( $this->invoice_id );
+                // Sort the types by parent child
+                $invoiceTypes    = $InvoiceTypesObj->sortParentChild($invoiceTypes);
+                if ( isset( $invoiceTypes ) ) {
+                    foreach ( $invoiceTypes as $invoiceType ) {
+                        $invTypes[$invoiceType['id']] = array(
+                            'id'     => $invoiceType['id'],
+                            'name'   => $invoiceType['name'],
+                            'amount' => $invoiceType['amount'],
+                        );
+                    }
+                    $invoiceTypeJSON = json_encode( $invTypes, JSON_NUMERIC_CHECK );
+                }
+
+            }  // show error?
+            break;
+
         case 'add':
             $invoices        = $this->newEntry();
             // Set the view file to editInvoice
@@ -324,23 +352,23 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
             }
             break;
 
-        case 'edit':
-            $invoices = $this->editEntry($this->invoice_id);
-
-            // If we have a good invoices
-            if ($invoices['status']) {
-                $haveTransactions = true;
-            }
-
-            // If we're locked to a member as a contact user and the invoices member doesn't equal the contact member
-            if ($lockedToMember && $invoices['fieldData']['ref_dest_id'] != $lockedToMember) {
-                $haveTransactions = false;
-                $invoices = false;
-            }
-
-            // Set the view file to editInvoice
-            $view = 'editInvoice';
-            break;
+        // case 'edit':
+        //     $invoices = $this->editEntry($this->invoice_id);
+        //
+        //     // If we have a good invoices
+        //     if ($invoices['status']) {
+        //         $haveTransactions = true;
+        //     }
+        //
+        //     // If we're locked to a member as a contact user and the invoices member doesn't equal the contact member
+        //     if ($lockedToMember && $invoices['fieldData']['ref_dest_id'] != $lockedToMember) {
+        //         $haveTransactions = false;
+        //         $invoices = false;
+        //     }
+        //
+        //     // Set the view file to editInvoice
+        //     $view = 'editInvoice';
+        //     break;
 
         case 'update':
 
@@ -536,6 +564,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
             'option'              => $option,
             'invoice_id'          => $this->invoice_id,
             'invoices'            => $invoices,
+            'lineItems'           => $lineItems,
             'nonAccountMembers'   => $nonAccountMembers,
             'haveInvoices'        => $haveInvoices,
             'invoiceUpdated'      => $invoiceUpdated,
index d726948..386e8e2 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -14,6 +14,9 @@ Invoicing:
 [x] -- Filter by county and category or member type
 [x]-Create labels
 [ ] -Send Email (invoices)
+[ ] Pro - Rate an invoice
+[ ] Ability to edit an invoice
+[ ] Ability to delete an invoice
 
 Reports:
 -Open Accounts
index 0be2545..540a74e 100644 (file)
         {if $invoice_id}
             <input type="hidden" name="option" value="update">
             <input type="hidden" name="id" value="{$invoice_id}">
+            <input type="hidden" name="account" value="{$invoices.fieldData.account.value}">
         {else}
             <input type="hidden" name="option" value="insert">
         {/if}
         <div class="glm-row">
             <div class="glm-columns glm-small-12 glm-large-12">
 
+                {if !$invoice_id}
                 <div class="glm-row">
                     <div style="text-align: right;padding-right: 5px;" class="glm-columns glm-small-12 glm-large-3 glm-required">
                         Billing Account
@@ -28,6 +30,7 @@
                         <a id="newAccountButton" href="#">New Account</a>
                     </div>
                 </div>
+                {/if}
                 <div class="glm-row">
                     <div style="text-align: right;padding-right: 5px;" class="glm-columns glm-small-12 glm-large-3 glm-required">
                         Due Date
index bd4172d..b34448d 100644 (file)
@@ -73,7 +73,7 @@
                 {else}
                     <tr class="alternate">
                 {/if}
-                    <td> {$t.id} </td>
+                    <td> <a href="{$adminUrl}?page=glm-members-admin-menu-billing&glm_action=invoices&option=edit&id={$t.id}">{$t.id}</a> </td>
                     <td> <a href="{$adminUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$t.member_id}">{$t.member_name}</a> </td>
                     <td>
                     {foreach $t.line_items as $item}