WIP: Renew member process
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 23 Mar 2018 20:46:28 +0000 (16:46 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 23 Mar 2018 20:46:28 +0000 (16:46 -0400)
Working on the process for renew member and their employees.

classes/billingSupport.php
models/admin/member/billing.php
views/admin/billing/renew.html
views/admin/billing/renewMembership.html [new file with mode: 0644]

index 7f82b1d..0658212 100644 (file)
@@ -793,5 +793,83 @@ class GlmBillingSupport
         return $accounts;
     }
 
+    public function createMemberInvoiceWithEmployees( $invoice_data )
+    {
+        // Make sure the required parts of $invoice_data exists.
+        if ( !isset( $invoice_data['account_id'] )
+            || !isset( $invoice_data['amount'] )
+            || !isset( $invoice_data['due_date'] )
+            || !isset( $invoice_data['member_invoice'] )
+            || !isset( $invoice_data['employee_data'] )
+            || !isset( $invoice_data['employees'] )
+        ) {
+            return false;
+        }
+        // Create invoice.
+        $this->wpdb->insert(
+            GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoices',
+            array(
+                'transaction_time' => date( 'Y-m-d H:i:s' ),
+                'account'          => $account_id,
+                'amount_total'     => $amount,
+                'balance'          => $amount,
+                'due_date'         => $due_date,
+                'paid'             => 0,
+                'notes'            => '',
+                'recurring'        => true,
+                'recurrence'       => 20
+            ),
+            array(
+                '%s', // transaction_time
+                '%d', // account
+                '%s', // amount
+                '%s', // balance
+                '%s', // due_date
+                '%s', // paid
+                '%s', // notes
+                '%s', // recurring
+                '%s', // recurrence
+            )
+        );
+        $invoice_id = $this->wpdb->insert_id;
+        if ( $invoice_id ) {
+            // Add line items for each employee.
+            foreach ( $employees as $ref_dest ) {
+                // Get the account from the ref_dest.
+                $line_account_id = $this->getAccountByRefDest( $ref_dest );
+                $this->wpdb->insert(
+                    GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'line_items',
+                    array(
+                        'invoice'        => $invoice_id,
+                        'line_item_type' => $line_item,
+                        'name'           => $_REQUEST['line_item_name'][$line_item],
+                        'amount'         => $_REQUEST['line_item_amount'][$line_item],
+                        'quantity'       => $_REQUEST['line_item_qty'][$line_item],
+                        'total'          => (float)$_REQUEST['line_item_qty'][$line_item] * (float)$_REQUEST['line_item_amount'][$line_item],
+                        'created'        => date('Y-m-d'),
+                        'first_due_date' => $_REQUEST['due_date'],
+                        'next_due_date'  => $_REQUEST['due_date'],
+                        'recurring'      => $invoiceType['recurring']['value'],
+                        'recurrence'     => $invoiceType['recurrence']
+                    ),
+                    array(
+                        '%d', // invoice
+                        '%d', // line_item_type (invoiceType id)
+                        '%s', // name
+                        '%s', // amount
+                        '%d', // quantity
+                        '%d', // total
+                        '%s', // created
+                        '%s', // first_due_date
+                        '%s', // next_due_date
+                        '%d', // recurring
+                        '%d', // recurrence
+                    )
+                );
+
+            }
+        }
+    }
+
 }
 
index 4de6596..6ebf47f 100644 (file)
@@ -183,7 +183,6 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
             if ( $member_invoice_id ) {
                 $member_invoice = $BillingSupport->getInvoicTypeById( $member_invoice_id );
-                // echo '<pre>$member_invoice: ' . print_r( $member_invoice, true ) . '</pre>';
             }
 
             $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
@@ -192,6 +191,34 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             // Get a list of this accounts employees. If they have any.
 
             break;
+
+        case 'renewMembership':
+            $view = 'renewMembership';
+            $messages[] = '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+
+            $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
+            if ( $member_invoice_id ) {
+                $member_invoice = $BillingSupport->getInvoicTypeById( $member_invoice_id );
+            }
+            $messages[] = '<pre>$member_invoice: ' . print_r( $member_invoice, true ) . '</pre>';
+
+            $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
+            $messages[] = '<pre>$employees: ' . print_r( $employees, true ) . '</pre>';
+
+            $invoice_data = array(
+                'account_id'     => filter_var( $_REQUEST['account_id'], FILTER_VALIDATE_INT ),
+                'amount'         => filter_var( $_REQUEST['total_renew_amount'], FILTER_VALIDATE_STRING ),
+                'due_date'       => date( 'Y-m-d' ),
+                'member_invoice' => $member_invoice,
+                'employee_data'  => $employees,
+                'employees'      => $_REQUEST['employees']
+            );
+
+            // Create the invoice for this member.
+
+
+            break;
+
         case 'account':
             require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH .  '/data/dataAccounts.php';
             $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
@@ -244,6 +271,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
 
             $view = 'editAccount';
             break;
+
         case 'view':
 
             $invoiceHtml = $BillingSupport->viewInvoice( $_REQUEST['id'] );
@@ -252,6 +280,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             $view = 'viewInvoice';
 
             break;
+
         case 'createPayment':
 
             $view = 'paymentProcess';
@@ -441,6 +470,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             }
 
             break;
+
         case 'makepayment':
 
             // Load DataClass for accounts.
index bd9b804..ab4f35c 100644 (file)
@@ -16,9 +16,9 @@
     <form action="{$thisUrl}?page={$thisPage}&glm_action=billing&option=makePayment" method="post">
         <input type="hidden" name="page" value="{$thisPage}" />
         <input type="hidden" name="glm_action" value="billing" />
-        <input type="hidden" name="option" value="createPayment" />
+        <input type="hidden" name="option" value="renewMembership" />
         <input type="hidden" name="member" value="{$memberID}" />
-        <input type="hidden" name="account_id" value="{$account.fieldData.id}" />
+        <input type="hidden" name="account_id" value="{$account_data.id}" />
         <input type="hidden" id="total_renew_amount" name="total_renew_amount" value="" />
 
         <h4>Employees:</h4>
diff --git a/views/admin/billing/renewMembership.html b/views/admin/billing/renewMembership.html
new file mode 100644 (file)
index 0000000..62b146c
--- /dev/null
@@ -0,0 +1,8 @@
+{include file='admin/member/header.html'}
+{include file='admin/billing/memberBillingSubHeader.html'}
+
+{foreach $messages as $message}
+{$message}<br>
+{/foreach}
+
+{include file='admin/footer.html'}