<?php
namespace App\Controller;
use App\Entity\Inversion;
use App\Entity\Tramite;
use App\Repository\UsuarioRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use App\Entity\Usuario;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Doctrine\ORM\Query\ResultSetMapping;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
/**
* @Route("/home")
*
*/
class HomeController extends AbstractController
{
/**
* @Route("/", name="home")
*/
public function index(UsuarioRepository $usuario, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$em = $this->getDoctrine()->getManager();
$sistemas = $usuario->findCustomAll();
if ($this->isGranted('ROLE_ADMIN') || $this->isGranted('ROLE_SUPER_ADMIN')) {
$monto_mensual = $em->getRepository(Inversion::class)->inversionMensual();
$monto_inversion_total = $em->getRepository(Inversion::class)->montoInversion();
$monto_pagar = $em->getRepository(Inversion::class)->montoPagar();
$monto_interes = $em->getRepository(Inversion::class)->montoIntereses();
$total_fondeadores = $em->getRepository(Inversion::class)->totalFondeadores();
$map = new ResultSetMapping();
$map->addScalarResult('anio', 'anio');
$map->addScalarResult('mes', 'mes');
$map->addScalarResult('total', 'total');
$query = $em->createNativeQuery("SELECT
DATE_FORMAT(created, '%Y') AS anio,
DATE_FORMAT(created, '%m') AS mes,
COUNT(id) AS total
FROM
datos_usuario
GROUP BY DATE_FORMAT(created, '%Y%m')", $map);
$resultset = $query->getResult();
$lista_unidades = array();
foreach ($resultset as $row) {
if (!is_null($row['mes'])) {
$lista_unidades[] = '["' . $row['anio'] . '-' . $row['mes'] . '", ' . $row['total'] . ']';
}
}
$pedidos = '[';
$pedidos .= implode(', ', $lista_unidades) . ']';
return $this->render('home/index.html.twig', [
'pedidos' => $pedidos,
'hoy' => date('Y-m-d'),
'monto_mensual' => $monto_mensual,
'monto_inversion_total' => $monto_inversion_total,
'monto_pagar' => $monto_pagar,
'monto_interes' => $monto_interes,
'total_fondeadores' => $total_fondeadores,
]);
}elseif ($this->isGranted('ROLE_FONDEADOR')){
$monto_mensual = $em->getRepository(Inversion::class)->inversionMensualFondeador($this->getUser()->getId());
$monto_inversion = $em->getRepository(Inversion::class)->montoInversionFondeador($this->getUser()->getId());
$monto_pagar = $em->getRepository(Inversion::class)->montoPagarFondeador($this->getUser()->getId());
$monto_interes = $em->getRepository(Inversion::class)->montoInteresFondeador($this->getUser()->getId());
return $this->render('home/fondeador.html.twig', [
'monto_mensual' => $monto_mensual,
'monto_inversion_total' => $monto_inversion,
'monto_pagar' => $monto_pagar,
'monto_interes' => $monto_interes,
'hoy' => date('Y-m-d'),
]);
}else{
return $this->render('home/default.html.twig', [
]);
}
}
/**
* @Route("/adminDashboard", name="adminDashboard")
*/
public function adminDashboard()
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$this->denyAccessUnlessGranted('ROLE_ADMIN');
// or add an optional message - seen by developers
$this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'User tried to access a page without having ROLE_ADMIN');
return $this->render('home/index.html.twig', [
'controller_name' => 'HomeController',
]);
}
}