4de1fc4e by Marty Penner

Fixed previous bad commit (forgot to svn add the file)

1 parent 98cf0d3d
1 <?php
2 namespace Tz\WordPress\Tools\UserManager;
3
4 use Tz, Tz\Common;
5 use Tz\WordPress\CBV;
6 use Tz\WordPress\CBV\User;
7 use Tz\WordPress\UAM;
8 use Tz\WordPress\Tools;
9 use Tz\WordPress\Tools\Auth;
10 use Exception, StdClass;
11 use WP_User;
12
13 global $wpdb;
14
15 // Get the original timezone (so we can set it back) and figure out the
16 // timestamp for March 1 UTC
17 $original_timezone = date_default_timezone_get();
18 date_default_timezone_set('UTC');
19 $begin_date = strtotime('March 1');
20 // Set the timezone back to original setting
21 date_default_timezone_set($original_timezone);
22
23 if (! empty($_POST['do_fix']) && $_POST['do_fix'] == 'y') {
24 $users = $wpdb->get_results("SELECT ID FROM {$wpdb->users} LIMIT 0,1000");
25 foreach ($users as $user) {
26 $invoices = get_user_meta($user->ID, 'invoices', TRUE);
27 foreach ($invoices as $invoice_id) {
28 // Get the transaction status
29 $trans_status = get_post_meta($invoice_id, 'trans_status', TRUE);
30 // Don't do anything unless the status is 'unpaid'
31 if ($trans_status != 'unpaid') {
32 continue;
33 }
34 // Get the invoice and check if it's newer than March 1 UTC
35 $invoice = get_post($invoice_id);
36 if (! strtotime($invoice->post_date) > $begin_date) {
37 continue;
38 }
39
40 // Here's the heavy work: get the payment data and add appropriate taxes
41 $payment = get_post_meta($invoice_id, 'payment', TRUE);
42 $trans_amount = get_post_meta($invoice_id, 'trans_amount', TRUE);
43
44 // Get the user's profile preference and use it to get the tax percent
45 if (! empty($user->profile_preference)) {
46 $preference = strtolower($user->profile_preference) . '_province';
47 $tax_percent = getTaxesByProvince($user->$preference) * .01;
48 } else {
49 $tax_percent = getTaxesByProvince($payment['bt_province']) * .01;
50 }
51
52
53 $payment['total_taxes'] = $payment['total_cost'] * $tax_percent;
54 $payment['total'] = number_format($payment['total_cost'] - $payment['total_discounts'] + $payment['total_taxes'], 2);
55 $trans_amount = $payment['total'];
56
57 // Now update the post
58 update_post_meta($invoice_id, 'payment', $payment);
59 update_post_meta($invoice_id, 'trans_amount', $trans_amount);
60 }
61 }
62 }
63
64 ?>
65 <style>
66
67 h4 {
68 float: left;
69 padding-right: 1em;
70 }
71
72 .merge-users {
73 float: left;
74 padding-right: 2em;
75 }
76
77 .merge-users label {
78 float: left;
79 font-weight: bold;
80 padding-right: 1em;
81 }
82
83 .merge-users input {
84 float: left;
85 }
86
87 .clear {
88 float: left;
89 clear: both;
90 }
91
92 .user-list, .user-list li {
93 float: left;
94 clear: both;
95 }
96
97 .changed {
98 margin-top: 5px;
99 clear: both;
100 display: none;
101 }
102
103 .changed h6 {
104 padding: 0px;
105 margin: 0px 0px 10px 0px;
106 font-size: 11px;
107 text-transform: uppercase;
108 }
109
110 .changed ul {
111 margin: 0;
112 padding: 0;
113 }
114
115 .changed ul li {
116 margin: 0px 0px 3px 0px;
117 padding: 0px;
118 font-size: 11px;
119 background: none;
120 }
121 .merge-table td { padding:10px;}
122 </style>
123
124 <div class="wrap">
125
126 <div id="icon-users" class="icon32"><br /></div>
127 <h2>Fix Unpaid Invoices</h2>
128
129 <div class="validation-errors" style="display:none; margin: 10px 0px 10px;">
130 <div class="error-wrap">
131 <ul></ul>
132 </div>
133 </div>
134
135 <div id="post-body" style="padding:10px 0px 15px 0px;">
136 <form method="post" id="fix_unpaid_invoices">
137 <!--<table cellspacing="0" class="widefat post fixed merge-table">
138 <thead>
139 <tr>
140 <th width="50%"><label for="search_user_from">Merge <strong><em>FROM</em></strong> User:</label></th>
141 <th width="50%"><label for="search_user_to">Merge <strong><em>TO</em></strong> User:</label></th>
142 </tr>
143 </thead>
144 <tbody>
145 <tr>
146 <td>
147 <div class="merge-users">
148 <input class="clear" type="text" name="search_user_from" value="<?php echo $_POST['search_user_from'] ?>" />
149 <input type="button" name="btn_user_from" value="Search" />&nbsp;<img id="search_user_from_spinner" class="spinners" src="/wp-content/tz-tools/com/Branding/images/spinner.gif" style="display:none;" />
150
151 </div>
152 </td>
153 <td>
154 <div class="merge-users">
155 <input class="clear" type="text" name="search_user_to" value="<?php echo $_POST['search_user_to'] ?>" />
156 <input type="button" name="btn_user_to" value="Search" />&nbsp;<img id="search_user_to_spinner" class="spinners" src="/wp-content/tz-tools/com/Branding/images/spinner.gif" style="display:none;" />
157 </div>
158 </td>
159 </tr>
160 <tr>
161 <td><div id="user-list-from"></div></td>
162 <td><div id="user-list-to"></div></td>
163 </tr>
164 </tbody>
165 </table>-->
166
167 <div id="field-list" class="changed">
168 <table cellspacing="0" class="widefat post fixed merge-table"></table>
169 </div>
170
171 <div style="clear:both;"></div>
172
173 <div style="margin-top:10px;">
174 <input type="hidden" name="do_fix" value="y" />
175 <input type="submit" value="Do It" />
176 </div>
177
178 </form>
179
180 </div>
181
182 </div>