Work on setting up member as line item
authorSteve Sutton <ssutton@gmail.com>
Mon, 26 Mar 2018 11:04:10 +0000 (07:04 -0400)
committerSteve Sutton <ssutton@gmail.com>
Mon, 26 Mar 2018 11:04:10 +0000 (07:04 -0400)
working on the renewal process.

classes/billingSupport.php
models/admin/member/billing.php

index 0658212..353aab3 100644 (file)
@@ -805,6 +805,7 @@ class GlmBillingSupport
         ) {
             return false;
         }
+        extract( $invoice_data );
         // Create invoice.
         $this->wpdb->insert(
             GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoices',
@@ -832,44 +833,73 @@ class GlmBillingSupport
             )
         );
         $invoice_id = $this->wpdb->insert_id;
+        // Add the line item for from the member invoice
+        $this->createLineItemForInvoice(
+            array(
+                'invoice_id'     => $invoice_id,
+                'line_item_type' => $member_invoice['id'],
+                'name'           => $member_invoice['name'],
+                'amount'         => $member_invoice['amount'],
+                'due_date'       => $due_date,
+                'recurring'      => $recurring,
+                'recurrence'     => $recurrence,
+            )
+        );
         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
-                    )
-                );
 
             }
         }
     }
 
+    public function createLineItemForInvoice( $data )
+    {
+        // Make sure the required parts of $data exists.
+        if ( !isset( $data['invoice_id'] )
+            || !isset( $data['line_item_type'] )
+            || !isset( $data['name'] )
+            || !isset( $data['amount'] )
+            || !isset( $data['due_date'] )
+            || !isset( $data['recurring'] )
+            || !isset( $data['recurrence'] )
+        ) {
+            return false;
+        }
+        extract( $data );
+
+        $this->wpdb->insert(
+            GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'line_items',
+            array(
+                'invoice'        => $invoice_id,
+                'line_item_type' => $line_item_type,
+                'name'           => $name,
+                'amount'         => $amount,
+                'quantity'       => 1,
+                'total'          => $amount,
+                'created'        => date('Y-m-d'),
+                'first_due_date' => $due_date,
+                'next_due_date'  => $due_date,
+                'recurring'      => $recurring,
+                'recurrence'     => $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 6ebf47f..4e35163 100644 (file)
@@ -181,10 +181,12 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             $view = 'renew';
 
             $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
+            // echo '<pre>$member_invoice_id: ' . print_r( $member_invoice_id, true ) . '</pre>';
             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 );
             // echo '<pre>$employees: ' . print_r( $employees, true ) . '</pre>';
 
@@ -213,6 +215,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                 'employee_data'  => $employees,
                 'employees'      => $_REQUEST['employees']
             );
+            $messages[] = '<pre>$invoice_data: ' . print_r( $invoice_data, true ) . '</pre>';
 
             // Create the invoice for this member.