<?php
namespace App\Controller;
use App\Entity\Invoice;
use App\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\EntityRepository;
use App\Entity\Customer;
use App\Entity\OrderProduct;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\HttpFoundation\Session\Session;
/**
* Require ROLE_ADMIN for *every* controller method in this class.
*
* @IsGranted("ROLE_USER")
*/
class DefaultController extends AbstractController
{
/**
* @Route("/", name="homepage")
*
*/
public function index(Session $session)
{
$session = new Session();
$locale = $this->getUser()->getLocale();
$session->set('_locale', $locale);
$url = $locale.'/home';
//return $this->redirectToRoute('home');
return $this->redirect($url);
}
/**
* @Route(
* "/{_locale}/home",
* name="home",
* requirements={
* "_locale": "%app_locales%",
* }
* )
*/
public function home(Request $request, TranslatorInterface $translator)
{
$locale = $request->getLocale();
if ($this->isGranted("ROLE_ADMIN"))
{
$i = $request->get('form');
if ($i==1)
{
$dateDeb = new \DateTime($request->get('dateD'));
$dateFin = new \DateTime($request->get('dateF'));
$dateDeb = $dateDeb -> format('Y-m-d');
$dateFin = $dateFin -> format('Y-m-d');
}
else
{
$date = new \DateTime();
$dateDeb = $date -> format('Y-m-01');
$dateFin = $date -> format('Y-m-t');
}
$stats = $this->getDoctrine()->getManager()->getRepository(OrderProduct::class)->statProductOrder($dateDeb, $dateFin, $this->getUser()->getShopID());
return $this->render('default/index.html.twig', ['dateD' => $dateDeb, 'dateF' => $dateFin, 'stats' => $stats]);
}
else
{
if ($this->getUser()->getSigned() == false)
{
$this->addFlash('alert', 'Attention, vous n\'avez pas encore accepté la convention, pour le faire, veuillez cliquer ici
');
}
if ($this->isGranted("ROLE_LOG"))
{
$now = new \DateTime('now');
$year = $now->format('Y');
$invoices = $this->getDoctrine()->getManager()->getRepository(Invoice::class)->findAdmin($year);
return $this->render('default/index_log.html.twig', ['invoices' => $invoices,]);
}
else
{
$customers = $this->getDoctrine()->getManager()->getRepository(Customer::class)->customerBoost(array(['user_id' => $this->getUser()]));
return $this->render('default/index_user.html.twig', ['customers' => $customers, 'locale' => $locale]);
}
}
}
/**
* @Route("/phpmyadmin", name="phpmyadmin")
*/
public function phpmyadmin(Request $request)
{
return $this->redirect('/dev/phpMyAdmin5/index.php', 301);
}
/**
* @Route("/winbooks", name="winbooks")
*/
public function winbooks(Request $request)
{
return $this->redirect('/dev/winbooks/index.php', 301);
}
}