<?php
namespace App\Controller\User;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use App\Services\GainpfEmpHelper;
use App\Services\LoanFunctions;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Entity;
use Symfony\Component\HttpFoundation\JsonResponse;
//use Security\AppSecurity\Security\Keys\SecuredLoginKeys;
use App\Security\Keys\SecuredLoginKeys;
use App\Interfaces\AuditableControllerInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use App\Form;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormEvent;
use Doctrine\ORM\EntityRepository;
class DefaultController extends AbstractController implements \App\Interfaces\AuditableControllerInterface
{
private $GainpfEmpHelper;
public function __construct(GainpfEmpHelper $GainpfEmpHelper,LoanFunctions $LoanFunctions)
{
$this->GainpfEmpHelper = $GainpfEmpHelper;
$this->LoanFunctions = $LoanFunctions;
}
/**
* @Route("/", name="_index")
*/
public function indexAction()
{
return $this->redirect($this->generateUrl('app_home'));
//return $this->render('User/Default/index.html.twig');
$user = $this->container->get('security.token_storage')->getToken()->getUser();
$paoid = $this->GainpfEmpHelper->getPao()->getId();
$objEntityManager = $this->getDoctrine()->getManager();
$level = $this->GainpfEmpHelper->getLevelCode();
$passwordStatus = $this->GainpfEmpHelper->getUserPasswordStatus();
if ($passwordStatus == 0) {
return $this->redirectToRoute("change_password_forced");
}
if (!$level) {
$paocdWithotPfno = $this->GainpfEmpHelper->getPaocdWithotPfno();
if($paocdWithotPfno){
$error[] = array('info' => 'danger', 'data' => 'Your department id not yet set. Please update it from principal login');
return $this->render('bene_dashboard/pages/dash_bene_error.html.twig', array('data' => $error));
} else{
return $this->render('Dashboard/error.html.twig');
}
} else {
$level = $level->getId();
}
if ($user->hasRole('ROLE_PAO_ADMIN')) {
$query = $objEntityManager->getRepository('App:MasterGainpfPao')->findOneBy(array('id' => $paoid));
$paoName = $query->getPaoDescrption();
return $this->render('Dashboard/admin.html.twig', array('paoName' => $paoName));
} elseif ($user->hasRole('ROLE_PAO_EMPLOYEE') || $user->hasRole('ROLE_OFFICE_ADMIN') || $user->hasRole('ROLE_OFFICE_EO_EMP') || $user->hasRole('ROLE_RO_USER')) {
$userDetails = $this->GainpfEmpHelper->getUserDetails();
return $this->render('bene_dashboard/employee_dashboard_page.html.twig', array('userDetails' => $userDetails));
} else if ($user->hasRole('ROLE_INST_EMP')) {
return $this->redirectToRoute("beneficiary_home");
} elseif ($user->hasRole('ROLE_OFFICE_EO_ADMIN') || $user->hasRole('ROLE_RO_ADMIN')) {
$userDetails = $this->GainpfEmpHelper->getUserDetails();
return $this->render('Dashboard/aeoadmin.html.twig', array('userDetails' => $userDetails));
} elseif ($user->hasRole('ROLE_OFFICE_EO_EMP')) {
return $this->render('Dashboard/aeoemp.html.twig');
} elseif ($user->hasRole('ROLE_INST_ADMIN')) {
$userDetails = $this->GainpfEmpHelper->getUserDetails();
return $this->render('Dashboard/employeeInst.html.twig', array('userDetails' => $userDetails));
} elseif ($user->hasRole('ROLE_GOVT_HM')) {
$userDetails = $this->GainpfEmpHelper->getUserDetails();
return $this->render('bene_dashboard/employee_dashboard_page.html.twig', array('userDetails' => $userDetails));
} elseif ($user->hasRole('ROLE_FINANCE')) {
$userDetails = $this->GainpfEmpHelper->getUserDetails();
return $this->render('bene_dashboard/employee_dashboard_page.html.twig', array('userDetails' => $userDetails));
} elseif ($user->hasRole('ROLE_OFFICE_EMP')) {
$type = array();
$type[0] = 0;
$type[1] = $paoid;
$em = $this->getDoctrine()->getManager();
$officeId = $this->GainpfEmpHelper->getOffice()->getId();
$em = $this->getDoctrine()->getManager();
$userDetails = $this->GainpfEmpHelper->getUserDetails();
$level = $this->GainpfEmpHelper->getLevel()->getLevelCode()->getId();
$office = $this->GainpfEmpHelper->getOffice()->getId();
$paoId = $this->GainpfEmpHelper->getPao();
//-------------Dashboard requirements-----------------------
$statistics = $em->getRepository('App:Statistics\Statistics')->findOneBy(['level' => $level, 'officeId' => $office]);
if ($statistics) {
$data = array();
$jsonDecodedContent = json_decode($statistics->getContent());
$data['Pending Loans'] = ['count' => $jsonDecodedContent->pending_loan, 'icon' => 'fa-file-text', 'bg' => 'bg-aqua', 'url' => 'pendingLoans_arrears'];
$data['Sanctioned Loans'] = ['count' => $jsonDecodedContent->sanctioned, 'icon' => 'fa-check', 'bg' => 'bg-red', 'url' => 'paoadmin_DDOSanctiondist'];
$data['Pending Credit'] = ['count' => $jsonDecodedContent->pending_credit, 'icon' => 'fa-file-text', 'bg' => 'bg-green', 'url' => 'credit_data_pending_acceptance'];
$data['Pending Debit'] = ['count' => $jsonDecodedContent->pending_debit, 'icon' => 'fa-file-text', 'bg' => 'bg-blue', 'url' => 'debit_data_pending_acceptance'];
$data['Credit data to be verified'] = ['count' => $jsonDecodedContent->not_ver_credit, 'icon' => 'fa fa-tasks', 'bg' => 'bg-aqua', 'url' => 'credit_data_pending_verification'];
$data['Debit data to be verified'] = ['count' => $jsonDecodedContent->not_ver_debit, 'icon' => 'fa fa-tasks', 'bg' => 'bg-green', 'url' => 'debit_data_pending_verification'];
$seatObj = $em->getRepository('App:GainpfSeatPanel')->findByEmpId($userDetails);
if ($seatObj) {
$seat = array();
foreach ($seatObj as $soffices) {
$seat[] = $soffices->getSeatId()->getId();
}
} else {
$seat = '';
}
if ($seat != '') {
$offices = $em->getRepository('App:MasterGainpfoffice')->getOfficesForCreditData($seat, $office);
foreach ($offices as $office) {
// $OfficeWithCode['All'] = '--All--';
$OfficeWithCode[$office['id']] = $office['officeCd'] . '-' . $office['officeName'];
}
$a[] = array_keys($OfficeWithCode);
foreach (array_shift($a) as $one) {
$b[] = $one;
}
$summaryCredit = $em->getRepository('App:GainpfCreditbillsSummaryTemp')->getSummaryAllDash($paoId, $b);
$data['Credit data to be verified in Seat'] = ['count' => $summaryCredit, 'icon' => 'fa fa-tasks', 'bg' => 'bg-green', 'url' => 'credit_data_pending_verification_seat'];
$summaryDebit = $em->getRepository('App:GainpfDebitbillSummary')->getSummaryAllDash($paoId, $b);
$data['Debit data to be verified in Seat'] = ['count' => $summaryDebit, 'icon' => 'fa fa-tasks', 'bg' => 'bg-red', 'url' => 'debit_data_pending_verification_seat'];
}
} else {
return $this->render('bene_dashboard/employee_dashboard_page.html.twig', array('userDetails' => $userDetails));
}
//-----------------------------------------------------------
return $this->render('bene_dashboard/employee_clone_page.html.twig', array('userDetails' => $userDetails, 'data' => $data));
}
}
/**
* @Route("portal/paoadmin/reportList/", name="creditDebit_listing1")
*/
public function reportListAction()
{
$em = $this->getDoctrine()->getManager();
for ($i = 8; $i <= 19; $i++) {
// $year[$i] = $em->getRepository('AppBundle:GainpfCreditbills')->getDistYear($i);
$bills[$i] = $em->getRepository('App:GainpfCreditbills')->getBillsNew($i);
}
return $this->render('Default/creditDebitReport.html.twig', array('bills' => $bills));
}
}