src/Controller/WebServiceController.php line 1411

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