* Also need to record the payment to the invoice_payments
* table so we know which payment was applied to the invoice.
*
- * @param mixed $invoice_id Id of the Invoice record
- * @param mixed $payment Total amount of the Payment
+ * @param int $payment_id Payment id
+ * @param int $account Total amount of the Payment
+ * @param float $payment Payment amount
+ * @param int $invoice_id Id of the Invoice record
*
* @access public
* @return void
*/
- public function recordPayment( $payment_id, $account, $payment )
+ public function recordPayment( $payment_id, $account, $payment, $invoice_id = null )
{
// record into the transaction table
$this->recordTransaction( $this->config['transaction_numb']['Payment'], $payment_id, $account, null, $payment );
- // Get the unpaid invoices
- $invoices = $this->getUnPaidInvoicesByAccount( $account );
- // echo '<pre>$invoices: ' . print_r( $invoices, true ) . '</pre>';
- if ( $invoices && is_array( $invoices ) && count( $invoices ) > 0 ) {
- foreach ( $invoices as $invoice ) {
- $balance = (float)$invoice['balance'];
- if ( $payment == $invoice['balance'] ) {
- // Mark this as paid then
- $this->updateInvoiceBalance( $invoice['id'], (float)0.00 );
- // Record the payment to the invoice_payments table
- $this->recordInvoicePayment( $invoice['id'], $payment_id, $invoice['balance'] );
- // $payment is used up so break from the foreach loop
- break;
- } 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;
- $this->updateInvoiceBalance( $invoice['id'], (float)$balance );
- // Record the payment to the invoice_payments table
- $this->recordInvoicePayment( $invoice['id'], $payment_id, (float)$payment );
- // $payment is used up so break from the foreach loop
- break;
+ // If there's an invoice_id
+ // If the payment amount is over then go through the other invoices.
+ if ( $invoice_id ) {
+ // Get the invoice
+ $invoice = $this->getInvoiceById( $invoice_id );
+ $balance = (float)$invoice['balance'];
+ if ( $payment == $invoice['balance'] ) {
+ // Mark this as paid then
+ $this->updateInvoiceBalance( $invoice['id'], (float)0.00 );
+ // Record the payment to the invoice_payments table
+ $this->recordInvoicePayment( $invoice['id'], $payment_id, $invoice['balance'] );
+ } else if ( $payment > $invoice['balance'] ) {
+ $this->updateInvoiceBalance( $invoice['id'], (float)0.00 );
+ $payment -= $invoice['balance'];
+ } else if ( $invoice['balance'] > $payment ) {
+ // Update the balance of the invoice
+ $balance = (float)$balance - (float)$payment;
+ $this->updateInvoiceBalance( $invoice['id'], (float)$balance );
+ // Record the payment to the invoice_payments table
+ $this->recordInvoicePayment( $invoice['id'], $payment_id, (float)$payment );
+ }
+
+ }
+
+ if ( $payment ) {
+
+ // Get the unpaid invoices
+ $invoices = $this->getUnPaidInvoicesByAccount( $account );
+ if ( $invoices && is_array( $invoices ) && count( $invoices ) > 0 ) {
+ foreach ( $invoices as $invoice ) {
+ $balance = (float)$invoice['balance'];
+ if ( $payment == $invoice['balance'] ) {
+ // Mark this as paid then
+ $this->updateInvoiceBalance( $invoice['id'], (float)0.00 );
+ // Record the payment to the invoice_payments table
+ $this->recordInvoicePayment( $invoice['id'], $payment_id, $invoice['balance'] );
+ // $payment is used up so break from the foreach loop
+ break;
+ } 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;
+ $this->updateInvoiceBalance( $invoice['id'], (float)$balance );
+ // Record the payment to the invoice_payments table
+ $this->recordInvoicePayment( $invoice['id'], $payment_id, (float)$payment );
+ // $payment is used up so break from the foreach loop
+ break;
+ }
}
}
+
}
+
}
public function createPayment( $account, $payment )
$Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
$billingAccount = $Accounts->newEntry();
$accounts = $Accounts->getList( '', 'ref_name' );
- // echo '<pre>$accounts: ' . print_r( $accounts, true ) . '</pre>';
// Need a list of members that don't have an account.
$nonAccountMembers = $this->wpdb->get_results(
ORDER BY name",
ARRAY_A
);
- // echo '<pre>$nonAccountMembers: ' . print_r( $nonAccountMembers, true ) . '</pre>';
if ( isset( $invoiceTypes ) ) {
foreach ( $invoiceTypes as $invoiceType ) {
}
}
}
+ $invoiceAdded = true;
// Here we're going to generate the invoice total.
$totals = $this->generateInvoiceTotal( $this->invoice_id );
// Now we have a total for the invoice we can record the transaction
// Set the view file to editInvoice
$view = 'editInvoice';
- $InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config );
- $invoiceTypes = $InvoiceTypesObj->getList();
- $invoiceTypes = $InvoiceTypesObj->sortParentChild($invoiceTypes);
+
+ // Reset this form to add a new one again
+ unset( $invoices );
+ $this->invoice_id = false;
+ $invoices = $this->newEntry();
+ $InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config );
+ $invoiceTypes = $InvoiceTypesObj->getList();
+ $invoiceTypes = $InvoiceTypesObj->sortParentChild($invoiceTypes);
+ // Need to get the accounts
+ $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
+ $billingAccount = $Accounts->newEntry();
+ $accounts = $Accounts->getList( '', 'ref_name' );
+
+ // Need a list of members that don't have an account.
+ $nonAccountMembers = $this->wpdb->get_results(
+ "SELECT id,name
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ WHERE id NOT IN (
+ SELECT distinct ref_dest
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts )
+ ORDER BY name",
+ ARRAY_A
+ );
if ( isset( $invoiceTypes ) ) {
foreach ( $invoiceTypes as $invoiceType ) {
$invTypes[$invoiceType['id']] = array(
$management = false;
$messages = array();
$invoices = false;
+ $paymentSuccess = false;
+ $paymentError = false;
// For lockedToMember.
$lockedToMember = false;
}
if (count($messages) == 0) {
+ $paymentSuccess = true;
// Determine the directory of the payment processor to load and instatiate it.
if ($ccProcessor && isset($this->config['proc_dir'][$ccProcessor])) {
// Create new payment.
$payment_id = $BillingSupport->createPayment( $paymentData['account_id'], $paymentData['amount'] );
// Record the payment.
- $BillingSupport->recordPayment( $payment_id, $paymentData['account_id'], $paymentData['amount'] );
+ $BillingSupport->recordPayment( $payment_id, $paymentData['account_id'], $paymentData['amount'], $paymentData['invoice_id'] );
$messages[] = $ccResult['statusText'];
$messages[] = $ccResult['description'];
}
} else {
+ $paymentError = true;
// Load DataClass for accounts.
require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php';
$Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
'management' => $management,
'messages' => $messages,
'invoices' => $invoices,
+ 'paymentSuccess' => $paymentSuccess,
+ 'paymentError' => $paymentError,
);
// Return status, any suggested view, and any data to controller.
{include file='admin/billing/subHeader.html'}
-{if $invoiceUpdated}<span class="glm-notice glm-flash-updated">Notification Updated</span>{/if}
-{if $invoiceUpdateError}<span class="glm-notice glm-flash-updated">Notification Update Error</span>{/if}
-{if $invoiceInsertError}<span class="glm-notice glm-flash-updated">Notification Insert Error</span>{/if}
-{if $invoiceAdded}<span class="glm-notice glm-flash-updated">Notification Added</span>{/if}
+{if $invoiceUpdated}<span class="glm-notice glm-flash-updated">Invoice Updated</span>{/if}
+{if $invoiceUpdateError}<span class="glm-notice glm-flash-updated">Invoice Update Error</span>{/if}
+{if $invoiceInsertError}<span class="glm-notice glm-flash-updated">Invoice Insert Error</span>{/if}
+{if $invoiceAdded}<span class="glm-notice glm-flash-updated">Invoice Added</span>{/if}
<div id="billing-invoice-form" style="max-width: 750px;">
<form id="create-invoice-form" action="{$thisUrl}?page={$thisPage}&glm_action=invoices" method="post">
// Close the dialog
newAccountDialog.dialog( 'close' );
} else {
- console.log( 'return', msg );
+ //console.log( 'return', msg );
}
});
}
{include file='admin/member/header.html'}
{include file='admin/billing/memberBillingSubHeader.html'}
-{if $messages}
- {foreach $messages as $message}
- <div class="">{$message}</div>
- {/foreach}
-{/if}
+<div id="billing-payment-form" style="max-width:750px;">
+
+ {if $paymentSuccess}<span class="glm-notice glm-flash-updated">Payment Completed</span>{/if}
+ {if $paymentError}<span class="glm-notice glm-flash-updated">Error With Payment</span>{/if}
+
+ {if $messages}
+ {foreach $messages as $message}
+ <div class="">{$message}</div>
+ {/foreach}
+ {/if}
-<div id="billing-payment-form" style="max-width:750px;">
<form action="{$thisUrl}?page={$thisPage}&glm_action=billing&option=makePayment" method="post">
<input type="hidden" name="page" value="{$thisPage}">
<input type="hidden" name="glm_action" value="billing">
<div class="glm-row">
<div class="glm-columns glm-small-12 glm-medium-3 glm-required"> Select Invoice </div>
<div class="glm-columns glm-small-12 glm-large-8">
- <select name="invoice_id" required>
+ <select id="billing-invoice-select" name="invoice_id" required>
<option value=""></option>
{if $invoices}
{foreach $invoices as $invoice}
<option
value="{$invoice.id}"
- {if isset($smarty.request.invoice_id) && $smarty.request.invoice_id == $invoice.id} selected{/if}>${$invoice.amount_total} Due {$invoice.due_date}</option>
+ data-amount="{$invoice.balance}"
+ {if isset($smarty.request.invoice_id) && $smarty.request.invoice_id == $invoice.id} selected{/if}>
+ ${$invoice.balance} Due {$invoice.due_date}
+ </option>
{/foreach}
{/if}
</select>
<input
class="glm-form-text-input-small"
type="number"
+ id="billing-amount"
name="amount"
step="0.01"
min="0.01"
</form>
</div>
+<script>
+jQuery(document).ready(function($){
+
+ $('#billing-invoice-select').change(function(){
+ // Get the data-amount and set the amount being paid.
+ $('#billing-amount').val( $(this).find('option:selected').data( 'amount') );
+ });
+
+ // Flash certain elements for a short time after display
+ $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
+
+});
+</script>
+
+
{include file='admin/footer.html'}
{include file='admin/member/header.html'}
{include file='admin/billing/memberBillingSubHeader.html'}
+{if $paymentSuccess}<span class="glm-notice glm-flash-updated">Payment Completed</span>{/if}
+
{if $messages}
{foreach $messages as $message}
- {$message} <br>
+ <div class="">{$message}</div>
{/foreach}
{/if}
+<script>
+jQuery(document).ready(function($){
+
+ // Flash certain elements for a short time after display
+ $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
+
+});
+</script>
{include file='admin/footer.html'}
var invoiceRecurring = $(this).data('invoice-recurring');
var invoiceRecurrence = $(this).data('invoice-recurrence');
- console.log( 'invoiceRecurring: ', invoiceRecurring );
+ //console.log( 'invoiceRecurring: ', invoiceRecurring );
// Set the values of the edit form for the selected invoiceType
$('#edit-id').val( invoiceID );