Skip to content

Commit

Permalink
review function + approved interface
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrodevog committed Sep 27, 2023
1 parent 3dd1002 commit 64063ec
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 43 deletions.
108 changes: 83 additions & 25 deletions module/LogisticsBundle/Controller/Admin/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,20 @@ 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(
'Warning',
'You have not reviewed any articles!'
);
} else {
$this->getEntityManager()->flush();

$this->flashMessenger()->success(
'Success',
'The request was successfully reviewed.'
Expand Down Expand Up @@ -176,18 +177,13 @@ 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'),
)
);
}
}

return new ViewModel();
}

Expand All @@ -197,6 +193,7 @@ public function approveAction()
if ($academic === null) {
return new ViewModel();
}
$reviewingUnit = $academic->getUnit($this->getCurrentAcademicYear());

$order = $this->getOrderEntity();
if ($order === null) {
Expand All @@ -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',
Expand All @@ -250,6 +260,7 @@ public function rejectAction()
if ($academic === null) {
return new ViewModel();
}
$reviewingUnit = $academic->getUnit($this->getCurrentAcademicYear());

$order = $this->getOrderEntity();
if ($order === null) {
Expand All @@ -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',
Expand Down Expand Up @@ -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
Expand Down
36 changes: 29 additions & 7 deletions module/LogisticsBundle/Controller/Admin/RequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

/**
Expand Down
16 changes: 16 additions & 0 deletions module/LogisticsBundle/Entity/Order/OrderArticleMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
12 changes: 6 additions & 6 deletions module/LogisticsBundle/Repository/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading

0 comments on commit 64063ec

Please sign in to comment.