When creating an invoice check for renewal flag on invoice
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 13 Aug 2018 19:57:05 +0000 (15:57 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 13 Aug 2018 19:57:05 +0000 (15:57 -0400)
If one of the line items is renewal type (recurring) then mark the
invoice renewal.

models/admin/billing/invoices.php

index 3680758..60a7d0e 100644 (file)
@@ -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;