Specify family unit size and allow multiple types of parcel contents.
$STATE_CANCELLED = 1 << 5;
$STATE_ANY = $all_states;
+ /* Parcel types. */
+ $parcel_sizes = array("Single", "Couple", "Family");
+ $PARCEL_SINGLE = 1 << 0;
+ $PARCEL_COUPLE = 1 << 1;
+ $PARCEL_FAMILY = 1 << 2;
+
+ $parcel_contents = array(null, null, null, "Vegetarian", "Halal", "Diabetic", "Baby 0-6 months", "Baby 6-12 months", "Toiletry bag");
+ $PARCEL_VEGETARIAN = 1 << 3;
+ $PARCEL_HALAL = 1 << 4;
+ $PARCEL_DIABETIC = 1 << 5;
+ $PARCEL_BABY6 = 1 << 6;
+ $PARCEL_BABY12 = 1 << 7;
+ $PARCEL_TOILETRY = 1 << 8;
+
?>
if (! $contact) continue;
$area = get_contact_area($contact);
- echo "<p>Order of <em>" . $order->getQuantity() . "kg</em> for <strong>" . htmlspecialchars($contact->getDisplayname()) . "</strong> in " . htmlspecialchars(get_area_displayname($area)) . ".</p>\n";
+ echo "<p>Order of <em>" . get_order_parcel_string($order) . "</em> for <strong>" . htmlspecialchars($contact->getDisplayname()) . "</strong> in " . htmlspecialchars(get_area_displayname($area)) . ".</p>\n";
$hub = get_hub_by_id($order->getHubId(), false);
if ($hub) {
echo "<p>Deliver to hub <strong> " . htmlspecialchars($hub->getName()) . "</strong>";
return sprintf("%0.2fkg on %s", $donation->getQuantity() / 1000, $donation->getDate());
}
+ function get_order_parcel_string($order) {
+ global $parcel_sizes, $parcel_contents;
+
+ $parcel_size = "";
+ for ($i = 0 ; $i < count($parcel_sizes); $i++) {
+ if ($order->getParcel() & (1 << $i)) {
+ $parcel_size = $parcel_sizes[$i];
+ break;
+ }
+ }
+
+ $selected = array();
+ for ($i = count($parcel_sizes); $i < count($parcel_contents); $i++) {
+ if ($order->getParcel() & (1 << $i)) $selected[] = $parcel_contents[$i];
+ }
+
+ return implode(": ", array($parcel_size, implode(", ", $selected)));
+ }
+
function get_order_displayname($order) {
- return sprintf("%0.2fkg on %s", $order->getQuantity() / 1000, $order->getDate());
+ return sprintf("<span class=\"small\">%s</span> on %s", get_order_parcel_string($order), $order->getDate());
}
function get_address_area($address) {
}
function show_order_form($order = null, $area_id = null) {
- global $states;
+ global $states, $parcel_sizes, $parcel_contents;
if ($order) {
$q = new OrderStateQuery;
echo " <td>"; input("quantity", sprintf("%0.2f", $order->getQuantity() / 1000)); echo "</td>\n";
echo "</tr>\n";
+ /* Parcel type. */
+ echo "<tr>\n";
+ echo " <td>Parcel size</td>\n";
+ echo " <td><select name=\"parcel_size\">\n";
+ $mask = 1 << (count($parcel_sizes) + 1);
+ for ($i = 0; $i < count($parcel_sizes); $i++) {
+ option("parcel_size", $i << 1, $parcel_sizes[$i], $order->getParcel() % $mask);
+ }
+ echo "</select></td>\n";
+ echo "</tr>\n";
+
+ /* Parcel contents. */
+ echo "<tr>\n";
+ echo " <td>Parcel contents</td>\n";
+ echo " <td>";
+ for ($i = count($parcel_sizes); $i < count($parcel_contents); $i++) {
+ echo " <input type=\"checkbox\" name=\"parcel_$i\"";
+ if ($order->getParcel() & (1 << $i)) echo " checked";
+ echo ">$parcel_contents[$i]\n";
+ }
+ echo "</td>\n";
+ echo "</tr>\n";
+
/* Driver. */
echo "<tr>\n";
echo " <td>Driver</td>\n";
}
function update_order(&$order, $new = false) {
- global $user_id;
+ global $user_id, $parcel_sizes, $parcel_contents;
#$date = ymd_to_iso8601("date");
$date = $_POST['date'];
if (! $driver_id) $driver_id = null;
$state = $_POST['state'];
if (! $state) $state = $GLOBALS['STATE_PLACED'];
+ $parcel = $_POST['parcel_size'];
+ for ($i = count($parcel_sizes); $i < count($parcel_contents); $i++) {
+ if ($_POST['parcel_' . $i] == "on") $parcel |= (1 << $i);
+ }
if ($date) {
list($y, $m, $d) = explode('-', $date);
$order->setBeneficiaryId($beneficiary_id);
$order->setHubId($hub_id);
$order->setQuantity($quantity * 1000);
+ $order->setParcel($parcel);
/* XXX: begin/commit */
try {
<column name="beneficiary_id" type="integer" required="true"/>
<column name="hub_id" type="integer" required="false"/>
<column name="quantity" type="integer" required="true"/>
+ <column name="parcel" type="integer" required="true"/>
<foreign-key foreignTable="Contact" phpName="Requester" refPhpName="Requester">
<reference local="requester_id" foreign="id"/>
</foreign-key>