Show outstanding orders in contact view.
authorIain Patterson <me@iain.cx>
Mon, 22 Apr 2013 20:40:09 +0000 (16:40 -0400)
committerIain Patterson <me@iain.cx>
Mon, 22 Apr 2013 20:40:09 +0000 (16:40 -0400)
List any orders which are not delivered or cancelled when viewing a
beneficiary.

lib/contact.php
lib/functions.php

index d83e101..a5bceee 100644 (file)
     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 "<tr>\n";
+        echo "  <td colspan=2><strong>Outstanding orders:</strong></td>\n";
+        echo "</tr>\n";
+
+        echo "<tr>\n";
+        echo "  <td colspan=2>\n";
+        foreach ($orders as $order) {
+          echo "    Order " . $order->getStrongLink($order->getId()) . ": " . get_order_displayname($order) . "<br>\n";
+        }
+        echo "  </td>\n";
+        echo "</tr>\n";
+      }
+    }
 
     /* Role. */
     echo "<tr>\n";
index 2f32a22..511e0cf 100644 (file)
     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);