<?php
namespace App\Controller;
use App\Repository\ClientRepository;
use App\Repository\InvoiceRepository;
use App\Repository\ServiceRepository;
use Symfony\Component\Mercure\Update;
use App\Repository\NotificationsRepository;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Mercure\PublisherInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class DashboardController extends AbstractController
{
#[Route('/', name: 'app_dashboard')]
public function index(InvoiceRepository $invoicerepository,ClientRepository $clientrepository,ServiceRepository $servicerepository,NotificationsRepository $notificationsrepository): Response
{
$invoicelist = $invoicerepository->findAll();
$clientlist = $clientrepository->findBy(['active' => true]);
$servicelist = $servicerepository->findBy(['active' => true, 'status' => 0]);
$total=0;
$igv=0;
$totaltoday=0;
foreach ($invoicelist as $invoice) {
$total+=$invoice->getTotal();
$igv+=$invoice->getTotaligv();
if ($invoice->getFechadeemision()->format('d-m-Y')==date('d-m-Y')){
$totaltoday+=$invoice->getTotal();
}
}
return $this->render('dashboard/index.html.twig', [
'controller_name' => 'DashboardController',
'titulo' => 'DashboardController',
'totalorder' => $total,
'nservice' => count($servicelist),
'nclient' => count($clientlist),
'totaltoday' => $totaltoday,
'notifications' => $notificationsrepository->getActivenotificationbyuser($this->getUser()->getId()),
]);
}
#[Route('/push', name: 'app_push')]
public function push(HubInterface $hub): Response
{
$update = new Update(
'notificacion',
json_encode(['mensaje' => 'Se ingresó un nuevo servicio'])
);
$hub->publish($update);
return new Response('published!');
}
}