Skip to content

Commit

Permalink
working review action
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrodevog committed Sep 25, 2023
1 parent c372ec6 commit 6540246
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 163 deletions.
192 changes: 61 additions & 131 deletions module/LogisticsBundle/Controller/Admin/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public function viewAction()
return new ViewModel();
}

$reviewingUnit = $academic->getUnit($this->getCurrentAcademicYear());

$order = $this->getOrderEntity();
if ($order === null) {
return new ViewModel();
Expand All @@ -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());
Expand All @@ -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();
}
}
}
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion module/LogisticsBundle/Entity/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_;

Expand Down
20 changes: 20 additions & 0 deletions module/LogisticsBundle/Form/Admin/Order/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -66,6 +72,7 @@ public function init()
'required' => true,
'attributes' => array(
'options' => $this->createUnitsArray(),
'id' => 'order_review_unit',
),
)
);
Expand All @@ -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(
Expand All @@ -99,6 +109,7 @@ public function init()
'required' => true,
'attributes' => array(
'options' => $this->createLocationsArray(),
'id' => 'order_review_location',
),
)
);
Expand All @@ -109,6 +120,9 @@ public function init()
'name' => 'start_date',
'label' => 'Start Date',
'required' => true,
'attributes' => array(
'id' => 'order_review_start_date',
),
)
);

Expand All @@ -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(
Expand All @@ -141,6 +158,7 @@ public function init()
'label' => 'Description',
'attributes' => array(
'style' => 'height: 20px;',
'id' => 'order_review_description',
),
'required' => false,
'options' => array(
Expand All @@ -160,6 +178,7 @@ public function init()
'label' => 'Internal Comment',
'attributes' => array(
'style' => 'height: 30px;',
'id' => 'order_review_internal_comment',
),
'options' => array(
'input' => array(
Expand All @@ -178,6 +197,7 @@ public function init()
'label' => 'External Comment',
'attributes' => array(
'style' => 'height: 30px;',
'id' => 'order_review_external_comment',
),
'options' => array(
'input' => array(
Expand Down
Loading

0 comments on commit 6540246

Please sign in to comment.