Additionally report orders by parcel contents. 2013-09-11
authorIain Patterson <me@iain.cx>
Wed, 11 Sep 2013 14:45:11 +0000 (15:45 +0100)
committerIain Patterson <me@iain.cx>
Wed, 11 Sep 2013 14:54:28 +0000 (10:54 -0400)
Break down sizes of parcel into parcel contents.

lib/report.php

index 05ca904..2209d52 100644 (file)
       /* Fill in missing weeks. XXX */
       for ($missing_week = $last_week + 1; $missing_week < $week; $missing_week++) {
         echo "<tr>\n";
-        printf("  <td>0</td><td>Week %d</td>\n", $missing_week);
+        printf("  <td align=\"right\">0</td><td>Week %d</td>\n", $missing_week);
         echo "</tr>\n";
       }
       echo "<tr>\n";
-      printf("  <td>%d</td><td>Week %d</td>\n", $row->getCount(), $week);
+      printf("  <td align=\"right\">%d</td><td>Week %d</td>\n", $row->getCount(), $week);
       echo "</tr>\n";
       $last_week = $week;
     }
     echo "<tr>\n";
-    echo "  <td class=\"strong\">$total</td><td class=\"strong\">Total</td>\n";
+    echo "  <td align=\"right\" class=\"strong\">$total</td><td class=\"strong\">Total</td>\n";
     echo "</tr>\n";
     echo "</table>\n";
   }
 
-  function show_size_report(&$order_ids) {
+  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 "<tr class=\"small\">\n";
+      printf("  <td align=\"right\">%d</td><td>%s</td>\n", count($contents), htmlspecialchars($parcel_contents[$i]));
+      echo "</tr>\n";
+    }
+
+    /* No special contents. */
+    echo "<tr class=\"small\">\n";
+    printf("  <td align=\"right\">%d</td><td>%s no special contents</td>\n", $grand_total - $total, htmlspecialchars($parcel_sizes[$parcel_size >> 1]));
+    echo "</tr>\n";
+  }
+
+  function show_parcel_report(&$order_ids) {
     global $parcel_sizes;
-    echo "<h3>Orders by parcel size</h3>\n";
+    echo "<h3>Orders by parcel type</h3>\n";
 
     $q = new OrderQuery;
     $q->filterById($order_ids);
     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]));
+      printf("  <td align=\"right\">%d</td><td>%s</td>\n", $row->getCount(), htmlspecialchars($parcel_sizes[$row->getSize() >> 1]));
       $total += $row->getCount();
       echo "</tr>\n";
+      show_contents_report($order_ids, $row->getSize(), $row->getCount());
     }
     echo "<tr>\n";
-    echo "  <td class=\"strong\">$total</td><td class=\"strong\">Total</td>\n";
+    echo "  <td align=\"right\" class=\"strong\">$total</td><td class=\"strong\">Total</td>\n";
     echo "</tr>\n";
     echo "</table>\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($requester->getDisplayname()));
+      printf("  <td align=\"right\">%d</td><td>%s</td>\n", $row->getCount(), htmlspecialchars($requester->getDisplayname()));
       $total += $row->getCount();
       echo "</tr>\n";
     }
     echo "<tr>\n";
-    echo "  <td class=\"strong\">$total</td><td class=\"strong\">Total</td>\n";
+    echo "  <td align=\"right\" class=\"strong\">$total</td><td class=\"strong\">Total</td>\n";
     echo "</tr>\n";
     echo "</table>\n";
   }
     }
 
     show_order_report($order_state_ids);
-    show_size_report($order_ids);
+    show_parcel_report($order_ids);
     show_requester_report($order_ids);
   }