<?php
namespace App\Controller;
use App\Entity\Installateur;
use App\Entity\ContactInstallateur;
use App\Entity\ChampsInstallateur;
use App\Repository\EquipeRepository;
use App\Entity\Champs;
use App\Entity\Tokenpassword;
use App\Entity\CommentaireInstalleur;
use App\Form\InstallateurType;
use App\Repository\InstallateurRepository;
use App\Repository\UserRepository;
use App\Repository\ChampsDefautRepository;
use App\Repository\ChampsInstallateurRepository;
use App\Repository\OperationStandardRepository;
use App\Repository\ChampsRepository;
use App\Repository\NotificationsRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\User;
use App\Entity\Notifications;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use App\Service\FileUploader;
use Datetime;
use App\Service\MailerService;
use App\Service\MessageService;
use App\Repository\DealRepository;
use App\Service\EmailSender;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
use Symfony\Contracts\Translation\TranslatorInterface;
use SymfonyCasts\Bundle\ResetPassword\Controller\ResetPasswordControllerTrait;
use SymfonyCasts\Bundle\ResetPassword\Exception\ResetPasswordExceptionInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use SymfonyCasts\Bundle\ResetPassword\ResetPasswordHelperInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordToken;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Security\Csrf\CsrfToken;
use App\Repository\SoustraitantRepository;
use App\Repository\ResetPasswordRequestRepository;
use App\Repository\ChampsSoustraitantRepository;
use App\Repository\ChampsDealRepository;
use App\Repository\DepotDossierRepository;
use App\Repository\ChampsDepotDossierRepository;
use App\Repository\ActiviteDealRepository;
use App\Repository\CommentairesControlleRepository;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\Process\Process;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use App\Form\ChangePasswordFormType;
use App\Form\ResetPasswordRequestFormType;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\Repository\CommentaireInstalleurRepository;
use App\Repository\TokenpasswordRepository;
use App\Repository\FactureAafRepository ;
use App\Repository\AppelqualiteRepository;
use App\Repository\ContratRepository;
use App\Repository\ContactInstallateurRepository;
/**
* @Route("/installateur")
*/
class InstallateurController extends AbstractController
{
private $resetPasswordHelper;
private $entityManager;
public function __construct(ResetPasswordHelperInterface $resetPasswordHelper, EntityManagerInterface $entityManager)
{
$this->resetPasswordHelper = $resetPasswordHelper;
$this->entityManager = $entityManager;
}
/**
* @Route("/", name="app_installateur_index", methods={"GET"})
*/
public function index(InstallateurRepository $installateurRepository,OperationStandardRepository $operationStandardRepository,
ChampsDefautRepository $champsDefautRepository,EmailSender $emailSender): Response
{
if ($this->isGranted('ROLE_INSTALLATEUR')) {
return $this->redirectToRoute('app_installateur_edit', ['id' => $this->getUser()->getInstallateur()->getId()], Response::HTTP_SEE_OTHER);
}
$installateur= $installateurRepository->findAll();
$tab=[];
$installateurs=[];
// id,type as owner,client as name ,date,file ,batiment
foreach ($installateur as $value) {
if ($value->getStatus() != "archive") {
$tab['id']=$value->getId();
$tab['name']=$value->getSociete();
$tab['owner']=$value->getNom();
$tab['industry_type']=$value->getPhone();
$tab['location']=$value->getAdresse();
$tab['contact_email']=$value->getEmail();
$tab['employee']="installateur";
$tab['icone']="ri-archive-line";
if ($value->getStatus()=='Validé') {
$tab['star_value']='<span class="badge progress-green p-2 border-0" >'.$value->getStatus().'</span>';
$tab['row_tr']='row-green';
} elseif($value->getStatus()=="Bloqué") {
$tab['star_value']='<span class="badge progress-red p-2 border-0" >'.$value->getStatus().'</span>';
$tab['row_tr']='row-red';
}elseif($value->getStatus()=="En Attente"){
$tab['star_value']='<span class="badge progress-yellow p-2 border-0" >'.$value->getStatus().'</span>';
$tab['row_tr']='row-yellow';
}else{
$tab['star_value']='<span class="badge progress-grey p-2 border-0" >Nouveau</span>';
$tab['row_tr']='row-grey';
}
$tab['image_src']=$value->getPhoto() != null ? "https://kaje-cee.net/assets/uplaod-installateur/".$value->getPhoto() : "https://kaje-cee.net/assets/images/user.png";
$installateurs[]=$tab;
}
}
$clientjson = json_encode($installateurs);
// var_dump(json_encode($clientjson ));
file_put_contents('assets/json/installateur-list.json', $clientjson);
// $emailpart ="contact@kaje-cee.net";
// $mailerService->send(
// "Prise de contact de la part de rouget",
// "contact@redcat-studio.fr",
// $emailpart,
// 'installateur/_email.html.twig',
// [
// "firstname" => 'rouget',
// "lastname" => "sall",
// "email" => "rouget@redcat-studio.fr",
// "message" => "teste"
// ]
// );
// $messageService->addSuccess("Message bien envoyé");
return $this->render('installateur/index.html.twig', [
'installateurs' => $installateurRepository->findAll(),
'operations' => $operationStandardRepository->findAll(),
'champs' => $champsDefautRepository->findAll(),
]);
}
/**
* @Route("/archivesinstallateur", name="app_installateur_indexarchive", methods={"GET"})
*/
public function indexarchive(InstallateurRepository $installateurRepository,OperationStandardRepository $operationStandardRepository,
ChampsDefautRepository $champsDefautRepository,EmailSender $emailSender): Response
{
$installateur= $installateurRepository->findAll();
$tab=[];
$installateurs=[];
// id,type as owner,client as name ,date,file ,batiment
foreach ($installateur as $value) {
if ($value->getStatus() == "archive") {
$tab['id']=$value->getId();
$tab['name']=$value->getSociete();
$tab['owner']=$value->getNom();
$tab['industry_type']=$value->getPhone();
$tab['location']=$value->getAdresse();
$tab['contact_email']=$value->getEmail();
$tab['employee']="installateur";
$tab['icone']="ri-delete-bin-fill";
if($value->getStatus()=="archive") {
$tab['star_value']='<span class="badge progress-red p-2 border-0" >'.$value->getStatus().'</span>';
$tab['row_tr']='row-red';
}else{
$tab['star_value']='<span class="badge progress-grey p-2 border-0" >Nouveau</span>';
$tab['row_tr']='row-grey';
}
$tab['image_src']=$value->getPhoto() != null ? "https://kaje-cee.net/assets/uplaod-installateur/".$value->getPhoto() : "https://kaje-cee.net/assets/images/user.png";
$installateurs[]=$tab;
}
}
$clientjson = json_encode($installateurs);
// dd(json_encode($clientjson ));
file_put_contents('assets/json/installateur-list.json', $clientjson);
// $emailpart ="contact@kaje-cee.net";
// $mailerService->send(
// "Prise de contact de la part de rouget",
// "contact@redcat-studio.fr",
// $emailpart,
// 'installateur/_email.html.twig',
// [
// "firstname" => 'rouget',
// "lastname" => "sall",
// "email" => "rouget@redcat-studio.fr",
// "message" => "teste"
// ]
// );
// $messageService->addSuccess("Message bien envoyé");
return $this->render('installateur/archive.html.twig', [
'installateurs' => $installateurRepository->findBy(['status' => 'archive'])
]);
}
/**
* @Route("/new", name="app_installateur_new", methods={"GET", "POST"})
*/
public function new(Request $request, InstallateurRepository $installateurRepository,EntityManagerInterface $entityManager ,UserPasswordHasherInterface $userPasswordHasher,
ChampsInstallateurRepository $champsInstallateurRepository,ChampsRepository $champsRepository,FileUploader $uploader,OperationStandardRepository $operationStandardRepository
,UserRepository $userRepository,ChampsDefautRepository $champsDefautRepository,ResetPasswordHelperInterface $resetPasswordHelper,MailerInterface $mailer, TranslatorInterface $translator, NotificationsRepository $notificationsRepository): Response
{
$installateur = new Installateur();
// $form = $this->createForm(InstallateurType::class, $installateur);
// $form->handleRequest($request);
if ($request->getMethod() == "POST") {
$form = $request->request;
// $date = date('d.m.Y', strtotime($form->get('datekbis'))) ;
// $datetime = new Datetime($date);
// var_dump($datetime) ;die('test');
$userold=$userRepository->findOneBy(["email"=>$form->get('email')]);
// var_dump($userold);die('test');
if ($userold != null) {
return $this->render('installateur/index.html.twig', [
'installateurs' => $installateurRepository->findAll(),
'messageuser'=>'Installateur déja Ajouter',
'operations' => $operationStandardRepository->findAll(),
'champs' => $champsRepository->findAll(),
]);
}
$user = new User();
$user->setEmail($form->get('email'));
$roles[]=$form->get('role');
$user->setRoles($roles);
$user->setPassword(
$userPasswordHasher->hashPassword(
$user,'kagekali01'
)
);
$entityManager->persist($user);
$installateur->setUser($user);
// $permission=[];
// foreach ($form->get('permission') as $value) {
// $permission[]=$value;
// }
if ($request->files->get('logo-file')) {
$nom='logo-'.$form->get('societe');
$uploader->setTargetDirectory($this->getParameter('installateur_directory'));
$uploader->upload($request->files->get('logo-file'),$nom);
$installateur->setPhoto($uploader->getFileName());
}
$installateur->setNom($form->get('nom'));
$installateur->setPrenom($form->get('prenom'));
$installateur->setSociete($form->get('societe'));
$installateur->setEmail($form->get('email'));
$installateur->setAdresse($form->get('adresse'));
$installateur->setPhone($form->get('phone'));
$installateur->setStatus("new");
$installateur->setEquipe($this->getUser()->getEquipe());
// $produit->setNom($form->get("nom"));
// $produit->setReference($form->get("reference"));
// $produit->setPrix($form->get("prix"));
// $produit->setDescription($form->get("description"));
// $produitRepository->add($produit, true);
if ($form->get('operations') !=null ) {
foreach ($form->get('operations') as $value) {
$ops= $operationStandardRepository->findOneBy(["id"=>intval($value)]);
$installateur->addOperationStandard($ops);
}
}
$installateurRepository->add($installateur, true);
$notifications = new Notifications();
$notifications->setUserId($user);
$notifications->setMessage("Bienvenue sur Kali & Co, veuillez compléter vos informations.");
$notifications->setAction("app_installateur_edit");
$notifications->setActionId($installateur->getId());
$notifications->setSender($this->getUser());
$notifications->setStatuts("non lu");
$notifications->setDate(new DateTime());
$notificationsRepository->add($notifications, true);
foreach ($champsDefautRepository->findAll() as $key => $champsDefaut) {
$champsInstallateur = new ChampsInstallateur();
$champsInstallateur->setNom($champsDefaut->getNom());
$champsInstallateur->setType($champsDefaut->getType());
$champsInstallateur->setType($champsDefaut->getType());
$champsInstallateur->setStatus('Non Transmis');
if ($champsDefaut->getDurevalidite()) {
$champsInstallateur->setDurevalidite($champsDefaut->getDurevalidite());
}
$champsInstallateur->setInstallateur($installateur);
$champsInstallateurRepository->add($champsInstallateur, true);
}
$notificationsRepository->add($notifications, true);
$username= $installateur->getPrenom()." ".$installateur->getNom();
$destination="installateur";
return $this->processSendingPasswordResetEmail(
$form->get('email'),
$mailer,
$translator,$destination,$username
);
return $this->redirectToRoute('app_installateur_edit', ['id' => $installateur->getId()], Response::HTTP_SEE_OTHER);
}
// if ($form->isSubmitted() && $form->isValid()) {
// $installateurRepository->add($installateur, true);
// return $this->redirectToRoute('app_installateur_index', [], Response::HTTP_SEE_OTHER);
// }
return $this->renderForm('installateur/new.html.twig', [
'installateur' => $installateur,
'operations' => $operationStandardRepository->findAll()
]);
}
/**
* @Route("/newcontact", name="app_contact_new", methods={"GET", "POST"})
*/
public function newcontact(Request $request,InstallateurRepository $installateurRepository,EntityManagerInterface $entityManager ,ContactInstallateurRepository $contactInstallateurRepository){
if ($request->getMethod() == "POST") {
$form = $request->request;
$contact = new ContactInstallateur();
//dd($form );
$contact->setNom($form->get('nom'));
$contact->setMail($form->get('mail'));
$contact->setTel($form->get('tel'));
$contact->setFonction($form->get('fonction'));
$installateur = $installateurRepository->findOneBy(["id" => intval($form->get('installateur_id'))]);
$contact->setInstallateur($installateur);
//dd($contact);
$contactInstallateurRepository->add($contact, true);
return $this->redirectToRoute('app_installateur_edit', ['id' =>$installateur->getId() ], Response::HTTP_SEE_OTHER);
}else{
return $this->redirectToRoute('app_installateur_index', Response::HTTP_SEE_OTHER);
}
}
/**
* @Route("/newdeal", name="app_installateur_newdeal", methods={"GET", "POST"})
*/
public function newdeal(Request $request, InstallateurRepository $installateurRepository,EntityManagerInterface $entityManager ,UserPasswordHasherInterface $userPasswordHasher,
ChampsInstallateurRepository $champsInstallateurRepository,ChampsRepository $champsRepository,FileUploader $uploader,OperationStandardRepository $operationStandardRepository
,UserRepository $userRepository,ChampsDefautRepository $champsDefautRepository,ResetPasswordHelperInterface $resetPasswordHelper,MailerInterface $mailer, TranslatorInterface $translator): Response
{
$installateur = new Installateur();
// $form = $this->createForm(InstallateurType::class, $installateur);
// $form->handleRequest($request);
if ($request->getMethod() == "POST") {
$form = $request->request;
$date = date('d.m.Y', strtotime($form->get('datekbis'))) ;
$datetime = new Datetime($date);
// var_dump($datetime) ;die('test');
$userold=$userRepository->findOneBy(["email"=>$form->get('email')]);
// var_dump($userold);die('test');
if ($userold != null) {
return $this->render('installateur/index.html.twig', [
'installateurs' => $installateurRepository->findAll(),
'messageuser'=>'Installateur déja Ajouter',
'operations' => $operationStandardRepository->findAll(),
'champs' => $champsRepository->findAll(),
]);
}
$user = new User();
$user->setEmail($form->get('email'));
$roles[]=$form->get('role');
$user->setRoles($roles);
$user->setPassword(
$userPasswordHasher->hashPassword(
$user,'kagekali01'
)
);
$entityManager->persist($user);
$installateur->setUser($user);
// $permission=[];
// foreach ($form->get('permission') as $value) {
// $permission[]=$value;
// }
if ($request->files->get('logo-file')) {
$nom='logo-'.$form->get('societe');
$uploader->setTargetDirectory($this->getParameter('installateur_directory'));
$uploader->upload($request->files->get('logo-file'),$nom);
$installateur->setPhoto($uploader->getFileName());
}
$installateur->setNom($form->get('nom'));
$installateur->setPrenom($form->get('prenom'));
$installateur->setSociete($form->get('societe'));
$installateur->setEmail($form->get('email'));
$installateur->setAdresse($form->get('adresse'));
$installateur->setPhone($form->get('phone'));
$installateur->setStatus("new");
if ($form->get('operations') !=null ) {
foreach ($form->get('operations') as $value) {
$ops= $operationStandardRepository->findOneBy(["id"=>intval($value)]);
$installateur->addOperationStandard($ops);
}
}
$installateurRepository->add($installateur, true);
foreach ($champsDefautRepository->findAll() as $key => $champsDefaut) {
$champsInstallateur = new ChampsInstallateur();
$champsInstallateur->setNom($champsDefaut->getNom());
$champsInstallateur->setType($champsDefaut->getType());
$champsInstallateur->setType($champsDefaut->getType());
$champsInstallateur->setStatus('Non Transmis');
if ($champsDefaut->getDurevalidite()) {
$champsInstallateur->setDurevalidite($champsDefaut->getDurevalidite());
}
$champsInstallateur->setInstallateur($installateur);
$champsInstallateurRepository->add($champsInstallateur, true);
}
$destination ="deal";
$username= $installateur->getPrenom()." ".$installateur->getNom();
return $this->processSendingPasswordResetEmail(
$form->get('email'),
$mailer,
$translator,$destination,$username
);
return $this->redirectToRoute('app_deal_new', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('installateur/new.html.twig', [
'installateur' => $installateur,
'operations' => $operationStandardRepository->findAll()
]);
}
/**
* @Route("/{id}", name="app_installateur_show", methods={"GET"})
*/
public function show(Installateur $installateur,OperationStandardRepository $operationStandardRepository): Response
{
if ($this->isGranted('ROLE_INSTALLATEUR')) {
if ($installateur->getId() !=$this->getUser()->getInstallateur()->getId() ) {
return $this->redirectToRoute('app_installateur_edit', ['id' => $this->getUser()->getInstallateur()->getId()], Response::HTTP_SEE_OTHER);
}else{
return $this->redirectToRoute('app_installateur_edit', ['id' => $installateur->getId()], Response::HTTP_SEE_OTHER);
}
}else{
return $this->redirectToRoute('app_installateur_edit', ['id' => $installateur->getId()], Response::HTTP_SEE_OTHER);
}
}
/**
* @Route("/{id}/edit", name="app_installateur_edit", methods={"GET", "POST"})
*/
public function edit(Request $request, Installateur $installateur, InstallateurRepository $installateurRepository, ChampsInstallateurRepository $champsInstallateurRepository,
FileUploader $uploader,ChampsRepository $champsRepository,OperationStandardRepository $operationStandardRepository,
CsrfTokenManagerInterface $csrfTokenManager,NotificationsRepository $notificationsRepository, EquipeRepository $equipeRepository): Response
{
// return $this->redirectToRoute('app_installateur_index', [], Response::HTTP_SEE_OTHER);
// $form = $this->createForm(InstallateurType::class, $installateur);
// $form->handleRequest($request);
$csrfToken = $csrfTokenManager->getToken('installateur_edit');
if ($this->isGranted('ROLE_INSTALLATEUR')) {
if ($installateur->getId() !=$this->getUser()->getInstallateur()->getId() ) {
return $this->redirectToRoute('app_installateur_edit', ['id' => $this->getUser()->getInstallateur()->getId()], Response::HTTP_SEE_OTHER);
}
}
$isCompleted = "oui";
if ($this->isGranted('ROLE_INSTALLATEUR')) {
if($installateur->getNom() == null || $installateur->getPrenom() == null || $installateur->getSociete() == null ||
$installateur->getPhone() == null || $installateur->getEmail() == null || $installateur->getAdresse() == null ){
$isCompleted = "non";
}
foreach($installateur->getChampsinstallateur() as $key => $value){
if($value->getType() !="file" && $value->getValeur() == null){
$isCompleted = "non";
}
if($value->getType() =="file" && $value->getStatus() == "Non Transmis"){
$isCompleted = "non";
}
}
if(count($installateur->getOperationStandards()) < 1){
$isCompleted = "non";
}
}
if ($request->getMethod() == "POST") {
$token = $request->request->get('_token');
$id = explode("A@",explode("12OU#@R",$token)[1])[0];
if ($id!=$installateur->getId()) {
return $this->redirectToRoute('app_installateur_edit', ['id' => $id], Response::HTTP_SEE_OTHER);
}
$form = $request->request;
if ($request->files->get('logo-file')) {
$nom='logo-'.$form->get('societe');
$uploader->setTargetDirectory($this->getParameter('installateur_directory'));
$uploader->upload($request->files->get('logo-file'),$nom);
$installateur->setPhoto($uploader->getFileName());
}
$installateur->setNom($form->get('nom'));
$installateur->setPrenom($form->get('prenom'));
$installateur->setSociete($form->get('societe'));
$installateur->setEmail($form->get('email'));
$installateur->setAdresse($form->get('adresse'));
$installateur->setPhone($form->get('phone'));
if (!$this->isGranted('ROLE_INSTALLATEUR')) {
$installateur->setStatus($form->get('status'));
}
$installateur->setCommentaire($form->get('commentaire'));
// $installateur->setPermissions($permission);
if ($form->get('operations') != null) {
// $tabopext=[];
foreach ($installateur->getOperationStandards() as $value) {
// $tabopext[]=$value->getId();
if (!in_array($value->getId(),$form->get('operations'))) {
$installateur->removeOperationStandard($value);
}
}
foreach ($form->get('operations') as $value) {
$ops= $operationStandardRepository->findOneBy(["id"=>intval($value)]);
$installateur->addOperationStandard($ops);
}
}else{
foreach ($installateur->getOperationStandards() as $value) {
$installateur->removeOperationStandard($value);
}
}
$installateurRepository->add($installateur, true);
$com = $installateurRepository->findOneBy(["id" => $installateur->getId() ]);
if($form->get('commentaire') != $com->getCommentaire()){
$notifications = new Notifications();
$notifications->setUserId($installateur->getUser());
$notifications->setMessage("Un commentaire a été posté dans votre profil.");
$notifications->setAction("app_installateur_edit");
$notifications->setActionId($installateur->getId());
$notifications->setSender($this->getUser());
$notifications->setStatuts("non lu");
$notifications->setDate(new DateTime());
$notificationsRepository->add($notifications, true);
}
if ($form->get('datekbis')!=null) {
$date = date('d.m.Y', strtotime($form->get('datekbis'))) ;
$datetime = new Datetime($date);
// var_dump($form->get('datekbis'));
// var_dump($datetime);die('test');
$id=$form->get("id_kbis");
$champsinst= $champsInstallateurRepository->findOneBy(["id" => intval($id)]);
if ($request->files->get('kbis')) {
$nom='kbis-'.$form->get('societe');
$uploader->setTargetDirectory($this->getParameter('installateur_directory'));
$uploader->upload($request->files->get('kbis'),$nom);
$valeur[]=$uploader->getFileName();
if ($champsinst->getValeur() != null ) {
foreach ($champsinst->getValeur() as $key => $value) {
$valeur[]=$value;
}
}
$champsinst->setValeur($valeur);
$champsinst->setStatus("Transmis");
// Notif admin
// $notifications = new Notifications();
// $notifications->setUserId($installateur->getUser()->getId());
// $notifications->setMessage($installateur->getSociete() + " vous a transmis son KBIS.");
// $notifications->setAction("app_installateur_edit");
// $notifications->setActionId($installateur->getId());
// $notifications->setSender($this->getUser());
// $notifications->setStatuts("non lu");
// $notifications->setDate(new DateTime());
// $notificationsRepository->add($notifications, true);
}
$champsinst->setDate($datetime);
$champsInstallateurRepository->add($champsinst, true);
}
foreach ($form as $key => $value) {
if (count(explode("-",$key)) ==2 && explode("-",$key)[0]=="champsinstvaleur") {
$id=$form->get('champsinstvaleur-'.explode("-",$key)[1]);
$champsinst= $champsInstallateurRepository->findOneBy(["id" => $id]);
if ($champsinst->getType()=="file") {
if ($request->files->get('champsinstallateur-'.explode("-",$key)[1])) {
$nom=explode(".",$request->files->get('champsinstallateur-'.explode("-",$key)[1])->getClientOriginalName())[0];
$uploader->setTargetDirectory($this->getParameter('installateur_directory'));
$uploader->upload($request->files->get('champsinstallateur-'.explode("-",$key)[1]),$nom);
// $champsinst->setValeur($uploader->getFileName());
$valeur=[];
$valeur[]=$uploader->getFileName();
if ($champsinst->getValeur() != null ) {
foreach ($champsinst->getValeur() as $key => $value) {
$valeur[]=$value;
}
}
$champsinst->setValeur($valeur);
$champsinst->setStatus('Transmis');
}
$champsInstallateurRepository->add($champsinst, true);
}
}
if (count(explode("-",$key)) ==2 && explode("-",$key)[0]=="champsinstallateur") {
$id=$form->get('champsinstvaleur-'.explode("-",$key)[1]);
$champsinst= $champsInstallateurRepository->findOneBy(["id" => $id]);
$valeur=[];
$valeur[]=$value;
if ($champsinst->getValeur() != null ) {
foreach ($champsinst->getValeur() as $key => $val) {
$valeur[]=$val;
}
}
$champsinst->setValeur($valeur);
if ($champsinst->getStatus()==null) {
$champsinst->setStatus('Non Transmis');
}else{
$champsinst->setStatus('Transmis');
}
$date = new Datetime();
$champsinst->setDate($date);
$champsInstallateurRepository->add($champsinst, true);
}
if (count(explode("_",$key)) >2 && explode("_",$key)[1]=="old"){
$champsInstallateur = new ChampsInstallateur();
$chmps= $champsRepository->find(["id"=>intval($value)]);
if ($chmps) {
$champsInstallateur->setNom($chmps->getNom());
$champsInstallateur->setType($chmps->getType());
$champsInstallateur->setInstallateur($installateur);
$champsInstallateur->setStatus('Non Transmis');
$champsInstallateurRepository->add($champsInstallateur, true);
}
}
if ( count(explode("_",$key)) >2 && explode("_",$key)[2]=="type") {
if (explode("_",$key)[3]=="nom") {
$champs->setNom($value);
if($champs->getType() != "file"){
$champsRepository->add($champs, true);
$champsInstallateur = new ChampsInstallateur();
// $champsInstallateur->setNom($champs->getNom());
// $champsInstallateur->setType($champs->getType());
// $champsInstallateur->setInstallateur($installateur);
// $champsInstallateur->setStatus('Non Transmis');
// $champsInstallateurRepository->add($champsInstallateur, true);
$champsInstallateur->setNom($champs->getNom());
$champsInstallateur->setType($champs->getType());
$champsInstallateur->setInstallateur($installateur);
$champsInstallateur->setStatus('Non Transmis');
$champsInstallateurRepository->add($champsInstallateur, true);
if($this->isGranted("ROLE_INSTALLATEUR") == false || $this->isGranted("ROLE_OBLIGE") == false){
$notifications = new Notifications();
$notifications->setUserId($champsInstallateur->getInstallateur()->getUser());
$notifications->setAction("app_installateur_edit");
$notifications->setMessage("De nouveaux éléments vous sont demandés dans votre profil.");
$notifications->setActionId($champsInstallateur->getInstallateur()->getId());
$notifications->setSender($this->getUser());
$notifications->setStatuts("non lu");
$notifications->setDate(new DateTime());
}
$notificationsRepository->add($notifications, true);
}
}elseif(explode("_",$key)[3]=="dure"){
if($champs->getType() == "file"){
if($value!=null){
$champs->setDurevalidite($value);
}
$champsRepository->add($champs, true);
$champsInstallateur = new ChampsInstallateur();
$champsInstallateur->setNom($champs->getNom());
$champsInstallateur->setType($champs->getType());
$champsInstallateur->setDurevalidite($champs->getDurevalidite());
$champsInstallateur->setInstallateur($installateur);
$champsInstallateur->setStatus('Non Transmis');
$champsInstallateurRepository->add($champsInstallateur, true);
if($this->isGranted("ROLE_INSTALLATEUR") == false || $this->isGranted("ROLE_OBLIGE") == false){
$notifications = new Notifications();
$notifications->setUserId($champsInstallateur->getInstallateur()->getUser());
$notifications->setAction("app_installateur_edit");
$notifications->setMessage("De nouveaux éléments vous sont demandés dans votre profil.");
$notifications->setActionId($champsInstallateur->getInstallateur()->getId());
$notifications->setSender($this->getUser());
$notifications->setStatuts("non lu");
$notifications->setDate(new DateTime());
}
$notificationsRepository->add($notifications, true);
}
}
else{
$champs = new Champs();
$champs->setType($value);
}
}
}
if(!$this->isGranted('ROLE_INSTALLATEUR')){
$notifications = new Notifications();
$notifications->setUserId($installateur->getUser());
$notifications->setAction("app_installateur_edit");
$notifications->setMessage("De nouveaux éléments vous sont demandés dans votre profil.");
$notifications->setActionId($installateur->getId());
$notifications->setSender($this->getUser());
$notifications->setStatuts("non lu");
$notifications->setDate(new DateTime());
$notificationsRepository->add($notifications, true);
}
return $this->redirectToRoute('app_installateur_edit', ['id' =>$installateur->getId() ], Response::HTTP_SEE_OTHER);
}
if ($this->isGranted('ROLE_INSTALLATEUR')) {
$notif = $notificationsRepository->findBy(["user_id" => $installateur->getUser(),"statuts"=> "non lu","action" => "app_installateur_edit", "action_id" => $installateur->getId()]);
if ($notif) {
foreach ($notif as $value) {
$datefinnotif = $value->getDate();
$dateday2 = new DateTime();
// Ajouter 2 jours
$datefinnotif->modify('+2 days');
// dd($datefinnotif);
// if ($dateday2 > $datefinnotif) {
// $value->setStatuts("lu");
// $notificationsRepository->add($value, true);
// }
$value->setStatuts("lu");
$notificationsRepository->add($value, true);
}
}
} else {
$admins = $equipeRepository->findAll();
foreach ($admins as $key => $value) {
$listPermissions = $value->getPermissions();
foreach ($listPermissions as $v) {
if($v == "NOTIFICATION" ){
$notif = $notificationsRepository->findBy(["statuts"=> "non lu", "action_id" => "app_installateur_edit", "action_id" => $installateur->getId()]);
if ($notif) {
foreach ($notif as $m => $n) {
$isEquipe = $equipeRepository->findOneBy(["id" => $n->getUserId()]);
if($isEquipe && $isEquipe->getRole() != "ROLE_INSTALLATEUR"){
$n->setStatuts("lu");
$notificationsRepository->add($n, true);
}
}
}
}
}
}
}
return $this->renderForm('installateur/edit.html.twig', [
'installateur' => $installateur,
'champsInstallateurs' =>$champsInstallateurRepository->findAll(),
'operationsStandars' => $operationStandardRepository->findAll(),
'csrf_token' => $csrfToken->getValue().'12OU#@R'.$installateur->getId()."A@T9",
"dateday"=>new Datetime(),
"isCompleted" => $isCompleted
]);
}
/**
* @Route("/{id}", name="app_installateur_delete", methods={"POST"})
*/
public function delete(Request $request, Installateur $installateur, InstallateurRepository $installateurRepository,UserRepository $userRepository,
ChampsInstallateurRepository $champsInstallateurRepository,DealRepository $dealRepository,SoustraitantRepository $soustraitantRepository,
ResetPasswordRequestRepository $resetPasswordRequestRepository,ChampsSoustraitantRepository $champsSoustraitantRepository,
ChampsDealRepository $champsDealRepository,DepotDossierRepository $depotDossierRepository,ChampsDepotDossierRepository $champsDepotDossierRepository,
ActiviteDealRepository $activiteDealRepository, NotificationsRepository $notificationsRepository,CommentairesControlleRepository $commentairesControlleRepository,
TokenpasswordRepository $tokenpasswordRepository,FactureAafRepository $factureAafRepository,AppelqualiteRepository $appelqualiteRepository,
CommentaireInstalleurRepository $commentaireInstalleurRepository,ContratRepository $contratRepository): Response
{
if ($this->isCsrfTokenValid('delete'.$installateur->getId(), $request->request->get('_token'))) {
$user=$userRepository->findOneBy(["email"=>$installateur->getEmail()]);
// var_dump($user->getId());die('test');
foreach ($installateur->getOperationStandards() as $value) {
$installateur->removeOperationStandard($value);
}
foreach ($installateur->getChampsinstallateur() as $value) {
$installateur->removeChampsinstallateur($value);
$champsInstallateurRepository->remove($value, true);
}
foreach ($installateur->getCommentaireInstalleurs() as $value) {
$installateur->removeCommentaireInstalleur($value);
$commentaireInstalleurRepository->remove($value, true);
}
foreach ($notificationsRepository->findBy(["action_id"=>$installateur->getId()]) as $value) {
$notificationsRepository->remove($value, true);
}
foreach ($user->getNotifications() as $value) {
$user->removeNotification($value);
$notificationsRepository->remove($value, true);
}
foreach ($user->getTokenpasswords() as $value) {
$user->removeTokenpassword($value);
$tokenpasswordRepository->remove($value, true);
}
foreach ($installateur->getDeals() as $value) {
foreach ($value->getDepotDossiers() as $dossier) {
foreach ($dossier->getChampsDepotDossiers() as $champdossier) {
$champsDepotDossierRepository->remove($champdossier, true);
}
foreach ($dossier->getCommentairesControlles() as $commentaire) {
$commentairesControlleRepository->remove($commentaire, true);
}
foreach ($dossier->getFactureAafs() as $value) {
// $depotDossier->removeFactureAaf($value);
foreach ($value->getCommentaireFactureaafs() as $commentaire) {
$value->removeCommentaireFactureaaf($commentaire);
// $activiteDealRepository->remove($commentaire, true);
}
$factureAafRepository->remove($value, true);
}
foreach ($dossier->getAppelqualites() as $value) {
// $depotDossier->removeAppelqualite($value);
foreach ($value->getCommentaireAppelqualites() as $commentaire) {
$value->removeCommentaireAppelqualite($commentaire);
// $activiteDealRepository->remove($commentaire, true);
}
$appelqualiteRepository->remove($value, true);
}
$depotDossierRepository->remove($dossier, true);
}
foreach ($value->getChampsdeal() as $champs) {
// $value->removeChampsSoustraitant($champs);
$champsDealRepository->remove($champs, true);
}
foreach ($value->getActiviteDeals() as $activite) {
$value->removeActiviteDeal($activite);
$activiteDealRepository->remove($activite, true);
}
foreach ($value->getCommentaireDeals() as $commentaire) {
$value->removeCommentaireDeal($commentaire);
// $activiteDealRepository->remove($commentaire, true);
}
foreach ($value->getHistoriqueDeals() as $historique) {
$value->removeHistoriqueDeal($historique);
// $activiteDealRepository->remove($commentaire, true);
}
foreach ($value->getSoustraitants() as $soustritant) {
$value->removeSoustraitant($soustritant);
// $activiteDealRepository->remove($commentaire, true);
}
foreach ($value->getOperation() as $operation) {
$value->removeOperation($operation);
}
if($value->getApporteurAffaire()){
$value->setApporteurAffaire(NULL);
}
foreach ($value->getOperation() as $value) {
$value->removeOperation($value);
}
if ($value->getContrat()) {
foreach ($value->getContrat()->getCommentaireContrats() as $commentaire) {
$value->getContrat()->removeCommentaireContrat($commentaire);
// $activiteDealRepository->remove($commentaire, true);
}
$contratRepository->remove($value->getContrat(), true);
}
$installateur->removeDeal($value);
$dealRepository->remove($value, true);
}
foreach ($installateur->getSoustraitants() as $value) {
foreach ($value->getChampsSoustraitants() as $champs) {
$value->removeChampsSoustraitant($champs);
$champsSoustraitantRepository->remove($champs, true);
}
foreach ($value->getOperationstandard() as $operation) {
$value->removeOperationstandard($operation);
}
$installateur->removeSoustraitant($value);
$soustraitantRepository->remove($value, true);
}
foreach ($resetPasswordRequestRepository->findBy(["user"=>$user->getId()]) as $value) {
$resetPasswordRequestRepository->remove($value, true);
}
$installateurRepository->remove($installateur, true);
$userRepository->remove($user, true);
}
return $this->redirectToRoute('app_installateur_index', [], Response::HTTP_SEE_OTHER);
}
private function processSendingPasswordResetEmail(string $emailFormData, MailerInterface $mailer, TranslatorInterface $translator,$destination,$username): RedirectResponse
{
$user = $this->entityManager->getRepository(User::class)->findOneBy([
'email' => $emailFormData,
]);
// Do not reveal whether a user account was found or not.
if (!$user) {
return $this->redirectToRoute('app_check_email');
}
try {
$resetToken = $this->resetPasswordHelper->generateResetToken($user);
$tokenpassword = new Tokenpassword();
$tokenpassword->setToken($resetToken->getToken());
$tokenpassword->setUser($user);
$tokenpassword->setDate(new Datetime());
$this->entityManager->persist($tokenpassword);
$this->entityManager->flush();
} catch (ResetPasswordExceptionInterface $e) {
// If you want to tell the user why a reset email was not sent, uncomment
// the lines below and change the redirect to 'app_forgot_password_request'.
// Caution: This may reveal if a user is registered or not.
//
// $this->addFlash('reset_password_error', sprintf(
// '%s - %s',
// $translator->trans(ResetPasswordExceptionInterface::MESSAGE_PROBLEM_HANDLE, [], 'ResetPasswordBundle'),
// $translator->trans($e->getReason(), [], 'ResetPasswordBundle')
// ));
// var_dump($e->getReason()); die('test');
return $this->redirectToRoute('app_check_email');
}
$email = (new TemplatedEmail())
->from(new Address('contact@kaje-cee.net', 'KAJE CEE'))
->to($user->getEmail())
->subject('Nouveau compte KAJE CEE')
->htmlTemplate('email/email-confirmation-compte.html.twig')
->context([
'resetToken' => $resetToken,
'username' => $username
])
;
$mailer->send($email);
if ($destination=="deal") {
return $this->redirectToRoute('app_deal_new', [], Response::HTTP_SEE_OTHER);
} else {
return $this->redirectToRoute('app_installateur_index', [], Response::HTTP_SEE_OTHER);
}
// Store the token object in session for retrieval in check-email route.
// $this->setTokenObjectInSession($resetToken);
}
private function processSendingPasswordResetEmailoublier(string $emailFormData, MailerInterface $mailer, TranslatorInterface $translator,$destination): RedirectResponse
{
$user = $this->entityManager->getRepository(User::class)->findOneBy([
'email' => $emailFormData,
]);
// Do not reveal whether a user account was found or not.
if (!$user) {
return $this->redirectToRoute('app_check_email');
}
try {
$resetToken = $this->resetPasswordHelper->generateResetToken($user);
$tokenpassword = new Tokenpassword();
$tokenpassword->setToken($resetToken->getToken());
$tokenpassword->setUser($user);
$tokenpassword->setDate(new Datetime());
$this->entityManager->persist($tokenpassword);
$this->entityManager->flush();
} catch (ResetPasswordExceptionInterface $e) {
// If you want to tell the user why a reset email was not sent, uncomment
// the lines below and change the redirect to 'app_forgot_password_request'.
// Caution: This may reveal if a user is registered or not.
//
// $this->addFlash('reset_password_error', sprintf(
// '%s - %s',
// $translator->trans(ResetPasswordExceptionInterface::MESSAGE_PROBLEM_HANDLE, [], 'ResetPasswordBundle'),
// $translator->trans($e->getReason(), [], 'ResetPasswordBundle')
// ));
// var_dump($e->getReason()); die('test');
return $this->redirectToRoute('app_check_email');
}
$email = (new TemplatedEmail())
->from(new Address('contact@kaje-cee.net', 'KAJE CEE'))
->to($user->getEmail())
->subject('KAJE CEE - Réinitialiser mon mot de passe')
->htmlTemplate('reset_password/email.html.twig')
->context([
'resetToken' => $resetToken,
])
;
$mailer->send($email);
return $this->redirectToRoute('app_login');
// Store the token object in session for retrieval in check-email route.
// $this->setTokenObjectInSession($resetToken);
}
/**
* @Route("/zip/{id}", name="app_installateur_zip", methods={"GET"})
*/
public function zip(Installateur $installateur): Response
{
// $sourceFolder = $this->getParameter('installateur_directory'). '/rouget'; // Remplacez par le chemin absolu de votre dossier
// $filesystem = new Filesystem();
// Vérifiez si le dossier existe
// if ($filesystem->exists($sourceFolder)) {
// Supprimez tous les fichiers et dossiers à l'intérieur du dossier
// $filesystem->remove(glob($sourceFolder . '/*'));
// Obtenez le nom du fichier à partir du chemin source
// foreach ($installateur->getChampsinstallateur() as $value) {
// if ($value->getType()=="file") {
// if ($value->getValeur()!=null) {
// $fileName = pathinfo($this->getParameter('installateur_directory').'/'.$value->getValeur(), PATHINFO_BASENAME);
// // Copiez le fichier vers le dossier de destination
// $sourceFolder = $sourceFolder . '/' . $fileName;
// $filesystem->copy($this->getParameter('installateur_directory').'/'.$value->getValeur(), $sourceFolder);
// }
// }
// }
// }
// sleep(5);
// Créez un nom de fichier unique pour le fichier ZIP
$zipFileName = $installateur->getSociete().'_' . date('YmdHis') . '.zip';
// Créez le chemin absolu vers le fichier ZIP
$zipFilePath = $this->getParameter('installateur_directory') . '/archiver/' . $zipFileName;
// Utilisez la classe ZipArchive pour créer le fichier ZIP
$zip = new \ZipArchive();
$zip->open($zipFilePath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
// Utilisez la classe Finder pour parcourir les fichiers du dossier source
// $finder = new Finder();
// $finder->files()->in($sourceFolder);
// foreach ($finder as $file) {
// $filePath = $file->getRealPath();
// $relativePath = $file->getRelativePath();
// // Ajouter le fichier au dossier compressé
// $zip->addFile($filePath, $relativePath);
// }
foreach ($installateur->getChampsinstallateur() as $value) {
if ($value->getType()=="file") {
if ($value->getValeur()!=null) {
$filePath = $this->getParameter('installateur_directory').'/'.$value->getValeur()[0];
$relativePath = $installateur->getSociete()."/".$value->getValeur()[0];
if (file_exists($filePath)) {
$zip->addFile($filePath, $relativePath);
}
// $zip->addFile($filePath, $relativePath);
}
}
}
// Fermer le fichier ZIP
$zip->close();
// Envoyer le fichier ZIP en tant que réponse de téléchargement
$response = new BinaryFileResponse($zipFilePath);
$response->headers->set('Content-Type', 'application/zip');
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $zipFileName);
// if ($filesystem->exists($sourceFolder)) {
// // Supprimez tous les fichiers et dossiers à l'intérieur du dossier
// $filesystem->remove(glob($sourceFolder . '/*'));
// }
return $response;
// return $this->redirectToRoute('app_installateur_sow', ['id' => $this->getUser()->getInstallateur()->getId()], Response::HTTP_SEE_OTHER);
}
/**
* @Route("/document/{id}/{document}", name="app_installateur_document", methods={"GET"})
*/
public function document(InstallateurRepository $installateurRepository, int $id, int $document): Response
{
$installateur= $installateurRepository->findOneBy(["id" => $id]);
return $this->render('documents/index.html.twig', [
'installateur' => $installateur,
"document" => intval($document)
]);
}
/**
* @Route("/commentaire/{id}", methods={"POST"})
*/
public function commentaire(Request $request,CommentaireInstalleurRepository $commentaireInstalleurRepository,Installateur $installateur,NotificationsRepository $notificationsRepository): JsonResponse
{
if ($request->getMethod() == "POST") {
// $file=$request->files->get('validedocument');
$commentaire = $request->request->get('commentaire');
if ($commentaire) {
$commentaireInstalleur = new CommentaireInstalleur();
$commentaireInstalleur->setCommentaire($commentaire);
$commentaireInstalleur->setDate(new DateTime());
$commentaireInstalleur->setInstalleur($installateur);
$commentaireInstalleur->setUser($this->getUser());
$commentaireInstalleurRepository->add($commentaireInstalleur, true);
$notifications = new Notifications();
$notifications->setUserId($installateur->getUser());
$notifications->setMessage("Un commentaire a été posté dans votre profil.");
$notifications->setAction("app_installateur_edit");
$notifications->setActionId($installateur->getId());
$notifications->setSender($this->getUser());
$notifications->setStatuts("non lu");
$notifications->setDate(new DateTime());
$notificationsRepository->add($notifications, true);
return $this->json(['success' => true, 'message' => 'commentaire ajouter ']);
}
}
return $this->json(['success' => false, 'error' => 'Erreur ']);
}
/**
* @Route("/archiverinstallateur/{id}", methods={"POST"})
*/
public function archiverinstallateur(Request $request,InstallateurRepository $installateurRepository,Installateur $installateur,DealRepository $dealRepository,
DepotDossierRepository $depotDossierRepository): JsonResponse
{
if ($request->getMethod() == "POST") {
// $file=$request->files->get('validedocument');
$id = $request->request->get('id');
if ($id) {
$installateur->setArchive($installateur->getStatus());
$installateur->setStatus("archive");
foreach ($installateur->getDeals() as $key => $deal) {
foreach ($deal->getDepotDossiers() as $key => $dossier) {
$dossier->setArchive($deal->getStatus());
$dossier->setStatus("archive");
$depotDossierRepository->add($dossier, true);
}
$deal->setArchive($deal->getStatus());
$deal->setStatus("archive");
$dealRepository->add($deal, true);
}
$installateurRepository->add($installateur, true);
return $this->json(['success' => true, 'message' => 'installateur archive']);
}
}
return $this->json(['success' => false, 'error' => 'Erreur ']);
}
/**
* @Route("/suprimercommentaire/{id}", methods={"POST"})
*/
public function suprimercommentaire(Request $request ,CommentaireInstalleurRepository $commentaireInstalleurRepository,CommentaireInstalleur $commentaireInstalleur): JsonResponse
{
if ($request->getMethod() == "POST") {
// $file=$request->files->get('validedocument');
$id = $request->request->get('id');
if ($id) {
$commentaireInstalleurRepository->remove($commentaireInstalleur, true);
return $this->json(['success' => true, 'message' => 'champs supprimer succès']);
}
}
return $this->json(['success' => false, 'error' => 'Erreur ']);
}
}