From: Steve Sutton Date: Wed, 14 Mar 2018 14:53:09 +0000 (-0400) Subject: Fix bug in payments X-Git-Tag: v1.0.0^2~149 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=c64c724baef4e7c92814ef5cbf5f400001940554;p=WP-Plugins%2Fglm-member-db-billing.git Fix bug in payments When applying payment to invoice with an id make sure you substract the balance from payment in each case. Then left over payments are applied to any remaining invoices. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 0114f65..bd84301 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -109,6 +109,7 @@ class GlmBillingSupport $invoice = $this->getInvoiceById( $invoice_id ); $balance = (float)$invoice['balance']; if ( $payment == $invoice['balance'] ) { + $payment -= $invoice['balance']; // Mark this as paid then $this->updateInvoiceBalance( $invoice['id'], (float)0.00 ); // Record the payment to the invoice_payments table @@ -116,6 +117,8 @@ class GlmBillingSupport } else if ( $payment > $invoice['balance'] ) { $this->updateInvoiceBalance( $invoice['id'], (float)0.00 ); $payment -= $invoice['balance']; + // Record the payment to the invoice_payments table + $this->recordInvoicePayment( $invoice['id'], $payment_id, $invoice['balance'] ); } else if ( $invoice['balance'] > $payment ) { // Update the balance of the invoice $balance = (float)$balance - (float)$payment; @@ -658,7 +661,7 @@ class GlmBillingSupport ); foreach ( $line_items as &$item ) { $index = (int)$item['recurrence']; - if ( $item.recurring && $this->config['recurrence'][$index] ) { + if ( $item['recurring'] && $this->config['recurrence'][$index] ) { $item['recurrence_string'] = $this->config['recurrence'][$index]; } } diff --git a/classes/notifications.php b/classes/notifications.php index 8badb00..58fbf62 100644 --- a/classes/notifications.php +++ b/classes/notifications.php @@ -121,6 +121,7 @@ class GlmNotifications ); // Merge any data passed into this method $account_data['data'] = $data; + $notification_message = $this->parseSmartyTemplateString( $account_data, wpautop( $notification_type['message'] ) @@ -129,6 +130,14 @@ class GlmNotifications $smarty->templateAssign( 'title', $notification_type['subject'] ); $smarty->templateAssign( 'html_content', $notification_message ); + // Setup the invoice html + $invoice_html = ''; + if ( isset( $data['type'] ) && $data['type'] == $this->config['transaction_numb']['Invoice'] ) { + $invoice_html = $BillingSupport->viewInvoice( $data['type_id'] ); + } + + $smarty->templateAssign( 'invoice_html', $invoice_html ); + // Generate output from model data and view $htmlMessage = $smarty->template->fetch( $viewFile ); diff --git a/models/admin/billing/index.php b/models/admin/billing/index.php index 2a54d8f..7c1ef23 100644 --- a/models/admin/billing/index.php +++ b/models/admin/billing/index.php @@ -229,7 +229,9 @@ class GlmMembersAdmin_billing_index extends GlmDataInvoices $overDueWhere = 'T.paid <> true AND T.due_date < now()'; $start = 1; $overdue = $this->getList( $overDueWhere, 'transaction_time', true, 'id', $start, $limit ); - $numberOverdue = $overdue['returned']; + if ( isset( $overdue['returned'] ) ) { + $numberOverdue = $overdue['returned']; + } break; } diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index 900e8de..3839cee 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -216,11 +216,10 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling $haveAccount = false; } } else { + $account = $Accounts->editEntry( $accountID ); $haveAccount = true; - // echo '
$account: ' . print_r( $account, true ) . '
'; } - // echo '
$account: ' . print_r( $account, true ) . '
'; $view = 'editAccount'; break; case 'view': @@ -301,12 +300,15 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling 'filter' => FILTER_SANITIZE_NUMBER_FLOAT, 'flags' => FILTER_FLAG_ALLOW_FRACTION, ), + 'billing_fname' => FILTER_SANITIZE_STRING, + 'billing_lname' => FILTER_SANITIZE_STRING, 'billing_addr1' => FILTER_SANITIZE_STRING, 'billing_addr2' => FILTER_SANITIZE_STRING, 'billing_city' => FILTER_SANITIZE_STRING, 'billing_state' => FILTER_SANITIZE_STRING, 'billing_zip' => FILTER_SANITIZE_STRING, 'billing_phone' => FILTER_SANITIZE_STRING, + 'email' => FILTER_SANITIZE_STRING, ) ); @@ -319,7 +321,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling 'city' => $paymentData['billing_city'], 'state' => $paymentData['billing_state'], 'zip' => $paymentData['billing_zip'], - 'phone' => $paymentData['bill_phone'], + 'phone' => $paymentData['billing_phone'], 'email' => $paymentData['email'] ); $cardMatch = $this->config['credit_card_match']; diff --git a/views/admin/notifications/notification.html b/views/admin/notifications/notification.html index a94383d..66b157a 100644 --- a/views/admin/notifications/notification.html +++ b/views/admin/notifications/notification.html @@ -6,5 +6,6 @@

{$title}

{$html_content} + {$invoice_html}