From: Steve Sutton Date: Fri, 21 Dec 2018 20:42:20 +0000 (-0500) Subject: Updating payment form X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=5c417bfdf7ab0658a5e35e4e80d8ed8f0abfe63a;p=WP-Plugins%2Fglm-member-db-billing.git Updating payment form Updates for adjustments. Update for paying not full amount. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index a1535b2..c618275 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -98,10 +98,15 @@ class GlmBillingSupport * @access public * @return void */ - public function recordPayment( $payment_id, $account, $payment, $invoices = null ) + public function recordPayment( $payment_id, $account, $payment, $invoices = null, $method = null ) { // record into the transaction table - $this->recordTransaction( $this->config['transaction_numb']['Payment'], $payment_id, $account, null, $payment ); + if ( $method ) { + $paymentMethod = $method; + } else { + $paymentMethod = $this->config['transaction_numb']['Payment']; + } + $this->recordTransaction( $paymentMethod, $payment_id, $account, null, $payment ); // If there's an invoice_id // If the payment amount is over then go through the other invoices. @@ -139,9 +144,15 @@ class GlmBillingSupport if ( $payment ) { // Get the unpaid invoices - $invoices = $this->getUnPaidInvoicesByAccount( $account ); - if ( $invoices && is_array( $invoices ) && count( $invoices ) > 0 ) { - foreach ( $invoices as $invoice ) { + $oldInvoices = $this->getUnPaidInvoicesByAccount( $account ); + foreach ( $oldInvoices as $key => $inv ) { + if ( in_array( $inv['id'], $invoices ) ) { + unset( $oldInvoices[$key] ); + } + } + // Need to exclude any invoices already done ($invoices) + if ( $oldInvoices && is_array( $oldInvoices ) && count( $oldInvoices ) > 0 ) { + foreach ( $oldInvoices as $invoice ) { $balance = (float)$invoice['balance']; if ( $payment == $invoice['balance'] ) { // Mark this as paid then @@ -440,6 +451,12 @@ class GlmBillingSupport // add to the $transaction array $transaction['transaction_data'] = $payment; break; + case $this->config['transaction_numb']['Adjustment']: + $payment = $this->getPaymentById( $transaction['type_id'] ); + $balance_due = $balance_due - $payment['amount']; + // add to the $transaction array + $transaction['transaction_data'] = $payment; + break; } } // echo '
$transactions: ' . print_r( $transactions, true ) . '
'; diff --git a/models/admin/billing/invoices.php b/models/admin/billing/invoices.php index 82b295b..f2a2ff4 100644 --- a/models/admin/billing/invoices.php +++ b/models/admin/billing/invoices.php @@ -370,8 +370,6 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices $invoices = $this->editEntry($this->invoice_id); - // echo '
' . print_r( $invoices, true) . '
'; - // Remove the old line items. $this->wpdb->delete( GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'line_items', @@ -439,7 +437,23 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices // Now we have a total for the invoice we can record the transaction $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); // Calling the support class to save the invoice to transaction table. - // $BillingSupport->recordInvoice( $this->invoice_id, $_REQUEST['account'], $totals['amount_total'] ); + // Reset for the edit form + $InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config ); + $invoiceTypes = $InvoiceTypesObj->getList(); + $lineItems = $BillingSupport->getLineItemsForInvoice( $this->invoice_id ); + // Sort the types by parent child + $invoiceTypes = $InvoiceTypesObj->sortParentChild($invoiceTypes); + if ( isset( $invoiceTypes ) ) { + foreach ( $invoiceTypes as $invoiceType ) { + $invTypes[$invoiceType['id']] = array( + 'id' => $invoiceType['id'], + 'name' => $invoiceType['name'], + 'amount' => $invoiceType['amount'], + ); + } + $invoiceTypeJSON = json_encode( $invTypes, JSON_NUMERIC_CHECK ); + } + } else { $invoiceUpdateError = true; } diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index c5d1f4e..2a6a21d 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -728,14 +728,13 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling $payment_method = filter_var( $_REQUEST['payment_method'], FILTER_VALIDATE_INT ); $payment_data = filter_var( $_REQUEST['payment_data'], FILTER_SANITIZE_STRING ); $invoices = filter_var( $_REQUEST['invoices'], FILTER_VALIDATE_INT, array( 'flags' => FILTER_REQUIRE_ARRAY ) ); - // echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; - if ( $account_id && $amount && $payment_method && $payment_data && !empty( $invoices ) ) { + if ( $account_id && $amount && $payment_method && !empty( $invoices ) ) { // Create new payment. $payment_id = $BillingSupport->createPayment( $account_id, $amount, $this->config['alt_payment_method'][$payment_method], $payment_data ); // Record the payment. - $BillingSupport->recordPayment( $payment_id, $account_id, $amount, $invoices ); + $BillingSupport->recordPayment( $payment_id, $account_id, $amount, $invoices, $this->config['transaction_numb']['Adjustment'] ); } break; diff --git a/views/admin/billing/invoiceStore.html b/views/admin/billing/invoiceStore.html index ee08d4c..ede3ff3 100644 --- a/views/admin/billing/invoiceStore.html +++ b/views/admin/billing/invoiceStore.html @@ -97,8 +97,8 @@ body {   {$payment.transaction_time|date_format:"%m/%d/%y"}   - Payment - - ${$payment.amount|string_format:"%.2f"} + {$payment.payment_method} + {if $payment.amount >= 0}-{/if} ${abs($payment.amount)|string_format:"%.2f"} {/foreach}
diff --git a/views/admin/billing/makePaymentAdjustment.html b/views/admin/billing/makePaymentAdjustment.html index a0764f6..ea02de2 100644 --- a/views/admin/billing/makePaymentAdjustment.html +++ b/views/admin/billing/makePaymentAdjustment.html @@ -42,7 +42,7 @@
Amount
- +
@@ -85,6 +85,45 @@