src/Controller/WebServiceController.php line 1410

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