src/Controller/DashboardController.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\ClientRepository;
  4. use App\Repository\InvoiceRepository;
  5. use App\Repository\ServiceRepository;
  6. use Symfony\Component\Mercure\Update;
  7. use App\Repository\NotificationsRepository;
  8. use Symfony\Component\Mercure\HubInterface;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\Mercure\PublisherInterface;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. class DashboardController extends AbstractController
  14. {
  15.     #[Route('/'name'app_dashboard')]
  16.     public function index(InvoiceRepository $invoicerepository,ClientRepository $clientrepository,ServiceRepository $servicerepository,NotificationsRepository $notificationsrepository): Response
  17.     {
  18.         $invoicelist $invoicerepository->findAll();
  19.         $clientlist $clientrepository->findBy(['active' => true]);
  20.         $servicelist $servicerepository->findBy(['active' => true'status' => 0]);
  21.         $total=0;
  22.         $igv=0;
  23.         $totaltoday=0;
  24.         foreach ($invoicelist as $invoice) {
  25.             $total+=$invoice->getTotal();
  26.             $igv+=$invoice->getTotaligv();
  27.             if ($invoice->getFechadeemision()->format('d-m-Y')==date('d-m-Y')){                
  28.                 $totaltoday+=$invoice->getTotal();
  29.             }
  30.         }
  31.        
  32.         return $this->render('dashboard/index.html.twig', [
  33.             'controller_name' => 'DashboardController',
  34.             'titulo' => 'DashboardController',
  35.             'totalorder' => $total,
  36.             'nservice' => count($servicelist),
  37.             'nclient' => count($clientlist),
  38.             'totaltoday' => $totaltoday,
  39.             'notifications' => $notificationsrepository->getActivenotificationbyuser($this->getUser()->getId()),
  40.         ]);
  41.     }
  42.     #[Route('/push'name'app_push')]
  43.     public function push(HubInterface $hub): Response
  44.     {
  45.         $update = new Update(
  46.             'notificacion',
  47.             json_encode(['mensaje' => 'Se ingresó un nuevo servicio'])
  48.         );
  49.         $hub->publish($update);
  50.         return new Response('published!');    
  51.     }
  52. }