From: Steve Sutton Date: Mon, 13 Aug 2018 19:57:05 +0000 (-0400) Subject: When creating an invoice check for renewal flag on invoice X-Git-Tag: v1.0.10^2~14 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=ab8071c5a933ba7cfc4e2a0cdce57b5d653ec253;p=WP-Plugins%2Fglm-member-db-billing.git When creating an invoice check for renewal flag on invoice If one of the line items is renewal type (recurring) then mark the invoice renewal. --- diff --git a/models/admin/billing/invoices.php b/models/admin/billing/invoices.php index 3680758..60a7d0e 100644 --- a/models/admin/billing/invoices.php +++ b/models/admin/billing/invoices.php @@ -175,6 +175,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices break; case 'insert': + $renewal_invoice = false; // Get Data Class for Invoice Types $InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config ); // Set transaction_time to current time. @@ -193,7 +194,9 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices foreach ( $line_items as $key => $line_item ) { // Get the invoice type $invoiceType = $InvoiceTypesObj->getEntry( $line_item ); - // + if ( $invoiceType['recurring']['value'] ) { + $renewal_invoice = true; + } // Add individual line item record $this->wpdb->insert( GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'line_items', @@ -225,6 +228,16 @@ 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' ) + ); + } } } $invoiceAdded = true;