<?php
namespace App\Controller;
use App\Entity\User;
use App\Repository\NotificariRepository;
use App\Repository\SarciniRepository;
use App\Repository\UserRepository;
use CMEN\GoogleChartsBundle\GoogleCharts\Charts\AnnotationChart;
use CMEN\GoogleChartsBundle\GoogleCharts\Charts\AreaChart;
use CMEN\GoogleChartsBundle\GoogleCharts\Charts\BarChart;
use CMEN\GoogleChartsBundle\GoogleCharts\Charts\GanttChart;
use CMEN\GoogleChartsBundle\GoogleCharts\Charts\Histogram;
use CMEN\GoogleChartsBundle\GoogleCharts\Charts\PieChart;
use DateTime;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\UX\Chartjs\Builder\ChartBuilderInterface;
use Symfony\UX\Chartjs\Model\Chart;
class RapoarteManagementController extends AbstractController
{
/**
* @Route("/rapoarte/management", name="app_rapoarte_management")
*/
public function index(UserRepository $userRepository, SarciniRepository $sarciniRepository, NotificariRepository $notificariRepository): Response
{
$user = $this->getUser();
$sarciniInLucru = $sarciniRepository->findBy(['responsabil' => $user]);
$cntCurrentDay = 0;
$pastDueCurrentDay = 0;
$cntNotif = 0;
foreach ($sarciniInLucru as $sarcini) {
$status = $sarcini->getStatus();
$date = $sarcini->getDate()->format('Y/m/d');
$date2 = new DateTime($date, new \DateTimeZone('Europe/Bucharest'));
$now = new DateTime("today", new \DateTimeZone('Europe/Bucharest'));
if ($status == 'In Lucru' && $date2 == $now) {
$cntCurrentDay++;
} elseif ($status == 'In Lucru' && $date2 < $now) {
$pastDueCurrentDay++;
}
}
$notificari = $notificariRepository->findBy(['responsabil' => $user, 'viewed' => null]);
foreach ($notificari as $notificare) {
$cntNotif++;
}
$allSarcini = $sarciniRepository->findBy(['Status'=>'In Lucru']);
$cntAllSarciniToday= 0;
$cntAllPastDue = 0;
foreach ($allSarcini as $sarcina){
$dateAll = $sarcina->getDate()->format('Y/m/d');
$dateAll2 = new DateTime($dateAll, new \DateTimeZone('Europe/Bucharest'));
$now = new DateTime("today", new \DateTimeZone('Europe/Bucharest'));
if ($dateAll2 == $now) {
$cntAllSarciniToday++;
} elseif ( $dateAll2 < $now) {
$cntAllPastDue++;
}
}
//
return $this->render('rapoarte_management/index.html.twig', [
'cntCurrentDay' => $cntCurrentDay,
'pastDueCurrentDay' => $pastDueCurrentDay,
'cntNotif' => $cntNotif,
'cntAllSarciniToday'=>$cntAllSarciniToday,
'cntAllPastDue'=>$cntAllPastDue
]);
}
}