filterByDate($then)->find(); if (count($orders)) { foreach ($orders as $order) $order_ids[] = $order->getId(); } else echo "
No deliveries for $date.
\n"; return $order_ids; } /* Find orders scheduled for delivery today. */ function get_orders_for_today() { return get_orders_for_date(date('Y-m-d'), time()); } /* Find drivers with deliveries today. */ function get_drivers_by_order_id($order_ids) { $driver_ids = array(); if (count($order_ids)) { $dbh = Propel::getConnection(); $sth = $dbh->prepare("select * from OrderState o where updated=(select max(updated) from OrderState where order_id=o.order_id) and order_id in (" . implode(",", $order_ids) . ") and driver_id is not null"); $sth->execute(); $order_states = OrderStatePeer::populateObjects($sth); if (count($order_states)) { foreach ($order_states as $order_state) $driver_ids[] = $order_state->getDriverId(); } else echo "No drivers assigned for deliveries.
\n"; } return $driver_ids; } /* Find schedule for a driver today. */ function get_driver_schedule_by_order_id($driver_id, $all_order_ids) { $order_ids = array(); if (! count($all_order_ids)) { echo "No orders for today.
\n"; return null; } $dbh = Propel::getConnection(); $sth = $dbh->prepare("select * from OrderState o where updated=(select max(updated) from OrderState where order_id=o.order_id) and order_id in (" . implode(",", $all_order_ids) . ") and driver_id=$driver_id"); $sth->execute(); $order_states = OrderStatePeer::populateObjects($sth); if (count($order_states)) { foreach ($order_states as $order_state) $order_ids[] = $order_state->getOrderId(); } else echo "No deliveries for this driver.
\n"; return $order_ids; } function show_driver_forms($driver_ids, $date = null) { global $module; if (! count($driver_ids)) return; $q = new ContactQuery(); $contacts = $q->filterById($driver_ids)->find(); if (! count($contacts)) { echo "Can't find drivers!
\n"; return; } echo "Drivers with deliveries scheduled on ";
if ($date) echo $date;
else echo date('Y-m-d', time());
echo ":";
foreach ($contacts as $contact) {
printf("
\n%s", ($date) ? "date/$date/" : "", urlencode($contact->getDisplayname()), $contact->getId(), htmlspecialchars($contact->getDisplayname()));
}
}
function show_driver_schedule($driver_name = null, $driver_id = null, $date = null) {
if (isset($driver_id)) $contact = get_contact_by_id($driver_id);
else if (isset($driver_name)) $contact = get_contact_by_name($driver_name);
if (! $contact) {
echo "
No such driver!
\n"; return; } echo "Order of " . get_order_parcel_string($order) . " for " . htmlspecialchars($contact->getDisplayname()) . " in " . htmlspecialchars(get_area_displayname($area)) . ".
\n"; $hub = get_hub_by_id($order->getHubId(), false); if ($hub) { echo "Deliver to hub " . htmlspecialchars($hub->getName()) . ""; $address = get_hub_address($hub); $phone = $hub->getTelephone1(); if ($phone) $phones[] = $phone; $phone = $hub->getTelephone2(); if ($phone) $phones[] = $phone; } else { echo "
Deliver direct to beneficiary";
$address = get_contact_address($contact);
$phone = $contact->getTelephone1();
if ($phone) $phones[] = $phone;
$phone = $contact->getTelephone2();
if ($phone) $phones[] = $phone;
}
$area = get_address_area($address);
echo " in " . htmlspecialchars($area->getName()) . " at:
";
$city = get_area_city($area);
echo "\n
" . htmlspecialchars($address->getLine());
echo "\n
" . htmlspecialchars($city->getName());
echo "\n
" . htmlspecialchars($address->getPostcode());
if (count($phones)) echo "\n
Telephone " . implode(" or ", $phones) . "";
echo "
Notes:\n"; echo htmlspecialchars($notes); echo "
\n"; } echo "