diff --git a/module/LogisticsBundle/Controller/Admin/OrderController.php b/module/LogisticsBundle/Controller/Admin/OrderController.php index bc9a576804..ef95279da6 100644 --- a/module/LogisticsBundle/Controller/Admin/OrderController.php +++ b/module/LogisticsBundle/Controller/Admin/OrderController.php @@ -39,6 +39,8 @@ public function viewAction() return new ViewModel(); } + $reviewingUnit = $academic->getUnit($this->getCurrentAcademicYear()); + $order = $this->getOrderEntity(); if ($order === null) { return new ViewModel(); @@ -48,8 +50,13 @@ public function viewAction() ->getRepository('LogisticsBundle\Entity\Order\OrderArticleMap') ->findAllByOrderQuery($order)->getResult(); - foreach ($articles as $mapping) { - error_log($mapping->getArticle()->getName()); + $mapped = array(); + foreach ($articles as $map) { + if (!isset($mapped[$map->getArticle()->getId()])) { + $mapped[$map->getArticle()->getId()] = 0; + } + + $mapped[$map->getArticle()->getId()] += $map->getAmount(); } $lastOrders = $this->getAllOrdersByRequest($order->getRequest()); @@ -70,52 +77,59 @@ public function viewAction() ); if ($this->getRequest()->isPost()) { - if ($this->getRequest()->getPost()->toArray()['submit'] == 'orderReview') { - $this->initAjax(); - $orderForm = $this->getForm('logistics_admin_order_review'); - $orderForm->setData($this->getRequest()->getPost()); - if ($orderForm->isValid()) { - error_log('Valid: order form'); - if ($this->getLastOrderByRequest($order->getRequest())->isReviewed()) { - error_log('existed'); - $orderForm->hydrateObject( - $this->recreateOrder( - $this->getLastOrderByRequest($order->getRequest()), - $academic->getUnit($this->getCurrentAcademicYear())->getName()) + if ($this->getRequest()->getPost()->toArray()['submit'] == 'articleReview') { + $articleForm->setData($this->getRequest()->getPost()); + if ($articleForm->isValid()) { + $newOrder = $this->getLastOrderByRequest($order->getRequest()); + $formData = $articleForm->getData(); + + $total = 0; + + foreach ($formData as $formKey => $formValue) { + $mappingId = substr($formKey, 8, strlen($formKey)); + if (substr($formKey, 0, 8) == 'article-' && $formValue != '' && $formValue != '0') { + $oldMapping = $this->getEntityManager() + ->getRepository('LogisticsBundle\Entity\Order\OrderArticleMap') + ->findOneById($mappingId); + $article = $oldMapping->getArticle(); + + if ($article->getUnit() === $reviewingUnit) { + $oldAmount = $oldMapping->getAmount(); + + $booking = new OrderArticleMap($newOrder, $article, $formValue, $oldAmount); + if ($oldAmount == $formValue) { + $booking->setStatus('goedgekeurd'); + } else { + $booking->setStatus('herzien'); + } + $total += $formValue - $oldAmount; + $this->getEntityManager()->persist($booking); + $this->getEntityManager()->flush(); + } + } + } + + if ($total == 0) { + $this->flashMessenger()->warn( + 'Warning', + 'You have not reviewed any articles!' ); } else { - error_log('didnt exist'); - $newOrder = $orderForm->hydrateObject( - $this->recreateOrder($order, $academic->getUnit($this->getCurrentAcademicYear())->getName()) + $this->getEntityManager()->flush(); + + $this->flashMessenger()->success( + 'Success', + 'The request was successfully reviewed.' ); - $newOrder->review(); - $this->getEntityManager()->persist($newOrder); } - $this->getEntityManager()->flush(); - - $this->flashMessenger()->success( - 'Success', - 'The request was succesfully reviewed.' - ); - return new ViewModel( + $this->redirect()->toRoute( + 'logistics_admin_request', array( - 'result' => (object)array('status' => 'success'), + 'action' => 'manage', ) ); -// return new ViewModel( -// array( -// 'result' => (object)array('status' => json_encode($this->getRequest()->getPost())), -// ) -// ); - } - } elseif ($this->getRequest()->getPost()->toArray()['submit'] == 'articleReview') { - $articleForm->setData($this->getRequest()->getPost()); - if ($orderForm->isValid()) { - error_log('Valid: article form'); - $this->flashMessenger()->success( - 'Success', - 'The request was succesfully reviewed.' - ); + + return new ViewModel(); } } } @@ -136,14 +150,11 @@ public function viewAction() public function reviewOrderAction() { $this->initAjax(); - error_log('Order form'); $academic = $this->getAcademicEntity(); if ($academic === null) { return new ViewModel(); } - $reviewingUnit = $academic->getUnit($this->getCurrentAcademicYear()); - $order = $this->getOrderEntity(); if ($order === null) { return new ViewModel(); @@ -152,13 +163,14 @@ public function reviewOrderAction() $orderForm = $this->getForm('logistics_admin_order_review'); if ($this->getRequest()->isPost()) { - error_log('post'); $orderForm->setData($this->getRequest()->getPost()); - error_log(json_encode($this->getRequest()->getPost())); if ($orderForm->isValid()) { - error_log('valid'); - $newOrder = $this->recreateOrder($orderForm->getOrder(), $academic->getUnit($this->getCurrentAcademicYear())->getName()); + $newOrder = $orderForm->hydrateObject( + $this->recreateOrder( + $this->getLastOrderByRequest($order->getRequest()), + $academic->getUnit($this->getCurrentAcademicYear())->getName()) + ); $newOrder->review(); $this->getEntityManager()->persist($newOrder); @@ -170,92 +182,10 @@ public function reviewOrderAction() ); return new ViewModel( array( - 'result' => (object)array('status' => json_encode($this->getRequest()->getPost())), + 'result' => (object)array('status' => 'success'), ) ); } - error_log('exit'); - - -// if ($orderForm->isValid()) { -// -// $newOrder = $this->recreateOrder($orderForm->getOrder(), $academic->getUnit($this->getCurrentAcademicYear())->getName()); -//// $newOrder = $this->recreateOrder($order, $academic->getUnit($this->getCurrentAcademicYear())->getName()); -// $newOrder->review(); -// $this->getEntityManager()->persist($newOrder); -// -// $request = $order->getRequest(); -// $request->handled(); -// -// $this->getEntityManager()->flush(); -// -// // $this->sendMailToContact($request); -// $this->flashMessenger()->success( -// 'Success', -// 'The request was succesfully reviewed.' -// ); -// -// -// return new ViewModel( -// array( -// 'result' => (object)array('status' => 'success'), -// ) -// ); -// } - } - - return new ViewModel(); - } - - public function reviewArticlesAction() - { - $this->initAjax(); - - $academic = $this->getAcademicEntity(); - if ($academic === null) { - return new ViewModel(); - } - - $reviewingUnit = $academic->getUnit($this->getCurrentAcademicYear()); - - $order = $this->getOrderEntity(); - if ($order === null) { - return new ViewModel(); - } - if ($academic !== $order->getCreator() - && (!$academic->isPraesidium($this->getCurrentAcademicYear()) - || $academic->getUnit($this->getCurrentAcademicYear()) !== $order->getUnit()) - ) { - return $this->notFoundAction(); - } - - if ($this->getRequest()->isPost()) { - $postData = $this->getRequest()->getPost(); - error_log('Article form'); - error_log(print_r($postData)); - $newOrder = $this->getLastOrderByRequest($order->getRequest()); - - $mappings = $this->getEntityManager() - ->getRepository('LogisticsBundle\Entity\Order\OrderArticleMap') - ->findAllByOrderQuery($order)->getResult(); - - foreach ($mappings as $mapping) { - if ($mapping->getArticle()->getUnit() === $reviewingUnit) { - $newMapping = new OrderArticleMap($newOrder, $mapping->getArticle(), $mapping->getAmount(), $mapping->getAmount()); - if ($mapping->getAmount() == $mapping->getOldAmount()) { - $newMapping->setStatus('goedgekeurd'); - } else { - $newMapping->setStatus('herzien'); - } - $this->getEntityManager()->persist($newMapping); - } - } - - return new ViewModel( - array( - 'result' => (object)array('status' => 'success'), - ) - ); } return new ViewModel(); diff --git a/module/LogisticsBundle/Entity/Inventory.php b/module/LogisticsBundle/Entity/Inventory.php index 1cedb05df6..e6143f6ef6 100644 --- a/module/LogisticsBundle/Entity/Inventory.php +++ b/module/LogisticsBundle/Entity/Inventory.php @@ -119,7 +119,7 @@ class Inventory /** * @var DateTime The expiry date * - * @ORM\Column(name="expiry_date", type="DateTime", nullable=true) + * @ORM\Column(name="expiry_date_", type="DateTime", nullable=true) */ private $expiryDate_; diff --git a/module/LogisticsBundle/Form/Admin/Order/Add.php b/module/LogisticsBundle/Form/Admin/Order/Add.php index b045ccf5be..3d5e532382 100644 --- a/module/LogisticsBundle/Form/Admin/Order/Add.php +++ b/module/LogisticsBundle/Form/Admin/Order/Add.php @@ -24,6 +24,9 @@ public function init() 'name' => 'name', 'label' => 'Order Name', 'required' => true, + 'attributes' => array( + 'id' => 'order_review_name', + ), 'options' => array( 'input' => array( 'filters' => array( @@ -47,6 +50,9 @@ public function init() 'type' => 'text', 'name' => 'contact', 'label' => 'Contact Name', + 'attributes' => array( + 'id' => 'order_review_contact', + ), 'required' => true, 'options' => array( 'input' => array( @@ -66,6 +72,7 @@ public function init() 'required' => true, 'attributes' => array( 'options' => $this->createUnitsArray(), + 'id' => 'order_review_unit', ), ) ); @@ -76,6 +83,9 @@ public function init() 'name' => 'email', 'label' => 'Email', 'required' => true, + 'attributes' => array( + 'id' => 'order_review_email', + ), 'options' => array( 'input' => array( 'filters' => array( @@ -99,6 +109,7 @@ public function init() 'required' => true, 'attributes' => array( 'options' => $this->createLocationsArray(), + 'id' => 'order_review_location', ), ) ); @@ -109,6 +120,9 @@ public function init() 'name' => 'start_date', 'label' => 'Start Date', 'required' => true, + 'attributes' => array( + 'id' => 'order_review_start_date', + ), ) ); @@ -118,6 +132,9 @@ public function init() 'name' => 'end_date', 'label' => 'End Date', 'required' => true, + 'attributes' => array( + 'id' => 'order_review_end_date', + ), 'options' => array( 'input' => array( 'validators' => array( @@ -141,6 +158,7 @@ public function init() 'label' => 'Description', 'attributes' => array( 'style' => 'height: 20px;', + 'id' => 'order_review_description', ), 'required' => false, 'options' => array( @@ -160,6 +178,7 @@ public function init() 'label' => 'Internal Comment', 'attributes' => array( 'style' => 'height: 30px;', + 'id' => 'order_review_internal_comment', ), 'options' => array( 'input' => array( @@ -178,6 +197,7 @@ public function init() 'label' => 'External Comment', 'attributes' => array( 'style' => 'height: 30px;', + 'id' => 'order_review_external_comment', ), 'options' => array( 'input' => array( diff --git a/module/LogisticsBundle/Resources/views/logistics/admin/order/view.twig b/module/LogisticsBundle/Resources/views/logistics/admin/order/view.twig index 516a1ff382..43be4c6381 100644 --- a/module/LogisticsBundle/Resources/views/logistics/admin/order/view.twig +++ b/module/LogisticsBundle/Resources/views/logistics/admin/order/view.twig @@ -314,40 +314,37 @@ reviewAll.find('.edit').unbind('click').click(function () { var reviewOrder = $('#review-order'); - var orderSubmit = reviewOrder.find('.orderSubmit'); - console.log(orderSubmit); - orderSubmit.click(); - if ('success' == orderData.status) { - var reviewArticle = $('#review-article'); - var articleSubmit = reviewArticle.find('.articleSubmit'); - console.log(articleSubmit); - articleSubmit.click(); + const orderBody = { + "name":reviewOrder.find('#order_review_name').val(), + "contact":reviewOrder.find('#order_review_contact').val(), + "unit":reviewOrder.find('#order_review_unit').val(), + "email":reviewOrder.find('#order_review_email').val(), + "location":reviewOrder.find('#order_review_location').val(), + "start_date":reviewOrder.find('#order_review_start_date').val(), + "end_date":reviewOrder.find('#order_review_end_date').val(), + "description":reviewOrder.find('#order_review_description').val(), + "internal_comment":reviewOrder.find('#order_review_internal_comment').val(), + "external_comment":reviewOrder.find('#order_review_external_comment').val(), + "submit":"orderReview" } - console.log('click'); - {# $.post('{{ url('logistics_admin_order', {"action": "reviewOrder"})}}' + id, function (orderData) {#} - {# console.log(orderData.status);#} - {# if (orderData && 'success' == orderData.status) {#} - {# $('.flashmessage').addClass('hide');#} - {# // $('.article_removed_success').removeClass('hide');#} - {# // $('.item-' + id).remove();#} - {# reviewAll.modal('hide');#} - {# $.post('{{ url('logistics_admin_order', {"action": "reviewArticles"})}}' + id, function (data) {#} - {# if (data && 'success' == data.status) {#} - {# $('.flashmessage').addClass('hide');#} - {# // $('.article_removed_success').removeClass('hide');#} - {# // $('.item-' + id).remove();#} - {# reviewAll.modal('hide');#} - {# } else {#} - {# errorRemove();#} - {# }#} - {# }, 'json').error(errorRemove);#} - {# } else {#} - {# errorRemove();#} - {# }#} - {# }, 'json').error(errorRemove);#} + + $.post('{{ url('logistics_admin_order', {"action": "reviewOrder"})}}' + id, orderBody, function (orderData) { + console.log(orderData.status); + if (orderData && 'success' == orderData.status) { + $('.flashmessage').addClass('hide'); + // $('.article_removed_success').removeClass('hide'); + // $('.item-' + id).remove(); + reviewAll.modal('hide'); + + var reviewArticle = $('#review-article'); + var articleSubmit = reviewArticle.find('.articleSubmit'); + articleSubmit.click(); + } else { + errorRemove(); + } + }, 'json').error(errorRemove); }); reviewAll.modal(); -{# {{ url('logistics_admin_order', {"action" : 'review', "id" : order.getId()}) }}#} } function errorRemove() {