User Manager Updates for invoices
Showing
3 changed files
with
60 additions
and
217 deletions
| ... | @@ -22,11 +22,24 @@ jQuery(function($) { | ... | @@ -22,11 +22,24 @@ jQuery(function($) { |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | $('#invoice_type').change(function() { | 24 | $('#invoice_type').change(function() { |
| 25 | if ($('#invoice_type').val() == "invoice") { | 25 | |
| 26 | $('.invoice_only').show(); | 26 | var invoice_type = $(this).val(); |
| 27 | } else { | 27 | |
| 28 | $('.invoice_only').hide(); | 28 | switch(invoice_type) { |
| 29 | case 'invoice': | ||
| 30 | $('tr.invoice_credit_only').show(); | ||
| 31 | $('tr.invoice_only').show(); | ||
| 32 | break; | ||
| 33 | case 'membership': | ||
| 34 | $('tr.invoice_credit_only').hide(); | ||
| 35 | $('tr.invoice_only').show(); | ||
| 36 | break; | ||
| 37 | default: | ||
| 38 | $('tr.invoice_credit_only').show(); | ||
| 39 | $('tr.invoice_only').hide(); | ||
| 29 | } | 40 | } |
| 41 | |||
| 42 | |||
| 30 | }); | 43 | }); |
| 31 | 44 | ||
| 32 | jQuery('#creditNotBtn').click(function(e) { | 45 | jQuery('#creditNotBtn').click(function(e) { | ... | ... |
| ... | @@ -713,6 +713,14 @@ class Actions { | ... | @@ -713,6 +713,14 @@ class Actions { |
| 713 | if ($uid == 0) { | 713 | if ($uid == 0) { |
| 714 | $uid = $_POST['uid']; | 714 | $uid = $_POST['uid']; |
| 715 | } | 715 | } |
| 716 | |||
| 717 | // All this for tax purposes.... | ||
| 718 | $pp = strtolower(get_user_meta($uid, 'profile_preference', true)); | ||
| 719 | if (empty($pp)) { | ||
| 720 | $pp = "home"; | ||
| 721 | } | ||
| 722 | $pp = $pp . "_"; | ||
| 723 | |||
| 716 | $amount = $_POST['amount']; | 724 | $amount = $_POST['amount']; |
| 717 | $invoice_type = $_POST['invoice_type']; | 725 | $invoice_type = $_POST['invoice_type']; |
| 718 | $paid_by = $_POST['paid_by']; | 726 | $paid_by = $_POST['paid_by']; |
| ... | @@ -728,6 +736,27 @@ class Actions { | ... | @@ -728,6 +736,27 @@ class Actions { |
| 728 | } | 736 | } |
| 729 | 737 | ||
| 730 | 738 | ||
| 739 | // if membership.... | ||
| 740 | if ($invoice_type=="membership") { | ||
| 741 | |||
| 742 | $paid = (isset($_POST['paid']) && $_POST['paid']=="on") ? true : false; | ||
| 743 | if ($paid) { | ||
| 744 | $status = "paid"; | ||
| 745 | } else { | ||
| 746 | $status = "unpaid"; | ||
| 747 | } | ||
| 748 | |||
| 749 | |||
| 750 | Invoice\GenerateMembershipInvoice($uid, $status, $paid_by, false); | ||
| 751 | // return json object | ||
| 752 | $return = array( | ||
| 753 | 'success' => 'true' | ||
| 754 | ); | ||
| 755 | die(json_encode($return)); | ||
| 756 | } | ||
| 757 | |||
| 758 | // if not membership..... | ||
| 759 | |||
| 731 | $items = array(); | 760 | $items = array(); |
| 732 | 761 | ||
| 733 | $items[] = array( | 762 | $items[] = array( |
| ... | @@ -753,12 +782,12 @@ class Actions { | ... | @@ -753,12 +782,12 @@ class Actions { |
| 753 | , 'total_taxes' => "" | 782 | , 'total_taxes' => "" |
| 754 | , 'subtotal' => $amount | 783 | , 'subtotal' => $amount |
| 755 | , 'total' => $amount | 784 | , 'total' => $amount |
| 756 | , 'bt_address' => "" | 785 | , 'bt_address' => get_user_meta($uid, $pp.'address', true) |
| 757 | , 'bt_address2' => "" | 786 | , 'bt_address2' => get_user_meta($uid, $pp.'address2', true) |
| 758 | , 'bt_city' => "" | 787 | , 'bt_city' => get_user_meta($uid, $pp.'city', true) |
| 759 | , 'bt_province' => "" | 788 | , 'bt_province' => get_user_meta($uid, $pp.'province', true) |
| 760 | , 'bt_country' => "" | 789 | , 'bt_country' => get_user_meta($uid, $pp.'country', true) |
| 761 | , 'bt_postal' => "" | 790 | , 'bt_postal' => get_user_meta($uid, $pp.'postal', true) |
| 762 | , 'bt_card_holder' => "" | 791 | , 'bt_card_holder' => "" |
| 763 | , 'bt_card_number' => "" | 792 | , 'bt_card_number' => "" |
| 764 | , 'bt_card_type' => $paid_by | 793 | , 'bt_card_type' => $paid_by | ... | ... |
| ... | @@ -29,19 +29,20 @@ use WP_User; | ... | @@ -29,19 +29,20 @@ use WP_User; |
| 29 | <table width="100%" style="margin-top:10px;"> | 29 | <table width="100%" style="margin-top:10px;"> |
| 30 | <tbody> | 30 | <tbody> |
| 31 | <tr> | 31 | <tr> |
| 32 | <td width="130">Description</td> | 32 | <td width="130">Type</td> |
| 33 | <td><input type="text" name="title" style="width:400px" /></td> | ||
| 34 | </tr> | ||
| 35 | <tr> | ||
| 36 | <td>Type</td> | ||
| 37 | <td> | 33 | <td> |
| 38 | <select name="invoice_type" id="invoice_type"> | 34 | <select name="invoice_type" id="invoice_type"> |
| 39 | <option value="invoice">Invoice</option> | 35 | <option value="invoice">Invoice</option> |
| 36 | <option value="membership">Membership Fees</option> | ||
| 40 | <option value="credit">Credit Note</option> | 37 | <option value="credit">Credit Note</option> |
| 41 | </select> | 38 | </select> |
| 42 | </td> | 39 | </td> |
| 43 | </tr> | 40 | </tr> |
| 44 | <tr> | 41 | <tr class="invoice_credit_only"> |
| 42 | <td>Description</td> | ||
| 43 | <td><input type="text" name="title" style="width:400px" /></td> | ||
| 44 | </tr> | ||
| 45 | <tr class="invoice_credit_only"> | ||
| 45 | <td>Amount ($)</td> | 46 | <td>Amount ($)</td> |
| 46 | <td><input type="text" name="amount" /></td> | 47 | <td><input type="text" name="amount" /></td> |
| 47 | </tr> | 48 | </tr> |
| ... | @@ -91,207 +92,7 @@ use WP_User; | ... | @@ -91,207 +92,7 @@ use WP_User; |
| 91 | 92 | ||
| 92 | //$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>'; | 93 | //$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>'; |
| 93 | 94 | ||
| 94 | $html .= '<div style="border:1px solid #777;padding:20px;position:relative;" id="viewable-port">'; | 95 | $html .= Invoice\DrawInvoice($invoice,true); |
| 95 | |||
| 96 | $status = get_post_meta($invoice->ID,'trans_status',true); | ||
| 97 | |||
| 98 | $html .= '<p> | ||
| 99 | <img src="/wp-content/themes/cbv/assets/images/logo.gif" width="114" height="92" /></p><p> | ||
| 100 | <strong>The Canadian Institute of Chartered Business Valuators</strong><br /> | ||
| 101 | 277 Wellington St. West, Suite 710<br /> | ||
| 102 | Toronto, ON, Canada M5V 3H2 | ||
| 103 | </p>'; | ||
| 104 | |||
| 105 | if ($status == 'unpaid') { | ||
| 106 | // Get the user's profile preference | ||
| 107 | $preference = strtolower($user->profile_preference); | ||
| 108 | |||
| 109 | // Build the 'Bill To:' info array | ||
| 110 | $user_fields = array('address', 'address2', 'city', 'province', 'country', 'postal'); | ||
| 111 | $bill_to = array(); | ||
| 112 | foreach ($user_fields as $field) { | ||
| 113 | // Use the preference to get the user's address info | ||
| 114 | $bill_to[$field] = get_user_meta($user->ID, "{$preference}_{$field}", TRUE); | ||
| 115 | } | ||
| 116 | // Finish it off with first and last name | ||
| 117 | $bill_to['first_name'] = get_user_meta($user->ID, 'first_name', TRUE); | ||
| 118 | $bill_to['last_name'] = get_user_meta($user->ID, 'last_name', TRUE); | ||
| 119 | |||
| 120 | // Now build the html | ||
| 121 | $html .= '<p><br /><h3>BILL TO:</h3>'; | ||
| 122 | $html .= "{$bill_to['first_name']} {$bill_to['last_name']}<br />"; | ||
| 123 | $html .= "{$bill_to['address']}, {$bill_to['address2']}<br />"; | ||
| 124 | $html .= "{$bill_to['city']}, {$bill_to['province']}, {$bill_to['country']} {$bill_to['postal']}</p>"; | ||
| 125 | } | ||
| 126 | |||
| 127 | $html .= '<h3 style="margin:0;padding:0;text-align:right;">Invoice No.: '.$invoice->ID.'</h3>'; | ||
| 128 | $html .= '<p style="text-align:right;margin-top:0;padding-top:0;"><strong>Invoice Date:</strong> '.$date.'</p>'; | ||
| 129 | $html .= '<h2>'.$invoice->post_title.'</h2>'; | ||
| 130 | |||
| 131 | $invoice_type = get_post_meta($invoice->ID, 'invoice_for', true); | ||
| 132 | |||
| 133 | $html .= '<p>'; | ||
| 134 | $html .= '<table cellpadding="0" cellspacing="0" border="0" class="invoice-table">'; | ||
| 135 | $html .= '<thead>'; | ||
| 136 | $html .= '<tr>'; | ||
| 137 | $html .= '<th>Item / Description</th>'; | ||
| 138 | |||
| 139 | //if ($status!="credit") { | ||
| 140 | $html .= '<th width="80">Cost</th>'; | ||
| 141 | $html .= '<th width="80">Discounts</th>'; | ||
| 142 | $html .= '<th width="120">Amount</th>'; | ||
| 143 | //} else { | ||
| 144 | //$html .= '<th width="120">Credit</th>'; | ||
| 145 | //} | ||
| 146 | |||
| 147 | $html .= '</tr>'; | ||
| 148 | $html .= '</thead>'; | ||
| 149 | $html .= '<tbody>'; | ||
| 150 | $i = 9; | ||
| 151 | foreach($invoice->items as $item) { | ||
| 152 | $row_class = ($i%2) ? "odd" : ""; | ||
| 153 | |||
| 154 | if ( $item['post_id'] > 0 ) { | ||
| 155 | $post = get_post($item['post_id']); | ||
| 156 | $description = $item['description']; | ||
| 157 | |||
| 158 | if ($post->post_type=="events") { | ||
| 159 | $event_term_slugs = array(); | ||
| 160 | $terms = get_the_terms($item['post_id'],'event_type'); | ||
| 161 | if (!empty($terms)) { | ||
| 162 | foreach($terms as $types) { | ||
| 163 | $event_term_slugs[$types->slug] = $types->name; | ||
| 164 | } | ||
| 165 | } | ||
| 166 | |||
| 167 | } | ||
| 168 | |||
| 169 | if ( isset($event_term_slugs['webinar']) ) { | ||
| 170 | $description = $post->post_title . " | " . date("M d, Y",get_post_meta($item['post_id'],'event_date',true)); | ||
| 171 | } else { | ||
| 172 | $description = $post->post_title . " | " . get_post_meta($item['post_id'],'location',true); | ||
| 173 | } | ||
| 174 | |||
| 175 | if ( count($item['discounts']) > 0 ) { | ||
| 176 | $item['discount_amount'] = ""; | ||
| 177 | |||
| 178 | $discount_text = "<br /><span>"; | ||
| 179 | for ($i=0; $i < count($item['discounts']); $i++) { | ||
| 180 | if ($i > 0) { $discount_text .= "<br />"; } | ||
| 181 | $discount_text .= "- $".$item['discounts'][$i]['discount']." OFF <em>".$item['discounts'][$i]['discount_label']."</em>"; | ||
| 182 | $item['discount_amount'] += $item['discounts'][$i]['discount']; | ||
| 183 | } | ||
| 184 | $discount_text .= "</span>"; | ||
| 185 | $description = "<strong>". $description ."</strong>".$discount_text; | ||
| 186 | } | ||
| 187 | |||
| 188 | |||
| 189 | |||
| 190 | } else { | ||
| 191 | $description = $item['description']; | ||
| 192 | } | ||
| 193 | |||
| 194 | $html .= '<tr>'; | ||
| 195 | $html .= '<td>'.$description.'</td>'; | ||
| 196 | |||
| 197 | //if ($status!="credit") { | ||
| 198 | $html .= '<td>$'.$item['cost'].'</td>'; | ||
| 199 | if (empty($item['discount_amount'])) { | ||
| 200 | $html .= '<td>$0.00</td>'; | ||
| 201 | } else { | ||
| 202 | $html .= '<td>-$'.$item['discount_amount'].'</td>'; | ||
| 203 | } | ||
| 204 | |||
| 205 | //} | ||
| 206 | $html .= '<td>$'.$item['subtotal'].'</td>'; | ||
| 207 | |||
| 208 | |||
| 209 | $html .= '</tr>'; | ||
| 210 | $i++; | ||
| 211 | } | ||
| 212 | $html .= '</tbody>'; | ||
| 213 | $html .= '</table>'; | ||
| 214 | //if ($status != "credit") { | ||
| 215 | $html .= '<table cellpadding="0" cellspacing="0" border="0" class="clean invoice-table">'; | ||
| 216 | |||
| 217 | $html .= '<tfoot>'; | ||
| 218 | |||
| 219 | |||
| 220 | $html .= '<tr>'; | ||
| 221 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Total Cost</td>'; | ||
| 222 | $html .= '<td width="120">$'.number_format($invoice->payment['total_cost'],2).'</td>'; | ||
| 223 | $html .= '</tr>'; | ||
| 224 | if ($invoice->payment['total_discounts'] > 0) { | ||
| 225 | $html .= '<tr>'; | ||
| 226 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Total Discounts</td>'; | ||
| 227 | $html .= '<td>$'.number_format($invoice->payment['total_discounts'],2).'</td>'; | ||
| 228 | $html .= '</tr>'; | ||
| 229 | $html .= '<tr>'; | ||
| 230 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Sub Total</td>'; | ||
| 231 | $html .= '<td>$'.number_format($invoice->payment['subtotal'],2).'</td>'; | ||
| 232 | $html .= '</tr>'; | ||
| 233 | } | ||
| 234 | if ($invoice->payment['total_taxes'] > 0) { | ||
| 235 | |||
| 236 | $html .= '<tr>'; | ||
| 237 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Taxes</td>'; | ||
| 238 | $html .= '<td>$'.number_format($invoice->payment['total_taxes'],2).'</td>'; | ||
| 239 | $html .= '</tr>'; | ||
| 240 | |||
| 241 | } | ||
| 242 | |||
| 243 | $amount = $invoice->payment['total']; | ||
| 244 | |||
| 245 | $credit = get_post_meta($invoice->ID, 'credit_amount', true); | ||
| 246 | if ( !empty($credit) && $status == "credit" ) { | ||
| 247 | |||
| 248 | $html .= '<tr>'; | ||
| 249 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold; color:green;">Credit</td>'; | ||
| 250 | $html .= '<td style="color:green;">-$'.number_format($credit,2).'</td>'; | ||
| 251 | $html .= '</tr>'; | ||
| 252 | |||
| 253 | |||
| 254 | $amount = ($amount - $credit); | ||
| 255 | } | ||
| 256 | |||
| 257 | $amount_label = ($status=="unpaid") ? "Amount Due" : "Total"; | ||
| 258 | |||
| 259 | |||
| 260 | |||
| 261 | $html .= '<tr>'; | ||
| 262 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">'.$amount_label.'</td>'; | ||
| 263 | $html .= '<td><strong>$'.number_format($amount,2).'</strong></td>'; | ||
| 264 | $html .= '</tr>'; | ||
| 265 | |||
| 266 | |||
| 267 | $html .= '</tfoot>'; | ||
| 268 | $html .= '</table>'; | ||
| 269 | //} | ||
| 270 | $html .= '</p>'; | ||
| 271 | |||
| 272 | $html .= (!empty($invoice->payment['bt_card_holder'])) ? '<h3>BILLED TO:</h3>' : ""; | ||
| 273 | $html .= (!empty($invoice->payment['bt_card_holder'])) ? $invoice->payment['bt_card_holder']."<br />" : ""; | ||
| 274 | $html .= (!empty($invoice->payment['bt_address'])) ? $invoice->payment['bt_address']." ".$invoice->payment['bt_address2'] . "<br />" : ""; | ||
| 275 | $html .= (!empty($invoice->payment['bt_city'])) ? $invoice->payment['bt_city'].", " .$invoice->payment['bt_province']."<br />" : ""; | ||
| 276 | $html .= (!empty($invoice->payment['bt_country'])) ? $invoice->payment['bt_country']." ".$invoice->payment['bt_postal']."<br /><br />" : ""; | ||
| 277 | $html .= (!empty($invoice->payment['bt_card_type'])) ? "Paid using: <strong>".CBV\get_payment_string($invoice->payment['bt_card_type'])."</strong> " . $invoice->payment['bt_card_number'] : ""; | ||
| 278 | |||
| 279 | //if ($status != "credit") { | ||
| 280 | $html .= '<p>GST/HST# R108075334</p>'; | ||
| 281 | //} | ||
| 282 | |||
| 283 | if ( $status == "paid" ) { | ||
| 284 | $html .= '<div style="text-align:center; font-size:14px; color:green;">-- <strong>PAID</strong> --</div>'; | ||
| 285 | } elseif ( $status == "unpaid" ) { | ||
| 286 | $html .= '<div style="text-align:center; font-size:14px; color:red;">-- THIS INVOICE IS <strong>UNPAID</strong> --</div>'; | ||
| 287 | } elseif ( $status == "credit" ) { | ||
| 288 | $html .= '<div style="text-align:center; font-size:14px; color:green;">-- <strong>CREDIT NOTE</strong> --</div>'; | ||
| 289 | } elseif ( $status == "cancelled" ) { | ||
| 290 | $html .= '<div style="text-align:center; font-size:14px; color:green;">-- THIS INVOICE IS <strong>CANCELLED</strong> --</div>'; | ||
| 291 | } | ||
| 292 | |||
| 293 | |||
| 294 | $html .= '</div>'; | ||
| 295 | 96 | ||
| 296 | //$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>'; | 97 | //$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>'; |
| 297 | 98 | ... | ... |
-
Please register or sign in to post a comment