<?php
namespace App\Controller;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Constraints\DateTime;
use App\Entity\DemandeAcquisition;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use App\Entity\DemandeSortie;
use App\Entity\DemandeUpdate;
use App\Entity\DemandeEnree;
use App\Entity\DemandeFormation;
use App\Entity\DemandeIdentification;
use App\Entity\DemandePrgAmelioration;
use App\Entity\DemandeRebouclage;
use App\Entity\OperationInsemination;
use App\Entity\ProgrammeAmelioration;
use App\Entity\DicEspece;
use App\Entity\DicRace;
use App\Entity\Eleveur;
use App\Entity\DicGouvernorat;
use App\Entity\DicDelegation;
use App\Entity\DicImada;
use App\Entity\Ferme;
use App\Entity\Troupeau;
use App\Entity\DicCircuit;
use App\Entity\CircuitImada;
use App\Entity\Animal;
use App\Entity\AgentOep;
use App\Entity\Agent;
use App\Entity\Adhesion;
use App\Entity\Inseminateur;
use Symfony\Component\HttpFoundation\JsonResponse;
use Psr\Log\LoggerInterface;
class SyncronisationController extends AbstractController
{
private $em, $translator;
private $serverIp;
public function __construct(EntityManagerInterface $em, TranslatorInterface $translator , ParameterBagInterface $params)
{
$this->em = $em;
$this->translator = $translator;
$this->serverIp = $_SERVER['SYNC_SERVER_IP'];
}
private function checkClientIp(Request $request): bool
{
$rip = $request->getClientIp();
return $rip === $this->serverIp;
}
#[Route('/api/AllDemandes', name: 'app_Demande_sortie')]
public function index(LoggerInterface $logger, Request $request)
{
$rip = $request->getClientIp();
$logger->info('api Synchro AllDemandes, ' . $rip);
/*if ($rip != $serverIp && $rip != '') {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}*/
if (!$this->checkClientIp($request)) {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}
$em = $this->em;
$content = $request->getContent();
$dataRecp = json_decode($content, true);
$logger->info('rebouclage1 : ***************** ' . $content);
$logger->info('rebouclage1 : *****************' . count($dataRecp));
$dernierRebouclage = $dataRecp["dernierRebouclage"];
$dernierUpdate = $dataRecp["dernierUpdate"];
$dernierPrgAmel = $dataRecp["dernierAmelioration"];
$dernierAcquisition = $dataRecp["dernierAcquisition"];
$dernierIdentification = $dataRecp["dernierIdentification"];
$dernierSortie = $dataRecp["dernierSortie"];
$dernierEntre = $dataRecp["dernierEntree"];
$dernierFormation = $dataRecp["dernierFormation"];
$dernierInsemination = $dataRecp["dernierInsemination"];
$dernierOpIdenti = $dataRecp["dernierOpIdentification"];
$logger->info('rebouclage1 : ' . $dernierRebouclage);
$logger->info('update1 : ' . $dernierUpdate);
$logger->info('aquisition1 : ' . $dernierAcquisition);
$logger->info('entree1 : ' . $dernierEntre);
$logger->info('formation1 : ' . $dernierFormation);
$logger->info('insemination : ' . $dernierInsemination);
$logger->info('operationIdenti : ' . $dernierOpIdenti);
if ($dernierOpIdenti == null) {
$dernierOpIdenti = 0;
}
if ($dernierInsemination == null) {
$dernierInsemination = 0;
}
if ($dernierRebouclage == null) {
$dernierRebouclage = 0;
}
if ($dernierUpdate == null) {
$dernierUpdate = 0;
}
if ($dernierPrgAmel == null) {
$dernierPrgAmel = 0;
}
if ($dernierAcquisition == null) {
$dernierAcquisition = 0;
}
if ($dernierIdentification == null) {
$dernierIdentification = 0;
}
if ($dernierSortie == null) {
$dernierSortie = 0;
}
if ($dernierEntre == null) {
$dernierEntre = 0;
}
if ($dernierFormation == null) {
$dernierFormation = 0;
}
$logger->info('rebouclage : ' . $dernierRebouclage);
$logger->info('update : ' . $dernierUpdate);
$logger->info('aquisition : ' . $dernierAcquisition);
$logger->info('entree : ' . $dernierEntre);
$logger->info('formation : ' . $dernierFormation);
$qb = $em->createQueryBuilder();
$query = $qb->select('S')
->from('App:DemandeSortie', 'S')
->where('S.etatTraitement > 0 ')
->andWhere('S.id > :dernierId')
->setParameter('dernierId', $dernierSortie);
$entityServices = $query->getQuery()->getResult();
$datas = array();
foreach ($entityServices as $key => $entityService) {
$datas[$key]['Id'] = $entityService->getId();
$datas[$key]['Animal'] = $entityService->getAnimal()->getId();
$datas[$key]['codAnimal'] = $entityService->getAnimal()->getIdentAnm();
$datas[$key]['Frm_Cod'] = $entityService->getFrmCod();
$datas[$key]['Date_Sortie'] = $entityService->getDateSor()->format('Y-m-d H:i:s');
$datas[$key]['Etat_Traitement'] = $entityService->getEtatTraitement();
if ($entityService->getDateTraitement()) {
$datas[$key]['Date_Traitement'] = $entityService->getDateTraitement()->format('Y-m-d H:i:s');
} else {
$datas[$key]['Date_Traitement'] = $entityService->getDateTraitement();
}
$datas[$key]['Cause_Sortie'] = $entityService->getCauseSor();
$datas[$key]['CreatedAt'] = $entityService->getCreatedAt()->format('Y-m-d H:i:s');;
$datas[$key]['Eleveur'] = $entityService->getEleveur()->getId();
$datas[$key]['codEleveur'] = $entityService->getEleveur()->getCodElv();
$datas[$key]['codSit'] = $entityService->getEleveur()->getGouvernorat()->getCodeGou();
$datas[$key]['codEspece'] = $entityService->getEspece()->getCodeEspece();
$datas[$key]['codAgn'] = $entityService->getCodAgn();
}
//$demandesUpdate = $em->getRepository(DemandeUpdate::class)->findAll();
$qb = $em->createQueryBuilder();
$query = $qb->select('u')
->from('App:DemandeUpdate', 'u')
->where('u.etatTraitement > 0 ')
->andWhere('u.id > :dernierId')
->setParameter('dernierId', $dernierUpdate);
$demandesUpdate = $query->getQuery()->getResult();
$demandeUp = array();
foreach ($demandesUpdate as $key => $demandeU) {
$demandeUp[$key]['Id'] = $demandeU->getId();
if ($demandeU->getAnimal() != null) {
$demandeUp[$key]['Animal'] = $demandeU->getAnimal()->getId();
$demandeUp[$key]['animalCod'] = $demandeU->getAnimal()->getIdentAnm();
} else {
$demandeUp[$key]['Animal'] = $demandeU->getAnimal();
$demandeUp[$key]['animalCod'] = $demandeU->getAnimal();
}
if ($demandeU->getEleveur() != null) {
$demandeUp[$key]['Eleveur'] = $demandeU->getEleveur()->getId();
$demandeUp[$key]['codEleveur'] = $demandeU->getEleveur()->getCodElv();
} else {
$demandeUp[$key]['Eleveur'] = $demandeU->getEleveur()->getId();
$demandeUp[$key]['codEleveur'] = $demandeU->getEleveur()->getCodElv();
}
if ($demandeU->getDicRace() != null) {
$demandeUp[$key]['dicRace'] = $demandeU->getDicRace()->getId();
$demandeUp[$key]['dicRaceCode'] = $demandeU->getDicRace()->getcodeRace();
} else {
$demandeUp[$key]['dicRace'] = $demandeU->getDicRace();
$demandeUp[$key]['dicRaceCode'] = $demandeU->getDicRace();
}
if ($demandeU->getSexAnm() == 1) {
$demandeUp[$key]['sexAnmCod'] = 'M';
} else {
$demandeUp[$key]['sexAnmCod'] = 'F';
}
$demandeUp[$key]['sexAnm'] = $demandeU->getSexAnm();
$demandeUp[$key]['codAgn'] = $demandeU->getCodAgn();
$demandeUp[$key]['dateNais'] = $demandeU->getDateNais()->format('Y-m-d');
$demandeUp[$key]['annNais'] = $demandeU->getAnnNais();
$demandeUp[$key]['etatTraitement'] = $demandeU->getEtatTraitement();
if ($demandeU->getDateTraitement() != null) {
$demandeUp[$key]['dateTraitement'] = $demandeU->getDateTraitement()->format('Y-m-d H:i:s');
} else {
$demandeUp[$key]['dateTraitement'] = $demandeU->getDateTraitement();
}
if ($demandeU->getDateDepot() != null) {
$demandeUp[$key]['dateDepot'] = $demandeU->getDateDepot()->format('Y-m-d H:i:s');
} else {
$demandeUp[$key]['dateDepot'] = $demandeU->getDateDepot();
}
if ($demandeU->getCreatedAt() != null) {
$demandeUp[$key]['createdAt'] = $demandeU->getCreatedAt()->format('Y-m-d H:i:s');
} else {
$demandeUp[$key]['createdAt'] = $demandeU->getCreatedAt();
}
if ($demandeU->getUpdatedAt() != null) {
$demandeUp[$key]['updatedAt'] = $demandeU->getUpdatedAt()->format('Y-m-d H:i:s');
} else {
$demandeUp[$key]['updatedAt'] = $demandeU->getUpdatedAt();
}
$demandeUp[$key]['idePere'] = $demandeU->getIdePere();
$demandeUp[$key]['ideMere'] = $demandeU->getIdeMere();
}
$qb = $em->createQueryBuilder();
$query = $qb->select('e')
->from('App:DemandeEnree', 'e')
->where('e.etatTraitement > 0 ')
->andWhere('e.id > :dernierId')
->setParameter('dernierId', $dernierEntre);
$demandesEntre = $query->getQuery()->getResult();
$demandeEn = array();
foreach ($demandesEntre as $key => $demandeE) {
$demandeEn[$key]['Id'] = $demandeE->getId();
// $demandeEn[$key]['Animal']= $demandeE->getAnimal()->getId();
//$demandeEn[$key]['Animal']= $demandeE->getAnimal();
$demandeEn[$key]['Animal'] = $demandeE->getIdentAnm();
$demandeEn[$key]['Ferme'] = $demandeE->getFerme()->getId();
$demandeEn[$key]['codSit'] = $demandeE->getFerme()->getImada()->getDelegation()->getGouvernorat()->getCodeGou();
$demandeEn[$key]['codEspece'] = $demandeE->getEspece()->getCodeEspece();
$demandeEn[$key]['codFerme'] = $demandeE->getFerme()->getFrmCod();
$demandeEn[$key]['dateCon'] = $demandeE->getDateCon();
$demandeEn[$key]['etatTraitement'] = $demandeE->getEtatTraitement();
$demandeEn[$key]['sorFrm'] = $demandeE->getSorFrm();
$demandeEn[$key]['identAnm'] = $demandeE->getIdentAnm();
$demandeEn[$key]['createdAt'] = $demandeE->getCreatedAt()->format('Y-m-d H:i:s');
$demandeEn[$key]['dateEnt'] = $demandeE->getDateEnt()->format('Y-m-d H:i:s');;
$demandeEn[$key]['eleveur'] = $demandeE->getEleveur()->getId();
$demandeEn[$key]['codEleveur'] = $demandeE->getEleveur()->getCodElv();
$demandeEn[$key]['codAgn'] = $demandeE->getCodAgn();
}
$qb = $em->createQueryBuilder();
/* $query = $qb->select('e')
->from('App:DemandeRebouclage', 'e')
->leftJoin('e.rebouclageAnimals','r')
->where('e.id = r.demRebouc')
->andWhere('e.etatTraitement > 0 ')
->andWhere('e.id > :dernierId')
->setParameter('dernierId',$dernierRebouclage );
$demandesRebouclage = $query->getQuery()->getResult();*/
$query = $qb->select('e')
->from('App:RebouclageAnimal', 'e')
->leftJoin('e.demRebouc', 'r')
->where('e.demRebouc = r.id')
->andWhere('r.etatTraitement > 0 ')
->andWhere('r.id > :dernierId')
->setParameter('dernierId', $dernierRebouclage);
$demandesRebouclage = $query->getQuery()->getResult();
//dump($demandesRebouclages);die;
$demandeReb = array();
foreach ($demandesRebouclage as $key => $demandeR) {
$demandeReb[$key]['Id'] = $demandeR->getDemRebouc()->getId();
$demandeReb[$key]['Eleveur'] = $demandeR->getDemRebouc()->getEleveur()->getId();
$demandeReb[$key]['eleveurCod'] = $demandeR->getDemRebouc()->getEleveur()->getCodElv();
$demandeReb[$key]['etatTraitement'] = $demandeR->getDemRebouc()->getEtatTraitement();
$demandeReb[$key]['dateDemande'] = $demandeR->getDemRebouc()->getDateDemande();
$demandeReb[$key]['dateRebouc'] = $demandeR->getDemRebouc()->getDateRebouc();
$demandeReb[$key]['codAgn'] = $demandeR->getDemRebouc()->getCodAgn();
if ($demandeR->getAnimal()->getTroupeau() != null) {
$demandeReb[$key]['frmCod'] = $demandeR->getAnimal()->getTroupeau()->getFerme()->getFrmCod();
$demandeReb[$key]['codGouv'] = $demandeR->getAnimal()->getTroupeau()->getFerme()->getImada()->getDelegation()->getGouvernorat()->getCodeGou();
} else {
$demandeReb[$key]['frmCod'] = null;
$demandeReb[$key]['codGouv'] = $demandeR->getDemRebouc()->getEleveur()->getGouvernorat()->getCodeGou();
}
$demandeReb[$key]['IdeAnim'] = $demandeR->getAnimal()->getIdentAnm();
$demandeReb[$key]['codEspece'] = $demandeR->getAnimal()->getDicRace()->getDicEspece()->getCodeEspece();
}
$qb = $em->createQueryBuilder();
$query = $qb->select('f')
->from('App:DemandeFormation', 'f')
->where('f.etatTraitement > 0 ')
->andWhere('f.id > :dernierId')
->setParameter('dernierId', $dernierFormation);
$demandesFormation = $query->getQuery()->getResult();
$demandeFor = array();
foreach ($demandesFormation as $key => $demandeF) {
$demandeFor[$key]['Id'] = $demandeF->getId();
$demandeFor[$key]['typeFormation'] = $demandeF->getTypeFormation();
$demandeFor[$key]['etatTraitement'] = $demandeF->getEtatTraitement();
$demandeFor[$key]['dateTraitement'] = $demandeF->getDateTraitement();
$demandeFor[$key]['dateDemande'] = $demandeF->getDateDemande();
$demandeFor[$key]['createdAt'] = $demandeF->getCreatedAt();
$demandeFor[$key]['updatedAt'] = $demandeF->getUpdatedAt();
$demandeFor[$key]['identElv'] = $demandeF->getIdentElv();
$demandeFor[$key]['nprElvLt'] = $demandeF->getNprElvLt();
$demandeFor[$key]['nprElvLi'] = $demandeF->getNprElvLi();
$demandeFor[$key]['cin'] = $demandeF->getCin();
$demandeFor[$key]['niveauEducation'] = $demandeF->getNiveauEducation();
$demandeFor[$key]['adresse'] = $demandeF->getAdresse();
$demandeFor[$key]['numTel'] = $demandeF->getNumTel();
$demandeFor[$key]['email'] = $demandeF->getEmail();
$demandeFor[$key]['docDiplomes'] = $demandeF->getDocDiplomes();
$demandeFor[$key]['motif'] = $demandeF->getMotif();
$demandeFor[$key]['gouvernorat'] = $demandeF->getGouvernorat()->getId();
$demandeFor[$key]['gouvernoratCod'] = $demandeF->getGouvernorat()->getCodeGou();
}
$qb = $em->createQueryBuilder();
$query = $qb->select('d')
->from('App:DemandePrgAmelioration', 'd')
->where('d.etatTraitement > 0 ')
->andWhere('d.id > :dernierId')
->setParameter('dernierId', $dernierPrgAmel);
$demandesPrgAmelioration = $query->getQuery()->getResult();
$demandeAm = array();
foreach ($demandesPrgAmelioration as $key => $demandeA) {
$demandeAm[$key]['Id'] = $demandeA->getId();
$demandeAm[$key]['Eleveur'] = $demandeA->getEleveur()->getId();
$demandeAm[$key]['codEleveur'] = $demandeA->getEleveur()->getCodElv();
if ($demandeA->getPgrAml() != null) {
$demandeAm[$key]['pgrAml'] = $demandeA->getPgrAml()->getId();
} else {
$demandeAm[$key]['pgrAml'] = $demandeA->getPgrAml();
}
$demandeAm[$key]['etatTraitement'] = $demandeA->getEtatTraitement();
$demandeAm[$key]['dateTraitement'] = $demandeA->getDateTraitement();
$demandeAm[$key]['dateDepot'] = $demandeA->getDateDepot();
}
$qb = $em->createQueryBuilder();
$query = $qb->select('aci')
->from('App:DemandeAcquisition', 'aci')
->where('aci.etatTraitement > 0 ')
->andWhere('aci.id > :dernierId')
->setParameter('dernierId', $dernierAcquisition);
$demandesAcquisition = $query->getQuery()->getResult();
$demandeAc = array();
foreach ($demandesAcquisition as $key => $demandeAci) {
$demandeAc[$key]['Id'] = $demandeAci->getId();
$demandeAc[$key]['Eleveur'] = $demandeAci->getEleveur()->getId();
$demandeAc[$key]['codEleveur'] = $demandeAci->getEleveur()->getCodElv();
$demandeAc[$key]['dicRace'] = $demandeAci->getDicRace()->getId();
$demandeAc[$key]['dicRaceCod'] = $demandeAci->getDicRace()->getcodeRace();
$demandeAc[$key]['nbr'] = $demandeAci->getNbr();
$demandeAc[$key]['etatTraitement'] = $demandeAci->getEtatTraitement();
$demandeAc[$key]['dateTraitement'] = $demandeAci->getDateTraitement();
$demandeAc[$key]['dateDepot'] = $demandeAci->getDateDepot();
$demandeAc[$key]['codAgn'] = $demandeAci->getCodAgn();
}
$qb = $em->createQueryBuilder();
$query = $qb->select('Iden')
->from('App:DemandeIdentification', 'Iden')
->where('Iden.etatTraitement > 0 ')
->andWhere('Iden.id > :dernierId')
->setParameter('dernierId', $dernierIdentification);
$demandesIdentifiacation = $query->getQuery()->getResult();
$demandeID = array();
foreach ($demandesIdentifiacation as $key => $demandeI) {
$demandeID[$key]['Id'] = $demandeI->getId();
$demandeID[$key]['Eleveur'] = $demandeI->getEleveur()->getId();
$demandeID[$key]['codEleveur'] = $demandeI->getEleveur()->getCodElv();
$demandeID[$key]['dicEspece'] = $demandeI->getDicEspece()->getId();
$demandeID[$key]['EspeceCod'] = $demandeI->getDicEspece()->getCodeEspece();
$demandeID[$key]['nbrMale'] = $demandeI->getNbrMale();
$demandeID[$key]['nbrFemelle'] = $demandeI->getNbrFemelle();
$demandeID[$key]['etatTraitement'] = $demandeI->getEtatTraitement();
$demandeID[$key]['dateTraitement'] = $demandeI->getDateTraitement();
$demandeID[$key]['dateDepot'] = $demandeI->getDateDepot();
}
$qb = $em->createQueryBuilder();
$query = $qb->select('Op')
->from('App:OperationInsemination', 'Op')
->Where('Op.id > :dernierId')
->setParameter('dernierId', $dernierInsemination);
$operationinsiminantion = $query->getQuery()->getResult();
$OpIns = array();
foreach ($operationinsiminantion as $key => $o) {
$OpIns[$key]['Id'] = $o->getId();
$OpIns[$key]['Circuit'] = $o->getDicCircuit()->getCodCircuit();
if ($o->getEleveur() != null) {
$OpIns[$key]['Eleveur'] = $o->getEleveur()->getCodElv();
$OpIns[$key]['gouvernorat'] = $o->getEleveur()->getGouvernorat()->getCodeGou();
$OpIns[$key]['delegation'] = $o->getEleveur()->getDelegation()->getCodDELG();
$OpIns[$key]['imada'] = $o->getEleveur()->getImada()->getCodIm();
} else {
$OpIns[$key]['Eleveur'] = $o->getNumeroEleveur();
$OpIns[$key]['gouvernorat'] = null;
$OpIns[$key]['delegation'] = null;
$OpIns[$key]['imada'] = null;
}
if ($o->getAnimal() != null) {
$OpIns[$key]['Animal'] = $o->getAnimal()->getIdentAnm();
$OpIns[$key]['especeCod'] = $o->getAnimal()->getDicRace()->getDicEspece()->getCodeEspece();
} else {
$OpIns[$key]['Animal'] = $o->getNumeroAnimal();
$OpIns[$key]['especeCod'] = null;
}
$OpIns[$key]['Certificat'] = $o->getCertificat();
$OpIns[$key]['dateOperation'] = $o->getDateOp();
$OpIns[$key]['etatValidation'] = $o->getEtatValidation();
$OpIns[$key]['annee'] = $o->getAnnee();
$OpIns[$key]['mois'] = $o->getMois();
$OpIns[$key]['CreatedAt'] = $o->getCreatedAt();
$OpIns[$key]['UpdatedAt'] = $o->getUpdatedAt();
$OpIns[$key]['codAgn'] = $o->getCodAgent();
$OpIns[$key]['taureau'] = $o->getNumeroTaureau();
}
$qb = $em->createQueryBuilder();
$query = $qb->select('OI')
->from('App:OperationIdentification', 'OI')
->where('OI.etatTraitement > 0 ')
->andWhere('OI.id > :dernierId')
->setParameter('dernierId', $dernierOpIdenti);
$operatioIdent = $query->getQuery()->getResult();
$opIden = array();
foreach ($operatioIdent as $key => $OI) {
$opIden[$key]['Id'] = $OI->getId();
$opIden[$key]['Eleveur'] = $OI->getEleveur()->getId();
$opIden[$key]['codEleveur'] = $OI->getEleveur()->getCodElv();
$opIden[$key]['Animal'] = $OI->getIdentAnimal();
$opIden[$key]['etatTraitement'] = $OI->getEtatTraitement();
$opIden[$key]['dateOp'] = $OI->getDateOp()->format('Y-m-d H:i:s');
$opIden[$key]['createdAt'] = $OI->getCreatedAt()->format('Y-m-d H:i:s');
$opIden[$key]['updatedAt'] = $OI->getUpdatedAt()->format('Y-m-d H:i:s');
$opIden[$key]['dicRace'] = $OI->getDicRace()->getId();
$opIden[$key]['dicRaceCod'] = $OI->getDicRace()->getcodeRace();
$opIden[$key]['dateNais'] = $OI->getDateNai()->format('Y-m-d');
$opIden[$key]['annNais'] = $OI->getAnnNai();
$opIden[$key]['sexAnm'] = $OI->getSexAnm();
$opIden[$key]['troupeau'] = $OI->getTroupeau()->getId();
$opIden[$key]['ferme'] = $OI->getFerme()->getId();
$opIden[$key]['codFerme'] = $OI->getFerme()->getFrmCod();
$opIden[$key]['Anne'] = $OI->getAnnee();
$opIden[$key]['Mois'] = $OI->getMois();
$opIden[$key]['numrTroup'] = $OI->getTroupeau()->getIdentTrp();
$opIden[$key]['EspeceCod'] = $OI->getDicRace()->getDicEspece()->getCodeEspece();
if ($OI->getSexAnm() == 1) {
$opIden[$key]['sexAnmCod'] = 'M';
} else {
$opIden[$key]['sexAnmCod'] = 'F';
}
$opIden[$key]['codAgn'] = $OI->getCodAgent();
$opIden[$key]['codSit'] = $OI->getEleveur()->getGouvernorat()->getCodeGou();
}
return new JsonResponse([
'demandesSortie' => $datas,
'demandesUpdate' => $demandeUp,
'demandesEntree' => $demandeEn,
'demandesReboubuclage' => $demandeReb,
'demandesFormation' => $demandeFor,
'demandesPrgAmelioration' => $demandeAm,
'demandesAcquisation' => $demandeAc,
'demandesIdentification' => $demandeID,
'operationInsimination' => $OpIns,
'operationIdentification' => $opIden
]);
}
#[Route('/api/race', name: 'app_race')]
public function getAllRace(Request $request, LoggerInterface $logger, ManagerRegistry $doctrine)
{
if (!$this->checkClientIp($request)) {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}
$em = $this->em;
$content = $request->getContent();
$dataArr = array();
$dataArr = json_decode($content, true);
foreach ($dataArr as $data) {
try {
$race = null;
$id = $data['COD_RACE'];
$races = $doctrine->getRepository(DicRace::class)->findBy(['COD_RACE' => $id]);
if ($races == null || count($races) == 0) {
$race = new DicRace();
$race->setcodeRace($id);
} else {
$race = $races[0];
}
$e = $data['COD_ESPECE'];
$espece = $doctrine->getRepository(DicEspece::class)->findOneBy(['COD_ESPECE' => $e]);
$race->setDicEspece($espece);
$race->setNomRaceLt($data['NOM_RACELT']);
$race->setNomRaceLi($data['NOM_RACELI']);
$em->persist($race);
$em->flush();
} catch (Exception $e) {
echo 'except *************************** ', $e->getMessage(), "\n";
}
}
return new JsonResponse([
'code' => 200,
'message' => 'Add request success',
'data3' => $race->getId()
]);
}
#[Route('/api/espece', name: 'app_espece')]
public function getAlllEspeces(Request $request, ManagerRegistry $doctrine)
{
if (!$this->checkClientIp($request)) {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}
$paramsArr = array();
$paramsArr = json_decode($request->getContent(), true);
$em = $this->em;
foreach ($paramsArr as $params) {
try {
$espece = null;
$id = $params['COD_ESPECE'];
$especes = $doctrine->getRepository(DicEspece::class)->findBy(['COD_ESPECE' => $id]);
if ($especes == null || count($especes) == 0) {
$espece = new DicEspece();
$espece->setCodeEspece($id);
} else {
$espece = $especes[0];
}
$espece->setDesEspeceLt($params['DES_ESPECELT']);
$espece->setDesEspeceLi($params['DES_ESPECELI']);
$em->persist($espece);
$em->flush();
} catch (Exception $e) {
echo 'except *************************** ', $e->getMessage(), "\n";
}
}
return new JsonResponse([
'code' => 200,
'message' => 'Add request success',
//'data' => $espece->getId()
]);
}
#[Route('/api/eleveur', name: 'app_eleveur')]
public function getAlllEleveur(Request $request, ManagerRegistry $doctrine)
{
if (!$this->checkClientIp($request)) {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}
$paramsArr = array();
$paramsArr = json_decode($request->getContent(), true);
$em = $this->em;
$date = new \DateTime('now');
if ($paramsArr == '') $dataArr = array();
foreach ($paramsArr as $params) {
try {
/*$g= $params['COD_GOU'];
$d=$params['COD_DEL'];
$i=$params['COD_IMA'];
$gouvernorat = $doctrine->getRepository(DicGouvernorat::class)->findOneBy(['COD_GOU' => $g]);
$delegation = $doctrine->getRepository(DicDelegation::class)->findOneBy(['COD_DELG' => $d]);
$imada = $doctrine->getRepository(DicImada::class)->findOneBy(['COD_IMAD' => $i]); */
$eleveur = null;
$id = trim($params['REF_ELV']);
$eleveurs = $doctrine->getRepository(Eleveur::class)->findBy(['codElv' => $id]);
if ($eleveurs == null || count($eleveurs) == 0) {
$eleveur = new Eleveur();
$eleveur->setCodElv($id);
$eleveur->setCreatedAt($date);
} else {
$eleveur = $eleveurs[0];
}
/*$eleveur->setImada($imada);
$eleveur->setGouvernorat($gouvernorat);
$eleveur->setDelegation($delegation);*/
$eleveur->setNprElvAr($params['NPR_ELVLI']);
$eleveur->setNprElvFr($params['NPR_ELVLT']);
$eleveur->setAdresse($params['ADR_ELVLT']);
$eleveur->setNumTel($params['TEL_ELV']);
$eleveur->setNumFax(intval($params['FAX_ELV']));
$eleveur->setUpdatedAt($date);
$em->persist($eleveur);
$em->flush();
} catch (Exception $e) {
echo 'except *************************** ', $e->getMessage(), "\n";
}
}
return new JsonResponse([
'code' => 200,
'message' => 'Add request success'
]);
}
#[Route('/api/NbEleveur', name: 'app_NbEleveur')]
public function getNombreEleveur(Request $request)
{
$em = $this->em;
$qb = $em->createQueryBuilder();
$query = $qb->select('count(E.id)')->from('App:Eleveur', 'E');
$nbrEleveur = $query->getQuery()->getSingleScalarResult();
return new JsonResponse([
'code' => 200,
'message' => 'Add request success',
'nbrEleveur' => $nbrEleveur
]);
}
#[Route('/api/ferme', name: 'app_ferme')]
public function getAllistFerme(Request $request, ManagerRegistry $doctrine, LoggerInterface $logger)
{
if (!$this->checkClientIp($request)) {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}
$dataArr = array();
$em = $this->em;
$content = $request->getContent();
$dataArr = json_decode($request->getContent(), true);
$date = new \DateTime('now');
if ($dataArr == '') $dataArr = array();
$nn = 0;
$ns = 0;
$nf = 0;
$total = 0; //count($dataArr);
//$logger->info('sync ************************** '.$ns.' -- '.$nf.' -- '.$total.' ***************************');
foreach ($dataArr as $data) {
try {
$ferme = null;
$i = $data['COD_IMA'];
$g = $data['COD_GOU'];
$d = $data['COD_DEL'];
$e = trim($data['REF_ELV']);
$id = trim($data['FRM_COD']);
$fermes = $doctrine->getRepository(Ferme::class)->findBy(['frm_cod' => $id]);
if ($e != null) {
$eleveur = $doctrine->getRepository(Eleveur::class)->findOneBy(['codElv' => $e]);
} else {
$eleveur = null;
}
if ($fermes == null || count($fermes) == 0) {
$ferme = new Ferme();
$ferme->setFrmCod($id);
$nn++;
} else {
$ferme = $fermes[0];
}
if ($g != null) {
$gouvernorat = $doctrine->getRepository(DicGouvernorat::class)->findOneBy(['COD_GOU' => $g]);
$gouv = $gouvernorat->getCodeGou();
} else {
$gouv = null;
$gouvernorat = null;
}
if ($d != null) {
$delegation = $doctrine->getRepository(DicDelegation::class)->findOneBy(['COD_DELG' => $d, 'gouvernorat' => $gouvernorat]);
$del = $delegation->getCodDELG();
} else {
$del = null;
$delegation = null;
}
if ($i != null) {
$imada = $doctrine->getRepository(DicImada::class)->findOneBy(['COD_IMAD' => $i, 'delegation' => $delegation]);
$im = $imada->getCodIm();
} else {
$imada = null;
$im = null;
}
$qb2 = $em->createQueryBuilder();
$query2 = $qb2->select('U')
->from('App:CircuitImada', 'U')
->where('U.COD_GOU = :gou')
->andWhere('U.COD_IMA = :ima')
->andWhere('U.COD_DEL = :del')
->setParameter('ima', $im)
->setParameter('del', $del)
->setParameter('gou', $gouv);
$numCircuits = $query2->getQuery()->getResult();
$circuit = null;
/*if ($numCircuits > 0 || count($numCircuits )>0 || $numCircuits != null ) {
$circuitt = $numCircuits[0];
} else{
$circuitt= $numCircuits;
}*/
$circuit = null;
if ($numCircuits != null) {
$circuitt = $numCircuits[0];
} else {
$circuitt = null;
}
//$circuitt= $numCircuits;
//dump($circuitt);die;
if ($circuitt != null) {
$num = $circuitt->getNUMCIR();
$circuit = $doctrine->getRepository(DicCircuit::class)->findOneBy(['codCircuit' => $num]);
}
//dump($circuitt, $num,$circuit);die;
$ferme->setImada($imada);
$ferme->setEleveur($eleveur);
$ferme->setDicCircuit($circuit);
$ferme->setFrmNomLt($data['FRM_DESLT']);
$ferme->setFrmNomLi($data['FRM_DESLI']);
$ferme->setFrmAdrFr($data['FRM_ADRLI']);
$em->persist($ferme);
if ($eleveur != null) {
$eleveur->setImada($imada);
$eleveur->setGouvernorat($gouvernorat);
$eleveur->setDelegation($delegation);
$eleveur->setUpdatedAt($date);
$em->persist($eleveur);
}
$em->flush();
$ns++;
} catch (Exception $e) {
echo 'except *************************** ', $e->getMessage(), "\n";
$nf++;
}
}
$logger->info('sync ************************** ' . $ns . ' -- ' . $nn . ' -- ' . $nf . ' -- ' . $total . ' ***********************');
return new JsonResponse([
'code' => 200,
'message' => 'Add request success',
// 'cinrcuitnum'=> $numCircuits
]);
}
#[Route('/api/NbFerme', name: 'app_NbFerme')]
public function getNombreFerme(Request $request, ManagerRegistry $doctrine)
{
$em = $this->em;
$qb = $em->createQueryBuilder();
$query = $qb->select('MAX(F.id)')->from('App:Ferme', 'F');
$dernierID = $query->getQuery()->getSingleScalarResult();
$qb1 = $em->createQueryBuilder();
$query1 = $qb1->select('F')
->from('App:Ferme', 'F')
->where('F.id = :DERId')
->setParameter('DERId', $dernierID);
$dernierFerme = $query1->getQuery()->getResult();
if ($dernierFerme == null) {
$codFrm = null;
} else {
$codFrm = $dernierFerme[0]->getFrmCod();
}
$qb2 = $em->createQueryBuilder();
$query2 = $qb2->select('count(F.id)')->from('App:Ferme', 'F');
$nbrFerme = $query2->getQuery()->getSingleScalarResult();
return new JsonResponse([
'code' => 200,
'message' => 'Add request success',
'dernierID' => $dernierID,
'dernierFrm' => $codFrm,
'NombreFrm' => $nbrFerme,
//'codecircuit' => $numCircuits
]);
}
#[Route('/api/troupeau', name: 'app_troupeau')]
public function getAlltroupeau(Request $request, ManagerRegistry $doctrine, LoggerInterface $logger)
{
if (!$this->checkClientIp($request)) {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}
$dataArr = array();
$em = $this->em;
$content = $request->getContent();
$dataArr = json_decode($content, true);
$ns = 0;
$nf = 0;
if ($dataArr == '') $dataArr = array();
foreach ($dataArr as $data) {
try {
$f = trim($data['FRM_COD']);
$p = $data['COD_ESPECE'];
$nmT = $data['NUM_TRP'];
$espece = $doctrine->getRepository(DicEspece::class)->findOneBy(['COD_ESPECE' => $p]);
$ferme = $doctrine->getRepository(Ferme::class)->findOneBy(['frm_cod' => $f]);
$qb = $em->createQueryBuilder();
$query = $qb->select('U')
->from('App:Troupeau', 'U')
->where('U.ferme = :ferm')
->andWhere('U.dicEspece = :espec')
->andWhere('U.identTrp = :numT')
->setParameter('espec', $espece->getId())
->setParameter('numT', $nmT)
->setParameter('ferm', $ferme->getId());
$troupaux = $query->getQuery()->getResult();
if ($troupaux == null || count($troupaux) == 0) {
$troupeau = new Troupeau();
} else {
$troupeau = $troupaux[0];
}
$troupeau->setFerme($ferme);
$troupeau->setDicEspece($espece);
$troupeau->setIdSync(trim($data['IDSYNC']));
$troupeau->setIdentTrp($nmT);
$em->persist($troupeau);
$em->flush();
$ns++;
//$nn++;
} catch (Exception $e) {
echo 'except *************************** ', $e->getMessage(), "\n";
$nf++;
}
$logger->info('sync ************************** ' . $ns . ' -- ' . $nf . ' ***********************');
}
return new JsonResponse([
'code' => 200,
'message' => 'Add request success',
]);
}
#[Route('/api/NbTroupeau', name: 'app_NbTroupeau')]
public function getNombreTroupeau(Request $request)
{
$em = $this->em;
$qb = $em->createQueryBuilder();
$query = $qb->select('MAX(T.idSync)')->from('App:Troupeau', 'T');
$nbrTroupeau = $query->getQuery()->getSingleScalarResult();
if ($nbrTroupeau == null) {
$nbrTroupeau = 0;
}
return new JsonResponse([
'nbrTroupeau' => $nbrTroupeau
]);
}
#[Route('/api/gouvernorat', name: 'app_gouvernourat')]
public function getAllistGouvernourat(Request $request, LoggerInterface $logger, ManagerRegistry $doctrine)
{
if (!$this->checkClientIp($request)) {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}
$em = $this->em;
$content = $request->getContent();
$dataArr = array();
$dataArr = json_decode($content, true);
if ($dataArr == '') $dataArr = array();
foreach ($dataArr as $data) {
try {
$gouvernorat = null;
$id = $data['COD_GOU'];
$gouvernorats = $doctrine->getRepository(DicGouvernorat::class)->findBy(['COD_GOU' => $id]);
if ($gouvernorats == null || count($gouvernorats) == 0) {
$gouvernorat = new DicGouvernorat();
$gouvernorat->setCodeGou($id);
} else {
$gouvernorat = $gouvernorats[0];
}
$gouvernorat->setGouvernorat($data['NOM_GOULT']);
$gouvernorat->setNomAr($data['NOM_GOULI']);
$em->persist($gouvernorat);
$em->flush();
} catch (Exception $e) {
echo 'except *************************** ', $e->getMessage(), "\n";
}
}
return new JsonResponse([
'code' => 200,
'message' => 'Add request success',
'data3' => $gouvernorat->getId()
]);
}
#[Route('/api/delegation', name: 'app_delegation')]
public function getListDelegation(Request $request, LoggerInterface $logger, ManagerRegistry $doctrine)
{
if (!$this->checkClientIp($request)) {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}
$em = $this->em;
$content = $request->getContent();
$dataArr = array();
$dataArr = json_decode($content, true);
if ($dataArr == '') $dataArr = array();
foreach ($dataArr as $data) {
try {
$delegation = null;
$id = $data['DES_DELLT'];
$delegations = $doctrine->getRepository(DicDelegation::class)->findBy(['delegation' => $id]);
if ($delegations == null || count($delegations) == 0) {
$delegation = new DicDelegation();
$delegation->setDelegation($id);
} else {
$delegation = $delegations[0];
}
$g = $data['COD_GOU'];
$gouvernorat = $doctrine->getRepository(DicGouvernorat::class)->findOneBy(['COD_GOU' => $g]);
$delegation->setGouvernorat($gouvernorat);
$delegation->setCodDELG($data['COD_DEL']);
$delegation->setNomAr($data['DES_DELLI']);
$em->persist($delegation);
$em->flush();
} catch (Exception $e) {
echo 'except *************************** ', $e->getMessage(), "\n";
}
}
return new JsonResponse([
'code' => 200,
'message' => 'Add request success',
//'data3' => $delegation->getId()
]);
}
#[Route('/api/imada', name: 'app_imada')]
public function getListImada(Request $request, LoggerInterface $logger, ManagerRegistry $doctrine)
{
if (!$this->checkClientIp($request)) {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}
$em = $this->em;
$content = $request->getContent();
$dataArr = array();
$dataArr = json_decode($content, true);
if ($dataArr == '') $dataArr = array();
foreach ($dataArr as $data) {
try {
$imada = null;
$id = $data['DES_IMALI'];
$d = $data['COD_DEL'];
$g = $data['COD_GOU'];
$im = $data['COD_IMA'];
if ($g != null) {
$gouvernorat = $doctrine->getRepository(DicGouvernorat::class)->findOneBy(['COD_GOU' => $g]);
} else {
$gouvernorat = null;
}
if ($d != null) {
$delegation = $doctrine->getRepository(DicDelegation::class)->findOneBy(['COD_DELG' => $d, 'gouvernorat' => $gouvernorat]);
} else {
$delegation = null;
}
$imadas = $doctrine->getRepository(DicImada::class)->findBy(['nom' => $id, 'delegation' => $delegation, 'COD_IMAD' => $im]);
if ($imadas == null || count($imadas) == 0) {
$imada = new DicImada();
} else {
$imada = $imadas[0];
}
$imada->setNom($id);
$imada->setDelegation($delegation);
$imada->setCodIm($data['COD_IMA']);
$imada->setNomAr($data['DES_IMALI']);
$em->persist($imada);
$em->flush();
} catch (Exception $e) {
echo 'except *************************** ', $e->getMessage(), "\n";
}
}
return new JsonResponse([
'code' => 200,
'message' => 'Add request success',
//'data' => $imada->getId()
]);
}
#[Route('/api/circuit', name: 'app_circuit')]
public function getListCircuit(Request $request, LoggerInterface $logger, ManagerRegistry $doctrine)
{
if (!$this->checkClientIp($request)) {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}
$em = $this->em;
$content = $request->getContent();
$dataArr = array();
$dataArr = json_decode($content, true);
if ($dataArr == '') $dataArr = array();
foreach ($dataArr as $data) {
try {
$circuit = null;
$id = $data['NUM_CIR'];
$circuits = $doctrine->getRepository(DicCircuit::class)->findBy(['codCircuit' => $id]);
if ($circuits == null || count($circuits) == 0) {
$circuit = new DicCircuit();
$circuit->setCodCircuit($id);
} else {
$circuit = $circuits[0];
}
$circuit->setDesCirLt($data['DES_CIRLT']);
$circuit->setDesCirLi($data['DES_CIRLI']);
$em->persist($circuit);
$em->flush();
} catch (Exception $e) {
echo 'except *************************** ', $e->getMessage(), "\n";
}
}
return new JsonResponse([
'code' => 200,
'message' => 'Add request success',
// 'data' => $circuit->getId()
]);
}
#[Route('/api/circuitImada', name: 'app_circuitimada')]
public function getListCircuitImada(Request $request, LoggerInterface $logger, ManagerRegistry $doctrine)
{
if (!$this->checkClientIp($request)) {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}
$em = $this->em;
$content = $request->getContent();
$dataArr = array();
$dataArr = json_decode($content, true);
if ($dataArr == '') $dataArr = array();
/* $gouvernorat = $data['COD_GOU'];
$delegation = $data ['COD_DEL'];
$imada = $data['COD_IMA'];
$circuit = $doctrine->getRepository(DicImada::class)->findOneBy(['COD_IMA' => $imada,'COD_DEL'=>$delegation,'COD_GOU'=>$gouvernorat]);*/
foreach ($dataArr as $data) {
try {
$gouvernorat = $data['COD_GOU'];
$delegation = $data['COD_DEL'];
$imada = $data['COD_IMA'];
$circuits = $doctrine->getRepository(CircuitImada::class)->findBy(['COD_IMA' => $imada, 'COD_DEL' => $delegation, 'COD_GOU' => $gouvernorat]);
if ($circuits == null || count($circuits) == 0) {
$cirImada = new CircuitImada();
} else {
$cirImada = $circuits[0];
}
$cirImada->setNUMCIR($data['NUM_CIR']);
$cirImada->setCODGOU($data['COD_GOU']);
$cirImada->setCODDEL($data['COD_DEL']);
$cirImada->setCODIMA($data['COD_IMA']);
$em->persist($cirImada);
$em->flush();
} catch (Exception $e) {
echo 'except *************************** ', $e->getMessage(), "\n";
}
}
return new JsonResponse([
'code' => 200,
'message' => 'Add request success',
//'data' => $cirImada->getId()
]);
}
#[Route('/api/animal', name: 'app_animal')]
public function getListAnimal(Request $request, LoggerInterface $logger, ManagerRegistry $doctrine)
{
if (!$this->checkClientIp($request)) {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}
$dataArr = array();
$em = $this->em;
$content = $request->getContent();
$dataArr = json_decode($content, true);
$date = new \DateTime('now');
$taille = count($dataArr);
$ns = 0;
$nf = 0;
$nn = 0;
$concatMessage = "";
$logger->info('sync ************************** ' . $ns . ' -- ' . $nf . ' -- ' . $taille . ' ***************************');
if ($dataArr == '') $dataArr = array();
foreach ($dataArr as $data) {
try {
$id = trim($data['IDE_ANIM']);
$concatMessage .= $id . " ";
$animal = null;
$animales = $doctrine->getRepository(Animal::class)->findBy(['identAnm' => $id]);
if ($animales == null || count($animales) == 0) {
$animal = new Animal();
$animal->setIdentAnm($id);
$animal->setIdSync(trim($data['IDSYNC']));
$animal->setCreatedAt($date);
$nn++;
$concatMessage .= " not found /";
} else {
$animal = $animales[0];
$concatMessage .= " found /";
$animal->setIdSync(trim($data['IDSYNC']));
}
$r = $data['COD_RACE'];
$t = $data['NUM_TRP'];
//$t= $data['FRM_COD_ACT'];
$f = trim($data['FRM_COD_ACT']);
$frmNais = trim($data['FRM_COD_NAI']);
$m = trim($data['IDE_MERE']);
$p = trim($data['IDE_PERE']);
$d = $data['DAT_NAI'];
$animPres = $data['ANIM_PRES'];
if ($d != null) {
$dateNaiss = str_replace(array("/"), '-', $d);
$logger->info('dd1 ' . $dateNaiss);
$datt = substr($d, 0, 2);
$logger->info("datt" . $datt);
$mois = substr($d, 3, 2);
$logger->info("mois" . $mois);
$year = substr($d, 6, 2);
$logger->info("year" . $year);
$dateNaiss = $year . '-' . $mois . '-' . $datt;
$logger->info("dateForm" . $dateNaiss);
} else {
$dateNaiss = null;
}
$race = $doctrine->getRepository(DicRace::class)->findOneBy(['COD_RACE' => $r]);
if ($animPres == 'N') {
$troupeau = null;
$ferme = null;
$fermeNais = $doctrine->getRepository(Ferme::class)->findOneBy(['frm_cod' => $frmNais]);
} else {
$ferme = $doctrine->getRepository(Ferme::class)->findOneBy(['frm_cod' => $f]);
$fermeNais = $doctrine->getRepository(Ferme::class)->findOneBy(['frm_cod' => $frmNais]);
//$troupeau = $doctrine->getRepository(Troupeau::class)->findOneBy(['ferme' => $ferme]);
$troupeau = $doctrine->getRepository(Troupeau::class)->findOneBy(['ferme' => $ferme, 'identTrp' => $t]);
}
$mere = $doctrine->getRepository(Animal::class)->findOneBy(['identAnm' => $m]);
$pere = $doctrine->getRepository(Animal::class)->findOneBy(['identAnm' => $p]);
$eleveur = null;
if ($ferme != null) {
$eleveur = $ferme->getEleveur();
}
if ($eleveur != null) {
$animal->setEleveur($eleveur);
}
if ($pere != null) {
$animal->setIdePere($pere);
}
if ($mere != null) {
$animal->setIdeMere($mere);
}
if ($data['SEX_ANM'] == 'M') {
$animal->setSexAnm(0);
} else {
$animal->setSexAnm(1);
}
if ($dateNaiss == null) {
$animal->setDateNai(null);
} else {
$animal->setDateNai(new \DateTime(date("y-m-d", strtotime($dateNaiss))));
}
$animal->setAnnNai($data['ANN_NAI']);
$animal->setTypAnm($data['TYP_ANIM']);
$animal->setTroupeau($troupeau);
$animal->setFermeNais($fermeNais);
$animal->setDicRace($race);
$animal->setUpdatedAt($date);
$concatMessage .= "*" . json_encode($animal) . "*";
$em->persist($animal);
$em->flush();
$ns++;
} catch (Exception $e) {
$nf++;
}
}
$logger->info('sync ************************** ' . $ns . ' -- ' . $nn . ' -- ' . $nf . ' -- ' . $taille . ' ***********************');
$concatMessage = "";
return new JsonResponse([
'code' => 200,
'message' => 'Add request success ' . $concatMessage,
'taille_tableau' => $taille,
'nbrsucess' => $ns,
'nbrfailed' => $nf
]);
}
#[Route('/api/NbAnimal', name: 'app_NbAnimal')]
public function getNombreAnimal(Request $request)
{
$em = $this->em;
$qb = $em->createQueryBuilder();
$query = $qb->select('MAX(A.idSync)')->from('App:Animal', 'A');
$nbrAnimal = $query->getQuery()->getSingleScalarResult();
if ($nbrAnimal == null) {
$nbrAnimal = 0;
}
return new JsonResponse([
'nbrAnimal' => $nbrAnimal,
]);
}
#[Route('/api/agentoep', name: 'app_agentoep')]
public function getListAgentOep(Request $request, LoggerInterface $logger, ManagerRegistry $doctrine)
{
if (!$this->checkClientIp($request)) {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}
$em = $this->em;
$content = $request->getContent();
$date = new \DateTime('now');
$dataArr = array();
$dataArr = json_decode($content, true);
foreach ($dataArr as $data) {
try {
$agent = null;
$id = trim($data['COD_AGN']);
$agents = $doctrine->getRepository(AgentOep::class)->findBy(['codAgent' => $id]);
if ($agents == null || count($agents) == 0) {
$agent = new AgentOep();
$agent->setCodAgent($id);
$agent->setIdentAgent($id);
$agent->setCreatedAt($date);
} else {
$agent = $agents[0];
}
$i = $data['COD_IMA'];
$d = $data['COD_DEL'];
$g = $data['COD_GOU'];
if ($g != null) {
$gouvern = $doctrine->getRepository(DicGouvernorat::class)->findOneBy(['COD_GOU' => $g]);
} else {
$gouvern = null;
}
if ($d != null) {
$delega = $doctrine->getRepository(DicDelegation::class)->findOneBy(['COD_DELG' => $d, 'gouvernorat' => $gouvern]);
} else {
$delega = null;
}
if ($i != null) {
$imada = $doctrine->getRepository(DicImada::class)->findOneBy(['COD_IMAD' => $i, 'delegation' => $delega]);
} else {
$imada = null;
}
$agent->setIdentAgent($id);
$agent->setNprAgentAr($data['NPR_POILI']);
$agent->setNprAgentFr($data['NPR_POILT']);
$agent->setDelegation($delega);
$agent->setGouvernorat($gouvern);
$agent->setImada($imada);
$agent->setUpdatedAt($date);
$em->persist($agent);
$em->flush();
} catch (Exception $e) {
echo 'except *************************** ', $e->getMessage(), "\n";
}
}
return new JsonResponse([
'code' => 200,
'message' => 'Add request success',
'data' => $agent->getId()
]);
}
#[Route('/api/insiminateur', name: 'app_insiminateur')]
public function getListInisiminateur(Request $request, LoggerInterface $logger, ManagerRegistry $doctrine)
{
if (!$this->checkClientIp($request)) {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}
$em = $this->em;
$content = $request->getContent();
$dataArr = array();
$dataArr = json_decode($content, true);
$date = new \DateTime('now');
foreach ($dataArr as $data) {
try {
$insiminateur = null;
$id = trim($data['COD_AGN']);
$insiminateurs = $doctrine->getRepository(Inseminateur::class)->findBy(['codIns' => $id]);
if ($insiminateurs == null || count($insiminateurs) == 0) {
$insiminateur = new Inseminateur();
$insiminateur->setCodIns($id);
} else {
$insiminateur = $insiminateurs[0];
}
$c = $data['NUM_CIR'];
$circuit = $doctrine->getRepository(CircuitImada::class)->findOneBy(['NUM_CIR' => $c]);
if ($circuit == null) {
$gouvern = null;
$diccirc = null;
} else {
$g = $circuit->getCODGOU();
$gouvern = $doctrine->getRepository(DicGouvernorat::class)->findOneBy(['COD_GOU' => $g]);
$diccirc = $doctrine->getRepository(DicCircuit::class)->findOneBy(['codCircuit' => $c]);
}
$insiminateur->setNprInsAr($data['NPR_POILI']);
$insiminateur->setNprInsFr($data['NPR_POILT']);
$insiminateur->setDicGouvernorat($gouvern);
$insiminateur->setDicCircuit($diccirc);
$insiminateur->setCreatedAt($date);
$em->persist($insiminateur);
$em->flush();
} catch (Exception $e) {
echo 'except *************************** ', $e->getMessage(), "\n";
}
}
return new JsonResponse([
'code' => 200,
'message' => 'Add request success',
'data' => $insiminateur->getId()
//'data' => $data
]);
}
#[Route('/api/agentIdent', name: 'app_agentIdent')]
public function getListAgentIdent(Request $request, LoggerInterface $logger, ManagerRegistry $doctrine)
{
if (!$this->checkClientIp($request)) {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}
$em = $this->em;
$content = $request->getContent();
$date = new \DateTime('now');
$dataArr = array();
$dataArr = json_decode($content, true);
foreach ($dataArr as $data) {
try {
$agent = null;
$id = trim($data['COD_AGN']);
$agents = $doctrine->getRepository(Agent::class)->findBy(['codAgent' => $id]);
if ($agents == null || count($agents) == 0) {
$agent = new Agent();
$agent->setCodAgent($id);
$agent->setCreatedAt($date);
} else {
$agent = $agents[0];
}
$i = $data['COD_IMA'];
$d = $data['COD_DEL'];
$g = $data['COD_GOU'];
if ($g != null) {
$gouvern = $doctrine->getRepository(DicGouvernorat::class)->findOneBy(['COD_GOU' => $g]);
} else {
$gouvern = null;
}
if ($d != null) {
$delega = $doctrine->getRepository(DicDelegation::class)->findOneBy(['COD_DELG' => $d, 'gouvernorat' => $gouvern]);
} else {
$delega = null;
}
if ($i != null) {
$imada = $doctrine->getRepository(DicImada::class)->findOneBy(['COD_IMAD' => $i, 'delegation' => $delega]);
} else {
$imada = null;
}
$agent->setNprAgentAr($data['NPR_POILI']);
$agent->setNprAgentFr($data['NPR_POILT']);
$agent->setDelegation($delega);
$agent->setGouvernorat($gouvern);
$agent->setImada($imada);
$agent->setUpdatedAt($date);
$em->persist($agent);
$em->flush();
} catch (Exception $e) {
echo 'except *************************** ', $e->getMessage(), "\n";
}
}
return new JsonResponse([
'code' => 200,
'message' => 'Add request success',
//'data' => $agent->getId()
]);
}
#[Route('/api/adhesion', name: 'app_adhesion')]
public function getAllAdhesion(Request $request, ManagerRegistry $doctrine, LoggerInterface $logger)
{
if (!$this->checkClientIp($request)) {
return new JsonResponse([
'code' => 403,
'message' => 'not allowed to run this action'
]);
}
$dataArr = array();
$em = $this->em;
$content = $request->getContent();
$dataArr = json_decode($content, true);
$ns = 0;
$nf = 0;
if ($dataArr == '') $dataArr = array();
foreach ($dataArr as $data) {
try {
$f = trim($data['FRM_COD']);
$E = $data['COD_ESPECE'];
$nmTrAdh = $data['NUM_TRPADH'];
$typAdh = $data['TYP_ADH'];
$espece = $doctrine->getRepository(DicEspece::class)->findOneBy(['COD_ESPECE' => $E]);
$ferme = $doctrine->getRepository(Ferme::class)->findOneBy(['frm_cod' => $f]);
$typeAdh = $doctrine->getRepository(ProgrammeAmelioration::class)->findOneBy(['codPrg' => $typAdh]);
$logger->info(' addhtype ************************** ' . $typAdh . ' ***************************');
$qb = $em->createQueryBuilder();
$query = $qb->select('U')
->from('App:Adhesion', 'U')
->where('U.ferme = :ferm')
->andWhere('U.espece = :espec')
->andWhere('U.NumTrpAdh = :Num')
->andWhere('U.TypAdh = :typ')
->setParameter('espec', $espece->getId())
->setParameter('typ', $typeAdh->getId())
->setParameter('Num', $nmTrAdh)
->setParameter('ferm', $ferme->getId());
$adhesions = $query->getQuery()->getResult();
$dateD = $data['DAT_DEB'];
// $dateDebut = DateTime::createFromFormat('Y-m-d H:i:s', $dateD);
if ($dateD != null) {
$dateDebut = str_replace(array("/"), '-', $dateD);
$logger->info('dd1 ' . $dateDebut);
$datt = substr($dateD, 0, 2);
$logger->info("datt" . $datt);
$mois = substr($dateD, 3, 2);
$logger->info("mois" . $mois);
$year = substr($dateD, 6, 2);
$logger->info("year" . $year);
$dateDebut = $year . '-' . $mois . '-' . $datt;
$logger->info("dateForm" . $dateDebut);
} else {
$dateDebut = null;
}
$dateF = $data['DAT_FIN'];
if ($dateF != null) {
$dateFin = str_replace(array("/"), '-', $dateF);
$logger->info('dd1 ' . $dateFin);
$datt = substr($dateF, 0, 2);
$logger->info("datt" . $datt);
$mois = substr($dateF, 3, 2);
$logger->info("mois" . $mois);
$year = substr($dateF, 6, 2);
$logger->info("year" . $year);
$dateFin = $year . '-' . $mois . '-' . $datt;
$logger->info("dateForm" . $dateFin);
} else {
$dateFin = null;
}
//$dateFin = DateTime::createFromFormat('Y-m-d H:i:s', $dateF);
$logger->info(' addhtype ************************** ' . $dateD . ' ***************************');
$codtypCon = null;
if ($data['COD_TYPCON'] = ! null) {
$codtypCon = $data['COD_TYPCON'];
}
$cauFinAdh = null;
if ($data['CAU_FINADH'] != null) {
$cauFinAdh = $data['CAU_FINADH'];
}
$codSite = null;
if ($data['CODE_SIT'] != null) {
$codSite = $data['CODE_SIT'];
}
$nbrSem = null;
if ($data['NBR_SEM'] != null) {
$nbrSem = $data['NBR_SEM'];
}
if ($adhesions == null || count($adhesions) == 0) {
$adhesion = new Adhesion();
$adhesion->setFerme($ferme);
$adhesion->setEspece($espece);
$adhesion->setNumTrpAdh($nmTrAdh);
$adhesion->setTypAdh($typeAdh);
$adhesion->setIdSync(trim($data['IDSYNC']));
if ($dateDebut) {
$adhesion->setDateDebut(new \DateTime(date("y-m-d", strtotime($dateDebut))));
} else {
$adhesion->setDateDebut(null);
}
$adhesion->setCodTypCon($codtypCon);
if ($dateFin != null) {
$adhesion->setDateFin(new \DateTime(date("y-m-d", strtotime($dateFin))));
} else {
$adhesion->setDateFin(null);
}
$adhesion->setCauFinAdh($cauFinAdh);
$adhesion->setCodSite($codSite);
$adhesion->setNbrSit($nbrSem);
$adhesion->setCausRetrAdh($data['CAUS_RETR_ADH']);
$em->persist($adhesion);
$em->flush();
$ns++;
//$nn++;
}
} catch (Exception $e) {
echo 'except *************************** ', $e->getMessage(), "\n";
$nf++;
}
$logger->info('sync ************************** ' . $ns . ' -- ' . $nf . ' ***********************');
}
return new JsonResponse([
'code' => 200,
'message' => 'Add request success',
'data' => $dataArr
]);
}
#[Route('/api/NbAdhesion', name: 'app_NbbAdhesion')]
public function getNombreAdhesions(Request $request)
{
$em = $this->em;
$qb = $em->createQueryBuilder();
$query = $qb->select('MAX(Ad.idSync)')
->from('App:Adhesion', 'Ad');
$nbrAdhesion = $query->getQuery()->getSingleScalarResult();
if ($nbrAdhesion == null) {
$nbrAdhesion = 0;
}
return new JsonResponse([
'nbrAdhesion' => $nbrAdhesion,
]);
}
}