user manager invoice updates
Showing
3 changed files
with
112 additions
and
46 deletions
| ... | @@ -21,11 +21,27 @@ jQuery(function($) { | ... | @@ -21,11 +21,27 @@ jQuery(function($) { |
| 21 | ); | 21 | ); |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | $('#invoice_type').change(function() { | ||
| 25 | if ($('#invoice_type').val() == "invoice") { | ||
| 26 | $('.invoice_only').show(); | ||
| 27 | } else { | ||
| 28 | $('.invoice_only').hide(); | ||
| 29 | } | ||
| 30 | }); | ||
| 31 | |||
| 24 | jQuery('#creditNotBtn').click(function(e) { | 32 | jQuery('#creditNotBtn').click(function(e) { |
| 25 | jQuery('#credit_note').slideToggle('fast'); | 33 | jQuery('#credit_note').slideToggle('fast'); |
| 34 | |||
| 35 | var InvoiceType = $('#invoice_type'); | ||
| 36 | if (InvoiceType.val() == "invoice") { | ||
| 37 | $('.invoice_only').show(); | ||
| 38 | } else { | ||
| 39 | $('.invoice_only').hide(); | ||
| 40 | } | ||
| 41 | |||
| 26 | jQuery('#creditForm').ajaxForm({ | 42 | jQuery('#creditForm').ajaxForm({ |
| 27 | url: '/wp-admin/admin-ajax.php' | 43 | url: '/wp-admin/admin-ajax.php' |
| 28 | , data: ({ajax:"yes", action: 'add_credit_note'}) | 44 | , data: ({ajax:"yes", action: 'create_invoice_note'}) |
| 29 | , dateType: 'json' | 45 | , dateType: 'json' |
| 30 | , type: 'POST' | 46 | , type: 'POST' |
| 31 | , success: function(data) { | 47 | , success: function(data) { | ... | ... |
| ... | @@ -678,12 +678,27 @@ class Actions { | ... | @@ -678,12 +678,27 @@ class Actions { |
| 678 | die(json_encode($return)); | 678 | die(json_encode($return)); |
| 679 | } | 679 | } |
| 680 | 680 | ||
| 681 | public static function wp_ajax_add_credit_note() { | 681 | public static function wp_ajax_create_invoice_note() { |
| 682 | global $wpdb; | ||
| 683 | |||
| 682 | $uid = $_POST['uid']; | 684 | $uid = $_POST['uid']; |
| 685 | $amount = $_POST['amount']; | ||
| 686 | $invoice_type = $_POST['invoice_type']; | ||
| 687 | $paid_by = $_POST['paid_by']; | ||
| 683 | $title = $_POST['title']; | 688 | $title = $_POST['title']; |
| 684 | $amount = "-".$_POST['amount']; | ||
| 685 | 689 | ||
| 686 | global $wpdb; | 690 | if ($invoice_type=="credit") { |
| 691 | $amount = "-".$amount; | ||
| 692 | } | ||
| 693 | |||
| 694 | $paid = isset($_POST['paid']) ? true : false; | ||
| 695 | if ($invoice_type=="invoice") { | ||
| 696 | if (!$paid) { | ||
| 697 | $paid_by = ""; | ||
| 698 | } | ||
| 699 | } else { | ||
| 700 | $paid_by = ""; | ||
| 701 | } | ||
| 687 | 702 | ||
| 688 | 703 | ||
| 689 | $items = array(); | 704 | $items = array(); |
| ... | @@ -692,18 +707,17 @@ class Actions { | ... | @@ -692,18 +707,17 @@ class Actions { |
| 692 | 'post_id' => 0 | 707 | 'post_id' => 0 |
| 693 | , 'cost' => $amount | 708 | , 'cost' => $amount |
| 694 | , 'discount_label' => "" | 709 | , 'discount_label' => "" |
| 695 | , 'discount_amount' => "" | 710 | , 'discount_amount' => 0 |
| 696 | , 'tax_label' => "" | 711 | , 'tax_label' => "" |
| 697 | , 'tax_rate' => "" | 712 | , 'tax_rate' => "" |
| 698 | , 'tax_amount' => "" | 713 | , 'tax_amount' => "0.00" |
| 699 | , 'subtotal' => $amount | 714 | , 'subtotal' => $amount |
| 700 | , 'total' => $amount | 715 | , 'total' => $amount |
| 701 | , 'description' => "Credit Note" | 716 | , 'description' => $title |
| 702 | , 'extras' => array() | 717 | , 'extras' => array() |
| 703 | 718 | ||
| 704 | ); | 719 | ); |
| 705 | 720 | ||
| 706 | |||
| 707 | $invoice_data = array(); | 721 | $invoice_data = array(); |
| 708 | $invoice_data['items'] = $items; | 722 | $invoice_data['items'] = $items; |
| 709 | $invoice_data['payment'] = array( | 723 | $invoice_data['payment'] = array( |
| ... | @@ -720,29 +734,23 @@ class Actions { | ... | @@ -720,29 +734,23 @@ class Actions { |
| 720 | , 'bt_postal' => "" | 734 | , 'bt_postal' => "" |
| 721 | , 'bt_card_holder' => "" | 735 | , 'bt_card_holder' => "" |
| 722 | , 'bt_card_number' => "" | 736 | , 'bt_card_number' => "" |
| 723 | , 'bt_card_type' => "" | 737 | , 'bt_card_type' => $paid_by |
| 724 | ); | 738 | ); |
| 725 | 739 | ||
| 726 | 740 | ||
| 727 | 741 | ||
| 728 | Invoice\create($invoice_data, 'credit', $title, $uid, 'credit', 'publish', $amount); | 742 | if ($invoice_type=="credit") { |
| 729 | 743 | $status = "credit"; | |
| 730 | // return json object | 744 | } else { |
| 731 | $return = array( | 745 | $paid = isset($_POST['paid']) ? true : false; |
| 732 | 'success' => 'true' | 746 | if ($paid) { |
| 733 | ); | 747 | $status = "paid"; |
| 734 | die(json_encode($return)); | 748 | } else { |
| 749 | $status = "unpaid"; | ||
| 750 | } | ||
| 735 | } | 751 | } |
| 736 | 752 | ||
| 737 | public static function wp_ajax_post_credit() { | 753 | Invoice\create($invoice_data, 'generic', $title, $uid, $status, 'publish', $amount); |
| 738 | |||
| 739 | $uid = $_POST['uid']; | ||
| 740 | $post_id = $_POST['event_id']; // could be an event, or a course. | ||
| 741 | $amount = $_POST['amount']; | ||
| 742 | |||
| 743 | |||
| 744 | // post credit to their account. | ||
| 745 | |||
| 746 | 754 | ||
| 747 | // return json object | 755 | // return json object |
| 748 | $return = array( | 756 | $return = array( |
| ... | @@ -753,7 +761,6 @@ class Actions { | ... | @@ -753,7 +761,6 @@ class Actions { |
| 753 | } | 761 | } |
| 754 | 762 | ||
| 755 | 763 | ||
| 756 | |||
| 757 | public static function wp_ajax_update_registration() { | 764 | public static function wp_ajax_update_registration() { |
| 758 | 765 | ||
| 759 | CBV\load('Events'); | 766 | CBV\load('Events'); | ... | ... |
| ... | @@ -15,10 +15,9 @@ use Exception, StdClass; | ... | @@ -15,10 +15,9 @@ use Exception, StdClass; |
| 15 | use WP_User; | 15 | use WP_User; |
| 16 | ?> | 16 | ?> |
| 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 | <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> | 18 | <h2 style="margin-bottom:10px;padding-bottom:0px;">Users' Payment History... |
| 19 | <h2 style="margin-bottom:10px;padding-bottom:0px;">Users' Invoices... | ||
| 20 | <?php if (!isset($_GET['view'])):?> | 19 | <?php if (!isset($_GET['view'])):?> |
| 21 | <a href="#" class="button add-new-h2" id="creditNotBtn">Creat new Invoice</a> | 20 | <a href="#" class="button add-new-h2" id="creditNotBtn">Creat new Invoice/Credit Note</a> |
| 22 | <?php endif; ?> | 21 | <?php endif; ?> |
| 23 | </h2> | 22 | </h2> |
| 24 | 23 | ||
| ... | @@ -26,19 +25,44 @@ use WP_User; | ... | @@ -26,19 +25,44 @@ use WP_User; |
| 26 | <div style="border:1px solid #e8e8e8; background-color:#f5f5f5;padding:10px;"> | 25 | <div style="border:1px solid #e8e8e8; background-color:#f5f5f5;padding:10px;"> |
| 27 | <form id="creditForm" method="POST"> | 26 | <form id="creditForm" method="POST"> |
| 28 | <input type="hidden" name="uid" value="<?php echo $_GET['uid']; ?>" /> | 27 | <input type="hidden" name="uid" value="<?php echo $_GET['uid']; ?>" /> |
| 29 | <h3 style="margin:0;padding:0;">Invoice...</h3> | 28 | <h3 style="margin:0;padding:0;">Invoice/Credit Note...</h3> |
| 30 | <table width="100%" style="margin-top:10px;"> | 29 | <table width="100%" style="margin-top:10px;"> |
| 31 | <tbody> | 30 | <tbody> |
| 32 | <tr> | 31 | <tr> |
| 33 | <td width="130">Invoice Description</td> | 32 | <td width="130">Description</td> |
| 34 | <td><input type="text" name="title" style="width:400px" /></td> | 33 | <td><input type="text" name="title" style="width:400px" /></td> |
| 35 | </tr> | 34 | </tr> |
| 36 | <tr> | 35 | <tr> |
| 37 | <td width="130">Amount ($)</td> | 36 | <td>Type</td> |
| 37 | <td> | ||
| 38 | <select name="invoice_type" id="invoice_type"> | ||
| 39 | <option value="invoice">Invoice</option> | ||
| 40 | <option value="credit">Credit Note</option> | ||
| 41 | </select> | ||
| 42 | </td> | ||
| 43 | </tr> | ||
| 44 | <tr> | ||
| 45 | <td>Amount ($)</td> | ||
| 38 | <td><input type="text" name="amount" /></td> | 46 | <td><input type="text" name="amount" /></td> |
| 39 | </tr> | 47 | </tr> |
| 48 | <tr class="invoice_only"> | ||
| 49 | <td>Paid?</td> | ||
| 50 | <td><input type="checkbox" name="paid" value="on" /></td> | ||
| 51 | </tr> | ||
| 52 | <tr class="invoice_only"> | ||
| 53 | <td>Paid By</td> | ||
| 54 | <td> | ||
| 55 | <select name="paid_by"> | ||
| 56 | <option value="">(none)</option> | ||
| 57 | <option value="visa">Visa</option> | ||
| 58 | <option value="mc">Mastercard</option> | ||
| 59 | <option value="amex">American Express</option> | ||
| 60 | <option value="cheque">Cheque</option> | ||
| 61 | </select> | ||
| 62 | </td> | ||
| 63 | </tr> | ||
| 40 | <tr> | 64 | <tr> |
| 41 | <td colspan="4" style="padding-top:5px;"><input type="submit" value="Apply Invoice" /></td> | 65 | <td colspan="4" style="padding-top:5px;"><input type="submit" value="Apply Invoice/Credit Note" /></td> |
| 42 | </tr> | 66 | </tr> |
| 43 | </tbody> | 67 | </tbody> |
| 44 | </table> | 68 | </table> |
| ... | @@ -69,18 +93,16 @@ use WP_User; | ... | @@ -69,18 +93,16 @@ use WP_User; |
| 69 | 93 | ||
| 70 | $html .= '<div style="border:1px solid #777;padding:20px;position:relative;" id="viewable-port">'; | 94 | $html .= '<div style="border:1px solid #777;padding:20px;position:relative;" id="viewable-port">'; |
| 71 | 95 | ||
| 72 | $html .= ' | 96 | $status = get_post_meta($invoice->ID,'trans_status',true); |
| 73 | <p><img src="/wp-content/themes/cbv/assets/images/logo.gif" width="114" height="92" /></p> | 97 | |
| 74 | <p><strong>The Canadian Institute of Chartered Business Valuators</strong><br /> | 98 | |
| 99 | $html .= '<p> | ||
| 100 | <img src="/wp-content/themes/cbv/assets/images/logo.gif" width="114" height="92" /></p><p> | ||
| 101 | <strong>The Canadian Institute of Chartered Business Valuators</strong><br /> | ||
| 75 | 277 Wellington St. West, Suite 710<br /> | 102 | 277 Wellington St. West, Suite 710<br /> |
| 76 | Toronto, ON, Canada M5V 3H2 | 103 | Toronto, ON, Canada M5V 3H2 |
| 77 | </p>'; | 104 | </p>'; |
| 78 | 105 | ||
| 79 | $status = get_post_meta($invoice->ID,'trans_status',true); | ||
| 80 | if ($status=="paid") { | ||
| 81 | $html .= '<div class="status-paid"></div>'; | ||
| 82 | } | ||
| 83 | |||
| 84 | $html .= '<h3 style="margin:0;padding:0;text-align:right;">Invoice No.: '.$invoice->ID.'</h3>'; | 106 | $html .= '<h3 style="margin:0;padding:0;text-align:right;">Invoice No.: '.$invoice->ID.'</h3>'; |
| 85 | $html .= '<p style="text-align:right;margin-top:0;padding-top:0;"><strong>Invoice Date:</strong> '.$date.'</p>'; | 107 | $html .= '<p style="text-align:right;margin-top:0;padding-top:0;"><strong>Invoice Date:</strong> '.$date.'</p>'; |
| 86 | $html .= '<h2>'.$invoice->post_title.'</h2>'; | 108 | $html .= '<h2>'.$invoice->post_title.'</h2>'; |
| ... | @@ -93,7 +115,7 @@ use WP_User; | ... | @@ -93,7 +115,7 @@ use WP_User; |
| 93 | $html .= '<tr>'; | 115 | $html .= '<tr>'; |
| 94 | $html .= '<th>Item / Description</th>'; | 116 | $html .= '<th>Item / Description</th>'; |
| 95 | 117 | ||
| 96 | if ($invoice_type!="credit") { | 118 | if ($status!="credit") { |
| 97 | $html .= '<th width="80">Cost</th>'; | 119 | $html .= '<th width="80">Cost</th>'; |
| 98 | $html .= '<th width="80">Discounts</th>'; | 120 | $html .= '<th width="80">Discounts</th>'; |
| 99 | $html .= '<th width="120">Amount</th>'; | 121 | $html .= '<th width="120">Amount</th>'; |
| ... | @@ -119,7 +141,7 @@ use WP_User; | ... | @@ -119,7 +141,7 @@ use WP_User; |
| 119 | $html .= '<tr class="'.$row_class.'">'; | 141 | $html .= '<tr class="'.$row_class.'">'; |
| 120 | $html .= '<td>'.$description.'</td>'; | 142 | $html .= '<td>'.$description.'</td>'; |
| 121 | 143 | ||
| 122 | if ($invoice_type!="credit") { | 144 | if ($status!="credit") { |
| 123 | $html .= '<td>$'.$item['cost'].'</td>'; | 145 | $html .= '<td>$'.$item['cost'].'</td>'; |
| 124 | if (empty($item['discount_amount'])) { | 146 | if (empty($item['discount_amount'])) { |
| 125 | $html .= '<td>$0.00</td>'; | 147 | $html .= '<td>$0.00</td>'; |
| ... | @@ -136,11 +158,12 @@ use WP_User; | ... | @@ -136,11 +158,12 @@ use WP_User; |
| 136 | } | 158 | } |
| 137 | $html .= '</tbody>'; | 159 | $html .= '</tbody>'; |
| 138 | $html .= '</table>'; | 160 | $html .= '</table>'; |
| 139 | if ($invoice_type != "credit") { | 161 | if ($status != "credit") { |
| 140 | $html .= '<table cellpadding="0" cellspacing="0" border="0" class="clean" id="invoice-table">'; | 162 | $html .= '<table cellpadding="0" cellspacing="0" border="0" class="clean" id="invoice-table">'; |
| 141 | 163 | ||
| 142 | $html .= '<tfoot>'; | 164 | $html .= '<tfoot>'; |
| 143 | 165 | ||
| 166 | |||
| 144 | $html .= '<tr>'; | 167 | $html .= '<tr>'; |
| 145 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Total Cost</td>'; | 168 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Total Cost</td>'; |
| 146 | $html .= '<td width="120">$'.number_format($invoice->payment['total_cost'],2).'</td>'; | 169 | $html .= '<td width="120">$'.number_format($invoice->payment['total_cost'],2).'</td>'; |
| ... | @@ -155,12 +178,19 @@ use WP_User; | ... | @@ -155,12 +178,19 @@ use WP_User; |
| 155 | $html .= '<td>$'.number_format($invoice->payment['subtotal'],2).'</td>'; | 178 | $html .= '<td>$'.number_format($invoice->payment['subtotal'],2).'</td>'; |
| 156 | $html .= '</tr>'; | 179 | $html .= '</tr>'; |
| 157 | } | 180 | } |
| 181 | if ($invoice->payment['total_taxes'] > 0) { | ||
| 182 | |||
| 158 | $html .= '<tr>'; | 183 | $html .= '<tr>'; |
| 159 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Taxes</td>'; | 184 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Taxes</td>'; |
| 160 | $html .= '<td>$'.number_format($invoice->payment['total_taxes'],2).'</td>'; | 185 | $html .= '<td>$'.number_format($invoice->payment['total_taxes'],2).'</td>'; |
| 161 | $html .= '</tr>'; | 186 | $html .= '</tr>'; |
| 187 | |||
| 188 | } | ||
| 189 | |||
| 190 | $amount_label = ($status=="paid") ? "Total" : "Amount Due"; | ||
| 191 | |||
| 162 | $html .= '<tr>'; | 192 | $html .= '<tr>'; |
| 163 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">Total</td>'; | 193 | $html .= '<td style="text-align:right;padding-right:10px;font-weight:bold;">'.$amount_label.'</td>'; |
| 164 | $html .= '<td><strong>$'.number_format($invoice->payment['total'],2).'</strong></td>'; | 194 | $html .= '<td><strong>$'.number_format($invoice->payment['total'],2).'</strong></td>'; |
| 165 | $html .= '</tr>'; | 195 | $html .= '</tr>'; |
| 166 | 196 | ||
| ... | @@ -170,7 +200,7 @@ use WP_User; | ... | @@ -170,7 +200,7 @@ use WP_User; |
| 170 | } | 200 | } |
| 171 | $html .= '</p>'; | 201 | $html .= '</p>'; |
| 172 | 202 | ||
| 173 | if ($invoice_type != "credit") { | 203 | if ($status != "credit" && $invoice->payment['bt_address'] != "" && $invoice->payment['bt_card_holder'] != "") { |
| 174 | $html .= '<h3>BILLED TO:</h3>'; | 204 | $html .= '<h3>BILLED TO:</h3>'; |
| 175 | $html .= $invoice->payment['bt_card_holder']."<br />"; | 205 | $html .= $invoice->payment['bt_card_holder']."<br />"; |
| 176 | $html .= $invoice->payment['bt_address']." ".$invoice->payment['bt_address2'] . "<br />"; | 206 | $html .= $invoice->payment['bt_address']." ".$invoice->payment['bt_address2'] . "<br />"; |
| ... | @@ -179,6 +209,19 @@ use WP_User; | ... | @@ -179,6 +209,19 @@ use WP_User; |
| 179 | $html .= "<strong>".ucwords($invoice->payment['bt_card_type'])."</strong> " . $invoice->payment['bt_card_number']; | 209 | $html .= "<strong>".ucwords($invoice->payment['bt_card_type'])."</strong> " . $invoice->payment['bt_card_number']; |
| 180 | } | 210 | } |
| 181 | 211 | ||
| 212 | if ($status != "credit") { | ||
| 213 | $html .= '<p>GST/HST# R108075334</p>'; | ||
| 214 | } | ||
| 215 | |||
| 216 | if ( $status == "paid" ) { | ||
| 217 | $html .= '<div style="text-align:center; font-size:14px; color:green;">-- <strong>PAID</strong> --</div>'; | ||
| 218 | } elseif ( $status == "unpaid" ) { | ||
| 219 | $html .= '<div style="text-align:center; font-size:14px; color:red;">-- THIS INVOICE IS <strong>UNPAID</strong> --</div>'; | ||
| 220 | } elseif ( $status == "credit" ) { | ||
| 221 | $html .= '<div style="text-align:center; font-size:14px; color:green;">-- <strong>CREDIT NOTE</strong> --</div>'; | ||
| 222 | } | ||
| 223 | |||
| 224 | |||
| 182 | $html .= '</div>'; | 225 | $html .= '</div>'; |
| 183 | 226 | ||
| 184 | //$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>'; | 227 | //$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>'; | ... | ... |
-
Please register or sign in to post a comment