From 2eb770a328e2abdcf65d1017767f73257e5defe8 Mon Sep 17 00:00:00 2001 From: Ryjek Date: Sat, 27 Sep 2025 21:09:59 +0200 Subject: [PATCH] add highlight report --- project/migrations/Version20250329215035.php | 31 +++++++++++++++++ project/migrations/Version20250330100207.php | 31 +++++++++++++++++ project/src/Controller/BaseController.php | 4 ++- project/src/Controller/ClientController.php | 18 +++++++++- project/src/Controller/ReportsController.php | 16 +++++++++ project/src/Entity/Clients.php | 16 +++++++++ project/src/Entity/Reports.php | 16 +++++++++ project/src/Enum/ReportHighlight.php | 32 ++++++++++++++++++ project/templates/customers/show.html.twig | 15 +++++++++ project/templates/reports/list.html.twig | 2 +- .../templates/reports/listInclude.html.twig | 33 ++++++++++++++++--- 11 files changed, 207 insertions(+), 7 deletions(-) create mode 100644 project/migrations/Version20250329215035.php create mode 100644 project/migrations/Version20250330100207.php create mode 100644 project/src/Enum/ReportHighlight.php diff --git a/project/migrations/Version20250329215035.php b/project/migrations/Version20250329215035.php new file mode 100644 index 0000000..d76cc02 --- /dev/null +++ b/project/migrations/Version20250329215035.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE reports ADD highlight INT DEFAULT 0 NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE reports DROP highlight'); + } +} diff --git a/project/migrations/Version20250330100207.php b/project/migrations/Version20250330100207.php new file mode 100644 index 0000000..16151bf --- /dev/null +++ b/project/migrations/Version20250330100207.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE clients ADD highlight INT DEFAULT 0 NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE clients DROP highlight'); + } +} diff --git a/project/src/Controller/BaseController.php b/project/src/Controller/BaseController.php index b759c82..d1c5c09 100644 --- a/project/src/Controller/BaseController.php +++ b/project/src/Controller/BaseController.php @@ -8,6 +8,7 @@ use App\Entity\ReportsTodo; use App\Enum\Months; use App\Enum\ReportStatus; use App\Enum\ReportTodoEnum; +use App\Enum\ReportHighlight; use App\Helper\MonthHelper; use App\Services\OverdueReports; use Doctrine\ORM\EntityManagerInterface; @@ -80,7 +81,8 @@ class BaseController extends AbstractController 'isOverdue' => $isOverdue, 'countOverdueLeft' => $overdueReports->getLeftCount(), 'client' => $client, - 'clientId' => $clientId + 'clientId' => $clientId, + 'highlightStatus' => ReportHighlight::cases() ]); } diff --git a/project/src/Controller/ClientController.php b/project/src/Controller/ClientController.php index 6aef647..c31ca11 100644 --- a/project/src/Controller/ClientController.php +++ b/project/src/Controller/ClientController.php @@ -6,6 +6,7 @@ use App\Entity\Clients; use App\Entity\Notes; use App\Entity\Reports; use App\Entity\Schedule; +use App\Enum\ReportHighlight; use App\Enum\ReportStatus; use App\Enum\ReportTodoEnum; use App\Services\AddReports; @@ -59,7 +60,8 @@ class ClientController extends AbstractController 'notes' => $notes, 'backUrl' => $request->headers->get('referer'), 'reportToDoList' => ReportTodoEnum::cases(), - 'reportStatus' => ReportStatus::INSERT + 'reportStatus' => ReportStatus::INSERT, + 'highlightStatus' => ReportHighlight::cases() ]); } #[Route('/dodaj_klienta/{id}', name: 'app_add_client', defaults: ['id'=>0])] @@ -165,4 +167,18 @@ class ClientController extends AbstractController ->add('submitAndRedirect', SubmitType::class, ) ->getForm(); } + + #[Route('/client_highlight/{id}', name: 'app_client_highlight', methods: ['POST'])] + public function updateHighlight(EntityManagerInterface $entityManager, Request $request, Clients $client): Response + { + $token = $request->get("token"); + if ($this->isCsrfTokenValid('client-highlight', $token)) { + $highlightId = intval($request->get("highlight_id")); + $highlight = ReportHighlight::tryFrom($highlightId); + $client->setHighlight($highlight); + $entityManager->persist($client); + $entityManager->flush(); + } + return $this->redirectToRoute('app_client', ['id'=>$client->getId()]); + } } \ No newline at end of file diff --git a/project/src/Controller/ReportsController.php b/project/src/Controller/ReportsController.php index fb1a55b..c77310c 100644 --- a/project/src/Controller/ReportsController.php +++ b/project/src/Controller/ReportsController.php @@ -4,7 +4,9 @@ namespace App\Controller; use App\Entity\Clients; use App\Entity\Reports; use App\Entity\ReportsTodo; +use App\Entity\Schedule; use App\Enum\ReportTodoEnum; +use App\Enum\ReportHighlight; use App\Services\AddReports; use App\Services\InvoiceServices; use Doctrine\ORM\EntityManagerInterface; @@ -114,4 +116,18 @@ class ReportsController extends AbstractController { return new Response(var_export($_POST,true)); } + + #[Route('/reports_highlight/{id}', name: 'app_report_highlight', methods: ['POST'])] + public function updateHighlight(EntityManagerInterface $entityManager, Request $request, Reports $reports): Response + { + $token = $request->get("token"); + if ($this->isCsrfTokenValid('schedule-highlight', $token)) { + $highlightId = intval($request->get("highlight_id")); + $highlight = ReportHighlight::tryFrom($highlightId); + $reports->setHighlight($highlight); + $entityManager->persist($reports); + $entityManager->flush(); + } + return $this->redirect($request->headers->get('referer') ?? $this->generateUrl('app_schedule')); + } } \ No newline at end of file diff --git a/project/src/Entity/Clients.php b/project/src/Entity/Clients.php index 23684f7..096add9 100644 --- a/project/src/Entity/Clients.php +++ b/project/src/Entity/Clients.php @@ -2,6 +2,7 @@ namespace App\Entity; +use App\Enum\ReportHighlight; use App\Repository\ClientsRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; @@ -50,6 +51,9 @@ class Clients #[ORM\Column(nullable: true)] private ?int $intPhone = null; + #[ORM\Column(enumType: ReportHighlight::class, options: ["default" => "0"])] + private ReportHighlight $highlight = ReportHighlight::STANDARD; + public function __construct() { $this->schedules = new ArrayCollection(); @@ -198,4 +202,16 @@ class Clients return $this; } + + public function getHighlight(): ReportHighlight + { + return $this->highlight; + } + + public function setHighlight(ReportHighlight $highlight): static + { + $this->highlight = $highlight; + + return $this; + } } diff --git a/project/src/Entity/Reports.php b/project/src/Entity/Reports.php index de56889..5ca9bb6 100644 --- a/project/src/Entity/Reports.php +++ b/project/src/Entity/Reports.php @@ -2,6 +2,7 @@ namespace App\Entity; +use App\Enum\ReportHighlight; use App\Enum\ReportStatus; use App\Enum\ReportTodoEnum; use App\Helper\MonthHelper; @@ -49,6 +50,9 @@ class Reports #[ORM\Column] private ?int $number = null; + #[ORM\Column(enumType: ReportHighlight::class, options: ["default" => "0"])] + private ReportHighlight $highlight = ReportHighlight::STANDARD; + public function __construct() { $this->reportsTodos = new ArrayCollection(); @@ -212,4 +216,16 @@ class Reports return $service->takeUrl($this); } + + public function getHighlight(): ReportHighlight + { + return $this->highlight; + } + + public function setHighlight(ReportHighlight $highlight): static + { + $this->highlight = $highlight; + + return $this; + } } diff --git a/project/src/Enum/ReportHighlight.php b/project/src/Enum/ReportHighlight.php new file mode 100644 index 0000000..9b072a4 --- /dev/null +++ b/project/src/Enum/ReportHighlight.php @@ -0,0 +1,32 @@ + '', + ReportHighlight::WARNING => 'warning', + ReportHighlight::INFO => 'info', + ReportHighlight::DANGER => 'danger', + }; + } + public function buttonLang(): string + { + return match ($this) + { + ReportHighlight::STANDARD => 'Brak', + ReportHighlight::WARNING => 'Ostrzeżenie', + ReportHighlight::INFO => 'Informacja', + ReportHighlight::DANGER => 'Ważne', + }; + } +} \ No newline at end of file diff --git a/project/templates/customers/show.html.twig b/project/templates/customers/show.html.twig index 6a2848c..0ed3c04 100644 --- a/project/templates/customers/show.html.twig +++ b/project/templates/customers/show.html.twig @@ -120,6 +120,21 @@ {% endif %} + +
+

