add expense report validator
This commit is contained in:
parent
62d3141813
commit
9b5a655574
|
@ -151,6 +151,14 @@ class ExpenseReportAdminController extends CrudController
|
|||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
if ($entity->getTotalAmount() === 0.0) {
|
||||
$this->addFlash('warning', 'Cette action est interdite car le total de la note de frais est 0.');
|
||||
|
||||
return $this->redirectToRoute('admin_expense_report_edit', [
|
||||
'entity' => $entity->getId(),
|
||||
]);
|
||||
}
|
||||
|
||||
$message = $request->request->get('form')['message'] ?? null;
|
||||
$entity->setIsRequestedPayment(true);
|
||||
$entityManager->update($entity);
|
||||
|
@ -185,6 +193,14 @@ class ExpenseReportAdminController extends CrudController
|
|||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
if ($entity->getTotalAmount() === 0.0) {
|
||||
$this->addFlash('warning', 'Cette action est interdite car le total de la note de frais est 0.');
|
||||
|
||||
return $this->redirectToRoute('admin_expense_report_edit', [
|
||||
'entity' => $entity->getId(),
|
||||
]);
|
||||
}
|
||||
|
||||
$message = $request->request->get('form')['message'] ?? null;
|
||||
$entity->setIsPaid(true);
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Core\Entity\EntityInterface;
|
||||
use App\Repository\ExpenseReportRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass=ExpenseReportRepository::class)
|
||||
|
@ -193,4 +193,30 @@ class ExpenseReport implements EntityInterface
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTotalAmount(?string $of = null, array $data = []): float
|
||||
{
|
||||
$amount = 0;
|
||||
|
||||
if ('moves' === $of) {
|
||||
foreach ($this->getMoves() as $data) {
|
||||
$amount += $this->getTotalAmount('move', $data);
|
||||
}
|
||||
} elseif ('various_payments' === $of) {
|
||||
foreach ($this->getVariousPayments() as $data) {
|
||||
$amount += $this->getTotalAmount('various_payment', $data);
|
||||
}
|
||||
} elseif ('move' === $of) {
|
||||
$amount += $data['highwayPay'];
|
||||
$amount += $data['parkingPay'];
|
||||
$amount += ($data['isRoundTrip'] ? 2 : 1) * $data['distance'] * $this->getScalePerKilometer();
|
||||
} elseif ('various_payment' === $of) {
|
||||
$amount += $data['amount'];
|
||||
} else {
|
||||
$amount += $this->getTotalAmount('moves');
|
||||
$amount += $this->getTotalAmount('various_payments');
|
||||
}
|
||||
|
||||
return $amount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<table class="table mb-0">
|
||||
<thead class="bg-light">
|
||||
<tr>
|
||||
<th width="100">Date</th>
|
||||
<th width="120">Date</th>
|
||||
<th>Évènement</th>
|
||||
<th>Trajet</th>
|
||||
<th width="120" class="text-right">Distance</th>
|
||||
|
@ -35,15 +35,13 @@
|
|||
{{ item.isRoundTrip ? 'oui' : 'non' }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{{ item.highwayPay > 0 ? (item.highwayPay ~ '€') : '-' }}
|
||||
{{ item.highwayPay > 0 ? (item.highwayPay|number_format(2, ',') ~ '€') : '-' }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{{ item.parkingPay > 0 ? (item.parkingPay ~ '€') : '-' }}
|
||||
{{ item.parkingPay > 0 ? (item.parkingPay|number_format(2, ',') ~ '€') : '-' }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{% set itemTotal = item.parkingPay + item.highwayPay + (item.distance * entity.scalePerKilometer * (item.isRoundTrip ? 2 : 1)) %}
|
||||
{% set total = total + itemTotal %}
|
||||
{{ itemTotal }}€
|
||||
{{ entity.totalAmount('move', item)|number_format(2, ',') }}€
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -56,7 +54,7 @@
|
|||
<table class="table mb-0">
|
||||
<thead class="bg-light">
|
||||
<tr>
|
||||
<th width="100">Date</th>
|
||||
<th width="120">Date</th>
|
||||
<th>Libellé</th>
|
||||
<th width="90" class="text-right">Montant TTC</th>
|
||||
</tr>
|
||||
|
@ -71,9 +69,7 @@
|
|||
{{ item.label }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{% set total = total + item.amount %}
|
||||
|
||||
{{ item.amount ~ '€' }}
|
||||
{{ entity.totalAmount('various_payment', item)|number_format(2, ',') }}€
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -84,10 +80,10 @@
|
|||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<tr>
|
||||
<td class="font-weight-bold">
|
||||
<td>
|
||||
Facture(s)
|
||||
</td>
|
||||
<td class="text-right"><span class="font-weight-bold mr-3">Total</span> {{ total }}€</td>
|
||||
<td class="text-right"><span class="font-weight-bold mr-3">Total</span> {{ entity.totalAmount|number_format(2, ',') }}€</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
|
@ -100,6 +96,10 @@
|
|||
{% endfor %}
|
||||
</td>
|
||||
<td width="250" class="text-right">
|
||||
Barème au kilomètre : {{ entity.scalePerKilometer|number_format(2, ',') }}
|
||||
<br>
|
||||
<br>
|
||||
|
||||
{% if entity.isPaid %}
|
||||
{% if entity.paidAt %}
|
||||
<span class="btn btn-success">Payée le {{ entity.paidAt|date('d/m/Y à H:i') }}</span>
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
{% extends '@Core/admin/crud/edit.html.twig' %}
|
||||
|
||||
{% block header_actions_after %}
|
||||
{% if not entity.isPaid %}
|
||||
{% if not entity.isRequestedPayment and (entity.user.id == app.user.id or is_granted('ROLE_TREASURER')) %}
|
||||
<span class="btn btn-success" data-toggle="modal" data-target="#notification">
|
||||
Demander le paiement
|
||||
</span>
|
||||
{% endif %}
|
||||
{% if entity.totalAmount > 0 %}
|
||||
{% if not entity.isPaid %}
|
||||
{% if not entity.isRequestedPayment and (entity.user.id == app.user.id or is_granted('ROLE_TREASURER')) %}
|
||||
<span class="btn btn-success" data-toggle="modal" data-target="#notification">
|
||||
Demander le paiement
|
||||
</span>
|
||||
{% endif %}
|
||||
|
||||
{% if entity.isRequestedPayment and is_granted('ROLE_TREASURER') %}
|
||||
<span class="btn btn-success" data-toggle="modal" data-target="#notification">
|
||||
Définir comme payée
|
||||
</span>
|
||||
{% if entity.isRequestedPayment and is_granted('ROLE_TREASURER') %}
|
||||
<span class="btn btn-success" data-toggle="modal" data-target="#notification">
|
||||
Définir comme payée
|
||||
</span>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue