diff --git a/config/routes/rider.yaml b/config/routes/rider.yaml index 70ddd91d..16a56993 100644 --- a/config/routes/rider.yaml +++ b/config/routes/rider.yaml @@ -41,3 +41,8 @@ rider_ajax_popup: path: /riders/{id}/popup controller: App\Controller\RiderController::popupInfo methods: [GET] + +rider_active_jo: + path: /riders/{id}/activejo/{jo_id} + controller: App\Controller\RiderController::riderActiveJO + methods: [GET] diff --git a/src/Controller/RiderController.php b/src/Controller/RiderController.php index 838b558b..ace84582 100644 --- a/src/Controller/RiderController.php +++ b/src/Controller/RiderController.php @@ -7,7 +7,10 @@ use App\Entity\Rider; use App\Entity\RiderSchedule; use App\Entity\Hub; use App\Entity\User; +use App\Entity\JobOrder; + use App\Service\FileUploader; +use App\Service\MQTTClient; use Doctrine\ORM\Query; use Doctrine\ORM\EntityManagerInterface; @@ -18,6 +21,8 @@ use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; + use Catalyst\MenuBundle\Annotation\Menu; use DateTime; @@ -510,4 +515,25 @@ class RiderController extends Controller return $this->render('rider/popup.html.twig', [ 'rider' => $rider ]); } + + /** + * @ParamConverter("rider", class="App\Entity\Rider") + */ + public function riderActiveJO(EntityManagerInterface $em, MQTTClient $mclient, Rider $rider, $jo_id) + { + $jo = $em->getRepository(JobOrder::class)->find($jo_id); + $rider->setActiveJobOrder($jo); + $em->flush(); + + // TODO: trigger what needs triggering in rider app + $payload = [ + 'event' => 'cancelled', + 'reason' => 'Reprioritization', + 'jo_id' => $jo->getID(), + ]; + $mclient->sendRiderEvent($jo, $payload); + + + return $this->redirecttoRoute('rider_update', ['id' => $rider->getID()]); + } } diff --git a/src/Entity/Rider.php b/src/Entity/Rider.php index f9331c03..53731475 100644 --- a/src/Entity/Rider.php +++ b/src/Entity/Rider.php @@ -64,6 +64,13 @@ class Rider */ protected $job_orders; + // rider's active job order since we now support multiple job orders per rider + /** + * @ORM\OneToOne(targetEntity="JobOrder") + * @ORM\JoinColumn(name="active_jo_id", referencedColumnName="id") + */ + protected $active_job_order; + // picture of rider /** * @ORM\Column(type="string", nullable=true) @@ -122,6 +129,8 @@ class Rider $this->flag_active = true; $this->username = null; $this->password = ''; + + $this->active_job_order = null; } public function getID() @@ -300,8 +309,19 @@ class Rider return $this->password; } + public function setActiveJobOrder(JobOrder $jo = null) + { + $this->active_job_order = $jo; + return $this; + } + public function getActiveJobOrder() { + // check if we have set a custom active + if ($this->active_job_order != null) + return $this->active_job_order; + + // no custom active job order $active_status = [ JOStatus::ASSIGNED, JOStatus::IN_TRANSIT, @@ -315,6 +335,20 @@ class Rider return $this->job_orders->matching($criteria)[0]; } + public function getOpenJobOrders() + { + $active_status = [ + JOStatus::ASSIGNED, + JOStatus::IN_TRANSIT, + JOStatus::IN_PROGRESS, + ]; + + $criteria = Criteria::create(); + $criteria->where(Criteria::expr()->in('status', $active_status)); + + return $this->job_orders->matching($criteria); + } + public function getSessions() { return $this->sessions; diff --git a/templates/rider/form.html.twig b/templates/rider/form.html.twig index c08c250c..a9b0264c 100644 --- a/templates/rider/form.html.twig +++ b/templates/rider/form.html.twig @@ -13,7 +13,7 @@
-
+
@@ -150,6 +150,56 @@ {% endif %}
+
+
+
+

+ Active Job Orders +

+
+
+
+ + + + + + + + + + + + + {% set active_jo_id = obj.getActiveJobOrder.getID|default(0) %} + {% for jo in obj.getOpenJobOrders %} + + + + + + + + + {% else %} + + + + {% endfor %} + +
IDDateCustomerLocationQ StatusAction
{{ jo.getID }}{{ jo.getDateSchedule.format('Y-m-d H:i:s') }}{{ jo.getCustomer.getNameDisplay }}{{ jo.getDeliveryAddress|default('') }}{% if jo.getID == active_jo_id %}Active{% endif %} + {% if jo.getID != active_jo_id %} + + + + + + + {% endif %} +
No assigned job orders.
+
+
+