For errors when processing renewal form.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 30 Mar 2018 13:25:22 +0000 (09:25 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 30 Mar 2018 13:25:22 +0000 (09:25 -0400)
Give error messages when processing renewal form.

classes/billingSupport.php
models/admin/member/billing.php
views/admin/settings/editNotificationType.html

index 69d6f8d..7c2189d 100644 (file)
@@ -1135,5 +1135,24 @@ class GlmBillingSupport
 
     }
 
+    public function removeInvoiceById( $invoice_id )
+    {
+        $this->wpdb->delete(
+            GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'line_items',
+            array( 'invoice' => $invoice_id ),
+            array( '%d' )
+        );
+        $this->wpdb->delete(
+            GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoices',
+            array( 'id' => $invoice_id ),
+            array( '%d' )
+        );
+        $this->wpdb->delete(
+            GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'transactions',
+            array( 'type' => $this->config['transaction_numb']['Invoice'], 'type_id' => $invoice_id ),
+            array( '%d', '%d' )
+        );
+    }
+
 }
 
index 85c1231..697fc9a 100644 (file)
@@ -240,7 +240,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                 'due_date'       => date( 'Y-m-d' ),
                 'member_invoice' => $member_invoice,
                 'employee_data'  => $employees,
-                'employees'      => $_REQUEST['employees']
+                'employees'      => isset( $_REQUEST['employees'] ) ? $_REQUEST['employees'] : array(),
             );
             if ( !$invoice_data ) {
                 $error = true;
@@ -256,7 +256,11 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
 
             // If there's any errors then re-show the form.
             if ( $error ) {
-                // TODO: Here we'll need to remove the invoice created if any.
+                // Remove the invoice created.
+                if ( $invoice_id ) {
+                    $BillingSupport->removeInvoiceById( $invoice_id );
+                }
+
                 $view = 'renew';
 
                 // Get list of payable invoice_types
@@ -281,6 +285,35 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                 // Do the Payment Processing.
                 $errors = $BillingSupport->processMemberRenewal( $accountID, $invoice_id, $invoice_data['amount'], $invoice_data['employees'] );
                 // echo '<pre>$errors: ' . print_r( $errors, true ) . '</pre>';
+                if ( $errors ) {
+                    // $messages[] = '<pre>$errors: ' . print_r( $errors, true ) . '</pre>';
+                    if ( count( $errors ) > 0 ) {
+                        $BillingSupport->removeInvoiceById( $invoice_id );
+                        foreach ( $errors as $error ) {
+                            $messages[] = '<span style="color: red;">'.$error.'</span>';
+                        }
+                    }
+                    $view = 'renew';
+
+                    // Get list of payable invoice_types
+                    $payable_types = $BillingSupport->getAllPayableInvoiceTypes();
+
+                    $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
+                    if ( $member_invoice_id ) {
+                        $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id );
+                    }
+
+                    // Get a list of this accounts employees. If they have any.
+                    $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
+
+                    // Load DataClass for Management.
+                    require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH .  '/data/dataManagement.php';
+                    $Management = new GlmDataBillingManagement( $this->wpdb, $this->config );
+                    $management = $Management->getEntry( 1 );
+
+                    // Need to see if there's an account for this member.
+                    $account = $Accounts->editEntry( $accountID );
+                }
             }
 
 
index afc6994..ca02852 100644 (file)
@@ -30,7 +30,7 @@
         </tr>
 
         <tr>
-            <th colspan="2">Due Date</th>
+            <th colspan="2">Renewal Date</th>
         </tr>
 
         <tr>