Skip to content

Commit

Permalink
better reviewing system
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrodevog committed Oct 8, 2023
1 parent bde80bd commit 5d7a7fb
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 30 deletions.
46 changes: 29 additions & 17 deletions module/LogisticsBundle/Controller/Admin/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,40 @@ public function viewAction()

$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');
foreach ($articles as $oldMapping) {
$id = $oldMapping->getId();
$amount = '0';
$comment = '';
foreach ($formData as $formKey => $formValue) {
$split = explode("-", $formKey);
$input = $split[0];
$type = $split[1];
$mappingId = $split[2];

if ($input == 'article' && $mappingId == $id) {
if ($type == 'amount') {
$amount = $formValue;
} else {
$booking->setStatus('herzien');
$comment = $formValue;
}
$total += $formValue - $oldAmount;
$this->getEntityManager()->persist($booking);
}
}

$article = $oldMapping->getArticle();
$oldAmount = $oldMapping->getAmount();

if ($article->getUnit() === $reviewingUnit) {
$booking = new OrderArticleMap($newOrder, $article, $amount, $oldAmount, $comment);
if ($oldAmount == $formValue) {
$booking->setStatus('goedgekeurd');
} else {
$booking->setStatus('herzien');
}
$total += $formValue - $oldAmount;
} else {
$booking = new OrderArticleMap($newOrder, $article, $oldAmount, $oldAmount);
}
$this->getEntityManager()->persist($booking);
}
$this->getEntityManager()->flush();

Expand Down
30 changes: 28 additions & 2 deletions module/LogisticsBundle/Entity/Order/OrderArticleMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ class OrderArticleMap
*/
private $status;

/**
* @var string comment about this Article-request in this order, used when review is done
*
* @ORM\Column(name="comment", type="text", options={"default" = ""}, nullable=true)
*/
private $comment;

