From aa759af8c55ad50ce745714726e577395f74522b Mon Sep 17 00:00:00 2001 From: Ryjek Date: Tue, 15 Oct 2024 12:15:57 +0200 Subject: [PATCH] add mailto to reports --- docker-compose.yml | 3 +- project/config/services.yaml | 3 ++ project/src/Entity/Reports.php | 15 ++++++++++ project/src/Helper/MonthHelper.php | 26 +++++++++++++++++ project/src/Services/MailtoServices.php | 17 +++++++++++ project/src/Twig/AppExtension.php | 29 +++++++++++++++++++ project/templates/email/firstReport.html.twig | 17 +++++++++++ project/templates/email/report.html.twig | 15 ++++++++++ .../templates/reports/listInclude.html.twig | 5 ++++ 9 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 project/src/Services/MailtoServices.php create mode 100644 project/templates/email/firstReport.html.twig create mode 100644 project/templates/email/report.html.twig diff --git a/docker-compose.yml b/docker-compose.yml index 82f6c53..fe24b38 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,8 +14,9 @@ services: - internal - myadmin www: - image: registry.docker.rhost.ovh/sprawozdania:0.2.2 + image: registry.docker.rhost.ovh/sprawozdania:0.2.3 restart: on-failure + platform: linux/x86_64 build: context: . dockerfile: services/www/Dockerfile diff --git a/project/config/services.yaml b/project/config/services.yaml index da10f6f..f8ac8a3 100644 --- a/project/config/services.yaml +++ b/project/config/services.yaml @@ -24,5 +24,8 @@ services: resource: '../src/Services/' arguments: - '@doctrine.orm.entity_manager' + App\Twig\AppExtension: + arguments: + - '@twig' # add more service definitions when explicit configuration is needed # please note that last definitions always *replace* previous ones diff --git a/project/src/Entity/Reports.php b/project/src/Entity/Reports.php index ea45acb..de56889 100644 --- a/project/src/Entity/Reports.php +++ b/project/src/Entity/Reports.php @@ -4,7 +4,10 @@ namespace App\Entity; use App\Enum\ReportStatus; use App\Enum\ReportTodoEnum; +use App\Helper\MonthHelper; use App\Repository\ReportsRepository; +use App\Services\AddReports; +use App\Services\MailtoServices; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; @@ -127,6 +130,11 @@ class Reports return $this->isReportsTodo(ReportTodoEnum::COMPLETE); } + public function isEmailSend(): bool + { + return $this->isReportsTodo(ReportTodoEnum::SENT_EMAIL); + } + public function countTodoReports(): int { $count = 0; @@ -197,4 +205,11 @@ class Reports return $this; } + + public function takeMailToUrl(): string + { + $service = new MailtoServices(); + + return $service->takeUrl($this); + } } diff --git a/project/src/Helper/MonthHelper.php b/project/src/Helper/MonthHelper.php index ad11619..22e2212 100644 --- a/project/src/Helper/MonthHelper.php +++ b/project/src/Helper/MonthHelper.php @@ -2,6 +2,7 @@ namespace App\Helper; use App\Services\OverdueReports; +use Symfony\Component\Validator\Constraints\Date; class MonthHelper { @@ -53,4 +54,29 @@ class MonthHelper } return $monthCurrent['date']; } + + + public static function takeMonthNameForEmail(int $month) : string + { + $months = [ + "stycznia", "lutego", "marca", "kwietnia", "maja", "czerwca", "lipca", "sierpnia", "września", "października", "listopada", "grudnia" + ]; + return $months[$month - 1] ?? ""; + } + + public static function takeDateFormatWithPolishMonths(\DateTimeInterface $date, bool $showDays = true): string + { + $day = $date->format('d'); + $month = $date->format('n'); + $year = $date->format('Y'); + $monthName = self::takeMonthNameForEmail($month); + + $stringReturn = ""; + if ($showDays) { + $stringReturn .= "$day "; + } + $stringReturn .= "$monthName $year"; + + return $stringReturn; + } } \ No newline at end of file diff --git a/project/src/Services/MailtoServices.php b/project/src/Services/MailtoServices.php new file mode 100644 index 0000000..b143d1b --- /dev/null +++ b/project/src/Services/MailtoServices.php @@ -0,0 +1,17 @@ +getDateStart())->modify("-1 month"); + + $template = "email/report.html.twig"; + $dateStart = (clone $dateBase)->modify("-".(AddReports::NEXT_REPORT_MONTH-1)." months")->modify("first day of this month"); + if ($reports->getNumber() === 1){ + $template = "email/firstReport.html.twig"; + $dateStart = $reports->getClient()->getDateLegitimacy(); + } + $view = sprintf( + file_get_contents($_SERVER['PWD']."/templates/".$template), + MonthHelper::takeDateFormatWithPolishMonths($dateStart), + MonthHelper::takeDateFormatWithPolishMonths($dateBase->modify("last day of this month")) + ); + $content = rawurlencode($view); + + /** @var Clients $client */ + $client = $reports->getClient(); + + return "mailto:{$client->getStrEmail()}?subject=$subject&body=$content"; + } } \ No newline at end of file diff --git a/project/templates/email/firstReport.html.twig b/project/templates/email/firstReport.html.twig new file mode 100644 index 0000000..e305cc1 --- /dev/null +++ b/project/templates/email/firstReport.html.twig @@ -0,0 +1,17 @@ +Szanowni Państwo, +w związku z prawomocnym zatwierdzeniem układu sąd ustanowił nadzorcą wykonania układu Pana Michała Kolczyńskiego. Wiąże się to z koniecznością składania do sądu kwartalnych sprawozdań z wykonania układu i realizacji płatności. + +Co za tym idzie, zwracam się z uprzejmą prośbą o przesłanie potwierdzeń dokonanych przelewów rat układowych za okres od %s roku do %s roku +oraz o odpowiedź na następujące pytania: + +1) Czy w okresie sprawozdawczym nastąpiły zwolnienia lub zatrudnienia pracowników; + +2) Czy zbyty lub nabyty został jakiś majątek? + +3) Proszę wymienić najważniejsze wydarzenia w działalności. (Czy udało się pozyskać nowych kontrahentów? Rozszerzenie rynku zbytu, nowe usługi, obniżenie kosztów utrzymania, nowi dostawcy?) + +4) Czy nastąpiły jakieś zmiany organizacyjne? + +Proszę o przekazanie niniejszych informacji oraz dokumentów w nieprzekraczalnym terminie 5 dni od otrzymania wiadomości. + +W razie pytań lub wątpliwości proszę o kontakt z asystentem prowadzącym postępowanie. \ No newline at end of file diff --git a/project/templates/email/report.html.twig b/project/templates/email/report.html.twig new file mode 100644 index 0000000..1bf986d --- /dev/null +++ b/project/templates/email/report.html.twig @@ -0,0 +1,15 @@ +Szanowni Państwo, + +zwracam się z uprzejmą prośbą o przesłanie potwierdzeń dokonanych przelewów rat układowych za okres od %s roku do %s roku oraz o odpowiedź na następujące pytania: + +1) Czy w okresie sprawozdawczym nastąpiły zwolnienia lub zatrudnienia pracowników; + +2) Czy zbyty lub nabyty został jakiś majątek? + +3) Proszę wymienić najważniejsze wydarzenia w działalności. (Czy udało się pozyskać nowych kontrahentów? Rozszerzenie rynku zbytu, nowe usługi, obniżenie kosztów utrzymania, nowi dostawcy?) + +4) Czy nastąpiły jakieś zmiany organizacyjne? + +Proszę o przekazanie niniejszych informacji oraz dokumentów w nieprzekraczalnym terminie 5 dni od otrzymania wiadomości. + +W razie pytań lub wątpliwości proszę o kontakt z asystentem prowadzącym postępowanie. \ No newline at end of file diff --git a/project/templates/reports/listInclude.html.twig b/project/templates/reports/listInclude.html.twig index ad82fc4..7d9c7d2 100644 --- a/project/templates/reports/listInclude.html.twig +++ b/project/templates/reports/listInclude.html.twig @@ -61,6 +61,11 @@ {# {% if not enum(groupStatus, 'COMPLETE') %}#}

{{ _self.statusForm(report, reportToDoList, groupStatus) }}

+ + {% if is_granted('reportEdit') and not report.isEmailSend %} + Wyślij maila + {% endif %} +
{# {% endif %}#} {% if enum(groupStatus, 'WORKING') %}