From 64063ec400c45f0962040870a4ed750172403890 Mon Sep 17 00:00:00 2001 From: pedrod Date: Wed, 27 Sep 2023 09:43:54 +0000 Subject: [PATCH] review function + approved interface --- .../Controller/Admin/OrderController.php | 108 ++++++++++++++---- .../Controller/Admin/RequestController.php | 36 ++++-- .../Entity/Order/OrderArticleMap.php | 16 +++ module/LogisticsBundle/Repository/Request.php | 12 +- .../Resources/config/install/acl.config.php | 4 +- .../admin/order/review-articles.twig | 3 - .../views/logistics/admin/order/view.twig | 1 + .../logistics/admin/request/approved.twig | 42 +++++++ .../admin/request/partials/navigation.twig | 3 + 9 files changed, 182 insertions(+), 43 deletions(-) delete mode 100644 module/LogisticsBundle/Resources/views/logistics/admin/order/review-articles.twig create mode 100644 module/LogisticsBundle/Resources/views/logistics/admin/request/approved.twig diff --git a/module/LogisticsBundle/Controller/Admin/OrderController.php b/module/LogisticsBundle/Controller/Admin/OrderController.php index ef95279da6..4dd9533c4c 100644 --- a/module/LogisticsBundle/Controller/Admin/OrderController.php +++ b/module/LogisticsBundle/Controller/Admin/OrderController.php @@ -104,10 +104,13 @@ public function viewAction() } $total += $formValue - $oldAmount; $this->getEntityManager()->persist($booking); - $this->getEntityManager()->flush(); + } } } + $this->getEntityManager()->flush(); + + // $this->sendMailToContact($request); if ($total == 0) { $this->flashMessenger()->warn( @@ -115,8 +118,6 @@ public function viewAction() 'You have not reviewed any articles!' ); } else { - $this->getEntityManager()->flush(); - $this->flashMessenger()->success( 'Success', 'The request was successfully reviewed.' @@ -176,10 +177,6 @@ public function reviewOrderAction() $this->getEntityManager()->persist($newOrder); $this->getEntityManager()->flush(); - $this->flashMessenger()->success( - 'Success', - 'The request was succesfully reviewed.' - ); return new ViewModel( array( 'result' => (object)array('status' => 'success'), @@ -187,7 +184,6 @@ public function reviewOrderAction() ); } } - return new ViewModel(); } @@ -197,6 +193,7 @@ public function approveAction() if ($academic === null) { return new ViewModel(); } + $reviewingUnit = $academic->getUnit($this->getCurrentAcademicYear()); $order = $this->getOrderEntity(); if ($order === null) { @@ -211,28 +208,41 @@ public function approveAction() } $newOrder = $this->recreateOrder($order, $academic->getUnit($this->getCurrentAcademicYear())->getName()); - $newOrder->approve(); $this->getEntityManager()->persist($newOrder); $request = $order->getRequest(); - $request->handled(); + $mappings = $this->getEntityManager() ->getRepository('LogisticsBundle\Entity\Order\OrderArticleMap') ->findAllByOrderQuery($order)->getResult(); foreach ($mappings as $mapping) { - $newMapping = new OrderArticleMap($newOrder, $mapping->getArticle(), $mapping->getAmount(), $mapping->getAmount()); - $newMapping->setStatus('goedgekeurd'); - $this->getEntityManager()->persist($newMapping); + $article = $mapping->getArticle(); + if ($article->getUnit() === $reviewingUnit) { + $newMapping = new OrderArticleMap($newOrder, $mapping->getArticle(), $mapping->getAmount(), $mapping->getAmount()); + $newMapping->setStatus('goedgekeurd'); + $this->getEntityManager()->persist($newMapping); + } + } + + if ($this->isAllMappingsApproved($newOrder)) { + $newOrder->approve(); + $request->handled(); + $this->flashMessenger()->success( + 'Success', + 'The request was successfully approved.' + ); + } else { + $newOrder->review(); + $this->flashMessenger()->success( + 'Success', + 'The articles were successfully approved.' + ); } $this->getEntityManager()->flush(); // $this->sendMailToContact($request); - $this->flashMessenger()->success( - 'Success', - 'The request was succesfully approved.' - ); $this->redirect()->toRoute( 'logistics_admin_request', @@ -250,6 +260,7 @@ public function rejectAction() if ($academic === null) { return new ViewModel(); } + $reviewingUnit = $academic->getUnit($this->getCurrentAcademicYear()); $order = $this->getOrderEntity(); if ($order === null) { @@ -268,24 +279,37 @@ public function rejectAction() $this->getEntityManager()->persist($newOrder); $request = $order->getRequest(); - $request->handled(); $mappings = $this->getEntityManager() ->getRepository('LogisticsBundle\Entity\Order\OrderArticleMap') ->findAllByOrderQuery($order)->getResult(); foreach ($mappings as $mapping) { - $newMapping = new OrderArticleMap($newOrder, $mapping->getArticle(), $mapping->getAmount(), $mapping->getAmount()); - $newMapping->setStatus('afgewezen'); - $this->getEntityManager()->persist($newMapping); + $article = $mapping->getArticle(); + if ($article->getUnit() === $reviewingUnit) { + $newMapping = new OrderArticleMap($newOrder, $article, $mapping->getAmount(), $mapping->getAmount()); + $newMapping->setStatus('afgewezen'); + $this->getEntityManager()->persist($newMapping); + } + } + + if ($this->isAllMappingsRejected($newOrder)) { + $newOrder->reject(); + $request->handled(); + $this->flashMessenger()->success( + 'Success', + 'The request was successfully rejected.' + ); + } else { + $newOrder->review(); + $this->flashMessenger()->success( + 'Success', + 'The articles were successfully rejected.' + ); } $this->getEntityManager()->flush(); // $this->sendMailToContact($request); - $this->flashMessenger()->success( - 'Success', - 'The request was succesfully rejected.' - ); $this->redirect()->toRoute( 'logistics_admin_request', @@ -769,6 +793,40 @@ private function recreateOrder(Order $order, string $updator) return $new; } + /** + * @param Order $order + * @return boolean + */ + private function isAllMappingsApproved($order) + { + $mappings = $this->getEntityManager() + ->getRepository('LogisticsBundle\Entity\Order\OrderArticleMap') + ->findAllByOrderQuery($order)->getResult(); + foreach ($mappings as $mapping) { + if (!$mapping->isApproved()) { + return False; + } + } + return True; + } + + /** + * @param Order $order + * @return boolean + */ + private function isAllMappingsRejected($order) + { + $mappings = $this->getEntityManager() + ->getRepository('LogisticsBundle\Entity\Order\OrderArticleMap') + ->findAllByOrderQuery($order)->getResult(); + foreach ($mappings as $mapping) { + if (!$mapping->isRejected()) { + return False; + } + } + return True; + } + /** * @param array $a1 * @param array $a2 diff --git a/module/LogisticsBundle/Controller/Admin/RequestController.php b/module/LogisticsBundle/Controller/Admin/RequestController.php index fa12fb2d59..311bab5048 100644 --- a/module/LogisticsBundle/Controller/Admin/RequestController.php +++ b/module/LogisticsBundle/Controller/Admin/RequestController.php @@ -18,7 +18,24 @@ class RequestController extends \CommonBundle\Component\Controller\ActionControl { public function manageAction() { - $requests = $this->getOpenRequests(); + $requests = $this->getUnhandledRequests(); + + // Gets last order for every request + $lastOrders = array(); + foreach ($requests as $request) { + $lastOrders[] = $this->getLastOrderByRequest($request); + } + + return new ViewModel( + array( + 'requests' => $lastOrders, + ) + ); + } + + public function approvedAction() + { + $requests = $this->getHandledRequests(); // Gets last order for every request $lastOrders = array(); @@ -73,8 +90,8 @@ public function conflictingAction() ->getRepository('LogisticsBundle\Entity\Order\OrderArticleMap') ->findAllByOrderQuery($order)->getResult()); } - $conflicts = array(); + $conflicts = array(); // Loop over all made mappings foreach ($mappings as $map) { // Find overlaps @@ -357,16 +374,21 @@ private function getOpenRequestsByAcademic(Academic $academic) /** * @return array */ - private function getOpenRequests() + private function getUnhandledRequests() { - $unhandledRequests = $this->getEntityManager() + return $this->getEntityManager() ->getRepository('LogisticsBundle\Entity\Request') ->findAllUnhandled(); - $handledRejects = $this->getEntityManager() + } + + /** + * @return array + */ + private function getHandledRequests() + { + return $this->getEntityManager() ->getRepository('LogisticsBundle\Entity\Request') ->findAllHandled(); - - return array_merge($unhandledRequests, $handledRejects); } /** diff --git a/module/LogisticsBundle/Entity/Order/OrderArticleMap.php b/module/LogisticsBundle/Entity/Order/OrderArticleMap.php index b288040bc5..c1ede7a40a 100644 --- a/module/LogisticsBundle/Entity/Order/OrderArticleMap.php +++ b/module/LogisticsBundle/Entity/Order/OrderArticleMap.php @@ -179,4 +179,20 @@ public function setStatus($status) { $this->status = $status; } + + /** + * @return boolean + */ + public function isApproved() + { + return $this->status == 'goedgekeurd'; + } + + /** + * @return boolean + */ + public function isRejected() + { + return $this->status == 'afgewezen'; + } } diff --git a/module/LogisticsBundle/Repository/Request.php b/module/LogisticsBundle/Repository/Request.php index addbd0375d..b66ff6cd2a 100644 --- a/module/LogisticsBundle/Repository/Request.php +++ b/module/LogisticsBundle/Repository/Request.php @@ -132,7 +132,7 @@ public function findHandledByAcademic(Academic $academic) /** * @return ArrayCollection */ - public function findAllHandled() + public function findAllApprovedHandled() { $query = $this->getEntityManager()->createQueryBuilder(); return $query->select('r') @@ -148,40 +148,40 @@ public function findAllHandled() } /** - * @param Academic $academic * @return ArrayCollection */ - public function findUnhandledByAcademic(Academic $academic) + public function findAllUnhandled() { $query = $this->getEntityManager()->createQueryBuilder(); return $query->select('r') ->from('LogisticsBundle\Entity\Request', 'r') ->where( $query->expr()->andx( - $query->expr()->eq('r.contact', ':academic'), $query->expr()->eq('r.handled', 'FALSE'), $query->expr()->eq('r.removed', 'FALSE'), ) ) - ->setParameter('academic', $academic) ->getQuery() ->getResult(); } /** + * @param Academic $academic * @return ArrayCollection */ - public function findAllUnhandled() + public function findUnhandledByAcademic(Academic $academic) { $query = $this->getEntityManager()->createQueryBuilder(); return $query->select('r') ->from('LogisticsBundle\Entity\Request', 'r') ->where( $query->expr()->andx( + $query->expr()->eq('r.contact', ':academic'), $query->expr()->eq('r.handled', 'FALSE'), $query->expr()->eq('r.removed', 'FALSE'), ) ) + ->setParameter('academic', $academic) ->getQuery() ->getResult(); } diff --git a/module/LogisticsBundle/Resources/config/install/acl.config.php b/module/LogisticsBundle/Resources/config/install/acl.config.php index 359ccaffd7..4912434f58 100644 --- a/module/LogisticsBundle/Resources/config/install/acl.config.php +++ b/module/LogisticsBundle/Resources/config/install/acl.config.php @@ -12,10 +12,10 @@ 'add', 'delete', 'edit', 'manage', 'search', 'typeahead', 'uploadImage', 'orders', 'csv', 'template' ), 'logistics_admin_order' => array( - 'add', 'delete', 'edit', 'manage', 'removed', 'articles', 'deleteArticle', 'articleMapping', 'approveArticle', 'reviewOrder', 'reviewArticles', 'approve', 'reject', 'view', + 'add', 'delete', 'edit', 'manage', 'removed', 'articles', 'deleteArticle', 'articleMapping', 'approveArticle', 'reviewOrder', 'approve', 'reject', 'view', ), 'logistics_admin_request' => array( - 'reject', 'approve', 'manage', 'view', 'conflicting', + 'manage', 'approved', 'approve', 'reject', 'view', 'conflicting', ), 'logistics_admin_van_reservation' => array( 'add', 'delete', 'edit', 'manage', 'old', diff --git a/module/LogisticsBundle/Resources/views/logistics/admin/order/review-articles.twig b/module/LogisticsBundle/Resources/views/logistics/admin/order/review-articles.twig deleted file mode 100644 index 82a1a56582..0000000000 --- a/module/LogisticsBundle/Resources/views/logistics/admin/order/review-articles.twig +++ /dev/null @@ -1,3 +0,0 @@ -{% autoescape false %} - {{ result|json_encode }} -{% endautoescape %} \ No newline at end of file diff --git a/module/LogisticsBundle/Resources/views/logistics/admin/order/view.twig b/module/LogisticsBundle/Resources/views/logistics/admin/order/view.twig index 43be4c6381..488cb1b242 100644 --- a/module/LogisticsBundle/Resources/views/logistics/admin/order/view.twig +++ b/module/LogisticsBundle/Resources/views/logistics/admin/order/view.twig @@ -315,6 +315,7 @@ reviewAll.find('.edit').unbind('click').click(function () { var reviewOrder = $('#review-order'); const orderBody = { + "csrf":, "name":reviewOrder.find('#order_review_name').val(), "contact":reviewOrder.find('#order_review_contact').val(), "unit":reviewOrder.find('#order_review_unit').val(), diff --git a/module/LogisticsBundle/Resources/views/logistics/admin/request/approved.twig b/module/LogisticsBundle/Resources/views/logistics/admin/request/approved.twig new file mode 100644 index 0000000000..8afc6c41af --- /dev/null +++ b/module/LogisticsBundle/Resources/views/logistics/admin/request/approved.twig @@ -0,0 +1,42 @@ +{% extends 'admin/base.twig' %} + +{% block content %} + {% include 'logistics/admin/request/partials/navigation.twig' %} + + {% include 'admin/partials/flashMessenger.twig' %} + +
+

