fix change template mode; fix schedule view; minor fixes
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Enum\Months;
|
||||
use App\Enum\ReportStatus;
|
||||
use App\Enum\ReportTodoEnum;
|
||||
use App\Helper\MonthHelper;
|
||||
use App\Services\OverdueReports;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@@ -26,12 +27,6 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class BaseController extends AbstractController
|
||||
{
|
||||
private MonthHelper $monthHelper;
|
||||
|
||||
public function __construct(){
|
||||
$this->monthHelper = new MonthHelper();
|
||||
}
|
||||
|
||||
#[Route('/', name: 'index')]
|
||||
public function index(): Response
|
||||
{
|
||||
@@ -42,12 +37,13 @@ class BaseController extends AbstractController
|
||||
}
|
||||
#[Route('/reports/{monthId}', name: 'app_base')]
|
||||
#[IsGranted('reportView')]
|
||||
public function reportsIndex(EntityManagerInterface $entityManager, int $monthId = 0) : Response
|
||||
public function reportsIndex(EntityManagerInterface $entityManager, OverdueReports $overdueReports, int $monthId = 0) : Response
|
||||
{
|
||||
$monthHelper = new MonthHelper($overdueReports);
|
||||
$isOverdue = false;
|
||||
if ($monthId > -1) {
|
||||
$monthCurrent = $this->monthHelper->getCurrentMonth($monthId);
|
||||
$reportsAll = $entityManager->getRepository(Reports::class)->findAllInMonth($monthCurrent);
|
||||
$monthCurrentDate = $monthHelper->getCurrentMonthDate($monthId);
|
||||
$reportsAll = $entityManager->getRepository(Reports::class)->findAllInMonth($monthCurrentDate);
|
||||
} else {
|
||||
$reportsAll = $entityManager->getRepository(Reports::class)->findAllOverdue();
|
||||
$isOverdue = true;
|
||||
@@ -67,10 +63,11 @@ class BaseController extends AbstractController
|
||||
ksort($reports);
|
||||
return $this->render('reports/list.html.twig', [
|
||||
'reportsGroup' => $reports,
|
||||
'months' => $this->monthHelper->takeMonths(),
|
||||
'currentMonth' => $monthCurrent ?? null,
|
||||
'months' => $monthHelper->takeMonths(),
|
||||
'currentMonth' => $monthCurrentDate ?? null,
|
||||
'reportToDoList' => ReportTodoEnum::cases(),
|
||||
'isOverdue' => $isOverdue,
|
||||
'countOverdueLeft' => $overdueReports->getLeftCount()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ class ReportsController extends AbstractController
|
||||
$token = $request->get("token");
|
||||
if ($this->isCsrfTokenValid('report-status', $token)) {
|
||||
$reportsService->setClient($report->getClient());
|
||||
$isDone = false;
|
||||
if ($request->get("unDone")){
|
||||
$todo = $entityManager->getRepository(ReportsTodo::class)->findOneBy([
|
||||
"report" => $report->getId(),
|
||||
@@ -30,8 +29,12 @@ class ReportsController extends AbstractController
|
||||
]);
|
||||
$todo->setDeleted(true);
|
||||
$entityManager->persist($todo);
|
||||
$report->setDone(false);
|
||||
} else {
|
||||
foreach (ReportTodoEnum::cases() as $case) {
|
||||
if (!$request->get($case->value)) {
|
||||
continue;
|
||||
}
|
||||
$todo = $entityManager->getRepository(ReportsTodo::class)->findOneBy([
|
||||
"report" => $report->getId(),
|
||||
"name" => $case->value
|
||||
@@ -40,19 +43,19 @@ class ReportsController extends AbstractController
|
||||
$todo = new ReportsTodo();
|
||||
$todo->setReport($report);
|
||||
$todo->setName($case);
|
||||
}
|
||||
if ($request->get($case->value) !== null) {
|
||||
$todo->setDeleted(false);
|
||||
} else {
|
||||
$todo->setDeleted(true);
|
||||
$todo->setDeleted(!$todo->isDeleted());
|
||||
}
|
||||
if ($todo->getName() === ReportTodoEnum::COMPLETE && !$todo->isDeleted()) {
|
||||
$isDone = true;
|
||||
if ($todo->getName() === ReportTodoEnum::COMPLETE) {
|
||||
if ($todo->isDeleted()) {
|
||||
$report->setDone(false);
|
||||
} else {
|
||||
$report->setDone(true);
|
||||
}
|
||||
}
|
||||
$entityManager->persist($todo);
|
||||
}
|
||||
}
|
||||
$report->setDone($isDone);
|
||||
$entityManager->persist($report);
|
||||
$entityManager->flush();
|
||||
$reportsService->tryAddNextReport();
|
||||
|
||||
@@ -18,6 +18,7 @@ class ScheduleController extends AbstractController
|
||||
{
|
||||
if ($typeId == 1) {
|
||||
$schedulesTmp = $entityManager->getRepository(Schedule::class)->findAllCurrent();
|
||||
$isOverdue = $entityManager->getRepository(Schedule::class)->findAllOverdue(true);
|
||||
} else {
|
||||
$schedulesTmp = $entityManager->getRepository(Schedule::class)->findAllOverdue();
|
||||
}
|
||||
@@ -25,16 +26,15 @@ class ScheduleController extends AbstractController
|
||||
return $this->render('schedule/index.html.twig', [
|
||||
'typeId' => $typeId,
|
||||
'schedules' => $schedulesTmp,
|
||||
'isOverdue' => $isOverdue ?? false,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/schedule_status', name: 'app_schedule_status')]
|
||||
public function setDone(EntityManagerInterface $entityManager, Request $request): Response
|
||||
#[Route('/schedule_status/{id}', name: 'app_schedule_status', methods: ['POST'])]
|
||||
public function setDone(EntityManagerInterface $entityManager, Request $request, Schedule $schedule): Response
|
||||
{
|
||||
$scheduleId = $request->getPayload()->get('scheduleId');
|
||||
$token = $request->getPayload()->get("token");
|
||||
if ($scheduleId && $this->isCsrfTokenValid('schedule-status', $token)) {
|
||||
$schedule = $entityManager->getRepository(Schedule::class)->find($scheduleId);
|
||||
$token = $request->get("token");
|
||||
if ($this->isCsrfTokenValid('schedule-status', $token)) {
|
||||
$isDone = true;
|
||||
if ($schedule->isDone()) {
|
||||
$isDone = false;
|
||||
|
||||
@@ -18,4 +18,15 @@ enum ScheduleStatus: int
|
||||
ScheduleStatus::COMPLETED => 'success',
|
||||
};
|
||||
}
|
||||
|
||||
public function borderColor(): string
|
||||
{
|
||||
return match ($this) {
|
||||
ScheduleStatus::TODO => '',
|
||||
ScheduleStatus::INCOMING => 'warning',
|
||||
ScheduleStatus::OVERDUE => 'danger',
|
||||
ScheduleStatus::COMPLETED => 'success',
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,53 @@
|
||||
<?php
|
||||
namespace App\Helper;
|
||||
|
||||
use App\Services\OverdueReports;
|
||||
|
||||
class MonthHelper
|
||||
{
|
||||
public function __construct(private readonly OverdueReports $overdueReports){}
|
||||
public function takeMonths() : array
|
||||
{
|
||||
$startDate = new \DateTime("-6 months");
|
||||
$startDate->modify("first day of this month");
|
||||
$return = [];
|
||||
$overdueCounts = $this->overdueReports->getList();
|
||||
for ($i=1; $i<=11; $i++) {
|
||||
$tmp = clone $startDate;
|
||||
$tmp->modify("+$i month");
|
||||
$return[$i] = $tmp;
|
||||
$return[$i] = [
|
||||
'date' => $tmp,
|
||||
'overdueCount' => 0
|
||||
];
|
||||
$key = $tmp->format('Y-m');
|
||||
if (isset($overdueCounts[$key])) {
|
||||
$return[$i]['overdueCount'] = $overdueCounts[$key];
|
||||
unset($overdueCounts[$key]);
|
||||
}
|
||||
}
|
||||
if (count($overdueCounts) > 0) {
|
||||
$this->overdueReports->setLeftCount(array_sum($overdueCounts));
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
public function getCurrentMonth(int $monthId) : \DateTime
|
||||
public function getCurrentMonthDate(int $monthId) : \DateTime
|
||||
{
|
||||
$months = $this->takeMonths();
|
||||
if ($monthId==0) {
|
||||
$currentMonth = intval(date("n"));
|
||||
|
||||
foreach ($months as $mId => $monthObj) {
|
||||
if ($monthObj->format("m") == $currentMonth) {
|
||||
$date = $monthObj['date']->format('m');
|
||||
if ($date == $currentMonth) {
|
||||
$monthCurrent = $monthObj;
|
||||
$monthId = $mId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$monthCurrent = $months[$monthId];
|
||||
}
|
||||
return $monthCurrent;
|
||||
return $monthCurrent['date'];
|
||||
}
|
||||
}
|
||||
@@ -11,25 +11,49 @@ use Doctrine\Persistence\ManagerRegistry;
|
||||
*/
|
||||
class ScheduleRepository extends ServiceEntityRepository
|
||||
{
|
||||
private const _OVERDUE_DAYS_START = 15;
|
||||
private const _OVERDUE_DAYS_END = 30;
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Schedule::class);
|
||||
}
|
||||
|
||||
public function findAllOverdue()
|
||||
public function findAllOverdue(bool $onlyCount = false) : array|int
|
||||
{
|
||||
$dateEnd = new \DateTime("now");
|
||||
$dateEnd->modify("-".self::_OVERDUE_DAYS_START." days");
|
||||
$reports = $this->createQueryBuilder('s')
|
||||
->where('s.isDone = :isDone')
|
||||
->andWhere('s.dateEnd < :dateEnd')
|
||||
// ->andWhere('s.isDelete = :isDelete')
|
||||
->setParameter('isDone', 0)
|
||||
// ->setParameter('isDelete', 0)
|
||||
->setParameter('dateEnd', $dateEnd);
|
||||
|
||||
if ($onlyCount) {
|
||||
$reports->select('COUNT(s.id)');
|
||||
return $reports->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
|
||||
return $reports->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function isOverdue(): bool
|
||||
{
|
||||
$dateEnd = new \DateTime("now");
|
||||
$dateEnd->modify("-".self::_OVERDUE_DAYS_START." days");
|
||||
$query = $this->createQueryBuilder('s')
|
||||
->select('count(s.id)')
|
||||
->where('s.isDone = :isDone')
|
||||
->andWhere('s.dateEnd < :dateEnd')
|
||||
// ->andWhere('s.isDelete = :isDelete')
|
||||
->setParameter('isDone', 0)
|
||||
// ->setParameter('isDelete', 0)
|
||||
->setParameter('dateEnd', $dateEnd)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
->getSingleScalarResult();
|
||||
|
||||
return $reports;
|
||||
trigger_error(var_export($query,true));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,9 +63,9 @@ class ScheduleRepository extends ServiceEntityRepository
|
||||
{
|
||||
$date = new \DateTime();
|
||||
$dateStart = clone $date;
|
||||
$dateStart->modify("-15 days");
|
||||
$dateStart->modify("-".self::_OVERDUE_DAYS_START." days");
|
||||
$dateEnd = clone $date;
|
||||
$dateEnd->modify("+30 days");
|
||||
$dateEnd->modify("+".self::_OVERDUE_DAYS_END." days");
|
||||
return $this->createQueryBuilder('r')
|
||||
->where('r.dateEnd >= :dateStart')
|
||||
->andWhere('r.dateEnd <= :dateEnd')
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace App\Services;
|
||||
use App\Entity\Reports;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
class OverdueReports
|
||||
{
|
||||
private array $list;
|
||||
private int $leftCount = 0;
|
||||
public function __construct(private readonly EntityManager $entity){
|
||||
$this->list = $this->takeOverdueList();
|
||||
}
|
||||
|
||||
public function getList(): array
|
||||
{
|
||||
return $this->list;
|
||||
}
|
||||
|
||||
public function setLeftCount(int $leftCount): void
|
||||
{
|
||||
$this->leftCount = $leftCount;
|
||||
}
|
||||
|
||||
public function getLeftCount(): int
|
||||
{
|
||||
return $this->leftCount;
|
||||
}
|
||||
|
||||
private function takeOverdueList() : array
|
||||
{
|
||||
$reports = $this->entity->getRepository(Reports::class)->findAllOverdue();
|
||||
if (!$reports) {
|
||||
return [];
|
||||
}
|
||||
$toReturn = [];
|
||||
/** @var Reports $report */
|
||||
foreach ($reports as $report) {
|
||||
$date = $report->getDateStart()->format('Y-m');
|
||||
if (!array_key_exists($date, $toReturn)) {
|
||||
$toReturn[$date] = 1;
|
||||
} else {
|
||||
$toReturn[$date]++;
|
||||
}
|
||||
}
|
||||
|
||||
return $toReturn;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user