feat: email reminder about pending feedbacks for hotel managers
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Cron;
|
||||
|
||||
use App\Email\Mailer;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\Upload;
|
||||
use App\Repository\DispositionRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class UploadReminderService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DispositionRepository $dispositionRepository,
|
||||
private readonly Mailer $mailer,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
public function sendContractUploadReminders(): string
|
||||
{
|
||||
// Contracts have to be uploaded before assignment's begin date. Reminder is
|
||||
// sent three days before end of this period thus due date is today in three days.
|
||||
$contractDueDate = (new \DateTimeImmutable())->modify('+3 days');
|
||||
|
||||
// Find dispositions of assignments with due contract upload
|
||||
$qb = $this->dispositionRepository->createQueryBuilder('disposition');
|
||||
|
||||
$dispositions = $qb
|
||||
->select('disposition', 'assignment', 'destination')
|
||||
->innerJoin('disposition.assignment', 'assignment')
|
||||
->innerJoin('assignment.destination', 'destination')
|
||||
->leftJoin('disposition.documents', 'document', Join::WITH, 'document.type = :documentType')
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->isNull('document'),
|
||||
$qb->expr()->orX(
|
||||
// Due date can be determined by assignment's date which potentially overrides destination date
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->isNotNull('assignment.dateFrom'),
|
||||
$qb->expr()->eq('assignment.dateFrom', ':dateFrom')
|
||||
),
|
||||
$qb->expr()->eq('destination.dateFrom', ':dateFrom'),
|
||||
)
|
||||
))
|
||||
->setParameters([
|
||||
'documentType' => Upload::TYPE_CONTRACT,
|
||||
'dateFrom' => $contractDueDate,
|
||||
])
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
|
||||
if (0 === $count = count($dispositions)) {
|
||||
$message = 'No reminders regarding due contract uploads to be sent';
|
||||
$this->logger->info($message);
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
foreach ($dispositions as $disposition) {
|
||||
$teamer = $disposition->getTeamer();
|
||||
|
||||
$this->mailer->createAndSendEmail([
|
||||
'disposition' => $disposition,
|
||||
], [
|
||||
'to' => $teamer->getCommunication()->getEmail(),
|
||||
'subject' => 'Reminder: Fehlende Dokumente',
|
||||
'template' => 'email/reminder_contract_upload.html.twig',
|
||||
]);
|
||||
}
|
||||
|
||||
$message = 'Sent '.$count.' reminders about due contract uploads';
|
||||
$this->logger->info($message);
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function sendInvoiceUploadReminders(): string
|
||||
{
|
||||
// Invoices have to be uploaded until 14 days after end of assignment. Reminder
|
||||
// is sent three days before end of this period thus on the 11th day after end of assignment.
|
||||
$invoiceDueDate = (new \DateTimeImmutable())->modify('-11 days');
|
||||
|
||||
// Find dispositions of assignments with due invoice upload
|
||||
$qb = $this->dispositionRepository->createQueryBuilder('disposition');
|
||||
|
||||
$dispositions = $qb
|
||||
->select('disposition', 'assignment', 'destination')
|
||||
->innerJoin('disposition.assignment', 'assignment')
|
||||
->innerJoin('assignment.destination', 'destination')
|
||||
->leftJoin('disposition.documents', 'document', Join::WITH, 'document.type = :documentType')
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->isNull('document'),
|
||||
$qb->expr()->orX(
|
||||
// Due date can be determined by assignment's date which potentially overrides destination date
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->isNotNull('assignment.dateTo'),
|
||||
$qb->expr()->eq('assignment.dateTo', ':dateTo')
|
||||
),
|
||||
$qb->expr()->eq('destination.dateTo', ':dateTo'),
|
||||
)
|
||||
))
|
||||
->setParameters([
|
||||
'documentType' => Upload::TYPE_INVOICE,
|
||||
'dateTo' => $invoiceDueDate,
|
||||
])
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
|
||||
if (0 === $count = count($dispositions)) {
|
||||
$message = 'No reminders regarding due invoice uploads to be sent';
|
||||
$this->logger->info($message);
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
foreach ($dispositions as $disposition) {
|
||||
$teamer = $disposition->getTeamer();
|
||||
|
||||
$this->mailer->createAndSendEmail([
|
||||
'disposition' => $disposition,
|
||||
], [
|
||||
'to' => $teamer->getCommunication()->getEmail(),
|
||||
'subject' => 'Reminder: Fehlende Dokumente',
|
||||
'template' => 'email/reminder_invoice_upload.html.twig',
|
||||
]);
|
||||
}
|
||||
|
||||
$message = 'Sent '.$count.' reminders about due invoice uploads';
|
||||
$this->logger->info($message);
|
||||
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user