diff --git a/src/Controller/Admin/ContratController.php b/src/Controller/Admin/ContratController.php index 227c77f..da7bade 100644 --- a/src/Controller/Admin/ContratController.php +++ b/src/Controller/Admin/ContratController.php @@ -56,7 +56,26 @@ class ContratController extends AbstractController return $this->redirectToRoute('app_admin_contrats_index'); } + // Recuperer les services + $serviceKeys = $request->request->all('service_key'); + $serviceQtys = $request->request->all('service_qty'); + $services = []; + + foreach ($serviceKeys as $i => $key) { + if ('' !== $key && isset(Contrat::SERVICE_CATALOG[$key])) { + $qty = (int) ($serviceQtys[$i] ?? 1); + if ($qty > 0) { + $services[] = [ + 'service' => $key, + 'quantity' => $qty, + 'priceHt' => Contrat::SERVICE_CATALOG[$key]['price'], + ]; + } + } + } + $contrat = new Contrat($email, $raisonSociale, $type); + $contrat->setServices($services); $this->em->persist($contrat); $this->em->flush(); diff --git a/src/Entity/Contrat.php b/src/Entity/Contrat.php index 9d34510..7766912 100644 --- a/src/Entity/Contrat.php +++ b/src/Entity/Contrat.php @@ -21,6 +21,20 @@ class Contrat self::TYPE_MIGRATION_SITECONSEIL => 'Contrat de Service - Migration SARL SITECONSEIL', ]; + public const SERVICE_CATALOG = [ + 'esite_vitrine' => ['label' => 'E-Site Vitrine', 'price' => '100.00', 'unit' => '/mois'], + 'esite_ecommerce' => ['label' => 'E-Site E-Commerce', 'price' => '150.00', 'unit' => '/mois'], + 'esite_hors_cms' => ['label' => 'Site hors CMS Esy-Web (hebergement seul)', 'price' => '100.00', 'unit' => '/mois'], + 'email_3go' => ['label' => 'E-Mail 3 Go', 'price' => '1.00', 'unit' => '/mois'], + 'email_50go' => ['label' => 'E-Mail 50 Go', 'price' => '5.00', 'unit' => '/mois'], + 'ndd_gestion' => ['label' => 'Nom de domaine - Gestion', 'price' => '30.00', 'unit' => '/an'], + 'ndd_renouvellement' => ['label' => 'Nom de domaine - Renouvellement', 'price' => '20.00', 'unit' => '/an'], + 'eprotect' => ['label' => 'E-Protect Pro', 'price' => '60.00', 'unit' => '/trimestre'], + 'ecalendar' => ['label' => 'E-Calendar', 'price' => '30.00', 'unit' => '/mois'], + 'echat' => ['label' => 'E-Chat', 'price' => '15.00', 'unit' => '/mois'], + 'emailer' => ['label' => 'E-Mailer', 'price' => '30.00', 'unit' => '/mois'], + ]; + #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] @@ -35,6 +49,10 @@ class Contrat #[ORM\Column(length: 50)] private string $type; + /** @var list */ + #[ORM\Column(type: 'json')] + private array $services = []; + #[ORM\Column(length: 20, options: ['default' => 'draft'])] private string $state = self::STATE_DRAFT; @@ -152,6 +170,30 @@ class Contrat return $this; } + /** @return list */ + public function getServices(): array + { + return $this->services; + } + + /** @param list $services */ + public function setServices(array $services): static + { + $this->services = $services; + + return $this; + } + + public function getTotalHt(): float + { + $total = 0.0; + foreach ($this->services as $s) { + $total += (float) $s['priceHt'] * $s['quantity']; + } + + return $total; + } + public function getSubmissionId(): ?string { return $this->submissionId; diff --git a/src/Service/Pdf/ContratMigrationSiteconseilPdf.php b/src/Service/Pdf/ContratMigrationSiteconseilPdf.php index 1ab7f25..9e66d0e 100644 --- a/src/Service/Pdf/ContratMigrationSiteconseilPdf.php +++ b/src/Service/Pdf/ContratMigrationSiteconseilPdf.php @@ -24,6 +24,7 @@ class ContratMigrationSiteconseilPdf extends Fpdi $this->writeHeader(); $this->writePreambule(); + $this->writeServicesTable(); $this->writeArticles(); $this->writeSignatures(); } @@ -166,6 +167,61 @@ class ContratMigrationSiteconseilPdf extends Fpdi $this->Ln(5); } + /** @codeCoverageIgnore */ + private function writeServicesTable(): void + { + $services = $this->contrat->getServices(); + if ([] === $services) { + return; + } + + if ($this->GetY() + 30 > $this->GetPageHeight() - 25) { + $this->AddPage(); + } + + $this->SetFont('Arial', 'B', 11); + $this->SetFillColor(250, 191, 4); + $this->Cell(0, 8, $this->enc(' SERVICES INCLUS DANS LE CONTRAT'), 0, 1, 'L', true); + $this->Ln(4); + + // Header tableau + $this->SetFont('Arial', 'B', 9); + $this->SetFillColor(35, 35, 35); + $this->SetTextColor(255, 255, 255); + $this->Cell(80, 7, $this->enc(' Service'), 1, 0, 'L', true); + $this->Cell(20, 7, $this->enc('Qte'), 1, 0, 'C', true); + $this->Cell(40, 7, $this->enc('Prix unitaire HT'), 1, 0, 'R', true); + $this->Cell(40, 7, $this->enc('Sous-total HT'), 1, 1, 'R', true); + $this->SetTextColor(0, 0, 0); + + $this->SetFont('Arial', '', 9); + $fill = false; + $catalog = \App\Entity\Contrat::SERVICE_CATALOG; + + foreach ($services as $s) { + $this->SetFillColor(245, 245, 240); + $label = $catalog[$s['service']]['label'] ?? $s['service']; + $unit = $catalog[$s['service']]['unit'] ?? ''; + $qty = $s['quantity']; + $price = (float) $s['priceHt']; + $subtotal = $price * $qty; + + $this->Cell(80, 6, $this->enc(' '.$label), 'B', 0, 'L', $fill); + $this->Cell(20, 6, (string) $qty, 'B', 0, 'C', $fill); + $this->Cell(40, 6, number_format($price, 2, ',', ' ').' '.EURO.' '.$unit, 'B', 0, 'R', $fill); + $this->Cell(40, 6, number_format($subtotal, 2, ',', ' ').' '.EURO, 'B', 1, 'R', $fill); + + $fill = !$fill; + } + + // Total + $this->SetFont('Arial', 'B', 10); + $this->Cell(140, 8, $this->enc('TOTAL HT'), 0, 0, 'R'); + $this->Cell(40, 8, number_format($this->contrat->getTotalHt(), 2, ',', ' ').' '.EURO, 0, 1, 'R'); + + $this->Ln(5); + } + /** @codeCoverageIgnore */ private function writeArticles(): void { diff --git a/templates/admin/contrats/index.html.twig b/templates/admin/contrats/index.html.twig index d8dd70e..b98e833 100644 --- a/templates/admin/contrats/index.html.twig +++ b/templates/admin/contrats/index.html.twig @@ -62,7 +62,7 @@ {# Modal creation #} + + {% endblock %} diff --git a/templates/admin/contrats/show.html.twig b/templates/admin/contrats/show.html.twig index 3d09017..5beec23 100644 --- a/templates/admin/contrats/show.html.twig +++ b/templates/admin/contrats/show.html.twig @@ -54,6 +54,54 @@ + {# Services #} + {% if contrat.services|length > 0 %} +
+

Services inclus

+
+ + + + + + + + + + + {% set catalogLabels = { + 'esite_vitrine': 'E-Site Vitrine', + 'esite_ecommerce': 'E-Site E-Commerce', + 'esite_hors_cms': 'Site hors CMS Esy-Web', + 'email_3go': 'E-Mail 3 Go', + 'email_50go': 'E-Mail 50 Go', + 'ndd_gestion': 'Nom de domaine - Gestion', + 'ndd_renouvellement': 'Nom de domaine - Renouvellement', + 'eprotect': 'E-Protect Pro', + 'ecalendar': 'E-Calendar', + 'echat': 'E-Chat', + 'emailer': 'E-Mailer' + } %} + {% for s in contrat.services %} + + + + + + + {% endfor %} + + + + + + + +
ServiceQuantitePrix unitaire HTSous-total HT
{{ catalogLabels[s.service] ?? s.service }}{{ s.quantity }}{{ s.priceHt|number_format(2, ',', ' ') }} €{{ (s.priceHt * s.quantity)|number_format(2, ',', ' ') }} €
Total HT{{ contrat.totalHt|number_format(2, ',', ' ') }} €
+
+
+ {% endif %} + {# Actions #}
{% if contrat.state == 'draft' %}