<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Doctrine\Persistence\ManagerRegistry;
use Psr\Log\LoggerInterface;
use App\Entity\DicGouvernorat;
use App\Entity\DicDelegation;
use App\Entity\DicImada;
use App\Entity\DicEspece;
use App\Entity\DicRace;
use App\Entity\Troupeau;
use App\Entity\Ferme;
use App\Entity\Animal;
use App\Entity\Eleveur;
use App\Entity\Inseminateur;
use App\Entity\AgentOep;
use App\Entity\Agent;
use App\Entity\User;
use App\Entity\OperationIdentification;
use App\Entity\OperationInsemination;
use App\Entity\DemandeRebouclage;
use App\Entity\DemandeAcquisition;
use App\Entity\DemandeEnree;
use App\Entity\DemandeSortie;
use App\Entity\DemandeUpdate;
use App\Entity\DemandeFormation;
use App\Entity\DocDiplome;
use App\Form\EleveurType;
use App\Form\InseminateurType;
use App\Form\AgentOepType;
use App\Form\AgentType;
use App\Form\DemandeFormationType;
use PhpOffice\PhpSpreadsheet\IOFactory;
use TCPDF;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
/**
* @Route("/{_locale}", requirements={"_locale": "ar|fr"})
*/
class AgentOepController extends AbstractController
{
#[Route('/agent/oep', name: 'app_agent_oep')]
public function index(): Response
{
return $this->render('agent_oep/index.html.twig', [
'controller_name' => 'AgentOepController',
]);
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/rapprts/list', name: 'agent_oep_rapport_annee_list', methods: ['GET', 'POST'])]
public function rapportByAnnee(Request $request, ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$user = $this->getUser();
// Récupérer la valeur de l'année dans l'URL
$annee = $request->query->get('annee');
// Si la valeur n'est pas définie dans l'URL, utiliser l'année en cours
if (!$annee) {
$annee = date('Y');
}
$anneeCourant = date('Y');
return $this->render('agent_oep/rapports.html.twig', [
'controller_name' => 'ProfilController',
'annee'=> $annee,
'anneeCourant'=>$anneeCourant
]);
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/rapprts/find', name: 'agent_oep_rapport_find', methods: ['GET', 'POST'])]
public function findRapportByAnnee(Request $request, ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$user = $this->getUser();
return $this->redirectToRoute('agent_oep_rapport_annee_list',['annee'=>$request->request->get('annee')]);
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/rapprts/{annee}/{mois}/list', name: 'agent_oep_rapport_list', methods: ['GET', 'POST'])]
public function rapportList(Request $request, int $annee, int $mois, ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$user = $this->getUser();
$agent=$doctrine->getRepository(AgentOep::class)->findOneBy(['user'=>$user]);
$idGouvernorat=-1;
if($agent->getGouvernorat() != null){
$idGouvernorat=$agent->getGouvernorat()->getId();
}
if($agent->isIsCentral() == true){
$operations= $doctrine->getRepository(OperationIdentification::class)->findBy(['annee'=>$annee, 'mois'=>$mois]);
}else{
$operations= $doctrine->getRepository(OperationIdentification::class)->getListByGouvernorat($idGouvernorat,$annee,$mois);
}
//dump($operations);die;
return $this->render('agent_oep/rapports_list.html.twig', [
'controller_name' => 'ProfilController',
'operations'=>$operations,
'annee'=> $annee,
'mois'=> $mois
]);
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/operationIdent/{annee}/{mois}/add', name: 'agent_oep_operation_ident_add')]
public function operationIdentAdd(Request $request, int $annee, int $mois, ManagerRegistry $doctrine): Response
{
$em = $doctrine->getManager();
$user = $this->getUser();
$agent=$doctrine->getRepository(AgentOep::class)->findOneBy(['user'=>$user]);
$eleveurs= $doctrine->getRepository(Eleveur::class)->findBy(['gouvernorat'=>$agent->getGouvernorat()]);
// dump($agent, $eleveurs);
$especes= $doctrine->getRepository(DicEspece::class)->findAll();
$minDate = new \DateTime(sprintf('01-%02d-%04d', $mois, $annee));
if($mois ==2 ){
$maxDate = new \DateTime(sprintf('28-%02d-%04d', $mois, $annee));
}else{
$maxDate = new \DateTime(sprintf('31-%02d-%04d', $mois, $annee));
}
return $this->render('agent_oep/add_indentification.html.twig', [
'controller_name' => 'ProfilController',
'eleveurs'=>$eleveurs,
'especes'=>$especes,
'annee'=> $annee,
'mois'=> $mois,
'minDate'=> $minDate,
'maxDate' => $maxDate
]);
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/rapprts/{annee}/{mois}/add', name: 'agent_oep_rapport_add')]
public function rapportAdd(Request $request, int $annee, int $mois, ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$user = $this->getUser();
$agent=$doctrine->getRepository(AgentOep::class)->findOneBy(['user'=>$user]);
$eleveur=$doctrine->getRepository(Eleveur::class)->find($request->request->get('ident_eleveur'));
$ferme=$doctrine->getRepository(Ferme::class)->find($request->request->get('ferme'));
$race=$doctrine->getRepository(DicRace::class)->find($request->request->get('race'));
$troupeau=$doctrine->getRepository(Troupeau::class)->find($request->request->get('troupeau'));
$codAgent = $agent->getIdentAgent();
$demande = new OperationIdentification();
$demande->setEleveur($eleveur);
$demande->setIdentAnimal($request->request->get('ident'));
$demande->setFerme($ferme);
$demande->setDicRace($race);
$demande->setTroupeau($troupeau);
$demande->setDateOp(new \DateTime($request->request->get('date')));
$demande->setAnnee($annee);
$demande->setMois($mois);
$demande->setSexAnm($request->request->get('sexe'));
$demande->setAnnNai($request->request->get('ann_nais'));
$demande->setDateNai(new \DateTime($request->request->get('date_nais')));
$demande->setEtatTraitement(0);
$demande->setCreatedAt(new \DateTime());
$demande->setCodAgent($codAgent);
$em->persist($demande);
$em->flush();
return $this->redirectToRoute('agent_oep_rapport_list',['annee'=>$annee,'mois'=>$mois]);
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/operationIdent/{id}/edit', name: 'agent_oep_operation_ident_edit')]
public function operationIdentEdit(Request $request, OperationIdentification $operation, ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$user = $this->getUser();
$agent=$doctrine->getRepository(AgentOep::class)->findOneBy(['user'=>$user]);
$eleveurs= $doctrine->getRepository(Eleveur::class)->findBy(['gouvernorat'=>$agent->getGouvernorat()]);
$fermes= $doctrine->getRepository(Ferme::class)->findBy(['eleveur'=>$operation->getEleveur()]);
$troupeaux= $doctrine->getRepository(Troupeau::class)->findBy(['ferme'=>$operation->getFerme()]);
$especes= $doctrine->getRepository(DicEspece::class)->findAll();
$races= $doctrine->getRepository(DicRace::class)->findBy(['dicEspece'=>$operation->getDicRace()->getDicEspece()]);
// dump($operation,$eleveurs);die;
return $this->render('agent_oep/edit_indentification.html.twig', [
'controller_name' => 'ProfilController',
'operation'=>$operation,
'eleveurs'=>$eleveurs,
'fermes'=>$fermes,
'troupeaux'=>$troupeaux,
'especes'=>$especes,
'races'=>$races,
'annee'=> $operation->getAnnee(),
'mois'=> $operation->getMois()
]);
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/rapprts/{id}/edit', name: 'agent_oep_rapport_edit')]
public function rapportEdit(Request $request, OperationIdentification $operation, ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$user = $this->getUser();
$eleveur=$doctrine->getRepository(Eleveur::class)->find($request->request->get('ident_eleveur'));
$ferme=$doctrine->getRepository(Ferme::class)->find($request->request->get('ferme'));
$race=$doctrine->getRepository(DicRace::class)->find($request->request->get('race'));
$troupeau=$doctrine->getRepository(Troupeau::class)->find($request->request->get('troupeau'));
$agent=$doctrine->getRepository(AgentOep::class)->findOneBy(['user'=>$user]);
$operation->setEleveur($eleveur);
$operation->setIdentAnimal($request->request->get('ident'));
$operation->setFerme($ferme);
$operation->setDicRace($race);
$operation->setTroupeau($troupeau);
$operation->setSexAnm($request->request->get('sexe'));
$operation->setAnnNai($request->request->get('ann_nais'));
$operation->setDateNai(new \DateTime($request->request->get('date_nais')));
$operation->setDateOp(new \DateTime($request->request->get('date')));
$operation->setUpdatedAt(new \DateTime());
$em->persist($operation);
$em->flush();
return $this->redirectToRoute('agent_oep_rapport_list',['annee'=>$operation->getAnnee(),'mois'=>$operation->getMois()]);
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/rapprts/{id}/{annee}/{mois}/traiter', name: 'agent_oep_rapport_traiter', methods: ['GET', 'POST'])]
public function rapportSend(Request $request,OperationIdentification $demande,int $annee, int $mois,ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$demande->setEtatTraitement(1);
$demande->setUpdatedAt(new \DateTime());
$em->persist($demande);
$em->flush();
/* $animal = new Animal();
$animal->setEleveur($demande->getEleveur());
$animal->setTroupeau($demande->getTroupeau());
$animal->setDicRace($demande->getDicRace());
$animal->setIdentAnm($demande->getIdentAnimal());
$animal->setSexAnm($demande->getSexAnm());
$animal->setDateNai($demande->getDateNai());
$animal->setAnnNai($demande->getAnnNai());
$animal->setCreatedAt(new \DateTime());
$em->persist($animal);
$em->flush();*/
return $this->redirectToRoute('agent_oep_rapport_list',['annee'=>$annee,'mois'=>$mois]);
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/rapprts/{id}/{annee}/{mois}/delete', name: 'agent_oep_rapport_delete')]
public function rapportDelete(Request $request,OperationIdentification $demande,int $annee, int $mois, ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$em->remove($demande);
$em->flush();
return $this->redirectToRoute('agent_oep_rapport_list',['annee'=>$annee,'mois'=>$mois]);
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/demandes/list', name: 'agent_oep_demande_list', methods: ['GET', 'POST'])]
public function getDemandes(Request $request, ManagerRegistry $doctrine,LoggerInterface $logger): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$user = $this->getUser();
$agent=$doctrine->getRepository(AgentOep::class)->findOneBy(['user'=>$user]);
$s = $request->query->get('s');
$logger->info('sync ************************** '.$s.' ***********************');
$demandesReb = [];
$demandesAc = [];
$demandesEnt=[];
$demandesSort=[];
$demandesUpdate=[];
switch ($s) {
case '1':
if($agent->isIsCentral()== true){
$demandesReb = $doctrine->getRepository(DemandeRebouclage::class)->getDemandeEnvoyer();
}else{
$idGouvernorat=-1;
if($agent->getGouvernorat() != null){
$idGouvernorat=$agent->getGouvernorat()->getId();
}
$demandesReb = $doctrine->getRepository(DemandeRebouclage::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
}
break;
case '2':
if($agent->isIsCentral()== true){
$demandesUpdate=$doctrine->getRepository(DemandeUpdate::class)->getDemandeEnvoyer();
}else{
$idGouvernorat=-1;
if($agent->getGouvernorat() != null){
$idGouvernorat=$agent->getGouvernorat()->getId();
}
$demandesUpdate=$doctrine->getRepository(DemandeUpdate::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
}
break;
case '3':
if($agent->isIsCentral()== true){
$demandesAc = $doctrine->getRepository(DemandeAcquisition::class)->getDemandeEnvoyer();
}else{
$idGouvernorat=-1;
if($agent->getGouvernorat() != null){
$idGouvernorat=$agent->getGouvernorat()->getId();
}
$demandesAc = $doctrine->getRepository(DemandeAcquisition::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
}
break;
case '4':
if($agent->isIsCentral()== true){
$demandesEnt=$doctrine->getRepository(DemandeEnree::class)->getDemandeEnvoyer();
}else{
$idGouvernorat=-1;
if($agent->getGouvernorat() != null){
$idGouvernorat=$agent->getGouvernorat()->getId();
}
$demandesEnt=$doctrine->getRepository(DemandeEnree::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
}
break;
case '5':
if($agent->isIsCentral()== true){
$demandesSort=$doctrine->getRepository(DemandeSortie::class)->getDemandeEnvoyer();
}else{
$idGouvernorat=-1;
if($agent->getGouvernorat() != null){
$idGouvernorat=$agent->getGouvernorat()->getId();
}
$demandesSort=$doctrine->getRepository(DemandeSortie::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
}
break;
default:
if($agent->isIsCentral()== true){
$demandesReb = $doctrine->getRepository(DemandeRebouclage::class)->getDemandeEnvoyer();
$demandesAc = $doctrine->getRepository(DemandeAcquisition::class)->getDemandeEnvoyer();
$demandesEnt=$doctrine->getRepository(DemandeEnree::class)->getDemandeEnvoyer();
$demandesSort=$doctrine->getRepository(DemandeSortie::class)->getDemandeEnvoyer();
$demandesUpdate=$doctrine->getRepository(DemandeUpdate::class)->getDemandeEnvoyer();
}else{
$idGouvernorat=-1;
if($agent->getGouvernorat() != null){
$idGouvernorat=$agent->getGouvernorat()->getId();
}
$demandesReb = $doctrine->getRepository(DemandeRebouclage::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
$demandesAc = $doctrine->getRepository(DemandeAcquisition::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
$demandesEnt=$doctrine->getRepository(DemandeEnree::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
$demandesSort=$doctrine->getRepository(DemandeSortie::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
$demandesUpdate=$doctrine->getRepository(DemandeUpdate::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
}
break;
}
/*
if ($s == 1 ){
if($agent->isIsCentral()== true){
$demandesReb = $doctrine->getRepository(DemandeRebouclage::class)->getDemandeEnvoyer();
$demandesAc = [];
$demandesEnt=[];
$demandesSort=[];
$demandesUpdate=[];
}else{
$idGouvernorat=-1;
if($agent->getGouvernorat() != null){
$idGouvernorat=$agent->getGouvernorat()->getId();
}
$demandesReb = $doctrine->getRepository(DemandeRebouclage::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
$demandesAc = [];
$demandesEnt=[];
$demandesSort=[];
$demandesUpdate=[];
}
}elseif ( $s == 2) {
if($agent->isIsCentral()== true){
$demandesReb = [];
$demandesAc = [];
$demandesEnt=[];
$demandesSort=[];
$demandesUpdate=$doctrine->getRepository(DemandeUpdate::class)->getDemandeEnvoyer();
}else{
$idGouvernorat=-1;
if($agent->getGouvernorat() != null){
$idGouvernorat=$agent->getGouvernorat()->getId();
}
$demandesReb = [];
$demandesAc = [];
$demandesEnt=[];
$demandesSort=[];
$demandesUpdate=$doctrine->getRepository(DemandeUpdate::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
}
}elseif( $s = 3 ){
if($agent->isIsCentral()== true){
$demandesReb = [];
$demandesAc = $doctrine->getRepository(DemandeAcquisition::class)->getDemandeEnvoyer();
$demandesEnt=[];
$demandesSort=[];
$demandesUpdate=[];
}else{
$idGouvernorat=-1;
if($agent->getGouvernorat() != null){
$idGouvernorat=$agent->getGouvernorat()->getId();
}
$demandesReb = [];
$demandesAc = $doctrine->getRepository(DemandeAcquisition::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
$demandesEnt=[];
$demandesSort = [];
$demandesUpdate=[];
}
}elseif( $s = 4){
if($agent->isIsCentral()== true){
$demandesReb = [];
$demandesAc = [];
$demandesEnt=$doctrine->getRepository(DemandeEnree::class)->getDemandeEnvoyer();
$demandesSort=[];
$demandesUpdate=[];
}else{
$idGouvernorat=-1;
if($agent->getGouvernorat() != null){
$idGouvernorat=$agent->getGouvernorat()->getId();
}
$demandesReb = [];
$demandesAc = [];
$demandesEnt=$doctrine->getRepository(DemandeEnree::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
$demandesSort=[];
$demandesUpdate=[];
}
}elseif ($s = 5){
if($agent->isIsCentral()== true){
$demandesReb = [];
$demandesAc = [];
$demandesEnt=[];
$demandesSort=$doctrine->getRepository(DemandeSortie::class)->getDemandeEnvoyer();
$demandesUpdate=[];
}else{
$idGouvernorat=-1;
if($agent->getGouvernorat() != null){
$idGouvernorat=$agent->getGouvernorat()->getId();
}
$demandesReb = [];
$demandesAc = [];
$demandesEnt=[];
$demandesSort=$doctrine->getRepository(DemandeSortie::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
$demandesUpdate=[];
}
}else{
if($agent->isIsCentral()== true){
$demandesReb = $doctrine->getRepository(DemandeRebouclage::class)->getDemandeEnvoyer();
$demandesAc = $doctrine->getRepository(DemandeAcquisition::class)->getDemandeEnvoyer();
$demandesEnt=$doctrine->getRepository(DemandeEnree::class)->getDemandeEnvoyer();
$demandesSort=$doctrine->getRepository(DemandeSortie::class)->getDemandeEnvoyer();
$demandesUpdate=$doctrine->getRepository(DemandeUpdate::class)->getDemandeEnvoyer();
}else{
$idGouvernorat=-1;
if($agent->getGouvernorat() != null){
$idGouvernorat=$agent->getGouvernorat()->getId();
}
$demandesReb = $doctrine->getRepository(DemandeRebouclage::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
$demandesAc = $doctrine->getRepository(DemandeAcquisition::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
$demandesEnt=$doctrine->getRepository(DemandeEnree::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
$demandesSort=$doctrine->getRepository(DemandeSortie::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
$demandesUpdate=$doctrine->getRepository(DemandeUpdate::class)->getDemandeEnvoyerByGouvernorat($idGouvernorat);
}
} */
//dump($demandesReb,$demandesAc,$demandesUpdate,$demandesEnt);die;
return $this->render('agent_oep/demandes_list.html.twig', [
'controller_name' => 'ProfilController',
'demandesReb' => $demandesReb,
'demandesAc' => $demandesAc,
'demandesEnt' => $demandesEnt,
'demandesSort' => $demandesSort,
'demandesUpdate' => $demandesUpdate,
'agent'=>$agent
]);
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/demandes/rebouclage/{id}/{etat}/traiter', name: 'agent_oep_demandereb_traiter', methods: ['GET', 'POST'])]
public function demandeRebTraiter(Request $request, DemandeRebouclage $demande, int $etat, ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$user = $this->getUser();
$agent=$doctrine->getRepository(AgentOep::class)->findOneBy(['user'=>$user]);
$demande->setEtatTraitement($etat);
$demande->setCodAgn($agent->getIdentAgent());
$em->persist($demande);
$em->flush();
return $this->redirectToRoute('agent_oep_demande_list');
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/demandes/acquisition/{id}/{etat}/traiter', name: 'agent_oep_demanderacq_traiter', methods: ['GET', 'POST'])]
public function demandeAcTraiter(Request $request, DemandeAcquisition $demande, int $etat, ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$user = $this->getUser();
$agent=$doctrine->getRepository(AgentOep::class)->findOneBy(['user'=>$user]);
$codAgn = $agent->getIdentAgent();
$demande->setEtatTraitement($etat);
$demande->setCodAgn($codAgn);
$em->persist($demande);
$em->flush();
return $this->redirectToRoute('agent_oep_demande_list');
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/demandes/entree/{id}/{etat}/traiter', name: 'agent_oep_demande_ent_trait', methods: ['GET', 'POST'])]
public function demandeEntreeTraiter(Request $request, DemandeEnree $demande, int $etat, ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$user = $this->getUser();
$agent=$doctrine->getRepository(AgentOep::class)->findOneBy(['user'=>$user]);
$codAgn = $agent->getIdentAgent();
$demande->setEtatTraitement($etat);
$demande->setCodAgn($codAgn);
$em->persist($demande);
$em->flush();
return $this->redirectToRoute('agent_oep_demande_list');
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/demandes/sortie/{id}/{etat}/traiter', name: 'agent_oep_demande_sort_trait', methods: ['GET', 'POST'])]
public function demandeSortieTraiter(Request $request, DemandeSortie $demande, int $etat, ManagerRegistry $doctrine): Response
{
$em = $doctrine->getManager();
$user = $this->getUser();
$agent=$doctrine->getRepository(AgentOep::class)->findOneBy(['user'=>$user]);
$codAgn = $agent->getIdentAgent();
$demande->setEtatTraitement($etat);
$demande->setCodAgn($codAgn);
$em->persist($demande);
$em->flush();
return $this->redirectToRoute('agent_oep_demande_list');
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/demandes/update/{id}/{etat}/traiter', name: 'agent_oep_demande_upd_trait', methods: ['GET', 'POST'])]
public function demandeUpdateTraiter(Request $request, DemandeUpdate $demande, int $etat, ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$user = $this->getUser();
$agent=$doctrine->getRepository(AgentOep::class)->findOneBy(['user'=>$user]);
$codAg = $agent->getIdentAgent();
$demande->setEtatTraitement($etat);
$demande->setCodAgn($agent->getIdentAgent());
$em->persist($demande);
$em->flush();
return $this->redirectToRoute('agent_oep_demande_list');
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/formations/list', name: 'agent_oep_formations_list', methods: ['GET', 'POST'])]
public function formationsList(Request $request, ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$user = $this->getUser();
$agent=$doctrine->getRepository(AgentOep::class)->findOneBy(['user'=>$user]);
if($agent->isIsCentral() == true){
$formations = $doctrine->getRepository(DemandeFormation::class)->findAll();
}else{
$formations = $doctrine->getRepository(DemandeFormation::class)->findBy(['gouvernorat'=>$agent->getGouvernorat()]);
}
return $this->render('agent_oep/formations_list.html.twig', [
'controller_name' => 'ProfilController',
'formations' => $formations,
]);
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/formations/{id}/traiter', name: 'agent_oep_formation_traiter', methods: ['GET', 'POST'])]
public function formationTraiter(Request $request, DemandeFormation $demande, ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
if($request->request->get('etat') == '1'){
$demande->setEtatTraitement(2);
}else if($request->request->get('etat') == '0'){
$demande->setEtatTraitement(3);
}
$demande->setMotif($request->request->get('motif'));
$demande->setDateTraitement(new \DateTime());
$demande->setUpdatedAt(new \DateTime());
$em->persist($demande);
$em->flush();
return $this->redirectToRoute('agent_oep_formations_list');
}
/*************************************Add Formation*****************************************/
#[Route('/demande_formation/add', name: 'demande_formation_add', methods: ['GET', 'POST'])]
public function demandeFormationAdd(Request $request, ManagerRegistry $doctrine): Response
{
$em = $doctrine->getManager();
$user = $this->getUser();
$demandeFormation = new DemandeFormation();
$form = $this->createForm(DemandeFormationType::class, $demandeFormation);
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($request->request->has('g-recaptcha-response')) {
if ($request->request->get('g-recaptcha-response') != '') {
$doc = $request->files->get('demande_formation')['docDiplomes'];
if ($doc != null) {
// Vérification stricte du type de fichier
$ext = strtolower($doc->getClientOriginalExtension());
if ($ext !== 'pdf') {
$this->addFlash('failure_insert_pdf', 'true');
return $this->render('formations/add_demande_formation.html.twig', [
'controller_name' => 'ProfilController',
'form' => $form->createView()
]);
}
$demandeFormation->setEtatTraitement(1);
$demandeFormation->setDateDemande(new \DateTime());
$demandeFormation->setCreatedAt(new \DateTime());
$em->persist($demandeFormation);
$em->flush();
$imageName = 'diplome_' . uniqid() . '.' . $ext;
$nameFile = $doc->getClientOriginalName();
$doc->move('uploads/demande_formation/diplomes', $imageName);
$fileNew = new DocDiplome();
$fileNew->setDemandeFormation($demandeFormation);
$fileNew->setNomOriginale($nameFile);
$fileNew->setNomFichier($imageName);
$fileNew->setCreatedAt(new \DateTime());
$em->persist($fileNew);
$em->flush();
return $this->render('formations/insert_success.html.twig', [
'controller_name' => 'ProfilController',
]);
}
}
}
$this->addFlash('failure_insert', 'true');
$user->setEmail($request->request->get('email'));
$user->setUsername($request->request->get('username'));
return $this->render('formations/add_demande_formation.html.twig', [
'controller_name' => 'ProfilController',
'form' => $form->createView()
]);
}
return $this->render('formations/add_demande_formation.html.twig', [
'controller_name' => 'ProfilController',
'form' => $form->createView()
]);
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/rapportIns/list', name: 'agent_oep_rapport_ins_annee_list', methods: ['GET', 'POST'])]
public function rapportInsByAnnee(Request $request, ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$user = $this->getUser();
// Récupérer la valeur de l'année dans l'URL
$annee = $request->query->get('annee');
// Si la valeur n'est pas définie dans l'URL, utiliser l'année en cours
if (!$annee) {
$annee = date('Y');
}
$anneeCourant = date('Y');
return $this->render('agent_oep/rapports_ins.html.twig', [
//'controller_name' => 'ProfilController',
'annee'=> $annee,
'anneeCourant'=>$anneeCourant
]);
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/agentOEP/rapportIns/{annee}/{mois}/list', name: 'agent_oep_rapport_ins_list', methods: ['GET', 'POST'])]
public function rapportInsList(Request $request, int $annee, int $mois, ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$user = $this->getUser();
$agent=$doctrine->getRepository(AgentOep::class)->findOneBy(['user'=>$user]);
if($agent->isIsCentral() == true){
$inseminateurs = $doctrine->getRepository(Inseminateur::class)->findAll();
}else{
$inseminateurs = $doctrine->getRepository(Inseminateur::class)->findBy(['dicGouvernorat' => $agent->getGouvernorat()]);
}
$etat = 0;
$inss = [];
foreach ($inseminateurs as $ins) {
$insem = $ins->getCodIns();
$operationsIns = $doctrine->getRepository(OperationInsemination::class)->getListByCircuitAndInsAndEtat($annee, $mois, $insem);
$operationsIns2 = $doctrine->getRepository(OperationInsemination::class)->getListByCircuitAndIns($annee, $mois, $insem);
if ($operationsIns) {
$inss[] = $ins->getId();
$etat = 1;
} else {
$etat = 2;
}
if ($operationsIns2 ) {
$etat = 1;
} else {
$inss[] = $ins->getId();
}
}
//dump($inseminateurs,$operationsIns,$inss);die;
return $this->render('agent_oep/rapports_list_ins.html.twig', [
'controller_name' => 'ProfilController',
'inseminateurs' => $inseminateurs,
'annee'=>$annee,
'mois'=>$mois,
'inss'=>$inss,
]);
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
#[Route('/pdf/agent/generator/rapport/ins/{annee}/{mois}/{ins}', name: 'agentOep_pdf_generator', methods: ['GET', 'POST'])]
public function rapportPdf(Request $request, int $annee, int $mois, int $ins , ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$user = $this->getUser();
$inseminateur = $doctrine->getRepository(Inseminateur::class)->findOneBy(['id' => $ins]);
$ins = $inseminateur->getCodIns();
$operationsIns = $doctrine->getRepository(OperationInsemination::class)->getListByCircuitANDIns($annee, $mois, $ins);
// Render the 'rapport_pdf.html.twig' template to generate HTML content
$htmlContent = $this->renderView('inseminateur/rapport_pfd.html.twig', [
'data' => $operationsIns,
'inseminateur' => $inseminateur,
'mois'=>$mois,
'annee'=>$annee
]);
// Create a TCPDF instance
// $pdf = new TCPDF();
$pdf = new TCPDF('L', 'mm', 'A4', true, 'UTF-8', false);
// $pdf->SetFont('dejavusans', '', 12);
$pdf->SetFont('freeserif', '', 11);
$pdf->setRTL(true);
// Add a page
/*$pdf->AddPage();*/
$pdf->AddPage('L');
// Add the HTML content to the PDF
// $pdf->writeHTML($htmlContent);
$pdf->writeHTML($htmlContent, true, false, true, false, '');
// Close and output the PDF
$pdf->Output('Rapport_Insemination.pdf', 'D');
return new Response();
}
/**
* @IsGranted("ROLE_AGENT_OEP")
*/
/**
* @Route("/csv/generator/rapport/ins/{annee}/{mois}/{ins}", name="agentOep_excel_generator", methods={"GET", "POST"})
*/
public function rapportExcel(Request $request, int $annee, int $mois, int $ins, ManagerRegistry $doctrine): Response
{
if($this->isGranted('ROLE_AGENT_OEP')== false){
return $this->render('erreur/access_denied.html.twig', []);
}
$em = $doctrine->getManager();
$user = $this->getUser();
$inseminateur = $doctrine->getRepository(Inseminateur::class)->findOneBy(['id' => $ins]);
$ins = $inseminateur->getCodIns();
$operationsIns = $doctrine->getRepository(OperationInsemination::class)->getListByCircuitANDIns($annee, $mois, $ins);
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$writer = IOFactory::createWriter($spreadsheet, 'Csv');
$writer->setUseBOM(true);
$writer->setDelimiter(';');
$writer->setEnclosure('');
$writer->setLineEnding("\r\n");
// Écrire les en-têtes
$enTetes = [
'gouv',
$inseminateur->getDicGouvernorat()->getCodeGou(),
$inseminateur->getDicGouvernorat()->getGouvernorat(),
];
$sheet->fromArray([$enTetes], null, 'A1', true);
$enTetes = [
'num circuit',
$inseminateur->getDicCircuit()->getCodCircuit(),
$inseminateur->getDicCircuit()->getDesCirLt(),
];
$sheet->fromArray([$enTetes], null, 'A2', true);
$enTetes = [
'cod inséminateur',
$inseminateur->getCodIns(),
$inseminateur->getNprInsFr(),
];
$sheet->fromArray([$enTetes], null, 'A3', true);
$enTetes = [
'N° animal',
'Date inséminat',
'N° taureau',
'CIN',
'',
'',
];
$sheet->fromArray([$enTetes], null, 'A5', true);
$row = 5; // Commencer à la ligne 5 pour les en-têtes
foreach ($operationsIns as $item) {
$row++;
$rowData = [
$item['numero_animal'],
$item['date_op'],
$item['numero_taureau'],
$item['numero_eleveur'],
'',
''
];
$sheet->fromArray([$rowData], null, 'A' . $row, true);
}
$response = new Response();
$response->headers->set('Content-Type', 'text/csv');
$response->headers->set('Content-Disposition', 'attachment; filename="Rapport_Insemination.csv');
$writer->save('php://output');
return $response;
}
}