5f4155a1 by Kevin Burton

invoicing updates

1 parent 8a0f1789
......@@ -164,20 +164,26 @@ jQuery(function($) {
jQuery('.invoice-refund-btn').live('click', function(e) {
var iid = $(this).attr('rel');
var current_amount = $(this).attr('amount');
jConfirm('<strong>Are you sure</strong> you want to <em>refund</em> this invoice?', 'Refund Invoice', function(c) {
if (c) {
jPrompt('How much would you like to re-imburse?', current_amount, 'Re-imburse...', function(r) {
if( r ) {
jQuery.ajax({
url: '/wp-admin/admin-ajax.php'
, data: ({ajax:"yes", action: 'admin_refund_invoice', invoice_id:iid })
, dataType: 'json'
, data: ({ajax:"yes", action: 'admin_refund_invoice',invoice_id:iid, amount:r})
, type: 'POST'
, dataType: 'json'
, success: function(data) {
document.location.reload();
}
});
}
});
}
});
e.preventDefault();
return false;
});
......@@ -207,11 +213,7 @@ jQuery(function($) {
var cb = this;
var options = {
success: function(data) {
if (data.refresh == "true") {
document.location.href = document.location.href;
} else {
jQuery.colorbox.close();
}
document.location.reload();
}
, data: ({ajax:"yes", action: 'admin_update_invoice'})
, dataType: 'json'
......
......@@ -713,10 +713,6 @@ class Actions {
$paid_by = $_POST['paid_by'];
$title = $_POST['title'];
if ($invoice_type=="credit") {
$amount = "-".$amount;
}
$paid = (isset($_POST['paid']) && $_POST['paid']=="on") ? true : false;
if ($invoice_type=="invoice") {
if (!$paid) {
......@@ -776,7 +772,10 @@ class Actions {
}
}
Invoice\create($invoice_data, 'generic', $title, $uid, $status, 'publish', $amount);
$new_invoice_id = Invoice\create($invoice_data, 'generic', $title, $uid, $status, 'publish', $amount);
if ($invoice_type=="credit") {
update_post_meta($new_invoice_id, 'credit_amount', $amount);
}
// return json object
$return = array(
......@@ -1106,24 +1105,45 @@ class Actions {
die(json_encode($return));
}
public static function wp_ajax_admin_refund_invoice() {
public static function wp_ajax_admin_update_invoice() {
$invoice_id = $_POST['invoice_id'];
$user_id = $_POST['uid'];
$invoice = get_post($invoice_id);
update_post_meta($invoice_id, 'trans_status', 'paid');
$payment = get_post_meta($invoice_id, 'payment', true);
$payment['bt_card_type'] = $_POST['paid_by'];
update_post_meta($invoice_id, 'payment', $payment);
$invoice_for = get_post_meta($invoice_id, 'invoice_for', true);
if ( !empty($invoice_for) && $invoice_for == "membership") {
$next_year = (int) date("Y");
$next_year = ($next_year + 1);
update_user_meta($user_id, 'membership_valid_until', $next_year);
}
$return = array(
'success' => 'true'
);
die(json_encode($return));
}
public static function wp_ajax_admin_refund_invoice() {
$invoice_id = $_POST['invoice_id'];
$amount = $_POST['amount'];
$invoice = get_post($invoice_id);
$payment = get_post_meta($invoice_id, 'payment', true);
$trans_amount = get_post_meta($invoice_id, 'trans_amount', true);
$invoice_for = get_post_meta($invoice_id, 'invoice_for', true);
$items = get_post_meta($invoice_id, 'items', true);
update_post_meta($invoice->ID, 'refunded', date('Y-m-d H:i:s'));
$invoice_data['items'] = $items;
$invoice_data['payment'] = $payment;
$new_invoice_id = Invoice\create($invoice_data, $invoice_for, $invoice->post_title, $invoice->post_author, 'credit', 'publish', $trans_amount);
update_post_meta($new_invoice_id, 'original_invoice_id', $invoice_id);
update_post_meta($new_invoice_id, 'credit_amount', $amount);
}
......
......@@ -155,8 +155,8 @@ use WP_User, WP_Roles;
<td><label for="status_retired">Retired status</label></td>
</tr>
<tr>
<td width="20"><input type="checkbox" id="status_disability" name="special_status[]" value="status_disability" <?php search_special_status('status_disability');?> /></td>
<td><label for="status_disability">Disability status</label></td>
<td width="20"><input type="checkbox" id="status_disabled" name="special_status[]" value="status_disabled" <?php search_special_status('status_disabled');?> /></td>
<td><label for="status_disabled">Disability status</label></td>
</tr>
<tr>
<td width="20"><input type="checkbox" id="status_parental" name="special_status[]" value="status_parental" <?php search_special_status('status_parental');?> /></td>
......
......@@ -17,7 +17,7 @@ use WP_User;
<div style="padding:10px 10px 0px 10px; min-width:760px;position:relative;">
<h2 style="margin-bottom:10px;padding-bottom:0px;">Users' Payment History...
<?php if (!isset($_GET['view'])):?>
<a href="#" class="button add-new-h2" id="creditNotBtn">Creat new Invoice/Credit Note</a>
<a href="#" class="button add-new-h2" id="creditNotBtn">Create new Invoice/Credit Note</a>
<?php endif; ?>
</h2>
......@@ -53,11 +53,11 @@ use WP_User;
<td>Paid By</td>
<td>
<select name="paid_by">
<option value="">(none)</option>
<option value="visa">Visa</option>
<option value="mc">Mastercard</option>
<option value="amex">American Express</option>
<option value="cheque">Cheque</option>
<option value="">Select payment type...</option>
<option value="PPV">Pre-paid with Visa</option>
<option value="PPMC">Pre-paid with Mastercard</option>
<option value="PPAMEX">Pre-paid with American Express</option>
<option value="CHEQUE">Paid by Cheque</option>
</select>
</td>
</tr>
......@@ -115,13 +115,13 @@ use WP_User;
$html .= '<tr>';
$html .= '<th>Item / Description</th>';
if ($status!="credit") {
//if ($status!="credit") {
$html .= '<th width="80">Cost</th>';
$html .= '<th width="80">Discounts</th>';
$html .= '<th width="120">Amount</th>';
} else {
$html .= '<th width="120">Credit</th>';
}
//} else {
//$html .= '<th width="120">Credit</th>';
//}
$html .= '</tr>';
$html .= '</thead>';
......@@ -176,7 +176,7 @@ use WP_User;
$html .= '<tr class="'.$row_class.'">';
$html .= '<td>'.$description.'</td>';
if ($status!="credit") {
//if ($status!="credit") {
$html .= '<td>$'.$item['cost'].'</td>';
if (empty($item['discount_amount'])) {
$html .= '<td>$0.00</td>';
......@@ -184,7 +184,7 @@ use WP_User;
$html .= '<td>-$'.$item['discount_amount'].'</td>';
}
}
//}
$html .= '<td>$'.$item['subtotal'].'</td>';
......@@ -193,7 +193,7 @@ use WP_User;
}
$html .= '</tbody>';
$html .= '</table>';
if ($status != "credit") {
//if ($status != "credit") {
$html .= '<table cellpadding="0" cellspacing="0" border="0" class="clean" id="invoice-table">';
$html .= '<tfoot>';
......@@ -222,31 +222,47 @@ use WP_User;
}
$amount_label = ($status=="paid") ? "Total" : "Amount Due";
$amount = $invoice->payment['total'];
$credit = get_post_meta($invoice->ID, 'credit_amount', true);
if ( !empty($credit) && $status == "credit" ) {
$html .= '<tr>';
$html .= '<td style="text-align:right;padding-right:10px;font-weight:bold; color:green;">Credit</td>';
$html .= '<td style="color:green;">-$'.number_format($credit,2).'</td>';
$html .= '</tr>';
$amount = ($amount - $credit);
}
$amount_label = ($status=="unpaid") ? "Amount Due" : "Total";
$html .= '<tr>';
$html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">'.$amount_label.'</td>';
$html .= '<td><strong>$'.number_format($invoice->payment['total'],2).'</strong></td>';
$html .= '<td><strong>$'.number_format($amount,2).'</strong></td>';
$html .= '</tr>';
$html .= '</tfoot>';
$html .= '</table>';
}
//}
$html .= '</p>';
if ($status != "credit" && $invoice->payment['bt_address'] != "" && $invoice->payment['bt_card_holder'] != "") {
$html .= '<h3>BILLED TO:</h3>';
$html .= $invoice->payment['bt_card_holder']."<br />";
$html .= $invoice->payment['bt_address']." ".$invoice->payment['bt_address2'] . "<br />";
$html .= $invoice->payment['bt_city'].", " .$invoice->payment['bt_province']."<br />";
$html .= $invoice->payment['bt_country']."&nbsp;&nbsp;".$invoice->payment['bt_postal']."<br /><br />";
$html .= "<strong>".ucwords($invoice->payment['bt_card_type'])."</strong>&nbsp;&nbsp;" . $invoice->payment['bt_card_number'];
}
//if ($status != "credit" && $invoice->payment['bt_address'] != "" && $invoice->payment['bt_card_holder'] != "") {
$html .= (!empty($invoice->payment['bt_card_holder'])) ? '<h3>BILLED TO:</h3>' : "";
$html .= (!empty($invoice->payment['bt_card_holder'])) ? $invoice->payment['bt_card_holder']."<br />" : "";
$html .= (!empty($invoice->payment['bt_address'])) ? $invoice->payment['bt_address']." ".$invoice->payment['bt_address2'] . "<br />" : "";
$html .= (!empty($invoice->payment['bt_city'])) ? $invoice->payment['bt_city'].", " .$invoice->payment['bt_province']."<br />" : "";
$html .= (!empty($invoice->payment['bt_country'])) ? $invoice->payment['bt_country']."&nbsp;&nbsp;".$invoice->payment['bt_postal']."<br /><br />" : "";
$html .= (!empty($invoice->payment['bt_card_type'])) ? "Paid using: <strong>".CBV\get_payment_string($invoice->payment['bt_card_type'])."</strong>&nbsp;&nbsp;" . $invoice->payment['bt_card_number'] : "";
//}
if ($status != "credit") {
//if ($status != "credit") {
$html .= '<p>GST/HST# R108075334</p>';
}
//}
if ( $status == "paid" ) {
$html .= '<div style="text-align:center; font-size:14px; color:green;">-- <strong>PAID</strong> --</div>';
......@@ -254,6 +270,8 @@ use WP_User;
$html .= '<div style="text-align:center; font-size:14px; color:red;">-- THIS INVOICE IS <strong>UNPAID</strong> --</div>';
} elseif ( $status == "credit" ) {
$html .= '<div style="text-align:center; font-size:14px; color:green;">-- <strong>CREDIT NOTE</strong> --</div>';
} elseif ( $status == "cancelled" ) {
$html .= '<div style="text-align:center; font-size:14px; color:green;">-- THIS INVOICE IS <strong>CANCELLED</strong> --</div>';
}
......
......@@ -40,13 +40,12 @@
<div style="padding: 0px 0px 10px 0px;">
<form method="post" action="" id="edit-invoice-form">
<input type="hidden" name="uid" value="<?php echo $uid; ?>" />
<input type="hidden" name="invoice_id" value="<?php echo $post->ID; ?>" />
<input type="hidden" name="type" value="<?php echo $action; ?>" />
<input type="hidden" name="uid" value="<?php echo $_GET['uid']; ?>" />
<input type="hidden" name="invoice_id" value="<?php echo $_GET['invoice_id']; ?>" />
<div class="dashboard-section" style="margin-left:20px;margin-top:10px;">
<div class="dashboard-section-content small">
<select name="status">
<select name="paid_by">
<option value="">Select payment type...</option>
<option value="PPV">Pre-paid with Visa</option>
<option value="PPMC">Pre-paid with Mastercard</option>
......