+ function show_postcode_report(&$order_ids) {
+ echo "<h3>Orders by postcode</h3>\n";
+
+ /*
+ No regex replace support in MySQL so we'll have to retrieve all records
+ and group the postcodes ourselves.
+ */
+ $q = new OrderQuery;
+ $q->filterById($order_ids);
+ $q->join("Beneficiary");
+ /* No foreign key so we need to list the two tables. */
+ $q->join("Beneficiary.Address");
+ /* Not a FoodOrder column so we need to ask for it explicitly. */
+ $q->withColumn('upper(postcode)', 'postcode');
+ $rows = $q->find();
+
+ $total = 0;
+ $postcodes = array();
+ foreach ($rows as $row) {
+ $postcode = preg_replace('/\s*[0-9][A-Z]+$/', '', trim($row->getPostcode()));
+ if (! $postcode) $postcode = "Unknown";
+ $postcodes[$postcode]++;
+ $total++;
+ }
+ ksort($postcodes);
+
+ echo "<table class=\"report\">\n";
+ foreach ($postcodes as $postcode => $count) {
+ echo "<tr>\n";
+ printf(" <td align=\"right\">%d</td><td>%s</td>\n", $count, htmlspecialchars($postcode));
+ echo "</tr>\n";
+ }
+ echo "<tr>\n";
+ echo " <td align=\"right\" class=\"strong\">$total</td><td class=\"strong\">Total</td>\n";
+ echo "</tr>\n";
+ echo "</table>\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 "<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) {