From 0404837e0c5953c6ae5586fcd06db60a54881f2f Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 30 Mar 2018 09:25:22 -0400 Subject: [PATCH] For errors when processing renewal form. Give error messages when processing renewal form. --- classes/billingSupport.php | 19 ++++++++++ models/admin/member/billing.php | 37 ++++++++++++++++++- .../admin/settings/editNotificationType.html | 2 +- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 69d6f8d..7c2189d 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -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' ) + ); + } + } diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index 85c1231..697fc9a 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -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 '
$errors: ' . print_r( $errors, true ) . '
'; + if ( $errors ) { + // $messages[] = '
$errors: ' . print_r( $errors, true ) . '
'; + if ( count( $errors ) > 0 ) { + $BillingSupport->removeInvoiceById( $invoice_id ); + foreach ( $errors as $error ) { + $messages[] = ''.$error.''; + } + } + $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 ); + } } diff --git a/views/admin/settings/editNotificationType.html b/views/admin/settings/editNotificationType.html index afc6994..ca02852 100644 --- a/views/admin/settings/editNotificationType.html +++ b/views/admin/settings/editNotificationType.html @@ -30,7 +30,7 @@ - Due Date + Renewal Date -- 2.17.1