src/Controller/SyncronisationController.php line 1434

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\Validator\Constraints as Assert;
  4. use Symfony\Component\Validator\Constraints\DateTime;
  5. use App\Entity\DemandeAcquisition;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use Doctrine\Persistence\ManagerRegistry;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  14. use App\Entity\DemandeSortie;
  15. use App\Entity\DemandeUpdate;
  16. use App\Entity\DemandeEnree;
  17. use App\Entity\DemandeFormation;
  18. use App\Entity\DemandeIdentification;
  19. use App\Entity\DemandePrgAmelioration;
  20. use App\Entity\DemandeRebouclage;
  21. use App\Entity\OperationInsemination;
  22. use App\Entity\ProgrammeAmelioration;
  23. use App\Entity\DicEspece;
  24. use App\Entity\DicRace;
  25. use App\Entity\Eleveur;
  26. use App\Entity\DicGouvernorat;
  27. use App\Entity\DicDelegation;
  28. use App\Entity\DicImada;
  29. use App\Entity\Ferme;
  30. use App\Entity\Troupeau;
  31. use App\Entity\DicCircuit;
  32. use App\Entity\CircuitImada;
  33. use App\Entity\Animal;
  34. use App\Entity\AgentOep;
  35. use App\Entity\Agent;
  36. use App\Entity\Adhesion;
  37. use App\Entity\Inseminateur;
  38. use Symfony\Component\HttpFoundation\JsonResponse;
  39. use Psr\Log\LoggerInterface;
  40. class SyncronisationController extends AbstractController
  41. {
  42.     private $em$translator;
  43.     private $serverIp;
  44.     public function __construct(EntityManagerInterface $emTranslatorInterface $translator ParameterBagInterface $params)
  45.     {
  46.         $this->em $em;
  47.         $this->translator $translator;
  48.         $this->serverIp $_SERVER['SYNC_SERVER_IP'];
  49.     }
  50.       
  51.      
  52.      private function checkClientIp(Request $request): bool
  53.      {
  54.          $rip $request->getClientIp();
  55.          return $rip === $this->serverIp;
  56.      }
  57.  
  58.     #[Route('/api/AllDemandes'name'app_Demande_sortie')]
  59.     public function index(LoggerInterface $loggerRequest $request)
  60.     {
  61.         
  62.         
  63.         $rip $request->getClientIp();
  64.         $logger->info('api Synchro AllDemandes, ' $rip);
  65.         /*if ($rip != $serverIp && $rip != '') {
  66.             return new JsonResponse([
  67.                 'code' => 403,
  68.                 'message' => 'not allowed to run this action'
  69.             ]);
  70.         }*/
  71.         if (!$this->checkClientIp($request)) {
  72.             return new JsonResponse([
  73.                 'code' => 403,
  74.                 'message' => 'not allowed to run this action'
  75.             ]);
  76.         }
  77.         
  78.         
  79.         $em $this->em;
  80.         $content $request->getContent();
  81.         $dataRecp json_decode($contenttrue);
  82.         $logger->info('rebouclage1 : ***************** ' $content);
  83.         $logger->info('rebouclage1 : *****************' count($dataRecp));
  84.         $dernierRebouclage $dataRecp["dernierRebouclage"];
  85.         $dernierUpdate $dataRecp["dernierUpdate"];
  86.         $dernierPrgAmel $dataRecp["dernierAmelioration"];
  87.         $dernierAcquisition $dataRecp["dernierAcquisition"];
  88.         $dernierIdentification $dataRecp["dernierIdentification"];
  89.         $dernierSortie $dataRecp["dernierSortie"];
  90.         $dernierEntre $dataRecp["dernierEntree"];
  91.         $dernierFormation $dataRecp["dernierFormation"];
  92.         $dernierInsemination $dataRecp["dernierInsemination"];
  93.         $dernierOpIdenti =  $dataRecp["dernierOpIdentification"];
  94.         $logger->info('rebouclage1 : ' $dernierRebouclage);
  95.         $logger->info('update1 : ' $dernierUpdate);
  96.         $logger->info('aquisition1 : ' $dernierAcquisition);
  97.         $logger->info('entree1 : ' $dernierEntre);
  98.         $logger->info('formation1 : ' $dernierFormation);
  99.         $logger->info('insemination : ' $dernierInsemination);
  100.         $logger->info('operationIdenti : ' $dernierOpIdenti);
  101.         if ($dernierOpIdenti == null) {
  102.             $dernierOpIdenti 0;
  103.         }
  104.         if ($dernierInsemination == null) {
  105.             $dernierInsemination 0;
  106.         }
  107.         if ($dernierRebouclage == null) {
  108.             $dernierRebouclage 0;
  109.         }
  110.         if ($dernierUpdate == null) {
  111.             $dernierUpdate 0;
  112.         }
  113.         if ($dernierPrgAmel == null) {
  114.             $dernierPrgAmel 0;
  115.         }
  116.         if ($dernierAcquisition == null) {
  117.             $dernierAcquisition 0;
  118.         }
  119.         if ($dernierIdentification == null) {
  120.             $dernierIdentification 0;
  121.         }
  122.         if ($dernierSortie == null) {
  123.             $dernierSortie 0;
  124.         }
  125.         if ($dernierEntre == null) {
  126.             $dernierEntre 0;
  127.         }
  128.         if ($dernierFormation == null) {
  129.             $dernierFormation 0;
  130.         }
  131.         $logger->info('rebouclage : ' $dernierRebouclage);
  132.         $logger->info('update : ' $dernierUpdate);
  133.         $logger->info('aquisition : ' $dernierAcquisition);
  134.         $logger->info('entree : ' $dernierEntre);
  135.         $logger->info('formation : ' $dernierFormation);
  136.         $qb $em->createQueryBuilder();
  137.         $query $qb->select('S')
  138.             ->from('App:DemandeSortie''S')
  139.             ->where('S.etatTraitement > 0 ')
  140.             ->andWhere('S.id > :dernierId')
  141.             ->setParameter('dernierId'$dernierSortie);
  142.         $entityServices $query->getQuery()->getResult();
  143.         $datas = array();
  144.         foreach ($entityServices as $key => $entityService) {
  145.             $datas[$key]['Id'] = $entityService->getId();
  146.             $datas[$key]['Animal'] = $entityService->getAnimal()->getId();
  147.             $datas[$key]['codAnimal'] = $entityService->getAnimal()->getIdentAnm();
  148.             $datas[$key]['Frm_Cod'] = $entityService->getFrmCod();
  149.             $datas[$key]['Date_Sortie'] = $entityService->getDateSor()->format('Y-m-d H:i:s');
  150.             $datas[$key]['Etat_Traitement'] = $entityService->getEtatTraitement();
  151.             if ($entityService->getDateTraitement()) {
  152.                 $datas[$key]['Date_Traitement'] = $entityService->getDateTraitement()->format('Y-m-d H:i:s');
  153.             } else {
  154.                 $datas[$key]['Date_Traitement'] = $entityService->getDateTraitement();
  155.             }
  156.             $datas[$key]['Cause_Sortie'] = $entityService->getCauseSor();
  157.             $datas[$key]['CreatedAt'] = $entityService->getCreatedAt()->format('Y-m-d H:i:s');;
  158.             $datas[$key]['Eleveur'] = $entityService->getEleveur()->getId();
  159.             $datas[$key]['codEleveur'] = $entityService->getEleveur()->getCodElv();
  160.             $datas[$key]['codSit'] = $entityService->getEleveur()->getGouvernorat()->getCodeGou();
  161.             $datas[$key]['codEspece'] = $entityService->getEspece()->getCodeEspece();
  162.             $datas[$key]['codAgn'] = $entityService->getCodAgn();
  163.         }
  164.         //$demandesUpdate = $em->getRepository(DemandeUpdate::class)->findAll();
  165.         $qb $em->createQueryBuilder();
  166.         $query $qb->select('u')
  167.             ->from('App:DemandeUpdate''u')
  168.             ->where('u.etatTraitement > 0 ')
  169.             ->andWhere('u.id > :dernierId')
  170.             ->setParameter('dernierId'$dernierUpdate);
  171.         $demandesUpdate $query->getQuery()->getResult();
  172.         $demandeUp = array();
  173.         foreach ($demandesUpdate as $key => $demandeU) {
  174.             $demandeUp[$key]['Id'] = $demandeU->getId();
  175.             if ($demandeU->getAnimal() != null) {
  176.                 $demandeUp[$key]['Animal'] = $demandeU->getAnimal()->getId();
  177.                 $demandeUp[$key]['animalCod'] = $demandeU->getAnimal()->getIdentAnm();
  178.             } else {
  179.                 $demandeUp[$key]['Animal'] = $demandeU->getAnimal();
  180.                 $demandeUp[$key]['animalCod'] = $demandeU->getAnimal();
  181.             }
  182.             if ($demandeU->getEleveur() != null) {
  183.                 $demandeUp[$key]['Eleveur'] = $demandeU->getEleveur()->getId();
  184.                 $demandeUp[$key]['codEleveur'] = $demandeU->getEleveur()->getCodElv();
  185.             } else {
  186.                 $demandeUp[$key]['Eleveur'] = $demandeU->getEleveur()->getId();
  187.                 $demandeUp[$key]['codEleveur'] = $demandeU->getEleveur()->getCodElv();
  188.             }
  189.             if ($demandeU->getDicRace() != null) {
  190.                 $demandeUp[$key]['dicRace'] = $demandeU->getDicRace()->getId();
  191.                 $demandeUp[$key]['dicRaceCode'] = $demandeU->getDicRace()->getcodeRace();
  192.             } else {
  193.                 $demandeUp[$key]['dicRace'] = $demandeU->getDicRace();
  194.                 $demandeUp[$key]['dicRaceCode'] = $demandeU->getDicRace();
  195.             }
  196.             if ($demandeU->getSexAnm() == 1) {
  197.                 $demandeUp[$key]['sexAnmCod'] = 'M';
  198.             } else {
  199.                 $demandeUp[$key]['sexAnmCod'] = 'F';
  200.             }
  201.             $demandeUp[$key]['sexAnm'] = $demandeU->getSexAnm();
  202.             $demandeUp[$key]['codAgn'] = $demandeU->getCodAgn();
  203.             $demandeUp[$key]['dateNais'] = $demandeU->getDateNais()->format('Y-m-d');
  204.             $demandeUp[$key]['annNais'] = $demandeU->getAnnNais();
  205.             $demandeUp[$key]['etatTraitement'] = $demandeU->getEtatTraitement();
  206.             if ($demandeU->getDateTraitement() != null) {
  207.                 $demandeUp[$key]['dateTraitement'] = $demandeU->getDateTraitement()->format('Y-m-d H:i:s');
  208.             } else {
  209.                 $demandeUp[$key]['dateTraitement'] = $demandeU->getDateTraitement();
  210.             }
  211.             if ($demandeU->getDateDepot() != null) {
  212.                 $demandeUp[$key]['dateDepot'] = $demandeU->getDateDepot()->format('Y-m-d H:i:s');
  213.             } else {
  214.                 $demandeUp[$key]['dateDepot'] = $demandeU->getDateDepot();
  215.             }
  216.             if ($demandeU->getCreatedAt() != null) {
  217.                 $demandeUp[$key]['createdAt'] = $demandeU->getCreatedAt()->format('Y-m-d H:i:s');
  218.             } else {
  219.                 $demandeUp[$key]['createdAt'] = $demandeU->getCreatedAt();
  220.             }
  221.             if ($demandeU->getUpdatedAt() != null) {
  222.                 $demandeUp[$key]['updatedAt'] = $demandeU->getUpdatedAt()->format('Y-m-d H:i:s');
  223.             } else {
  224.                 $demandeUp[$key]['updatedAt'] = $demandeU->getUpdatedAt();
  225.             }
  226.             $demandeUp[$key]['idePere'] = $demandeU->getIdePere();
  227.             $demandeUp[$key]['ideMere'] = $demandeU->getIdeMere();
  228.         }
  229.         $qb $em->createQueryBuilder();
  230.         $query $qb->select('e')
  231.             ->from('App:DemandeEnree''e')
  232.             ->where('e.etatTraitement > 0 ')
  233.             ->andWhere('e.id > :dernierId')
  234.             ->setParameter('dernierId'$dernierEntre);
  235.         $demandesEntre $query->getQuery()->getResult();
  236.         $demandeEn = array();
  237.         foreach ($demandesEntre as $key => $demandeE) {
  238.             $demandeEn[$key]['Id'] = $demandeE->getId();
  239.             // $demandeEn[$key]['Animal']= $demandeE->getAnimal()->getId();
  240.             //$demandeEn[$key]['Animal']= $demandeE->getAnimal();
  241.             $demandeEn[$key]['Animal'] = $demandeE->getIdentAnm();
  242.             $demandeEn[$key]['Ferme'] = $demandeE->getFerme()->getId();
  243.             $demandeEn[$key]['codSit'] = $demandeE->getFerme()->getImada()->getDelegation()->getGouvernorat()->getCodeGou();
  244.             $demandeEn[$key]['codEspece'] = $demandeE->getEspece()->getCodeEspece();
  245.             $demandeEn[$key]['codFerme'] = $demandeE->getFerme()->getFrmCod();
  246.             $demandeEn[$key]['dateCon'] = $demandeE->getDateCon();
  247.             $demandeEn[$key]['etatTraitement'] = $demandeE->getEtatTraitement();
  248.             $demandeEn[$key]['sorFrm'] = $demandeE->getSorFrm();
  249.             $demandeEn[$key]['identAnm'] = $demandeE->getIdentAnm();
  250.             $demandeEn[$key]['createdAt'] = $demandeE->getCreatedAt()->format('Y-m-d H:i:s');
  251.             $demandeEn[$key]['dateEnt'] = $demandeE->getDateEnt()->format('Y-m-d H:i:s');;
  252.             $demandeEn[$key]['eleveur'] = $demandeE->getEleveur()->getId();
  253.             $demandeEn[$key]['codEleveur'] = $demandeE->getEleveur()->getCodElv();
  254.             $demandeEn[$key]['codAgn'] = $demandeE->getCodAgn();
  255.         }
  256.         $qb $em->createQueryBuilder();
  257.         /* $query = $qb->select('e')
  258.             ->from('App:DemandeRebouclage', 'e')
  259.             ->leftJoin('e.rebouclageAnimals','r')
  260.             ->where('e.id = r.demRebouc')
  261.             ->andWhere('e.etatTraitement > 0 ')
  262.             ->andWhere('e.id > :dernierId')
  263.             ->setParameter('dernierId',$dernierRebouclage );
  264.         $demandesRebouclage = $query->getQuery()->getResult();*/
  265.         $query $qb->select('e')
  266.             ->from('App:RebouclageAnimal''e')
  267.             ->leftJoin('e.demRebouc''r')
  268.             ->where('e.demRebouc = r.id')
  269.             ->andWhere('r.etatTraitement > 0 ')
  270.             ->andWhere('r.id > :dernierId')
  271.             ->setParameter('dernierId'$dernierRebouclage);
  272.         $demandesRebouclage $query->getQuery()->getResult();
  273.         //dump($demandesRebouclages);die;
  274.         $demandeReb = array();
  275.         foreach ($demandesRebouclage as $key => $demandeR) {
  276.             $demandeReb[$key]['Id'] = $demandeR->getDemRebouc()->getId();
  277.             $demandeReb[$key]['Eleveur'] = $demandeR->getDemRebouc()->getEleveur()->getId();
  278.             $demandeReb[$key]['eleveurCod'] = $demandeR->getDemRebouc()->getEleveur()->getCodElv();
  279.             $demandeReb[$key]['etatTraitement'] = $demandeR->getDemRebouc()->getEtatTraitement();
  280.             $demandeReb[$key]['dateDemande'] = $demandeR->getDemRebouc()->getDateDemande();
  281.             $demandeReb[$key]['dateRebouc'] = $demandeR->getDemRebouc()->getDateRebouc();
  282.             $demandeReb[$key]['codAgn'] = $demandeR->getDemRebouc()->getCodAgn();
  283.             if ($demandeR->getAnimal()->getTroupeau() != null) {
  284.                 $demandeReb[$key]['frmCod'] = $demandeR->getAnimal()->getTroupeau()->getFerme()->getFrmCod();
  285.                 $demandeReb[$key]['codGouv'] = $demandeR->getAnimal()->getTroupeau()->getFerme()->getImada()->getDelegation()->getGouvernorat()->getCodeGou();
  286.             } else {
  287.                 $demandeReb[$key]['frmCod'] = null;
  288.                 $demandeReb[$key]['codGouv'] = $demandeR->getDemRebouc()->getEleveur()->getGouvernorat()->getCodeGou();
  289.             }
  290.             $demandeReb[$key]['IdeAnim'] = $demandeR->getAnimal()->getIdentAnm();
  291.             $demandeReb[$key]['codEspece'] = $demandeR->getAnimal()->getDicRace()->getDicEspece()->getCodeEspece();
  292.         }
  293.         $qb $em->createQueryBuilder();
  294.         $query $qb->select('f')
  295.             ->from('App:DemandeFormation''f')
  296.             ->where('f.etatTraitement > 0 ')
  297.             ->andWhere('f.id > :dernierId')
  298.             ->setParameter('dernierId'$dernierFormation);
  299.         $demandesFormation $query->getQuery()->getResult();
  300.         $demandeFor = array();
  301.         foreach ($demandesFormation as $key => $demandeF) {
  302.             $demandeFor[$key]['Id'] = $demandeF->getId();
  303.             $demandeFor[$key]['typeFormation'] = $demandeF->getTypeFormation();
  304.             $demandeFor[$key]['etatTraitement'] = $demandeF->getEtatTraitement();
  305.             $demandeFor[$key]['dateTraitement'] = $demandeF->getDateTraitement();
  306.             $demandeFor[$key]['dateDemande'] = $demandeF->getDateDemande();
  307.             $demandeFor[$key]['createdAt'] = $demandeF->getCreatedAt();
  308.             $demandeFor[$key]['updatedAt'] = $demandeF->getUpdatedAt();
  309.             $demandeFor[$key]['identElv'] = $demandeF->getIdentElv();
  310.             $demandeFor[$key]['nprElvLt'] = $demandeF->getNprElvLt();
  311.             $demandeFor[$key]['nprElvLi'] = $demandeF->getNprElvLi();
  312.             $demandeFor[$key]['cin'] = $demandeF->getCin();
  313.             $demandeFor[$key]['niveauEducation'] = $demandeF->getNiveauEducation();
  314.             $demandeFor[$key]['adresse'] = $demandeF->getAdresse();
  315.             $demandeFor[$key]['numTel'] = $demandeF->getNumTel();
  316.             $demandeFor[$key]['email'] = $demandeF->getEmail();
  317.             $demandeFor[$key]['docDiplomes'] = $demandeF->getDocDiplomes();
  318.             $demandeFor[$key]['motif'] = $demandeF->getMotif();
  319.             $demandeFor[$key]['gouvernorat'] = $demandeF->getGouvernorat()->getId();
  320.             $demandeFor[$key]['gouvernoratCod'] = $demandeF->getGouvernorat()->getCodeGou();
  321.         }
  322.         $qb $em->createQueryBuilder();
  323.         $query $qb->select('d')
  324.             ->from('App:DemandePrgAmelioration''d')
  325.             ->where('d.etatTraitement > 0 ')
  326.             ->andWhere('d.id > :dernierId')
  327.             ->setParameter('dernierId'$dernierPrgAmel);
  328.         $demandesPrgAmelioration $query->getQuery()->getResult();
  329.         $demandeAm = array();
  330.         foreach ($demandesPrgAmelioration as $key => $demandeA) {
  331.             $demandeAm[$key]['Id'] = $demandeA->getId();
  332.             $demandeAm[$key]['Eleveur'] = $demandeA->getEleveur()->getId();
  333.             $demandeAm[$key]['codEleveur'] = $demandeA->getEleveur()->getCodElv();
  334.             if ($demandeA->getPgrAml() != null) {
  335.                 $demandeAm[$key]['pgrAml'] = $demandeA->getPgrAml()->getId();
  336.             } else {
  337.                 $demandeAm[$key]['pgrAml'] = $demandeA->getPgrAml();
  338.             }
  339.             $demandeAm[$key]['etatTraitement'] = $demandeA->getEtatTraitement();
  340.             $demandeAm[$key]['dateTraitement'] = $demandeA->getDateTraitement();
  341.             $demandeAm[$key]['dateDepot'] = $demandeA->getDateDepot();
  342.         }
  343.         $qb $em->createQueryBuilder();
  344.         $query $qb->select('aci')
  345.             ->from('App:DemandeAcquisition''aci')
  346.             ->where('aci.etatTraitement > 0 ')
  347.             ->andWhere('aci.id > :dernierId')
  348.             ->setParameter('dernierId'$dernierAcquisition);
  349.         $demandesAcquisition $query->getQuery()->getResult();
  350.         $demandeAc = array();
  351.         foreach ($demandesAcquisition as $key => $demandeAci) {
  352.             $demandeAc[$key]['Id'] = $demandeAci->getId();
  353.             $demandeAc[$key]['Eleveur'] = $demandeAci->getEleveur()->getId();
  354.             $demandeAc[$key]['codEleveur'] = $demandeAci->getEleveur()->getCodElv();
  355.             $demandeAc[$key]['dicRace'] = $demandeAci->getDicRace()->getId();
  356.             $demandeAc[$key]['dicRaceCod'] = $demandeAci->getDicRace()->getcodeRace();
  357.             $demandeAc[$key]['nbr'] = $demandeAci->getNbr();
  358.             $demandeAc[$key]['etatTraitement'] = $demandeAci->getEtatTraitement();
  359.             $demandeAc[$key]['dateTraitement'] = $demandeAci->getDateTraitement();
  360.             $demandeAc[$key]['dateDepot'] = $demandeAci->getDateDepot();
  361.             $demandeAc[$key]['codAgn'] = $demandeAci->getCodAgn();
  362.         }
  363.         $qb $em->createQueryBuilder();
  364.         $query $qb->select('Iden')
  365.             ->from('App:DemandeIdentification''Iden')
  366.             ->where('Iden.etatTraitement > 0 ')
  367.             ->andWhere('Iden.id > :dernierId')
  368.             ->setParameter('dernierId'$dernierIdentification);
  369.         $demandesIdentifiacation  $query->getQuery()->getResult();
  370.         $demandeID = array();
  371.         foreach ($demandesIdentifiacation as $key => $demandeI) {
  372.             $demandeID[$key]['Id'] = $demandeI->getId();
  373.             $demandeID[$key]['Eleveur'] = $demandeI->getEleveur()->getId();
  374.             $demandeID[$key]['codEleveur'] = $demandeI->getEleveur()->getCodElv();
  375.             $demandeID[$key]['dicEspece'] = $demandeI->getDicEspece()->getId();
  376.             $demandeID[$key]['EspeceCod'] = $demandeI->getDicEspece()->getCodeEspece();
  377.             $demandeID[$key]['nbrMale'] = $demandeI->getNbrMale();
  378.             $demandeID[$key]['nbrFemelle'] = $demandeI->getNbrFemelle();
  379.             $demandeID[$key]['etatTraitement'] = $demandeI->getEtatTraitement();
  380.             $demandeID[$key]['dateTraitement'] = $demandeI->getDateTraitement();
  381.             $demandeID[$key]['dateDepot'] = $demandeI->getDateDepot();
  382.         }
  383.         $qb $em->createQueryBuilder();
  384.         $query $qb->select('Op')
  385.             ->from('App:OperationInsemination''Op')
  386.             ->Where('Op.id > :dernierId')
  387.             ->setParameter('dernierId'$dernierInsemination);
  388.         $operationinsiminantion $query->getQuery()->getResult();
  389.         $OpIns = array();
  390.         foreach ($operationinsiminantion as $key => $o) {
  391.             $OpIns[$key]['Id'] = $o->getId();
  392.             $OpIns[$key]['Circuit'] = $o->getDicCircuit()->getCodCircuit();
  393.             if ($o->getEleveur() != null) {
  394.                 $OpIns[$key]['Eleveur'] = $o->getEleveur()->getCodElv();
  395.                 $OpIns[$key]['gouvernorat'] = $o->getEleveur()->getGouvernorat()->getCodeGou();
  396.                 $OpIns[$key]['delegation'] = $o->getEleveur()->getDelegation()->getCodDELG();
  397.                 $OpIns[$key]['imada'] = $o->getEleveur()->getImada()->getCodIm();
  398.             } else {
  399.                 $OpIns[$key]['Eleveur'] = $o->getNumeroEleveur();
  400.                 $OpIns[$key]['gouvernorat'] = null;
  401.                 $OpIns[$key]['delegation'] = null;
  402.                 $OpIns[$key]['imada'] = null;
  403.             }
  404.             if ($o->getAnimal() != null) {
  405.                 $OpIns[$key]['Animal'] = $o->getAnimal()->getIdentAnm();
  406.                 $OpIns[$key]['especeCod'] = $o->getAnimal()->getDicRace()->getDicEspece()->getCodeEspece();
  407.             } else {
  408.                 $OpIns[$key]['Animal'] = $o->getNumeroAnimal();
  409.                 $OpIns[$key]['especeCod'] = null;
  410.             }
  411.             $OpIns[$key]['Certificat'] = $o->getCertificat();
  412.             $OpIns[$key]['dateOperation'] = $o->getDateOp();
  413.             $OpIns[$key]['etatValidation'] = $o->getEtatValidation();
  414.             $OpIns[$key]['annee'] = $o->getAnnee();
  415.             $OpIns[$key]['mois'] = $o->getMois();
  416.             $OpIns[$key]['CreatedAt'] = $o->getCreatedAt();
  417.             $OpIns[$key]['UpdatedAt'] = $o->getUpdatedAt();
  418.             $OpIns[$key]['codAgn'] = $o->getCodAgent();
  419.             $OpIns[$key]['taureau'] = $o->getNumeroTaureau();
  420.         }
  421.         $qb $em->createQueryBuilder();
  422.         $query $qb->select('OI')
  423.             ->from('App:OperationIdentification''OI')
  424.             ->where('OI.etatTraitement > 0 ')
  425.             ->andWhere('OI.id > :dernierId')
  426.             ->setParameter('dernierId'$dernierOpIdenti);
  427.         $operatioIdent $query->getQuery()->getResult();
  428.         $opIden = array();
  429.         foreach ($operatioIdent as $key => $OI) {
  430.             $opIden[$key]['Id'] = $OI->getId();
  431.             $opIden[$key]['Eleveur'] = $OI->getEleveur()->getId();
  432.             $opIden[$key]['codEleveur'] = $OI->getEleveur()->getCodElv();
  433.             $opIden[$key]['Animal'] = $OI->getIdentAnimal();
  434.             $opIden[$key]['etatTraitement'] = $OI->getEtatTraitement();
  435.             $opIden[$key]['dateOp'] = $OI->getDateOp()->format('Y-m-d H:i:s');
  436.             $opIden[$key]['createdAt'] = $OI->getCreatedAt()->format('Y-m-d H:i:s');
  437.             $opIden[$key]['updatedAt'] = $OI->getUpdatedAt()->format('Y-m-d H:i:s');
  438.             $opIden[$key]['dicRace'] = $OI->getDicRace()->getId();
  439.             $opIden[$key]['dicRaceCod'] = $OI->getDicRace()->getcodeRace();
  440.             $opIden[$key]['dateNais'] = $OI->getDateNai()->format('Y-m-d');
  441.             $opIden[$key]['annNais'] = $OI->getAnnNai();
  442.             $opIden[$key]['sexAnm'] = $OI->getSexAnm();
  443.             $opIden[$key]['troupeau'] = $OI->getTroupeau()->getId();
  444.             $opIden[$key]['ferme'] = $OI->getFerme()->getId();
  445.             $opIden[$key]['codFerme'] = $OI->getFerme()->getFrmCod();
  446.             $opIden[$key]['Anne'] = $OI->getAnnee();
  447.             $opIden[$key]['Mois'] = $OI->getMois();
  448.             $opIden[$key]['numrTroup'] = $OI->getTroupeau()->getIdentTrp();
  449.             $opIden[$key]['EspeceCod'] = $OI->getDicRace()->getDicEspece()->getCodeEspece();
  450.             if ($OI->getSexAnm() == 1) {
  451.                 $opIden[$key]['sexAnmCod'] = 'M';
  452.             } else {
  453.                 $opIden[$key]['sexAnmCod'] = 'F';
  454.             }
  455.             $opIden[$key]['codAgn'] = $OI->getCodAgent();
  456.             $opIden[$key]['codSit'] = $OI->getEleveur()->getGouvernorat()->getCodeGou();
  457.         }
  458.     
  459.         return new JsonResponse([
  460.             'demandesSortie' => $datas,
  461.             'demandesUpdate' => $demandeUp,
  462.             'demandesEntree' => $demandeEn,
  463.             'demandesReboubuclage' => $demandeReb,
  464.             'demandesFormation' => $demandeFor,
  465.             'demandesPrgAmelioration' => $demandeAm,
  466.             'demandesAcquisation' => $demandeAc,
  467.             'demandesIdentification' => $demandeID,
  468.             'operationInsimination' => $OpIns,
  469.             'operationIdentification' => $opIden
  470.         ]);
  471.     }
  472.     #[Route('/api/race'name'app_race')]
  473.     public function getAllRace(Request $requestLoggerInterface $loggerManagerRegistry $doctrine)
  474.     {
  475.         if (!$this->checkClientIp($request)) {
  476.             return new JsonResponse([
  477.                 'code' => 403,
  478.                 'message' => 'not allowed to run this action'
  479.             ]);
  480.         }
  481.         $em $this->em;
  482.         $content $request->getContent();
  483.         $dataArr = array();
  484.         $dataArr json_decode($contenttrue);
  485.         foreach ($dataArr as $data) {
  486.             try {
  487.                 $race null;
  488.                 $id $data['COD_RACE'];
  489.                 $races $doctrine->getRepository(DicRace::class)->findBy(['COD_RACE' => $id]);
  490.                 if ($races == null || count($races) == 0) {
  491.                     $race = new DicRace();
  492.                     $race->setcodeRace($id);
  493.                 } else {
  494.                     $race $races[0];
  495.                 }
  496.                 $e $data['COD_ESPECE'];
  497.                 $espece $doctrine->getRepository(DicEspece::class)->findOneBy(['COD_ESPECE' => $e]);
  498.                 $race->setDicEspece($espece);
  499.                 $race->setNomRaceLt($data['NOM_RACELT']);
  500.                 $race->setNomRaceLi($data['NOM_RACELI']);
  501.                 $em->persist($race);
  502.                 $em->flush();
  503.             } catch (Exception $e) {
  504.                 echo 'except *************************** ',  $e->getMessage(), "\n";
  505.             }
  506.         }
  507.         return new JsonResponse([
  508.             'code' => 200,
  509.             'message' => 'Add request success',
  510.             'data3' => $race->getId()
  511.         ]);
  512.     }
  513.     #[Route('/api/espece'name'app_espece')]
  514.     public function getAlllEspeces(Request $requestManagerRegistry $doctrine)
  515.     {
  516.         if (!$this->checkClientIp($request)) {
  517.             return new JsonResponse([
  518.                 'code' => 403,
  519.                 'message' => 'not allowed to run this action'
  520.             ]);
  521.         }
  522.         $paramsArr = array();
  523.         $paramsArr json_decode($request->getContent(), true);
  524.         $em $this->em;
  525.         foreach ($paramsArr as $params) {
  526.             try {
  527.                 $espece null;
  528.                 $id $params['COD_ESPECE'];
  529.                 $especes $doctrine->getRepository(DicEspece::class)->findBy(['COD_ESPECE' => $id]);
  530.                 if ($especes == null || count($especes) == 0) {
  531.                     $espece = new DicEspece();
  532.                     $espece->setCodeEspece($id);
  533.                 } else {
  534.                     $espece $especes[0];
  535.                 }
  536.                 $espece->setDesEspeceLt($params['DES_ESPECELT']);
  537.                 $espece->setDesEspeceLi($params['DES_ESPECELI']);
  538.                 $em->persist($espece);
  539.                 $em->flush();
  540.             } catch (Exception $e) {
  541.                 echo 'except *************************** ',  $e->getMessage(), "\n";
  542.             }
  543.         }
  544.         return new JsonResponse([
  545.             'code' => 200,
  546.             'message' => 'Add request success',
  547.             //'data'    => $espece->getId()
  548.         ]);
  549.     }
  550.     #[Route('/api/eleveur'name'app_eleveur')]
  551.     public function getAlllEleveur(Request $requestManagerRegistry $doctrine)
  552.     {
  553.         if (!$this->checkClientIp($request)) {
  554.             return new JsonResponse([
  555.                 'code' => 403,
  556.                 'message' => 'not allowed to run this action'
  557.             ]);
  558.         }
  559.         $paramsArr = array();
  560.         $paramsArr json_decode($request->getContent(), true);
  561.         $em $this->em;
  562.         $date = new \DateTime('now');
  563.         if ($paramsArr == '')        $dataArr = array();
  564.         foreach ($paramsArr as $params) {
  565.             try {
  566.                 /*$g= $params['COD_GOU'];
  567.         $d=$params['COD_DEL'];
  568.         $i=$params['COD_IMA'];
  569.         $gouvernorat = $doctrine->getRepository(DicGouvernorat::class)->findOneBy(['COD_GOU' => $g]);
  570.         $delegation = $doctrine->getRepository(DicDelegation::class)->findOneBy(['COD_DELG' => $d]);
  571.         $imada = $doctrine->getRepository(DicImada::class)->findOneBy(['COD_IMAD' => $i]); */
  572.                 $eleveur null;
  573.                 $id trim($params['REF_ELV']);
  574.                 $eleveurs $doctrine->getRepository(Eleveur::class)->findBy(['codElv' => $id]);
  575.                 if ($eleveurs == null || count($eleveurs) == 0) {
  576.                     $eleveur = new Eleveur();
  577.                     $eleveur->setCodElv($id);
  578.                     $eleveur->setCreatedAt($date);
  579.                 } else {
  580.                     $eleveur $eleveurs[0];
  581.                 }
  582.                 /*$eleveur->setImada($imada);
  583.             $eleveur->setGouvernorat($gouvernorat);
  584.             $eleveur->setDelegation($delegation);*/
  585.                 $eleveur->setNprElvAr($params['NPR_ELVLI']);
  586.                 $eleveur->setNprElvFr($params['NPR_ELVLT']);
  587.                 $eleveur->setAdresse($params['ADR_ELVLT']);
  588.                 $eleveur->setNumTel($params['TEL_ELV']);
  589.                 $eleveur->setNumFax(intval($params['FAX_ELV']));
  590.                 $eleveur->setUpdatedAt($date);
  591.                 $em->persist($eleveur);
  592.                 $em->flush();
  593.             } catch (Exception $e) {
  594.                 echo 'except *************************** ',  $e->getMessage(), "\n";
  595.             }
  596.         }
  597.         return new JsonResponse([
  598.             'code' => 200,
  599.             'message' => 'Add request success'
  600.         ]);
  601.     }
  602.     #[Route('/api/NbEleveur'name'app_NbEleveur')]
  603.     public function getNombreEleveur(Request $request)
  604.     {
  605.         $em $this->em;
  606.         $qb $em->createQueryBuilder();
  607.         $query $qb->select('count(E.id)')->from('App:Eleveur''E');
  608.         $nbrEleveur $query->getQuery()->getSingleScalarResult();
  609.         return new JsonResponse([
  610.             'code' => 200,
  611.             'message' => 'Add request success',
  612.             'nbrEleveur' => $nbrEleveur
  613.         ]);
  614.     }
  615.     #[Route('/api/ferme'name'app_ferme')]
  616.     public function getAllistFerme(Request $requestManagerRegistry $doctrineLoggerInterface $logger)
  617.     {
  618.         if (!$this->checkClientIp($request)) {
  619.             return new JsonResponse([
  620.                 'code' => 403,
  621.                 'message' => 'not allowed to run this action'
  622.             ]);
  623.         }
  624.         $dataArr = array();
  625.         $em $this->em;
  626.         $content $request->getContent();
  627.         $dataArr json_decode($request->getContent(), true);
  628.         $date = new \DateTime('now');
  629.         if ($dataArr == '')        $dataArr = array();
  630.         $nn 0;
  631.         $ns 0;
  632.         $nf 0;
  633.         $total 0//count($dataArr);
  634.         //$logger->info('sync ************************** '.$ns.' -- '.$nf.' -- '.$total.' ***************************'); 
  635.         foreach ($dataArr as $data) {
  636.             try {
  637.                 $ferme null;
  638.                 $i $data['COD_IMA'];
  639.                 $g $data['COD_GOU'];
  640.                 $d $data['COD_DEL'];
  641.                 $e trim($data['REF_ELV']);
  642.                 $id trim($data['FRM_COD']);
  643.                 $fermes $doctrine->getRepository(Ferme::class)->findBy(['frm_cod' => $id]);
  644.                 if ($e != null) {
  645.                     $eleveur $doctrine->getRepository(Eleveur::class)->findOneBy(['codElv' => $e]);
  646.                 } else {
  647.                     $eleveur null;
  648.                 }
  649.                 if ($fermes == null || count($fermes) == 0) {
  650.                     $ferme = new Ferme();
  651.                     $ferme->setFrmCod($id);
  652.                     $nn++;
  653.                 } else {
  654.                     $ferme $fermes[0];
  655.                 }
  656.                 if ($g != null) {
  657.                     $gouvernorat $doctrine->getRepository(DicGouvernorat::class)->findOneBy(['COD_GOU' => $g]);
  658.                     $gouv $gouvernorat->getCodeGou();
  659.                 } else {
  660.                     $gouv null;
  661.                     $gouvernorat null;
  662.                 }
  663.                 if ($d != null) {
  664.                     $delegation $doctrine->getRepository(DicDelegation::class)->findOneBy(['COD_DELG' => $d'gouvernorat' => $gouvernorat]);
  665.                     $del $delegation->getCodDELG();
  666.                 } else {
  667.                     $del null;
  668.                     $delegation null;
  669.                 }
  670.                 if ($i != null) {
  671.                     $imada $doctrine->getRepository(DicImada::class)->findOneBy(['COD_IMAD' => $i'delegation' => $delegation]);
  672.                     $im $imada->getCodIm();
  673.                 } else {
  674.                     $imada null;
  675.                     $im null;
  676.                 }
  677.                 $qb2 $em->createQueryBuilder();
  678.                 $query2 $qb2->select('U')
  679.                     ->from('App:CircuitImada''U')
  680.                     ->where('U.COD_GOU = :gou')
  681.                     ->andWhere('U.COD_IMA = :ima')
  682.                     ->andWhere('U.COD_DEL = :del')
  683.                     ->setParameter('ima'$im)
  684.                     ->setParameter('del'$del)
  685.                     ->setParameter('gou'$gouv);
  686.                 $numCircuits $query2->getQuery()->getResult();
  687.                 $circuit null;
  688.                 /*if ($numCircuits > 0 || count($numCircuits )>0  || $numCircuits != null ) { 
  689.      $circuitt = $numCircuits[0]; 
  690.         } else{
  691.         $circuitt= $numCircuits;
  692.         }*/
  693.                 $circuit null;
  694.                 if ($numCircuits != null) {
  695.                     $circuitt $numCircuits[0];
  696.                 } else {
  697.                     $circuitt null;
  698.                 }
  699.                 //$circuitt= $numCircuits;
  700.                 //dump($circuitt);die;
  701.                 if ($circuitt != null) {
  702.                     $num $circuitt->getNUMCIR();
  703.                     $circuit $doctrine->getRepository(DicCircuit::class)->findOneBy(['codCircuit' => $num]);
  704.                 }
  705.                 //dump($circuitt, $num,$circuit);die;
  706.                 $ferme->setImada($imada);
  707.                 $ferme->setEleveur($eleveur);
  708.                 $ferme->setDicCircuit($circuit);
  709.                 $ferme->setFrmNomLt($data['FRM_DESLT']);
  710.                 $ferme->setFrmNomLi($data['FRM_DESLI']);
  711.                 $ferme->setFrmAdrFr($data['FRM_ADRLI']);
  712.                 $em->persist($ferme);
  713.                 if ($eleveur != null) {
  714.                     $eleveur->setImada($imada);
  715.                     $eleveur->setGouvernorat($gouvernorat);
  716.                     $eleveur->setDelegation($delegation);
  717.                     $eleveur->setUpdatedAt($date);
  718.                     $em->persist($eleveur);
  719.                 }
  720.                 $em->flush();
  721.                 $ns++;
  722.             } catch (Exception $e) {
  723.                 echo 'except *************************** ',  $e->getMessage(), "\n";
  724.                 $nf++;
  725.             }
  726.         }
  727.         $logger->info('sync ************************** ' $ns ' -- ' $nn ' -- ' $nf ' -- ' $total ' ***********************');
  728.         return new JsonResponse([
  729.             'code' => 200,
  730.             'message' => 'Add request success',
  731.             // 'cinrcuitnum'=> $numCircuits
  732.         ]);
  733.     }
  734.     #[Route('/api/NbFerme'name'app_NbFerme')]
  735.     public function getNombreFerme(Request $requestManagerRegistry $doctrine)
  736.     {
  737.         $em $this->em;
  738.         $qb $em->createQueryBuilder();
  739.         $query $qb->select('MAX(F.id)')->from('App:Ferme''F');
  740.         $dernierID $query->getQuery()->getSingleScalarResult();
  741.         $qb1 $em->createQueryBuilder();
  742.         $query1 $qb1->select('F')
  743.             ->from('App:Ferme''F')
  744.             ->where('F.id = :DERId')
  745.             ->setParameter('DERId'$dernierID);
  746.         $dernierFerme $query1->getQuery()->getResult();
  747.         if ($dernierFerme == null) {
  748.             $codFrm null;
  749.         } else {
  750.             $codFrm $dernierFerme[0]->getFrmCod();
  751.         }
  752.         $qb2 $em->createQueryBuilder();
  753.         $query2 $qb2->select('count(F.id)')->from('App:Ferme''F');
  754.         $nbrFerme $query2->getQuery()->getSingleScalarResult();
  755.         return new JsonResponse([
  756.             'code' => 200,
  757.             'message' => 'Add request success',
  758.             'dernierID' => $dernierID,
  759.             'dernierFrm' => $codFrm,
  760.             'NombreFrm' => $nbrFerme,
  761.             //'codecircuit' => $numCircuits
  762.         ]);
  763.     }
  764.     #[Route('/api/troupeau'name'app_troupeau')]
  765.     public function getAlltroupeau(Request $requestManagerRegistry $doctrineLoggerInterface $logger)
  766.     {
  767.         if (!$this->checkClientIp($request)) {
  768.             return new JsonResponse([
  769.                 'code' => 403,
  770.                 'message' => 'not allowed to run this action'
  771.             ]);
  772.         }
  773.         $dataArr = array();
  774.         $em $this->em;
  775.         $content $request->getContent();
  776.         $dataArr json_decode($contenttrue);
  777.         $ns 0;
  778.         $nf 0;
  779.         if ($dataArr == '')        $dataArr = array();
  780.         foreach ($dataArr as $data) {
  781.             try {
  782.                 $f trim($data['FRM_COD']);
  783.                 $p $data['COD_ESPECE'];
  784.                 $nmT $data['NUM_TRP'];
  785.                 $espece $doctrine->getRepository(DicEspece::class)->findOneBy(['COD_ESPECE' => $p]);
  786.                 $ferme $doctrine->getRepository(Ferme::class)->findOneBy(['frm_cod' => $f]);
  787.                 $qb $em->createQueryBuilder();
  788.                 $query $qb->select('U')
  789.                     ->from('App:Troupeau''U')
  790.                     ->where('U.ferme = :ferm')
  791.                     ->andWhere('U.dicEspece = :espec')
  792.                     ->andWhere('U.identTrp = :numT')
  793.                     ->setParameter('espec'$espece->getId())
  794.                     ->setParameter('numT'$nmT)
  795.                     ->setParameter('ferm'$ferme->getId());
  796.                 $troupaux $query->getQuery()->getResult();
  797.                 if ($troupaux  == null || count($troupaux) == 0) {
  798.                     $troupeau = new Troupeau();
  799.                 } else {
  800.                     $troupeau $troupaux[0];
  801.                 }
  802.                 $troupeau->setFerme($ferme);
  803.                 $troupeau->setDicEspece($espece);
  804.                 $troupeau->setIdSync(trim($data['IDSYNC']));
  805.                 $troupeau->setIdentTrp($nmT);
  806.                 $em->persist($troupeau);
  807.                 $em->flush();
  808.                 $ns++;
  809.                 //$nn++;
  810.             } catch (Exception $e) {
  811.                 echo 'except *************************** ',  $e->getMessage(), "\n";
  812.                 $nf++;
  813.             }
  814.             $logger->info('sync ************************** ' $ns '  -- ' $nf ' ***********************');
  815.         }
  816.         return new JsonResponse([
  817.             'code' => 200,
  818.             'message' => 'Add request success',
  819.         ]);
  820.     }
  821.     #[Route('/api/NbTroupeau'name'app_NbTroupeau')]
  822.     public function getNombreTroupeau(Request $request)
  823.     {
  824.         $em $this->em;
  825.         $qb $em->createQueryBuilder();
  826.         $query $qb->select('MAX(T.idSync)')->from('App:Troupeau''T');
  827.         $nbrTroupeau $query->getQuery()->getSingleScalarResult();
  828.         if ($nbrTroupeau == null) {
  829.             $nbrTroupeau 0;
  830.         }
  831.         return new JsonResponse([
  832.             'nbrTroupeau' => $nbrTroupeau
  833.         ]);
  834.     }
  835.     #[Route('/api/gouvernorat'name'app_gouvernourat')]
  836.     public function getAllistGouvernourat(Request $requestLoggerInterface $loggerManagerRegistry $doctrine)
  837.     {
  838.         if (!$this->checkClientIp($request)) {
  839.             return new JsonResponse([
  840.                 'code' => 403,
  841.                 'message' => 'not allowed to run this action'
  842.             ]);
  843.         }
  844.         $em $this->em;
  845.         $content $request->getContent();
  846.         $dataArr = array();
  847.         $dataArr json_decode($contenttrue);
  848.         if ($dataArr == '')        $dataArr = array();
  849.         foreach ($dataArr as $data) {
  850.             try {
  851.                 $gouvernorat null;
  852.                 $id $data['COD_GOU'];
  853.                 $gouvernorats $doctrine->getRepository(DicGouvernorat::class)->findBy(['COD_GOU' => $id]);
  854.                 if ($gouvernorats == null || count($gouvernorats) == 0) {
  855.                     $gouvernorat = new DicGouvernorat();
  856.                     $gouvernorat->setCodeGou($id);
  857.                 } else {
  858.                     $gouvernorat $gouvernorats[0];
  859.                 }
  860.                 $gouvernorat->setGouvernorat($data['NOM_GOULT']);
  861.                 $gouvernorat->setNomAr($data['NOM_GOULI']);
  862.                 $em->persist($gouvernorat);
  863.                 $em->flush();
  864.             } catch (Exception $e) {
  865.                 echo 'except *************************** ',  $e->getMessage(), "\n";
  866.             }
  867.         }
  868.         return new JsonResponse([
  869.             'code' => 200,
  870.             'message' => 'Add request success',
  871.             'data3' => $gouvernorat->getId()
  872.         ]);
  873.     }
  874.     #[Route('/api/delegation'name'app_delegation')]
  875.     public function getListDelegation(Request $requestLoggerInterface $loggerManagerRegistry $doctrine)
  876.     {
  877.         if (!$this->checkClientIp($request)) {
  878.             return new JsonResponse([
  879.                 'code' => 403,
  880.                 'message' => 'not allowed to run this action'
  881.             ]);
  882.         }
  883.         $em $this->em;
  884.         $content $request->getContent();
  885.         $dataArr = array();
  886.         $dataArr json_decode($contenttrue);
  887.         if ($dataArr == '')        $dataArr = array();
  888.         foreach ($dataArr as $data) {
  889.             try {
  890.                 $delegation null;
  891.                 $id $data['DES_DELLT'];
  892.                 $delegations $doctrine->getRepository(DicDelegation::class)->findBy(['delegation' => $id]);
  893.                 if ($delegations  == null || count($delegations) == 0) {
  894.                     $delegation = new DicDelegation();
  895.                     $delegation->setDelegation($id);
  896.                 } else {
  897.                     $delegation $delegations[0];
  898.                 }
  899.                 $g $data['COD_GOU'];
  900.                 $gouvernorat $doctrine->getRepository(DicGouvernorat::class)->findOneBy(['COD_GOU' => $g]);
  901.                 $delegation->setGouvernorat($gouvernorat);
  902.                 $delegation->setCodDELG($data['COD_DEL']);
  903.                 $delegation->setNomAr($data['DES_DELLI']);
  904.                 $em->persist($delegation);
  905.                 $em->flush();
  906.             } catch (Exception $e) {
  907.                 echo 'except *************************** ',  $e->getMessage(), "\n";
  908.             }
  909.         }
  910.         return new JsonResponse([
  911.             'code' => 200,
  912.             'message' => 'Add request success',
  913.             //'data3' => $delegation->getId()
  914.         ]);
  915.     }
  916.     #[Route('/api/imada'name'app_imada')]
  917.     public function getListImada(Request $requestLoggerInterface $loggerManagerRegistry $doctrine)
  918.     {
  919.         if (!$this->checkClientIp($request)) {
  920.             return new JsonResponse([
  921.                 'code' => 403,
  922.                 'message' => 'not allowed to run this action'
  923.             ]);
  924.         }
  925.         $em $this->em;
  926.         $content $request->getContent();
  927.         $dataArr = array();
  928.         $dataArr json_decode($contenttrue);
  929.         if ($dataArr == '')        $dataArr = array();
  930.         foreach ($dataArr as $data) {
  931.             try {
  932.                 $imada null;
  933.                 $id $data['DES_IMALI'];
  934.                 $d $data['COD_DEL'];
  935.                 $g $data['COD_GOU'];
  936.                 $im $data['COD_IMA'];
  937.                 if ($g != null) {
  938.                     $gouvernorat $doctrine->getRepository(DicGouvernorat::class)->findOneBy(['COD_GOU' => $g]);
  939.                 } else {
  940.                     $gouvernorat null;
  941.                 }
  942.                 if ($d != null) {
  943.                     $delegation $doctrine->getRepository(DicDelegation::class)->findOneBy(['COD_DELG' => $d'gouvernorat' => $gouvernorat]);
  944.                 } else {
  945.                     $delegation null;
  946.                 }
  947.                 $imadas $doctrine->getRepository(DicImada::class)->findBy(['nom' => $id'delegation' => $delegation'COD_IMAD' => $im]);
  948.                 if ($imadas  == null || count($imadas) == 0) {
  949.                     $imada = new DicImada();
  950.                 } else {
  951.                     $imada $imadas[0];
  952.                 }
  953.                 $imada->setNom($id);
  954.                 $imada->setDelegation($delegation);
  955.                 $imada->setCodIm($data['COD_IMA']);
  956.                 $imada->setNomAr($data['DES_IMALI']);
  957.                 $em->persist($imada);
  958.                 $em->flush();
  959.             } catch (Exception $e) {
  960.                 echo 'except *************************** ',  $e->getMessage(), "\n";
  961.             }
  962.         }
  963.         return new JsonResponse([
  964.             'code' => 200,
  965.             'message' => 'Add request success',
  966.             //'data' => $imada->getId()
  967.         ]);
  968.     }
  969.     #[Route('/api/circuit'name'app_circuit')]
  970.     public function getListCircuit(Request $requestLoggerInterface $loggerManagerRegistry $doctrine)
  971.     {
  972.         if (!$this->checkClientIp($request)) {
  973.             return new JsonResponse([
  974.                 'code' => 403,
  975.                 'message' => 'not allowed to run this action'
  976.             ]);
  977.         }
  978.         $em $this->em;
  979.         $content $request->getContent();
  980.         $dataArr = array();
  981.         $dataArr json_decode($contenttrue);
  982.         if ($dataArr == '')        $dataArr = array();
  983.         foreach ($dataArr as $data) {
  984.             try {
  985.                 $circuit null;
  986.                 $id $data['NUM_CIR'];
  987.                 $circuits $doctrine->getRepository(DicCircuit::class)->findBy(['codCircuit' => $id]);
  988.                 if ($circuits  == null || count($circuits) == 0) {
  989.                     $circuit = new DicCircuit();
  990.                     $circuit->setCodCircuit($id);
  991.                 } else {
  992.                     $circuit $circuits[0];
  993.                 }
  994.                 $circuit->setDesCirLt($data['DES_CIRLT']);
  995.                 $circuit->setDesCirLi($data['DES_CIRLI']);
  996.                 $em->persist($circuit);
  997.                 $em->flush();
  998.             } catch (Exception $e) {
  999.                 echo 'except *************************** ',  $e->getMessage(), "\n";
  1000.             }
  1001.         }
  1002.         return new JsonResponse([
  1003.             'code' => 200,
  1004.             'message' => 'Add request success',
  1005.             // 'data' => $circuit->getId()
  1006.         ]);
  1007.     }
  1008.     #[Route('/api/circuitImada'name'app_circuitimada')]
  1009.     public function getListCircuitImada(Request $requestLoggerInterface $loggerManagerRegistry $doctrine)
  1010.     {
  1011.         if (!$this->checkClientIp($request)) {
  1012.             return new JsonResponse([
  1013.                 'code' => 403,
  1014.                 'message' => 'not allowed to run this action'
  1015.             ]);
  1016.         }
  1017.         $em $this->em;
  1018.         $content $request->getContent();
  1019.         $dataArr = array();
  1020.         $dataArr json_decode($contenttrue);
  1021.         if ($dataArr == '')        $dataArr = array();
  1022.         /* $gouvernorat = $data['COD_GOU'];
  1023.         $delegation = $data ['COD_DEL'];
  1024.         $imada = $data['COD_IMA'];
  1025.         $circuit = $doctrine->getRepository(DicImada::class)->findOneBy(['COD_IMA' => $imada,'COD_DEL'=>$delegation,'COD_GOU'=>$gouvernorat]);*/
  1026.         foreach ($dataArr as $data) {
  1027.             try {
  1028.                 $gouvernorat $data['COD_GOU'];
  1029.                 $delegation $data['COD_DEL'];
  1030.                 $imada $data['COD_IMA'];
  1031.                 $circuits $doctrine->getRepository(CircuitImada::class)->findBy(['COD_IMA' => $imada'COD_DEL' => $delegation'COD_GOU' => $gouvernorat]);
  1032.                 if ($circuits  == null || count($circuits) == 0) {
  1033.                     $cirImada = new CircuitImada();
  1034.                 } else {
  1035.                     $cirImada $circuits[0];
  1036.                 }
  1037.                 $cirImada->setNUMCIR($data['NUM_CIR']);
  1038.                 $cirImada->setCODGOU($data['COD_GOU']);
  1039.                 $cirImada->setCODDEL($data['COD_DEL']);
  1040.                 $cirImada->setCODIMA($data['COD_IMA']);
  1041.                 $em->persist($cirImada);
  1042.                 $em->flush();
  1043.             } catch (Exception $e) {
  1044.                 echo 'except *************************** ',  $e->getMessage(), "\n";
  1045.             }
  1046.         }
  1047.         return new JsonResponse([
  1048.             'code' => 200,
  1049.             'message' => 'Add request success',
  1050.             //'data' => $cirImada->getId()
  1051.         ]);
  1052.     }
  1053.     #[Route('/api/animal'name'app_animal')]
  1054.     public function getListAnimal(Request $requestLoggerInterface $loggerManagerRegistry $doctrine)
  1055.     {
  1056.         if (!$this->checkClientIp($request)) {
  1057.             return new JsonResponse([
  1058.                 'code' => 403,
  1059.                 'message' => 'not allowed to run this action'
  1060.             ]);
  1061.         }
  1062.         $dataArr = array();
  1063.         $em $this->em;
  1064.         $content $request->getContent();
  1065.         $dataArr json_decode($contenttrue);
  1066.         $date = new \DateTime('now');
  1067.         $taille count($dataArr);
  1068.         $ns 0;
  1069.         $nf 0;
  1070.         $nn 0;
  1071.         $concatMessage "";
  1072.         $logger->info('sync ************************** ' $ns ' -- ' $nf ' -- ' $taille ' ***************************');
  1073.         if ($dataArr == '')        $dataArr = array();
  1074.         foreach ($dataArr as $data) {
  1075.             try {
  1076.                 $id trim($data['IDE_ANIM']);
  1077.                 $concatMessage .= $id " ";
  1078.                 $animal null;
  1079.                 $animales $doctrine->getRepository(Animal::class)->findBy(['identAnm' => $id]);
  1080.                 if ($animales == null || count($animales) == 0) {
  1081.                     $animal = new Animal();
  1082.                     $animal->setIdentAnm($id);
  1083.                     $animal->setIdSync(trim($data['IDSYNC']));
  1084.                     $animal->setCreatedAt($date);
  1085.                     $nn++;
  1086.                     $concatMessage .= " not found /";
  1087.                 } else {
  1088.                     $animal $animales[0];
  1089.                     $concatMessage .= " found /";
  1090.                     $animal->setIdSync(trim($data['IDSYNC']));
  1091.                 }
  1092.                 $r $data['COD_RACE'];
  1093.                 $t $data['NUM_TRP'];
  1094.                 //$t= $data['FRM_COD_ACT'];
  1095.                 $f trim($data['FRM_COD_ACT']);
  1096.                 $frmNais trim($data['FRM_COD_NAI']);
  1097.                 $m trim($data['IDE_MERE']);
  1098.                 $p trim($data['IDE_PERE']);
  1099.                 $d $data['DAT_NAI'];
  1100.                 $animPres $data['ANIM_PRES'];
  1101.                 if ($d != null) {
  1102.                     $dateNaiss str_replace(array("/"), '-'$d);
  1103.                     $logger->info('dd1 ' $dateNaiss);
  1104.                     $datt substr($d02);
  1105.                     $logger->info("datt" $datt);
  1106.                     $mois substr($d32);
  1107.                     $logger->info("mois" $mois);
  1108.                     $year substr($d62);
  1109.                     $logger->info("year" $year);
  1110.                     $dateNaiss $year '-' $mois '-' $datt;
  1111.                     $logger->info("dateForm" $dateNaiss);
  1112.                 } else {
  1113.                     $dateNaiss null;
  1114.                 }
  1115.                 $race $doctrine->getRepository(DicRace::class)->findOneBy(['COD_RACE' => $r]);
  1116.                 if ($animPres == 'N') {
  1117.                     $troupeau null;
  1118.                     $ferme null;
  1119.                     $fermeNais $doctrine->getRepository(Ferme::class)->findOneBy(['frm_cod' => $frmNais]);
  1120.                 } else {
  1121.                     $ferme $doctrine->getRepository(Ferme::class)->findOneBy(['frm_cod' => $f]);
  1122.                     $fermeNais $doctrine->getRepository(Ferme::class)->findOneBy(['frm_cod' => $frmNais]);
  1123.                     //$troupeau = $doctrine->getRepository(Troupeau::class)->findOneBy(['ferme' => $ferme]);
  1124.                     $troupeau $doctrine->getRepository(Troupeau::class)->findOneBy(['ferme' => $ferme'identTrp' => $t]);
  1125.                 }
  1126.                 $mere $doctrine->getRepository(Animal::class)->findOneBy(['identAnm' => $m]);
  1127.                 $pere $doctrine->getRepository(Animal::class)->findOneBy(['identAnm' => $p]);
  1128.                 $eleveur  null;
  1129.                 if ($ferme != null) {
  1130.                     $eleveur $ferme->getEleveur();
  1131.                 }
  1132.                 if ($eleveur != null) {
  1133.                     $animal->setEleveur($eleveur);
  1134.                 }
  1135.                 if ($pere != null) {
  1136.                     $animal->setIdePere($pere);
  1137.                 }
  1138.                 if ($mere != null) {
  1139.                     $animal->setIdeMere($mere);
  1140.                 }
  1141.                 if ($data['SEX_ANM'] == 'M') {
  1142.                     $animal->setSexAnm(0);
  1143.                 } else {
  1144.                     $animal->setSexAnm(1);
  1145.                 }
  1146.                 if ($dateNaiss == null) {
  1147.                     $animal->setDateNai(null);
  1148.                 } else {
  1149.                     $animal->setDateNai(new \DateTime(date("y-m-d"strtotime($dateNaiss))));
  1150.                 }
  1151.                 $animal->setAnnNai($data['ANN_NAI']);
  1152.                 $animal->setTypAnm($data['TYP_ANIM']);
  1153.                 $animal->setTroupeau($troupeau);
  1154.                 $animal->setFermeNais($fermeNais);
  1155.                 $animal->setDicRace($race);
  1156.                 $animal->setUpdatedAt($date);
  1157.                 $concatMessage .= "*" json_encode($animal) . "*";
  1158.                 $em->persist($animal);
  1159.                 $em->flush();
  1160.                 $ns++;
  1161.             } catch (Exception $e) {
  1162.                 $nf++;
  1163.             }
  1164.         }
  1165.         $logger->info('sync ************************** ' $ns ' -- ' $nn ' -- ' $nf ' -- ' $taille ' ***********************');
  1166.         $concatMessage "";
  1167.         return new JsonResponse([
  1168.             'code' => 200,
  1169.             'message' => 'Add request success ' $concatMessage,
  1170.             'taille_tableau' => $taille,
  1171.             'nbrsucess' => $ns,
  1172.             'nbrfailed' => $nf
  1173.         ]);
  1174.     }
  1175.     #[Route('/api/NbAnimal'name'app_NbAnimal')]
  1176.     public function getNombreAnimal(Request $request)
  1177.     {
  1178.         $em $this->em;
  1179.         $qb $em->createQueryBuilder();
  1180.         $query $qb->select('MAX(A.idSync)')->from('App:Animal''A');
  1181.         $nbrAnimal $query->getQuery()->getSingleScalarResult();
  1182.         if ($nbrAnimal == null) {
  1183.             $nbrAnimal 0;
  1184.         }
  1185.         return new JsonResponse([
  1186.             'nbrAnimal' => $nbrAnimal,
  1187.         ]);
  1188.     }
  1189.     #[Route('/api/agentoep'name'app_agentoep')]
  1190.     public function getListAgentOep(Request $requestLoggerInterface $loggerManagerRegistry $doctrine)
  1191.     {
  1192.         if (!$this->checkClientIp($request)) {
  1193.             return new JsonResponse([
  1194.                 'code' => 403,
  1195.                 'message' => 'not allowed to run this action'
  1196.             ]);
  1197.         }
  1198.         $em $this->em;
  1199.         $content $request->getContent();
  1200.         $date = new \DateTime('now');
  1201.         $dataArr = array();
  1202.         $dataArr json_decode($contenttrue);
  1203.         foreach ($dataArr as $data) {
  1204.             try {
  1205.                 $agent null;
  1206.                 $id trim($data['COD_AGN']);
  1207.                 $agents $doctrine->getRepository(AgentOep::class)->findBy(['codAgent' => $id]);
  1208.                 if ($agents  == null || count($agents) == 0) {
  1209.                     $agent = new AgentOep();
  1210.                     $agent->setCodAgent($id);
  1211.                     $agent->setIdentAgent($id);
  1212.                     $agent->setCreatedAt($date);
  1213.                 } else {
  1214.                     $agent $agents[0];
  1215.                 }
  1216.                 $i $data['COD_IMA'];
  1217.                 $d $data['COD_DEL'];
  1218.                 $g $data['COD_GOU'];
  1219.                 if ($g != null) {
  1220.                     $gouvern $doctrine->getRepository(DicGouvernorat::class)->findOneBy(['COD_GOU' => $g]);
  1221.                 } else {
  1222.                     $gouvern null;
  1223.                 }
  1224.                 if ($d != null) {
  1225.                     $delega $doctrine->getRepository(DicDelegation::class)->findOneBy(['COD_DELG' => $d'gouvernorat' => $gouvern]);
  1226.                 } else {
  1227.                     $delega null;
  1228.                 }
  1229.                 if ($i != null) {
  1230.                     $imada $doctrine->getRepository(DicImada::class)->findOneBy(['COD_IMAD' => $i'delegation' => $delega]);
  1231.                 } else {
  1232.                     $imada null;
  1233.                 }
  1234.                 $agent->setIdentAgent($id);
  1235.                 $agent->setNprAgentAr($data['NPR_POILI']);
  1236.                 $agent->setNprAgentFr($data['NPR_POILT']);
  1237.                 $agent->setDelegation($delega);
  1238.                 $agent->setGouvernorat($gouvern);
  1239.                 $agent->setImada($imada);
  1240.                 $agent->setUpdatedAt($date);
  1241.                 $em->persist($agent);
  1242.                 $em->flush();
  1243.             } catch (Exception $e) {
  1244.                 echo 'except *************************** ',  $e->getMessage(), "\n";
  1245.             }
  1246.         }
  1247.         return new JsonResponse([
  1248.             'code' => 200,
  1249.             'message' => 'Add request success',
  1250.             'data' =>  $agent->getId()
  1251.         ]);
  1252.     }
  1253.     #[Route('/api/insiminateur'name'app_insiminateur')]
  1254.     public function getListInisiminateur(Request $requestLoggerInterface $loggerManagerRegistry $doctrine)
  1255.     {
  1256.         if (!$this->checkClientIp($request)) {
  1257.             return new JsonResponse([
  1258.                 'code' => 403,
  1259.                 'message' => 'not allowed to run this action'
  1260.             ]);
  1261.         }
  1262.         $em $this->em;
  1263.         $content $request->getContent();
  1264.         $dataArr = array();
  1265.         $dataArr json_decode($contenttrue);
  1266.         $date = new \DateTime('now');
  1267.         foreach ($dataArr as $data) {
  1268.             try {
  1269.                 $insiminateur null;
  1270.                 $id trim($data['COD_AGN']);
  1271.                 $insiminateurs $doctrine->getRepository(Inseminateur::class)->findBy(['codIns' => $id]);
  1272.                 if ($insiminateurs  == null || count($insiminateurs) == 0) {
  1273.                     $insiminateur = new Inseminateur();
  1274.                     $insiminateur->setCodIns($id);
  1275.                 } else {
  1276.                     $insiminateur $insiminateurs[0];
  1277.                 }
  1278.                 $c $data['NUM_CIR'];
  1279.                 $circuit $doctrine->getRepository(CircuitImada::class)->findOneBy(['NUM_CIR' => $c]);
  1280.                 if ($circuit == null) {
  1281.                     $gouvern null;
  1282.                     $diccirc null;
  1283.                 } else {
  1284.                     $g $circuit->getCODGOU();
  1285.                     $gouvern $doctrine->getRepository(DicGouvernorat::class)->findOneBy(['COD_GOU' => $g]);
  1286.                     $diccirc $doctrine->getRepository(DicCircuit::class)->findOneBy(['codCircuit' => $c]);
  1287.                 }
  1288.                 $insiminateur->setNprInsAr($data['NPR_POILI']);
  1289.                 $insiminateur->setNprInsFr($data['NPR_POILT']);
  1290.                 $insiminateur->setDicGouvernorat($gouvern);
  1291.                 $insiminateur->setDicCircuit($diccirc);
  1292.                 $insiminateur->setCreatedAt($date);
  1293.                 $em->persist($insiminateur);
  1294.                 $em->flush();
  1295.             } catch (Exception $e) {
  1296.                 echo 'except *************************** ',  $e->getMessage(), "\n";
  1297.             }
  1298.         }
  1299.         return new JsonResponse([
  1300.             'code' => 200,
  1301.             'message' => 'Add request success',
  1302.             'data' =>  $insiminateur->getId()
  1303.             //'data' =>  $data
  1304.         ]);
  1305.     }
  1306.     #[Route('/api/agentIdent'name'app_agentIdent')]
  1307.     public function getListAgentIdent(Request $requestLoggerInterface $loggerManagerRegistry $doctrine)
  1308.     {
  1309.         if (!$this->checkClientIp($request)) {
  1310.             return new JsonResponse([
  1311.                 'code' => 403,
  1312.                 'message' => 'not allowed to run this action'
  1313.             ]);
  1314.         }
  1315.         $em $this->em;
  1316.         $content $request->getContent();
  1317.         $date = new \DateTime('now');
  1318.         $dataArr = array();
  1319.         $dataArr json_decode($contenttrue);
  1320.         foreach ($dataArr as $data) {
  1321.             try {
  1322.                 $agent null;
  1323.                 $id trim($data['COD_AGN']);
  1324.                 $agents $doctrine->getRepository(Agent::class)->findBy(['codAgent' => $id]);
  1325.                 if ($agents  == null || count($agents) == 0) {
  1326.                     $agent = new Agent();
  1327.                     $agent->setCodAgent($id);
  1328.                     $agent->setCreatedAt($date);
  1329.                 } else {
  1330.                     $agent $agents[0];
  1331.                 }
  1332.                 $i $data['COD_IMA'];
  1333.                 $d $data['COD_DEL'];
  1334.                 $g $data['COD_GOU'];
  1335.                 if ($g != null) {
  1336.                     $gouvern $doctrine->getRepository(DicGouvernorat::class)->findOneBy(['COD_GOU' => $g]);
  1337.                 } else {
  1338.                     $gouvern null;
  1339.                 }
  1340.                 if ($d != null) {
  1341.                     $delega $doctrine->getRepository(DicDelegation::class)->findOneBy(['COD_DELG' => $d'gouvernorat' => $gouvern]);
  1342.                 } else {
  1343.                     $delega null;
  1344.                 }
  1345.                 if ($i != null) {
  1346.                     $imada $doctrine->getRepository(DicImada::class)->findOneBy(['COD_IMAD' => $i'delegation' => $delega]);
  1347.                 } else {
  1348.                     $imada null;
  1349.                 }
  1350.                 $agent->setNprAgentAr($data['NPR_POILI']);
  1351.                 $agent->setNprAgentFr($data['NPR_POILT']);
  1352.                 $agent->setDelegation($delega);
  1353.                 $agent->setGouvernorat($gouvern);
  1354.                 $agent->setImada($imada);
  1355.                 $agent->setUpdatedAt($date);
  1356.                 $em->persist($agent);
  1357.                 $em->flush();
  1358.             } catch (Exception $e) {
  1359.                 echo 'except *************************** ',  $e->getMessage(), "\n";
  1360.             }
  1361.         }
  1362.         return new JsonResponse([
  1363.             'code' => 200,
  1364.             'message' => 'Add request success',
  1365.             //'data' =>  $agent->getId()
  1366.         ]);
  1367.     }
  1368.     #[Route('/api/adhesion'name'app_adhesion')]
  1369.     public function getAllAdhesion(Request $requestManagerRegistry $doctrineLoggerInterface $logger)
  1370.     {
  1371.         if (!$this->checkClientIp($request)) {
  1372.             return new JsonResponse([
  1373.                 'code' => 403,
  1374.                 'message' => 'not allowed to run this action'
  1375.             ]);
  1376.         }
  1377.         $dataArr = array();
  1378.         $em $this->em;
  1379.         $content $request->getContent();
  1380.         $dataArr json_decode($contenttrue);
  1381.         $ns 0;
  1382.         $nf 0;
  1383.         if ($dataArr == '')        $dataArr = array();
  1384.         foreach ($dataArr as $data) {
  1385.             try {
  1386.                 $f trim($data['FRM_COD']);
  1387.                 $E $data['COD_ESPECE'];
  1388.                 $nmTrAdh $data['NUM_TRPADH'];
  1389.                 $typAdh $data['TYP_ADH'];
  1390.                 $espece $doctrine->getRepository(DicEspece::class)->findOneBy(['COD_ESPECE' => $E]);
  1391.                 $ferme $doctrine->getRepository(Ferme::class)->findOneBy(['frm_cod' => $f]);
  1392.                 $typeAdh $doctrine->getRepository(ProgrammeAmelioration::class)->findOneBy(['codPrg' => $typAdh]);
  1393.                 $logger->info(' addhtype ************************** ' $typAdh ' ***************************');
  1394.                 $qb $em->createQueryBuilder();
  1395.                 $query $qb->select('U')
  1396.                     ->from('App:Adhesion''U')
  1397.                     ->where('U.ferme = :ferm')
  1398.                     ->andWhere('U.espece = :espec')
  1399.                     ->andWhere('U.NumTrpAdh = :Num')
  1400.                     ->andWhere('U.TypAdh = :typ')
  1401.                     ->setParameter('espec'$espece->getId())
  1402.                     ->setParameter('typ'$typeAdh->getId())
  1403.                     ->setParameter('Num'$nmTrAdh)
  1404.                     ->setParameter('ferm'$ferme->getId());
  1405.                 $adhesions $query->getQuery()->getResult();
  1406.                 $dateD $data['DAT_DEB'];
  1407.                 // $dateDebut = DateTime::createFromFormat('Y-m-d H:i:s', $dateD);
  1408.                 if ($dateD != null) {
  1409.                     $dateDebut str_replace(array("/"), '-'$dateD);
  1410.                     $logger->info('dd1 ' $dateDebut);
  1411.                     $datt substr($dateD02);
  1412.                     $logger->info("datt" $datt);
  1413.                     $mois substr($dateD32);
  1414.                     $logger->info("mois" $mois);
  1415.                     $year substr($dateD62);
  1416.                     $logger->info("year" $year);
  1417.                     $dateDebut $year '-' $mois '-' $datt;
  1418.                     $logger->info("dateForm" $dateDebut);
  1419.                 } else {
  1420.                     $dateDebut null;
  1421.                 }
  1422.                 $dateF $data['DAT_FIN'];
  1423.                 if ($dateF != null) {
  1424.                     $dateFin str_replace(array("/"), '-'$dateF);
  1425.                     $logger->info('dd1 ' $dateFin);
  1426.                     $datt substr($dateF02);
  1427.                     $logger->info("datt" $datt);
  1428.                     $mois substr($dateF32);
  1429.                     $logger->info("mois" $mois);
  1430.                     $year substr($dateF62);
  1431.                     $logger->info("year" $year);
  1432.                     $dateFin $year '-' $mois '-' $datt;
  1433.                     $logger->info("dateForm" $dateFin);
  1434.                 } else {
  1435.                     $dateFin null;
  1436.                 }
  1437.                 //$dateFin = DateTime::createFromFormat('Y-m-d H:i:s', $dateF);
  1438.                 $logger->info(' addhtype ************************** ' $dateD ' ***************************');
  1439.                 $codtypCon null;
  1440.                 if ($data['COD_TYPCON'] = ! null) {
  1441.                     $codtypCon $data['COD_TYPCON'];
  1442.                 }
  1443.                 $cauFinAdh null;
  1444.                 if ($data['CAU_FINADH'] != null) {
  1445.                     $cauFinAdh $data['CAU_FINADH'];
  1446.                 }
  1447.                 $codSite null;
  1448.                 if ($data['CODE_SIT'] != null) {
  1449.                     $codSite $data['CODE_SIT'];
  1450.                 }
  1451.                 $nbrSem null;
  1452.                 if ($data['NBR_SEM'] != null) {
  1453.                     $nbrSem $data['NBR_SEM'];
  1454.                 }
  1455.                 if ($adhesions  == null || count($adhesions) == 0) {
  1456.                     $adhesion = new Adhesion();
  1457.                     $adhesion->setFerme($ferme);
  1458.                     $adhesion->setEspece($espece);
  1459.                     $adhesion->setNumTrpAdh($nmTrAdh);
  1460.                     $adhesion->setTypAdh($typeAdh);
  1461.                     $adhesion->setIdSync(trim($data['IDSYNC']));
  1462.                     if ($dateDebut) {
  1463.                         $adhesion->setDateDebut(new \DateTime(date("y-m-d"strtotime($dateDebut))));
  1464.                     } else {
  1465.                         $adhesion->setDateDebut(null);
  1466.                     }
  1467.                     $adhesion->setCodTypCon($codtypCon);
  1468.                     if ($dateFin != null) {
  1469.                         $adhesion->setDateFin(new \DateTime(date("y-m-d"strtotime($dateFin))));
  1470.                     } else {
  1471.                         $adhesion->setDateFin(null);
  1472.                     }
  1473.                     $adhesion->setCauFinAdh($cauFinAdh);
  1474.                     $adhesion->setCodSite($codSite);
  1475.                     $adhesion->setNbrSit($nbrSem);
  1476.                     $adhesion->setCausRetrAdh($data['CAUS_RETR_ADH']);
  1477.                     $em->persist($adhesion);
  1478.                     $em->flush();
  1479.                     $ns++;
  1480.                     //$nn++;
  1481.                 }
  1482.             } catch (Exception $e) {
  1483.                 echo 'except *************************** ',  $e->getMessage(), "\n";
  1484.                 $nf++;
  1485.             }
  1486.             $logger->info('sync ************************** ' $ns '  -- ' $nf ' ***********************');
  1487.         }
  1488.         return new JsonResponse([
  1489.             'code' => 200,
  1490.             'message' => 'Add request success',
  1491.             'data' => $dataArr
  1492.         ]);
  1493.     }
  1494.     #[Route('/api/NbAdhesion'name'app_NbbAdhesion')]
  1495.     public function getNombreAdhesions(Request $request)
  1496.     {
  1497.         $em $this->em;
  1498.         $qb $em->createQueryBuilder();
  1499.         $query $qb->select('MAX(Ad.idSync)')
  1500.             ->from('App:Adhesion''Ad');
  1501.         $nbrAdhesion $query->getQuery()->getSingleScalarResult();
  1502.         if ($nbrAdhesion == null) {
  1503.             $nbrAdhesion 0;
  1504.         }
  1505.         return new JsonResponse([
  1506.             'nbrAdhesion' => $nbrAdhesion,
  1507.         ]);
  1508.     }
  1509. }