/**
* @static
* @var array All the possible statuses allowed
Expand Down Expand Up @@ -85,14 +92,17 @@ class OrderArticleMap
* @param Order $order
* @param Article $article
* @param integer $amount
* @param int $oldAmount
* @param integer $oldAmount
* @param string $comment
*/
public function __construct(Order $order, Article $article, $amount, $oldAmount=0)
public function __construct(Order $order, Article $article, $amount, $oldAmount=0, $comment='')
{
$this->referencedOrder = $order;
$this->referencedArticle = $article;
$this->amount = $amount;
$this->oldAmount = $oldAmount;
$this->comment = $comment;

if ($article->getStatusKey() === 'ok') {
$this->status = 'aangevraagd';
} else {
Expand Down Expand Up @@ -180,6 +190,22 @@ public function setStatus($status)
$this->status = $status;
}

/**
* @return string
*/
public function getComment()
{
return $this->comment;
}

/**
* @param string $comment
*/
public function setComment($comment)
{
$this->comment = $comment;
}

/**
* @return boolean
*/
Expand Down
24 changes: 22 additions & 2 deletions module/LogisticsBundle/Form/Admin/Order/OrderArticleMap/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public function init()
$this->add(
array(
'type' => 'text',
'name' => 'article-' . $mapping->getId(),
'name' => 'article-amount-' . $mapping->getId(),
'label' => 'Amount',
'value' => $mapping->getAmount(),
'attributes' => array(
'class' => 'input-very-mini',
'id' => 'article-' . $mapping->getId(),
'id' => 'article-amount-' . $mapping->getId(),
),
'required' => true,
'options' => array(
Expand All @@ -49,6 +49,26 @@ public function init()
)
);

$this->add(
array(
'type' => 'textarea',
'name' => 'article-comment-' . $mapping->getId(),
'label' => 'Comment',
'value' => $mapping->getComment(),
'attributes' => array(
'style' => 'height: 30px;',
'id' => 'article-comment-' . $mapping->getId(),
),
'options' => array(
'input' => array(
'filters' => array(
array('name' => 'StringTrim'),
),
),
),
)
);

$this->addSubmit('articleReview', 'articleSubmit hide');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div id="controller_action" style="width:inherit;">
{% if order.getId() == lastOrders[0].getId() and order.getStatus() == 'Pending' %}
<aside style="margin-top: 32px">
{% if hasAccess('logistics_admin_order', 'review') %}
{% if hasAccess('logistics_admin_order', 'reviewOrder') %}
<div class="sidebox">
<div class="title">Edit Order Info</div>
<div class="content">
Expand Down Expand Up @@ -183,7 +183,7 @@
{% if order.getId() == lastOrders[0].getId() and order.getStatus() == 'Pending' %}
<div class="row" style="margin-top: 30px; text-align: center">
<div style="width: 230px; margin: auto">
{% if hasAccess('logistics_admin_order', 'review') %}
{% if hasAccess('logistics_admin_order', 'reviewOrder') %}
<a class="edit review" style="margin: 6px" href="#" data-id="{{ order.getId() }}">
<b style="padding-left: 5px">Review</b>
</a>
Expand Down Expand Up @@ -295,13 +295,15 @@
var id = $this.data('id');
var name = $this.data('name');
var oldAmount = $this.data('content');
var input = reviewArticle.find('#article-' + id)
var input_amount = reviewArticle.find('#article-amount-' + id);
var input_comment = reviewArticle.find('#article-comment-' + id);
reviewArticle.find('.articleName').html(name);
// Hide all labels and inputs
reviewArticle.find('.form-group').addClass('hide');
// Unhide input and label for article
input.closest('.form-group').removeClass('hide');
input_amount.closest('.form-group').removeClass('hide');
input_comment.closest('.form-group').removeClass('hide');
reviewArticle.find('.edit').unbind('click').click(function () {
reviewArticle.modal('hide');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</div>
<div class="pull-right" style="margin-top: 30px;">
{% if order.getExternalComment() %}
<a rel="popover" style="float: right; background-color: #ed1a1a; padding: 10px"
<a rel="popover" style="float: right; background-color: #ed1a1a; padding: 10px; font-size: 12px"
data-original-title="{{ translate('Logistics remark') }}"
data-content="<span class='badge badge-info'></span> {{ order.getExternalComment() }}<br/>"
data-placement="left" class="label label-warning">{{ translate('Logistics remark') }}</a>
Expand Down Expand Up @@ -94,7 +94,7 @@
<th style="width: 25%">{{ Translate('Name') }}</th>
<th style="width: 25%">{{ Translate('Unit') }}</th>
<th style="width: 20%">{{ Translate('Status') }}</th>
<th style="width: 20%">{{ Translate('Description') }}</th>
<th style="width: 20%">{{ Translate('Comment') }}</th>
<th style="width: 10%">{{ Translate('Amount') }}</th>
</tr>

Expand All @@ -107,9 +107,10 @@
<td>{{ mapping.getArticle().getName() }}</td>
<td>{{ mapping.getArticle().getUnit().getName() }}</td>
<td>{{ mapping.getStatus() }}</td>
<td>{% if mapping.getArticle().getAdditionalInfo()|length > 1 %}
<a rel="popover" data-original-title="{{ translate('Comments') }}"
data-content="<span class='badge badge-info'></span> {{ mapping.getArticle().getAdditionalInfo() }}<br/>"
<td>{% if mapping.getComment()|length > 0 %}
<a rel="popover" style="background-color: #ed1a1a;"
data-original-title="{{ translate('Comments') }}"
data-content="<span class='badge badge-info'></span> {{ mapping.getComment() }}<br/>"
data-placement="left" class="label label-warning">{{ translate('Remark') }}</a>
{% endif %}</td>
<td>{{ mapping.getAmount() }}</td>
Expand Down

0 comments on commit 5d7a7fb

Please sign in to comment.