Oznaczenie

+
+ +
+ + {% for status in highlightStatus %} + + {% endfor %} +
+
+
diff --git a/project/templates/reports/list.html.twig b/project/templates/reports/list.html.twig index 8b1cf1a..a474b96 100644 --- a/project/templates/reports/list.html.twig +++ b/project/templates/reports/list.html.twig @@ -17,7 +17,7 @@

{{ reports.status.takeLang }}

{% for report in reports.reports %} - {{ sets.cardView(report, reports.status, reportToDoList) }} + {{ sets.cardView(report, reports.status, reportToDoList,highlightStatus) }} {% endfor %}
diff --git a/project/templates/reports/listInclude.html.twig b/project/templates/reports/listInclude.html.twig index 7d9c7d2..f1e74d0 100644 --- a/project/templates/reports/listInclude.html.twig +++ b/project/templates/reports/listInclude.html.twig @@ -35,9 +35,9 @@ {% endmacro %} -{% macro cardView(report, groupStatus, reportToDoList) %} -
-
+{% macro cardView(report, groupStatus, reportToDoList, highlightStatus) %} +
+
{{ report.number }}
{% if enum(groupStatus, 'COMPLETE') and false %} @@ -49,7 +49,7 @@
{% endif %} -
+
{% if is_granted('clientView') %} {{ report.client.strName }} @@ -74,4 +74,29 @@
{% endif %}
+ + + {% endmacro %} \ No newline at end of file