33725e22 by Kevin Burton

user manager pay history

1 parent 33bf7108
......@@ -21,6 +21,23 @@ jQuery(function($) {
);
}
jQuery('#creditNotBtn').click(function(e) {
jQuery('#credit_note').slideToggle('fast');
jQuery('#creditForm').ajaxForm({
url: '/wp-admin/admin-ajax.php'
, data: ({ajax:"yes", action: 'add_credit_note'})
, dateType: 'json'
, type: 'POST'
, success: function(data) {
// reload, cannot use reload() because then the form values get re-applied.
document.location.href = document.location.href;
}
});
e.preventDefault();
return false;
});
jQuery('.remove-user').colorbox({onComplete: function() {
var cb = this;
......
......@@ -18,12 +18,14 @@ use Tz\WordPress\CBV;
use Tz\WordPress\CBV\User;
use Tz\WordPress\CBV\Events;
use Tz\WordPress\CBV\CEHours;
use Tz\WordPress\CBV\Invoice;
use Exception, StdClass;
use WP_User;
const OPTION_NAME = "user_options";
const CAPABILITY = "manage_cbv_users";
CBV\load('Invoice');
CBV\load('User');
Tools\import('HTML');
......@@ -661,6 +663,62 @@ class Actions {
die(json_encode($return));
}
public static function wp_ajax_add_credit_note() {
$uid = $_POST['uid'];
$title = $_POST['title'];
$amount = "-".$_POST['amount'];
global $wpdb;
$items = array();
$items[] = array(
'post_id' => 0
, 'cost' => $amount
, 'discount_label' => ""
, 'discount_amount' => ""
, 'tax_label' => ""
, 'tax_rate' => ""
, 'tax_amount' => ""
, 'subtotal' => $amount
, 'total' => $amount
, 'description' => "Credit Note"
, 'extras' => array()
);
$invoice_data = array();
$invoice_data['items'] = $items;
$invoice_data['payment'] = array(
'total_cost' => $amount
, 'total_discounts' => ""
, 'total_taxes' => ""
, 'subtotal' => $amount
, 'total' => $amount
, 'bt_address' => ""
, 'bt_address2' => ""
, 'bt_city' => ""
, 'bt_province' => ""
, 'bt_country' => ""
, 'bt_postal' => ""
, 'bt_card_holder' => ""
, 'bt_card_number' => ""
, 'bt_card_type' => ""
);
Invoice\create($invoice_data, 'credit', $title, $uid, 'credit', 'publish', $amount);
// return json object
$return = array(
'success' => 'true'
);
die(json_encode($return));
}
public static function wp_ajax_post_credit() {
$uid = $_POST['uid'];
......
......@@ -204,6 +204,7 @@ use WP_User, WP_Roles;
</div>
<div style="clear:both;"></div>
</div>
<div style="clear:both;"></div>
</div>
......
......@@ -14,10 +14,35 @@ use Tz\WordPress\Tools\Notifications;
use Exception, StdClass;
use WP_User;
?>
<div style="padding:10px 10px 0px 10px; min-width:760px;">
<h2 style="margin-bottom:10px;padding-bottom:0px;">Users' Invoices...</h2>
<div style="padding:10px 10px 0px 10px; min-width:760px;position:relative;">
<div style="position:absolute; width:200px; height:30px;right:20px; top:35px;text-align:right;font-size:16px;">Balance: <strong>$<?php echo get_user_meta($_GET['uid'],'balance',true);?></strong></div>
<h2 style="margin-bottom:10px;padding-bottom:0px;">Users' Invoices...
<?php if (!isset($_GET['view'])):?>
<a href="#" class="button add-new-h2" id="creditNotBtn">Make Credit Note</a>
<?php endif; ?>
</h2>
<div id="credit_note" style="display:none;">
<div style="border:1px solid #e8e8e8; background-color:#f5f5f5;padding:10px;">
<form id="creditForm" method="POST">
<input type="hidden" name="uid" value="<?php echo $_GET['uid']; ?>" />
<h3 style="margin:0;padding:0;">Credit Note:</h3>
<table width="100%">
<tbody>
<tr>
<td width="80">Credit for:</td>
<td><input type="text" name="title" style="width:400px" /></td>
<td width="130" style="text-align:right;padding-right:10px;">Credit Amount $</td>
<td><input type="text" name="amount" /></td>
</tr>
<tr>
<td colspan="4" style="padding-top:5px;"><input type="submit" value="Apply Credit Note" /></td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
<?php
if ( isset($_GET['view']) ) {
......@@ -36,8 +61,14 @@ use WP_User;
$html = '<p><a href="/wp-admin/admin.php?page=cbv_users&action=edit&uid='.$_GET['uid'].'&section=payhistory">Show all invoices</a></p>';
$html .= '<p>
<img src="assets/images/logo.gif" width="114" height="92" /><br />
<strong>The Canadian Institute of Chartered Business Valuators</strong><br />
277 Wellington St. West, Suite 710<br />
Toronto, ON, Canada M5V 3H2
</p>';
$html .= '<div style="text-align:right;margin-bottom:5px;"><a href="/invoices/?view='.$invoice->ID.'&pagename=invoice-preview" class="label label-black-print print-invoice-handler" target="_blank"></a></div>';
//$html .= '<div style="text-align:right;margin-bottom:5px;"><a href="/invoices/?view='.$invoice->ID.'&pagename=invoice-preview" class="label label-black-print print-invoice-handler" target="_blank"></a></div>';
$html .= '<div style="border:1px solid #777;padding:20px;position:relative;" id="viewable-port">';
......@@ -50,14 +81,22 @@ use WP_User;
$html .= '<p style="text-align:right;margin-top:0;padding-top:0;"><strong>Invoice Date:</strong> '.$date.'</p>';
$html .= '<h2>'.$invoice->post_title.'</h2>';
$invoice_type = get_post_meta($invoice->ID, 'invoice_for', true);
$html .= '<p>';
$html .= '<table cellpadding="0" cellspacing="0" border="0" id="invoice-table">';
$html .= '<thead>';
$html .= '<tr>';
$html .= '<th>Item / Description</th>';
if ($invoice_type!="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>';
}
$html .= '</tr>';
$html .= '</thead>';
$html .= '<tbody>';
......@@ -75,6 +114,8 @@ use WP_User;
$html .= '<tr class="'.$row_class.'">';
$html .= '<td>'.$description.'</td>';
if ($invoice_type!="credit") {
$html .= '<td>$'.$item['cost'].'</td>';
if (empty($item['discount_amount'])) {
$html .= '<td>$0.00</td>';
......@@ -82,20 +123,24 @@ use WP_User;
$html .= '<td>-$'.$item['discount_amount'].'</td>';
}
}
$html .= '<td>$'.$item['subtotal'].'</td>';
$html .= '</tr>';
$i++;
}
$html .= '</tbody>';
$html .= '</table>';
if ($invoice_type != "credit") {
$html .= '<table cellpadding="0" cellspacing="0" border="0" class="clean" id="invoice-table">';
$html .= '<tfoot>';
$html .= '<tr>';
$html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Total Cost</td>';
$html .= '<td width="120">$'.number_format($invoice->payment['total_cost'],2).'</td>';
$html .= '</tr>';
if ($invoice->payment['total_discounts'] > 0) {
$html .= '<tr>';
$html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Total Discounts</td>';
......@@ -106,7 +151,6 @@ use WP_User;
$html .= '<td>$'.number_format($invoice->payment['subtotal'],2).'</td>';
$html .= '</tr>';
}
$html .= '<tr>';
$html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Taxes</td>';
$html .= '<td>$'.number_format($invoice->payment['total_taxes'],2).'</td>';
......@@ -115,20 +159,25 @@ use WP_User;
$html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Total</td>';
$html .= '<td><strong>$'.number_format($invoice->payment['total'],2).'</strong></td>';
$html .= '</tr>';
$html .= '</tfoot>';
$html .= '</table>';
}
$html .= '</p>';
if ($invoice_type != "credit") {
$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'];
}
$html .= '</div>';
$html .= '<div style="text-align:right;margin-top:5px;"><a href="/invoices/?view='.$_GET['view'].'&pagename=invoice-preview" class="label label-black-print print-invoice-handler" target="_blank"></a></div>';
//$html .= '<div style="text-align:right;margin-top:5px;"><a href="/invoices/?view='.$_GET['view'].'&pagename=invoice-preview" class="label label-black-print print-invoice-handler" target="_blank"></a></div>';
print $html;
......