From 2cce3a10f172ca1ee7150d80d80d98ecb7527d3b Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Mon, 22 Apr 2013 16:40:09 -0400 Subject: [PATCH] Show outstanding orders in contact view. List any orders which are not delivered or cancelled when viewing a beneficiary. --- lib/contact.php | 21 +++++++++++++++++++++ lib/functions.php | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/lib/contact.php b/lib/contact.php index d83e101..a5bceee 100644 --- a/lib/contact.php +++ b/lib/contact.php @@ -180,6 +180,27 @@ global $contact_roles, $parcel_sizes, $parcel_contents; if (! $contact) $contact = new Contact; + else if ($contact->getRole() & $GLOBALS['ROLE_BENEFICIARY']) { + $state_mask = $GLOBALS['STATE_ANY']; + $state_mask &= ~$GLOBALS['STATE_DELIVERED']; + $state_mask &= ~$GLOBALS['STATE_CANCELLED']; + + $orders = get_contact_orders($contact, $state_mask); + + if (count($orders)) { + echo "\n"; + echo " Outstanding orders:\n"; + echo "\n"; + + echo "\n"; + echo " \n"; + foreach ($orders as $order) { + echo " Order " . $order->getStrongLink($order->getId()) . ": " . get_order_displayname($order) . "
\n"; + } + echo " \n"; + echo "\n"; + } + } /* Role. */ echo "\n"; diff --git a/lib/functions.php b/lib/functions.php index 2f32a22..511e0cf 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -185,6 +185,13 @@ return $order_ids; } + function get_contact_orders($contact, $state_mask = null) { + $q = new OrderQuery; + $q->filterByBeneficiaryId($contact->getId()); + if ($state_mask) $q->filterById(get_order_ids_by_state($state_mask)); + return $q->orderByDate()->find(); + } + function get_user_by_contact_id($id, $verbose = true) { $q = new UserQuery; $user = $q->findOneByContactId($id); -- 2.7.4