diff --git a/src/Controller/ExpenseReportAdminController.php b/src/Controller/ExpenseReportAdminController.php index 4b5b252..20009b8 100644 --- a/src/Controller/ExpenseReportAdminController.php +++ b/src/Controller/ExpenseReportAdminController.php @@ -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); diff --git a/src/Entity/ExpenseReport.php b/src/Entity/ExpenseReport.php index d3870f3..fea36e7 100644 --- a/src/Entity/ExpenseReport.php +++ b/src/Entity/ExpenseReport.php @@ -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; + } } diff --git a/templates/admin/expense_report/_show.html.twig b/templates/admin/expense_report/_show.html.twig index 8aa05b5..f1b81e4 100644 --- a/templates/admin/expense_report/_show.html.twig +++ b/templates/admin/expense_report/_show.html.twig @@ -5,7 +5,7 @@ - + @@ -35,15 +35,13 @@ {{ item.isRoundTrip ? 'oui' : 'non' }} {% endfor %} @@ -56,7 +54,7 @@
DateDate Évènement Trajet Distance - {{ item.highwayPay > 0 ? (item.highwayPay ~ '€') : '-' }} + {{ item.highwayPay > 0 ? (item.highwayPay|number_format(2, ',') ~ '€') : '-' }} - {{ item.parkingPay > 0 ? (item.parkingPay ~ '€') : '-' }} + {{ item.parkingPay > 0 ? (item.parkingPay|number_format(2, ',') ~ '€') : '-' }} - {% 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, ',') }}€
- + @@ -71,9 +69,7 @@ {{ item.label }} {% endfor %} @@ -84,10 +80,10 @@
DateDate Libellé Montant TTC
- {% set total = total + item.amount %} - - {{ item.amount ~ '€' }} + {{ entity.totalAmount('various_payment', item)|number_format(2, ',') }}€
- - +
+ Facture(s) Total {{ total }}€Total {{ entity.totalAmount|number_format(2, ',') }}€
@@ -100,6 +96,10 @@ {% endfor %} + Barème au kilomètre : {{ entity.scalePerKilometer|number_format(2, ',') }} +
+
+ {% if entity.isPaid %} {% if entity.paidAt %} Payée le {{ entity.paidAt|date('d/m/Y à H:i') }} diff --git a/templates/admin/expense_report/edit.html.twig b/templates/admin/expense_report/edit.html.twig index 122aba4..c5e86fd 100644 --- a/templates/admin/expense_report/edit.html.twig +++ b/templates/admin/expense_report/edit.html.twig @@ -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')) %} - - Demander le paiement - - {% 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')) %} + + Demander le paiement + + {% endif %} - {% if entity.isRequestedPayment and is_granted('ROLE_TREASURER') %} - - Définir comme payée - + {% if entity.isRequestedPayment and is_granted('ROLE_TREASURER') %} + + Définir comme payée + + {% endif %} {% endif %} {% endif %} {% endblock %}