Updating payment type on new accounts
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 14 Mar 2019 19:12:25 +0000 (15:12 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 14 Mar 2019 19:12:25 +0000 (15:12 -0400)
When creating on the new invoice page.

models/admin/billing/invoices.php

index cda9c6f..f281205 100644 (file)
@@ -249,7 +249,6 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
             // Set transaction_time to current time.
             $_REQUEST['transaction_time'] = date('Y-m-d H:i:s');
             $_REQUEST['due_date'] = date('Y-m-d', strtotime($_REQUEST['due_date']));
-            // echo '<pre>' . print_r( $_REQUEST, true ) . '</pre>';
             $invoices = $this->insertEntry();
 
             // TODO: Need to check to see if we received a good response
@@ -305,6 +304,31 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
                             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' )
+                            );
+                        }
                     }
                 }
             }