Skip to content

Commit

Permalink
Merge branch 'master' of github.com:LitusProject/Litus
Browse files Browse the repository at this point in the history
  • Loading branch information
rserry committed Sep 26, 2023
2 parents ee9ad14 + 6540246 commit 54b7a44
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 182 deletions.
151 changes: 74 additions & 77 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 @@ -69,6 +76,64 @@ public function viewAction()
)
);

if ($this->getRequest()->isPost()) {
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 {
$this->getEntityManager()->flush();

$this->flashMessenger()->success(
'Success',
'The request was successfully reviewed.'
);
}
$this->redirect()->toRoute(
'logistics_admin_request',
array(
'action' => 'manage',
)
);

return new ViewModel();
}
}
}

return new ViewModel(
array(
'order' => $order,
Expand All @@ -85,51 +150,36 @@ public function viewAction()
public function reviewOrderAction()
{
$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();
}

$orderForm = $this->getForm('logistics_admin_order_review', $order);
$orderForm = $this->getForm('logistics_admin_order_review');

if ($this->getRequest()->isPost()) {
$orderForm->setData($this->getRequest()->getPost());

return new ViewModel(
array(
'result' => (object)array('status' => json_encode($this->getRequest()->getPost())),
)
);



if ($orderForm->isValid()) {

$newOrder = $this->recreateOrder($orderForm->getOrder(), $academic->getUnit($this->getCurrentAcademicYear())->getName());
// $newOrder = $this->recreateOrder($order, $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);

$request = $order->getRequest();
$request->handled();

$this->getEntityManager()->persist($newOrder);
$this->getEntityManager()->flush();

// $this->sendMailToContact($request);
$this->flashMessenger()->success(
'Success',
'The request was succesfully reviewed.'
);


return new ViewModel(
array(
'result' => (object)array('status' => 'success'),
Expand All @@ -141,59 +191,6 @@ public function reviewOrderAction()
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(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();
}

public function approveAction()
{
$academic = $this->getAcademicEntity();
Expand Down
3 changes: 1 addition & 2 deletions module/LogisticsBundle/Controller/InventoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LogisticsBundle\Controller;

use DateTime;
use Laminas\View\Model\ViewModel;
use LogisticsBundle\Entity\Inventory;

Expand All @@ -16,8 +17,6 @@ public function indexAction()
$this->getParam('page')
);

$presentDate = date('');

return new ViewModel(
array(
'paginator' => $paginator,
Expand Down
8 changes: 8 additions & 0 deletions module/LogisticsBundle/Entity/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LogisticsBundle\Entity;

use DateTime;
use Doctrine\ORM\Mapping as ORM;

/**
Expand Down Expand Up @@ -115,6 +116,13 @@ class Inventory
*/
private $expiryDate;

/**
* @var DateTime The expiry date
*
* @ORM\Column(name="expiry_date_", type="DateTime", nullable=true)
*/
private $expiryDate_;

/**
* Inventory constructor
*/
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function init()
),
)
);

$this->addSubmit('articleReview', 'articleSubmit hide');
}
}

Expand Down
2 changes: 1 addition & 1 deletion module/LogisticsBundle/Form/Admin/Order/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function init()
{
parent::init();

$this->remove('submit')->addSubmit('review', 'hide');
$this->remove('submit')->addSubmit('orderReview', 'orderSubmit hide');

if ($this->order !== null) {
$this->bind($this->order);
Expand Down
3 changes: 1 addition & 2 deletions module/LogisticsBundle/Form/Inventory/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public function init()
{
parent::init();

$nameField = $this->get('name');
$nameField->setRequired();
$nameField = $this->get('name')->setRequired();

// $this->remove('unit')->remove('perUnit');

Expand Down
11 changes: 6 additions & 5 deletions module/LogisticsBundle/Resources/layouts/logistics/base.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<a href="{{ url('logistics_catalog', {"language": language.getAbbrev()}) }}">{{ translate('Material') }}</a>
</li>
{% endif %}
{% if hasAccess('logistics_inventory', 'index') %}
<li {% if 'logistics_inventory' == getParam('controller') %}class="active"{% endif %}>
<a href="{{ url('logistics_inventory', {"language": language.getAbbrev()}) }}">{{ translate('Flesserke') }}</a>
</li>
{% endif %}
{% if hasAccess('logistics_index', 'index') %}
<li {% if 'logistics_index' == getParam('controller') %} class="active" {% endif %}>
<a href="{{ url("logistics_index", {"language": language.getAbbrev()}) }}">{{ translate('Van') }}</a>
Expand All @@ -42,11 +47,7 @@
{# <a href="{{ url('logistics_lease', {"language": language.getAbbrev()}) }}">{{ translate('Lease') }}</a>#}
{# </li>#}
{# {% endif %}#}
{% if hasAccess('logistics_inventory', 'index') %}
<li {% if 'logistics_inventory' == getParam('controller') %}class="active"{% endif %}>
<a href="{{ url('logistics_inventory', {"language": language.getAbbrev()}) }}">{{ translate('Inventory') }}</a>
</li>
{% endif %}

{# {% if hasAccess('logistics_inventory', 'add') %}#}
{# <li {% if 'logistics_inventory' == getParam('controller') %}class="active"{% endif %}>#}
{# <a href="{{ url('logistics_inventory', {"language": language.getAbbrev(), 'action': 'add'}) }}">{{ translate('Flesserke Form') }}</a>#}
Expand Down
Loading

0 comments on commit 54b7a44

Please sign in to comment.