Fix bug in payments
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 14 Mar 2018 14:53:09 +0000 (10:53 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 14 Mar 2018 14:53:09 +0000 (10:53 -0400)
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.

classes/billingSupport.php
classes/notifications.php
models/admin/billing/index.php
models/admin/member/billing.php
views/admin/notifications/notification.html

index 0114f65..bd84301 100644 (file)
@@ -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];
             }
         }
index 8badb00..58fbf62 100644 (file)
@@ -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 );
 
index 2a54d8f..7c1ef23 100644 (file)
@@ -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;
         }
index 900e8de..3839cee 100644 (file)
@@ -216,11 +216,10 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                     $haveAccount = false;
                 }
             } else {
+                $account     = $Accounts->editEntry( $accountID );
                 $haveAccount = true;
-                // echo '<pre>$account: ' . print_r( $account, true ) . '</pre>';
             }
 
-            // echo '<pre>$account: ' . print_r( $account, true ) . '</pre>';
             $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'];
index a94383d..66b157a 100644 (file)
@@ -6,5 +6,6 @@
     <body>
         <h1 id="title"> {$title} </h1>
         {$html_content}
+        {$invoice_html}
     </body>
 </html>