JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
added "unpaid totals" section to admin home. removed untested capability of dealing...
authorJason Woofenden <jason283@herkamire.com>
Fri, 16 Jan 2009 04:12:43 +0000 (23:12 -0500)
committerJason Woofenden <jason283@herkamire.com>
Fri, 16 Jan 2009 04:12:43 +0000 (23:12 -0500)
index.html
index.php

index 886dfba..192fccf 100644 (file)
     <div>Total: ~task_total.money~</div>
   <!--~end~-->
 
     <div>Total: ~task_total.money~</div>
   <!--~end~-->
 
+  <!--~unpaid_totals start~-->
+    <h3>Unpaid totals</h3>
+    <p>"queued" includes work-in-progress.
+    <!--~unpaid_totals_row start~-->
+    <div class="task_link">~client.html~ queued: ~queued_total.money~, tested: ~tested_total.money~, done: ~done_total.money~</div>
+    <!--~end~-->
+  <!--~end~-->
+
   <!--~finished_paid start~-->
     <h3>Finished and paid for</h3>
     <!--~finished_paid_row start~-->
   <!--~finished_paid start~-->
     <h3>Finished and paid for</h3>
     <!--~finished_paid_row start~-->
index 4258b8a..1c17785 100644 (file)
--- 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);
 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) {
        $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_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');
                                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;
                }
 
                        $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();
 
 function _index_main() {
        $client_id = logged_in();
 
@@ -69,15 +110,17 @@ function _index_main() {
                tem_show('su_link');
                tem_show('needs_attention_header');
 
                tem_show('su_link');
                tem_show('needs_attention_header');
 
+               $GLOBALS['unpaid_totals'] = array();
                # things with a view link:
                # 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:
 
                # 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_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);
                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');
        } 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');