Report orders by parcel size.
authorIain Patterson <me@iain.cx>
Mon, 9 Sep 2013 21:46:16 +0000 (22:46 +0100)
committerIain Patterson <me@iain.cx>
Wed, 11 Sep 2013 14:54:28 +0000 (10:54 -0400)
lib/report.php

index b268440..05ca904 100644 (file)
     echo "</table>\n";
   }
 
+  function show_size_report(&$order_ids) {
+    global $parcel_sizes;
+    echo "<h3>Orders by parcel size</h3>\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 "<table class=\"report\">\n";
+    foreach ($rows as $row) {
+      echo "<tr>\n";
+      $requester = get_contact_by_id($row->getRequesterId());
+      printf("  <td>%d</td><td>%s</td>\n", $row->getCount(), htmlspecialchars($parcel_sizes[$row->getSize() >> 1]));
+      $total += $row->getCount();
+      echo "</tr>\n";
+    }
+    echo "<tr>\n";
+    echo "  <td class=\"strong\">$total</td><td class=\"strong\">Total</td>\n";
+    echo "</tr>\n";
+    echo "</table>\n";
+  }
+
   function show_requester_report(&$order_ids) {
     echo "<h3>Orders by referrer</h3>\n";
 
     }
 
     show_order_report($order_state_ids);
+    show_size_report($order_ids);
     show_requester_report($order_ids);
   }