user manager pay history
Showing
4 changed files
with
134 additions
and
9 deletions
| ... | @@ -21,6 +21,23 @@ jQuery(function($) { | ... | @@ -21,6 +21,23 @@ jQuery(function($) { |
| 21 | ); | 21 | ); |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | jQuery('#creditNotBtn').click(function(e) { | ||
| 25 | jQuery('#credit_note').slideToggle('fast'); | ||
| 26 | jQuery('#creditForm').ajaxForm({ | ||
| 27 | url: '/wp-admin/admin-ajax.php' | ||
| 28 | , data: ({ajax:"yes", action: 'add_credit_note'}) | ||
| 29 | , dateType: 'json' | ||
| 30 | , type: 'POST' | ||
| 31 | , success: function(data) { | ||
| 32 | // reload, cannot use reload() because then the form values get re-applied. | ||
| 33 | document.location.href = document.location.href; | ||
| 34 | |||
| 35 | } | ||
| 36 | }); | ||
| 37 | e.preventDefault(); | ||
| 38 | return false; | ||
| 39 | }); | ||
| 40 | |||
| 24 | jQuery('.remove-user').colorbox({onComplete: function() { | 41 | jQuery('.remove-user').colorbox({onComplete: function() { |
| 25 | 42 | ||
| 26 | var cb = this; | 43 | var cb = this; | ... | ... |
| ... | @@ -18,12 +18,14 @@ use Tz\WordPress\CBV; | ... | @@ -18,12 +18,14 @@ use Tz\WordPress\CBV; |
| 18 | use Tz\WordPress\CBV\User; | 18 | use Tz\WordPress\CBV\User; |
| 19 | use Tz\WordPress\CBV\Events; | 19 | use Tz\WordPress\CBV\Events; |
| 20 | use Tz\WordPress\CBV\CEHours; | 20 | use Tz\WordPress\CBV\CEHours; |
| 21 | use Tz\WordPress\CBV\Invoice; | ||
| 21 | use Exception, StdClass; | 22 | use Exception, StdClass; |
| 22 | use WP_User; | 23 | use WP_User; |
| 23 | 24 | ||
| 24 | const OPTION_NAME = "user_options"; | 25 | const OPTION_NAME = "user_options"; |
| 25 | const CAPABILITY = "manage_cbv_users"; | 26 | const CAPABILITY = "manage_cbv_users"; |
| 26 | 27 | ||
| 28 | CBV\load('Invoice'); | ||
| 27 | CBV\load('User'); | 29 | CBV\load('User'); |
| 28 | Tools\import('HTML'); | 30 | Tools\import('HTML'); |
| 29 | 31 | ||
| ... | @@ -661,6 +663,62 @@ class Actions { | ... | @@ -661,6 +663,62 @@ class Actions { |
| 661 | die(json_encode($return)); | 663 | die(json_encode($return)); |
| 662 | } | 664 | } |
| 663 | 665 | ||
| 666 | public static function wp_ajax_add_credit_note() { | ||
| 667 | $uid = $_POST['uid']; | ||
| 668 | $title = $_POST['title']; | ||
| 669 | $amount = "-".$_POST['amount']; | ||
| 670 | |||
| 671 | global $wpdb; | ||
| 672 | |||
| 673 | |||
| 674 | $items = array(); | ||
| 675 | |||
| 676 | $items[] = array( | ||
| 677 | 'post_id' => 0 | ||
| 678 | , 'cost' => $amount | ||
| 679 | , 'discount_label' => "" | ||
| 680 | , 'discount_amount' => "" | ||
| 681 | , 'tax_label' => "" | ||
| 682 | , 'tax_rate' => "" | ||
| 683 | , 'tax_amount' => "" | ||
| 684 | , 'subtotal' => $amount | ||
| 685 | , 'total' => $amount | ||
| 686 | , 'description' => "Credit Note" | ||
| 687 | , 'extras' => array() | ||
| 688 | |||
| 689 | ); | ||
| 690 | |||
| 691 | |||
| 692 | $invoice_data = array(); | ||
| 693 | $invoice_data['items'] = $items; | ||
| 694 | $invoice_data['payment'] = array( | ||
| 695 | 'total_cost' => $amount | ||
| 696 | , 'total_discounts' => "" | ||
| 697 | , 'total_taxes' => "" | ||
| 698 | , 'subtotal' => $amount | ||
| 699 | , 'total' => $amount | ||
| 700 | , 'bt_address' => "" | ||
| 701 | , 'bt_address2' => "" | ||
| 702 | , 'bt_city' => "" | ||
| 703 | , 'bt_province' => "" | ||
| 704 | , 'bt_country' => "" | ||
| 705 | , 'bt_postal' => "" | ||
| 706 | , 'bt_card_holder' => "" | ||
| 707 | , 'bt_card_number' => "" | ||
| 708 | , 'bt_card_type' => "" | ||
| 709 | ); | ||
| 710 | |||
| 711 | |||
| 712 | |||
| 713 | Invoice\create($invoice_data, 'credit', $title, $uid, 'credit', 'publish', $amount); | ||
| 714 | |||
| 715 | // return json object | ||
| 716 | $return = array( | ||
| 717 | 'success' => 'true' | ||
| 718 | ); | ||
| 719 | die(json_encode($return)); | ||
| 720 | } | ||
| 721 | |||
| 664 | public static function wp_ajax_post_credit() { | 722 | public static function wp_ajax_post_credit() { |
| 665 | 723 | ||
| 666 | $uid = $_POST['uid']; | 724 | $uid = $_POST['uid']; | ... | ... |
| ... | @@ -14,10 +14,35 @@ use Tz\WordPress\Tools\Notifications; | ... | @@ -14,10 +14,35 @@ use Tz\WordPress\Tools\Notifications; |
| 14 | use Exception, StdClass; | 14 | use Exception, StdClass; |
| 15 | use WP_User; | 15 | use WP_User; |
| 16 | ?> | 16 | ?> |
| 17 | <div style="padding:10px 10px 0px 10px; min-width:760px;"> | 17 | <div style="padding:10px 10px 0px 10px; min-width:760px;position:relative;"> |
| 18 | <h2 style="margin-bottom:10px;padding-bottom:0px;">Users' Invoices...</h2> | 18 | <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> |
| 19 | 19 | <h2 style="margin-bottom:10px;padding-bottom:0px;">Users' Invoices... | |
| 20 | 20 | <?php if (!isset($_GET['view'])):?> | |
| 21 | <a href="#" class="button add-new-h2" id="creditNotBtn">Make Credit Note</a> | ||
| 22 | <?php endif; ?> | ||
| 23 | </h2> | ||
| 24 | |||
| 25 | <div id="credit_note" style="display:none;"> | ||
| 26 | <div style="border:1px solid #e8e8e8; background-color:#f5f5f5;padding:10px;"> | ||
| 27 | <form id="creditForm" method="POST"> | ||
| 28 | <input type="hidden" name="uid" value="<?php echo $_GET['uid']; ?>" /> | ||
| 29 | <h3 style="margin:0;padding:0;">Credit Note:</h3> | ||
| 30 | <table width="100%"> | ||
| 31 | <tbody> | ||
| 32 | <tr> | ||
| 33 | <td width="80">Credit for:</td> | ||
| 34 | <td><input type="text" name="title" style="width:400px" /></td> | ||
| 35 | <td width="130" style="text-align:right;padding-right:10px;">Credit Amount $</td> | ||
| 36 | <td><input type="text" name="amount" /></td> | ||
| 37 | </tr> | ||
| 38 | <tr> | ||
| 39 | <td colspan="4" style="padding-top:5px;"><input type="submit" value="Apply Credit Note" /></td> | ||
| 40 | </tr> | ||
| 41 | </tbody> | ||
| 42 | </table> | ||
| 43 | </form> | ||
| 44 | </div> | ||
| 45 | </div> | ||
| 21 | 46 | ||
| 22 | <?php | 47 | <?php |
| 23 | if ( isset($_GET['view']) ) { | 48 | if ( isset($_GET['view']) ) { |
| ... | @@ -36,8 +61,14 @@ use WP_User; | ... | @@ -36,8 +61,14 @@ use WP_User; |
| 36 | 61 | ||
| 37 | $html = '<p><a href="/wp-admin/admin.php?page=cbv_users&action=edit&uid='.$_GET['uid'].'§ion=payhistory">Show all invoices</a></p>'; | 62 | $html = '<p><a href="/wp-admin/admin.php?page=cbv_users&action=edit&uid='.$_GET['uid'].'§ion=payhistory">Show all invoices</a></p>'; |
| 38 | 63 | ||
| 64 | $html .= '<p> | ||
| 65 | <img src="assets/images/logo.gif" width="114" height="92" /><br /> | ||
| 66 | <strong>The Canadian Institute of Chartered Business Valuators</strong><br /> | ||
| 67 | 277 Wellington St. West, Suite 710<br /> | ||
| 68 | Toronto, ON, Canada M5V 3H2 | ||
| 69 | </p>'; | ||
| 39 | 70 | ||
| 40 | $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>'; | 71 | //$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>'; |
| 41 | 72 | ||
| 42 | $html .= '<div style="border:1px solid #777;padding:20px;position:relative;" id="viewable-port">'; | 73 | $html .= '<div style="border:1px solid #777;padding:20px;position:relative;" id="viewable-port">'; |
| 43 | 74 | ||
| ... | @@ -50,14 +81,22 @@ use WP_User; | ... | @@ -50,14 +81,22 @@ use WP_User; |
| 50 | $html .= '<p style="text-align:right;margin-top:0;padding-top:0;"><strong>Invoice Date:</strong> '.$date.'</p>'; | 81 | $html .= '<p style="text-align:right;margin-top:0;padding-top:0;"><strong>Invoice Date:</strong> '.$date.'</p>'; |
| 51 | $html .= '<h2>'.$invoice->post_title.'</h2>'; | 82 | $html .= '<h2>'.$invoice->post_title.'</h2>'; |
| 52 | 83 | ||
| 84 | $invoice_type = get_post_meta($invoice->ID, 'invoice_for', true); | ||
| 85 | |||
| 53 | $html .= '<p>'; | 86 | $html .= '<p>'; |
| 54 | $html .= '<table cellpadding="0" cellspacing="0" border="0" id="invoice-table">'; | 87 | $html .= '<table cellpadding="0" cellspacing="0" border="0" id="invoice-table">'; |
| 55 | $html .= '<thead>'; | 88 | $html .= '<thead>'; |
| 56 | $html .= '<tr>'; | 89 | $html .= '<tr>'; |
| 57 | $html .= '<th>Item / Description</th>'; | 90 | $html .= '<th>Item / Description</th>'; |
| 91 | |||
| 92 | if ($invoice_type!="credit") { | ||
| 58 | $html .= '<th width="80">Cost</th>'; | 93 | $html .= '<th width="80">Cost</th>'; |
| 59 | $html .= '<th width="80">Discounts</th>'; | 94 | $html .= '<th width="80">Discounts</th>'; |
| 60 | $html .= '<th width="120">Amount</th>'; | 95 | $html .= '<th width="120">Amount</th>'; |
| 96 | } else { | ||
| 97 | $html .= '<th width="120">Credit</th>'; | ||
| 98 | } | ||
| 99 | |||
| 61 | $html .= '</tr>'; | 100 | $html .= '</tr>'; |
| 62 | $html .= '</thead>'; | 101 | $html .= '</thead>'; |
| 63 | $html .= '<tbody>'; | 102 | $html .= '<tbody>'; |
| ... | @@ -75,6 +114,8 @@ use WP_User; | ... | @@ -75,6 +114,8 @@ use WP_User; |
| 75 | 114 | ||
| 76 | $html .= '<tr class="'.$row_class.'">'; | 115 | $html .= '<tr class="'.$row_class.'">'; |
| 77 | $html .= '<td>'.$description.'</td>'; | 116 | $html .= '<td>'.$description.'</td>'; |
| 117 | |||
| 118 | if ($invoice_type!="credit") { | ||
| 78 | $html .= '<td>$'.$item['cost'].'</td>'; | 119 | $html .= '<td>$'.$item['cost'].'</td>'; |
| 79 | if (empty($item['discount_amount'])) { | 120 | if (empty($item['discount_amount'])) { |
| 80 | $html .= '<td>$0.00</td>'; | 121 | $html .= '<td>$0.00</td>'; |
| ... | @@ -82,20 +123,24 @@ use WP_User; | ... | @@ -82,20 +123,24 @@ use WP_User; |
| 82 | $html .= '<td>-$'.$item['discount_amount'].'</td>'; | 123 | $html .= '<td>-$'.$item['discount_amount'].'</td>'; |
| 83 | } | 124 | } |
| 84 | 125 | ||
| 126 | } | ||
| 85 | $html .= '<td>$'.$item['subtotal'].'</td>'; | 127 | $html .= '<td>$'.$item['subtotal'].'</td>'; |
| 128 | |||
| 129 | |||
| 86 | $html .= '</tr>'; | 130 | $html .= '</tr>'; |
| 87 | $i++; | 131 | $i++; |
| 88 | } | 132 | } |
| 89 | $html .= '</tbody>'; | 133 | $html .= '</tbody>'; |
| 90 | $html .= '</table>'; | 134 | $html .= '</table>'; |
| 135 | if ($invoice_type != "credit") { | ||
| 91 | $html .= '<table cellpadding="0" cellspacing="0" border="0" class="clean" id="invoice-table">'; | 136 | $html .= '<table cellpadding="0" cellspacing="0" border="0" class="clean" id="invoice-table">'; |
| 137 | |||
| 92 | $html .= '<tfoot>'; | 138 | $html .= '<tfoot>'; |
| 139 | |||
| 93 | $html .= '<tr>'; | 140 | $html .= '<tr>'; |
| 94 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Total Cost</td>'; | 141 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Total Cost</td>'; |
| 95 | $html .= '<td width="120">$'.number_format($invoice->payment['total_cost'],2).'</td>'; | 142 | $html .= '<td width="120">$'.number_format($invoice->payment['total_cost'],2).'</td>'; |
| 96 | $html .= '</tr>'; | 143 | $html .= '</tr>'; |
| 97 | |||
| 98 | |||
| 99 | if ($invoice->payment['total_discounts'] > 0) { | 144 | if ($invoice->payment['total_discounts'] > 0) { |
| 100 | $html .= '<tr>'; | 145 | $html .= '<tr>'; |
| 101 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Total Discounts</td>'; | 146 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Total Discounts</td>'; |
| ... | @@ -106,7 +151,6 @@ use WP_User; | ... | @@ -106,7 +151,6 @@ use WP_User; |
| 106 | $html .= '<td>$'.number_format($invoice->payment['subtotal'],2).'</td>'; | 151 | $html .= '<td>$'.number_format($invoice->payment['subtotal'],2).'</td>'; |
| 107 | $html .= '</tr>'; | 152 | $html .= '</tr>'; |
| 108 | } | 153 | } |
| 109 | |||
| 110 | $html .= '<tr>'; | 154 | $html .= '<tr>'; |
| 111 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Taxes</td>'; | 155 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Taxes</td>'; |
| 112 | $html .= '<td>$'.number_format($invoice->payment['total_taxes'],2).'</td>'; | 156 | $html .= '<td>$'.number_format($invoice->payment['total_taxes'],2).'</td>'; |
| ... | @@ -115,20 +159,25 @@ use WP_User; | ... | @@ -115,20 +159,25 @@ use WP_User; |
| 115 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Total</td>'; | 159 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Total</td>'; |
| 116 | $html .= '<td><strong>$'.number_format($invoice->payment['total'],2).'</strong></td>'; | 160 | $html .= '<td><strong>$'.number_format($invoice->payment['total'],2).'</strong></td>'; |
| 117 | $html .= '</tr>'; | 161 | $html .= '</tr>'; |
| 162 | |||
| 163 | |||
| 118 | $html .= '</tfoot>'; | 164 | $html .= '</tfoot>'; |
| 119 | $html .= '</table>'; | 165 | $html .= '</table>'; |
| 166 | } | ||
| 120 | $html .= '</p>'; | 167 | $html .= '</p>'; |
| 121 | 168 | ||
| 169 | if ($invoice_type != "credit") { | ||
| 122 | $html .= '<h3>BILLED TO:</h3>'; | 170 | $html .= '<h3>BILLED TO:</h3>'; |
| 123 | $html .= $invoice->payment['bt_card_holder']."<br />"; | 171 | $html .= $invoice->payment['bt_card_holder']."<br />"; |
| 124 | $html .= $invoice->payment['bt_address']." ".$invoice->payment['bt_address2'] . "<br />"; | 172 | $html .= $invoice->payment['bt_address']." ".$invoice->payment['bt_address2'] . "<br />"; |
| 125 | $html .= $invoice->payment['bt_city'].", " .$invoice->payment['bt_province']."<br />"; | 173 | $html .= $invoice->payment['bt_city'].", " .$invoice->payment['bt_province']."<br />"; |
| 126 | $html .= $invoice->payment['bt_country']." ".$invoice->payment['bt_postal']."<br /><br />"; | 174 | $html .= $invoice->payment['bt_country']." ".$invoice->payment['bt_postal']."<br /><br />"; |
| 127 | $html .= "<strong>".ucwords($invoice->payment['bt_card_type'])."</strong> " . $invoice->payment['bt_card_number']; | 175 | $html .= "<strong>".ucwords($invoice->payment['bt_card_type'])."</strong> " . $invoice->payment['bt_card_number']; |
| 176 | } | ||
| 128 | 177 | ||
| 129 | $html .= '</div>'; | 178 | $html .= '</div>'; |
| 130 | 179 | ||
| 131 | $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>'; | 180 | //$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>'; |
| 132 | 181 | ||
| 133 | 182 | ||
| 134 | print $html; | 183 | print $html; | ... | ... |
-
Please register or sign in to post a comment