src/Controller/ReservationListingController.php line 34

  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use App\Entity\Reservation;
  8. use App\Service\GuestyConnector;
  9. use Doctrine\Persistence\ManagerRegistry;
  10. use Psr\Log\LoggerInterface;
  11. class ReservationListingController extends AbstractController
  12. {
  13.     protected ManagerRegistry $doctrine;
  14.     protected Request $request;
  15.     protected LoggerInterface $logger;
  16.     private \Doctrine\Persistence\ObjectRepository $repository;
  17.     public function __construct(
  18.         ManagerRegistry $doctrine,
  19.         LoggerInterface $logger
  20.     ){
  21.         $this->doctrine $doctrine;
  22.         $this->logger $logger;
  23.         $this->repository$this->doctrine->getRepository(Reservation::class);
  24.     }
  25.     #[Route('/reservation/listing'name'app_reservation_listing')]
  26.     public function index(Request $request): Response
  27.     {
  28.         $this->request $request;
  29.         $type $this->request->query->get('type');
  30.         $data $this->retreiveFromDb($type);
  31.         return $this->render('reservation_listing/index.html.twig', [
  32.             'controller_name' => 'ReservationListingController',
  33.             'data' => $data,
  34.             'judete' => Reservation::COUNTIES,
  35.             'sectoare' => Reservation::SECTORS,
  36.             'type'=>$type ??'Upcoming'
  37.         ]);
  38.     }
  39.     public function retreiveFromDb$type 'upcoming')
  40.     {
  41.         switch ($type){
  42.             case 'single':
  43.                 $id =$this->request->query->get('guesty_id');
  44.                 $result = [$this->repository->findOneBy(['guesty_id'=>$id])];
  45.                 break;
  46.             case 'invoicing_today':
  47.                 $result $this->repository->getInvoicingToday();
  48.                 break;
  49.             case 'pending':
  50.                 // pending
  51.                 $result $this->repository->getPending();
  52.                 break;
  53.             case 'pending2':
  54.                 // pending
  55.                 $result $this->repository->getByFlow('pending');
  56.                 break;
  57.             case 'upcoming2':
  58.                 // pending
  59.                 $result $this->repository->getByFlow('upcoming');
  60.                 break;
  61.             case 'past':
  62.                 $result =  $this->repository->getPast();
  63.                 break;
  64.             case 'currentmonth':
  65.                 $result =   $this->repository->getCurrentMonth();
  66.                 break;
  67.             case 'lastmonth':
  68.                 $result =   $this->repository->getLastMonth();
  69.                 break;
  70.             case 'last2months':
  71.                 $result =   $this->repository->getLast2Months();
  72.                 break;
  73.             case 'invoiced':
  74.                 $result =  $this->repository->getInvoiced();
  75.                 break;
  76.             case 'canceled':
  77.                 $result =    $this->repository->getCanceled();
  78.                 break;
  79.             case 'needsaddress':
  80.                 $result =  $this->repository->getNeedsAddress();
  81.                 break;
  82.             case 'filter':
  83.                 $checkoutFrom=$this->request->get('checkoutfrom');
  84.                 $checkoutUntil=$this->request->get('checkoutuntil');
  85.                 $invoiceableOnly=$this->request->get('invoiceableonly');
  86.                 $notinvoicedonly=$this->request->get('notinvoicedonly');
  87.                 $fulladdressonly=$this->request->get('fulladdressonly');
  88.                 $params = [
  89.                     'checkoutfrom' =>$checkoutFrom,
  90.                     'checkoutuntil' =>$checkoutUntil,
  91.                     'invoiceableonly' =>$invoiceableOnly,
  92.                     'notinvoicedonly' => $notinvoicedonly,
  93.                     'fulladdressonly' => $fulladdressonly
  94.                 ];
  95.                 $result =  $this->repository->getFiltered($params);
  96.                 break;
  97.             case 'all':
  98.                 $result $this->repository->findAll();
  99.                 break;
  100.             case 'upcoming_invoices':
  101.                 $result =   $this->repository->getUpcomingInvoices();
  102.                 break;
  103.             case 'ongoing':
  104.                 $result =   $this->repository->getOngoing();
  105.                 break;
  106.             case 'upcoming':
  107.             default:
  108.                 $result =  $this->repository->getUpcomingReservations();
  109.                 break;
  110.         }
  111.         return $result;
  112.     }
  113. }