<?php
namespace App\Controller\Notes;
use App\Entity\Articles\Article;
use App\Entity\Clients\Client;
use App\Entity\Fournisseurs\Fournisseur;
use App\Entity\GestionComerciale\Commande;
use App\Entity\GestionComerciale\CommandeFournisseur;
use App\Entity\Inventaires\Inventaire;
use App\Entity\Kanban\Fiche;
use App\Entity\Notes\Categorie;
use App\Entity\Notes\Invitation;
use App\Entity\Notes\Note;
use App\Entity\Notes\Statut;
use App\Entity\Utilisateur\Contact;
use App\Entity\Utilisateur\Utilisateur;
use App\Form\Notes\NoteType;
use App\Form\Notes\SupprimerNoteType;
use App\Library\Datatable\Util\Datatable;
use App\Repository\Notes\NoteRepository;
use App\Service\FO\Mailer;
use App\Service\GestionComerciale\EmailService;
use App\Service\Notes\NoteGoogleAgendaService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Form\FormError;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class NoteController extends AbstractController
{
/**
* @Route("/rappels", name="dtc_lister_rappel")
*/
public function listeRappelAction(Request $request, EntityManagerInterface $entityManager)
{
//return false;
$user = $this->getUser();
$notes = $entityManager->getRepository(Note::class)->getRappel($user);
$rendu = $this->renderView('Notes/Note/template_note.html.twig', ['notes' => $notes]);
return new JsonResponse(['rendu' => $rendu]);
}
/**
* @Route("/rappels/termine/{id}/{type}", name="dtc_cloturer_rappel")
*/
public function cloturerRappelAction(Request $request, Note $note, $type = "", EntityManagerInterface $em)
{
if ($type == "fermer") {
$note->setTermine(1);
$em->persist($note);
$em->flush();
} else {
$delai = $request->query->get('delai');
if ($delai == "0") {
$note->setTermine(1);
$em->persist($note);
$em->flush();
} else {
$note->setTermine(0);
$date = new \DateTime();
if ($delai == "1H") {
$date->add(new \DateInterval('PT60M'));
} elseif ($delai == "5M") {
$date->add(new \DateInterval('PT05M'));
} else {
$date->add(new \DateInterval('P'.$delai.'D'));
}
$note->setDateRappel($date);
$em->persist($note);
$em->flush();
}
}
return new JsonResponse(['rendu' => "1"]);
}
/**
* @Route("/note/kanban/fiche/{id}/nouveau", name="dtc_note_kanban_ajouter")
*/
public function ajouterFicheKanbanAction(Request $request, Fiche $fiche, EntityManagerInterface $em, ValidatorInterface $validator, NoteGoogleAgendaService $serviceGoogleAgenda)
{
$user = $this->getUser();
$note = new Note();
$categorie_note = $em->getRepository(Categorie::class)->findAll();
$statutAfaire = $em->getRepository(Statut::class)->find(1);
$note->setStatut($statutAfaire);
$note->setUtilisateur($user);
if (is_object($fiche->getClient())) {
$note->setClient($fiche->getClient());
}
$dateNoteDebut = new \Datetime();
$dateNoteFin = new \Datetime();
$note->setDateDebut($dateNoteDebut);
$dateNoteFin = date_modify($dateNoteFin, "+1 hour");
$type_json = "";
$currentPath = "";
$currentPath = $request->query->get('currentPath');
$note->setFiche($fiche);
$note->setDateFin($dateNoteFin);
$form = $this->createForm(NoteType::class, $note);
$errors = "";
$form->handleRequest($request);
if ($form->isSubmitted()) {
/*
if(is_object($note->getStatut()) and $note->getStatut()->getId() == "1" and $note->getDateRappel() == NULL) {
$error = new FormError("Vous devez indiquer une date de rappel !");
$form->get('statut')->addError($error);
}
*/
if ($form->isValid()) {
if ($note->getLibelle() == "" and is_object($note->getCategorie())) {
$note->setLibelle($note->getCategorie()->getLibelle());
} elseif ($note->getLibelle() == "") {
$note->setLibelle("Sans titre");
}
$url = "";
if ($note->getAlerte() == "") {
$note->setDateRappel(null);
} else {
$dateRappel = new \Datetime($note->getDateDebut()->format('Y-m-d H:i:s'));
$dateRappel->add(new \DateInterval('PT'.$note->getAlerte().'M'));
$note->setDateRappel($dateRappel);
}
$em->persist($note);
$em->flush();
$serviceGoogleAgenda->ajouter($note);
return new JsonResponse(
['type_json' => $type_json, 'rendu' => '', 'valide' => '1', 'url' => $url, "errors" => $errors]
);
} else {
$errors = $validator->validate($note);
$errors = $this->renderView('layout-errors.html.twig', ['errors' => $errors, 'form' => $form->createView()]);
$rendu = $this->renderView(
'Notes/Note/ajouter_modal.html.twig',
['currentPath' => $currentPath, 'categorie_note' => $categorie_note, 'form' => $form->createView(), 'errors' => $errors, "fiche" => $fiche]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'errors' => $errors]);
}
}
return $this->render(
'Notes/Note/note_fiche.html.twig',
['currentPath' => $currentPath, 'categorie_note' => $categorie_note, 'form' => $form->createView(), 'errors' => $errors, "fiche" => $fiche]
);
}
/**
* @Route("/note/nouveau", name="dtc_note_ajouter")
*/
public function ajouterAction(Request $request, EntityManagerInterface $em, TranslatorInterface $translator, ValidatorInterface $validator, Mailer $emailService)
{
$type_json = "";
$param = $request->query->all();
$titre_modal = $translator->trans("Nouvelle Tâche");
$note = new Note();
$categorie_note = $em->getRepository(Categorie::class)->findAll();
$statutAfaire = $em->getRepository(Statut::class)->find(1);
$repo_user = $em->getRepository(Utilisateur::class);
$repo_invitation = $em->getRepository(Invitation::class);
$note->setStatut($statutAfaire);
$get = $request->query->all();
$dateDuJour = new \Datetime();
$dateNoteDebut = new \Datetime();
$dateNoteFin = new \Datetime();
$note->setDateDebut($dateNoteDebut);
$dateNoteFin = date_modify($dateNoteFin, "+1 hour");
// $dateNote->add(new \DateInterval('PT1H'));
$currentPath = "";
$currentPath = $request->query->get('callback');
$type_tache = "";
if (array_key_exists('type', $get) && $get["type"] != "") {
$type_tache = $get["type"];
}
if (array_key_exists('type', $get) && $get["type"] == "commande" && array_key_exists('id', $get) && $get["id"] != "") {
$repo_commande = $em->getRepository(Commande::class);
$obj = $repo_commande->find($get["id"]);
if (is_object($obj)) {
$note->setCommande($obj);
if (is_object($obj->getClient())) {
$note->setClient($obj->getClient());
}
}
} elseif (array_key_exists('type', $get) && $get["type"] == "fournisseur" && array_key_exists('id', $get) && $get["id"] != "") {
$repo_fournisseur = $em->getRepository(Fournisseur::class);
$obj = $repo_fournisseur->find($get["id"]);
if (is_object($obj)) {
$note->setFournisseur($obj);
}
} elseif (array_key_exists('type', $get) && $get["type"] == "client" && array_key_exists('id', $get) && $get["id"] != "") {
$repo_client = $em->getRepository(Client::class);
$obj = $repo_client->find($get["id"]);
if (is_object($obj)) {
$note->setClient($obj);
}
} elseif (array_key_exists('type', $get) && $get["type"] == "commandeFournisseur" && array_key_exists('id', $get) && $get["id"] != "") {
$repo_commande_fournisseur = $em->getRepository(CommandeFournisseur::class);
$obj = $repo_commande_fournisseur->find($get["id"]);
if (is_object($obj)) {
$note->setCommandeFournisseur($obj);
if (is_object($obj->getFournisseur())) {
$note->setFournisseur($obj->getFournisseur());
}
}
} elseif (array_key_exists('type', $get) && $get["type"] == "article" && array_key_exists('id', $get) && $get["id"] != "") {
$repo_article = $em->getRepository(Article::class);
$obj = $repo_article->find($get["id"]);
if (is_object($obj)) {
$note->setArticle($obj);
}
} elseif (array_key_exists('type', $get) && $get["type"] == "inventaire" && array_key_exists('id', $get) && $get["id"] != "") {
$repo_inventaire = $em->getRepository(Inventaire::class);
$obj = $repo_inventaire->find($get["id"]);
if (is_object($obj)) {
$note->setInventaire($obj);
}
}
$affaire = "";
$affaire_id = $request->query->get('affaire');
if ($affaire_id != "") {
$repo_affaire = $em->getRepository(Fiche::class);
$affaire = $repo_affaire->find($affaire_id);
if (is_object($affaire)) {
$note->setFiche($affaire);
if (is_object($affaire->getClient())) {
$note->setClient($affaire->getClient());
if (is_object($affaire->getContact())) {
$note->setContact($affaire->getContact());
}
}
}
}
$note->setDateFin($dateNoteFin);
//$equipiers = $repo_user->findAll();
$equipiers = $repo_user->findBy(["visible" => 1, "archive" => 0], ["prenom" => "asc"]);
$repo_client = $em->getRepository(Client::class);
$client = "";
if (array_key_exists('client', $param)) {
$client = $repo_client->find($param['client']);
if (is_object($client)) {
$note->setClient($client);
}
} elseif (array_key_exists('email', $param) && is_array($param["email"]) && count($param["email"]) > 0) {
//echo "<div>EMAIL ".$param["email"][0]."</div>";
$email_recherche = trim($param["email"][0]);
if ($email_recherche != "") {
$repo_client = $em->getRepository(Client::class);
$client_email = $repo_client->findOneBy(["email" => $email_recherche]);
if (is_object($client_email)) {
$note->setClient($client_email);
//echo "toto";
} else {
$repo_contact = $em->getRepository(Contact::class);
$contact_email = $repo_contact->findOneBy(["email" => $email_recherche]);
if (is_object($contact_email) && is_object($contact_email->getClient())) {
$note->setClient($contact_email->getClient());
$note->setContact($contact_email);
}
}
}
if (is_object($note->getClient())) {
$repo_affaire = $em->getRepository(Fiche::class);
$affaire = $repo_affaire->findOneBy(["client" => $note->getClient()], ["date" => "DESC"]);
if (is_object($affaire)) {
$note->setFiche($affaire);
}
}
}
$sujet = "";
if (array_key_exists('sujet', $param)) {
$note->setLibelle($param["sujet"]);
$sujet = $param["sujet"];
}
$user = $this->getUser();
$note->setUtilisateur($user);
//$form = $this->createForm(new NoteType($em), $note);
$form = $this->createForm(NoteType::class, $note);
$errors = "";
$form->handleRequest($request);
if ($form->isSubmitted()) {
/*
if(is_object($note->getStatut()) and $note->getStatut()->getId() == "1" and $note->getDateRappel() == NULL) {
$error = new FormError("Vous devez indiquer une date de rappel !");
$form->get('statut')->addError($error);
}
*/
if ($form->isValid()) {
$post = $request->request->all();
if ( ! is_object($note->getClient())) {
if (array_key_exists('clientSelect', $post) && $post["clientSelect"] != '') {
$post["clientSelect"] = substr($post["clientSelect"], 1, -1);
$client = new Client();
$client->setRaisonSociale($post["clientSelect"]);
$em->persist($client);
$note->setClient($client);
$em->flush();
}
}
if ( ! is_object($note->getContact())) {
if (array_key_exists('contactSelect', $post) && $post["contactSelect"] != '') {
$post["contactSelect"] = substr($post["contactSelect"], 1, -1);
$contact = new Contact();
$contact->setPrenom($post["contactSelect"]);
$contact->setClient($note->getClient());
$contact->setDefaut(false);
$em->persist($contact);
$note->setContact($contact);
}
}
//print_r($post);
if ($note->getLibelle() == "" and is_object($note->getCategorie())) {
$note->setLibelle($note->getCategorie()->getLibelle());
}
if (is_object($client)) {
$url = $this->generateUrl('dtc_client_modifier', ["tab" => "notes", "id" => $client->getId()]);
} elseif ($currentPath == "agenda" or $currentPath == "agenda") {
$url = "";
$type_json = "agenda";
} elseif ($currentPath != "") {
$url = $currentPath;
$type_json = "agenda";
} else {
$url = "";
//$url = $this->generateUrl('dtcfo_homepage', array());
}
$dateRappel = "";
if ($note->getAlerte() == "") {
$note->setDateRappel(null);
} else {
$dateRappel = new \Datetime($note->getDateDebut()->format('Y-m-d H:i:s'));
$dateRappel->sub(new \DateInterval('PT'.$note->getAlerte().'M'));
$note->setDateRappel($dateRappel);
}
if (is_object($dateRappel) && $dateRappel < $dateDuJour) {
$note->setTermine(1);
}
$em->persist($note);
$em->flush();
// Gérer les invitations
if (array_key_exists('invites', $post) && count($post["invites"]) > 0) {
for ($ii = 0; $ii < count($post["invites"]); $ii++) {
$invite = $repo_user->find($post["invites"][$ii]);
if (is_object($invite)) {
$invitation = new Invitation();
$invitation->setNote($note);
$invitation->setEmetteur($user);
$invitation->setDestinataire($invite);
$invitation->setJeton($invitation->generateRandomString());
$em->persist($invitation);
//$emailService->envoyerEmail($commande);
}
}
$em->flush();
}
if (array_key_exists('invites', $post) && count($post["invites"]) > 0) {
for ($ii = 0; $ii < count($post["invites"]); $ii++) {
$invite = $repo_user->find($post["invites"][$ii]);
$invitation = $repo_invitation->findOneBy(["note" => $note, "destinataire" => $invite]);
if (is_object($invite)) {
$emailService->sendMailInvitation($note, $invitation);
}
}
}
if ($note->getRecurrence() != "" && ! is_object($note->getParent())) {
if ( ! is_null($note->getFinRecurrence())) {
$dateFinRecurrence = new \Datetime($note->getFinRecurrence()->format('Y-m-d H:i:s'));
} else {
$dateFinRecurrence = new \Datetime($note->getDateDebut()->format('Y-m-d H:i:s'));
$dateFinRecurrence->add(new \DateInterval('P3650D'));
}
$dateTemp = new \Datetime($note->getDateDebut()->format('Y-m-d H:i:s'));
$dateDebutTemp = new \Datetime($note->getDateDebut()->format('Y-m-d H:i:s'));
$dateFinTemp = new \Datetime($note->getDateFin()->format('Y-m-d H:i:s'));
if (is_object($note->getDateRappel())) {
$dateRappelTemp = new \Datetime($note->getDateRappel()->format('Y-m-d H:i:s'));
}
$compteur_occurence = 300;
while ($dateTemp < $dateFinRecurrence and $compteur_occurence > 0) {
$compteur_occurence--;
$noteClonee = clone $note;
if ($note->getRecurrence() == "jour") {
$dateTemp->modify('+1 day');
$dateFinTemp->modify('+1 day');
if (is_object($note->getDateRappel())) {
$dateRappelTemp->modify('+1 day');
}
$dateDebutTemp->modify('+1 day');
}
if ($note->getRecurrence() == "semaine") {
$dateTemp->modify('+1 week');
$dateFinTemp->modify('+1 week');
if (is_object($note->getDateRappel())) {
$dateRappelTemp->modify('+1 week');
}
$dateDebutTemp->modify('+1 week');
}
if ($note->getRecurrence() == "mois") {
$dateTemp->modify('+1 month');
$dateFinTemp->modify('+1 month');
if (is_object($note->getDateRappel())) {
$dateRappelTemp->modify('+1 month');
}
$dateDebutTemp->modify('+1 month');
}
if ($note->getRecurrence() == "an") {
$dateTemp->modify('+1 year');
$dateFinTemp->modify('+1 year');
if (is_object($note->getDateRappel())) {
$dateRappelTemp->modify('+1 year');
}
$dateDebutTemp->modify('+1 year');
}
$dateDebutTempBis = new \Datetime($dateDebutTemp->format('Y-m-d H:i:s'));
$dateFinTempBis = new \Datetime($dateFinTemp->format('Y-m-d H:i:s'));
if (is_object($note->getDateRappel())) {
$dateRappelTempBis = new \Datetime($dateRappelTemp->format('Y-m-d H:i:s'));
}
$noteClonee->setDateDebut($dateDebutTempBis);
$noteClonee->setDateFin($dateFinTempBis);
if (is_object($note->getDateRappel())) {
$noteClonee->setDateRappel($dateRappelTempBis);
}
if (is_object($note->getDateRappel()) && $dateRappelTempBis < $dateDuJour) {
$noteClonee->setTermine(1);
}
/*
$noteClonee->setDateDebut($dateDebutTemp);
$noteClonee->setDateFin($dateFinTemp);
$noteClonee->setDateRappel($dateRappelTemp);
*/
$note->setParent($note);
$noteClonee->setParent($note);
//$serviceGoogleAgenda = $this->get('dtc.notegoogleagenda');
//$serviceGoogleAgenda->ajouter($noteClonee);
$em->persist($noteClonee);
// Gérer les invitations
if (array_key_exists('invites', $post) && count($post["invites"]) > 0) {
for ($ii = 0; $ii < count($post["invites"]); $ii++) {
$invite = $repo_user->find($post["invites"][$ii]);
if (is_object($invite)) {
$invitation = new Invitation();
$invitation->setNote($noteClonee);
$invitation->setEmetteur($user);
$invitation->setDestinataire($invite);
$invitation->setJeton($invitation->generateRandomString());
$em->persist($invitation);
//$emailService->envoyerEmail($commande);
}
}
$em->flush();
$em->refresh($noteClonee);
}
$em->flush();
$em->refresh($noteClonee);
//$builder = new ProcessBuilder();
//$builder->setArguments(array('php', '../app/console', 'cron:synchronisationgoogleagenda','ajouter',$noteClonee->getId()));
//$builder->getProcess()->start();
$process = new Process(['php', 'bin/console', 'cron:synchronisationgoogleagenda', 'ajouter', $noteClonee->getId()]);
$process->setWorkingDirectory($this->getParameter('kernel.project_dir'));
$process->setOptions(['create_new_console' => true]);
$process->start();
}
}
$em->flush();
$em->refresh($note);
//$serviceGoogleAgenda = $this->get('dtc.notegoogleagenda');
//$serviceGoogleAgenda->ajouter($note);
/*
$builder = new Process();
$builder->setWorkingDirectory("../");
$builder->setArguments(['php', 'bin/console', 'cron:synchronisationgoogleagenda', 'ajouter', $note->getId()]);
$builder->run();
*/
$process = new Process(['php', 'bin/console', 'cron:synchronisationgoogleagenda', 'ajouter', $note->getId()]);
$process->setWorkingDirectory($this->getParameter('kernel.project_dir'));
$process->setOptions(['create_new_console' => true]);
$process->start();
/*
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
*/
//exit;
if (array_key_exists('origine', $get) && $get["origine"] == "webmail") {
//echo "A";
//exit;
return new JsonResponse(['rendu' => '', 'valide' => '1', 'url' => $url, 'type' => 'ajout_note_webmail']);
} elseif (array_key_exists('table', $get) && $get["table"] != "") {
//echo "B";
//exit;
return new Response(
json_encode(['rendu' => '', 'valide' => '1', 'url' => $url, 'type' => 'recharger_datatable', 'id_datatable' => $get["table"]]),
200,
['Content-Type' => 'application/json']
);
} else {
//echo "C(".$type_json.":".$currentPath.")";
//exit;
return new JsonResponse(['type' => $type_json, 'rendu' => '', 'valide' => '1', 'url' => $url]);
}
return new JsonResponse(['type_json' => $type_json, 'rendu' => '', 'valide' => '1', 'url' => $url]);
} else {
$errors = $validator->validate($note);
$rendu = $this->renderView(
'Notes/Note/ajouter_modal.html.twig',
[
'note' => $note,
'sujet' => $sujet,
'affaire' => $affaire,
'equipiers' => $equipiers,
'currentPath' => $currentPath,
'categorie_note' => $categorie_note,
'form' => $form->createView(),
'errors' => $errors,
'type_tache' => $type_tache,
]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
}
$rendu = $this->renderView(
'Notes/Note/ajouter_modal.html.twig',
[
'note' => $note,
'sujet' => $sujet,
'affaire' => $affaire,
'equipiers' => $equipiers,
'currentPath' => $currentPath,
'categorie_note' => $categorie_note,
'form' => $form->createView(),
'errors' => $errors,
'type_tache' => $type_tache,
]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
/**
* @Route("/note/modifier/{objet}/{id}/{type}", name="dtc_note_modifier")
*/
public function modifierAction(Request $request, Note $objet, $id, $type, EntityManagerInterface $em, TranslatorInterface $translator, ValidatorInterface $validator, Mailer $emailService
) {
$type_json = "";
$note = $objet;
$user = $this->getUser();
$param = $request->query->all();
$get = $request->query->all();
$categorie_note = $em->getRepository(Categorie::class)->findAll();
$repo_note = $em->getRepository(Note::class);
$repo_user = $em->getRepository(Utilisateur::class);
$repo_invitation = $em->getRepository(Invitation::class);
$dateDuJour = new \Datetime();
//$equipiers = $repo_user->findAll();
//$equipiers = $repo_user->findBy(array("visible"=>1,"visibileListingMail"=>1,"archive"=>0));
$equipiers = $repo_user->findBy(["visible" => 1, "archive" => 0], ["prenom" => "asc"]);
$invites = $repo_invitation->findBy(["note" => $note]);
$affaire = "";
/*
if(is_object($note->getFiche())) {
$affaire = $note->getFiche();
}
*/
if ($user->getId() != $note->getUtilisateur()->getId() and $note->getPrive()) {
$titre_modal = $translator->trans("Note privé");
$rendu = $this->renderView('Notes/Note/note_prive.html.twig', ["errors" => "Cette note est privé, vous ne pouvez pas la visualiser"]);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
if ($user->getId() != $note->getUtilisateur()->getId() and 1 != 1) {
$titre_modal = $translator->trans("Affichage tâche");
$errors = "";
$form = $this->createForm(NoteType::class, $note);
$rendu = $this->renderView(
'Notes/Note/afficher_modal.html.twig',
[
'invites' => $invites,
'equipiers' => $equipiers,
'categorie_note' => $categorie_note,
'note' => $note,
'errors' => $errors,
'form' => $form->createView(),
]
);
return new Response(json_encode(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]));
}
$titre_modal = $translator->trans("Modifier une tâche");
//$note = new Note;
$client = "";
if (array_key_exists('client', $param)) {
$repo_client = $em->getRepository(Client::class);
$client = $repo_client->find($param['client']);
if (is_object($client)) {
$note->setClient($client);
}
}
$user = $this->getUser();
//$note->setUtilisateur($user);
$form = $this->createForm(NoteType::class, $note);
$errors = "";
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$post = $request->request->all();
//print_r($post);
//exit;
if ($type == "liste") {
$url = $this->generateUrl('dtc_note_liste', []);
//$this->addFlash('notice',$translator->trans('Note modifiée avec succès !'));
} elseif ($type == "agenda") {
$url = "";
$type_json = "agenda";
} elseif (is_object($note->getClient())) {
$url = $this->generateUrl('dtc_client_modifier', ["tab" => "notes", "id" => $note->getClient()->getId()]);
} elseif ($type == "kanban") {
//$rendu = $this->renderView('Notes/Note/ajouter_modal.html.twig', array('invites'=>$invites, 'equipiers'=>$equipiers,'categorie_note'=>$categorie_note,'form' => $form->createView(),'errors'=>$errors,'note'=>$note));
//return new Response(json_encode(array('rendu'=>$rendu,'valide'=>'0','url'=>'','titre'=>$titre_modal)), 200, array('Content-Type'=>'application/json'));
$url = "";
$type_json = "";
} else {
$url = $this->generateUrl('dtcfo_homepage', []);
}
if ($note->getAlerte() == "") {
$note->setDateRappel(null);
} else {
$dateRappel = new \Datetime($note->getDateDebut()->format('Y-m-d H:i:s'));
$dateRappel->add(new \DateInterval('PT'.$note->getAlerte().'M'));
$note->setDateRappel($dateRappel);
}
if ($dateDuJour > $note->getDateDebut()) {
$note->setTermine(1);
} else {
$note->setTermine(0);
}
if ($note->getMessage() == "undefined") {
$note->setMessage("");
}
$em->persist($note);
$em->flush();
$tab_nouveaux_invites = [];
// Gérer les invitations
if (array_key_exists('invites', $post) && count($post["invites"]) > 0) {
for ($ii = 0; $ii < count($post["invites"]); $ii++) {
//echo "<div>Z</div>";
$invite = $repo_user->find($post["invites"][$ii]);
$deja_invite = $repo_invitation->findOneBy(["note" => $note, "destinataire" => $invite]);
if (is_object($invite) and ! is_object($deja_invite)) {
//echo "<div>A</div>";
$invitation = new Invitation();
$invitation->setNote($note);
$invitation->setEmetteur($user);
$invitation->setDestinataire($invite);
$invitation->setJeton($invitation->generateRandomString());
$em->persist($invitation);
$tab_nouveaux_invites[] = $invite;
//$emailService->envoyerEmail($commande);
} else {
// echo "<div>B</div>";
$invitation = $repo_invitation->findOneBy(["note" => $note, "destinataire" => $invite]);
if (is_object($invite) and (is_null($invitation->getAccepte()) or $invitation->getAccepte() == 1)) {
$emailService->sendMailInvitationModifier($note, $invitation);
}
}
}
$em->flush();
}
if (count($tab_nouveaux_invites) > 0) {
foreach ($tab_nouveaux_invites as $nouveau_invite) {
//echo "<div>R</div>";
$invitation = $repo_invitation->findOneBy(["note" => $note, "destinataire" => $nouveau_invite]);
if (is_object($invite)) {
//echo "<div>T</div>";
$emailService->sendMailInvitation($note, $invitation);
}
}
}
//print_r($post);
if (array_key_exists('operation', $post) && $post["operation"] == "futur" && is_object($note->getParent())) {
//mail("thomas@noogaa.com","A tes edit ".$note->getId(),"tes edit ".$note->getId());
$repo_note = $em->getRepository(Note::class);
$notesEnfants = $repo_note->findBy(["parent" => $note->getParent()]);
if (count($notesEnfants) > 0) {
foreach ($notesEnfants as $ne) {
//if($ne->getDateDebut() > $note->getDateDebut() && $note->getId() != $ne->getId()) {
if ($note->getId() != $ne->getId()) {
//mail("thomas@noogaa.com","B tes edit ".$note->getId(),"tes edit ".$note->getId());
$em->remove($ne);
$em->flush();
/*
// TODO refactor command
$builder = new ProcessBuilder();
$builder->setWorkingDirectory("../");
$builder->setArguments(['php', 'bin/console', 'cron:synchronisationgoogleagenda', 'supprimer', $ne->getId()]);
$builder->getProcess()->start();
*/
}
}
} else {
//mail("thomas@noogaa.com","C tes edit ".$note->getId(),"tes edit ".$note->getId());
}
}
//echo "BBBBBBBB==>".$note->getRecurrence();
//if(!is_object($note->getParent())) {
if ((array_key_exists('operation', $post) && $post["operation"] == "futur" && is_object($note->getParent())) or (array_key_exists(
'operation',
$post
) && $post["operation"] == "")) {
if ($note->getRecurrence() != "") {
$note->setParent($note);
if ( ! is_null($note->getFinRecurrence())) {
$dateFinRecurrence = new \Datetime($note->getFinRecurrence()->format('Y-m-d H:i:s'));
} else {
$dateFinRecurrence = new \Datetime($note->getDateDebut()->format('Y-m-d H:i:s'));
$dateFinRecurrence->add(new \DateInterval('P3650D'));
}
$dateTemp = new \Datetime($note->getDateDebut()->format('Y-m-d H:i:s'));
$dateDebutTemp = new \Datetime($note->getDateDebut()->format('Y-m-d H:i:s'));
$dateFinTemp = new \Datetime($note->getDateFin()->format('Y-m-d H:i:s'));
if (is_object($note->getDateRappel())) {
$dateRappelTemp = new \Datetime($note->getDateRappel()->format('Y-m-d H:i:s'));
}
$compteur_occurence = 300;
//echo "XXXXXXXX";
while ($dateTemp < $dateFinRecurrence and $compteur_occurence > 0) {
//echo "R";
$compteur_occurence--;
$noteClonee = clone $note;
if ($note->getRecurrence() == "jour") {
$dateTemp->modify('+1 day');
$dateFinTemp->modify('+1 day');
if (is_object($note->getDateRappel())) {
$dateRappelTemp->modify('+1 day');
}
$dateDebutTemp->modify('+1 day');
}
if ($note->getRecurrence() == "semaine") {
$dateTemp->modify('+1 week');
$dateFinTemp->modify('+1 week');
if (is_object($note->getDateRappel())) {
$dateRappelTemp->modify('+1 week');
}
$dateDebutTemp->modify('+1 week');
}
if ($note->getRecurrence() == "mois") {
$dateTemp->modify('+1 month');
$dateFinTemp->modify('+1 month');
if (is_object($note->getDateRappel())) {
$dateRappelTemp->modify('+1 month');
}
$dateDebutTemp->modify('+1 month');
}
if ($note->getRecurrence() == "an") {
$dateTemp->modify('+1 year');
$dateFinTemp->modify('+1 year');
if (is_object($note->getDateRappel())) {
$dateRappelTemp->modify('+1 year');
}
$dateDebutTemp->modify('+1 year');
}
$dateDebutTempBis = new \Datetime($dateDebutTemp->format('Y-m-d H:i:s'));
$dateFinTempBis = new \Datetime($dateFinTemp->format('Y-m-d H:i:s'));
if (is_object($note->getDateRappel())) {
$dateRappelTempBis = new \Datetime($dateRappelTemp->format('Y-m-d H:i:s'));
}
$noteClonee->setDateDebut($dateDebutTempBis);
$noteClonee->setDateFin($dateFinTempBis);
if (is_object($note->getDateRappel())) {
$noteClonee->setDateRappel($dateRappelTempBis);
}
if (is_object($note->getDateRappel()) && $dateRappelTempBis < $dateDuJour) {
$noteClonee->setTermine(1);
}
/*
$noteClonee->setDateDebut($dateDebutTemp);
$noteClonee->setDateFin($dateFinTemp);
$noteClonee->setDateRappel($dateRappelTemp);
*/
$note->setParent($note);
$noteClonee->setParent($note);
$noteClonee->setIdImport(null);
$em->persist($noteClonee);
$em->flush();
$em->refresh($noteClonee);
// TODO refactor command
/*
$builder = new ProcessBuilder();
$builder->setWorkingDirectory("../");
$builder->setArguments(['php', 'bin/console', 'cron:synchronisationgoogleagenda', 'ajouter', $noteClonee->getId()]);
$builder->getProcess()->start();
*/
}
$em->flush();
}
}
//$serviceGoogleAgenda = $this->get('dtc.notegoogleagenda');
//$serviceGoogleAgenda->modifier($note);
$em->refresh($note);
// TODO refactor command
/*
$builder = new ProcessBuilder();
$builder->setWorkingDirectory("../");
$builder->setArguments(['php', 'bin/console', 'cron:synchronisationgoogleagenda', 'modifier', $note->getId()]);
$builder->getProcess()->start();
*/
$url = "";
if (array_key_exists('table', $get) && $get["table"] != "") {
return new JsonResponse(
['rendu' => '', 'valide' => '1', 'url' => $url, 'type' => 'recharger_datatable', 'id_datatable' => $get["table"]]
);
} else {
if ($type == "liste") {
$this->addFlash('notice', $translator->trans('Note modifiée avec succès !'));
}
return new JsonResponse(['type' => $type_json, 'rendu' => '', 'valide' => '1', 'url' => $url]);
}
return new JsonResponse(['type' => $type_json, 'rendu' => '', 'valide' => '1', 'url' => $url]);
} else {
$errors = $validator->validate($note);
$rendu = $this->renderView(
'Notes/Note/ajouter_modal.html.twig',
[
'affaire' => $affaire,
'invites' => $invites,
'equipiers' => $equipiers,
'categorie_note' => $categorie_note,
'form' => $form->createView(),
'errors' => $errors,
'note' => $note,
]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
}
$rendu = $this->renderView(
'Notes/Note/ajouter_modal.html.twig',
[
'affaire' => $affaire,
'invites' => $invites,
'equipiers' => $equipiers,
'categorie_note' => $categorie_note,
'form' => $form->createView(),
'errors' => $errors,
'note' => $note,
]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
/**
* @Route("/note/supprimer/{objet}/{id}/{type}", name="dtc_note_supprimer")
*/
public function supprimerAction(Request $request, Note $objet, $id, $type, EntityManagerInterface $em, TranslatorInterface $translator, Mailer $mailer,
ValidatorInterface $validator
) {
$note = $objet;
$form = $this->createForm(SupprimerNoteType::class, $note);
$get = $request->query->all();
/* if($user->getId() != $note->getUtilisateur()->getId()) { à changer
$titre_modal=$translator->trans("Demande de confirmation");
$erreur = "Cette note a été mise en ligne par ".$note->getUtilisateur()->getPrenom()." ".$note->getUtilisateur()->getNom().", vous ne pouvez pas la supprimer.";
$rendu = $this->renderView('FO/Supprimer/supprimer_impossible.html.twig', array('errors'=>$erreur));
return new Response(json_encode(array('rendu'=>$rendu,'valide'=>'0','url'=>'','titre'=>$titre_modal)), 200, array('Content-Type'=>'application/json'));
}*/
$titre_modal = $translator->trans("Demande de confirmation");
$errors = "";
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$type_json = "";
if ($form->isValid()) {
$post = $request->request->all();
if (array_key_exists('operation', $post) && $post["operation"] == "futur" && is_object($note->getParent())) {
$repo_note = $em->getRepository(Note::class);
$notesEnfants = $repo_note->findBy(["parent" => $note->getParent()]);
if (count($notesEnfants) > 0) {
foreach ($notesEnfants as $ne) {
if ($ne->getDateDebut() > $note->getDateDebut()) {
// TODO refactor command
// $builder = new ProcessBuilder();
// $builder->setWorkingDirectory("../");
// $builder->setArguments(array('php', 'bin/console', 'cron:synchronisationgoogleagenda', 'supprimer', $ne->getId()));
// $builder->getProcess()->start();
$em->remove($ne);
//$serviceGoogleAgenda = $this->get('dtc.notegoogleagenda');
//$serviceGoogleAgenda->supprimer($ne);
/*
$builder = new ProcessBuilder();
$builder->setArguments(array('php', '../bin/console', 'cron:synchronisationgoogleagenda','supprimer',$ne->getId()));
$builder->getProcess()->start();
*/
}
}
}
}
$repo_invitation = $em->getRepository(Invitation::class);
$invites = $repo_invitation->findBy(["note" => $note]);
if (count($invites) > 0) {
foreach ($invites as $inv) {
//$emailService->sendMailInvitation($note,$invite);
if (is_null($inv->getAccepte()) or $inv->getAccepte() == "1") {
$mailer->sendMailInvitationAnnule($note, $inv);
}
}
}
// TODO refactor commmand
// $builder = new ProcessBuilder();
// $builder->setWorkingDirectory("../");
// $builder->setArguments(array('php', 'bin/console', 'cron:synchronisationgoogleagenda', 'supprimer', $note->getId()));
// $builder->getProcess()->start();
$em->remove($note);
$em->flush();
if ($type == "liste") {
$url = $this->generateUrl('dtc_note_liste', []);
} elseif ($type == "agenda") {
$url = "";
$type_json = "agenda";
} elseif (is_object($note->getClient())) {
$url = $this->generateUrl('dtc_client_modifier', ["tab" => "notes", "id" => $note->getClient()->getId()]);
} else {
$url = $this->generateUrl('dtcfo_homepage', []);
}
//$serviceGoogleAgenda = $this->get('dtc.notegoogleagenda');
//$serviceGoogleAgenda->supprimer($note);
/*
$builder = new ProcessBuilder();
$builder->setArguments(array('php', '../bin/console', 'cron:synchronisationgoogleagenda','supprimer',$note->getId()));
$builder->getProcess()->start();
*/
$url = "";
if (array_key_exists('table', $get) && $get["table"] != "") {
return new JsonResponse(
['rendu' => '', 'valide' => '1', 'url' => $url, 'type' => 'recharger_datatable', 'id_datatable' => $get["table"]]
);
} else {
if ($type != "agenda") {
$this->addFlash('notice', $translator->trans('Note supprimée avec succès !'));
}
return new JsonResponse(['type' => $type_json, 'rendu' => '', 'valide' => '1', 'url' => $url]);
}
} else {
$errors = $validator->validate($note);
$rendu = $this->renderView(
'Notes/Note/supprimer.html.twig',
['form' => $form->createView(), 'errors' => $errors, 'id' => $note->getId(), 'note' => $note, 'type' => '']
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
}
$rendu = $this->renderView('Notes/Note/supprimer.html.twig', ['form' => $form->createView(), 'id' => $note->getId(), 'type' => '', 'errors' => $errors, 'note' => $note]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
/**
* @Route("/note/client", name="dtc_note_liste")
* @Route("/note/", name="dtc_note_liste2")
*/
public function listerAction(Request $request, Datatable $datatable, TranslatorInterface $translator, EntityManagerInterface $em)
{
$user = $this->getUser();
$categorie = $request->query->get('cat');
$param = $request->query->all();
$repo_statut = $em->getRepository(Statut::class);
$statut = null;
if (array_key_exists('statut', $param)) {
$statut = $repo_statut->find($param["statut"]);
}
$tableau_class_cellule = [];
$tableau_class_cellule[] = ["className" => "colonne_id", "targets" => [0], "visible" => false, "orderable" => false, "searchable" => false];
$tableau_class_cellule[] = ["className" => "colonne_id", "targets" => [1], "visible" => false, "orderable" => false, "searchable" => false];
$tableau_class_cellule[] = ["className" => "colonne_id text-center", "targets" => [2], "visible" => true, "orderable" => false, "searchable" => false];
$tableau_class_cellule[] = ["className" => "colonne_id text-center", "targets" => [9], "visible" => true, "orderable" => false, "searchable" => false];
$tableau_class_cellule[] = ["className" => "colonne_id text-center", "targets" => [11], "visible" => true, "orderable" => false, "searchable" => false];
//$tableau_class_cellule[]=array("className"=>"colonne_id","targets"=>array(0),"visible"=>false,"orderable"=>false,"searchable"=> false);
//$tableau_class_cellule[]=array("className"=>"visible_export colonne_id","targets"=>array(1),"visible"=>$serviceColonneTableau->getColonneUtilisateur("DTCNotesBundle:Note","id"),"orderable"=>true,"searchable"=> false);
//$tableau_class_cellule[]=array("className"=>"visible_export colonne_id","targets"=>array(2),"visible"=>$serviceColonneTableau->getColonneUtilisateur("DTCNotesBundle:Note","message"),"orderable"=>true,"searchable"=> false);
//$tableau_class_cellule[]=array("className"=>"visible_export colonne_id","targets"=>array(3),"visible"=>$serviceColonneTableau->getColonneUtilisateur("DTCNotesBundle:Note","cat"),"orderable"=>true,"searchable"=> false);
//$tableau_class_cellule[]=array("className"=>"visible_export colonne_id","targets"=>array(4),"visible"=>$serviceColonneTableau->getColonneUtilisateur("DTCNotesBundle:Note","client"),"orderable"=>true,"searchable"=> false);
//$tableau_class_cellule[]=array("className"=>"visible_export colonne_id","targets"=>array(5),"visible"=>$serviceColonneTableau->getColonneUtilisateur("DTCNotesBundle:Note","contact"),"orderable"=>true,"searchable"=> false);
//$tableau_class_cellule[]=array("className"=>"visible_export colonne_id","targets"=>array(6),"visible"=>$serviceColonneTableau->getColonneUtilisateur("DTCNotesBundle:Note","date"),"orderable"=>true,"searchable"=> false);
//$tableau_class_cellule[]=array("className"=>"visible_export colonne_id","targets"=>array(7),"visible"=>$serviceColonneTableau->getColonneUtilisateur("DTCNotesBundle:Note","rappel"),"orderable"=>true,"searchable"=> false);
//$tableau_class_cellule[]=array("orderable"=>false,"className"=>"colonne_id","targets"=>array(8),"visible"=>true);
$tableau_class_cellule = [];
$tableau_class_cellule[] = ["className" => "colonne_id", "targets" => [0], "visible" => false, "orderable" => false, "searchable" => false];
$tableau_class_cellule[] = ["className" => "colonne_id", "targets" => [1], "visible" => false, "orderable" => false, "searchable" => false];
$tableau_class_cellule[] = ["className" => "colonne_id text-center", "targets" => [2], "visible" => true, "orderable" => true, "searchable" => false];
$tableau_class_cellule[] = ["className" => "colonne_id ", "targets" => [3], "visible" => true, "orderable" => true, "searchable" => false];
$tableau_class_cellule[] = ["className" => "colonne_id ", "targets" => [4], "visible" => true, "orderable" => true, "searchable" => false];
$tableau_class_cellule[] = ["className" => "colonne_id ", "targets" => [5], "visible" => true, "orderable" => true, "searchable" => false];
$tableau_class_cellule[] = ["className" => "colonne_id ", "targets" => [6], "visible" => true, "orderable" => true, "searchable" => false];
$tableau_class_cellule[] = ["className" => "colonne_id text-center", "targets" => [7], "visible" => true, "orderable" => true, "searchable" => false];
$tableau_class_cellule[] = ["className" => "colonne_id ", "targets" => [8], "visible" => true, "orderable" => true, "searchable" => false];
$tableau_class_cellule[] = ["className" => "colonne_id ", "targets" => [9], "visible" => true, "orderable" => false, "searchable" => false];
$this->datatable($request, $datatable, $translator);
$parametres = [];
if ( ! array_key_exists('equipiers', $param)) {
$param['equipiers'] = [$user->getId()];
}
if ( ! array_key_exists('statut', $param)) {
$param['statut'] = 1;//à faire
}
//$parametres["parametres"] = $param;
$listeCategorieNote = $em->getRepository(Categorie::class)->findAll();
$repo_user = $em->getRepository(Utilisateur::class);
//$equipiers = $repo_user->findAll();
//$equipiers = $repo_user->findBy(array("visible"=>1,"visibileListingMail"=>1,"archive"=>0));
$equipiers = $repo_user->findBy(["visible" => 1, "archive" => 0], ["prenom" => "asc"]);
return $this->render('Notes/Note/lister.html.twig', [
'listeCategorieNote' => $listeCategorieNote,
'categorie' => $categorie,
'parametres' => $param,
'statut' => $statut,
'statuts' => $repo_statut->findAll(),
'tableauClassColonne' => $tableau_class_cellule,
'equipiers' => $equipiers,
]);
}
/**
* @Route("/note/grid", name="dtc_note_liste_grid")
*/
public function gridAction(Request $request, Datatable $datatable, TranslatorInterface $translator)
{
return $this->datatable($request, $datatable, $translator)->execute();
}
private function datatable(Request $request, Datatable $datatable, TranslatorInterface $translator)
{
$param = $request->query->all();
//var_dump($param);
$user = $this->getUser();
$datatable->setDatatableId('dta-notes-clients')
->setEntity(Note::class, "x")
->setFields(
[
$translator->trans("ID") => 'x.id',
$translator->trans("Date échéance") => 'x.dateDebut',
//$translator->trans("Offre") => 'f.reference',
//$translator->trans("Tunnel") => 'k.libelle',
$translator->trans("Client") => 'cl.nom',
$translator->trans("Titre") => 'x.libelle',
$translator->trans("Type") => 'cn.libelle',
$translator->trans("Contact") => 'c.nom',
$translator->trans("Statut") => 's.libelle',
$translator->trans("Auteur") => 'u.nom',
$translator->trans("Actions") => 'x.id',
"_identifier_" => 'x.id',
]
)
//->addJoin('x.fiche', 'f', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
//->addJoin('f.kanban', 'k', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->addJoin('x.categorie', 'cn', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->addJoin('x.statut', 's', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->addJoin('x.contact', 'c', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->addJoin('x.client', 'cl', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->addJoin('x.utilisateur', 'u', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->setRenderers(
[
1 => [
'view' => 'FO/DataTable/heure.html.twig',
'params' => [],
],
2 => [
'view' => 'FO/DataTable/avec_lien_edit_route.html.twig',
'params' => [
'edit_route' => 'dtc_client_modifier',
'typeDocument' => 'client',
],
],
3 => [
'view' => 'FO/DataTable/titre_activite.html.twig',
'params' => [
'edit_route' => 'dtc_note_modifier',
'supprimer_route' => 'dtc_note_supprimer',
//'id' => $client->getId(),
'width_modal' => 900,
'type' => "liste",
'objet' => Note::class,
],
],
4 => [
'view' => 'FO/DataTable/type_activite.html.twig',
'params' => [],
],
5 => [
'view' => 'FO/DataTable/contact.html.twig',
'params' => [],
],
7 => [
'view' => 'FO/DataTable/utilisateur.html.twig',
'params' => [],
],
8 => [
'view' => 'FO/DataTable/actions_activites_modal.html.twig',
'params' => [
'edit_route' => 'dtc_note_modifier',
'supprimer_route' => 'dtc_note_supprimer',
//'id' => $client->getId(),
'width_modal' => 900,
'type' => "liste",
'objet' => Note::class,
'table' => "dta-notes-clients",
],
],
]
)
->setOrder("x.dateDebut", "desc")
->setSearch(true)
->setSearchFields([2])
->setMultiple(
[
'delete' => [
'title' => $translator->trans('Non disponible'),
'route' => 'dtc_commande_liste_supprimer',
],
]
);
$where = "";
$where = "(x.prive = :prive OR x.prive IS NULL OR x.utilisateur = :utilisateur) AND (x.categorie != :categorieintervention or x.categorie is null) AND x.statut = :statut";
$parameters = ["prive" => 0, "utilisateur" => $user, "categorieintervention" => 8, 'statut' => 1];
$where = "(x.categorie NOT IN (:categorieintervention) or x.categorie IS NULL) and (x.modifiable is null or x.modifiable=1)";
$parameters = ["categorieintervention" => [8]];
//dump($param);
if (array_key_exists('parametres', $param)) {
if (array_key_exists('affaire', $param["parametres"]) and $param["parametres"]["affaire"] > 0) {
$parameters["affaire"] = $param["parametres"]["affaire"];
if ($where != "") {
$where .= " AND";
}
$where .= " x.fiche >= :affaire";
}
if (array_key_exists('cat_activites_hidden', $param["parametres"]) and $param["parametres"]["cat_activites_hidden"] != "") {
//$datatable->addJoin('x.client', 'client', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
$parameters["cat_activite"] = $param["parametres"]["cat_activites_hidden"];
if ($where != "") {
$where .= " AND ";
}
$where .= "cn.id = :cat_activite";
}
if (array_key_exists('client', $param["parametres"]) and $param["parametres"]["client"] > 0) {
//$datatable->addJoin('x.client', 'client', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
$parameters["client"] = $param["parametres"]["client"];
if ($where != "") {
$where .= " AND ";
}
$where .= "x.client = :client";
}
if (array_key_exists('date_debut', $param["parametres"]) and $param["parametres"]["date_debut"] > 0) {
$debut = \DateTime::createFromFormat('d/m/Y', $param["parametres"]['date_debut']);
$debut->setTime(00, 00, 00);
$parameters["debut"] = $debut;
if ($where != "") {
$where .= " AND";
}
$where .= " x.dateDebut >= :debut";
}
if (array_key_exists('equipiers', $param["parametres"]) and count($param["parametres"]["equipiers"]) > 0) {
if ($where != "") {
$where .= " AND";
}
$where .= " x.utilisateur IN (:equipiers) AND (x.prive = :prive OR x.prive IS NULL OR x.utilisateur = :utilisateur)";
$parameters["equipiers"] = $param["parametres"]["equipiers"];
$parameters["utilisateur"] = $user;
$parameters["prive"] = 0;
//echo "AAAA";
}
if (array_key_exists('date_fin', $param["parametres"]) and $param["parametres"]["date_fin"] > 0) {
$fin = \DateTime::createFromFormat('d/m/Y', $param["parametres"]['date_fin']);
$fin->setTime(23, 59, 59);
$parameters["fin"] = $fin;
if ($where != "") {
$where .= " AND";
}
$where .= " x.dateDebut <= :fin";
}
if (array_key_exists('statut', $param["parametres"]) and $param["parametres"]["statut"] > 0) {
$parameters["statut"] = $param["parametres"]["statut"];
if ($where != "") {
$where .= " AND";
}
$where .= " s.id = :statut";
}
if (array_key_exists('cat', $param["parametres"]) and $param["parametres"]["cat"] > 0) {
$parameters["cat"] = $param["parametres"]["cat"];
if ($where != "") {
$where .= " AND";
}
$where .= " cn.id = :cat";
}
}
if ($where != '') {
//echo $where."<br/><br/>";
//print_r($param) ;
//exit;
$datatable->setWhere($where, $parameters);
}
return $datatable;
}
/**
* @Route("/tache/charger-tableau/{id}/{type}", name="dtc_tache_article_charger_tableau")
* @Route("/tache/charger-tableau/{id}/{type}", name="dtc_tache_client_charger_tableau")
* @Route("/tache/charger-tableau/{id}/{type}", name="dtc_tache_fournisseur_charger_tableau")
* @Route("/tache/charger-tableau/{id}/{type}", name="dtc_tache_commandeFournisseur_charger_tableau")
* @Route("/tache/charger-tableau/{id}/{type}", name="dtc_tache_commande_charger_tableau")
* @Route("/note/charger-tableau/{id}/{type}", name="dtc_note_charger_tableau")
*/
public function chargerTableauAction(Request $request, $id = "0", $type = "", EntityManagerInterface $em)
{
$objet = null;
if ($type == "article") {
$repo_objet = $em->getRepository(Article::class);
$objet = $repo_objet->find($id);
} elseif ($type == "client") {
$repo_objet = $em->getRepository(Client::class);
$objet = $repo_objet->find($id);
} elseif ($type == "commande") {
$repo_objet = $em->getRepository(Commande::class);
$objet = $repo_objet->find($id);
} elseif ($type == "commandeFournisseur") {
$repo_objet = $em->getRepository(CommandeFournisseur::class);
$objet = $repo_objet->find($id);
} elseif ($type == "fournisseur") {
$repo_objet = $em->getRepository(Fournisseur::class);
$objet = $repo_objet->find($id);
}
$rendu = $this->renderView('Notes/Note/charger_tableau.html.twig', ["id" => $id, "type" => $type, "objet" => $objet]);
return new JsonResponse(['rendu' => $rendu]);
}
}