src/Controller/DashboardController.php line 33
<?phpnamespace App\Controller;use App\Entity\Reservation;use App\Service\GuestyConnector;use Doctrine\Persistence\ManagerRegistry;use Psr\Log\LoggerInterface;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;class DashboardController extends AbstractController{protected ManagerRegistry $doctrine;protected Request $request;protected LoggerInterface $logger;private \Doctrine\Persistence\ObjectRepository $repository;public function __construct(GuestyConnector $guestyconnector,ManagerRegistry $doctrine,LoggerInterface $logger){$this->doctrine = $doctrine;$this->logger = $logger;$this->repository= $this->doctrine->getRepository(Reservation::class);}#[Route('/', name: 'app_home')]public function index(): Response{$data = $this->retreiveFromDb();return $this->render('dashboard/index.html.twig', ['controller_name' => 'DashboardController','data' => $data,]);}public function retreiveFromDb( $type = 'upcoming'){$repository = $this->doctrine->getRepository(Reservation::class);$now = new \DateTime();$lastMonth = new \DateTime('-1 month');$last2Months = new \DateTime('-1 month');/*case 'invoicing_today':$result = $this->repository->getInvoicingToday();break;case 'pending':// pending$result = $this->repository->getPending();break;case 'pending2':// pending$result = $this->repository->getByFlow('pending');break;case 'upcoming2':// pending$result = $this->repository->getByFlow('upcoming');break;case 'past':$result = $this->repository->getPast();break;case 'currentmonth':$result = $this->repository->getCurrentMonth();break;*/$data=['pending'=> $this->repository->getByFlow('pending'),'needsaddress'=> $this->repository->getNeedsAddress(),'past'=> $this->doctrine->getManager()->createQuery('SELECT e FROM App\Entity\Reservation e WHERE e.checkout < CURRENT_DATE() and e.status != :status_canceled and e.status!=:status_inquiry and e.status_invoice is NULL ORDER BY e.checkout DESC')->setParameter('status_canceled',"canceled" )->setParameter('status_inquiry',"inquiry" )->getResult(),'currentmonth'=> $this->doctrine->getManager()->createQuery('SELECT e FROM App\Entity\Reservation e WHERE YEAR(e.checkout) = :year AND MONTH(e.checkout) = MONTH(:date) and e.status != :status_canceled and e.status!=:status_inquiry')->setParameter('year', $now->format("Y") )->setParameter('date', $now)->setParameter('status_canceled',"canceled" )->setParameter('status_inquiry',"inquiry" )->getResult(),'lastmonth'=> $this->doctrine->getManager()->createQuery('SELECT e FROM App\Entity\Reservation e WHERE YEAR(e.checkout) = :year AND MONTH(e.checkout) = MONTH(:date) and e.status != :status_canceled and e.status!=:status_inquiry')->setParameter('year', $lastMonth->format("Y") )->setParameter('date', $lastMonth)->setParameter('status_canceled',"canceled" )->setParameter('status_inquiry',"inquiry" )->getResult(),'last2months'=> $this->doctrine->getManager()->createQuery('SELECT e FROM App\Entity\Reservation e WHERE YEAR(e.checkout) = :year AND (MONTH(e.checkout) = MONTH(:date) OR MONTH(e.checkout) = MONTH(:date2) ) and e.status != :status_canceled and e.status!=:status_inquiry' )->setParameter('year', $last2Months->format("Y") )->setParameter('date', $lastMonth)->setParameter('date2', $last2Months)->setParameter('status_canceled',"canceled" )->setParameter('status_inquiry',"inquiry" )->getResult(),'invoiced'=> $this->doctrine->getManager()->createQuery('SELECT e FROM App\Entity\Reservation e WHERE e.status_invoice=1 and e.status!=:status_inquiry ORDER BY e.checkin ASC')->setParameter('status_inquiry',"inquiry" )->getResult(),'canceled'=> $this->doctrine->getManager()->createQuery('SELECT e FROM App\Entity\Reservation e WHERE e.status= :status_canceled or e.status=:status_inquiry ORDER BY e.checkin ASC')->setParameter('status_canceled',"canceled" )->setParameter('status_inquiry',"inquiry" )->getResult(),'invoicing_today' => $this->repository->getInvoicingToday()];$data['all'] =$repository->findAll();$data['upcoming']=$this->doctrine->getManager()->createQuery('SELECT e FROM App\Entity\Reservation e WHERE e.checkin > CURRENT_DATE() and e.status != :status_canceled and e.status!=:status_inquiry ORDER BY e.checkin ASC ')->setParameter('status_canceled',"canceled" )->setParameter('status_inquiry',"inquiry" )->getResult();$checkoutFrom='01-05-2025';$checkoutFrom= new \DateTime($checkoutFrom);$invoiced = $this->doctrine->getManager()->createQuery('SELECT e FROM App\Entity\Reservation e WHERE e.checkout >= :checkout1 and e.status!=:status_inquiry and e.status_invoice=1 ORDER BY e.checkin ASC')->setParameter('checkout1',$checkoutFrom)->setParameter('status_inquiry', "inquiry")->getResult();$autoinvoiced = $this->doctrine->getManager()->createQuery('SELECT e FROM App\Entity\Reservation e WHERE e.status_invoice=1 and e.auto_invoiced=1 ORDER BY e.checkin ASC')->getResult();$data['autoinvoiced']=['autoinvoiced' => count($autoinvoiced),'invoiced' => count($invoiced),'percent' => count($autoinvoiced)/count($invoiced) * 100,];return $data;}}