git://git.iain.cx/iain
/
readifood.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' into uat
[readifood.git]
/
lib
/
delivery.php
diff --git
a/lib/delivery.php
b/lib/delivery.php
index
03495df
..
3b45558
100644
(file)
--- a/
lib/delivery.php
+++ b/
lib/delivery.php
@@
-1,19
+1,33
@@
<?php
<?php
- /* Find orders scheduled for delivery today. */
- function get_orders_for_today() {
+ if (isset($_POST['show_date'])) {
+ header(sprintf("Location: http%s://%s/%s/date/%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, $_POST['date']));
+ exit;
+ }
+
+ /* Find orders scheduled for delivery on a certain date. */
+ function get_orders_for_date($date) {
$order_ids = array();
$order_ids = array();
+ /* $date is in Y-m-d format. */
+ list($y, $m, $d) = explode('-', $date);
+ $then = mktime(0, 0, 0, $m, $d, $y);
+
$q = new OrderQuery();
$q = new OrderQuery();
- $orders = $q->filterByDate(
time('Y-m-d')
)->find();
+ $orders = $q->filterByDate(
$then
)->find();
if (count($orders)) {
foreach ($orders as $order) $order_ids[] = $order->getId();
}
if (count($orders)) {
foreach ($orders as $order) $order_ids[] = $order->getId();
}
- else echo "<p>No deliveries
today
.</p>\n";
+ else echo "<p>No deliveries
for $date
.</p>\n";
return $order_ids;
}
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();
/* Find drivers with deliveries today. */
function get_drivers_by_order_id($order_ids) {
$driver_ids = array();
@@
-53,7
+67,7
@@
return $order_ids;
}
return $order_ids;
}
- function show_driver_forms($driver_ids) {
+ function show_driver_forms($driver_ids
, $date = null
) {
global $module;
if (! count($driver_ids)) return;
global $module;
if (! count($driver_ids)) return;
@@
-65,13
+79,16
@@
return;
}
return;
}
- echo "<p>Drivers with deliveries scheduled:";
+ echo "<p>Drivers with deliveries scheduled on ";
+ if ($date) echo $date;
+ else echo date('Y-m-d', time());
+ echo ":";
foreach ($contacts as $contact) {
foreach ($contacts as $contact) {
- printf("<br>\n<a href=\"/$module/
driver/%s/%d\">%s</a>
", urlencode($contact->getDisplayname()), $contact->getId(), htmlspecialchars($contact->getDisplayname()));
+ printf("<br>\n<a href=\"/$module/
%sdriver/%s/%d\">%s</a>", ($date) ? "date/$date/" : "
", urlencode($contact->getDisplayname()), $contact->getId(), htmlspecialchars($contact->getDisplayname()));
}
}
}
}
- function show_driver_schedule($driver_name = null, $driver_id = null) {
+ 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) {
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) {
@@
-79,24
+96,42
@@
return;
}
return;
}
- echo "<h3>Delivery schedule for <strong>" . htmlspecialchars($contact->getDisplayname()) . "</strong></h3>\n";
- $order_ids = get_driver_schedule_by_order_id($contact->getId(), get_orders_for_today());
+ echo "<h3>Delivery schedule for <strong>" . htmlspecialchars($contact->getDisplayname()) . "</strong> on ";
+ if ($date) {
+ $order_ids = get_orders_for_date($date);
+ echo $date;
+ }
+ else {
+ $order_ids = get_orders_for_today();
+ echo date('Y-m-d', time());
+ }
+ echo "</h3>\n";
+
$q = new OrderQuery;
$q = new OrderQuery;
- $orders = $q->filterById(
$order_ids
)->find();
+ $orders = $q->filterById(
get_driver_schedule_by_order_id($contact->getId(), $order_ids)
)->find();
foreach ($orders as $order) {
$contact = get_contact_by_id($order->getBeneficiaryId());
if (! $contact) continue;
foreach ($orders as $order) {
$contact = get_contact_by_id($order->getBeneficiaryId());
if (! $contact) continue;
+ $phones = array();
$area = get_contact_area($contact);
$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>";
$address = get_hub_address($hub);
$hub = get_hub_by_id($order->getHubId(), false);
if ($hub) {
echo "<p>Deliver to hub <strong> " . htmlspecialchars($hub->getName()) . "</strong>";
$address = get_hub_address($hub);
+ $phone = $hub->getTelephone1();
+ if ($phone) $phones[] = $phone;
+ $phone = $hub->getTelephone2();
+ if ($phone) $phones[] = $phone;
}
else {
echo "<p>Deliver direct to beneficiary";
$address = get_contact_address($contact);
}
else {
echo "<p>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);
}
$area = get_address_area($address);
@@
-105,18
+140,46
@@
echo "\n<br>" . htmlspecialchars($address->getLine());
echo "\n<br>" . htmlspecialchars($city->getName());
echo "\n<br>" . htmlspecialchars($address->getPostcode());
echo "\n<br>" . htmlspecialchars($address->getLine());
echo "\n<br>" . htmlspecialchars($city->getName());
echo "\n<br>" . htmlspecialchars($address->getPostcode());
+ if (count($phones)) echo "\n<br><br>Telephone <strong>" . implode(" or ", $phones) . "</strong>";
echo "</p>\n";
echo "</p>\n";
+ $notes = $order->getNotes();
+ if ($notes) {
+ echo "<p><strong>Notes:</strong>\n";
+ echo htmlspecialchars($notes);
+ echo "</p>\n";
+ }
+
echo "<hr>\n\n";
}
}
echo "<hr>\n\n";
}
}
+ function show_delivery_date_form($date = null) {
+ echo "<form method=\"POST\" action=\"" . $_SERVER['REQUEST_URI'] . "\">\n";
+ echo "<p>Show deliveries for\n";
+ show_date_form("date", $date);
+ submit("show_date", "Show");
+ echo "</form>\n";
+ }
+
+ $date = null;
list($ignored, $id, $args) = parse_parameters($parameters);
list($ignored, $id, $args) = parse_parameters($parameters);
- if (count($args)) show_driver_schedule($args[0], $args[1]);
+ if ($parameters[0] == "date") {
+ if ($args[0]) {
+ if (preg_match('/^[1-9][0-9][0-9][0-9]-[01][0-9]-[0-3][0-9]$/', $args[0])) $date = $args[0];
+ array_shift($args);
+ }
+ }
+
+ if ($args[0] == "driver") array_shift($args);
+ if (count($args)) show_driver_schedule($args[0], $args[1], $date);
else {
else {
- $order_ids = get_orders_for_today();
+ if ($date) $order_ids = get_orders_for_date($date);
+ else $order_ids = get_orders_for_today();
+
if ($order_ids) $driver_ids = get_drivers_by_order_id($order_ids);
if ($order_ids) $driver_ids = get_drivers_by_order_id($order_ids);
- if ($driver_ids) show_driver_forms($driver_ids);
+ if ($driver_ids) show_driver_forms($driver_ids, $date);
+ show_delivery_date_form($date);
}
?>
}
?>