diff --git a/src/Controller/AnnonceCreationController.php b/src/Controller/AnnonceCreationController.php index 6a3f658911ecd83783aa2af09484c63889fccefd..5b01e153a1397e103a3216a687f099bf6d41f0cb 100644 --- a/src/Controller/AnnonceCreationController.php +++ b/src/Controller/AnnonceCreationController.php @@ -32,6 +32,9 @@ class AnnonceCreationController extends AbstractController $pret->setDateDebut($form->get('date_debut')->getData()); $pret->setFournisseur($user); $pret->setProprietaire($user); + $pret->setTermine(false); + $pret->setFournisseurValide(false); + $pret->setClientValide(false); $entityManager->persist($pret); } else { $service = new Services(); @@ -41,6 +44,9 @@ class AnnonceCreationController extends AbstractController $service->setDateDebut($form->get('date_debut')->getData()); $service->setFournisseur($user); $service->setProprietaire($user); + $service->setTermine(false); + $service->setFournisseurValide(false); + $service->setClientValide(false); $entityManager->persist($service); } $entityManager->flush(); diff --git a/src/Controller/AnnonceDetailController.php b/src/Controller/AnnonceDetailController.php index b3a3ac1e2a07fecf2961a6003a8f3145848ce3d3..6f7dbd89b27ed89302f14b539704980759e370ff 100644 --- a/src/Controller/AnnonceDetailController.php +++ b/src/Controller/AnnonceDetailController.php @@ -103,6 +103,14 @@ class AnnonceDetailController extends AbstractController $entityManager = $this->doctrine->getManager(); $prestation = $data['annonce']; + + //On reverse l'argent dans le compte du client + $data['user']->setNbFlorains($data['user']->getNbFlorains() + $prestation->getCoutPrestation()); + + //On enlève les validations des deux partis + $prestation->setFournisseurValide(false); + $prestation->setClientValide(false); + $notification = new Notification(); $notification->setDescription("Annulation de la réservation de l'annonce " . $prestation->getTitre() . " par " . $this->getUser()->getLogin()); $notification->setType("Annulation réservation annonce"); @@ -120,6 +128,10 @@ class AnnonceDetailController extends AbstractController } else { if ($interet) { $data['annonce']->setIdClient($data['user']); + + //On prélève le compte du client sans verser le propriétaire + $data['user']->setNbFlorains($data['user']->getNbFlorains() - $data['annonce']->getCoutPrestation()); + $notification = new Notification(); $notification->setDescription("Réservation de l'annonce " . $data['annonce']->getTitre() . " par " . $this->getUser()->getLogin()); $notification->setType("Réservation annonce"); @@ -160,4 +172,32 @@ class AnnonceDetailController extends AbstractController $data['entityManager']->flush(); return $this->redirectToRoute('annonce_detail', ['id' => $id]); } + + #[Route('/validerPrestation/{id}', name: 'app_valider_prestation')] + public function validerPrestation($id): Response{ + $data = $this->getCommonData($id); + $user = $data['user']; + $prestation = $data['annonce']; + + if($user->getId() == $prestation->getFournisseur()->getId()) { + $prestation->setFournisseurValide(true); + }else if ($user->getId() == $prestation->getIdClient()->getId()){ + $prestation->setClientValide(true); + } + + $data['entityManager']->persist($prestation); + $data['entityManager']->flush(); + + if(count($prestation->getLitiges()) == 0 && $prestation->isFournisseurValide() && $prestation->isClientValide()){ + //La prestation est validé, donc on verse le montant de florain au fournisseur + $prestation->getFournisseur()->setNbFlorains($prestation->getFournisseur()->getNbFlorains() + $prestation->getCoutPrestation()); + + $prestation->setTermine(true); + } + + $data['entityManager']->persist($prestation); + $data['entityManager']->flush(); + + return $this->redirectToRoute('annonce_detail', ['id' => $id]); + } } diff --git a/src/Controller/LitigeDetailController.php b/src/Controller/LitigeDetailController.php index 866ec62ad8a87841d531fad4cc6df2222037276a..61d55394c31fd352f2d651a6117b46be95b1c62a 100644 --- a/src/Controller/LitigeDetailController.php +++ b/src/Controller/LitigeDetailController.php @@ -86,11 +86,13 @@ class LitigeDetailController extends AbstractController $fournisseurs = $utilisateurSuppr->getPrestationsFournisseur(); foreach($fournisseurs as $f){ $f->setFournisseur(null); + $f->setFournisseurValide(false); } $clients = $utilisateurSuppr->getPrestationsClient(); foreach($clients as $c){ $c->setIdClient(null); + $c->setClientValide(false); } $litiges = $utilisateurSuppr->getLitiges(); @@ -109,9 +111,16 @@ class LitigeDetailController extends AbstractController $entityManager = $this->doctrine->getManager(); $litige = $entityManager->getRepository(Litige::class)->find($id); + $prestation = $litige->getIdPrestation(); + $entityManager->remove($litige); $entityManager->flush(); + $prestation->checkValide(); + + $entityManager->persist($prestation); + $entityManager->flush(); + return $this->redirectToRoute('app_home_page'); } } diff --git a/src/Entity/Prestations.php b/src/Entity/Prestations.php index 318721c74f9cbb8845358a48fd48d6753a42517e..1cc6f152be9f7f5be6b040aa4f74d104bbf97f49 100644 --- a/src/Entity/Prestations.php +++ b/src/Entity/Prestations.php @@ -56,6 +56,15 @@ class Prestations #[ORM\ManyToMany(targetEntity: Utilisateur::class, mappedBy: 'prestations_aimees')] private Collection $utilisateurs_aimant; + #[ORM\Column] + private ?bool $termine = null; + + #[ORM\Column] + private ?bool $fournisseurValide = null; + + #[ORM\Column] + private ?bool $clientValide = null; + public function __construct() { $this->litiges = new ArrayCollection(); @@ -250,4 +259,49 @@ class Prestations return $this; } + + public function isTermine(): ?bool + { + return $this->termine; + } + + public function setTermine(bool $termine): static + { + $this->termine = $termine; + + return $this; + } + + public function isFournisseurValide(): ?bool + { + return $this->fournisseurValide; + } + + public function setFournisseurValide(bool $fournisseurValide): static + { + $this->fournisseurValide = $fournisseurValide; + + return $this; + } + + public function isClientValide(): ?bool + { + return $this->clientValide; + } + + public function setClientValide(bool $clientValide): static + { + $this->clientValide = $clientValide; + + return $this; + } + + public function checkValide(): static + { + if (count($this->litiges) == 0 && $this->fournisseurValide && $this->clientValide){ + $this->termine = true; + } + + return $this; + } } diff --git a/templates/annonce_detail/annonce.html.twig b/templates/annonce_detail/annonce.html.twig index 67f15c20251975d986ee085335ed297d41be9c39..ce2364e0efe285b5a14a4711e88ed20f5aba07d8 100644 --- a/templates/annonce_detail/annonce.html.twig +++ b/templates/annonce_detail/annonce.html.twig @@ -12,43 +12,73 @@ <div class="annonce_img"> <h1>{{ annonce.Titre }}</h1> <img src={{asset('/img/logo.png')}} alt="logo eco-presto" width="50%"/> - {% if app.user.id is defined and (app.user.id == annonce.proprietaire.id or is_granted('ROLE_ADMIN'))%} - <button class="btn-suppression" id="deleteTransactionButton">Supprimer l'annonce</button> + {% if annonce.termine %} + Cette annonce est terminé + {% else %} + {% if app.user.id is defined and is_granted('ROLE_USER')%} + {% if annonce.fournisseur.id is defined %} + {% if app.user.id == annonce.fournisseur.id %} + {% if annonce.fournisseurValide %} + Vous avez déjà validé la prestation + {% else %} + {% if annonce.IdClient.id is defined %} + <a href="{{ path('app_valider_prestation', {'id': annonce.id, 'interet': false}) }}"><button class="btn-connexion" id="btnValider">Valider la réservation</button></a> + {% endif %} + {% endif %} + {% endif %} + {% endif %} + {% if annonce.IdClient.id is defined %} + {% if app.user.id == annonce.IdClient.id %} + {% if annonce.clientValide %} + Vous avez déjà validé la prestation + {% else %} + {% if annonce.fournisseur.id is defined %} + <a href="{{ path('app_valider_prestation', {'id': annonce.id, 'interet': false}) }}"><button class="btn-connexion" id="btnValider">Valider la réservation</button></a> + {% endif %} + {% endif %} + {% endif %} + {% endif %} + {% endif %} + {% if app.user.id is defined and (app.user.id == annonce.proprietaire.id or is_granted('ROLE_ADMIN'))%} + <button class="btn-suppression" id="deleteTransactionButton">Supprimer l'annonce</button> - <script> - document.getElementById('deleteTransactionButton').addEventListener('click', function() { - // Afficher une boîte de dialogue de confirmation - var confirmation = confirm('Êtes-vous sûr de vouloir supprimer cette transaction ?'); + <script> + document.getElementById('deleteTransactionButton').addEventListener('click', function() { + // Afficher une boîte de dialogue de confirmation + var confirmation = confirm('Êtes-vous sûr de vouloir supprimer cette transaction ?'); - // Si l'utilisateur confirme, rediriger vers la page de suppression de la transaction - if (confirmation) { - window.location.href = '{{ path('app_delete_transaction', {'prestationId': annonce.id} ) }}'; - } - }); - </script> + // Si l'utilisateur confirme, rediriger vers la page de suppression de la transaction + if (confirmation) { + window.location.href = '{{ path('app_delete_transaction', {'prestationId': annonce.id} ) }}'; + } + }); + </script> - {% elseif app.user.id is defined %} - {% if not is_granted ("ROLE_ADMIN") and not app.user.isSommeil() %} - {% if annonce.IdClient != NULL %} - {% if user.id == annonce.IdClient.Id %} - <a href="{{ path('app_reserver_prestation', {'id': annonce.id, 'interet': false}) }}"><button class="btn-suppression" id="btnAnnuler">Annuler la réservation</button></a> + {% elseif app.user.id is defined %} + {% if not is_granted ("ROLE_ADMIN") and not app.user.isSommeil() %} + {% if annonce.IdClient != NULL %} + {% if user.id == annonce.IdClient.Id %} + <a href="{{ path('app_reserver_prestation', {'id': annonce.id, 'interet': false}) }}"><button class="btn-suppression" id="btnAnnuler">Annuler la réservation</button></a> + {% else %} + <p>Déjà réservé</p> + <a href=""><button class="btn-connexion2" id="btnListeAttente">Se mettre en liste d'attente</button></a> + {% endif %} {% else %} - <p>Déjà réservé</p> - <a href=""><button class="btn-connexion2" id="btnListeAttente">Se mettre en liste d'attente</button></a> + <a href="{{ path('app_reserver_prestation', {'id': annonce.id, 'interet': true}) }}"><button class="btn-connexion" id="btnRepondre">Répondre à l'annonce</button></a> {% endif %} - {% else %} - <a href="{{ path('app_reserver_prestation', {'id': annonce.id, 'interet': true}) }}"><button class="btn-connexion" id="btnRepondre">Répondre à l'annonce</button></a> - {% endif %} - {% endif %} - {% endif %} + {% endif %} + {% endif %} - {% if not is_granted('ROLE_ADMIN') and (annonce.fournisseur != NULL) and (annonce.IdClient != NULL) %} - <a href="{{ path('app_litige_creation', {'id': annonce.id}) }}"><button class="btn-suppression" id="btnCreerLitige">Créer un litige</button></a> + {% if not is_granted('ROLE_ADMIN') and (annonce.fournisseur != NULL) and (annonce.IdClient != NULL) %} + <a href="{{ path('app_litige_creation', {'id': annonce.id}) }}"><button class="btn-suppression" id="btnCreerLitige">Créer un litige</button></a> + {% endif %} {% endif %} + + </div> <div class="annonce_desc"> - {% if user %} + {% if user and not is_granted ("ROLE_ADMIN") %} {% if user.id != annonce.proprietaire.id %} <a href="{{ path('app_aimer_prestation', {'id': annonce.id}) }}"><button class="btn-like"> {% if user.aimePrestation(annonce) %}