src/Controller/DealController.php line 483

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Deal;
  4. use App\Entity\HistoriqueDeal;
  5. use App\Entity\ChampsDeal;
  6. use App\Entity\ChampsDefautDeal;
  7. use App\Entity\CommentaireDeal;
  8. use App\Form\DealType;
  9. use App\Repository\DealRepository;
  10. use App\Repository\ChampsDealRepository;
  11. use App\Repository\EquipeRepository;
  12. use App\Repository\ChampsDefautRepository;
  13. use App\Repository\ChampsDefautDealRepository;
  14. use App\Repository\ChampsInstallateurRepository;
  15. use App\Repository\HistoriqueDealRepository;
  16. use App\Repository\OperationStandardRepository;
  17. use App\Repository\UserRepository;
  18. use App\Repository\CommentaireDealRepository;
  19. use App\Repository\NotificationsRepository;
  20. use App\Repository\SoustraitantRepository;
  21. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\HttpFoundation\Response;
  24. use Symfony\Component\Routing\Annotation\Route;
  25. use App\Entity\Champs;
  26. use App\Entity\Notifications;
  27. use App\Repository\InstallateurRepository;
  28. use App\Repository\ObligesRepository;
  29. use Datetime;
  30. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  31. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  32. use Symfony\Component\Process\Process;
  33. use Symfony\Component\Filesystem\Filesystem;
  34. use Symfony\Component\Finder\Finder;
  35. use App\Repository\ApporteurAffaireRepository;
  36. use App\Repository\ActiviteDealRepository;
  37. use App\Repository\ContratRepository;
  38. use App\Repository\FactureAafRepository;
  39. use App\Repository\AppelqualiteRepository;
  40. use App\Entity\ActiviteDeal;
  41. use App\Repository\ChampsSoustraitantRepository;
  42. use App\Repository\DepotDossierRepository;
  43. use App\Repository\ChampsDepotDossierRepository;
  44. use App\Repository\CommentairesControlleRepository;
  45. use App\Repository\DealobligeRepository;
  46. use Symfony\Component\HttpFoundation\JsonResponse;
  47. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  48. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  49. /**
  50.  * @Route("/deal")
  51.  */
  52. class DealController extends AbstractController
  53. {
  54.     /**
  55.      * @Route("/", name="app_deal_index", methods={"GET", "POST"})
  56.      */
  57.     public function index(Request $request,DealRepository $dealRepository,InstallateurRepository $installateurRepository,ObligesRepository $obligesRepository,
  58.     ChampsDefautRepository $champsDefautRepositoryChampsInstallateurRepository $champsInstallateurRepositoryUserRepository $userRepository
  59.     HistoriqueDealRepository $historiqueDealRepositoryOperationStandardRepository $operationStandardRepository): Response
  60.     {
  61.        
  62.         $idexporte=0;
  63.         $exporte ="non";
  64.         if ($this->isGranted('ROLE_INSTALLATEUR')) {
  65.             $deal=$this->getUser()->getInstallateur()->getDeals();
  66.         }elseif($this->isGranted('ROLE_OBLIGE')){
  67.             $deal=$this->getUser()->getObliges()->getDeals();
  68.         }else{
  69.             $deal=[];
  70.             
  71.             if ($request->getMethod() == "POST") {
  72.                 $form $request->request;
  73.                 if($form->get("filtreinstallateur") != null ){
  74.                     foreach ($form->get("filtreinstallateur") as $value) {
  75.                         foreach ($dealRepository->findBy([], ['id' => 'DESC']) as $dl) {
  76.                             if ($dl->getInstallateur()->getId() == $value) {
  77.                                 
  78.                                 if ($form->get("filtreoblige") != null) {
  79.                                     
  80.                                    foreach ($form->get("filtreoblige") as  $obg) {
  81.                                         if ($dl->getDealoblige()->getOblige()->getId() == $obg) {
  82.                                             //dd($form->get("filtrestatus"));
  83.                                             if ($form->get("filtrestatus") != null) {
  84.                                                 foreach ($form->get("filtrestatus") as $status) {
  85.                                                     if ($dl->getStatus() == $status ) {
  86.                                                         $deal[]=$dl;
  87.                                                     }
  88.                                                 }
  89.                                             }else{
  90.                                                 $deal[]=$dl;
  91.                                             }
  92.                                         }
  93.                                     }
  94.                                 } else {
  95.                                     if ($form->get("filtrestatus") != null) {
  96.                                         foreach ($form->get("filtrestatus") as $status) {
  97.                                             if ($dl->getStatus() == $status ) {
  98.                                                 $deal[]=$dl;
  99.                                             }
  100.                                         }
  101.                                     } else {
  102.                                         $deal[]=$dl;
  103.                                     }
  104.                                     
  105.                                    
  106.                                 }
  107.                                 
  108.                             }
  109.                         }
  110.                     }
  111.                 }else{
  112.                     if ($form->get("filtreoblige") != null) {
  113.                         foreach ($dealRepository->findBy([], ['id' => 'DESC']) as $dl) {
  114.                             foreach ($form->get("filtreoblige") as  $obg) {
  115.                                 if ($dl->getDealoblige()->getOblige()->getId() == $obg) {
  116.                                     //dd($form->get("filtrestatus"));
  117.                                     if ($form->get("filtrestatus") != null) {
  118.                                         foreach ($form->get("filtrestatus") as $status) {
  119.                                             if ($dl->getStatus() == $status ) {
  120.                                                 $deal[]=$dl;
  121.                                             }
  122.                                         }
  123.                                     }else{
  124.                                         $deal[]=$dl;
  125.                                     }
  126.                                 }
  127.                             }
  128.                         }
  129.                     }else{
  130.                         if ($form->get("filtrestatus") != null) {
  131.                             foreach ($dealRepository->findBy([], ['id' => 'DESC']) as $dl) {
  132.                                 foreach ($form->get("filtrestatus") as $status) {
  133.                                     if ($dl->getStatus() == $status ) {
  134.                                         $deal[]=$dl;
  135.                                     }
  136.                                 }
  137.                             }
  138.                         }else{
  139.                             $deal$dealRepository->findBy([], ['id' => 'DESC']);
  140.                         }
  141.                     }
  142.                 }
  143.              $exporte ="oui";
  144.             }else{
  145.                 
  146.                 $deal$dealRepository->findBy([], ['id' => 'DESC']);
  147.             }
  148.         }
  149.         $tab=[];
  150.         $deals=[];
  151.         $statuts = ["Contrat généré","Annulé","Bloqué","Contrat Signé","Validé""En Attente","Nouveau"];
  152.         
  153.         // id,type as owner,client as name ,date,file ,batiment
  154.         $i 1;
  155.         foreach ($statuts as $statut) {
  156.             foreach ($deal as  $value) {
  157.             
  158.                 if($statut == $value->getStatus()){
  159.                   if ($idexporte == 0) {
  160.                     $idexporte=$value->getId();
  161.                   }
  162.                     $tab['id']=$i;
  163.                     $tab['id_deal']=$value->getId();
  164.                     $tab['name']=$value->getNumero();  
  165.                     $tab['owner']=$value->getInstallateur()->getSociete();
  166.                     $tab['owner_id']=$value->getInstallateur()->getId();
  167.                     if($value->getDate()){
  168.                         $tab['industry_type']=$value->getDate()->format('d-m-Y');
  169.                     }
  170.                     if($value->getTaux()){
  171.                      $tab['location']=$value->getTaux();
  172.                     }
  173.                     if($value->getDealoblige()){
  174.                         $tab['contact_email']=$value->getDealoblige()->getOblige()->getSociete();
  175.                         $tab['contact_email_id']=$value->getDealoblige()->getOblige()->getId();
  176.                     }
  177.                    
  178.                     $tab['icone']="ri-archive-line";
  179.                     if($value->getDatefin()){
  180.                         $dateTime2 $value->getDatefin();
  181.                         $formattedDate2 $dateTime2->format('d/m/Y');
  182.                         $tab['datefin']=$formattedDate2
  183.                     }
  184.                     
  185.                     
  186.                     $tab['action_deal']=[];
  187.                     $historique null;
  188.                    if ($historiqueDealRepository->findBy(["deal" => $value->getId()])) {
  189.                         foreach ($historiqueDealRepository->findBy(["deal" => $value->getId()]) as $hist) {
  190.                             $historique $hist;
  191.                         }
  192.                    }
  193.                    
  194.                     if($historique != null) {
  195.                         $userModif $userRepository->findOneBy(["id" => $historique->getUser()]);
  196.                         if($userModif->getInstallateur() != null){
  197.                             $tab['action_deal']['action_id']=$userModif->getInstallateur()->getId();  
  198.                             $tab['action_deal']['action_nom']=$userModif->getInstallateur()->getNom();  
  199.                             $tab['action_deal']['action_prenom']=$userModif->getInstallateur()->getPrenom();  
  200.                             $tab['action_deal']['action_photo']= $userModif->getInstallateur()->getPhoto() != null "https://kaje-cee.net/assets/uplaod-installateur/".$userModif->getInstallateur()->getPhoto() : "https://kaje-cee.net/assets/images/user.png";
  201.                             $tab['action_deal']['action_role']="Installateur";  
  202.                         } else{
  203.                             $tab['action_deal']['action_id']=$userModif->getEquipe()->getId();  
  204.                             $tab['action_deal']['action_nom']=$userModif->getEquipe()->getNom();  
  205.                             $tab['action_deal']['action_prenom']=$userModif->getEquipe()->getPrenom();   
  206.                             $tab['action_deal']['action_photo']=$userModif->getEquipe()->getPhoto() != null "https://kaje-cee.net/assets/uplaod-equipe/".$userModif->getEquipe()->getPhoto() : "https://kaje-cee.net/assets/images/user.png";
  207.                             $tab['action_deal']['action_role']="Administrateur"
  208.                         }
  209.                         $dateTime $historique->getDate();
  210.                         $formattedDate $dateTime->format('d/m/Y');
  211.                         $tab['action_deal']['action_date']=$formattedDate
  212.                         $tab['action_deal']['action_commentaire']=$historique->getAction(); 
  213.                     }
  214.                     
  215.                     $tab['employee']="deal";
  216.                     if ($value->getStatus()=='Validé') {
  217.                         $tab['star_value']='<span class="badge progress-green p-2 border-0" >'.$value->getStatus().'</span>';
  218.                         $tab['row_tr']='row-green';
  219.                     } elseif($value->getStatus()=="Annulé") {
  220.                         $tab['star_value']='<span class="badge progress-red p-2 border-0" >'.$value->getStatus().'</span>';
  221.                         $tab['row_tr']='row-red';
  222.                     }elseif($value->getStatus()=="Bloqué") {
  223.                         $tab['star_value']='<span class="badge progress-red p-2 border-0" >'.$value->getStatus().'</span>';
  224.                         $tab['row_tr']='row-red';
  225.                     }
  226.                     elseif($value->getStatus()=="Contrat Déposé"){
  227.                         $tab['star_value']='<span class="badge progress-yellow p-2 border-0" >'.$value->getStatus().'</span>';
  228.                         $tab['row_tr']='row-yellow';
  229.                     }elseif($value->getStatus()=="Contrat Signé"){
  230.                         $tab['star_value']='<span class="badge progress-blue p-2 border-0" >'.$value->getStatus().'</span>';
  231.                         $tab['row_tr']='row-blue';
  232.                     }elseif($value->getStatus()=="Contrat généré"){
  233.                         $tab['star_value']='<span class="badge progress-yellow p-2 border-0" >'.$value->getStatus().'</span>';
  234.                         $tab['row_tr']='row-blue';
  235.                     }elseif($value->getStatus()=="En Attente"){
  236.                         $tab['star_value']='<span class="badge progress-yellow p-2 border-0" >'.$value->getStatus().'</span>';
  237.                         $tab['row_tr']='row-yellow';
  238.                     }else{
  239.                         $tab['star_value']='<span class="badge progress-grey p-2 border-0" >Nouveau</span>';
  240.                         $tab['row_tr']='row-grey';
  241.                     }
  242.                     $champsInstallateur $value->getInstallateur()->getChampsinstallateur();
  243.                     if(count($champsInstallateur) > 0){
  244.                         foreach ( $champsInstallateur as $champ) {
  245.                             if($champ->getNom() == "KBIS"){
  246.                             
  247.             
  248.                                 if ($champ->getStatus()=='Validé') {
  249.                                     $tab['kbis']='<button class="badge progress-green p-2 border-0" >'.$champ->getStatus().'</button>';
  250.                                 } elseif($champ->getStatus()=="Non Valide") {
  251.                                     $tab['kbis']='<button class="badge progress-red p-2 border-0" >'.$champ->getStatus().'</button>';
  252.                                 }elseif($champ->getStatus()=="Transmis"){
  253.                                     $tab['kbis']='<button class="badge progress-yellow p-2 border-0" >'.$champ->getStatus().'</button>';
  254.                                 }else{
  255.                                     $tab['kbis']='<button class="badge progress-grey p-2 border-0" >Non Transmis</button>';
  256.                                 }
  257.                                 
  258.                             }
  259.                         }
  260.                     } else {
  261.                         
  262.                         $tab['kbis']='<button class="badge progress-grey p-2 border-0" >Non Transmis</button>';
  263.                     }
  264.                 
  265.                     // logo, nom, prenom, role de la personne
  266.                     // date
  267.                     
  268.                     
  269.                     $tab['image_src']="https://kaje-cee.net/#";
  270.                     $deals[]=$tab;
  271.                     $i=$i 1;
  272.                 }
  273.             }
  274.             
  275.         }
  276.         // dd($deals);
  277.         // die();
  278.         $clientjson json_encode($deals);
  279.         file_put_contents('assets/json/deal-list.json'$clientjson);
  280.         return $this->render('deal/index.html.twig', [
  281.             'deals' => $dealRepository->findAll(),
  282.             'listinstallateurs' => $installateurRepository->findBy(["status"=>'Validé']),
  283.             'listobliges' => $obligesRepository->findAll(),
  284.             'champs' => $champsDefautRepository->findAll(),
  285.             'allInstallateurs' => $installateurRepository->findAll(),
  286.             'operationsStandard' => $operationStandardRepository->findAll(),
  287.             'exporte' => $exporte,
  288.             'idexporte' => $idexporte
  289.         ]);
  290.     }
  291.     /**
  292.      * @Route("/archivesdeal", name="app_deal_archivesdeal", methods={"GET", "POST"})
  293.      */
  294.     public function archivesdeal(Request $request,DealRepository $dealRepository,InstallateurRepository $installateurRepository,ObligesRepository $obligesRepository,
  295.     ChampsDefautRepository $champsDefautRepositoryChampsInstallateurRepository $champsInstallateurRepositoryUserRepository $userRepository
  296.     HistoriqueDealRepository $historiqueDealRepositoryOperationStandardRepository $operationStandardRepository): Response
  297.     {
  298.  
  299.         $deal$dealRepository->findBy(['status' => 'archive'], ['id' => 'DESC']);
  300.         $tab=[];
  301.         $deals=[];
  302.         $statuts = ["archive"];
  303.         
  304.         // id,type as owner,client as name ,date,file ,batiment
  305.         $i 1;
  306.         foreach ($statuts as $statut) {
  307.             foreach ($deal as  $value) {
  308.             
  309.                 if($statut == $value->getStatus()){
  310.                 
  311.                     $tab['id']=$i;
  312.                     $tab['id_deal']=$value->getId();
  313.                     $tab['name']=$value->getNumero();  
  314.                     $tab['owner']=$value->getInstallateur()->getSociete();
  315.                     $tab['owner_id']=$value->getInstallateur()->getId();
  316.                     if ($value->getDate()) {
  317.                     $tab['industry_type']=$value->getDate()->format('d-m-Y');
  318.                     }
  319.                     $tab['location']=$value->getTaux();
  320.                     if ($value->getDealoblige()->getOblige()) {
  321.                         $tab['contact_email']=$value->getDealoblige()->getOblige()->getSociete();
  322.                         $tab['contact_email_id']=$value->getDealoblige()->getOblige()->getId();
  323.                     }
  324.                     
  325.                     $tab['icone']="ri-delete-bin-fill";
  326.                     if ($value->getDatefin()) {
  327.                     $dateTime2 $value->getDatefin();
  328.                     $formattedDate2 $dateTime2->format('d/m/Y');
  329.                     $tab['datefin']=$formattedDate2
  330.                       }
  331.                     $tab['action_deal']=[];
  332.                     $historique null;
  333.                    if ($historiqueDealRepository->findBy(["deal" => $value->getId()])) {
  334.                         foreach ($historiqueDealRepository->findBy(["deal" => $value->getId()]) as $hist) {
  335.                             $historique $hist;
  336.                         }
  337.                    }
  338.                    
  339.                     if($historique != null) {
  340.                         $userModif $userRepository->findOneBy(["id" => $historique->getUser()]);
  341.                         if($userModif->getInstallateur() != null){
  342.                             $tab['action_deal']['action_id']=$userModif->getInstallateur()->getId();  
  343.                             $tab['action_deal']['action_nom']=$userModif->getInstallateur()->getNom();  
  344.                             $tab['action_deal']['action_prenom']=$userModif->getInstallateur()->getPrenom();  
  345.                             $tab['action_deal']['action_photo']= $userModif->getInstallateur()->getPhoto() != null "https://kaje-cee.net/assets/uplaod-installateur/".$userModif->getInstallateur()->getPhoto() : "https://kaje-cee.net/assets/images/user.png";
  346.                             $tab['action_deal']['action_role']="Installateur";  
  347.                         } else{
  348.                             $tab['action_deal']['action_id']=$userModif->getEquipe()->getId();  
  349.                             $tab['action_deal']['action_nom']=$userModif->getEquipe()->getNom();  
  350.                             $tab['action_deal']['action_prenom']=$userModif->getEquipe()->getPrenom();   
  351.                             $tab['action_deal']['action_photo']=$userModif->getEquipe()->getPhoto() != null "https://kaje-cee.net/assets/uplaod-equipe/".$userModif->getEquipe()->getPhoto() : "https://kaje-cee.net/assets/images/user.png";
  352.                             $tab['action_deal']['action_role']="Administrateur"
  353.                         }
  354.                         $dateTime $historique->getDate();
  355.                         $formattedDate $dateTime->format('d/m/Y');
  356.                         $tab['action_deal']['action_date']=$formattedDate
  357.                         $tab['action_deal']['action_commentaire']=$historique->getAction(); 
  358.                     }
  359.                     
  360.                     $tab['employee']="deal";
  361.                     if($value->getStatus()=="archive") {
  362.                         $tab['star_value']='<span class="badge progress-red p-2 border-0" >'.$value->getStatus().'</span>';
  363.                         $tab['row_tr']='row-red';
  364.                     }
  365.                    
  366.                     $champsInstallateur $value->getInstallateur()->getChampsinstallateur();
  367.                     if(count($champsInstallateur) > 0){
  368.                         foreach ( $champsInstallateur as $champ) {
  369.                             if($champ->getNom() == "KBIS"){
  370.                             
  371.             
  372.                                 if ($champ->getStatus()=='Validé') {
  373.                                     $tab['kbis']='<button class="badge progress-green p-2 border-0" >'.$champ->getStatus().'</button>';
  374.                                 } elseif($champ->getStatus()=="Non Valide") {
  375.                                     $tab['kbis']='<button class="badge progress-red p-2 border-0" >'.$champ->getStatus().'</button>';
  376.                                 }elseif($champ->getStatus()=="Transmis"){
  377.                                     $tab['kbis']='<button class="badge progress-yellow p-2 border-0" >'.$champ->getStatus().'</button>';
  378.                                 }else{
  379.                                     $tab['kbis']='<button class="badge progress-grey p-2 border-0" >Non Transmis</button>';
  380.                                 }
  381.                                 
  382.                             }
  383.                         }
  384.                     } else {
  385.                         
  386.                         $tab['kbis']='<button class="badge progress-grey p-2 border-0" >Non Transmis</button>';
  387.                     }
  388.                 
  389.                     // logo, nom, prenom, role de la personne
  390.                     // date
  391.                     
  392.                     
  393.                     $tab['image_src']="https://kaje-cee.net/#";
  394.                     $deals[]=$tab;
  395.                     $i=$i 1;
  396.                 }
  397.             }
  398.             
  399.         }
  400.         // dd($deals);
  401.         // die();
  402.         $clientjson json_encode($deals);
  403.         file_put_contents('assets/json/deal-list.json'$clientjson);
  404.         return $this->render('deal/archivesdeal.html.twig', [
  405.             'deals' => $dealRepository->findAll(),
  406.             'allInstallateurs' => $installateurRepository->findAll()
  407.         ]);
  408.     }
  409.     
  410.     
  411.      /**
  412.      * @Route("/dealdesarchives", name="app_deal_desarchives", methods={"GET", "POST"})
  413.      */
  414.     public function dealdesarchives(Request $request,DepotDossierRepository $depotDossierRepository,DealRepository $dealRepository): Response
  415.     {
  416.         if ($request->getMethod() == "POST") {
  417.             $form $request->request
  418.            //dd($form);
  419.            if ($form->get("chk_deal") != null) {
  420.                 foreach ($form->get("chk_deal") as $key => $value) {
  421.                     $deal $dealRepository->findOneBy(["id"=>intval($value)]);
  422.                    
  423.                    if ($deal->getDepotDossiers() != null) {
  424.                         foreach ($deal->getDepotDossiers() as $key => $dossier) {
  425.                             $dossier->setStatus($dossier->getArchive());
  426.                             $depotDossierRepository->add($dossiertrue);
  427.                         }
  428.                    }
  429.                    
  430.                     $deal->setStatus($deal->getArchive());
  431.                     $dealRepository->add($dealtrue);
  432.                    
  433.                     
  434.                 }
  435.            }
  436.         }
  437.         return $this->redirectToRoute('app_deal_index', [], Response::HTTP_SEE_OTHER);
  438.     }
  439.     /**
  440.      * @Route("/new", name="app_deal_new", methods={"GET", "POST"})
  441.      */
  442.     public function new(Request $requestDealRepository $dealRepository,InstallateurRepository $installateurRepository,
  443.     ObligesRepository $obligesRepository,ChampsDealRepository $champsDealRepository,ChampsDefautDealRepository $champsDefautDealRepository,
  444.     ChampsDefautRepository $champsDefautRepository,OperationStandardRepository $operationStandardRepository,
  445.     ApporteurAffaireRepository $apporteurAffaireRepository,ActiviteDealRepository $activiteDealRepository,
  446.     NotificationsRepository $notificationsRepositoryHistoriqueDealRepository $historiqueDealRepository,DealobligeRepository $dealobligeRepository): Response
  447.     {
  448.         $deal = new Deal();
  449.         if ($request->getMethod() == "POST") {
  450.                 $form $request->request;
  451.                 $dealoblige$dealobligeRepository->findOneBy(["id"=>intval($form->get('oblige'))]);
  452.                 $installateur$installateurRepository->findOneBy(["id"=>intval($form->get('installateur'))]);
  453.                 $deal->setNumero($dealoblige->getNom().'-'.$installateur->getSociete());
  454.                 $deal->setType($form->get('parties'));
  455.                 $deal->setTaux($form->get('taux'));
  456.                 $cible='';
  457.                 // dd($form->get('cible'));
  458.                  if ($form->get('cible')) {
  459.                      foreach ($form->get('cible') as $key => $value) {
  460.                         
  461.                              $cible.=$value."-";
  462.                          
  463.                          
  464.                      }
  465.                  }
  466.                 
  467.                  $deal->setCible($cible); 
  468.                 $date date('d-m-Y'strtotime($form->get('date'))) ;
  469.                 
  470.                 $datetime = new Datetime($date);
  471.                 $deal->setDatefin($datetime); 
  472.                 $deal->setDate(new Datetime()); 
  473.                 $deal->setStatus("Nouveau"); 
  474.                 
  475.                 
  476.                 
  477.                 
  478.                 $deal->setInstallateur($installateur);
  479.                 
  480.                 $deal->setOblige($dealoblige->getOblige());
  481.                 $deal->setDealoblige($dealoblige);
  482.                 $oblige=$dealoblige->getOblige();
  483.                 if ($form->get('apporteur')!=null) {
  484.                     
  485.                     $apporteur$apporteurAffaireRepository->findOneBy(["id"=>intval($form->get('apporteur'))]);
  486.                     $deal->setApporteurAffaire($apporteur);
  487.                 }
  488.                 $dealRepository->add($dealtrue);
  489.                 
  490.                 foreach ($oblige->getChampsobliges() as  $chmps) {
  491.                        $champsDeal = new ChampsDeal();
  492.                       
  493.                        $champsDeal->setNom($chmps->getNom());
  494.                        $champsDeal->setType($chmps->getType());
  495.                        if ($chmps->getType()== 'file') {
  496.                         $champsDeal->setStatus('Non Transmis');
  497.                        }
  498.                        $champsDeal->setDurevalidite($chmps->getDurevalidite());
  499.                        $champsDeal->setDeal($deal);
  500.                        
  501.                        $champsDealRepository->add($champsDealtrue);
  502.                 }
  503.                 foreach ($form as $key => $value) {
  504.                     
  505.                     if (count(explode("_",$key)) >&& explode("_",$key)[1]=="old"){
  506.                         
  507.                         $champsDeal = new ChampsDeal();
  508.                        $chmps$champsDefautDealRepository->find(["id"=>intval($value)]);
  509.                        $champsDeal->setNom($chmps->getNom());
  510.                        $champsDeal->setType($chmps->getType());
  511.                        if ($chmps->getType()== 'file') {
  512.                         $champsDeal->setStatus('Non Transmis');
  513.                        }
  514.                        $champsDeal->setDurevalidite($chmps->getDurevalidite());
  515.                        $champsDeal->setDeal($deal);
  516.                        
  517.                        $champsDealRepository->add($champsDealtrue);
  518.     
  519.                     }
  520.                     
  521.                     if ( count(explode("_",$key)) >&& explode("_",$key)[2]=="type") {
  522.     
  523.                         if (explode("_",$key)[3]=="nom") {
  524.                             $champs->setNom($value);
  525.                            
  526.                         }elseif(explode("_",$key)[3]=="dure"){
  527.                             
  528.                             if($value!=null){
  529.                                 $champs->setDurevalidite($value);
  530.                             }
  531.                             
  532.                             $champsDefautDealRepository->add($champstrue);
  533.     
  534.                             $champsDeal = new ChampsDeal();
  535.     
  536.                             $champsDeal->setNom($champs->getNom());
  537.                             $champsDeal->setType($champs->getType());
  538.                             if ($champs->getType()== 'file') {
  539.                                 $champsDeal->setStatus('Non Transmis');
  540.                                }
  541.                             $champsDeal->setDurevalidite($champs->getDurevalidite());
  542.                             $champsDeal->setDeal($deal);
  543.                             $champsDealRepository->add($champsDealtrue);
  544.                         }
  545.                         else{
  546.                             
  547.                             $champs = new ChampsDefautDeal();
  548.                             $champs->setType($value);
  549.                         }
  550.                    
  551.                     }
  552.                 }
  553.                // Notif Installateur
  554.                $notifications = new Notifications();
  555.                $notifications->setUserId($installateur->getUser());
  556.                $notifications->setMessage("Vous avez un nouveau deal. Veuillez remplir les informations.");
  557.                $notifications->setAction("app_deal_edit");
  558.                $notifications->setActionId($deal->getId());
  559.                $notifications->setSender($this->getUser());
  560.                $notifications->setStatuts("non lu");
  561.                $notifications->setDate(new DateTime());
  562.                
  563.                $notificationsRepository->add($notificationstrue);
  564.                
  565.                // Notif Obligé
  566.                $notificationsOblige = new Notifications();
  567.                $notificationsOblige->setUserId($oblige->getUser());
  568.                $notificationsOblige->setMessage("Un nouveau deal a été créé.");
  569.                $notificationsOblige->setAction("app_deal_edit");
  570.                $notificationsOblige->setActionId($deal->getId());
  571.                $notificationsOblige->setSender($this->getUser());
  572.                $notificationsOblige->setStatuts("non lu");
  573.                $notificationsOblige->setDate(new DateTime());
  574.                
  575.                $notificationsRepository->add($notificationsObligetrue);
  576.                 $activiteDeal = new ActiviteDeal();
  577.                 $activiteDeal->setFonction('equipe');
  578.                 $activiteDeal->setEquipe($this->getUser()->getEquipe());
  579.                 $activiteDeal->setCommentaire("Création du Deal entre l'installateur ".$deal->getInstallateur()->getSociete()." et l'obligé ".$deal->getDealoblige()->getOblige()->getSociete());
  580.                 $activiteDeal->setDate(new Datetime());
  581.                 $activiteDeal->setDeal($deal);
  582.                 $activiteDealRepository->add($activiteDealtrue);
  583.                 // Historique
  584.                $historiqueDeal = new HistoriqueDeal();
  585.                $historiqueDeal->setUser($this->getUser());
  586.                $historiqueDeal->setDeal($deal);
  587.                $historiqueDeal->setDate(new DateTime());
  588.                $historiqueDeal->setAction("Création du Deal ".$deal->getNumero());
  589.                $historiqueDealRepository->add($historiqueDealtrue);
  590.                 return $this->redirectToRoute('app_deal_edit', ['id' =>$deal->getId()], Response::HTTP_SEE_OTHER);
  591.         }
  592.         // $form = $this->createForm(DealType::class, $deal);
  593.         // $form->handleRequest($request);
  594.         // if ($form->isSubmitted() && $form->isValid()) {
  595.         //     $dealRepository->add($deal, true);
  596.         //     return $this->redirectToRoute('app_deal_index', [], Response::HTTP_SEE_OTHER);
  597.         // }
  598.         // 'listinstallateurs' => $installateurRepository->findBy(["status"=>'Validé']),
  599.         if ($request->query->get('insparam') != null ) {
  600.             $idinstallateurGet $request->query->get('insparam');
  601.         } else {
  602.             $idinstallateurGet 0;
  603.         }
  604.         return $this->renderForm('deal/new.html.twig', [
  605.             'deal' => $deal,
  606.             'listinstallateurs' => $installateurRepository->findAll(),
  607.             'listobliges' => $obligesRepository->findAll(),
  608.             'listdealobliges' => $dealobligeRepository->findAll(),
  609.             'champs' => $champsDefautRepository->findAll(),
  610.             'dealoperations' => $operationStandardRepository->findAll(),
  611.             'listapporteurs' => $apporteurAffaireRepository->findAll(),
  612.             'idinstallateurGet' => $idinstallateurGet
  613.         ]);
  614.     }
  615.     /**
  616.      * @Route("/{id}", name="app_deal_show", methods={"GET"})
  617.      */
  618.     public function show(Deal $deal): Response
  619.     {
  620.         if ($this->isGranted('ROLE_INSTALLATEUR')) {
  621.             $deals=$this->getUser()->getInstallateur()->getDeals();
  622.             foreach ($deals as  $value) {
  623.                 if ($value->getId() == $deal->getId()) {
  624.                     return $this->redirectToRoute('app_deal_edit', ['id' =>$deal->getId()], Response::HTTP_SEE_OTHER);
  625.                 }
  626.             }
  627.             return $this->redirectToRoute('app_deal_index', [], Response::HTTP_SEE_OTHER);
  628.          
  629.         }else{
  630.             return $this->redirectToRoute('app_deal_edit', ['id' =>$deal->getId()], Response::HTTP_SEE_OTHER);
  631.         }
  632.        
  633.     }
  634.      /**
  635.      * @Route("/{id}/edit", name="app_deal_edit", methods={"GET", "POST"})
  636.      */
  637.     public function edit(Request $requestDeal $dealDealRepository $dealRepository,ChampsDealRepository $champsDealRepository,
  638.     ChampsDefautDealRepository $champsDefautDealRepository,ActiviteDealRepository $activiteDealRepository,NotificationsRepository $notificationsRepository
  639.     EquipeRepository $equipeRepositoryHistoriqueDealRepository $historiqueDealRepository,SoustraitantRepository $soustraitantRepository,
  640.     OperationStandardRepository $operationStandardRepository): Response
  641.     {
  642.         $dealCommentaire $deal->getCommentaire();
  643.         
  644.         $isCompleted "oui";
  645.         if ($this->isGranted('ROLE_INSTALLATEUR')) {
  646.             
  647.             if ($this->getUser()->getInstallateur()->getId() != $deal->getInstallateur()->getId()) {
  648.                 return $this->redirectToRoute('app_deal_index', [], Response::HTTP_SEE_OTHER);
  649.             }
  650.             if($deal->getInstallateur()->getNom() == null || $deal->getInstallateur()->getPrenom() == null || $deal->getInstallateur()->getSociete() == null || 
  651.                 $deal->getInstallateur()->getPhone() == null || $deal->getInstallateur()->getEmail() == null || $deal->getInstallateur()->getAdresse() == null ){
  652.                     $isCompleted "non";
  653.             }
  654.             foreach($deal->getInstallateur()->getChampsinstallateur() as $key => $value){
  655.                 if($value->getType() !="file" && $value->getValeur() == null){
  656.                     $isCompleted "non";
  657.                 }
  658.                 if($value->getType() =="file" && $value->getStatus() == "Non Transmis"){
  659.                     $isCompleted "non";
  660.                 }
  661.             }
  662.             if(count($deal->getInstallateur()->getOperationStandards()) < 1){
  663.                 $isCompleted "non";
  664.             }
  665.         }
  666.         
  667.         if ($request->getMethod() == "POST") {
  668.             
  669.             $form $request->request;
  670.            
  671.             // $deal->setNumero($form->get('nom'));
  672.             if (!$this->isGranted('ROLE_INSTALLATEUR')) {
  673.                 $deal->setNumero($form->get('nom'));
  674.                 if($form->get('parties')){
  675.                     $deal->setType($form->get('parties'));
  676.                 }
  677.                 if($form->get('taux')){
  678.                     $deal->setTaux($form->get('taux'));
  679.                 }
  680.                
  681.                 $cible='';
  682.                // dd($form->get('cible'));
  683.                 if ($form->get('cible')) {
  684.                     foreach ($form->get('cible') as $key => $value) {
  685.                        
  686.                             $cible.=$value."-";
  687.                         
  688.                         
  689.                     }
  690.                     $deal->setCible($cible); 
  691.                 }
  692.                
  693.                 
  694.                     $date date('d-m-Y'strtotime($form->get('date'))) ;
  695.                 
  696.                     $datetime = new Datetime($date);
  697.                     // var_dump($form->get('date'));
  698.                     // var_dump($date);
  699.                     //  var_dump($datetime);die('test');
  700.                 $deal->setDatefin($datetime); 
  701.                 $deal->setDate(new Datetime()); 
  702.                 
  703.                 
  704.                 $deal->setCommentaire($form->get('commentaire')); 
  705.                
  706.                 
  707.             }
  708.             if ($form->get('soustraitants') != null) {
  709.                 foreach ($deal->getSoustraitants() as  $value) {
  710.                     if (!in_array($value->getId(),$form->get('soustraitants'))) {
  711.                      $deal->removeSoustraitant($value);
  712.                     }
  713.                  }
  714.                  foreach ($form->get('soustraitants') as  $value) {
  715.                     $soustraitant$soustraitantRepository->findOneBy(["id"=>intval($value)]);
  716.                     
  717.                     $deal->addSoustraitant($soustraitant);
  718.                 }
  719.                }else{
  720.                 foreach ($deal->getSoustraitants() as  $value) {
  721.                    
  722.                      $deal->removeSoustraitant($value);
  723.                     
  724.                  }
  725.                }
  726.             if ($form->get('operations') != null) {
  727.                 foreach ($deal->getOperation() as  $value) {
  728.                     if (!in_array($value->getId(),$form->get('operations'))) {
  729.                         $deal->removeOperation($value);
  730.                     }
  731.                  }
  732.                  foreach ($form->get('operations') as  $value) {
  733.                     $ops$operationStandardRepository->findOneBy(["id"=>intval($value)]);
  734.                     $deal->addOperation($ops);
  735.                 }
  736.                }else{
  737.                 foreach ($deal->getOperation() as  $value) {
  738.                    
  739.                     $deal->removeOperation($value);
  740.                     
  741.                  }
  742.                }
  743.                 $activiteDeal = new ActiviteDeal();
  744.                 $historiqueDeal = new HistoriqueDeal();
  745.                 if ($this->isGranted('ROLE_INSTALLATEUR')) {
  746.                     $activiteDeal->setFonction('installateur');
  747.                     $activiteDeal->setInstallateur($this->getUser()->getInstallateur());
  748.                     $activiteDeal->setCommentaire("Modification des éléments ");
  749.                     $historiqueDeal->setAction("Modification du Deal ".$deal->getNumero());
  750.                 }else{
  751.                     $activiteDeal->setFonction('equipe');
  752.                     $activiteDeal->setEquipe($this->getUser()->getEquipe());
  753.                     if($deal->getStatus() != $form->get('status')){
  754.                         $activiteDeal->setCommentaire($this->getUser()->getEquipe()->getPrenom()." a modifié le statut en : ".$form->get('status'));
  755.                         $historiqueDeal->setAction($this->getUser()->getEquipe()->getPrenom()." a modifié le statut en : ".$form->get('status'));
  756.                      }else{
  757.                         $activiteDeal->setCommentaire("Modification des éléments ");
  758.                         $historiqueDeal->setAction("Modification du Deal ".$deal->getNumero());
  759.                      }
  760.                      $deal->setStatus($form->get('status')); 
  761.                 }
  762.                 
  763.                 
  764.                 $activiteDeal->setDate(new Datetime());
  765.                 $activiteDeal->setDeal($deal);
  766.                 $activiteDealRepository->add($activiteDealtrue);
  767.                 // Historique
  768.                
  769.                $historiqueDeal->setUser($this->getUser());
  770.                $historiqueDeal->setDeal($deal);
  771.                $historiqueDeal->setDate(new DateTime());
  772.                
  773.                $historiqueDealRepository->add($historiqueDealtrue);
  774.            
  775.            
  776.             $dealRepository->add($dealtrue);
  777.             if ($form->get('status') == "Validé") {
  778.                 // Notif Installateur
  779.                $notifications = new Notifications();
  780.                $notifications->setUserId($deal->getInstallateur()->getUser());
  781.                $notifications->setMessage("Deal ".$deal->getNumero()." est Validé !!!");
  782.                $notifications->setAction("app_deal_edit");
  783.                $notifications->setActionId($deal->getId());
  784.                $notifications->setSender($this->getUser());
  785.                $notifications->setStatuts("non lu");
  786.                $notifications->setDate(new DateTime());
  787.                
  788.                $notificationsRepository->add($notificationstrue);
  789.     
  790.     
  791.                $activiteDeal = new ActiviteDeal();
  792.                $activiteDeal->setFonction('equipe');
  793.                $activiteDeal->setEquipe($this->getUser()->getEquipe());
  794.                $activiteDeal->setCommentaire("Deal ".$deal->getNumero()." est Validé !!!");
  795.                $activiteDeal->setDate(new Datetime());
  796.                $activiteDeal->setDeal($deal);
  797.                $activiteDealRepository->add($activiteDealtrue);
  798.             }
  799.           
  800.        
  801.             foreach ($form as $key => $value) {
  802.                     if (count(explode("-",$key)) ==&& explode("-",$key)[0]=="champsinstallateur") {
  803.                         $id=$form->get('champsinstvaleur-'.explode("-",$key)[1]);
  804.                         $champsinst$champsDealRepository->findOneBy(["id" => $id]);
  805.                         $valeur=[];
  806.                         $valeur[]=$value;
  807.                         if ($champsinst->getValeur() != null ) {
  808.                             foreach ($champsinst->getValeur() as $key => $val) {
  809.                                 $valeur[]=$val;
  810.                             }
  811.                         }
  812.                         
  813.                         $champsinst->setValeur($valeur);
  814.                         // $champsinst->setValeur($value);
  815.                         if ($champsinst->getStatus()==null) {
  816.                             $champsinst->setStatus('Non Transmis');
  817.                          }else{
  818.                             $champsinst->setStatus('Transmis');
  819.                          }
  820.                         $date = new Datetime();
  821.                         $champsinst->setDate($date);
  822.                         $champsDealRepository->add($champsinsttrue);
  823.                       
  824.                     }
  825.     
  826.                     if (count(explode("_",$key)) >&& explode("_",$key)[1]=="old"){
  827.                         
  828.                         $champsDeal = new ChampsDeal();
  829.                        $chmps$champsDefautDealRepository->find(["id"=>intval($value)]);
  830.                        $champsDeal->setNom($chmps->getNom());
  831.                        $champsDeal->setType($chmps->getType());
  832.                        if($chmps->getDurevalidite()!=null){
  833.                            $champsDeal->setDurevalidite($chmps->getDurevalidite());
  834.                          }
  835.                        if ($champsDeal->getStatus()==null) {
  836.                                 $champsDeal->setStatus('Non Transmis');
  837.                             }else{
  838.                                 $champsDeal->setStatus('Transmis');
  839.                             }
  840.                        $champsDeal->setDeal($deal);
  841.                        
  842.                        $champsDealRepository->add($champsDealtrue);
  843.     
  844.                     }
  845.                     
  846.                     if ( count(explode("_",$key)) >&& explode("_",$key)[2]=="type") {
  847.     
  848.                         if (explode("_",$key)[3]=="nom") {
  849.                             $champs->setNom($value);
  850.                             if($champs->getType() != "file"){
  851.                                 $champsDefautDealRepository->add($champstrue);
  852.                                 $champsDeal = new ChampsDeal();
  853.                                 $champsDeal->setNom($champs->getNom());
  854.                                 $champsDeal->setType($champs->getType());
  855.                                 $champsDeal->setDeal($deal);
  856.                                 $champsDealRepository->add($champsDealtrue);
  857.                             }
  858.                             
  859.     
  860.                         }elseif(explode("_",$key)[3]=="dure"){
  861.                             if($champs->getType() == "file"){
  862.                             $champsDeal = new ChampsDeal();
  863.     
  864.                             if($value!=null){
  865.                                 $champsDeal->setDurevalidite($value);
  866.                             }
  867.                             $champsDeal->setNom($champs->getNom());
  868.                             $champsDeal->setType($champs->getType());
  869.                             $champsDeal->setDeal($deal);
  870.                             if ($champsDeal->getStatus()==null) {
  871.                                 $champsDeal->setStatus('Non Transmis');
  872.                             }else{
  873.                                 $champsDeal->setStatus('Transmis');
  874.                             }
  875.                             $champsDealRepository->add($champsDealtrue);
  876.                             }
  877.                         }
  878.                         else{
  879.                             
  880.                             $champs = new ChampsDefautDeal();
  881.                             $champs->setType($value);
  882.                         }
  883.                    
  884.                     }
  885.             }
  886.                 
  887.             return $this->redirectToRoute('app_deal_edit', ['id' =>$deal->getId()], Response::HTTP_SEE_OTHER);
  888.         }
  889.         // $form = $this->createForm(DealType::class, $deal);
  890.         // $form->handleRequest($request);
  891.         // if ($form->isSubmitted() && $form->isValid()) {
  892.         //     $dealRepository->add($deal, true);
  893.         //     return $this->redirectToRoute('app_deal_index', [], Response::HTTP_SEE_OTHER);
  894.         // }
  895.        
  896.         if ($this->isGranted('ROLE_INSTALLATEUR')) {
  897.             $notif $notificationsRepository->findAll(["user_id" => $deal->getInstallateur()->getUser(),"statuts"=> "non lu""action" => "app_deal_edit""action_id" => $deal->getId()]);
  898.             if ($notif) {
  899.                 foreach ($notif as $key => $value) {
  900.                     $datefinnotif $value->getDate();
  901.                     $dateday2 = new DateTime();
  902.                     // Ajouter 2 jours
  903.                     $datefinnotif->modify('+2 days');
  904.                    // dd($datefinnotif);
  905.                         $value->setStatuts("lu");
  906.                         $notificationsRepository->add($valuetrue);
  907.                     // if ($dateday2 > $datefinnotif) {
  908.                         
  909.                     // }
  910.                    
  911.                 }
  912.                 
  913.             }
  914.            
  915.         }
  916.         
  917.         
  918.         $champsdefaut=[];
  919.         $champsvalide=0;
  920.         foreach ($deal->getChampsdeal() as $champs) {
  921.                 foreach ($champsDefautDealRepository->findAll()  as  $value) {
  922.                     if ($value->getNom() == $champs->getNom()) {
  923.                         $champsdefaut[]=$value;
  924.                     }
  925.                 }
  926.                 if ($champs->getStatus() != "Validé" and $champs->getType() == "file" ) {
  927.                     $champsvalide=$champsvalide 1;
  928.                 }
  929.                
  930.         }
  931.         foreach ($deal->getInstallateur()->getChampsinstallateur() as $champs) {
  932.             if ($champs->getStatus() != "Validé" and $champs->getType() == "file" ) {
  933.                 $champsvalide=$champsvalide 1;
  934.             }
  935.         }
  936.         //dd($champsvalide);
  937.         return $this->renderForm('deal/edit.html.twig', [
  938.             'deal' => $deal,
  939.             'champsdefaut' => $champsdefaut,
  940.             "dateday"=>new Datetime(),
  941.             'isCompleted' => $isCompleted,
  942.             'champsvalide' => $champsvalide,
  943.             'operationsStandars' => $operationStandardRepository->findAll(),
  944.         ]);
  945.     }
  946.     
  947.     /**
  948.      * @Route("/{id}", name="app_deal_delete", methods={"POST"})
  949.      */
  950.     public function delete(Request $requestDeal $dealDealRepository $dealRepository,ChampsDealRepository $champsDealRepository,ActiviteDealRepository $activiteDealRepository
  951.     NotificationsRepository $notificationsRepository,HistoriqueDealRepository $historiqueDealRepository,FactureAafRepository $factureAafRepository,AppelqualiteRepository $appelqualiteRepository,
  952.     SoustraitantRepository $soustraitantRepositor,ContratRepository $contratRepository,
  953.     DepotDossierRepository $depotDossierRepository,ChampsDepotDossierRepository $champsDepotDossierRepository,CommentairesControlleRepository $commentairesControlleRepository): Response
  954.     {
  955.         if ($this->isCsrfTokenValid('delete'.$deal->getId(), $request->request->get('_token'))) {
  956.             foreach ($deal->getChampsDeal() as  $value) {
  957.            
  958.                 $deal->removeChampsDeal($value);
  959.                 $champsDealRepository->remove($valuetrue);
  960.                
  961.             }
  962.             foreach ($notificationsRepository->findBy(["action_id"=>$deal->getId()]) as  $value) {
  963.                 $notificationsRepository->remove($valuetrue);
  964.              }
  965.             foreach ($deal->getActiviteDeals() as  $value) {
  966.            
  967.                 $deal->removeActiviteDeal($value);
  968.                 $activiteDealRepository->remove($valuetrue);
  969.                
  970.             }
  971.             foreach ($deal->getHistoriqueDeals() as  $value) {
  972.            
  973.                 $deal->removeHistoriqueDeal($value);
  974.                 $historiqueDealRepository->remove($valuetrue);
  975.                
  976.             }
  977.             foreach ($deal->getOperation() as  $value) {
  978.            
  979.                 $deal->removeOperation($value);
  980.                 
  981.                
  982.             }
  983.             if($deal->getApporteurAffaire()){
  984.                 $deal->setApporteurAffaire(NULL);
  985.             }
  986.             
  987.             
  988.             foreach ($deal->getDepotDossiers() as $dossier) {
  989.            
  990.                 foreach ($dossier->getChampsDepotDossiers() as $champdossier) {
  991.                     $champsDepotDossierRepository->remove($champdossiertrue);
  992.                 }
  993.                 foreach ($dossier->getCommentairesControlles() as $commentaire) {
  994.                     $commentairesControlleRepository->remove($commentairetrue);
  995.                 }
  996.                 foreach ($dossier->getSoustraitants() as  $value) {
  997.            
  998.                     $dossier->removeSoustraitant($value);
  999.     
  1000.                    // $soustraitantRepository->remove($value, true);
  1001.                    
  1002.                 }
  1003.                 foreach ($dossier->getFactureAafs() as  $value) {
  1004.        
  1005.                     // $depotDossier->removeFactureAaf($value);
  1006.                     foreach ($value->getCommentaireFactureaafs() as  $commentaire) {
  1007.                         $value->removeCommentaireFactureaaf($commentaire);
  1008.         
  1009.                         // $activiteDealRepository->remove($commentaire, true);
  1010.                     
  1011.                     }
  1012.                     $factureAafRepository->remove($valuetrue);
  1013.                    
  1014.                 }
  1015.     
  1016.                 foreach ($dossier->getAppelqualites() as  $value) {
  1017.                     foreach ($value->getCommentaireAppelqualites() as  $commentaire) {
  1018.                         $value->removeCommentaireAppelqualite($commentaire);
  1019.         
  1020.                         // $activiteDealRepository->remove($commentaire, true);
  1021.                     
  1022.                     }
  1023.                     // $depotDossier->removeAppelqualite($value);
  1024.     
  1025.                     $appelqualiteRepository->remove($valuetrue);
  1026.                    
  1027.                 }
  1028.                 $depotDossierRepository->remove($dossiertrue);
  1029.         
  1030.             }
  1031.             foreach ($deal->getCommentaireDeals() as  $commentaire) {
  1032.                     
  1033.                 $deal->removeCommentaireDeal($commentaire);
  1034.                 // $activiteDealRepository->remove($commentaire, true);
  1035.             
  1036.             }
  1037.             
  1038.             foreach ($deal->getSoustraitants() as  $soustritant) {
  1039.                 $deal->removeSoustraitant($soustritant);
  1040.                 // $activiteDealRepository->remove($commentaire, true);
  1041.             
  1042.             }
  1043.             if($deal->getContrat()){
  1044.                 foreach ($deal->getContrat()->getCommentaireContrats() as  $commentaire) {
  1045.                     $deal->getContrat()->removeCommentaireContrat($commentaire);
  1046.     
  1047.                     // $activiteDealRepository->remove($commentaire, true);
  1048.                 
  1049.                 }
  1050.                 $contratRepository->remove($deal->getContrat(), true);
  1051.             }
  1052.             
  1053.             
  1054.             
  1055.             $dealRepository->remove($dealtrue);
  1056.         }
  1057.         return $this->redirectToRoute('app_deal_index', [], Response::HTTP_SEE_OTHER);
  1058.     }
  1059.     /**
  1060.      * @Route("/zip/{id}", name="app_deal_zip",  methods={"GET", "POST"})
  1061.      */
  1062.     public function zip(Deal $deal,Request $request): Response
  1063.     {
  1064.         
  1065.        
  1066.         // Créez un nom de fichier unique pour le fichier ZIP
  1067.         $zipFileName 'Archiver_Deal_'.$deal->getInstallateur()->getSociete().'_' date('d-m-Y-His') . '.zip';
  1068.     
  1069.         // Créez le chemin absolu vers le fichier ZIP
  1070.         $zipFilePath $this->getParameter('installateur_directory') . '/archiver/' $zipFileName;
  1071.     
  1072.         // Utilisez la classe ZipArchive pour créer le fichier ZIP
  1073.         $zip = new \ZipArchive();
  1074.         $zip->open($zipFilePath\ZipArchive::CREATE \ZipArchive::OVERWRITE);
  1075.     
  1076.         
  1077.             
  1078.        
  1079.             foreach ($deal->getInstallateur()->getChampsinstallateur() as $value) {
  1080.                 if ($value->getType()=="file") {
  1081.                     if ($value->getValeur()!=null) {
  1082.                         
  1083.                      $filePath $this->getParameter('installateur_directory')."/".$value->getValeur()[0];
  1084.                      $relativePath $deal->getInstallateur()->getSociete()."/".$value->getValeur()[0];
  1085.                      if (file_exists($filePath)) {
  1086.                         $zip->addFile($filePath$relativePath);
  1087.                     }
  1088.                     // $zip->addFile($filePath, $relativePath);
  1089.                     }
  1090.                  }
  1091.                 
  1092.                  
  1093.             }
  1094.             foreach ($deal->getChampsDeal() as $value) {
  1095.                 if ($value->getType()=="file") {
  1096.                     if ($value->getValeur()!=null) {
  1097.                      //dd($value->getValeur()[0]);
  1098.                      $filePath $this->getParameter('installateur_directory')."/".$value->getValeur()[0];
  1099.                      $relativePath $deal->getInstallateur()->getSociete()."/".$value->getValeur()[0];
  1100.                      if (file_exists($filePath)) {
  1101.                         $zip->addFile($filePath$relativePath);
  1102.                     }
  1103.                     // $zip->addFile($filePath, $relativePath);
  1104.                     }
  1105.                  }
  1106.                 
  1107.                  
  1108.             }
  1109.             // Fermer le fichier ZIP
  1110.             $zip->close();
  1111.             // Envoyer le fichier ZIP en tant que réponse de téléchargement
  1112.             $response = new BinaryFileResponse($zipFilePath);
  1113.             $response->headers->set('Content-Type''application/zip');
  1114.             $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT$zipFileName);
  1115.             // if ($filesystem->exists($sourceFolder)) {
  1116.             //     // Supprimez tous les fichiers et dossiers à l'intérieur du dossier
  1117.             //     $filesystem->remove(glob($sourceFolder . '/*'));
  1118.             // }
  1119.             return $response;
  1120.                 // return $this->redirectToRoute('app_installateur_sow', ['id' => $this->getUser()->getInstallateur()->getId()], Response::HTTP_SEE_OTHER);
  1121.       
  1122.        
  1123.         
  1124.     }
  1125.         /**
  1126.      * @Route("/{id}/archives", name="app_deal_archives", methods={"GET", "POST"})
  1127.      */
  1128.     public function archives(Request $request,Deal $deal): Response
  1129.     {
  1130.         
  1131.         if ($request->getMethod() == "POST") {
  1132.             $form $request->request;
  1133.         
  1134.        
  1135.         // Créez un nom de fichier unique pour le fichier ZIP
  1136.         $zipFileName 'Deal_'.$deal->getInstallateur()->getSociete().'_' date('d-m-Y-His') . '.zip';
  1137.     
  1138.         // Créez le chemin absolu vers le fichier ZIP
  1139.         $zipFilePath $this->getParameter('installateur_directory') . '/archiver/' $zipFileName;
  1140.     
  1141.         // Utilisez la classe ZipArchive pour créer le fichier ZIP
  1142.         $zip = new \ZipArchive();
  1143.         $zip->open($zipFilePath\ZipArchive::CREATE \ZipArchive::OVERWRITE);
  1144.     
  1145.       
  1146.             
  1147.             // foreach ($deal->getInstallateur()->getChampsinstallateur() as $value) {
  1148.             //     if ($value->getType()=="file") {
  1149.             //         if ($value->getValeur()!=null) {
  1150.                      
  1151.             //          $filePath = $this->getParameter('installateur_directory').'/'.$value->getValeur();
  1152.             //          $relativePath = $deal->getInstallateur()->getSociete()."/".$value->getValeur();
  1153.             //          $zip->addFile($filePath, $relativePath);
  1154.             //         }
  1155.             //      }
  1156.                 
  1157.                  
  1158.             // }
  1159.             if ($form->get("chk_archiverdeal") != null ) {
  1160.                 foreach ($form->get("chk_archiverdeal") as $key => $champs) {
  1161.                     foreach ($deal->getChampsDeal() as $value) {
  1162.                         if ($value->getType()=="file") {
  1163.                             if ($value->getId() == $champs) {
  1164.                                 if ($value->getValeur()!=null) {
  1165.                                     foreach ($value->getValeur() as $val) {
  1166.                                         $filePath $this->getParameter('installateur_directory').'/'.$val;
  1167.                                         $relativePath $deal->getInstallateur()->getSociete()."/".$val;
  1168.                                         $zip->addFile($filePath$relativePath);
  1169.                                     }
  1170.                                     
  1171.                                 }
  1172.                             }
  1173.                         }
  1174.                         
  1175.                          
  1176.                     }
  1177.                 }
  1178.             }
  1179.             if ($form->get("chk_archiverinstallateur") != null ) {
  1180.                 foreach ($form->get("chk_archiverinstallateur") as $key => $champs) {
  1181.                     foreach ($deal->getInstallateur()->getChampsinstallateur() as $value) {
  1182.                         if ($value->getType()=="file") {
  1183.                             if ($value->getId() == $champs) {
  1184.                                 if ($value->getValeur()!=null) {
  1185.                                     foreach ($value->getValeur() as $val) {
  1186.                                         $filePath $this->getParameter('installateur_directory').'/'.$val;
  1187.                                         $relativePath $deal->getInstallateur()->getSociete()."/".$val;
  1188.                                         $zip->addFile($filePath$relativePath);
  1189.                                     }
  1190.                                     
  1191.                                 }
  1192.                             }
  1193.                         }
  1194.                         
  1195.                          
  1196.                     }
  1197.                 }
  1198.             }
  1199.            
  1200.             
  1201.             // Fermer le fichier ZIP
  1202.             $zip->close();
  1203.             // Envoyer le fichier ZIP en tant que réponse de téléchargement
  1204.             $response = new BinaryFileResponse($zipFilePath);
  1205.             $response->headers->set('Content-Type''application/zip');
  1206.             $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT$zipFileName);
  1207.             // if ($filesystem->exists($sourceFolder)) {
  1208.             //     // Supprimez tous les fichiers et dossiers à l'intérieur du dossier
  1209.             //     $filesystem->remove(glob($sourceFolder . '/*'));
  1210.             // }
  1211.             return $response;
  1212.             }
  1213.             return $this->redirectToRoute('app_deal_edit', ['id' =>$deal->getId()], Response::HTTP_SEE_OTHER);
  1214.       
  1215.        
  1216.         
  1217.     }
  1218.   /**
  1219.      * @Route("/commentaire/{id}", methods={"POST"})
  1220.      */
  1221.     public function commentaire(Request $request,CommentaireDealRepository $commentaireDealRepository,Deal $deal): JsonResponse
  1222.     
  1223.         
  1224.         
  1225.   
  1226.         if ($request->getMethod() == "POST") {
  1227.             
  1228.             // $file=$request->files->get('validedocument');
  1229.             $commentaire $request->request->get('commentaire');
  1230.           
  1231.              if ($commentaire) {
  1232.                
  1233.                     $commentaireDeal = new CommentaireDeal();
  1234.                     
  1235.                     $commentaireDeal->setCommentaire($commentaire);
  1236.                     $commentaireDeal->setDate(new DateTime());
  1237.                     $commentaireDeal->setDeal($deal);
  1238.                     $commentaireDeal->setUser($this->getUser());
  1239.                     $commentaireDealRepository->add($commentaireDealtrue);
  1240.                    
  1241.                         
  1242.                         
  1243.                     
  1244.                    
  1245.                     return $this->json(['success' => true'message' => 'commentaire ajouter ']);
  1246.              }
  1247.         }
  1248.         return $this->json(['success' => false'error' => 'Erreur ']);
  1249.     }
  1250.     
  1251.      /**
  1252.      * @Route("/archiverdeal/{id}", methods={"POST"})
  1253.      */
  1254.     public function archiverdeal(Request $request,Deal $deal,DealRepository $dealRepository,
  1255.     DepotDossierRepository $depotDossierRepository): JsonResponse
  1256.     
  1257.         
  1258.         
  1259.   
  1260.         if ($request->getMethod() == "POST") {
  1261.             
  1262.             // $file=$request->files->get('validedocument');
  1263.             $id $request->request->get('id');
  1264.           
  1265.              if ($id) {
  1266.                
  1267.                     foreach ($deal->getDepotDossiers() as $key => $dossier) {
  1268.                         $dossier->setArchive($dossier->getStatus());
  1269.                         $dossier->setStatus("archive"); 
  1270.                         $depotDossierRepository->add($dossiertrue);
  1271.                     }
  1272.                     $deal->setArchive($deal->getStatus());
  1273.                     $deal->setStatus("archive");
  1274.                     $dealRepository->add($dealtrue);
  1275.                       
  1276.                     return $this->json(['success' => true'message' => 'deal archive']);
  1277.              }
  1278.         }
  1279.         return $this->json(['success' => false'error' => 'Erreur ']);
  1280.     }
  1281.     /**
  1282.      * @Route("/suprimercommentaire/{id}", methods={"POST"})
  1283.      */
  1284.     public function suprimercommentaire(Request $request ,CommentaireDealRepository $commentaireDealRepository,CommentaireDeal $commentaireDeal): JsonResponse
  1285.     
  1286.         
  1287.         
  1288.   
  1289.         if ($request->getMethod() == "POST") {
  1290.             
  1291.             // $file=$request->files->get('validedocument');
  1292.             $id $request->request->get('id');
  1293.             
  1294.              if ($id) {
  1295.                     
  1296.                 $commentaireDealRepository->remove($commentaireDealtrue);
  1297.                    
  1298.                     
  1299.                     return $this->json(['success' => true'message' => 'champs supprimer succès']);
  1300.              }
  1301.         }
  1302.         return $this->json(['success' => false'error' => 'Erreur ']);
  1303.     }
  1304.   
  1305.     /**
  1306.      * @Route("/exporte/{id}", name="app_exporte",  methods={"GET"})
  1307.      */
  1308.     public function exporte(Deal $deal,DealRepository $dealRepository): Response
  1309.     {
  1310.         
  1311.         
  1312.         $jsonFilePath 'assets/json/deal-list.json';
  1313.         // Étape 1 : Récupérer le contenu JSON depuis le fichier
  1314.         $jsonContent file_get_contents($jsonFilePath);
  1315.         // Étape 2 : Décoder le contenu JSON en tableau PHP
  1316.         $phpArray json_decode($jsonContenttrue);
  1317.       
  1318.         // Créer un nouveau classeur Excel
  1319.         $spreadsheet = new Spreadsheet();
  1320.                 
  1321.         // Obtenir la feuille active
  1322.         $sheet $spreadsheet->getActiveSheet();
  1323.         // Écrire des données dans la feuille
  1324.         $sheet->setCellValue('A1''Deal');
  1325.         $sheet->setCellValue('B1''Installateur');
  1326.         $sheet->setCellValue('C1''Oblige');
  1327.         $sheet->setCellValue('D1''Date de Fin');
  1328.         $sheet->setCellValue('E1''Status');
  1329.         $i=2;
  1330.         
  1331.         if ($phpArray === null) {
  1332.             echo "Erreur lors du décodage JSON : " json_last_error_msg();
  1333.         } else {
  1334.             // Utilisez le tableau PHP $phpArray comme bon vous semble
  1335.             foreach ($phpArray as $value) {
  1336.                 $dl=$dealRepository->findOneBy(["id"=>intval($value["id_deal"])]);
  1337.                 $sheet->setCellValue('A'.$i$dl->getNumero());
  1338.                 $sheet->setCellValue('B'.$i$dl->getInstallateur()->getSociete());
  1339.                 $sheet->setCellValue('C'.$i$dl->getDealoblige()->getOblige()->getSociete());
  1340.                 $sheet->setCellValue('D'.$i,  $dl->getDatefin());
  1341.                 $sheet->setCellValue('E'.$i$dl->getStatus());
  1342.                 $i=$i+1;
  1343.             }
  1344.         }
  1345.        
  1346.         // Créer un objet Writer pour enregistrer le fichier
  1347.         $writer = new Xlsx($spreadsheet);
  1348.         // Enregistrer le fichier à un emplacement
  1349.         $now = new DateTime();
  1350.                 $date $now->format('d-m-Y H-i-s');
  1351.         $nomexecel "deal-".$this->getUser()->getEquipe()->getPrenom()."-".$date;
  1352.         $cheminFichier =$this->getParameter('installateur_directory') . "/export/export".$nomexecel.".xlsx";
  1353.         $writer->save($cheminFichier);
  1354.         // Renvoyer la réponse avec le fichier Excel en pièce jointe
  1355.         return $this->file($cheminFichier);
  1356.     }
  1357.     /**
  1358.      * @Route("/commentaireedite/{id}", methods={"POST"})
  1359.      */
  1360.     public function commentaireedite(Request $request,CommentaireDealRepository $commentaireDealRepository,CommentaireDeal $commentaireDeal ): JsonResponse
  1361.     
  1362.         
  1363.         
  1364.   
  1365.         if ($request->getMethod() == "POST") {
  1366.             
  1367.             // $file=$request->files->get('validedocument');
  1368.             $commentaire $request->request->get('commentaire');
  1369.        
  1370.             
  1371.              if ($commentaire) {
  1372.             
  1373.                     $commentaireDeal->setCommentaire($commentaire);
  1374.                     $commentaireDeal->setDate(new DateTime());
  1375.                     $commentaireDealRepository->add($commentaireDealtrue);
  1376.                         
  1377.                         
  1378.                     
  1379.                    
  1380.                     return $this->json(['success' => true'message' => 'commentaire ajouter ']);
  1381.              }
  1382.         }
  1383.         return $this->json(['success' => false'error' => 'Erreur ']);
  1384.     }
  1385. }