Updates for adjustments.
Update for paying not full amount.
* @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.
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
// 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 '<pre>$transactions: ' . print_r( $transactions, true ) . '</pre>';
$invoices = $this->editEntry($this->invoice_id);
- // echo '<pre>' . print_r( $invoices, true) . '</pre>';
-
// Remove the old line items.
$this->wpdb->delete(
GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'line_items',
// 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;
}
$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 '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
- 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;
<td align="left" width="150"> </td>
<td align="left" width="20">{$payment.transaction_time|date_format:"%m/%d/%y"}</td>
<td align="right" width="10"> </td>
- <td align="left">Payment </td>
- <td align="right" width="60">- ${$payment.amount|string_format:"%.2f"}</td>
+ <td align="left"> {$payment.payment_method} </td>
+ <td align="right" width="60">{if $payment.amount >= 0}-{/if} ${abs($payment.amount)|string_format:"%.2f"}</td>
</tr>
{/foreach}
<tr><td colspan="5"><hr></td></tr>
<div class="glm-billing-field">
<div class="glm-billing-label glm-required"> Amount </div>
<div class="glm-billing-input">
- <input name="amount" required />
+ <input type="number" name="amount" required />
</div>
</div>
<script>
jQuery(document).ready(function($){
+ // Need to require that they select at least one invoice
+ $('#PaymentForm').submit(function(){
+ var invoice_amount = $('#total_amount').val();
+ if ( invoice_amount == 0 ) {
+ alert( 'You have to select at least one invoice with an amount due.' );
+ return false;
+ } else {
+ return true;
+ }
+ return false;
+ });
+
+ function getPageTotal(){
+
+ // Calculate the total for this page.
+ // Get the member_renewing amount.
+ if ( $('input[name^=invoices]:checked').length === 1 ) {
+ var invoice_amount = parseFloat( $('input[name^=invoices]:checked').data('amount') );
+ } else if ( $('input[name^=invoices]:checked').length > 1 ) {
+ var invoice_amount = 0.00;
+ $('input[name^=invoices]:checked').each(function(){
+ invoice_amount += parseFloat( $(this).data('amount') );
+ });
+ } else {
+ var invoice_amount = 0.00;
+ }
+
+ $('#total_amount_display').html( '$' + invoice_amount );
+ $('#total_amount').val( invoice_amount );
+
+ }
+
+ getPageTotal();
+
+ // trigger total if changing Membership
+ $('input[name^=invoices]').change(function(){
+ getPageTotal();
+ });
+
// 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);
margin-right: 0;
}
- /* Force table to not be like tables anymore */
+ /* Force table to not be like tables anymore */
#wpbody-content #glm-admin-billing-wrapper table,
#wpbody-content #glm-admin-billing-wrapper thead,
#wpbody-content #glm-admin-billing-wrapper tbody,
#wpbody-content #glm-admin-billing-wrapper th,
#wpbody-content #glm-admin-billing-wrapper td,
#wpbody-content #glm-admin-billing-wrapper tr {
- display: block;
- }
+ display: block;
+ }
- /* Hide table headers (but not display: none;, for accessibility) */
- #wpbody-content #glm-admin-billing-wrapper thead tr {
- position: absolute;
- top: -9999px;
- left: -9999px;
- }
+ /* Hide table headers (but not display: none;, for accessibility) */
+ #wpbody-content #glm-admin-billing-wrapper thead tr {
+ position: absolute;
+ top: -9999px;
+ left: -9999px;
+ }
- #wpbody-content #glm-admin-billing-wrapper tr { border: 1px solid #ccc; }
+ #wpbody-content #glm-admin-billing-wrapper tr { border: 1px solid #ccc; }
- #wpbody-content #glm-admin-billing-wrapper td {
- /* Behave like a "row" */
- border: none;
- border-bottom: 1px solid #eee;
- position: relative;
- padding-left: 25%;
- }
+ #wpbody-content #glm-admin-billing-wrapper td {
+ /* Behave like a "row" */
+ border: none;
+ border-bottom: 1px solid #eee;
+ position: relative;
+ padding-left: 25%;
+ }
- #wpbody-content #glm-admin-billing-wrapper td:before {
- /* Now like a table header */
- position: absolute;
- /* Top/left values mimic padding */
- top: 6px;
- left: 6px;
- width: 25%;
- padding-right: 10px;
- white-space: nowrap;
- }
- /* Label the data */
- #wpbody-content #glm-admin-billing-wrapper td:nth-of-type(1):before { content: "ID"; }
- #wpbody-content #glm-admin-billing-wrapper td:nth-of-type(2):before { content: "Date"; }
- #wpbody-content #glm-admin-billing-wrapper td:nth-of-type(3):before { content: "Due"; }
- #wpbody-content #glm-admin-billing-wrapper td:nth-of-type(4):before { content: "Type"; }
- #wpbody-content #glm-admin-billing-wrapper td:nth-of-type(5):before { content: "Items"; }
+ #wpbody-content #glm-admin-billing-wrapper td:before {
+ /* Now like a table header */
+ position: absolute;
+ /* Top/left values mimic padding */
+ top: 6px;
+ left: 6px;
+ width: 25%;
+ padding-right: 10px;
+ white-space: nowrap;
+ }
+ /* Label the data */
+ #wpbody-content #glm-admin-billing-wrapper td:nth-of-type(1):before { content: "ID"; }
+ #wpbody-content #glm-admin-billing-wrapper td:nth-of-type(2):before { content: "Date"; }
+ #wpbody-content #glm-admin-billing-wrapper td:nth-of-type(3):before { content: "Due"; }
+ #wpbody-content #glm-admin-billing-wrapper td:nth-of-type(4):before { content: "Type"; }
+ #wpbody-content #glm-admin-billing-wrapper td:nth-of-type(5):before { content: "Items"; }
#wpbody-content #glm-admin-billing-wrapper td:nth-of-type(6):before { content: "Amount"; }
#wpbody-content #glm-admin-billing-wrapper td:nth-of-type(7):before { content: "Balance"; }
#wpbody-content #glm-admin-billing-wrapper td:nth-of-type(8):before { content: "Pay"; }
<td class="glm-shrink"> </td>
<td class="glm-shrink"> </td>
</tr>
+ {* Adjustment *}
+ {elseif $transaction.type == '30'}
+ <tr{if $alt % 2 == 0} class="alternate"{/if}>
+ <td class="glm-shrink">{$transaction.transaction_data.id}</td>
+ <td class="glm-shrink">{$transaction.transaction_data.transaction_time|date_format:"%D"}</td>
+ <td class="glm-shrink"> </td>
+ <td class="glm-shrink">{$transaction_types[$transaction.type]}</td>
+ <td class="glm-shrink"> </td>
+ <td class="glm-shrink">${$transaction.transaction_data.amount}</td>
+ <td class="glm-shrink"> </td>
+ <td class="glm-shrink"> </td>
+ <td class="glm-shrink"> </td>
+ </tr>
{/if}
+
{$alt = $alt + 1}
{/foreach}