X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=index.php;h=d8eb41130720eef386128c8e8319fe1cb3d61f74;hb=e5f77e537873002e9ee3a730e99c5f55a5aa0535;hp=b156cb76164dc6bc27a277811c89930f200c2042;hpb=3689b5636b2eb76dc1f920a1b0129e71be1a62b7;p=contractor-progress.git diff --git a/index.php b/index.php index b156cb7..d8eb411 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,20 @@ . + require_once('code/tasks.php'); function index_main() { @@ -17,21 +32,30 @@ 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); tem_set('task_state', task_state_pretty($state)); if(logged_in_as_contractor()) { - tem_set('client', db_get_value('people', 'name', 'where id=%i', $client_id)); + 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; } @@ -41,34 +65,89 @@ 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) { + $total_finished_untested = 0; + $total_finished_unpaid = 0; + $total_queue = 0; + $total_working = 0; + 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('not_tested_total', $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'); + $total_finished_untested += $finished_untested; + $total_finished_unpaid += $finished_unpaid; + $total_queue += $queue; + $total_working += $working; + } + + tem_set('tested_total', $total_finished_unpaid); + tem_set('done_total', $total_finished_unpaid + $total_finished_untested); + tem_set('not_tested_total', $total_finished_untested); + tem_set('queued_total', $total_queue + $total_working); + tem_set('client', 'all'); + tem_show('unpaid_totals_row'); + + tem_show('unpaid_totals'); + } +} + function _index_main() { $client_id = logged_in(); # make sure they've filled out the tiny user agreement $tiny_agreement = db_get_value('people', 'tiny_agreement', 'where id=%i', $client_id); - if($tiny_agreement < 30) { + if($tiny_agreement < 30 || $tiny_agreement > 999) { return './tiny_agreement'; } if(logged_in_as_contractor()) { tem_show('su_link'); tem_show('needs_attention_header'); - task_summary('needs_approval', 'where state=%i order by id desc', TASK_WORKING); - task_summary('needs_fixing', 'where (state=%i || state=%i) || (client_id=1 && state<%i) order by id desc', TASK_NEEDS_QUOTE, TASK_BUG, TASK_QUEUED); - task_summary('finished_unpaid', 'where state=%i && paid = 0 order by id desc', TASK_FINISHED); - task_summary('finished_paid', 'where state=%i && paid = 1 order by id desc', TASK_FINISHED); - task_summary('queue', 'where state=%i order by client_id, ord', TASK_QUEUED); + + $GLOBALS['unpaid_totals'] = array(); + # things with a view link: + 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 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_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'); task_summary('needs_approval', 'where client_id=%i && (state=%i || state=%i) order by id', $client_id, TASK_NEEDS_GO_AHEAD, TASK_NEEDS_TESTING); task_summary('needs_fixing', 'where client_id=%i && (state=%i || state=%i) order by id', $client_id, TASK_DRAFT, TASK_NEEDS_CLARIFICATION); } - task_summary('queue', 'where client_id=%i && state=%i order by ord', $client_id, TASK_QUEUED); + task_summary('queue', 'where client_id=%i && state=%i order by ord desc', $client_id, TASK_QUEUED); task_summary('jason', 'where client_id=%i && (state=%i || state=%i) order by id desc', $client_id, TASK_NEEDS_QUOTE, TASK_BUG); task_summary('jason_working', 'where client_id=%i && state=%i order by id desc', $client_id, TASK_WORKING); - task_summary('finished_unpaid', 'where client_id=%i && state=%i && paid=0 order by id desc', $client_id, TASK_FINISHED); - task_summary('finished_paid', 'where client_id=%i && state=%i && paid=1 order by id desc', $client_id, TASK_FINISHED); + task_summary('finished_unpaid', 'where client_id=%i && state=%i && paid=0 order by finished_at desc', $client_id, TASK_FINISHED); + task_summary('finished_paid', 'where client_id=%i && state=%i && paid=1 order by finished_at desc', $client_id, TASK_FINISHED); } return; }