From: Steve Sutton Date: Mon, 5 Aug 2019 20:39:41 +0000 (-0400) Subject: Update invoice create page to use renewal flag. X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=d9053ec985d55fb5d7ee616c787d0a98ecfd664f;p=WP-Plugins%2Fglm-member-db-billing.git Update invoice create page to use renewal flag. Properly flag an invoice so it sets renewal date when paid. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 80f361e..334f89e 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -241,14 +241,17 @@ class GlmBillingSupport ); // find out if this invoice is a renewal. - $is_renewal = $this->wpdb->get_var( + $invoiceData = $this->wpdb->get_var( $this->wpdb->prepare( - "SELECT renewal + "SELECT renewal,account FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices WHERE id = %d", $invoice_id ) ); + $account_id = $invoiceData['account']; + $is_renewal = $invoiceData['renewal']; + $this->updateAccountRenewalDate( $invoiceData['account'] ); // If this is a renewal then get all line items and update their renewal dates. if ( $is_renewal ) { @@ -263,7 +266,9 @@ class GlmBillingSupport ); if ( $line_items ) { foreach ( $line_items as $account ) { - $this->updateAccountRenewalDate( $account['account'] ); + if ( $account['account'] && $account['account'] != $account_id ) { + $this->updateAccountRenewalDate( $account['account'] ); + } } } } @@ -1141,7 +1146,7 @@ class GlmBillingSupport 'recurrence' => $new_member_invoice_type['recurrence'], ) ); - echo '
$invoice_id: ' . print_r( $invoice_id, true ) . '
'; + // echo '
$invoice_id: ' . print_r( $invoice_id, true ) . '
'; if ( $invoice_id ) { if ( isset( $employees ) && is_array( $employees ) ) { // Add line items for each employee. diff --git a/classes/data/dataInvoices.php b/classes/data/dataInvoices.php index 9a5345e..374661b 100644 --- a/classes/data/dataInvoices.php +++ b/classes/data/dataInvoices.php @@ -177,6 +177,14 @@ class GlmDataInvoices extends GlmDataAbstract 'use' => 'a', ), + // Renewal + 'renewal' => array( + 'field' => 'renewal', + 'type' => 'checkbox', + 'default' => true, + 'use' => 'a', + ), + // Recurring 'recurring' => array( 'field' => 'recurring', diff --git a/models/admin/billing/invoices.php b/models/admin/billing/invoices.php index 124d7e9..03627b5 100644 --- a/models/admin/billing/invoices.php +++ b/models/admin/billing/invoices.php @@ -374,40 +374,40 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices ); } // If one of the invoice line items is recurring then mark the invoice as renewal. - if ( $renewal_invoice ) { - $this->wpdb->update( - GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoices', - array( 'renewal' => 1 ), - array( 'id' => $this->invoice_id ), - array( '%s' ), - array( '%d' ) - ); - // Check the billing account and see if it needs to have invoice_type set. - $invoice_type_id = $this->wpdb->get_var( - $this->wpdb->prepare( - "SELECT invoice_type - FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts - WHERE id = %d", - $_REQUEST['account'] - ) - ); - if ( !$invoice_type_id ) { - // Then setup the invoice_type id - $this->wpdb->update( - GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts', - array( - 'invoice_type' => $line_item, - 'email_invoice' => true - ), - array( 'id' => $_REQUEST['account'] ), - array( - '%d', - '%d' - ), - array( '%d' ) - ); - } - } + // if ( $renewal_invoice ) { + // $this->wpdb->update( + // GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoices', + // array( 'renewal' => 1 ), + // array( 'id' => $this->invoice_id ), + // array( '%s' ), + // array( '%d' ) + // ); + // // Check the billing account and see if it needs to have invoice_type set. + // $invoice_type_id = $this->wpdb->get_var( + // $this->wpdb->prepare( + // "SELECT invoice_type + // FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts + // WHERE id = %d", + // $_REQUEST['account'] + // ) + // ); + // if ( !$invoice_type_id ) { + // // Then setup the invoice_type id + // $this->wpdb->update( + // GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts', + // array( + // 'invoice_type' => $line_item, + // 'email_invoice' => true + // ), + // array( 'id' => $_REQUEST['account'] ), + // array( + // '%d', + // '%d' + // ), + // array( '%d' ) + // ); + // } + // } } } $invoiceAdded = true; @@ -526,13 +526,13 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices } // If one of the invoice line items is recurring then mark the invoice as renewal. if ( $renewal_invoice ) { - $this->wpdb->update( - GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoices', - array( 'renewal' => 1 ), - array( 'id' => $this->invoice_id ), - array( '%s' ), - array( '%d' ) - ); + // $this->wpdb->update( + // GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoices', + // array( 'renewal' => 1 ), + // array( 'id' => $this->invoice_id ), + // array( '%s' ), + // array( '%d' ) + // ); } } } diff --git a/views/admin/billing/editInvoice.html b/views/admin/billing/editInvoice.html index 100b709..b60e9ad 100644 --- a/views/admin/billing/editInvoice.html +++ b/views/admin/billing/editInvoice.html @@ -97,6 +97,19 @@ + + {* Renewal *} + {$ui = [ + 'value' => $invoices.fieldData.renewal.value|default:true, + 'field' => 'renewal', + 'label' => 'Renewal', + 'required' => false, + 'errorText' => 'Renewal is Required', + 'dataError' => '', + 'tip' => 'On will set the accounts renewal date when this invoice is paid' + ]} + {include file='ui/f6/checkbox.html'} +
Add Line Item
Create New Line Item diff --git a/views/admin/billing/invoices.html b/views/admin/billing/invoices.html index 6ce51c2..34e1cc8 100644 --- a/views/admin/billing/invoices.html +++ b/views/admin/billing/invoices.html @@ -137,6 +137,7 @@ Due Date Amount Total Balance + Renewal @@ -154,9 +155,10 @@ {$t.due_date.date} {$t.amount_total} {$t.balance} + {if $t.renewal.value}Yes{else}No{/if} - +