X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;ds=sidebyside;f=lib%2Freport.php;h=2209d528f65c26707e95df5280e12ad8979536b0;hb=6c0392caed936af1c4f3fba0c49beda59011f7d5;hp=2fabab43be17fff3cf048e2349ebfe467f4bb8ed;hpb=524fe78f250d75cc54dba1dfb482ea4cdf574768;p=readifood.git diff --git a/lib/report.php b/lib/report.php index 2fabab4..2209d52 100644 --- a/lib/report.php +++ b/lib/report.php @@ -79,7 +79,7 @@ $week = 1; $last_week = 0; $total = 0; - echo "\n"; + echo "
\n"; foreach ($rows as $row) { /* Convert week of year to date range. */ if (! $week_offset) $week_offset = $row->getWeek() - 1; @@ -88,16 +88,64 @@ /* Fill in missing weeks. XXX */ for ($missing_week = $last_week + 1; $missing_week < $week; $missing_week++) { echo "\n"; - printf(" \n", $missing_week); + printf(" \n", $missing_week); echo "\n"; } echo "\n"; - printf(" \n", $row->getCount(), $week); + printf(" \n", $row->getCount(), $week); echo "\n"; $last_week = $week; } echo "\n"; - echo " \n"; + echo " \n"; + echo "\n"; + echo "
0Week %d0Week %d
%dWeek %d%dWeek %d
$totalTotal$totalTotal
\n"; + } + + function show_contents_report(&$order_ids, $parcel_size, $grand_total) { + global $parcel_sizes, $parcel_contents; + + $total = 0; + for ($i = count($parcel_sizes); $i < count($parcel_contents); $i++) { + $q = new OrderQuery; + $q->filterById($order_ids); + $q->where(sprintf("parcel & %d", $parcel_size)); + $q->where(sprintf("parcel & %d", (1 << $i))); + $contents = $q->find(); + $total += count($contents); + echo "\n"; + printf(" %d%s\n", count($contents), htmlspecialchars($parcel_contents[$i])); + echo "\n"; + } + + /* No special contents. */ + echo "\n"; + printf(" %d%s no special contents\n", $grand_total - $total, htmlspecialchars($parcel_sizes[$parcel_size >> 1])); + echo "\n"; + } + + function show_parcel_report(&$order_ids) { + global $parcel_sizes; + echo "

Orders by parcel type

\n"; + + $q = new OrderQuery; + $q->filterById($order_ids); + $q->withColumn(sprintf("parcel & %d", (1 << count($parcel_sizes)) - 1), 'size'); + $q->withColumn('count(*)', 'count'); + $q->addGroupByColumn('size')->addAscendingOrderByColumn('size'); + $rows = $q->find(); + $total = 0; + echo "\n"; + foreach ($rows as $row) { + echo "\n"; + $requester = get_contact_by_id($row->getRequesterId()); + printf(" \n", $row->getCount(), htmlspecialchars($parcel_sizes[$row->getSize() >> 1])); + $total += $row->getCount(); + echo "\n"; + show_contents_report($order_ids, $row->getSize(), $row->getCount()); + } + echo "\n"; + echo " \n"; echo "\n"; echo "
%d%s
$totalTotal
\n"; } @@ -111,17 +159,17 @@ $q->groupByRequesterId()->addDescendingOrderByColumn('count'); $rows = $q->find(); $total = 0; - echo "\n"; + echo "
\n"; /* XXX Join! */ foreach ($rows as $row) { echo "\n"; $requester = get_contact_by_id($row->getRequesterId()); - printf(" \n", $row->getCount(), htmlspecialchars($requester->getDisplayname())); + printf(" \n", $row->getCount(), htmlspecialchars($requester->getDisplayname())); $total += $row->getCount(); echo "\n"; } echo "\n"; - echo " \n"; + echo " \n"; echo "\n"; echo "
%d%s%d%s
$totalTotal$totalTotal
\n"; } @@ -152,6 +200,7 @@ } show_order_report($order_state_ids); + show_parcel_report($order_ids); show_requester_report($order_ids); }