src/Controller/WebServiceController.php line 2835

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\AttributeCharge;
  4. use App\Entity\Charge;
  5. use App\Entity\DetailFichier;
  6. use App\Entity\DetailMission;
  7. use App\Entity\DifficulteTechnique;
  8. use App\Entity\InfosModelFichier;
  9. use App\Entity\PointageUser;
  10. use App\Repository\PointageUserRepository;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Doctrine\ORM\EntityManagerInterface;
  16. use App\Service\ValidateService;
  17. use Symfony\Component\HttpFoundation\JsonResponse;
  18. use Symfony\Component\Serializer\SerializerInterface;
  19. use App\Entity\Utilisateur
  20. use Lexik\Bundle\JWTAuthenticationBundle\Encoder\JWTEncoderInterface;
  21. use App\Repository\UtilisateurRepository;
  22. use App\Repository\MissionRepository;
  23. use App\Repository\StockMissionRepository;
  24. use App\Entity\Mission
  25. use App\Entity\InfosDetailFichier;
  26. use App\Entity\Images;
  27. use App\Entity\Notifications;
  28. use App\Entity\SousTache;
  29. use App\Entity\StockDetailFichier;
  30. use App\Entity\StockMission;
  31. use App\Entity\Tache;
  32. use Symfony\Component\HttpFoundation\File\File;
  33. use App\Repository\TacheRepository;
  34. use Symfony\Component\Notifier\Notification\Notification;
  35. use App\Entity\Marche;
  36. use App\Entity\MouvementStock;
  37. use App\Entity\Piece;
  38. use App\Entity\StockReception;
  39. use App\Entity\TachePj;
  40. use App\Entity\TacheUtilisateur;
  41. use App\Service\BaseService;
  42. use Doctrine\DBAL\Connection;
  43. class WebServiceController extends AbstractController
  44. {
  45.     public $baseService;
  46.     public $pointageRepo;
  47.     
  48.     public function __construct(BaseService $baseService PointageUserRepository $pointageRepoConnection $conn 
  49.         )
  50.     {
  51.         $this->baseService $baseService;
  52.         $this->pointageRepo $pointageRepo;
  53.         $this->conn $conn;
  54.     }
  55.     
  56.     #[Route('/webService/login'name'webServiceLogin')]
  57.     public function webServiceLogin(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  58.     JWTEncoderInterface $jwtManager,UtilisateurRepository $UtilisateurRepository): JsonResponse
  59.     {
  60.         $tokenJWT "";
  61.         $codeStatut "ERROR";
  62.         $response "";
  63.         $responseObjects = array();
  64.         
  65.         try 
  66.         {
  67.             $email=$request->get('email');
  68.             $password=$request->get('password');
  69.             $token=$request->get('token');
  70.             
  71.             if(trim($email) == "" || trim($password) == "" )
  72.             {
  73.                 $codeStatut "ERROR-EMPTY-PARAMS";
  74.                 $response "L'email ou le mot de passe est vide";
  75.             }
  76.             else
  77.             {
  78.                 $utilisateur $entityManager->getRepository(Utilisateur::class)->findOneBy(array("emaiUtil" => $email,"passUtil" => sha1($password)));
  79.                 if($utilisateur)
  80.                 {
  81.                     $data = [
  82.                         'userId' => $utilisateur->getId(),
  83.                     ];
  84.                     $bureaux $UtilisateurRepository->getUserBureaux($utilisateur->getId());
  85.                     if($token != "" and $token != null)
  86.                     {
  87.                        $utilisateur->setTokenDevice($token); 
  88.                        $entityManager->flush();
  89.                     }
  90.                     
  91.                     $tokenJWT $jwtManager->encode($data);
  92.                     
  93.                     $responseObjects['user'] = $utilisateur;
  94.                     $responseObjects['bureaux'] = $bureaux;
  95.                     $response "ok";
  96.                     $codeStatut "OK";
  97.                 }
  98.                 else
  99.                 {
  100.                     $response "L'email ou le mot de passe est incorrect";
  101.                     $codeStatut "ERROR-PARAMS";
  102.                 }
  103.             }
  104.         }
  105.         catch(\Exception $e
  106.         {
  107.             $codeStatut $e->getMessage() ;
  108.             $response "une erreur s'est produite!";
  109.         }
  110.         $resp["codeStatut"] = $codeStatut;
  111.         $resp["message"] = $response;
  112.         $resp["token"] = $tokenJWT;
  113.         $resp["object"] =  $responseObjects;
  114.         $json $serializer->serialize($resp'json');
  115.         $jsonResponse = new JsonResponse($json200, [], true);
  116.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  117.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  118.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  119.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  120.         return $jsonResponse;
  121.     }
  122.     #[Route('/webService/getData'name'webServicGetData')]
  123.     public function webServicGetData(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  124.     JWTEncoderInterface $jwtManager,MissionRepository $missionRepository,StockMissionRepository $stockMissionRepository): JsonResponse
  125.     {
  126.         $codeStatut "ERROR";
  127.         $response "";
  128.         $responseObjects = array();
  129.         $decoded "";
  130.         $allMissions = [];
  131.         $missions = [];
  132.         $userImagenull;
  133.         try 
  134.         {
  135.             $jwt $request->headers->get('Authorization');
  136.             $jwt substr($jwt7);
  137.             $decoded $jwtManager->decode($jwt);
  138.             $id $decoded['userId'];
  139.             //$data = $missionRepository->getData($id);
  140.             $allMissions $entityManager->getRepository(Mission::class)->findBy(array("etatMiss" => [1,2] ,"idAgent" =>  $id ));
  141.             $utilisateur $entityManager->getRepository(Utilisateur::class)->find($id);
  142.             if($utilisateur)
  143.             {
  144.                 $userPATH $this->getParameter('kernel.project_dir') . '/public/assets/images/Users/' $utilisateur->getLogoUtil();
  145.                 $userImage = new File($userPATH);  
  146.             }
  147.             
  148.            
  149.             foreach ($allMissions as $mission) {
  150.                 $marche $entityManager->getRepository(Marche::class)->find($mission->getIdMarche());
  151.             
  152.                 if(!empty($mission->getImagArti()))
  153.                 {
  154.                     $filePath $this->getParameter('kernel.project_dir') . '/public/assets/images/IconsMarche/' $mission->getImagArti();
  155.                 }
  156.                 else
  157.                 {
  158.                     $filePath $this->getParameter('kernel.project_dir') . '/public/assets/images/IconsMarche/main.jpg';
  159.                 }
  160.                 $file = new File($filePath);    
  161.                 if ($marche) {
  162.                     $missionData = [
  163.                         'marchename' => $marche->getNumeMarc(),
  164.                         'id' => $mission->getId(),
  165.                         'etatMiss' => $mission->getEtatMiss(),
  166.                         'NumeMiss' => $mission->getNumeMiss(),
  167.                         'dateCreation' => $mission->getDateCreation(),
  168.                         'dateFin' => $mission->getDateFin(),
  169.                         'code' => $mission->getCodeArti(),
  170.                         'image' => $file,
  171.                         'idMarche' => $marche->getId(),
  172.                         'titre' => $mission->getTitre(),
  173.                     ];
  174.             
  175.                     // Add the mission data to the $missions array
  176.                     $missions[] = $missionData;
  177.                 }
  178.             }
  179.             $files = [];
  180.             $stockUtilise = [];
  181.             $stock = [];
  182.             $diffs = [];
  183.             foreach($missions as $mission)
  184.             {
  185.                 $detailMission $entityManager->getRepository(DetailMission::class)->findBy(array("idMission" => $mission["id"]));
  186.                 foreach($detailMission as $dt)
  187.                 {
  188.                     $details[] = $dt;
  189.                     $data[] = $missionRepository->getForm($dt->getIdDetail());
  190.                     
  191.                     $images $entityManager->getRepository(Images::class)->findBy(array("idDetailFichier" => $dt->getIdDetail()));
  192.                     
  193.                     foreach ($images as $image) {
  194.                         $filePath $this->getParameter('kernel.project_dir') . '/public' $image->getUrlImage();
  195.                         
  196.                         $file = new File($filePath);
  197.                         
  198.                         // Construct the response array
  199.                         $toSend['id'] = $image->getId();
  200.                         $toSend['idDetailFichier'] = $image->getIdDetailFichier();
  201.                         $toSend['imageData'] = $file;
  202.                         $files[] = $toSend;
  203.                     }
  204.                     
  205.                     $sU $entityManager->getRepository(StockDetailFichier::class)->findBy(array("idDetail" => $dt->getIdDetail()));
  206.                     if($sU)
  207.                     {
  208.                          $stockUtilise[] = $sU;
  209.                     }
  210.                 }
  211.                 
  212.                 $diffs[] = $entityManager->getRepository(DifficulteTechnique::class)->findAll(['idMarche' => [$mission["idMarche"], 0]]);
  213.                 
  214.                 $stc $stockMissionRepository->getStock($mission["id"]);
  215.                 if($stc)
  216.                 {
  217.                     $stock[] =$stc;
  218.                 }
  219.                 
  220.             }
  221.             
  222.             $depenses = [];
  223.             $allDepenses $entityManager->getRepository(Charge::class)->findBy(['idAgent' => $id]);
  224.             $categories $entityManager->getRepository(AttributeCharge::class)->findAll();
  225.             foreach ($allDepenses as $depense) {
  226.                 
  227.                     $filePath $this->getParameter('kernel.project_dir') . '/public' $depense->getImg();
  228.                     $file = new File($filePath);    
  229.                     $depenseData = [
  230.                         'id' => $depense->getId(),
  231.                         'idAttCha' => $depense->getIdAttCha(),
  232.                         'modePaie' => $depense->getModePaie(),
  233.                         'dateCreation' => $depense->getDateCreation(),
  234.                         'observation' => $depense->getObservation(),
  235.                         'titrChar' => $depense->getTitrChar(),
  236.                         'img' => $file,
  237.                         'totalHt' => $depense->getTotalHt(),
  238.                         'totalTtc' => $depense->getTotalTtc(),
  239.                         'idMarche' => $depense->getIdMarche(),
  240.                     ];
  241.                     
  242.                     $depenses[] = $depenseData;
  243.             }
  244.             
  245.             $marches $entityManager->getRepository(Marche::class)->findBy(["EtatMarc" => 1]);
  246.             $responseObjects['missions'] = $missions;
  247.             $responseObjects['details'] = $details;
  248.             $responseObjects['data'] = $data;
  249.             $responseObjects['images'] = $files;
  250.             $responseObjects['stock'] = $stock;
  251.             $responseObjects['stockUtilise'] = $stockUtilise;
  252.             $responseObjects['difficultes'] = $diffs;
  253.             $responseObjects['utilisateur'] = $utilisateur;
  254.             $responseObjects['logo'] = $userImage;
  255.             $responseObjects['categories'] = $categories;
  256.             $responseObjects['depenses'] = $depenses;
  257.             $responseObjects['marches'] = $marches;
  258.             $codeStatut 'OK';
  259.             $response "ok";
  260.         }
  261.         catch(\Exception $e
  262.         {
  263.             $codeStatut $e->getMessage() ;
  264.             $response "une erreur s'est produite!";
  265.         }
  266.         $resp["codeStatut"] = $codeStatut;
  267.         $resp["message"] = $response;
  268.         $resp["token"] = $decoded;
  269.         $resp["object"] =  $responseObjects;
  270.         $json $serializer->serialize($resp'json');
  271.         $response = new JsonResponse($json200, [], true);
  272.         return $response;
  273.     }
  274.     #[Route('/webService/getMissions'name'getMissions')]
  275.     public function getMissions(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  276.     JWTEncoderInterface $jwtManager,BaseService $baseService): JsonResponse
  277.     {
  278.         $tokenJWT "";
  279.         $codeStatut "ERROR";
  280.         $response "";
  281.         $responseObjects = array();
  282.         
  283.         try 
  284.         {
  285.             
  286.             $jwt $request->headers->get('Authorization');
  287.             $jwt substr($jwt7);
  288.             $decoded $jwtManager->decode($jwt);
  289.     
  290.             $id $decoded['userId'];
  291.             
  292.             $chckAccess $baseService->RoleMobile(82,$id);
  293.     
  294.             if($chckAccess == 0){
  295.                 $codeStatut "ERROR-ACCES";
  296.                 $response "erreur access";
  297.         
  298.             }
  299.             else if ($chckAccess == 2)
  300.             {
  301.                 $codeStatut "ERROR-ACCES";
  302.                 $response "erreur access";
  303.     
  304.             }
  305.     
  306.             if($response == '')
  307.             {
  308.     
  309.                 
  310.                 $jwt $request->headers->get('Authorization');
  311.                 $jwt substr($jwt7);
  312.                 $decoded $jwtManager->decode($jwt);
  313.     
  314.                 $id $decoded['userId'];
  315.     
  316.                 $missions = [];
  317.                 $Allmissions $entityManager->getRepository(Mission::class)->findBy(['idAgent' => $id"etatMiss" => [1,2]]);
  318.                 
  319.                 foreach ($Allmissions as $mission) {
  320.                     $marche $entityManager->getRepository(Marche::class)->find($mission->getIdMarche());
  321.                 
  322.                     if(!empty($mission->getImagArti()))
  323.                     {
  324.                         $filePath $this->getParameter('kernel.project_dir') . '/public/assets/images/IconsMarche/' $mission->getImagArti();
  325.                     }
  326.                     else
  327.                     {
  328.                         $filePath $this->getParameter('kernel.project_dir') . '/public/assets/images/IconsMarche/main.jpg';
  329.     
  330.                     }
  331.     
  332.                     $file = new File($filePath);    
  333.     
  334.                     if ($marche) {
  335.                         $missionData = [
  336.                             'marchename' => $marche->getNumeMarc(),
  337.                             'id' => $mission->getId(),
  338.                             'etatMiss' => $mission->getEtatMiss(),
  339.                             'NumeMiss' => $mission->getNumeMiss(),
  340.                             'dateCreation' => $mission->getDateCreation(),
  341.                             'dateFin' => $mission->getDateFin(),
  342.                             'code' => $mission->getCodeArti(),
  343.                             'image' => $file,
  344.                             'titre' => $mission->getTitre(),
  345.                             'marcheTitle' => $marche->getObjeMarc(), 
  346.                         ];
  347.                 
  348.                         // Add the mission data to the $missions array
  349.                         $missions[] = $missionData;
  350.                     }
  351.                 }
  352.                 
  353.                 $responseObjects $missions;
  354.     
  355.                 $codeStatut "OK";
  356.             
  357.                     
  358.     
  359.                 
  360.     
  361.             }
  362.     
  363.             
  364.         
  365.         }
  366.         catch(\Exception $e
  367.         {
  368.             $response $e->getMessage();
  369.             $codeStatut "ERROR-EXE";
  370.         }
  371.         $resp["codeStatut"] = $codeStatut;
  372.         $resp["message"] = $response;
  373.         $resp["token"] = $tokenJWT;
  374.         $resp["object"] =  $responseObjects;
  375.         $json $serializer->serialize($resp'json');
  376.         $jsonResponse = new JsonResponse($json200, [], true);
  377.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  378.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  379.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  380.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  381.         return $jsonResponse;
  382.     }
  383.     #[Route('/webService/getDetailsMissions'name'getDetailsMissions')]
  384.     public function getDetailsMissions(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  385.     JWTEncoderInterface $jwtManager): JsonResponse
  386.     {
  387.         $tokenJWT "";
  388.         $codeStatut "ERROR";
  389.         $response "";
  390.         $responseObjects = array();
  391.         try 
  392.         {
  393.             $jwt $request->headers->get('Authorization');
  394.             $jwt substr($jwt7);
  395.             $decoded $jwtManager->decode($jwt);
  396.             $id $decoded['userId'];
  397.             $idMission =$request->get('id');
  398.             $details $entityManager->getRepository(DetailMission::class)->findBy(array('idMission' => $idMission));
  399.             $responseObjects $details;
  400.             $codeStatut "OK";
  401.             $codeStatut "OK";
  402.         }
  403.         catch(\Exception $e
  404.         {
  405.             $response "une erreur s'est produite!";
  406.             $codeStatut "ERROR-EXE";
  407.         }
  408.         $resp["codeStatut"] = $codeStatut;
  409.         $resp["message"] = $response;
  410.         $resp["token"] = $tokenJWT;
  411.         $resp["object"] =  $responseObjects;
  412.         $json $serializer->serialize($resp'json');
  413.         $jsonResponse = new JsonResponse($json200, [], true);
  414.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  415.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  416.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  417.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  418.         return $jsonResponse;
  419.     }
  420.     #[Route('/webService/getFormDetail'name'getFormDetail')]
  421.     public function getFormDetail(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  422.     JWTEncoderInterface $jwtManager,MissionRepository $missionRepository,StockMissionRepository $stockMissionRepository): JsonResponse
  423.     {
  424.         $tokenJWT "";
  425.         $codeStatut "ERROR";
  426.         $response "";
  427.         $responseObjects = array();
  428.         try 
  429.         {
  430.             $jwt $request->headers->get('Authorization');
  431.             $jwt substr($jwt7);
  432.             $decoded $jwtManager->decode($jwt);
  433.             $id $decoded['userId'];
  434.             $idDetail =$request->get('id');
  435.             $detail $entityManager->getRepository(DetailMission::class)->find($idDetail);
  436.             if($detail)
  437.             {
  438.                 $stockUtilise $entityManager->getRepository(StockDetailFichier::class)->findBy(array("idDetail" => $detail->getIdDetail()));
  439.                 $mission $entityManager->getRepository(Mission::class)->find($detail->getIdMission());
  440.                 $stock $stockMissionRepository->getStock($detail->getIdMission());
  441.                 $data $missionRepository->getForm($detail->getIdDetail());
  442.                 $files = [];
  443.                 $images $entityManager->getRepository(Images::class)->findBy(array("idDetailFichier" => $detail->getIdDetail()));
  444.                 foreach($images as $image)
  445.                 {
  446.                     $filePath $this->getParameter('kernel.project_dir') . '/public' $image->getUrlImage();
  447.                     $file = new File($filePath);
  448.                     $toSend['id'] = $image->getId();
  449.                     $toSend['file'] = $file;
  450.                     $files[] = $toSend;
  451.                 }
  452.                 $diffs $entityManager->getRepository(DifficulteTechnique::class)->findBy(['idMarche' => [$mission->getIdMarche(), 0]]);
  453.                 $responseObjects["detail"] = $detail;
  454.                 $responseObjects["form"] = $data;
  455.                 $responseObjects["images"] = $files;
  456.                 $responseObjects["stock"] = $stock;
  457.                 $responseObjects["stockUtilise"] = $stockUtilise;
  458.                 $responseObjects["difficultes"] = $diffs;
  459.                 $response "OK";
  460.                 $codeStatut "OK";
  461.     
  462.             }
  463.             else
  464.             {
  465.                 $codeStatut "ERROR-DET";
  466.                 $response "Desolé, ce detail est introuvable !!";
  467.             }
  468.         }
  469.         catch(\Exception $e
  470.         {
  471.             $codeStatut "ERROR-EXE";
  472.             $response $e->getMessage();
  473.         }
  474.         $resp["codeStatut"] = $codeStatut;
  475.         $resp["message"] = $response;
  476.         $resp["token"] = $tokenJWT;
  477.         $resp["object"] =  $responseObjects;
  478.         $json $serializer->serialize($resp'json');
  479.         $jsonResponse = new JsonResponse($json200, [], true);
  480.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  481.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  482.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  483.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  484.         return $jsonResponse;
  485.     }
  486.     #[Route('/webService/sendFormData'name'sendFormData')]
  487.     public function sendFormData(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  488.     JWTEncoderInterface $jwtManager): JsonResponse
  489.     {
  490.         $tokenJWT "";
  491.         $codeStatut "ERROR";
  492.         $response "";
  493.         $responseObjects = array();
  494.         $date = new \DateTime();
  495.         try 
  496.         {
  497.             $jwt $request->headers->get('Authorization');
  498.             $jwt substr($jwt7);
  499.             $decoded $jwtManager->decode($jwt);
  500.             $idUser $decoded['userId'];
  501.             $id $request->get('id');
  502.             $formJson $request->get('form');
  503.             $form json_decode($formJsontrue);
  504.             $stockJson $request->get('stockUtilise');
  505.             $stock json_decode($stockJsontrue);
  506.             $longitude $request->get('longitude');
  507.             $latitude $request->get('latitude');
  508.             $detailMission $entityManager->getRepository(DetailMission::class)->find($id);
  509.             if($detailMission)
  510.             {
  511.     
  512.                 if($longitude == "" || $latitude == "")
  513.                 {
  514.                     $codeStatut "ERROR-GPS";
  515.                     $response "Veuillez activer le GPS pour obtenir les points de localisation";
  516.                 }
  517.                 else
  518.                 {
  519.                     foreach ($form as $formItem) {
  520.                         $id $formItem['id'];
  521.                         $valueInfo $formItem['value_info'];
  522.             
  523.                         // Retrieve InfosDetailFicher entity by id
  524.                         $infosDetailFicher $entityManager->getRepository(InfosDetailFichier::class)->find($id);
  525.             
  526.                         if ($infosDetailFicher) {
  527.                             // Update the valueInfo property
  528.                             $infosDetailFicher->setValueInfo($valueInfo);
  529.             
  530.                             // Persist the changes to the database
  531.                             $entityManager->persist($infosDetailFicher);
  532.                         }
  533.                     }
  534.     
  535.                     $detailFichier $entityManager->getRepository(DetailFichier::class)->find($infosDetailFicher->getIdDetail());
  536.     
  537.                     $images $entityManager->getRepository(Images::class)->findBy(array("idDetailFichier" => $detailMission->getIdDetail()));
  538.                     foreach($images as $image)
  539.                     {
  540.                         $entityManager->remove($image);
  541.                     }
  542.             
  543.                     $imageFolder $this->getParameter('kernel.project_dir') . '/public/assets/imagesMissions/';
  544.                 
  545.                     for ($i 0$request->files->has("capturedPhoto$i"); $i++) {
  546.         
  547.                         $file $request->files->get("capturedPhoto$i");
  548.                         
  549.                         // Generate a unique filename
  550.                         $filename md5(uniqid()) . '.' $file->getClientOriginalExtension();
  551.                         
  552.                         // Move the file to the target directory
  553.                         $file->move($imageFolder$filename);
  554.                         
  555.                         // Create a new Image object
  556.                         $image = new Images();
  557.                         $image->setUrlImage('/assets/imagesMissions/' $filename); // Assuming the path is relative to the public directory
  558.                         $image->setIdDetailFichier($detailMission->getIdDetail());
  559.                         $image->setIdFichier($infosDetailFicher->getIdFichier());
  560.         
  561.                         // Persist the Image object to the database
  562.                         $entityManager->persist($image);
  563.         
  564.                     }
  565.                     foreach ($stock as $article) {
  566.                                
  567.                         $stockMission $entityManager->getRepository(StockMission::class)->findOneBy(array("idMission" => $detailMission->getIdMission(),"idPiece" => $article['idPiec']));
  568.                         if($stockMission)
  569.                         {
  570.                             $qte $stockMission->getQte();
  571.                             $stockDetail $entityManager->getRepository(StockDetailFichier::class)->findOneBy(array("idDetail" => $detailMission->getIdDetail(),"idPiece" => $article['idPiec']));
  572.                             if($stockDetail)
  573.                             {
  574.                                 $qte $qte+$stockDetail->getQte();
  575.                                 $entityManager->remove($stockDetail);
  576.                             }
  577.                             if( $article['qte'] > 0)
  578.                             {
  579.                                 $newQte $qte $article['qte'];
  580.                                 if($newQte>= 0)
  581.                                 {
  582.                                     $stockMission->setQte($newQte);
  583.                                     $detailStock = new StockDetailFichier();
  584.                                     $detailStock->setIdDetail($detailMission->getIdDetail());
  585.                                     $detailStock->setIdMission($detailMission->getIdMission());
  586.                                     $detailStock->setIdPiece($article['idPiec']);
  587.                                     $detailStock->setQte($article['qte']);
  588.                                     $detailStock->setDateCreation(new \DateTime());
  589.                                     $entityManager->persist($detailStock);
  590.                                     $entityManager->flush();
  591.                                 }
  592.                             }
  593.                             
  594.                         }
  595.                     }
  596.     
  597.                     $detailFichier->setEtatDeta(2);
  598.                     $detailMission->setDateFin($date);
  599.                     $detailFichier->setLongitude($longitude);
  600.                     $detailFichier->setLatitude($latitude);
  601.                     $detailMission->setLongitude($longitude);
  602.                     $detailMission->setLatitude($latitude);
  603.                     $detailMission->setEtatDeta(1);
  604.                     
  605.                      $date = new \DateTime();
  606.                     $formattedDate $date->format('Y-m-d H:i:s');
  607.                     $sql='UPDATE `infos_detail_fichier` d SET  d.`value_info`=:value where d.id_detail = :idDetail and  d.id_info  in (select i.id from infos_model_fichier i where i.type_info = :idInfo) ';
  608.                     $stmt $this->conn->prepare($sql);
  609.                     $stmt->bindValue(":idDetail",$detailMission->getIdDetail());
  610.                     $stmt->bindValue(":value",$formattedDate);
  611.                     $stmt->bindValue(":idInfo",7);
  612.                     $stmt $stmt->executeQuery();
  613.                     
  614.                     $detailsMissionNoCompelt $entityManager->getRepository(DetailMission::class)->findBy(array("idMission" => $detailMission->getIdMission(),"etatDeta" => 0) );
  615.                     if(count($detailsMissionNoCompelt) <= 1)
  616.                     {
  617.                         $mission $entityManager->getRepository(Mission::class)->find($detailMission->getIdMission());
  618.                         $mission->setEtatMiss(2);
  619.                         $stockMission $entityManager->getRepository(StockMission::class)->findBy(array("idMission" => $mission->getId()));
  620.                         foreach($stockMission as $stock)
  621.                         {
  622.                             if($stock->getQte() > 0)
  623.                             {
  624.                                 $mouvement = new MouvementStock();
  625.                                 $mouvement->setIdPiec($stock->getIdPiece());
  626.                                 $mouvement->setDateMouv(new \DateTime());
  627.                                 $mouvement->setToStock($stock->getFromStock());
  628.                                 $mouvement->setQte($stock->getQte());
  629.                                 $mouvement->setFromStock(-1);
  630.                                 $mouvement->setMotifMouv('Retroure de stock mission');
  631.                                 $mouvement->setEtatMouv(0);
  632.                                 $entityManager->persist($mouvement);
  633.                                 $entityManager->flush();
  634.                 
  635.                                 if($stock->getFromStock() == 0)
  636.                                 {
  637.                                     $article $entityManager->getRepository(Piece::class)->find($stock->getIdPiece());
  638.                                     $inStokc $article->getInStock();
  639.                                     $qteArticle $inStokc $stock->getQte();
  640.                                     $article->setInStock($qteArticle);
  641.                                 }
  642.                                 else
  643.                                 {
  644.                                     $stockR = new StockReception();
  645.                                     $stockR->setIdBure($stock->getFromStock());
  646.                                     $stockR->setIdPiec($stock->getIdPiece());
  647.                                     $stockR->setQte($stock->getQte());
  648.                                     $stockR->setIdMouv($mouvement->getId());
  649.                                     $entityManager->persist($stockR);
  650.                 
  651.                                 }
  652.                             }
  653.                         }       
  654.         
  655.                     }
  656.         
  657.                     $entityManager->flush();
  658.                     $response "OK";
  659.                     $codeStatut "OK";
  660.                 }
  661.                 
  662.             }
  663.             else
  664.             {
  665.                 $codeStatut "ERROR-DET";
  666.                 $response "Desolé, ce detail de mission est introuvable !!";
  667.     
  668.             }
  669.         }
  670.         catch(\Exception $e
  671.         {
  672.             $codeStatut "ERROR-EXE";
  673.             $response $e->getMessage();
  674.         }
  675.         $resp["codeStatut"] = $codeStatut;
  676.         $resp["message"] = $response;
  677.         $resp["token"] = $tokenJWT;
  678.         $resp["object"] =  $responseObjects;
  679.         $json $serializer->serialize($resp'json');
  680.         $jsonResponse = new JsonResponse($json200, [], true);
  681.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  682.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  683.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  684.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  685.         return $jsonResponse;
  686.     }
  687.     #[Route('/webService/sendFormDataDeff'name'sendFormDataDeff')]
  688.     public function sendFormDataDeff(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  689.     JWTEncoderInterface $jwtManager): JsonResponse
  690.     {
  691.         $tokenJWT "";
  692.         $codeStatut "ERROR";
  693.         $response "";
  694.         $responseObjects = array();
  695.         try 
  696.         {
  697.             $jwt $request->headers->get('Authorization');
  698.             $jwt substr($jwt7);
  699.             $decoded $jwtManager->decode($jwt);
  700.             $idUser $decoded['userId'];
  701.             $id $request->get('id');
  702.             $defTech $request->get('defTech');
  703.             $observation $request->get('observation');
  704.             $longitude $request->get('longitude');
  705.             $latitude $request->get('latitude');
  706.             $detailMission $entityManager->getRepository(DetailMission::class)->find($id);
  707.             if($detailMission)
  708.             {
  709.                 if($longitude == "" || $latitude == "")
  710.                 {
  711.                     $codeStatut "ERROR-GPS";
  712.                     $response "Veuillez activer le GPS pour obtenir les points de localisation";
  713.                 }
  714.                 else
  715.                 {
  716.                     $detailFichier $entityManager->getRepository(DetailFichier::class)->find($detailMission->getIdDetail());
  717.                     $detailMission->setDeffTech($defTech);
  718.                     $detailMission->setObseDeff($observation);
  719.     
  720.             
  721.                     $images $entityManager->getRepository(Images::class)->findBy(array("idDetailFichier" => $detailMission->getIdDetail()));
  722.                     foreach($images as $image)
  723.                     {
  724.                         $entityManager->remove($image);
  725.                     }
  726.                     $imageFolder $this->getParameter('kernel.project_dir') . '/public/assets/imagesMissions/';
  727.                 
  728.                     for ($i 0$request->files->has("capturedPhoto$i"); $i++){
  729.         
  730.                         $file $request->files->get("capturedPhoto$i");
  731.                         
  732.                         // Generate a unique filename
  733.                         $filename md5(uniqid()) . '.' $file->getClientOriginalExtension();
  734.                         
  735.                         // Move the file to the target directory
  736.                         $file->move($imageFolder$filename);
  737.                         
  738.                         // Create a new Image object
  739.                         $image = new Images();
  740.                         $image->setUrlImage('/assets/imagesMissions/' $filename); // Assuming the path is relative to the public directory
  741.                         $image->setIdDetailFichier($detailFichier->getId());
  742.                         $image->setIdFichier($detailFichier->getIdFichier());
  743.         
  744.                         // Persist the Image object to the database
  745.                         $entityManager->persist($image);
  746.         
  747.                     }
  748.     
  749.                     $detailFichier->setEtatDeta(2);
  750.                     $detailMission->setDateFin(new \DateTime());
  751.                     $detailFichier->setLongitude($longitude);
  752.                     $detailFichier->setLatitude($latitude);
  753.                     $detailMission->setLongitude($longitude);
  754.                     $detailMission->setLatitude($latitude);
  755.                     $detailMission->setEtatDeta(1);
  756.                     
  757.                      $date = new \DateTime();
  758.                     $formattedDate $date->format('Y-m-d H:i:s');
  759.                     $sql='UPDATE `infos_detail_fichier` d SET  d.`value_info`=:value where d.id_detail = :idDetail and  d.id_info  in (select i.id from infos_model_fichier i where i.type_info = :idInfo) ';
  760.                     $stmt $this->conn->prepare($sql);
  761.                     $stmt->bindValue(":idDetail",$detailMission->getIdDetail());
  762.                     $stmt->bindValue(":value",$formattedDate);
  763.                     $stmt->bindValue(":idInfo",7);
  764.                     $stmt $stmt->executeQuery();
  765.         
  766.                     $detailsMissionNoCompelt $entityManager->getRepository(DetailMission::class)->findBy(array("idMission" => $detailMission->getIdMission(),"etatDeta" => 0) );
  767.                     if(count($detailsMissionNoCompelt) <= 1)
  768.                     {
  769.                         $mission $entityManager->getRepository(Mission::class)->find($detailMission->getIdMission());
  770.                         $mission->setEtatMiss(2);
  771.                         $stockMission $entityManager->getRepository(StockMission::class)->findBy(array("idMission" => $mission->getId()));
  772.                         foreach($stockMission as $stock)
  773.                         {
  774.                             if($stock->getQte() > 0)
  775.                             {
  776.                                 $mouvement = new MouvementStock();
  777.                                 $mouvement->setIdPiec($stock->getIdPiece());
  778.                                 $mouvement->setDateMouv(new \DateTime());
  779.                                 $mouvement->setToStock($stock->getFromStock());
  780.                                 $mouvement->setQte($stock->getQte());
  781.                                 $mouvement->setFromStock(-1);
  782.                                 $mouvement->setMotifMouv('Retroure de stock mission');
  783.                                 $mouvement->setEtatMouv(0);
  784.                                 $entityManager->persist($mouvement);
  785.                                 $entityManager->flush();
  786.                 
  787.                                 if($stock->getFromStock() == 0)
  788.                                 {
  789.                                     $article $entityManager->getRepository(Piece::class)->find($stock->getIdPiece());
  790.                                     $inStokc $article->getInStock();
  791.                                     $qteArticle $inStokc $stock->getQte();
  792.                                     $article->setInStock($qteArticle);
  793.                                 }
  794.                                 else
  795.                                 {
  796.                                     $stockR = new StockReception();
  797.                                     $stockR->setIdBure($stock->getFromStock());
  798.                                     $stockR->setIdPiec($stock->getIdPiece());
  799.                                     $stockR->setQte($stock->getQte());
  800.                                     $stockR->setIdMouv($mouvement->getId());
  801.                                     $entityManager->persist($stockR);
  802.                 
  803.                                 }
  804.                             }
  805.                         }       
  806.         
  807.                     }
  808.                     $entityManager->flush();
  809.                     $response "OK";
  810.                     $codeStatut "OK";
  811.                 }
  812.                 
  813.             }
  814.             else
  815.             {
  816.                 $codeStatut "ERROR-DET";
  817.                 $response "Desolé, ce detail de mission est introuvable !!";
  818.     
  819.             }
  820.                 
  821.         }
  822.         catch(\Exception $e
  823.         {
  824.             $codeStatut "ERROR-EXE";
  825.             $response "une erreur s'est produite!";
  826.         }
  827.         $resp["codeStatut"] = $codeStatut;
  828.         $resp["message"] = $response;
  829.         $resp["token"] = $tokenJWT;
  830.         $resp["object"] =  $responseObjects;
  831.         $json $serializer->serialize($resp'json');
  832.         $jsonResponse = new JsonResponse($json200, [], true);
  833.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  834.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  835.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  836.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  837.         return $jsonResponse;
  838.     }
  839.     #[Route('/webService/getTaches'name'getTachesWs')]
  840.     public function getTaches(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  841.      UtilisateurRepository $repoUser,TacheRepository $tacheRepository,JWTEncoderInterface $jwtManager BaseService $baseService): JsonResponse
  842.     {
  843.         $tokenJWT "";
  844.         $codeStatut "ERROR";
  845.         $response "";
  846.         $responseObjects = array();
  847.         $tachesWithSousTaches = [];
  848.         $affectationUser false;
  849.         $affectationAjoutUser false;
  850.         $dataUsers = [];
  851.         
  852.         
  853.         
  854.         try 
  855.         {
  856.             $jwt $request->headers->get('Authorization');
  857.             $jwt substr($jwt7);
  858.             $decoded $jwtManager->decode($jwt);
  859.     
  860.             $id $decoded['userId'];
  861.             $user $entityManager->getRepository(Utilisateur::class)->find($id);
  862.     
  863.             $chckAccess $baseService->RoleMobile(90,$id);
  864.             if($chckAccess == 0){
  865.                 $codeStatut "ERROR-ACCES";
  866.                 $response "erreur access";
  867.             }
  868.             else if ($chckAccess == 2)
  869.             {
  870.                 $codeStatut "ERROR-ACCES";
  871.                 $response "erreur access";
  872.     
  873.             }
  874.             $dataUsers $repoUser->getUsersBureau2($user->getId());
  875.             if($response == '')
  876.             {
  877.                 
  878.                 $jwt $request->headers->get('Authorization');
  879.                 $jwt substr($jwt7);
  880.                 $decoded $jwtManager->decode($jwt);
  881.     
  882.                 $id $decoded['userId'];
  883.                 $taches $tacheRepository->getTacheUser($id,null);
  884.                 foreach ($taches as $t) {
  885.                     // Use findBy to get all SousTaches for each Tache
  886.                     $sousTaches $entityManager->getRepository(SousTache::class)->findBy(['idTache' => $t->getId()]);
  887.         
  888.                     // Merge Tache with associated SousTaches
  889.                     $tachesWithSousTaches[] = [
  890.                         'tache' => $t,
  891.                         'sousTaches' => $sousTaches,
  892.                     ];
  893.                 }        
  894.                 $dataUsers $repoUser->getUsersBureau2($user->getId());
  895.                 $responseObjects $tachesWithSousTaches;
  896.                 $codeStatut "OK";
  897.                
  898.                 
  899.             }
  900.              
  901.             $affectationUser true;
  902.             if($user->getTypeUtil() != 0){
  903.                 $chckAccess $baseService->RoleMobile(126,$id);
  904.                 if($chckAccess == 1  ){
  905.                      $codeStatut "OK";
  906.                     $dataUsers $repoUser->getUsersBureau2($user->getId());
  907.                 }else{
  908.                     $affectationUser false;
  909.                 }
  910.             }
  911.             $affectationAjoutUser true;
  912.             if($user->getTypeUtil() != 0){
  913.                 $chckAccess =  $baseService->RoleMobile(91,$id); 
  914.                 if($chckAccess != 1){
  915.                     
  916.                     $affectationAjoutUser false;
  917.                 }else{
  918.                     $codeStatut "OK";
  919.                 }
  920.             }
  921.             
  922.             
  923.             
  924.         }
  925.         catch(\Exception $e
  926.         {
  927.             $response $e->getMessage();
  928.             $codeStatut "ERROR-EXE";
  929.         }
  930.         $resp["codeStatut"] = $codeStatut;
  931.         $resp["message"] = $baseService->RoleMobile(126,$id);;
  932.         $resp["token"] = $tokenJWT;
  933.         $resp["object"] =  $responseObjects;
  934.         $resp["data"] =  $dataUsers;
  935.         $resp["affectationUser"] = $affectationUser;
  936.         $resp["affectationAjoutUser"] =  $affectationAjoutUser;
  937.         
  938.         
  939.         $json $serializer->serialize($resp'json');
  940.         $jsonResponse = new JsonResponse($json200, [], true);
  941.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  942.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  943.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  944.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  945.         return $jsonResponse;
  946.     }
  947.     
  948.     #[Route('/webService/getTache/{id}'name'getOneTache')]
  949.     public function getTache(Request $requestEntityManagerInterface $entityManagerJWTEncoderInterface $jwtManager ,BaseService $baseService SerializerInterface $serializer$id): Response
  950.     {
  951.         $response "";
  952.         $codeStatut "";
  953.         $data = [];
  954.         
  955.         try {
  956.               // Get Tache entity
  957.                    $jwt $request->headers->get('Authorization');
  958.             $jwt substr($jwt7);
  959.             $decoded $jwtManager->decode($jwt);
  960.     
  961.             $idUser $decoded['userId'];
  962.             $chckAccess $baseService->RoleMobile(90,$idUser);
  963.             if($chckAccess == 0){
  964.                 $codeStatut "ERROR-ACCES";
  965.                 $response "erreur access";
  966.             }{
  967.                 $tache $entityManager->getRepository(Tache::class)->find($id);
  968.     
  969.                 if (!$tache) {
  970.                     return new JsonResponse(['error' => 'Tache not found.'], 404);
  971.                 }
  972.             
  973.                 // Get related SousTache entities
  974.                 $sousTaches $entityManager->getRepository(SousTache::class)->findByIdTache($id);
  975.                 $tacheUsers $entityManager->getRepository(TacheUtilisateur::class)->findByIdTach($id);
  976.                 $tache_pj $entityManager->getRepository(TachePj::class)->findBy(["id_tache"=>$id]);
  977.         
  978.                 // Create an array with information about both entities
  979.                 $data = [
  980.                     'tache' => $tache,
  981.                     'sousTaches' => $sousTaches,
  982.                     'users' => $tacheUsers,
  983.                     'taches_pj'=>$tache_pj
  984.                 ];
  985.                 
  986.                 $codeStatut "OK";
  987.                 // Serialize the array to JSON
  988.                 $jsonData $serializer->serialize($data'json');
  989.         
  990.                 // Return the JSON response
  991.             }
  992.         }  catch(\Exception $e
  993.         {
  994.             $response $e->getMessage();
  995.             $codeStatut "ERROR-EXE";
  996.         }
  997.         $resp["codeStatut"] = $codeStatut;
  998.         $resp["message"] = $response;
  999.         $resp["object"] =  $data;
  1000.         
  1001.         $json $serializer->serialize($resp'json');
  1002.         $jsonResponse = new JsonResponse($json200, [], true);
  1003.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  1004.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  1005.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  1006.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  1007.         return $jsonResponse;
  1008.     }
  1009.     #[Route('/webService/setEtatTache'name'setEtatTache')]
  1010.     public function setEtatTache(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  1011.     JWTEncoderInterface $jwtManager): JsonResponse
  1012.     {
  1013.         $tokenJWT "";
  1014.         $codeStatut "ERROR";
  1015.         $response "";
  1016.         $responseObjects = array();
  1017.         try 
  1018.         {
  1019.             $jwt $request->headers->get('Authorization');
  1020.             $jwt substr($jwt7);
  1021.             $decoded $jwtManager->decode($jwt);
  1022.             $id $decoded['userId'];
  1023.             $idTache $request->get('id');
  1024.             $etat = (int)$request->get('etat');
  1025.             $tache $entityManager->getRepository(tache::class)->find($idTache);
  1026.             if($tache)
  1027.             {
  1028.                 $tache->setEtatTach($etat);
  1029.                 $entityManager->flush();
  1030.                 $codeStatut "OK";
  1031.                 $response "ok";
  1032.             }
  1033.             else
  1034.             {
  1035.                 $codeStatut "ERROR-TAC";
  1036.                 $response "Desolé, cette tache est introuvable !!";
  1037.             }
  1038.         }
  1039.         catch(\Exception $e
  1040.         {
  1041.             $response $e->getMessage();
  1042.             $codeStatut "ERROR-EXE";
  1043.         }
  1044.         $resp["codeStatut"] = $codeStatut;
  1045.         $resp["message"] = $response;
  1046.         $resp["token"] = $tokenJWT;
  1047.         $resp["object"] =  $responseObjects;
  1048.         $json $serializer->serialize($resp'json');
  1049.         $jsonResponse = new JsonResponse($json200, [], true);
  1050.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  1051.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  1052.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  1053.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  1054.         return $jsonResponse;
  1055.     }
  1056.     #[Route('/webService/sendDepense'name'sendDepense')]
  1057.     public function sendDepense(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  1058.     JWTEncoderInterface $jwtManager,BaseService $baseService): JsonResponse
  1059.     {
  1060.         $tokenJWT "";
  1061.         $codeStatut "ERROR";
  1062.         $response "";
  1063.         $responseObjects = array();
  1064.         
  1065.         
  1066.         try 
  1067.         {
  1068.             $jwt $request->headers->get('Authorization');
  1069.             $jwt substr($jwt7);
  1070.             $decoded $jwtManager->decode($jwt);
  1071.     
  1072.             $id $decoded['userId'];
  1073.     
  1074.             $chckAccess $baseService->RoleMobile(35,$id);
  1075.             if($chckAccess == 0){
  1076.                 $codeStatut "ERROR-ACCES";
  1077.                 $response "erreur access";
  1078.         
  1079.             }
  1080.             else if ($chckAccess == 2)
  1081.             {
  1082.                 $codeStatut "ERROR-ACCES";
  1083.                 $response "erreur access";
  1084.     
  1085.             }
  1086.     
  1087.     
  1088.             if($response == '')
  1089.             {
  1090.                
  1091.         
  1092.                     $jwt $request->headers->get('Authorization');
  1093.                     $jwt substr($jwt7);
  1094.                     $decoded $jwtManager->decode($jwt);
  1095.                     $idUser $decoded['userId'];
  1096.         
  1097.         
  1098.                     $dataJson $request->get('data');
  1099.                     $data json_decode($dataJsontrue);
  1100.                     $file $request->files->get("capturedPhoto");
  1101.         
  1102.                     $totalHt str_replace(',''.'$data['totalHt']);
  1103.                     $totalTtc str_replace(',''.'$data['totalTtc']);
  1104.                     $charge = new Charge();
  1105.                     $charge->setTitrChar($data['objet']);
  1106.                     $charge->setDateCreation(new \DateTime($data['dateCreation']));
  1107.                     $charge->setIdAttCha($data['categorie']);
  1108.                     $charge->setTotalHt$totalHt);
  1109.                     $charge->setTotalTtc($totalTtc);
  1110.                     $charge->setObservation($data['observation']);
  1111.                     $charge->setIdFour(0);
  1112.                     $charge->setIdBure(0);
  1113.                     $charge->setModePaie($data['modePaiement']);
  1114.                     $charge->setIdAgent($id);
  1115.                     $charge->setIdUtil($idUser);
  1116.                     $charge->setIdMarche($data['idMarche']);
  1117.                     $imageFolder $this->getParameter('kernel.project_dir') . '/public/assets/images/Charges/';
  1118.                                 
  1119.                     // Generate a unique filename
  1120.                     $filename md5(uniqid()) . '.' $file->getClientOriginalExtension();
  1121.                     
  1122.                     // Move the file to the target directory
  1123.                     $file->move($imageFolder$filename);
  1124.         
  1125.                     $charge->setImg('/assets/images/Charges/' $filename);
  1126.         
  1127.                     // Persist the Charge entity and flush it to the database
  1128.                     $entityManager->persist($charge);
  1129.                     $entityManager->flush();
  1130.         
  1131.                     $response "OK";
  1132.                     $codeStatut "OK";
  1133.         
  1134.                 
  1135.     
  1136.             }
  1137.             
  1138.         }
  1139.         catch(\Exception $e
  1140.         {
  1141.             $response $e->getMessage();
  1142.             $codeStatut "ERROR-EXE";
  1143.         }
  1144.         
  1145.        
  1146.         $resp["codeStatut"] = $codeStatut;
  1147.         $resp["message"] = $response;
  1148.         $resp["token"] = $tokenJWT;
  1149.         $resp["object"] =  $responseObjects;
  1150.         $json $serializer->serialize($resp'json');
  1151.         $jsonResponse = new JsonResponse($json200, [], true);
  1152.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  1153.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  1154.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  1155.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  1156.         return $jsonResponse;
  1157.     }
  1158.     #[Route('/webService/getDepenses'name'getDepenses')]
  1159.     public function getDepenses(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  1160.     JWTEncoderInterface $jwtManager,BaseService $baseService): JsonResponse
  1161.     {
  1162.         $tokenJWT "";
  1163.         $codeStatut "ERROR";
  1164.         $response "";
  1165.         $responseObjects = array();
  1166.         
  1167.         
  1168.         try 
  1169.         {
  1170.         
  1171.             $jwt $request->headers->get('Authorization');
  1172.             $jwt substr($jwt7);
  1173.             $decoded $jwtManager->decode($jwt);
  1174.     
  1175.             $id $decoded['userId'];
  1176.     
  1177.             $chckAccess $baseService->RoleMobile(34,$id);
  1178.             if($chckAccess == 0){
  1179.                 $codeStatut "ERROR-ACCES";
  1180.                 $response "erreur access";
  1181.         
  1182.             }
  1183.             else if ($chckAccess == 2)
  1184.             {
  1185.                 $codeStatut "ERROR-ACCES";
  1186.                 $response "erreur access";
  1187.     
  1188.             }
  1189.     
  1190.             if($response == '')
  1191.             {
  1192.                 
  1193.         
  1194.                     $jwt $request->headers->get('Authorization');
  1195.                     $jwt substr($jwt7);
  1196.                     $decoded $jwtManager->decode($jwt);
  1197.         
  1198.                     $id $decoded['userId'];
  1199.         
  1200.                     $depenses $entityManager->getRepository(Charge::class)->findBy(['idAgent' => $id]);
  1201.                     $categories $entityManager->getRepository(AttributeCharge::class)->findAll();
  1202.                     $marches $entityManager->getRepository(Marche::class)->findBy(["EtatMarc" => 1]);
  1203.                     $responseObjects['depenses'] = $depenses;
  1204.                     $responseObjects['marches'] = $marches;
  1205.                     $responseObjects['categories'] = $categories;
  1206.                     $codeStatut "OK";
  1207.     
  1208.     
  1209.             }
  1210.             
  1211.         }
  1212.         catch(\Exception $e
  1213.         {
  1214.             $response $e->getMessage();
  1215.             $codeStatut "ERROR-EXE";
  1216.         }
  1217.     
  1218.         $resp["codeStatut"] = $codeStatut;
  1219.         $resp["message"] = $response;
  1220.         $resp["token"] = $tokenJWT;
  1221.         $resp["object"] =  $responseObjects;
  1222.         $json $serializer->serialize($resp'json');
  1223.         $jsonResponse = new JsonResponse($json200, [], true);
  1224.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  1225.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  1226.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  1227.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  1228.         return $jsonResponse;
  1229.     }
  1230.     #[Route('/webService/getNotifications'name'getNotifications')]
  1231.     public function getNotifications(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  1232.     JWTEncoderInterface $jwtManager,TacheRepository $tacheRepository): JsonResponse
  1233.     {
  1234.         $tokenJWT "";
  1235.         $codeStatut "ERROR";
  1236.         $response "";
  1237.         $responseObjects = array();
  1238.         try 
  1239.         {
  1240.             $jwt $request->headers->get('Authorization');
  1241.             $jwt substr($jwt7);
  1242.             $decoded $jwtManager->decode($jwt);
  1243.             $id $decoded['userId'];
  1244.             $notifications $entityManager->getRepository(Notifications::class)->findBy(array('idUser' => $id,'etat' => 1));
  1245.             $responseObjects $notifications;
  1246.             $response 'ok';
  1247.             $codeStatut "OK";
  1248.         }
  1249.         catch(\Exception $e
  1250.         {
  1251.             $response $e->getMessage();
  1252.             $codeStatut "ERROR-EXE";
  1253.         }
  1254.         $resp["codeStatut"] = $codeStatut;
  1255.         $resp["message"] = $response;
  1256.         $resp["token"] = $tokenJWT;
  1257.         $resp["object"] =  $responseObjects;
  1258.         $json $serializer->serialize($resp'json');
  1259.         $jsonResponse = new JsonResponse($json200, [], true);
  1260.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  1261.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  1262.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  1263.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  1264.         return $jsonResponse;
  1265.     }
  1266.     #[Route('/webService/setNotifLu'name'setNotifLu')]
  1267.     public function setNotifLu(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  1268.     JWTEncoderInterface $jwtManager,TacheRepository $tacheRepository): JsonResponse
  1269.     {
  1270.         $tokenJWT "";
  1271.         $codeStatut "ERROR";
  1272.         $response "";
  1273.         $responseObjects = array();
  1274.         try 
  1275.         {
  1276.             $jwt $request->headers->get('Authorization');
  1277.             $jwt substr($jwt7);
  1278.             $decoded $jwtManager->decode($jwt);
  1279.             $id $decoded['userId'];
  1280.             $from $request->get("all");
  1281.             if($from == '0')
  1282.             {
  1283.                 $notifications $entityManager->getRepository(Notifications::class)->findBy(array('idUser' => $id,'etat' => 1));
  1284.                 foreach($notifications as $notif)
  1285.                 {
  1286.                     $notif->setEtat(0);
  1287.                 }
  1288.                 $entityManager->flush();
  1289.             }
  1290.             else
  1291.             {
  1292.                 $notification $entityManager->getRepository(Notifications::class)->find($from);
  1293.                  $notification->setEtat(0);
  1294.                 
  1295.                 $entityManager->flush();
  1296.             }
  1297.             $response 'ok';
  1298.             $codeStatut "OK";
  1299.         }
  1300.         catch(\Exception $e
  1301.         {
  1302.             $response $e->getMessage();
  1303.             $codeStatut "ERROR-EXE";
  1304.         }
  1305.         $resp["codeStatut"] = $codeStatut;
  1306.         $resp["message"] = $response;
  1307.         $resp["token"] = $tokenJWT;
  1308.         $resp["object"] =  $responseObjects;
  1309.         $json $serializer->serialize($resp'json');
  1310.         $jsonResponse = new JsonResponse($json200, [], true);
  1311.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  1312.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  1313.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  1314.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  1315.         return $jsonResponse;
  1316.     }
  1317.     #[Route('/webService/removeDepense'name'removeDepense')]
  1318.     public function removeDepense(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  1319.     JWTEncoderInterface $jwtManager,TacheRepository $tacheRepository,BaseService $baseService): JsonResponse
  1320.     {
  1321.         $tokenJWT "";
  1322.         $codeStatut "ERROR";
  1323.         $response "";
  1324.         $responseObjects = array();
  1325.         
  1326.         $jwt $request->headers->get('Authorization');
  1327.         $jwt substr($jwt7);
  1328.         $decoded $jwtManager->decode($jwt);
  1329.         $id $decoded['userId'];
  1330.         
  1331.         try 
  1332.         {
  1333.             
  1334.             $chckAccess $baseService->RoleMobile(101,$id);
  1335.             if($chckAccess == 0){
  1336.                 $codeStatut "ERROR-ACCES";
  1337.                 $response "erreur access";
  1338.         
  1339.             }
  1340.             else if ($chckAccess == 2)
  1341.             {
  1342.                 $codeStatut "ERROR-ACCES";
  1343.                 $response "erreur access";
  1344.     
  1345.             }
  1346.             
  1347.     
  1348.             if($response == '')
  1349.             {
  1350.              
  1351.         
  1352.                     $jwt $request->headers->get('Authorization');
  1353.                     $jwt substr($jwt7);
  1354.                     $decoded $jwtManager->decode($jwt);
  1355.         
  1356.                     $id $request->get("id");
  1357.                     $charge $entityManager->getRepository(Charge::class)->find($id);
  1358.                     if($charge)
  1359.                     {
  1360.                         $entityManager->remove($charge);
  1361.                         $entityManager->flush();
  1362.                         $response 'ok';
  1363.                         $codeStatut "OK";
  1364.             
  1365.                     }
  1366.                     else
  1367.                     {
  1368.                         $codeStatut "ERROR-CHA";
  1369.                         $response "Desolé, cette depense est introuvable !!";
  1370.         
  1371.                     }
  1372.     
  1373.             }
  1374.         }
  1375.         catch(\Exception $e
  1376.         {
  1377.             $response $e->getMessage();
  1378.             $codeStatut "ERROR-EXE";
  1379.         }
  1380.         $resp["codeStatut"] = $codeStatut;
  1381.         $resp["message"] = $response;
  1382.         $resp["token"] = $tokenJWT;
  1383.         $resp["object"] =  $responseObjects;
  1384.         $json $serializer->serialize($resp'json');
  1385.         $jsonResponse = new JsonResponse($json200, [], true);
  1386.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  1387.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  1388.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  1389.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  1390.         return $jsonResponse;
  1391.     }
  1392.     #[Route('/webService/addPieceTache'name'addPieceTache')]
  1393.     public function addPieceTache(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  1394.     JWTEncoderInterface $jwtManager,TacheRepository $tacheRepository,BaseService $baseService): JsonResponse
  1395.     {
  1396.         $tokenJWT "";
  1397.         $codeStatut "ERROR";
  1398.         $response "";
  1399.         $responseObjects = array();
  1400.         /*$chckAccess = $baseService->RoleMobile(101,2);
  1401.         if($chckAccess == 0){
  1402.             $codeStatut = "ERROR-ACCES";
  1403.             $response = "erreur access";
  1404.     
  1405.         }
  1406.         else if ($chckAccess == 2)
  1407.         {
  1408.             $codeStatut = "ERROR-ACCES";
  1409.             $response = "erreur access";
  1410.         }*/
  1411.         
  1412.         if($response == '')
  1413.         {
  1414.             try 
  1415.             {
  1416.     
  1417.                 $jwt $request->headers->get('Authorization');
  1418.                 $jwt substr($jwt7);
  1419.                 $decoded $jwtManager->decode($jwt);
  1420.     
  1421.                 // $id = $decoded['userId'];
  1422.                 $id $request->get("id");
  1423.                 $tache $entityManager->getRepository(Tache::class)->find($id);
  1424.                 if (!$tache) {
  1425.                     $codeStatut "ERROR-TAC";
  1426.                     $response "Désolé, cette tâche est introuvable !!";
  1427.                 } else {
  1428.                     // Handle file uploads
  1429.                     $files $request->files->get('files');
  1430.                     $imageFolder $this->getParameter('kernel.project_dir') . '/public/assets/tache_pj/';
  1431.                     if ($files) {
  1432.                         foreach ($files as $file) {
  1433.                             // Generate a unique filename
  1434.                             $filename md5(uniqid()) . '.' $file->getClientOriginalExtension();
  1435.                             
  1436.                             // Move the file to the target directory
  1437.                             $file->move($imageFolder$filename);
  1438.                             $fille = new TachePj();
  1439.                             $fille->setIdUser($id);
  1440.                             $fille->setIdTache($id);
  1441.                             $fille->setUrl("/assets/tache_pj/" $filename);
  1442.                             $entityManager->persist($fille);
  1443.                             $entityManager->flush();
  1444.                         }
  1445.                         $codeStatut "OK";
  1446.                         $response "Files uploaded successfully.";
  1447.                     } else {
  1448.                         $response "No files uploaded.";
  1449.                     }
  1450.                 }
  1451.             }
  1452.             catch(\Exception $e
  1453.             {
  1454.                 $response $e->getMessage();
  1455.                 $codeStatut "ERROR-EXE";
  1456.             }
  1457.         }
  1458.         $resp["codeStatut"] = $codeStatut;
  1459.         $resp["message"] = $response;
  1460.         $resp["token"] = $tokenJWT;
  1461.         $resp["object"] =  $responseObjects;
  1462.         $json $serializer->serialize($resp'json');
  1463.         $jsonResponse = new JsonResponse($json200, [], true);
  1464.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  1465.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  1466.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  1467.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  1468.         return $jsonResponse;
  1469.     }
  1470.     #[Route('/webService/getTachePiece'name'getTachePiece')]
  1471.     public function getTachePiece(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  1472.     JWTEncoderInterface $jwtManager,TacheRepository $tacheRepository): JsonResponse
  1473.     {
  1474.         $tokenJWT "";
  1475.         $codeStatut "ERROR";
  1476.         $response "";
  1477.         $responseObjects = array();
  1478.         try 
  1479.         {
  1480.             $jwt $request->headers->get('Authorization');
  1481.             $jwt substr($jwt7);
  1482.             $decoded $jwtManager->decode($jwt);
  1483.             // $id = $decoded['userId'];
  1484.             $id $request->get("id");
  1485.             $tache $entityManager->getRepository(Tache::class)->find($id);
  1486.             if($tache)
  1487.             {
  1488.                 $responseObjects['tache'] = $tache;
  1489.                 $files = [];
  1490.                 $images $entityManager->getRepository(TachePj::class)->findBy(array('id_tache' => $id));
  1491.                 foreach($images as $image)
  1492.                 {
  1493.                     $filePath $this->getParameter('kernel.project_dir') . '/public' $image->getUrl();
  1494.                     $file = new File($filePath);
  1495.                     $toSend['id'] = $image->getId();
  1496.                     $toSend['file'] = $file;
  1497.                     $files[] = $toSend;
  1498.                 }
  1499.                 $responseObjects['files'] = $files;
  1500.                 $response 'ok';
  1501.                 $codeStatut "OK";
  1502.     
  1503.             }
  1504.         }
  1505.         catch(\Exception $e
  1506.         {
  1507.             $response $e->getMessage();
  1508.             $codeStatut "ERROR-EXE";
  1509.         }
  1510.         $resp["codeStatut"] = $codeStatut;
  1511.         $resp["message"] = $response;
  1512.         $resp["token"] = $tokenJWT;
  1513.         $resp["object"] =  $responseObjects;
  1514.         $json $serializer->serialize($resp'json');
  1515.         $jsonResponse = new JsonResponse($json200, [], true);
  1516.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  1517.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  1518.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  1519.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  1520.         return $jsonResponse;
  1521.     }
  1522.     #[Route('/webService/removePiece'name'removePiece')]
  1523.     public function removePiece(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  1524.     JWTEncoderInterface $jwtManager,TacheRepository $tacheRepository,BaseService $baseService): JsonResponse
  1525.     {
  1526.         $tokenJWT "";
  1527.         $codeStatut "ERROR";
  1528.         $response "";
  1529.         $responseObjects = array();
  1530.         /*$chckAccess = $baseService->RoleMobile(101,2);
  1531.         if($chckAccess == 0){
  1532.             $codeStatut = "ERROR-ACCES";
  1533.             $response = "erreur access";
  1534.     
  1535.         }
  1536.         else if ($chckAccess == 2)
  1537.         {
  1538.             $codeStatut = "ERROR-ACCES";
  1539.             $response = "erreur access";
  1540.         }*/
  1541.         
  1542.         if($response == '')
  1543.         {
  1544.             try 
  1545.             {
  1546.     
  1547.                 $jwt $request->headers->get('Authorization');
  1548.                 $jwt substr($jwt7);
  1549.                 $decoded $jwtManager->decode($jwt);
  1550.     
  1551.                 // $id = $decoded['userId'];
  1552.                 $id $request->get("id");
  1553.                 $piece $entityManager->getRepository(TachePj::class)->find($id);
  1554.                 if($piece)
  1555.                 {
  1556.                     if($piece->getIdUser() == $id)
  1557.                     {
  1558.                         $entityManager->remove($piece);
  1559.                         $entityManager->flush();
  1560.                         $response 'ok';
  1561.                         $codeStatut "OK";
  1562.     
  1563.                     }
  1564.                     else
  1565.                     {
  1566.                         $codeStatut "ERROR-ACC";
  1567.                         $response "Desolé, vous n'avez pas pu supprimer ce fichier !!";
  1568.     
  1569.                     }
  1570.         
  1571.                 }
  1572.                 else
  1573.                 {
  1574.                     $codeStatut "ERROR-PIE";
  1575.                     $response "Desolé, cette piece est introuvable !!";
  1576.     
  1577.                 }
  1578.                
  1579.             }
  1580.             catch(\Exception $e
  1581.             {
  1582.                 $response $e->getMessage();
  1583.                 $codeStatut "ERROR-EXE";
  1584.             }
  1585.     
  1586.         }
  1587.         $resp["codeStatut"] = $codeStatut;
  1588.         $resp["message"] = $response;
  1589.         $resp["token"] = $tokenJWT;
  1590.         $resp["object"] =  $responseObjects;
  1591.         $json $serializer->serialize($resp'json');
  1592.         $jsonResponse = new JsonResponse($json200, [], true);
  1593.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  1594.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  1595.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  1596.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  1597.         return $jsonResponse;
  1598.     }
  1599.     
  1600.     
  1601.     #[Route('/webService/syncData'name'syncData')]
  1602.     public function syncData(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  1603.     JWTEncoderInterface $jwtManager,TacheRepository $tacheRepository,BaseService $baseService): JsonResponse
  1604.     {
  1605.         
  1606.         $tokenJWT "";
  1607.         $codeStatut "ERROR";
  1608.         $response "";
  1609.         $responseObjects = array();
  1610.         try 
  1611.         {
  1612.             $jwt $request->headers->get('Authorization');
  1613.             $jwt substr($jwt7);
  1614.             $decoded $jwtManager->decode($jwt);
  1615.             $id $decoded['userId'];
  1616.             $missionsJson $request->get('missions');
  1617.             $missions json_decode($missionsJsontrue);
  1618.             $detailsJson $request->get('details');
  1619.             $details json_decode($detailsJsontrue);
  1620.             $infosJson $request->get('infos');
  1621.             $infos json_decode($infosJsontrue);
  1622.             $stockJson $request->get('stockMission');
  1623.             $stock json_decode($stockJsontrue);
  1624.             $imagesJson $request->get('images');
  1625.             $images json_decode($imagesJsontrue);
  1626.             $stockUtiliseJson $request->get('stockUtilise');
  1627.             $stockUtilise json_decode($stockUtiliseJsontrue);
  1628.             $depensesJson $request->get('depenses');
  1629.             $depenses json_decode($depensesJsontrue);
  1630.             
  1631.             
  1632.             $missToR = array();
  1633.             $detaToR = array();
  1634.             $infoToR = array();
  1635.             $imagToR = array();
  1636.             $stocToR = array();
  1637.             $stdtToR = array();
  1638.             $depeToR = array();
  1639.             
  1640.             foreach($missions as $ms)
  1641.             {
  1642.                 if ($ms["sync"] == 1) {
  1643.                 
  1644.                     $dateStr $ms["dateFin"];
  1645.                 
  1646.                     // Example: "Wed Sep 24 2025 16:57:44 GMT+0100 (UTC+01:00)"
  1647.                     $date \DateTime::createFromFormat(
  1648.                         'D M d Y H:i:s \G\M\TO'// match "Wed Sep 24 2025 16:57:44 GMT+0100"
  1649.                         $dateStr
  1650.                     );
  1651.                 
  1652.                     if (!$date) {
  1653.                         // fallback: remove the "(UTC+01:00)" part
  1654.                         $dateStr preg_replace('/\(.*\)$/'''$dateStr);
  1655.                         $date    = new \DateTime(trim($dateStr));
  1656.                     }
  1657.                 
  1658.                     $mission $entityManager->getRepository(Mission::class)->find($ms["id"]);
  1659.                     $mission->setDateFin($date);
  1660.                     $mission->setEtatMiss($ms["etatMiss"]);
  1661.                 
  1662.                     $entityManager->flush();
  1663.                     array_push($missToR$ms["id"]);
  1664.                 }
  1665.             }
  1666.             
  1667.             $responseObjects["missToR"] = $missToR;
  1668.             foreach($details as $dt)
  1669.             {
  1670.                 if($dt["sync"] == 1)
  1671.                 {
  1672.                     $detail =  $entityManager->getRepository(DetailMission::class)->find($dt["id"]);
  1673.                     
  1674.                     $dateFin $dt["dateFin"];
  1675.                     // Step 1: Remove the part in parentheses (e.g., (UTC+01:00))
  1676.                     $cleanedDateFin preg_replace('/\s\(.*\)$/'''$dateFin); // Result: "Thu Dec 05 2024 14:51:15 GMT+0100"
  1677.                     $detail->setDateFin(new \DateTime($cleanedDateFin));
  1678.                     $detail->setEtatDeta($dt["etatDeta"]);
  1679.                     $detail->setDeffTech($dt["deffTech"]);
  1680.                     $detail->setObseDeff($dt["obseDeff"]);
  1681.                     $detail->setLongitude($dt["longitude"]);
  1682.                     $detail->setLatitude($dt["latitude"]);
  1683.                     
  1684.                     $entityManager->flush();
  1685.                     array_push($detaToR$dt["id"]);
  1686.                 }
  1687.             }
  1688.             $responseObjects["detaToR"] = $detaToR;
  1689.             foreach($infos as $inf)
  1690.             {
  1691.                 if($inf["sync"] == 1)
  1692.                 {
  1693.                     $info =  $entityManager->getRepository(InfosDetailFichier::class)->find($inf["id"]);
  1694.                     $info->setValueInfo($inf["value_info"]);
  1695.                     
  1696.                     $entityManager->flush();
  1697.                     array_push($infoToR$inf["id"]);
  1698.                 }
  1699.             }
  1700.             $responseObjects["infoToR"] = $infoToR;
  1701.             foreach($stock as $s)
  1702.             {
  1703.                 if($s["sync"] == 1)
  1704.                 {
  1705.                     $stockMiss =  $entityManager->getRepository(StockMission::class)->find($s["id"]);
  1706.                     $stockMiss->setQte($s["qte"]);
  1707.                     
  1708.                     $entityManager->flush();
  1709.                     array_push($stocToR$s["id"]);
  1710.                 }
  1711.             }
  1712.             $responseObjects["stocToR"] = $stocToR;
  1713.             $imageFolder $this->getParameter('kernel.project_dir') . '/public/assets/imagesMissions/';
  1714.                 
  1715.     
  1716.             $seenIdDetailFichiers = array();
  1717.             foreach ($images as $image) {
  1718.                 $idDetailFichier $image['idDetailFichier'];
  1719.                 if (!in_array($idDetailFichier$seenIdDetailFichiers)) {
  1720.                     $seenIdDetailFichiers[] = $idDetailFichier;
  1721.                 }
  1722.             }
  1723.             
  1724.             $allImagesRelated $entityManager->getRepository(Images::class)->findBy(['idDetailFichier' => $seenIdDetailFichiers]);
  1725.             foreach ($allImagesRelated as $imR) {
  1726.                 $entityManager->remove($imR);
  1727.             }
  1728.             foreach ($images as $imageData) {
  1729.                 // Extract data
  1730.                 $base64Data $imageData['file'];
  1731.                 $idDetailFichier $imageData['idDetailFichier'];
  1732.             
  1733.                 // Remove the header from the base64 data
  1734.                 $base64Data preg_replace('/^data:image\/\w+;base64,/'''$base64Data);
  1735.             
  1736.                 // Decode base64 data
  1737.                 $imageBase base64_decode($base64Data);
  1738.             
  1739.                 // Generate a unique filename
  1740.                 $filename md5(uniqid()) . '.jpeg'// Assuming JPEG format
  1741.             
  1742.                 // Save the image to the desired location
  1743.                 $imagePath $imageFolder $filename// Update with your desired path
  1744.                 file_put_contents($imagePath$imageBase);
  1745.             
  1746.                 $image = new Images();
  1747.                 $image->setUrlImage('/assets/imagesMissions/' $filename); // Assuming the path is relative to the public directory
  1748.                 $image->setIdDetailFichier($idDetailFichier);
  1749.                 $image->setIdFichier(0);
  1750.             
  1751.                 // Persist the Image object to the database
  1752.                 $entityManager->persist($image);
  1753.     
  1754.                 $entityManager->flush();
  1755.                 array_push($imagToR$idDetailFichier);
  1756.             }
  1757.             
  1758.             $responseObjects["imagToR"] = $imagToR;
  1759.             
  1760.             
  1761.             $seenIdDetail = array();
  1762.             foreach ($stockUtilise as $stockData) {
  1763.                 $idDetail $stockData['idDetail'];
  1764.                 if (!in_array($idDetail$seenIdDetail)) {
  1765.                     $seenIdDetail[] = $idDetail;
  1766.                 }
  1767.             }
  1768.             
  1769.             $allIsRelated $entityManager->getRepository(StockDetailFichier::class)->findBy(['idDetail' => $seenIdDetail]);
  1770.             foreach ($allIsRelated as $imR) {
  1771.                 $entityManager->remove($imR);
  1772.             }
  1773.             foreach ($stockUtilise as $stockData) {
  1774.                 $stockDetailFichier = new StockDetailFichier();
  1775.                 $stockDetailFichier->setIdDetail($stockData["idDetail"]); 
  1776.                 $stockDetailFichier->setIdMission($stockData["idMission"]);
  1777.                 $stockDetailFichier->setIdPiece($stockData["idPiec"]);
  1778.                 $stockDetailFichier->setQte($stockData["qte"]);
  1779.                 $stockDetailFichier->setDateCreation(new \DateTime($stockData["dateCreation"]));
  1780.                 // Persist the Stock Detail object to the database
  1781.                 $entityManager->persist($stockDetailFichier);
  1782.     
  1783.                 $entityManager->flush();
  1784.                 array_push($stdtToR$stockData["idDetail"]);
  1785.                 $entityManager->flush();
  1786.             }
  1787.             
  1788.             
  1789.             $responseObjects["stdtToR"] = $stdtToR;
  1790.             
  1791.             
  1792.             $oldDepenses $entityManager->getRepository(Charge::class)->findBy(array("idAgent" => $id));
  1793.             
  1794.             // Array to keep track of old expenses that need to be removed
  1795.             $expensesToRemove = array();
  1796.             
  1797.             // Remove old expenses that are not present in the new list
  1798.             foreach ($oldDepenses as $oldDepense) {
  1799.                 $found false;
  1800.                 foreach ($depenses as $de) {
  1801.                     if ($oldDepense->getId() == $de['id']) {
  1802.                         $found true;
  1803.                         break;
  1804.                     }
  1805.                 }
  1806.                 if (!$found) {
  1807.                     // Mark the old expense for removal
  1808.                     $expensesToRemove[] = $oldDepense;
  1809.                 }
  1810.             }
  1811.             
  1812.             // Remove old expenses that are not present in the new list
  1813.             foreach ($expensesToRemove as $expenseToRemove) {
  1814.                 $entityManager->remove($expenseToRemove);
  1815.             }
  1816.             
  1817.             // Add or update new expenses
  1818.             foreach ($depenses as $de) {
  1819.                 if($de['sync'] == '1')
  1820.                 {
  1821.                      $found false;
  1822.                 foreach ($oldDepenses as $oldDepense) {
  1823.                     if ($oldDepense->getId() == $de['id']) {
  1824.                         // Update the existing expense
  1825.                         $oldDepense->setTitrChar($de['titrChar']);
  1826.                         $oldDepense->setDateCreation(new \DateTime($de['dateCreation']));
  1827.                         $oldDepense->setIdAttCha($de['idAttCha']);
  1828.                         $oldDepense->setTotalHt($de['totalHt']);
  1829.                         $oldDepense->setTotalTtc($de['totalTtc']);
  1830.                         $oldDepense->setObservation($de['observation']);
  1831.                         $oldDepense->setModePaie($de['modePaie']);
  1832.                         $oldDepense->setIdAgent($id);
  1833.                 
  1834.                         $found true;
  1835.                         break;
  1836.                     }
  1837.                 }
  1838.                 if (!$found) {
  1839.                     dump($de['idMarche']);
  1840.                     // Add new expense
  1841.                     $charge = new Charge();
  1842.                     $charge->setTitrChar($de['titrChar']);
  1843. $dateStr preg_replace('/\s*\(.*\)$/'''$de['dateCreation']); 
  1844. // removes "(UTC+01:00)"
  1845. $charge->setDateCreation(new \DateTime($dateStr));
  1846.                     $charge->setIdAttCha($de['idAttCha']);
  1847.                     $charge->setTotalHt($de['totalHt']);
  1848.                     $charge->setTotalTtc($de['totalTtc']);
  1849.                     $charge->setObservation($de['observation']);
  1850.                     $charge->setIdFour(0);
  1851.                     $charge->setIdBure(0);
  1852.                     $charge->setModePaie($de['modePaie']);
  1853.                     $charge->setIdAgent($id);
  1854.                     $charge->setIdUtil($id);
  1855.                     $charge->setIdMarche($de['idMarche']);
  1856.                     $imageFolder $this->getParameter('kernel.project_dir') . '/public/assets/images/Charges/';
  1857.                                 
  1858.                     $base64Data $de['img'];
  1859.     
  1860.                     // Remove the header from the base64 data
  1861.                     $base64Data preg_replace('/^data:image\/\w+;base64,/'''$base64Data);
  1862.                 
  1863.                     // Decode base64 data
  1864.                     $imageBase base64_decode($base64Data);
  1865.                 
  1866.                     // Generate a unique filename
  1867.                     $filename md5(uniqid()) . '.jpeg'// Assuming JPEG format
  1868.                 
  1869.                     // Save the image to the desired location
  1870.                     $imagePath $imageFolder $filename
  1871.                 
  1872.                     file_put_contents($imagePath$imageBase);
  1873.                     $charge->setImg("/assets/images/Charges/".$filename);
  1874.             
  1875.                     // Persist the Charge entity and flush it to the database
  1876.                     $entityManager->persist($charge);
  1877.                 }
  1878.                 
  1879.                 $entityManager->flush();
  1880.                 array_push($depeToR$de["id"]);
  1881.                 }
  1882.                
  1883.             }
  1884.             
  1885.             $responseObjects["depeToR"] = $depeToR;
  1886.             
  1887.             // Flush changes to the database
  1888.             $codeStatut "OK";
  1889.             $response "ok";
  1890.         }
  1891.         catch(\Exception $e
  1892.         {
  1893.             $response $e->getMessage();
  1894.             $codeStatut "ERROR-EXE";
  1895.         }
  1896.         
  1897.         $resp["codeStatut"] = $codeStatut;
  1898.         $resp["message"] = $response;
  1899.         $resp["token"] = $tokenJWT;
  1900.         $resp["object"] =  $responseObjects;
  1901.         $json $serializer->serialize($resp'json');
  1902.         $jsonResponse = new JsonResponse($json200, [], true);
  1903.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  1904.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  1905.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  1906.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  1907.         return $jsonResponse;
  1908.         
  1909.         
  1910.     }
  1911.     
  1912.     
  1913.     #[Route('/webService/getAllNotifications'name'getAllNotifications')]
  1914.     public function getAllNotifications(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  1915.     JWTEncoderInterface $jwtManager,TacheRepository $tacheRepository): JsonResponse
  1916.     {
  1917.         $tokenJWT "";
  1918.         $codeStatut "ERROR";
  1919.         $response "";
  1920.         $responseObjects = array();
  1921.         try 
  1922.         {
  1923.             $jwt $request->headers->get('Authorization');
  1924.             $jwt substr($jwt7);
  1925.             $decoded $jwtManager->decode($jwt);
  1926.             $id $decoded['userId'];
  1927.             $notifications $entityManager->getRepository(Notifications::class)->findBy(
  1928.                 array('idUser' => $id),
  1929.                 array('id' => 'DESC'),
  1930.                 50 // Maximum number of results
  1931.             );
  1932.             $responseObjects $notifications;
  1933.             $response 'ok';
  1934.             $codeStatut "OK";
  1935.         }
  1936.         catch(\Exception $e
  1937.         {
  1938.             $response $e->getMessage();
  1939.             $codeStatut "ERROR-EXE";
  1940.         }
  1941.         $resp["codeStatut"] = $codeStatut;
  1942.         $resp["message"] = $response;
  1943.         $resp["token"] = $tokenJWT;
  1944.         $resp["object"] =  $responseObjects;
  1945.         $json $serializer->serialize($resp'json');
  1946.         $jsonResponse = new JsonResponse($json200, [], true);
  1947.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  1948.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  1949.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  1950.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  1951.         return $jsonResponse;
  1952.     }
  1953.     //Tache:
  1954.     #[Route('/webService/addTache'name'webServiceAddTache')]
  1955.     public function addTache(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  1956.     TacheRepository $tacheRepository,BaseService $baseService,ValidateService $validateService ,  JWTEncoderInterface $jwtManager): JsonResponse
  1957.     {
  1958.         $tokenJWT "";
  1959.         $codeStatut "ERROR";
  1960.         $response "";
  1961.         $responseObjects = array();
  1962.         
  1963.         $jwt $request->headers->get('Authorization');
  1964.         $jwt substr($jwt7);
  1965.         $decoded $jwtManager->decode($jwt);
  1966.         $id $decoded['userId'];
  1967.         $chckAccess $baseService->RoleMobile(92,$id);
  1968.         if($chckAccess != 1){
  1969.             $codeStatut "ERROR-ACCES";
  1970.             $response "erreur access";
  1971.         }
  1972.         // else if ($chckAccess == 2)
  1973.         // {
  1974.         //     $codeStatut = "ERROR-ACCES";
  1975.         //     $response = "erreur access";
  1976.         // }
  1977.         
  1978.         if($response == '')
  1979.         {
  1980.             try 
  1981.             {
  1982.                 
  1983.                 $user $entityManager->getRepository(Utilisateur::class)->find($id);
  1984.                 
  1985.                 $dateCreation = new \DateTime();
  1986.     
  1987.                 $nomTach=$request->get('nomTach');
  1988.                 $prioTach=$request->get('prioTach');
  1989.                 $typeTach=$request->get('typeTach');
  1990.                 $dateEcheance=$request->get('dateEcheance');
  1991.                 $users=json_decode($request->get('users'));
  1992.                 $idMarche=$request->get('idMarche');
  1993.                 $objetDetail=$request->get('objetDetail');
  1994.                 $etatTach=$request->get('etatTach');
  1995.                 // $files = $_FILES['files'];
  1996.                 $dateDebut=$request->get('DateDebut');
  1997.                 $contraintes = array(
  1998.                     "nomTach" => array("val" => $nomTach"length" => 255"type" => "string""isBlank" => true),
  1999.                 );
  2000.     
  2001.                 $valideBonCommande$validateService->validateur($contraintes);
  2002.                 if ($valideBonCommande === true
  2003.                 {
  2004.                     define('TARGET''./assets/tache_pj/');    // Repertoire cible
  2005.                     define('MAX_SIZE'100000000);    // Taille max en octets du fichier
  2006.                     define('WIDTH_MAX'4000);    // Largeur max de l'image en pixels
  2007.                     define('HEIGHT_MAX'3000);    // Hauteur max de l'image en pixels
  2008.                     // Tableaux de donnees
  2009.                     $tabExt = array('pdf''zip''png''gif','jpeg','jpg');    // Extensions autorisees
  2010.                     $affectationUser true;
  2011.                     if($user->getTypeUtil() != 0){
  2012.                         //$chckAccess = $this->baseService->Role(126);
  2013.                         $chckAccess $baseService->RoleMobile(126,$id);
  2014.                         if(!$chckAccess != 1){
  2015.                             $affectationUser false;
  2016.                         }
  2017.                     }
  2018.     
  2019.                     $tache = new Tache();
  2020.                     $tache->setNomTach($nomTach);
  2021.                     $tache->setTypeTach($typeTach);
  2022.                     $tache->setDateCreation($dateCreation);
  2023.                     if($dateEcheance != "undefined"){
  2024.                         $tache->setDateEcheance(new \DateTime($dateEcheance));
  2025.                     }
  2026.                     if($dateDebut  != "undefined"){
  2027.                         $tache->setDateDebut(new \DateTime($dateDebut));
  2028.                     }
  2029.                     $tache->setEtatTach($etatTach);
  2030.                     $tache->setPrioTach($prioTach);
  2031.                     $tache->setIdMarche($idMarche);
  2032.                     
  2033.                     $entityManager->persist($tache);
  2034.                     $entityManager->flush();
  2035.         
  2036.                     $text 'Veuillez consulter votre tâche affectée';
  2037.                     if($affectationUser != true )
  2038.                     {
  2039.                         $tacheUser = new TacheUtilisateur();
  2040.                         $tacheUser->setidUtil($user->getId());
  2041.                         $tacheUser->setIdTach($tache->getId());
  2042.                         $entityManager->persist($tacheUser);
  2043.                         $entityManager->flush();
  2044.                         //Notification util
  2045.                         $baseService->addNotifications($text $tache->getId() , $user->getId(),0);
  2046.                     }
  2047.                     else
  2048.                     {
  2049.                         if (isset($users) && is_array($users) && count($users) > 0) {
  2050.                             foreach ($users as $u)
  2051.                             {
  2052.                                 $tacheUser = new TacheUtilisateur();
  2053.                                 $tacheUser->setidUtil($u);
  2054.                                 $tacheUser->setIdTach($tache->getId());
  2055.                                 $entityManager->persist($tacheUser);
  2056.                                 $entityManager->flush();
  2057.                                 //Notification util
  2058.                                 $baseService->addNotifications($text $tache->getId() , $u,0);
  2059.                             }
  2060.                         }else{
  2061.                             $tacheUser = new TacheUtilisateur();
  2062.                             $tacheUser->setidUtil($user->getId());
  2063.                             $tacheUser->setIdTach($tache->getId());
  2064.                             $entityManager->persist($tacheUser);
  2065.                             $entityManager->flush();
  2066.                             //Notification util
  2067.                             $baseService->addNotifications($text $tache->getId() , $user->getId(),0);
  2068.                         }
  2069.                     }
  2070.                     
  2071.                     
  2072.                     if($user->getTypeUtil() == && !$users){
  2073.                         //Notification util
  2074.                         $baseService->addNotifications($text $tache->getId() , $user->getId(),0);
  2075.                     }
  2076.                     if (isset($objetDetail) && is_array($objetDetail) && count($objetDetail) > 0) {
  2077.         
  2078.                         for($i=0;$i<count($objetDetail);$i++)
  2079.                         {
  2080.         
  2081.                             $sousTache=new SousTache();
  2082.                             $sousTache->setIdTache($tache->getId());
  2083.                             $sousTache->setObjet($objetDetail[$i]);
  2084.                             $entityManager->persist($sousTache);
  2085.         
  2086.                         }
  2087.                     }
  2088.     
  2089.                     // for ($i = 0; $i < count($files['name']); $i++){
  2090.                     //     $fille = new TachePj();
  2091.                     //     $fille->setIdUser($user->getId());
  2092.                     //     $fille->setIdTache($tache->getId());
  2093.                         
  2094.                     //     if (!empty($files['name'][$i])) {
  2095.                     //         // Recuperation de l'extension du fichier
  2096.                     //         $extension = pathinfo($files['name'][$i], PATHINFO_EXTENSION);
  2097.                     //         // On verifie l'extension du fichier
  2098.                     //         if (in_array(strtolower($extension), $tabExt)) {
  2099.                     //             $file_temp = $files['tmp_name'][$i];
  2100.                     //             if (!empty($file_temp)) {
  2101.                     //                 // On recupere les dimensions du fichier
  2102.                     //                 $infosImg = getimagesize($files['tmp_name'][$i]);
  2103.                     //                 // On verifie les dimensions et taille de l'image
  2104.                     //                 if (filesize($files['tmp_name'][$i]) <= MAX_SIZE) {
  2105.                     //                     // Parcours du tableau d'erreurs
  2106.                     //                     if (isset($files['error'][$i]) && UPLOAD_ERR_OK === $files['error'][$i]) {
  2107.                     //                         // On renomme le fichier
  2108.                     //                         $nomImage = md5(uniqid()) . '.' . $extension;
  2109.                     //                         // Si c'est OK, on teste l'upload
  2110.                     //                         if (move_uploaded_file($files['tmp_name'][$i], TARGET . $nomImage)) 
  2111.                     //                         {
  2112.                     //                             $url = "/assets/tache_pj/" . $nomImage;
  2113.                     //                             $fille->setUrl($url);
  2114.                     //                             $entityManager->persist($fille);
  2115.                     //                         }
  2116.                     //                     }
  2117.                     //                 }
  2118.                     //             }
  2119.                     //         }
  2120.                     //     }
  2121.                     // }
  2122.     
  2123.                     $entityManager->flush();
  2124.                     $responseObjects['id']=$tache->getId();
  2125.                     $response "OK";
  2126.                 }
  2127.                 else
  2128.                 {
  2129.         
  2130.                     $response 'Veuillez vérifier vos informations, un des champs est incorrect !';
  2131.                 }
  2132.             }
  2133.             catch(\Exception $e
  2134.             {
  2135.                 $response $e->getMessage();
  2136.                 $codeStatut "ERROR-EXE";
  2137.             }
  2138.         }
  2139.         $resp["codeStatut"] = $response;
  2140.         $resp["message"] = $response;
  2141.         $resp["token"] = $tokenJWT;
  2142.         $resp["object"] =  $responseObjects;
  2143.         
  2144.         $json $serializer->serialize($resp'json');
  2145.         $jsonResponse = new JsonResponse($json200, [], true);
  2146.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  2147.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  2148.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  2149.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  2150.         return $jsonResponse;
  2151.     }
  2152.     #[Route('/webService/updateTache'name'webServiceUpdateTache')]
  2153.     public function updateTache(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,
  2154.     TacheRepository $tacheRepository,BaseService $baseService,ValidateService $validateService ,  JWTEncoderInterface $jwtManager): JsonResponse
  2155.     {
  2156.         $tokenJWT "";
  2157.         $codeStatut "ERROR";
  2158.         $response "";
  2159.         $responseObjects = array();
  2160.       
  2161.         $jwt $request->headers->get('Authorization');
  2162.         $jwt substr($jwt7);
  2163.         $decoded $jwtManager->decode($jwt);
  2164.         $id $decoded['userId'];
  2165.         $idUser $decoded['userId'];
  2166.         $chckAccess $baseService->RoleMobile(92,$idUser);
  2167.         if($chckAccess != 1){
  2168.             $codeStatut "ERROR-ACCES";
  2169.             $response "erreur access";
  2170.         }
  2171.             
  2172.         
  2173.         if($response == '')
  2174.         {
  2175.             try 
  2176.             {
  2177.                 
  2178.             $user $entityManager->getRepository(Utilisateur::class)->find($id);
  2179.                 
  2180.             $dateCreation = new \DateTime();
  2181.             
  2182.             $idTach=$request->get('idTach');
  2183.             $nomTach=$request->get('nomTach');
  2184.             $prioTach=$request->get('prioTach');
  2185.             $typeTach=$request->get('typeTach');
  2186.             $dateEcheance=$request->get('dateEcheanceUp');
  2187.             $users=json_decode($request->get('users'));
  2188.             $idMarche=$request->get('idMarche');
  2189.             $etatTach=$request->get('etatTachUp');
  2190.             $objetDetail=$request->get('objetDetailUp');
  2191.             $dateDebut=$request->get('dateDebutUp');
  2192.             $tache $entityManager->getRepository(Tache::class)->find($idTach);
  2193.     
  2194.             if(!$tache)
  2195.             {
  2196.                 $response 'Desolé, cette tache est introuvable !';
  2197.             }
  2198.             else
  2199.             {
  2200.                 $contraintes = array(
  2201.                     "nomTach" => array("val" => $nomTach"length" => 255"type" => "string""isBlank" => true),
  2202.                 );
  2203.         
  2204.                 $valideBonCommande$validateService->validateur($contraintes);
  2205.                 if ($valideBonCommande === true
  2206.                 {
  2207.     
  2208.                     $sousTaches $entityManager->getRepository(SousTache::class)->findByIdTache($idTach);
  2209.                     $tacheUsers $entityManager->getRepository(TacheUtilisateur::class)->findByIdTach($idTach);
  2210.             
  2211.                     // Remove the tache
  2212.                     foreach($sousTaches as $s)
  2213.                     {
  2214.                         $entityManager->remove($s);
  2215.                     }
  2216.                     foreach($tacheUsers as $t)
  2217.                     {
  2218.                         $entityManager->remove($t);
  2219.                     }
  2220.         
  2221.         
  2222.                     $entityManager->flush();
  2223.     
  2224.                     $tache->setNomTach($nomTach);
  2225.                     $tache->setTypeTach($typeTach);
  2226.                     $tache->setDateCreation($dateCreation);
  2227.                     $tache->setDateEcheance(new \DateTime($dateEcheance));
  2228.                     $tache->setEtatTach($etatTach);
  2229.                     $tache->setPrioTach($prioTach);
  2230.                     $tache->setIdMarche($idMarche);
  2231.                     $tache->setDateDebut(new \DateTime($dateDebut));
  2232.                     $entityManager->persist($tache);
  2233.                     $entityManager->flush();
  2234.                     define('TARGET''./assets/tache_pj/');    // Repertoire cible
  2235.                     define('MAX_SIZE'100000000);    // Taille max en octets du fichier
  2236.                     define('WIDTH_MAX'4000);    // Largeur max de l'image en pixels
  2237.                     define('HEIGHT_MAX'3000);    // Hauteur max de l'image en pixels
  2238.                     // Tableaux de donnees
  2239.                     $tabExt = array('pdf''zip''png''gif','jpeg','jpg');    // Extensions autorisees
  2240.         
  2241.                     if($user->getTypeUtil() != 0)
  2242.                     {
  2243.                         $tacheUser = new TacheUtilisateur();
  2244.                         $tacheUser->setidUtil($user->getId());
  2245.                         $tacheUser->setIdTach($tache->getId());
  2246.         
  2247.                         $entityManager->persist($tacheUser);
  2248.                         $entityManager->flush();
  2249.     
  2250.                     }
  2251.                     else
  2252.                     {
  2253.                         if($users)
  2254.                         foreach ($users as $u)
  2255.                         {
  2256.             
  2257.                             $tacheUser = new TacheUtilisateur();
  2258.                             $tacheUser->setidUtil($u);
  2259.                             $tacheUser->setIdTach($tache->getId());
  2260.             
  2261.                             $entityManager->persist($tacheUser);
  2262.                             $entityManager->flush();
  2263.                         }
  2264.                     }
  2265.     
  2266.                     if(isset($objetDetail)){
  2267.                         for($i=0;$i<count($objetDetail);$i++)
  2268.                         {
  2269.                             $sousTache=new SousTache();
  2270.                             $sousTache->setIdTache($tache->getId());
  2271.                             $sousTache->setObjet($objetDetail[$i]);
  2272.                             $entityManager->persist($sousTache);
  2273.                         }
  2274.                     }
  2275.                     if(isset($files))
  2276.                     for ($i 0$i count($files['name']); $i++){
  2277.                         $fille = new TachePj();
  2278.                         $fille->setIdUser($user->getId());
  2279.                         $fille->setIdTache($tache->getId());
  2280.                         
  2281.                         if (isset($files) && !empty($files['name'][$i])) {
  2282.                             // Recuperation de l'extension du fichier
  2283.                             $extension pathinfo($files['name'][$i], PATHINFO_EXTENSION);
  2284.                             // On verifie l'extension du fichier
  2285.                             if (in_array(strtolower($extension), $tabExt)) {
  2286.                                 $file_temp $files['tmp_name'][$i];
  2287.                                 if (!empty($file_temp)) {
  2288.                                     // On recupere les dimensions du fichier
  2289.                                     $infosImg getimagesize($files['tmp_name'][$i]);
  2290.                                     // On verifie les dimensions et taille de l'image
  2291.                                     if (filesize($files['tmp_name'][$i]) <= MAX_SIZE) {
  2292.                                         // Parcours du tableau d'erreurs
  2293.                                         if (isset($files['error'][$i]) && UPLOAD_ERR_OK === $files['error'][$i]) {
  2294.                                             // On renomme le fichier
  2295.                                             $nomImage md5(uniqid()) . '.' $extension;
  2296.                                             // Si c'est OK, on teste l'upload
  2297.                                             if (move_uploaded_file($files['tmp_name'][$i], TARGET $nomImage)) 
  2298.                                             {
  2299.                                                 $url "/assets/tache_pj/" $nomImage;
  2300.                                                 $fille->setUrl($url);
  2301.                                                 $entityManager->persist($fille);
  2302.                                             }
  2303.                                         }
  2304.                                     }
  2305.                                 }
  2306.                             }
  2307.                         }
  2308.                     }
  2309.                     $entityManager->flush();
  2310.         
  2311.                     $response 'ok';
  2312.                 }
  2313.                 else
  2314.                 {
  2315.         
  2316.                     $response 'Veuillez vérifier vos informations, un des champs est incorrect !';
  2317.                 }
  2318.             }
  2319.             }
  2320.             catch(\Exception $e
  2321.             {
  2322.                 $response $e->getMessage();
  2323.                 $codeStatut "ERROR-EXE";
  2324.             }
  2325.         }
  2326.         $resp["codeStatut"] = $response;
  2327.         $resp["message"] = $response;
  2328.         $resp["token"] = $tokenJWT;
  2329.         $resp["object"] =  $responseObjects;
  2330.         $json $serializer->serialize($resp'json');
  2331.         $jsonResponse = new JsonResponse($json200, [], true);
  2332.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  2333.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  2334.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  2335.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  2336.         return $jsonResponse;
  2337.     }
  2338.     
  2339.     // #[Route('/webService/taskMail', name: 'taskMail')]
  2340.     // public function taskMail(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,BaseService $baseService): JsonResponse
  2341.     // {
  2342.     //     $codeStatut = "ERROR";
  2343.     //     $response = "";
  2344.     //     $responseObjects = array();
  2345.         
  2346.     //     try 
  2347.     //     {
  2348.     //         //Task due
  2349.     //         $query = $entityManager->createQuery(
  2350.     //             'SELECT tu
  2351.     //             FROM App\Entity\TacheUtilisateur tu where tu.idTach  in (SELECT t.id
  2352.     //             FROM App\Entity\Tache t where t.etatTach != 3 and t.dateEcheance < :dateNow )
  2353.     //             '
  2354.     //         );
  2355.     //         $query->setParameter('dateNow', new \DateTime());
  2356.     //         $resultDue = $query->getResult();
  2357.     //         foreach ($resultDue as $value) {
  2358.     //             $user = $entityManager->getRepository(Utilisateur::class)->find($value->getIdUtil());
  2359.     //             $tache = $entityManager->getRepository(Tache::class)->find($value->getIdTach());
  2360.     //             $nomUser = $user->getPrenUtil()." ".$user->getNomUtil();
  2361.     //             $baseService->taskMail($user->getId(),$nomUser , 3 , $tache , $user->getEmaiUtil());
  2362.     //         }
  2363.     //         //Task in progress
  2364.     //         $query = $entityManager->createQuery(
  2365.     //             'SELECT tu
  2366.     //             FROM App\Entity\TacheUtilisateur tu where tu.idTach  in (SELECT t.id
  2367.     //             FROM App\Entity\Tache t where t.etatTach = 2  )
  2368.     //             '
  2369.     //         );
  2370.     //         $resultProgress = $query->getResult();
  2371.     //         foreach ($resultProgress as $value) {
  2372.     //             $user = $entityManager->getRepository(Utilisateur::class)->find($value->getIdUtil());
  2373.     //             $tache = $entityManager->getRepository(Tache::class)->find($value->getIdTach());
  2374.     //             $nomUser = $user->getPrenUtil()." ".$user->getNomUtil();
  2375.     //             $baseService->taskMail($user->getId(),$nomUser , 2 , $tache , $user->getEmaiUtil());
  2376.     //         }
  2377.     //         $codeStatut = "OK";
  2378.     //     }
  2379.     //     catch(\Exception $e) 
  2380.     //     {
  2381.     //         $response = $e->getMessage();
  2382.     //         $codeStatut = "ERROR-EXE";
  2383.     //     }
  2384.     //     $resp["codeStatut"] = $codeStatut;
  2385.     //     $resp["message"] = $response;
  2386.         
  2387.     //     $json = $serializer->serialize($resp, 'json');
  2388.     //     $jsonResponse = new JsonResponse($json, 200, [], true);
  2389.     //     $jsonResponse->headers->set('Access-Control-Allow-Origin', '*');
  2390.     //     $jsonResponse->headers->set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, DELETE, PUT');
  2391.     //     $jsonResponse->headers->set('Access-Control-Allow-Headers', 'Content-Type, Authorization');
  2392.     //     $jsonResponse->headers->set('Access-Control-Max-Age', 3600);
  2393.     //     return $jsonResponse;
  2394.     // }
  2395.     #[Route('/webService/taskMail'name'taskMail')]
  2396.     public function taskMail(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,BaseService $baseService): JsonResponse
  2397.     {
  2398.         $codeStatut "ERROR";
  2399.         $response "";
  2400.         $responseObjects = array();
  2401.         
  2402.         try 
  2403.         {
  2404.             $query $entityManager->createQuery(
  2405.                 'SELECT tu
  2406.                 FROM App\Entity\TacheUtilisateur tu where tu.idTach  in (SELECT t.id
  2407.                 FROM App\Entity\Tache t where t.etatTach = 2 )
  2408.                 '
  2409.             );
  2410.             $resultProgress $query->getResult();
  2411.             foreach ($resultProgress as $value) {
  2412.                 $user $entityManager->getRepository(Utilisateur::class)->find($value->getIdUtil());
  2413.                 $tache $entityManager->getRepository(Tache::class)->find($value->getIdTach());
  2414.                 $nomUser $user->getPrenUtil()." ".$user->getNomUtil();
  2415.                 $baseService->taskMail($user->getId(),$nomUser $tache $user->getEmaiUtil());
  2416.             }
  2417.             $startOfDay = (new \DateTime())->setTime(0,0,0);
  2418.             $endOfDay   = (new \DateTime())->setTime(23,59,59);
  2419.             $query $entityManager->createQuery(
  2420.                 'SELECT tu
  2421.                 FROM App\Entity\TacheUtilisateur tu
  2422.                 WHERE tu.idTach IN (
  2423.                     SELECT t.id
  2424.                     FROM App\Entity\Tache t
  2425.                     WHERE t.etatTach != 3
  2426.                     AND t.dateDebut BETWEEN :startOfDay AND :endOfDay
  2427.                 )'
  2428.             );
  2429.             $query->setParameter('startOfDay'$startOfDay);
  2430.             $query->setParameter('endOfDay'$endOfDay);
  2431.             $resultProgress $query->getResult();
  2432.             foreach ($resultProgress as $value) {
  2433.                 $user $entityManager->getRepository(Utilisateur::class)->find($value->getIdUtil());
  2434.                 $tache $entityManager->getRepository(Tache::class)->find($value->getIdTach());
  2435.                 $nomUser $user->getPrenUtil()." ".$user->getNomUtil();
  2436.                 $baseService->taskMail($user->getId(),$nomUser $tache $user->getEmaiUtil());
  2437.             }
  2438.             $codeStatut "OK";
  2439.         }
  2440.         catch(\Exception $e
  2441.         {
  2442.             $response $e->getMessage();
  2443.             $codeStatut "ERROR-EXE";
  2444.         }
  2445.         $resp["codeStatut"] = $codeStatut;
  2446.         $resp["message"] = $response;
  2447.         
  2448.         $json $serializer->serialize($resp'json');
  2449.         $jsonResponse = new JsonResponse($json200, [], true);
  2450.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  2451.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  2452.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  2453.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  2454.         return $jsonResponse;
  2455.     }
  2456.     #[Route('/webService/taskMailRetard'name'taskMailRetard')]
  2457.     public function taskMailRetard(Request $request,SerializerInterface $serializer,EntityManagerInterface $entityManager,BaseService $baseService): JsonResponse
  2458.     {
  2459.         $codeStatut "ERROR";
  2460.         $response "";
  2461.         $responseObjects = array();
  2462.         
  2463.         try 
  2464.         {
  2465.             //Task due
  2466.             $query $entityManager->createQuery(
  2467.                 'SELECT tu
  2468.                 FROM App\Entity\TacheUtilisateur tu where tu.idTach  in (SELECT t.id
  2469.                 FROM App\Entity\Tache t where t.etatTach != 3 and t.dateEcheance < :dateNow )
  2470.                 '
  2471.             );
  2472.             $query->setParameter('dateNow', new \DateTime());
  2473.             $resultDue $query->getResult();
  2474.             foreach ($resultDue as $value) {
  2475.                 $user $entityManager->getRepository(Utilisateur::class)->find($value->getIdUtil());
  2476.                 $tache $entityManager->getRepository(Tache::class)->find($value->getIdTach());
  2477.                 $nomUser $user->getPrenUtil()." ".$user->getNomUtil();
  2478.                 $baseService->taskMail($user->getId(),$nomUser $tache $user->getEmaiUtil());
  2479.             }
  2480.             $codeStatut "OK";
  2481.         }
  2482.         catch(\Exception $e
  2483.         {
  2484.             $response $e->getMessage();
  2485.             $codeStatut "ERROR-EXE";
  2486.         }
  2487.         $resp["codeStatut"] = $codeStatut;
  2488.         $resp["message"] = $response;
  2489.         
  2490.         $json $serializer->serialize($resp'json');
  2491.         $jsonResponse = new JsonResponse($json200, [], true);
  2492.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  2493.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  2494.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  2495.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  2496.         return $jsonResponse;
  2497.     }
  2498.     
  2499.     #[Route('/webService/addPointage'name'addPointage' methods:['POST'])]
  2500.     public function addPointage(Request $request,  SerializerInterface $serializer,EntityManagerInterface $entityManager,BaseService $baseService JWTEncoderInterface $jwtManager): JsonResponse
  2501.     {
  2502.         $codeStatut "ERROR";
  2503.         $response "";
  2504.         $responseObjects = array();
  2505.         try 
  2506.         {
  2507.             $jwt $request->headers->get('Authorization');
  2508.             $jwt substr($jwt7);
  2509.             $decoded $jwtManager->decode($jwt);
  2510.             $idUser $decoded['userId'];
  2511.             $type $request->get('type');
  2512.             $arrayType = ['1','2','3','4'];
  2513.             $datetime = new \DateTime();
  2514.             $dateDay $datetime->format('Y-m-d');
  2515.             $check true;
  2516.             if(in_array($type $arrayType)){
  2517.                 if($type == '1'){
  2518.                     if($this->pointageRepo->checkDebut($idUser $dateDay) != false){
  2519.                         $check false;
  2520.                         $response "Veuillez pointer une manière correcte !";
  2521.                     };
  2522.                 }else if($type == '2' || $type == '3'){
  2523.                     if($this->pointageRepo->checkPause($idUser $dateDay $type) == false){
  2524.                         $check false;
  2525.                         $response "Veuillez pointer une manière correcte !";
  2526.                     };
  2527.                 }else if($type == '4'){
  2528.                     if($this->pointageRepo->checkFin($idUser $dateDay ) == false){
  2529.                         $check false;
  2530.                         $response "Veuillez pointer une manière correcte !";
  2531.                     };
  2532.                 }
  2533.                 if($check == true){
  2534.                     $latitude $request->get('latitude');
  2535.                     $longitude $request->get('longitude');
  2536.                     
  2537.                     if($latitude != "" && $latitude != "" ){
  2538.                         $pointage = new PointageUser();
  2539.                         $pointage->setDateAction(new \DateTime());
  2540.                         $pointage->setIdUser($idUser);
  2541.                         $pointage->setTypePointage($type);
  2542.                         $pointage->setLatitude($latitude); 
  2543.                         $pointage->setLongitude($longitude); 
  2544.                         $entityManager->persist($pointage);
  2545.                         $entityManager->flush();
  2546.         
  2547.                         $text "Status de présence : ";
  2548.                         if($type == '1'){
  2549.                             $this->pointageRepo->insertWorkTime($idUser $dateDay 1);
  2550.                             $text .= 'Début de travail';
  2551.                         }else if($type == '2'){
  2552.                             $text .= 'Début de pause';
  2553.                         }else if($type == '3'){
  2554.                             $text .= 'Fin de pause';
  2555.                         }else if($type == '4'){
  2556.                             $text .= 'Fin de travail';
  2557.                         }
  2558.         
  2559.                         $response $text;
  2560.                         if($type == '4'){
  2561.                                 $this->pointageRepo->insertWorkTime2($idUser $dateDay 1);
  2562.                             // if($this->pointageRepo->checkAllType($idUser , $dateDay)){
  2563.                                 // $this->pointageRepo->insertWorkTime($idUser , $dateDay , 1);
  2564.                             // }else if($this->pointageRepo->checkAllType2($idUser , $dateDay)){
  2565.                             //     $this->pointageRepo->insertWorkTime($idUser , $dateDay , 2);
  2566.                             // }
  2567.                             
  2568.                         }
  2569.                         $codeStatut "OK";
  2570.                         
  2571.                     }else{
  2572.                         $codeStatut "ERREUR_MAPS";
  2573.                         $response "Veuillez activer la localisation !";
  2574.                     }
  2575.                     
  2576.                     
  2577.                 }
  2578.             }else{
  2579.                 $codeStatut="ERROR_DATA";
  2580.                 $response "Veuillez vérifier vos données !";
  2581.             }
  2582.         }
  2583.         catch(\Exception $e
  2584.         {
  2585.             $response $e->getMessage();
  2586.             $codeStatut "ERROR-EXE";
  2587.         }
  2588.         $resp["codeStatut"] = $codeStatut;
  2589.         $resp["message"] = $response;
  2590.         
  2591.         $json $serializer->serialize($resp'json');
  2592.         $jsonResponse = new JsonResponse($json200, [], true);
  2593.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  2594.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  2595.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  2596.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  2597.         return $jsonResponse;
  2598.     }
  2599.     #[Route('/webService/listeWorkPointage'name'listeWorkPointage' ,methods:['POST'])]
  2600.     public function listeWorkPointage(Request $request,  SerializerInterface $serializer,EntityManagerInterface $entityManager,BaseService $baseService JWTEncoderInterface $jwtManager): JsonResponse
  2601.     {
  2602.         $codeStatut "ERROR";
  2603.         $response "";
  2604.         $responseObjects = array();
  2605.         $liste = [];
  2606.         try 
  2607.         {
  2608.             $jwt $request->headers->get('Authorization');
  2609.             $jwt substr($jwt7);
  2610.             $decoded $jwtManager->decode($jwt);
  2611.             $idUser $decoded['userId'];
  2612.             $resp["date"] = $request->get('date');
  2613.             $chckAccess $baseService->RoleMobile(128,$idUser);
  2614.             if($chckAccess == 1){
  2615.                 if($idUser ){
  2616.                     $datetime = new \DateTime($request->get('date'));
  2617.                     $dateDay $datetime->format('Y-m-d');
  2618.     
  2619.                     if($datetime > new \DateTime()){
  2620.                         $codeStatut='ERROR_DATE';
  2621.                         $response='Veuillez vérifier la date saisie !';
  2622.                     }
  2623.                     else{
  2624.                         $liste $this->pointageRepo->workTimeListe($dateDay);  
  2625.                         $codeStatut "OK";
  2626.                     }
  2627.                     
  2628.                 }else{
  2629.                     $codeStatut="ERROR_DATA";
  2630.                     $response "Veuillez vérifier vos données !";
  2631.                 }
  2632.             }else{
  2633.                 $codeStatut="ERROR_ACCESS";
  2634.                 $response "ERROR_ACCESS";
  2635.             }
  2636.         }
  2637.         catch(\Exception $e
  2638.         {
  2639.             $response $e->getMessage();
  2640.             $codeStatut "ERROR-EXE";
  2641.         }
  2642.         $resp["codeStatut"] = $codeStatut;
  2643.         $resp["message"] = $response;
  2644.         $resp["data"] = $liste;
  2645.         
  2646.         $json $serializer->serialize($resp'json');
  2647.         $jsonResponse = new JsonResponse($json200, [], true);
  2648.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  2649.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  2650.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  2651.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  2652.         return $jsonResponse;
  2653.     }
  2654.     #[Route('/webService/detailsPointageByDay'name'detailsPointageByDay' ,methods:['POST'])]
  2655.     public function detailsPointageByDay(Request $request,  SerializerInterface $serializer,EntityManagerInterface $entityManager,BaseService $baseService JWTEncoderInterface $jwtManager): JsonResponse
  2656.     {
  2657.         $codeStatut "ERROR";
  2658.         $response "";
  2659.         $responseObjects = array();
  2660.         $liste = [];
  2661.         try 
  2662.         {
  2663.             $jwt $request->headers->get('Authorization');
  2664.             $jwt substr($jwt7);
  2665.             $decoded $jwtManager->decode($jwt);
  2666.             $idUser $decoded['userId'];
  2667.             $date $request->get('date');
  2668.             $id $request->get('id');
  2669.             $chckAccess $baseService->RoleMobile(128,$idUser);
  2670.             
  2671.             if($idUser ){
  2672.                 $datetime = new \DateTime($date);
  2673.                 $dateDay $datetime->format('Y-m-d');
  2674.                 $liste $this->pointageRepo->workTimeListeByDay($id,$dateDay);  
  2675.                 $codeStatut "OK";
  2676.                 
  2677.             }else{
  2678.                 $codeStatut="ERROR_DATA";
  2679.                 $response "Veuillez vérifier vos données !";
  2680.             }
  2681.             
  2682.         }
  2683.         catch(\Exception $e
  2684.         {
  2685.             $response $e->getMessage();
  2686.             $codeStatut "ERROR-EXE";
  2687.         }
  2688.         $resp["codeStatut"] = $codeStatut;
  2689.         $resp["message"] = $response;
  2690.         $resp["data"] = $liste;
  2691.         $resp["chckAccess"] = $chckAccess;
  2692.         
  2693.         
  2694.         $json $serializer->serialize($resp'json');
  2695.         $jsonResponse = new JsonResponse($json200, [], true);
  2696.         $jsonResponse->headers->set('Access-Control-Allow-Origin''*');
  2697.         $jsonResponse->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS, DELETE, PUT');
  2698.         $jsonResponse->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  2699.         $jsonResponse->headers->set('Access-Control-Max-Age'3600);
  2700.         return $jsonResponse;
  2701.     }
  2702.     
  2703. }