5f4155a1 by Kevin Burton

invoicing updates

1 parent 8a0f1789
...@@ -164,17 +164,23 @@ jQuery(function($) { ...@@ -164,17 +164,23 @@ jQuery(function($) {
164 164
165 jQuery('.invoice-refund-btn').live('click', function(e) { 165 jQuery('.invoice-refund-btn').live('click', function(e) {
166 var iid = $(this).attr('rel'); 166 var iid = $(this).attr('rel');
167 var current_amount = $(this).attr('amount');
167 168
168 jConfirm('<strong>Are you sure</strong> you want to <em>refund</em> this invoice?', 'Refund Invoice', function(c) { 169 jConfirm('<strong>Are you sure</strong> you want to <em>refund</em> this invoice?', 'Refund Invoice', function(c) {
169 if (c) { 170 if (c) {
170 jQuery.ajax({ 171
171 url: '/wp-admin/admin-ajax.php' 172 jPrompt('How much would you like to re-imburse?', current_amount, 'Re-imburse...', function(r) {
172 , data: ({ajax:"yes", action: 'admin_refund_invoice', invoice_id:iid }) 173 if( r ) {
173 , dataType: 'json' 174 jQuery.ajax({
174 , type: 'POST' 175 url: '/wp-admin/admin-ajax.php'
175 , success: function(data) { 176 , data: ({ajax:"yes", action: 'admin_refund_invoice',invoice_id:iid, amount:r})
176 document.location.reload(); 177 , type: 'POST'
177 } 178 , dataType: 'json'
179 , success: function(data) {
180 document.location.reload();
181 }
182 });
183 }
178 }); 184 });
179 } 185 }
180 }); 186 });
...@@ -207,11 +213,7 @@ jQuery(function($) { ...@@ -207,11 +213,7 @@ jQuery(function($) {
207 var cb = this; 213 var cb = this;
208 var options = { 214 var options = {
209 success: function(data) { 215 success: function(data) {
210 if (data.refresh == "true") { 216 document.location.reload();
211 document.location.href = document.location.href;
212 } else {
213 jQuery.colorbox.close();
214 }
215 } 217 }
216 , data: ({ajax:"yes", action: 'admin_update_invoice'}) 218 , data: ({ajax:"yes", action: 'admin_update_invoice'})
217 , dataType: 'json' 219 , dataType: 'json'
......
...@@ -712,11 +712,7 @@ class Actions { ...@@ -712,11 +712,7 @@ class Actions {
712 $invoice_type = $_POST['invoice_type']; 712 $invoice_type = $_POST['invoice_type'];
713 $paid_by = $_POST['paid_by']; 713 $paid_by = $_POST['paid_by'];
714 $title = $_POST['title']; 714 $title = $_POST['title'];
715 715
716 if ($invoice_type=="credit") {
717 $amount = "-".$amount;
718 }
719
720 $paid = (isset($_POST['paid']) && $_POST['paid']=="on") ? true : false; 716 $paid = (isset($_POST['paid']) && $_POST['paid']=="on") ? true : false;
721 if ($invoice_type=="invoice") { 717 if ($invoice_type=="invoice") {
722 if (!$paid) { 718 if (!$paid) {
...@@ -776,7 +772,10 @@ class Actions { ...@@ -776,7 +772,10 @@ class Actions {
776 } 772 }
777 } 773 }
778 774
779 Invoice\create($invoice_data, 'generic', $title, $uid, $status, 'publish', $amount); 775 $new_invoice_id = Invoice\create($invoice_data, 'generic', $title, $uid, $status, 'publish', $amount);
776 if ($invoice_type=="credit") {
777 update_post_meta($new_invoice_id, 'credit_amount', $amount);
778 }
780 779
781 // return json object 780 // return json object
782 $return = array( 781 $return = array(
...@@ -1106,24 +1105,45 @@ class Actions { ...@@ -1106,24 +1105,45 @@ class Actions {
1106 die(json_encode($return)); 1105 die(json_encode($return));
1107 } 1106 }
1108 1107
1108 public static function wp_ajax_admin_update_invoice() {
1109 $invoice_id = $_POST['invoice_id'];
1110 $user_id = $_POST['uid'];
1111
1112 update_post_meta($invoice_id, 'trans_status', 'paid');
1113 $payment = get_post_meta($invoice_id, 'payment', true);
1114 $payment['bt_card_type'] = $_POST['paid_by'];
1115 update_post_meta($invoice_id, 'payment', $payment);
1116
1117 $invoice_for = get_post_meta($invoice_id, 'invoice_for', true);
1118 if ( !empty($invoice_for) && $invoice_for == "membership") {
1119 $next_year = (int) date("Y");
1120 $next_year = ($next_year + 1);
1121 update_user_meta($user_id, 'membership_valid_until', $next_year);
1122 }
1123
1124 $return = array(
1125 'success' => 'true'
1126 );
1127 die(json_encode($return));
1128 }
1129
1109 public static function wp_ajax_admin_refund_invoice() { 1130 public static function wp_ajax_admin_refund_invoice() {
1110 $invoice_id = $_POST['invoice_id']; 1131 $invoice_id = $_POST['invoice_id'];
1132 $amount = $_POST['amount'];
1111 1133
1112 $invoice = get_post($invoice_id); 1134 $invoice = get_post($invoice_id);
1113 $payment = get_post_meta($invoice_id, 'payment', true); 1135 $payment = get_post_meta($invoice_id, 'payment', true);
1114
1115
1116 $trans_amount = get_post_meta($invoice_id, 'trans_amount', true); 1136 $trans_amount = get_post_meta($invoice_id, 'trans_amount', true);
1117 $invoice_for = get_post_meta($invoice_id, 'invoice_for', true); 1137 $invoice_for = get_post_meta($invoice_id, 'invoice_for', true);
1118 $items = get_post_meta($invoice_id, 'items', true); 1138 $items = get_post_meta($invoice_id, 'items', true);
1119
1120 update_post_meta($invoice->ID, 'refunded', date('Y-m-d H:i:s')); 1139 update_post_meta($invoice->ID, 'refunded', date('Y-m-d H:i:s'));
1121 1140
1122 $invoice_data['items'] = $items; 1141
1123 $invoice_data['payment'] = $payment; 1142 $invoice_data['items'] = $items;
1143 $invoice_data['payment'] = $payment;
1124 $new_invoice_id = Invoice\create($invoice_data, $invoice_for, $invoice->post_title, $invoice->post_author, 'credit', 'publish', $trans_amount); 1144 $new_invoice_id = Invoice\create($invoice_data, $invoice_for, $invoice->post_title, $invoice->post_author, 'credit', 'publish', $trans_amount);
1125 1145 update_post_meta($new_invoice_id, 'original_invoice_id', $invoice_id);
1126 1146 update_post_meta($new_invoice_id, 'credit_amount', $amount);
1127 1147
1128 } 1148 }
1129 1149
......
...@@ -155,8 +155,8 @@ use WP_User, WP_Roles; ...@@ -155,8 +155,8 @@ use WP_User, WP_Roles;
155 <td><label for="status_retired">Retired status</label></td> 155 <td><label for="status_retired">Retired status</label></td>
156 </tr> 156 </tr>
157 <tr> 157 <tr>
158 <td width="20"><input type="checkbox" id="status_disability" name="special_status[]" value="status_disability" <?php search_special_status('status_disability');?> /></td> 158 <td width="20"><input type="checkbox" id="status_disabled" name="special_status[]" value="status_disabled" <?php search_special_status('status_disabled');?> /></td>
159 <td><label for="status_disability">Disability status</label></td> 159 <td><label for="status_disabled">Disability status</label></td>
160 </tr> 160 </tr>
161 <tr> 161 <tr>
162 <td width="20"><input type="checkbox" id="status_parental" name="special_status[]" value="status_parental" <?php search_special_status('status_parental');?> /></td> 162 <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; ...@@ -17,7 +17,7 @@ use WP_User;
17 <div style="padding:10px 10px 0px 10px; min-width:760px;position:relative;"> 17 <div style="padding:10px 10px 0px 10px; min-width:760px;position:relative;">
18 <h2 style="margin-bottom:10px;padding-bottom:0px;">Users' Payment History... 18 <h2 style="margin-bottom:10px;padding-bottom:0px;">Users' Payment History...
19 <?php if (!isset($_GET['view'])):?> 19 <?php if (!isset($_GET['view'])):?>
20 <a href="#" class="button add-new-h2" id="creditNotBtn">Creat new Invoice/Credit Note</a> 20 <a href="#" class="button add-new-h2" id="creditNotBtn">Create new Invoice/Credit Note</a>
21 <?php endif; ?> 21 <?php endif; ?>
22 </h2> 22 </h2>
23 23
...@@ -53,11 +53,11 @@ use WP_User; ...@@ -53,11 +53,11 @@ use WP_User;
53 <td>Paid By</td> 53 <td>Paid By</td>
54 <td> 54 <td>
55 <select name="paid_by"> 55 <select name="paid_by">
56 <option value="">(none)</option> 56 <option value="">Select payment type...</option>
57 <option value="visa">Visa</option> 57 <option value="PPV">Pre-paid with Visa</option>
58 <option value="mc">Mastercard</option> 58 <option value="PPMC">Pre-paid with Mastercard</option>
59 <option value="amex">American Express</option> 59 <option value="PPAMEX">Pre-paid with American Express</option>
60 <option value="cheque">Cheque</option> 60 <option value="CHEQUE">Paid by Cheque</option>
61 </select> 61 </select>
62 </td> 62 </td>
63 </tr> 63 </tr>
...@@ -115,13 +115,13 @@ use WP_User; ...@@ -115,13 +115,13 @@ use WP_User;
115 $html .= '<tr>'; 115 $html .= '<tr>';
116 $html .= '<th>Item / Description</th>'; 116 $html .= '<th>Item / Description</th>';
117 117
118 if ($status!="credit") { 118 //if ($status!="credit") {
119 $html .= '<th width="80">Cost</th>'; 119 $html .= '<th width="80">Cost</th>';
120 $html .= '<th width="80">Discounts</th>'; 120 $html .= '<th width="80">Discounts</th>';
121 $html .= '<th width="120">Amount</th>'; 121 $html .= '<th width="120">Amount</th>';
122 } else { 122 //} else {
123 $html .= '<th width="120">Credit</th>'; 123 //$html .= '<th width="120">Credit</th>';
124 } 124 //}
125 125
126 $html .= '</tr>'; 126 $html .= '</tr>';
127 $html .= '</thead>'; 127 $html .= '</thead>';
...@@ -176,7 +176,7 @@ use WP_User; ...@@ -176,7 +176,7 @@ use WP_User;
176 $html .= '<tr class="'.$row_class.'">'; 176 $html .= '<tr class="'.$row_class.'">';
177 $html .= '<td>'.$description.'</td>'; 177 $html .= '<td>'.$description.'</td>';
178 178
179 if ($status!="credit") { 179 //if ($status!="credit") {
180 $html .= '<td>$'.$item['cost'].'</td>'; 180 $html .= '<td>$'.$item['cost'].'</td>';
181 if (empty($item['discount_amount'])) { 181 if (empty($item['discount_amount'])) {
182 $html .= '<td>$0.00</td>'; 182 $html .= '<td>$0.00</td>';
...@@ -184,7 +184,7 @@ use WP_User; ...@@ -184,7 +184,7 @@ use WP_User;
184 $html .= '<td>-$'.$item['discount_amount'].'</td>'; 184 $html .= '<td>-$'.$item['discount_amount'].'</td>';
185 } 185 }
186 186
187 } 187 //}
188 $html .= '<td>$'.$item['subtotal'].'</td>'; 188 $html .= '<td>$'.$item['subtotal'].'</td>';
189 189
190 190
...@@ -193,7 +193,7 @@ use WP_User; ...@@ -193,7 +193,7 @@ use WP_User;
193 } 193 }
194 $html .= '</tbody>'; 194 $html .= '</tbody>';
195 $html .= '</table>'; 195 $html .= '</table>';
196 if ($status != "credit") { 196 //if ($status != "credit") {
197 $html .= '<table cellpadding="0" cellspacing="0" border="0" class="clean" id="invoice-table">'; 197 $html .= '<table cellpadding="0" cellspacing="0" border="0" class="clean" id="invoice-table">';
198 198
199 $html .= '<tfoot>'; 199 $html .= '<tfoot>';
...@@ -222,31 +222,47 @@ use WP_User; ...@@ -222,31 +222,47 @@ use WP_User;
222 222
223 } 223 }
224 224
225 $amount_label = ($status=="paid") ? "Total" : "Amount Due"; 225 $amount = $invoice->payment['total'];
226
227 $credit = get_post_meta($invoice->ID, 'credit_amount', true);
228 if ( !empty($credit) && $status == "credit" ) {
229
230 $html .= '<tr>';
231 $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold; color:green;">Credit</td>';
232 $html .= '<td style="color:green;">-$'.number_format($credit,2).'</td>';
233 $html .= '</tr>';
234
235
236 $amount = ($amount - $credit);
237 }
238
239 $amount_label = ($status=="unpaid") ? "Amount Due" : "Total";
240
241
226 242
227 $html .= '<tr>'; 243 $html .= '<tr>';
228 $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">'.$amount_label.'</td>'; 244 $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">'.$amount_label.'</td>';
229 $html .= '<td><strong>$'.number_format($invoice->payment['total'],2).'</strong></td>'; 245 $html .= '<td><strong>$'.number_format($amount,2).'</strong></td>';
230 $html .= '</tr>'; 246 $html .= '</tr>';
231 247
232 248
233 $html .= '</tfoot>'; 249 $html .= '</tfoot>';
234 $html .= '</table>'; 250 $html .= '</table>';
235 } 251 //}
236 $html .= '</p>'; 252 $html .= '</p>';
237 253
238 if ($status != "credit" && $invoice->payment['bt_address'] != "" && $invoice->payment['bt_card_holder'] != "") { 254 //if ($status != "credit" && $invoice->payment['bt_address'] != "" && $invoice->payment['bt_card_holder'] != "") {
239 $html .= '<h3>BILLED TO:</h3>'; 255 $html .= (!empty($invoice->payment['bt_card_holder'])) ? '<h3>BILLED TO:</h3>' : "";
240 $html .= $invoice->payment['bt_card_holder']."<br />"; 256 $html .= (!empty($invoice->payment['bt_card_holder'])) ? $invoice->payment['bt_card_holder']."<br />" : "";
241 $html .= $invoice->payment['bt_address']." ".$invoice->payment['bt_address2'] . "<br />"; 257 $html .= (!empty($invoice->payment['bt_address'])) ? $invoice->payment['bt_address']." ".$invoice->payment['bt_address2'] . "<br />" : "";
242 $html .= $invoice->payment['bt_city'].", " .$invoice->payment['bt_province']."<br />"; 258 $html .= (!empty($invoice->payment['bt_city'])) ? $invoice->payment['bt_city'].", " .$invoice->payment['bt_province']."<br />" : "";
243 $html .= $invoice->payment['bt_country']."&nbsp;&nbsp;".$invoice->payment['bt_postal']."<br /><br />"; 259 $html .= (!empty($invoice->payment['bt_country'])) ? $invoice->payment['bt_country']."&nbsp;&nbsp;".$invoice->payment['bt_postal']."<br /><br />" : "";
244 $html .= "<strong>".ucwords($invoice->payment['bt_card_type'])."</strong>&nbsp;&nbsp;" . $invoice->payment['bt_card_number']; 260 $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'] : "";
245 } 261 //}
246 262
247 if ($status != "credit") { 263 //if ($status != "credit") {
248 $html .= '<p>GST/HST# R108075334</p>'; 264 $html .= '<p>GST/HST# R108075334</p>';
249 } 265 //}
250 266
251 if ( $status == "paid" ) { 267 if ( $status == "paid" ) {
252 $html .= '<div style="text-align:center; font-size:14px; color:green;">-- <strong>PAID</strong> --</div>'; 268 $html .= '<div style="text-align:center; font-size:14px; color:green;">-- <strong>PAID</strong> --</div>';
...@@ -254,6 +270,8 @@ use WP_User; ...@@ -254,6 +270,8 @@ use WP_User;
254 $html .= '<div style="text-align:center; font-size:14px; color:red;">-- THIS INVOICE IS <strong>UNPAID</strong> --</div>'; 270 $html .= '<div style="text-align:center; font-size:14px; color:red;">-- THIS INVOICE IS <strong>UNPAID</strong> --</div>';
255 } elseif ( $status == "credit" ) { 271 } elseif ( $status == "credit" ) {
256 $html .= '<div style="text-align:center; font-size:14px; color:green;">-- <strong>CREDIT NOTE</strong> --</div>'; 272 $html .= '<div style="text-align:center; font-size:14px; color:green;">-- <strong>CREDIT NOTE</strong> --</div>';
273 } elseif ( $status == "cancelled" ) {
274 $html .= '<div style="text-align:center; font-size:14px; color:green;">-- THIS INVOICE IS <strong>CANCELLED</strong> --</div>';
257 } 275 }
258 276
259 277
......
...@@ -40,13 +40,12 @@ ...@@ -40,13 +40,12 @@
40 <div style="padding: 0px 0px 10px 0px;"> 40 <div style="padding: 0px 0px 10px 0px;">
41 <form method="post" action="" id="edit-invoice-form"> 41 <form method="post" action="" id="edit-invoice-form">
42 42
43 <input type="hidden" name="uid" value="<?php echo $uid; ?>" /> 43 <input type="hidden" name="uid" value="<?php echo $_GET['uid']; ?>" />
44 <input type="hidden" name="invoice_id" value="<?php echo $post->ID; ?>" /> 44 <input type="hidden" name="invoice_id" value="<?php echo $_GET['invoice_id']; ?>" />
45 <input type="hidden" name="type" value="<?php echo $action; ?>" />
46 45
47 <div class="dashboard-section" style="margin-left:20px;margin-top:10px;"> 46 <div class="dashboard-section" style="margin-left:20px;margin-top:10px;">
48 <div class="dashboard-section-content small"> 47 <div class="dashboard-section-content small">
49 <select name="status"> 48 <select name="paid_by">
50 <option value="">Select payment type...</option> 49 <option value="">Select payment type...</option>
51 <option value="PPV">Pre-paid with Visa</option> 50 <option value="PPV">Pre-paid with Visa</option>
52 <option value="PPMC">Pre-paid with Mastercard</option> 51 <option value="PPMC">Pre-paid with Mastercard</option>
......