Requests

+ + + + + + + + + + + + {% for request in requests %} + + + + + + + {# class="{% if request.getStatus() == 'Approved' %}accept_request{% elseif request.getStatus() == 'Rejected' %}reject_request{% endif %}" #} + + + {% endfor %} +
NameContactUnitStart DateEnd DateStatusAction
{{ request.getName() }}{{ request.getContact() }}{{ request.getUnit().getName() }}{{ request.getStartDate().format('d/m/Y H:i') }}{{ request.getEndDate().format('d/m/Y H:i') }}{{ request.getStatus() }} + {% if hasAccess('logistics_admin_order', 'view') %} + View + {% endif %} +
+
+ + {% include 'admin/partials/paginationControl.twig' %} +
+ +{% endblock %} diff --git a/module/LogisticsBundle/Resources/views/logistics/admin/request/partials/navigation.twig b/module/LogisticsBundle/Resources/views/logistics/admin/request/partials/navigation.twig index 6faa83a7e3..6a77d7043b 100644 --- a/module/LogisticsBundle/Resources/views/logistics/admin/request/partials/navigation.twig +++ b/module/LogisticsBundle/Resources/views/logistics/admin/request/partials/navigation.twig @@ -6,6 +6,9 @@ {% if hasAccess('logistics_admin_request', 'conflicting') %}
  • Conflicting
  • {% endif %} + {% if hasAccess('logistics_admin_request', 'approved') %} +
  • Approved
  • + {% endif %} {% if hasAccess('logistics_admin_request', 'manage') %}
  • Manage
  • {% endif %}