From: Iain Patterson Date: Mon, 22 Apr 2013 20:40:09 +0000 (-0400) Subject: Show outstanding orders in contact view. X-Git-Tag: 2013-05-13~32 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=2cce3a10f172ca1ee7150d80d80d98ecb7527d3b;p=readifood.git Show outstanding orders in contact view. List any orders which are not delivered or cancelled when viewing a beneficiary. --- 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);