major fixes
This commit is contained in:
@@ -36,18 +36,21 @@ class BaseController extends AbstractController
|
||||
}
|
||||
return $this->redirectToRoute('app_base');
|
||||
}
|
||||
#[Route('/reports/{monthId}', name: 'app_base')]
|
||||
#[Route('/reports/{monthId}/{clientId}', name: 'app_base')]
|
||||
#[IsGranted('reportView')]
|
||||
public function reportsIndex(EntityManagerInterface $entityManager, CacheInterface $cache, OverdueReports $overdueReports, int $monthId = 0) : Response
|
||||
public function reportsIndex(EntityManagerInterface $entityManager, CacheInterface $cache, OverdueReports $overdueReports, int $monthId = 0, int $clientId = 0) : Response
|
||||
{
|
||||
$client = null;
|
||||
if ($clientId) {
|
||||
$client = $entityManager->getRepository(Clients::class)->find($clientId);
|
||||
}
|
||||
$overdueReports->setClient($client);
|
||||
$monthHelper = new MonthHelper($overdueReports);
|
||||
$isOverdue = false;
|
||||
$monthCurrentDate = $monthHelper->getCurrentMonthDate($monthId);
|
||||
$reportsAll = $this->takeReportsAll($entityManager,$cache,$monthCurrentDate);
|
||||
$reportsAll = $this->takeReportsAll($entityManager, $clientId, $monthCurrentDate);
|
||||
|
||||
if ($monthId > -1) {
|
||||
$reportsAll = $entityManager->getRepository(Reports::class)->findAllInMonth($monthCurrentDate);
|
||||
} else {
|
||||
if ($monthId < 0) {
|
||||
$isOverdue = true;
|
||||
}
|
||||
|
||||
@@ -69,16 +72,18 @@ class BaseController extends AbstractController
|
||||
'currentMonth' => $monthCurrentDate ?? null,
|
||||
'reportToDoList' => ReportTodoEnum::cases(),
|
||||
'isOverdue' => $isOverdue,
|
||||
'countOverdueLeft' => $overdueReports->getLeftCount()
|
||||
'countOverdueLeft' => $overdueReports->getLeftCount(),
|
||||
'client' => $client,
|
||||
'clientId' => $clientId
|
||||
]);
|
||||
}
|
||||
|
||||
private function takeReportsAll(EntityManagerInterface $entityManager, CacheInterface $cache, ?\DateTime $monthCurrent = null) : array
|
||||
private function takeReportsAll(EntityManagerInterface $entityManager, int $clientId, ?\DateTime $monthCurrent = null) : array
|
||||
{
|
||||
if ($monthCurrent !== null) {
|
||||
$ret = $entityManager->getRepository(Reports::class)->findAllInMonth($monthCurrent);
|
||||
$ret = $entityManager->getRepository(Reports::class)->findAllInMonth($monthCurrent,$clientId);
|
||||
} else {
|
||||
$ret = $entityManager->getRepository(Reports::class)->findAllOverdue();
|
||||
$ret = $entityManager->getRepository(Reports::class)->findAllOverdue($clientId);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
@@ -6,6 +6,8 @@ use App\Entity\Clients;
|
||||
use App\Entity\Notes;
|
||||
use App\Entity\Reports;
|
||||
use App\Entity\Schedule;
|
||||
use App\Enum\ReportStatus;
|
||||
use App\Enum\ReportTodoEnum;
|
||||
use App\Services\AddReports;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@@ -50,13 +52,14 @@ class ClientController extends AbstractController
|
||||
$schedules = $entityManager->getRepository(Schedule::class)->findOneBy(["client" => $clients->getId()]);
|
||||
$reports = $entityManager->getRepository(Reports::class)->findBy(["client" => $clients->getId()],["number"=>"DESC"]);
|
||||
$notes = $entityManager->getRepository(Notes::class)->findOneBy(["clientId" => $clients->getId()]);
|
||||
|
||||
return $this->render('customers/show.html.twig', [
|
||||
'client' => $clients,
|
||||
'schedules' => $schedules,
|
||||
'reports' => $reports,
|
||||
'notes' => $notes,
|
||||
'backUrl' => $request->headers->get('referer')
|
||||
'backUrl' => $request->headers->get('referer'),
|
||||
'reportToDoList' => ReportTodoEnum::cases(),
|
||||
'reportStatus' => ReportStatus::INSERT
|
||||
]);
|
||||
}
|
||||
#[Route('/dodaj_klienta/{id}', name: 'app_add_client', defaults: ['id'=>0])]
|
||||
|
||||
@@ -26,7 +26,7 @@ class ReportsRepository extends ServiceEntityRepository
|
||||
return parent::findBy($criteria, $orderBy, $limit, $offset); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
public function findAllOverdue()
|
||||
public function findAllOverdue(int $clientId = 0)
|
||||
{
|
||||
$dateEnd = new \DateTime();
|
||||
$dateEnd->modify("last day of previous month");
|
||||
@@ -36,7 +36,12 @@ class ReportsRepository extends ServiceEntityRepository
|
||||
->andWhere('r.isDone = :isDone')
|
||||
->setParameter('isDone', 0)
|
||||
->setParameter('isDelete', 0)
|
||||
->setParameter('dateEnd', $dateEnd)
|
||||
->setParameter('dateEnd', $dateEnd);
|
||||
if ($clientId > 0) {
|
||||
$reports->andWhere('r.client = :client');
|
||||
$reports->setParameter('client', $clientId);
|
||||
}
|
||||
$reports = $reports
|
||||
->orderBy("r.number","ASC")
|
||||
->getQuery()
|
||||
->getResult();
|
||||
@@ -48,8 +53,9 @@ class ReportsRepository extends ServiceEntityRepository
|
||||
|
||||
/**
|
||||
* @return Reports[] Returns an array of Reports objects
|
||||
* @throws \DateMalformedStringException
|
||||
*/
|
||||
public function findAllInMonth(\DateTime $date): array
|
||||
public function findAllInMonth(\DateTime $date, int $clientId = 0): array
|
||||
{
|
||||
$dateStart = clone $date;
|
||||
$dateStart->modify("first day of this month");
|
||||
@@ -61,13 +67,15 @@ class ReportsRepository extends ServiceEntityRepository
|
||||
->andWhere('r.isDelete = :deleted')
|
||||
->setParameter('dateStart', $dateStart->format('Y-m-d'))
|
||||
->setParameter('dateEnd', $dateEnd->format('Y-m-d'))
|
||||
->setParameter('deleted', 0)
|
||||
->setParameter('deleted', 0);
|
||||
if ($clientId > 0) {
|
||||
$reports->andWhere('r.client = :client');
|
||||
$reports->setParameter('client', $clientId);
|
||||
}
|
||||
$reports = $reports
|
||||
->orderBy("r.number","ASC")
|
||||
// ->setMaxResults(10)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
|
||||
->getResult();
|
||||
// $this->countReport($reports);
|
||||
|
||||
return $reports;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace App\Services;
|
||||
use App\Entity\Clients;
|
||||
use App\Entity\Reports;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
@@ -8,12 +9,14 @@ class OverdueReports
|
||||
{
|
||||
private array $list;
|
||||
private int $leftCount = 0;
|
||||
public function __construct(private readonly EntityManager $entity){
|
||||
$this->list = $this->takeOverdueList();
|
||||
}
|
||||
private ?Clients $client = null;
|
||||
public function __construct(private readonly EntityManager $entity){}
|
||||
|
||||
public function getList(): array
|
||||
{
|
||||
if(!isset($this->list)){
|
||||
$this->list = $this->takeOverdueList();
|
||||
}
|
||||
return $this->list;
|
||||
}
|
||||
|
||||
@@ -22,6 +25,11 @@ class OverdueReports
|
||||
$this->leftCount = $leftCount;
|
||||
}
|
||||
|
||||
public function setClient(?Clients $client): void
|
||||
{
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
public function getLeftCount(): int
|
||||
{
|
||||
return $this->leftCount;
|
||||
@@ -29,7 +37,11 @@ class OverdueReports
|
||||
|
||||
private function takeOverdueList() : array
|
||||
{
|
||||
$reports = $this->entity->getRepository(Reports::class)->findAllOverdue();
|
||||
$clientId = 0;
|
||||
if($this->client){
|
||||
$clientId = $this->client->getId();
|
||||
}
|
||||
$reports = $this->entity->getRepository(Reports::class)->findAllOverdue($clientId);
|
||||
if (!$reports) {
|
||||
return [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user