From: Jason Woofenden Date: Fri, 16 Jan 2009 04:12:43 +0000 (-0500) Subject: added "unpaid totals" section to admin home. removed untested capability of dealing... X-Git-Url: https://jasonwoof.com/gitweb/?p=contractor-progress.git;a=commitdiff_plain;h=1f3edf2d29c76c8c2789f23e9f02869df72327e0 added "unpaid totals" section to admin home. removed untested capability of dealing with tasks that have the contractor as the client --- diff --git a/index.html b/index.html index 886dfba..192fccf 100644 --- a/index.html +++ b/index.html @@ -63,6 +63,14 @@
Total: ~task_total.money~
+ +

Unpaid totals

+

"queued" includes work-in-progress. + +

+ + +

Finished and paid for

diff --git a/index.php b/index.php index 4258b8a..1c17785 100644 --- a/index.php +++ b/index.php @@ -32,13 +32,13 @@ function index_main() { function task_summary($tem_prefix, $where_clause/*, ... */) { $args = func_get_args(); $args = array_slice($args, 1); - array_unshift($args, 'tasks', 'id,price,title,state,client_id'); + array_unshift($args, 'tasks', 'id,price,title,state,client_id,paid'); $rows = call_user_func_array('db_get_rows', $args); #$rows = db_get_rows('tasks', 'id,price,title,state,client_id', $where_clause); if($rows) { $total = 0.0; foreach($rows as $row) { - list($id, $price, $title, $state, $client_id) = $row; + list($id, $price, $title, $state, $client_id, $paid) = $row; tem_set('task_id', $id); tem_set('task_title', $title); tem_set('task_price', $price); @@ -47,6 +47,15 @@ function task_summary($tem_prefix, $where_clause/*, ... */) { tem_set('client', db_get_value('people', 'username', 'where id=%i', $client_id)); } tem_show($tem_prefix . '_row'); + if(!$paid && isset($GLOBALS['unpaid_totals'])) { + if(!isset($GLOBALS['unpaid_totals'][$client_id])) { + $GLOBALS['unpaid_totals'][$client_id] = array(); + } + if(!isset($GLOBALS['unpaid_totals'][$client_id][$tem_prefix])) { + $GLOBALS['unpaid_totals'][$client_id][$tem_prefix] = 0; + } + $GLOBALS['unpaid_totals'][$client_id][$tem_prefix] += $price; + } $total += $price; } @@ -56,6 +65,38 @@ function task_summary($tem_prefix, $where_clause/*, ... */) { } } +# pass multi-dimensional hash arr[client_id][status]. +# status strings: 'finished_untested', 'finished_unpaid', 'queue' +function totals_summary($arr) { + if($arr) { + foreach($arr as $client_id => $t) { + $finished_untested = 0; + $finished_unpaid = 0; + $queue = 0; + $working = 0; + if(isset($t['finished_untested'])) { + $finished_untested = $t['finished_untested']; + } + if(isset($t['finished_unpaid'])) { + $finished_unpaid = $t['finished_unpaid']; + } + if(isset($t['queue'])) { + $queue = $t['queue']; + } + if(isset($t['needs_approval'])) { # administrator page re-uses this for TASK_WORKING + $working = $t['needs_approval']; + } + tem_set('tested_total', $finished_unpaid); + tem_set('done_total', $finished_unpaid + $finished_untested); + tem_set('queued_total', $queue + $working); + tem_set('client', db_get_value('people', 'username', 'where id=%i', $client_id)); + tem_show('unpaid_totals_row'); + } + + tem_show('unpaid_totals'); + } +} + function _index_main() { $client_id = logged_in(); @@ -69,15 +110,17 @@ function _index_main() { tem_show('su_link'); tem_show('needs_attention_header'); + $GLOBALS['unpaid_totals'] = array(); # things with a view link: - task_summary('needs_approval', 'where state=%i || (client_id=%i && (state=%i || state=%i || state=%i)) order by id desc', TASK_WORKING, $client_id, TASK_NEEDS_TESTING, TASK_NEEDS_GO_AHEAD, TASK_BUG); + task_summary('needs_approval', 'where state=%i order by id desc', TASK_WORKING); # this affects queued_total # things with an edit link: - task_summary('needs_fixing', 'where (state=%i || state=%i) || (client_id=%i && (state<%i || state=%i)) order by id desc', TASK_NEEDS_QUOTE, TASK_BUG, $client_id, TASK_DRAFT, TASK_NEEDS_CLARIFICATION); - task_summary('finished_unpaid', 'where state=%i && paid=0 order by finished_at desc', TASK_FINISHED); + task_summary('needs_fixing', 'where state=%i || state=%i order by id desc', TASK_NEEDS_QUOTE, TASK_BUG); task_summary('finished_untested', 'where state=%i order by client_id, finished_at desc', TASK_NEEDS_TESTING); - task_summary('finished_paid', 'where state=%i && paid = 1 order by finished_at desc limit 20', TASK_FINISHED); + task_summary('finished_unpaid', 'where state=%i && paid=0 order by finished_at desc', TASK_FINISHED); task_summary('queue', 'where state=%i order by client_id, ord desc', TASK_QUEUED); + totals_summary($GLOBALS['unpaid_totals']); + task_summary('finished_paid', 'where state=%i && paid = 1 order by finished_at desc limit 20', TASK_FINISHED); } else { if(db_count('tasks', 'where client_id=%i && (state=%i || state=%i || state=%i || state=%i)', $client_id, TASK_DRAFT, TASK_NEEDS_CLARIFICATION, TASK_NEEDS_GO_AHEAD, TASK_NEEDS_TESTING)) { tem_show('needs_attention_header');