From: Iain Patterson Date: Fri, 8 Apr 2016 12:01:17 +0000 (-0400) Subject: Allow date range in order view. X-Git-Tag: 2016-04-08^0 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=6a5bca8bea9c16060c3c90bbbb1cbbfe86562666;p=readifood.git Allow date range in order view. Restrict to orders for delivery between specified dates. --- diff --git a/lib/order.php b/lib/order.php index 2476ef1..2a126d2 100644 --- a/lib/order.php +++ b/lib/order.php @@ -31,18 +31,18 @@ set_last_selected("area_id", $_POST['area_id']); $q = new AreaQuery; $area = $q->findOneById($_POST['area_id']); - header(sprintf("Location: http%s://%s/%s/in/area/%s/%d%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, urlencode($area->getName()), $_POST['area_id'], get_order_state_query_uri(get_order_state_mask()))); + header(sprintf("Location: http%s://%s/%s/in/area/%s/%d%s%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, urlencode($area->getName()), $_POST['area_id'], get_order_state_query_uri(get_order_state_mask(), get_order_date_query_uri($_POST['from'], $_POST['to'])))); exit; } else if ($_POST['show_in_city']) { set_last_selected("city_id", $_POST['city_id']); $q = new CityQuery; $city = $q->findOneById($_POST['city_id']); - header(sprintf("Location: http%s://%s/%s/in/city/%s/%d%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, urlencode($city->getName()), $_POST['city_id'], get_order_state_query_uri(get_order_state_mask()))); + header(sprintf("Location: http%s://%s/%s/in/city/%s/%d%s%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, urlencode($city->getName()), $_POST['city_id'], get_order_state_query_uri(get_order_state_mask()), get_order_date_query_uri($_POST['from'], $_POST['to']))); exit; } - function show_orders($city_id = null, $area_id = null, $requester_ids = null, $beneficiary_ids = null, $state_mask = null) { + function show_orders($city_id = null, $area_id = null, $requester_ids = null, $beneficiary_ids = null, $state_mask = null, $from = null, $to = null) { list($first_page, $per_page) = pagination(); /* XXX: Use Propel methods. */ if (isset($state_mask)) $order_ids = get_order_ids_by_state($state_mask); @@ -61,6 +61,8 @@ } } if (isset($state_mask)) $q->filterById($order_ids); + if (isset($from)) $q->where('Order.Date >= ?', $from); + if (isset($to)) $q->where('Order.Date <= ?', $to); $orders = $q->orderByDate('desc')->orderById('desc')->paginate($first_page, $per_page); if (count($orders)) { foreach ($orders as $order) { @@ -71,42 +73,42 @@ else echo " none"; } - function show_city_orders($city_name, $city_id = null, $state_mask = null) { + function show_city_orders($city_name, $city_id = null, $state_mask = null, $from = null, $to = null) { if (isset($city_id)) $city = get_city_by_id($city_id); else if ($city_name) $city = get_city_by_name($city_name); if ($city) { echo "

Orders in city " . $city->getLink(get_city_displayname($city)) . ":"; - return show_orders($city->getId(), null, null, null, $state_mask); + return show_orders($city->getId(), null, null, null, $state_mask, $from, $to); } else echo "

No such city!

\n"; } - function show_requester_orders($contact_name, $contact_id = null, $state_mask = null) { + function show_requester_orders($contact_name, $contact_id = null, $state_mask = null, $from = null, $to = null) { if (isset($contact_id)) $contact = get_contact_by_id($contact_id); else if ($contact_name) $contact = get_contact_by_name($contact_name); if ($contact) { echo "

Orders from referrer " . $contact->getLink() . ":"; - return show_orders(null, null, $contact->getId(), null, $state_mask); + return show_orders(null, null, $contact->getId(), null, $state_mask, $from, $to); } else echo "

No such contact!

\n"; } - function show_beneficiary_orders($contact_name, $contact_id = null, $state_mask = null) { + function show_beneficiary_orders($contact_name, $contact_id = null, $state_mask = null, $from = null, $to = null) { if (isset($contact_id)) $contact = get_contact_by_id($contact_id); else if ($contact_name) $contact = get_contact_by_name($contact_name); if ($contact) { echo "

Orders to beneficiary " . $contact->getLink() . ":"; - return show_orders(null, null, null, $contact->getId(), $state_mask); + return show_orders(null, null, null, $contact->getId(), $state_mask, $from, $to); } else echo "

No such contact!

\n"; } - function show_area_orders($area_name, $area_id = null, $state_mask = null) { + function show_area_orders($area_name, $area_id = null, $state_mask = null, $from = null, $to = null) { if (isset($area_id)) $area = get_area_by_id($area_id); else if ($area_name) $area = get_area_by_name($area_name); if ($area) { echo "

Orders in area " . $area->getLink() . ":"; - return show_orders(null, $area->getId(), null, null, $state_mask); + return show_orders(null, $area->getId(), null, null, $state_mask, $from, $to); } else echo "

No such area!

\n"; } @@ -167,6 +169,16 @@ return "/state/" . get_order_state_query_string($mask); } + function get_order_date_query_uri($from, $to) { + $uri = ""; + if ($from) $uri .= "/from/$from"; + if ($to) $uri .= "/to/$to"; + + if (! $uri) return ""; + + return "/dated$uri"; + } + function show_order_areas_form($city_id = null) { $areas = get_city_areas($city_id); if (! count($areas)) { @@ -215,9 +227,13 @@ echo "\n"; } - function show_order_forms($city_id, $state_mask) { + function show_order_forms($city_id, $state_mask, $from = null, $to = null) { form("noprint standout"); show_order_state_form($state_mask); + echo "

Restrict to orders for delivery between "; + datepicker("from", $from, true, null, false, "to"); + echo " and "; + datepicker("to", $to, true, "from", false); show_order_areas_form($city_id); show_order_cities_form($city_id); end_form(); @@ -626,6 +642,18 @@ } } + for ($i = 1; $i < count($parameters); $i++) { + if ($parameters[$i] == "dated") { + for ($j = $i + 1; $j < count($parameters) - 1; $j++) { + if ($parameters[$j] == "from") $from = $parameters[$j + 1]; + if ($parameters[$j] == "to") $to = $parameters[$j + 1]; + } + + if ($from || $to) check_dates('order', $from, $to, false, false); + break; + } + } + if ($parameters[0] == "in") { /* /order/in/area/Romsey+Town/1 */ switch ($parameters[1]) { @@ -637,7 +665,7 @@ $area = $q->findOneById($area_id); $city = get_area_city($area); if ($city) $city_id = $city->getId(); - show_area_orders($parameters[2], $area_id, $state_mask); + show_area_orders($parameters[2], $area_id, $state_mask, $from, $to); break; case "city": @@ -645,7 +673,7 @@ $_POST['city_id'] = $city_id; $q = new CityQuery; $city = $q->findOneById($city_id); - show_city_orders($parameters[2], $city_id, $state_mask); + show_city_orders($parameters[2], $city_id, $state_mask, $from, $to); break; } } @@ -656,7 +684,7 @@ $contact_id = $parameters[3]; $q = new ContactQuery; $contact = $q->findOneById($contact_id); - show_requester_orders($parameters[2], $contact_id, $state_mask); + show_requester_orders($parameters[2], $contact_id, $state_mask, $from, $to); break; } } @@ -667,7 +695,7 @@ $contact_id = $parameters[3]; $q = new ContactQuery; $hub = $q->findOneById($contact_id); - show_beneficiary_orders($parameters[2], $contact_id, $state_mask); + show_beneficiary_orders($parameters[2], $contact_id, $state_mask, $from, $to); break; } } @@ -695,9 +723,9 @@ } } else if (isset($id)) show_order($id); - else if ($state_mask) show_orders(null, null, null, null, $state_mask); + else if ($state_mask) show_orders(null, null, null, null, $state_mask, $from, $to); - show_order_forms($city_id, $state_mask); + show_order_forms($city_id, $state_mask, $from, $to); show_add_new_order_form($city_id);