filterByDate(time('Y-m-d'))->find(); if (count($orders)) { foreach ($orders as $order) $order_ids[] = $order->getId(); } else echo "
No deliveries today.
\n"; return $order_ids; } /* 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) { 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:";
foreach ($contacts as $contact) {
printf("
\n%s", urlencode($contact->getDisplayname()), $contact->getId(), htmlspecialchars($contact->getDisplayname()));
}
}
function show_driver_schedule($driver_name = null, $driver_id = 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); } else { echo "
Deliver direct to beneficiary";
$address = get_contact_address($contact);
}
$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());
echo "