Merge branch 'master' into invoices
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace App\Services;
|
||||
|
||||
use App\Entity\Clients;
|
||||
use App\Entity\Reports;
|
||||
use App\Helper\MonthHelper;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Twig\Environment;
|
||||
|
||||
class MailtoServices extends AbstractController
|
||||
{
|
||||
public function takeUrl(Reports $reports): string
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,10 @@
|
||||
// src/Twig/AppExtension.php
|
||||
namespace App\Twig;
|
||||
|
||||
use App\Entity\Clients;
|
||||
use App\Entity\Reports;
|
||||
use App\Helper\MonthHelper;
|
||||
use App\Services\AddReports;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
@@ -20,6 +24,7 @@ class AppExtension extends AbstractExtension
|
||||
return [
|
||||
new TwigFunction('enum', [$this, 'enumChecker']),
|
||||
new TwigFunction('is_route_active', [$this, 'getActualRoute']),
|
||||
new TwigFunction('getMailtoLink', [$this, 'getMailtoLink']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -41,4 +46,28 @@ class AppExtension extends AbstractExtension
|
||||
{
|
||||
return $value === $route ? 'active' : '';
|
||||
}
|
||||
|
||||
public function getMailtoLink(Reports $reports): string
|
||||
{
|
||||
$subject = rawurlencode("Sprawozdanie z wykonania układu");
|
||||
$dateBase = (clone $reports->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";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user