diff --git a/src/Controller/Admin/EcheancierController.php b/src/Controller/Admin/EcheancierController.php index 10477b1..6968aaf 100644 --- a/src/Controller/Admin/EcheancierController.php +++ b/src/Controller/Admin/EcheancierController.php @@ -51,7 +51,9 @@ class EcheancierController extends AbstractController } $totalHtFloat = (float) str_replace(',', '.', $totalHt); - $monthlyAmount = round($totalHtFloat / $nbEcheances, 2); + $majoration = round($totalHtFloat * Echeancier::MAJORATION_RATE, 2); + $totalMajore = round($totalHtFloat + $majoration, 2); + $monthlyAmount = round($totalMajore / $nbEcheances, 2); $echeancier = new Echeancier($customer, $description, number_format($totalHtFloat, 2, '.', '')); @@ -65,7 +67,7 @@ class EcheancierController extends AbstractController for ($i = 1; $i <= $nbEcheances; ++$i) { $scheduledAt = $start->modify('+'.($i - 1).' months'); $amount = $i === $nbEcheances - ? number_format($totalHtFloat - ($monthlyAmount * ($nbEcheances - 1)), 2, '.', '') + ? number_format($totalMajore - ($monthlyAmount * ($nbEcheances - 1)), 2, '.', '') : number_format($monthlyAmount, 2, '.', ''); $line = new EcheancierLine($echeancier, $i, $amount, $scheduledAt); diff --git a/src/Entity/Echeancier.php b/src/Entity/Echeancier.php index ba6d1e5..5ccc1a1 100644 --- a/src/Entity/Echeancier.php +++ b/src/Entity/Echeancier.php @@ -340,8 +340,26 @@ class Echeancier return $this; } + public const MAJORATION_RATE = 0.05; + // ── Computed ── + /** + * Montant de la majoration (5% du montant total). + */ + public function getMajoration(): float + { + return round((float) $this->totalAmountHt * self::MAJORATION_RATE, 2); + } + + /** + * Montant total avec majoration (total + 5%). + */ + public function getTotalWithMajoration(): float + { + return round((float) $this->totalAmountHt + $this->getMajoration(), 2); + } + public function getNbLines(): int { return $this->lines->count(); @@ -391,12 +409,12 @@ class Echeancier } /** - * Montant mensuel (total / nb echeances). + * Montant mensuel (total majore / nb echeances). */ public function getMonthlyAmount(): float { $nb = $this->getNbLines(); - return $nb > 0 ? round((float) $this->totalAmountHt / $nb, 2) : 0.0; + return $nb > 0 ? round($this->getTotalWithMajoration() / $nb, 2) : 0.0; } } diff --git a/src/Service/Pdf/EcheancierPdf.php b/src/Service/Pdf/EcheancierPdf.php index 9787c89..7b87347 100644 --- a/src/Service/Pdf/EcheancierPdf.php +++ b/src/Service/Pdf/EcheancierPdf.php @@ -128,10 +128,22 @@ class EcheancierPdf extends Fpdi $labelW = 55; $this->SetFont('Arial', '', 10); - $this->Cell($labelW, 6, $this->enc('Montant total HT :'), 0, 0, 'L'); + $this->Cell($labelW, 6, $this->enc('Montant de la creance :'), 0, 0, 'L'); $this->SetFont('Arial', 'B', 10); $this->Cell(0, 6, number_format((float) $this->echeancier->getTotalAmountHt(), 2, ',', ' ').' '.EURO, 0, 1, 'L'); + $this->SetFont('Arial', '', 10); + $this->Cell($labelW, 6, $this->enc('Majoration (5%) :'), 0, 0, 'L'); + $this->SetFont('Arial', 'B', 10); + $this->SetTextColor(220, 38, 38); + $this->Cell(0, 6, '+ '.number_format($this->echeancier->getMajoration(), 2, ',', ' ').' '.EURO, 0, 1, 'L'); + $this->SetTextColor(0, 0, 0); + + $this->SetFont('Arial', '', 10); + $this->Cell($labelW, 6, $this->enc('Total a payer :'), 0, 0, 'L'); + $this->SetFont('Arial', 'B', 11); + $this->Cell(0, 6, number_format($this->echeancier->getTotalWithMajoration(), 2, ',', ' ').' '.EURO, 0, 1, 'L'); + $this->SetFont('Arial', '', 10); $this->Cell($labelW, 6, $this->enc('Nombre d\'echeances :'), 0, 0, 'L'); $this->SetFont('Arial', 'B', 10); @@ -182,11 +194,11 @@ class EcheancierPdf extends Fpdi $fill = !$fill; } - // Total + // Total avec majoration $this->SetFont('Arial', 'B', 10); $this->SetFillColor(253, 191, 4); - $this->Cell(70, 8, $this->enc(' TOTAL'), 0, 0, 'L', true); - $this->Cell(50, 8, number_format((float) $this->echeancier->getTotalAmountHt(), 2, ',', ' ').' '.EURO, 0, 0, 'R', true); + $this->Cell(70, 8, $this->enc(' TOTAL (creance + majoration 5%)'), 0, 0, 'L', true); + $this->Cell(50, 8, number_format($this->echeancier->getTotalWithMajoration(), 2, ',', ' ').' '.EURO, 0, 0, 'R', true); $this->Cell(50, 8, '', 0, 1, 'C', true); $this->Ln(5); diff --git a/templates/admin/echeancier/show.html.twig b/templates/admin/echeancier/show.html.twig index 280b9a1..118d4db 100644 --- a/templates/admin/echeancier/show.html.twig +++ b/templates/admin/echeancier/show.html.twig @@ -39,8 +39,9 @@ {# Resume #}
-

Montant total

-

{{ echeancier.totalAmountHt|number_format(2, ',', ' ') }} €

+

Creance + majoration 5%

+

{{ echeancier.totalWithMajoration|number_format(2, ',', ' ') }} €

+

{{ echeancier.totalAmountHt|number_format(2, ',', ' ') }} + {{ echeancier.majoration|number_format(2, ',', ' ') }} €

Mensualite

diff --git a/templates/echeancier/process.html.twig b/templates/echeancier/process.html.twig index 4bf241a..9ff4f82 100644 --- a/templates/echeancier/process.html.twig +++ b/templates/echeancier/process.html.twig @@ -28,14 +28,19 @@
{# Resume #} -
+
-

Total HT

+

Creance

{{ echeancier.totalAmountHt|number_format(2, ',', ' ') }} €

-

Echeances

-

{{ echeancier.nbLines }} mois

+

Majoration 5%

+

+ {{ echeancier.majoration|number_format(2, ',', ' ') }} €

+
+
+

Total a payer

+

{{ echeancier.totalWithMajoration|number_format(2, ',', ' ') }} €

+

en {{ echeancier.nbLines }} mois

Mensualite

diff --git a/templates/emails/echeancier_proposition.html.twig b/templates/emails/echeancier_proposition.html.twig index 24868c1..e926c4f 100644 --- a/templates/emails/echeancier_proposition.html.twig +++ b/templates/emails/echeancier_proposition.html.twig @@ -17,8 +17,16 @@ {{ echeancier.description }} - Montant total HT - {{ echeancier.totalAmountHt }} € + Montant de la creance + {{ echeancier.totalAmountHt }} € + + + Majoration (5%) + + {{ echeancier.majoration|number_format(2, ',', ' ') }} € + + + Total a payer + {{ echeancier.totalWithMajoration|number_format(2, ',', ' ') }} € Nombre d'echeances