Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Tenzing
/
Tz Tools
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
ee92c36e
authored
2011-03-17 14:33:31 +0000
by
Chris Boden
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Fixed loop on invoice fix
1 parent
3624166b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
38 deletions
com/UserManager/views/fix_unpaid.php
com/UserManager/views/fix_unpaid.php
View file @
ee92c36
...
...
@@ -21,44 +21,51 @@ $begin_date = strtotime('March 1');
date_default_timezone_set
(
$original_timezone
);
if
(
!
empty
(
$_POST
[
'do_fix'
])
&&
$_POST
[
'do_fix'
]
==
'y'
)
{
$users
=
$wpdb
->
get_results
(
"SELECT ID FROM
{
$wpdb
->
users
}
LIMIT 0,1000"
);
foreach
(
$users
as
$user
)
{
$invoices
=
get_user_meta
(
$user
->
ID
,
'invoices'
,
TRUE
);
foreach
(
$invoices
as
$invoice_id
)
{
// Get the transaction status
$trans_status
=
get_post_meta
(
$invoice_id
,
'trans_status'
,
TRUE
);
// Don't do anything unless the status is 'unpaid'
if
(
$trans_status
!=
'unpaid'
)
{
continue
;
}
// Get the invoice and check if it's newer than March 1 UTC
$invoice
=
get_post
(
$invoice_id
);
if
(
!
strtotime
(
$invoice
->
post_date
)
>
$begin_date
)
{
continue
;
}
// Here's the heavy work: get the payment data and add appropriate taxes
$payment
=
get_post_meta
(
$invoice_id
,
'payment'
,
TRUE
);
$trans_amount
=
get_post_meta
(
$invoice_id
,
'trans_amount'
,
TRUE
);
// Get the user's profile preference and use it to get the tax percent
if
(
!
empty
(
$user
->
profile_preference
))
{
$preference
=
strtolower
(
$user
->
profile_preference
)
.
'_province'
;
$tax_percent
=
getTaxesByProvince
(
$user
->
$preference
)
*
.
01
;
}
else
{
$tax_percent
=
getTaxesByProvince
(
$payment
[
'bt_province'
])
*
.
01
;
}
$payment
[
'total_taxes'
]
=
$payment
[
'total_cost'
]
*
$tax_percent
;
$payment
[
'total'
]
=
number_format
(
$payment
[
'total_cost'
]
-
$payment
[
'total_discounts'
]
+
$payment
[
'total_taxes'
],
2
);
$trans_amount
=
$payment
[
'total'
];
// Now update the post
update_post_meta
(
$invoice_id
,
'payment'
,
$payment
);
update_post_meta
(
$invoice_id
,
'trans_amount'
,
$trans_amount
);
}
}
$count_result
=
mysql_query
(
"SELECT COUNT(*) FROM `
{
$wpdb
->
users
}
`"
,
$wpdb
->
dbh
);
list
(
$num
)
=
mysql_fetch_row
(
$count_result
);
$max
=
1000
;
for
(
$ui
=
0
;
$ui
<
$num
;
$ui
+=
$max
)
{
$users
=
$wpdb
->
get_results
(
"SELECT ID FROM `
{
$wpdb
->
users
}
` LIMIT
{
$ui
}
,
{
$max
}
"
);
foreach
(
$users
as
$user
)
{
$invoices
=
get_user_meta
(
$user
->
ID
,
'invoices'
,
TRUE
);
foreach
(
$invoices
as
$invoice_id
)
{
// Get the transaction status
$trans_status
=
get_post_meta
(
$invoice_id
,
'trans_status'
,
TRUE
);
// Don't do anything unless the status is 'unpaid'
if
(
$trans_status
!=
'unpaid'
)
{
continue
;
}
// Get the invoice and check if it's newer than March 1 UTC
$invoice
=
get_post
(
$invoice_id
);
if
(
!
strtotime
(
$invoice
->
post_date
)
>
$begin_date
)
{
continue
;
}
// Here's the heavy work: get the payment data and add appropriate taxes
$payment
=
get_post_meta
(
$invoice_id
,
'payment'
,
TRUE
);
$trans_amount
=
get_post_meta
(
$invoice_id
,
'trans_amount'
,
TRUE
);
// Get the user's profile preference and use it to get the tax percent
if
(
!
empty
(
$user
->
profile_preference
))
{
$preference
=
strtolower
(
$user
->
profile_preference
)
.
'_province'
;
$tax_percent
=
getTaxesByProvince
(
$user
->
$preference
)
*
.
01
;
}
else
{
$tax_percent
=
getTaxesByProvince
(
$payment
[
'bt_province'
])
*
.
01
;
}
$payment
[
'total_taxes'
]
=
$payment
[
'total_cost'
]
*
$tax_percent
;
$payment
[
'total'
]
=
number_format
(
$payment
[
'total_cost'
]
-
$payment
[
'total_discounts'
]
+
$payment
[
'total_taxes'
],
2
);
$trans_amount
=
$payment
[
'total'
];
// Now update the post
update_post_meta
(
$invoice_id
,
'payment'
,
$payment
);
update_post_meta
(
$invoice_id
,
'trans_amount'
,
$trans_amount
);
}
}
unset
(
$users
,
$invoices
);
}
}
?>
...
...
Please
register
or
sign in
to post a comment