From: Steve Sutton Date: Mon, 26 Mar 2018 11:04:10 +0000 (-0400) Subject: Work on setting up member as line item X-Git-Tag: v1.0.0^2~107 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=f79d54881b97ca246b6b85b714bedf65db0ccc0a;p=WP-Plugins%2Fglm-member-db-billing.git Work on setting up member as line item working on the renewal process. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 0658212..353aab3 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -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 + ) + ); + } + } diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index 6ebf47f..4e35163 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -181,10 +181,12 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling $view = 'renew'; $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID ); + // echo '
$member_invoice_id: ' . print_r( $member_invoice_id, true ) . '
'; if ( $member_invoice_id ) { $member_invoice = $BillingSupport->getInvoicTypeById( $member_invoice_id ); } + // echo '
$member_invoice: ' . print_r( $member_invoice, true ) . '
'; $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); // echo '
$employees: ' . print_r( $employees, true ) . '
'; @@ -213,6 +215,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling 'employee_data' => $employees, 'employees' => $_REQUEST['employees'] ); + $messages[] = '
$invoice_data: ' . print_r( $invoice_data, true ) . '
'; // Create the invoice for this member.