Skip to content
Snippets Groups Projects
Commit bf1b9957 authored by DEMANGEL Mael's avatar DEMANGEL Mael
Browse files

Ajout de la logique de la vie d'une annonce

parent a920fec4
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,9 @@ class AnnonceCreationController extends AbstractController ...@@ -32,6 +32,9 @@ class AnnonceCreationController extends AbstractController
$pret->setDateDebut($form->get('date_debut')->getData()); $pret->setDateDebut($form->get('date_debut')->getData());
$pret->setFournisseur($user); $pret->setFournisseur($user);
$pret->setProprietaire($user); $pret->setProprietaire($user);
$pret->setTermine(false);
$pret->setFournisseurValide(false);
$pret->setClientValide(false);
$entityManager->persist($pret); $entityManager->persist($pret);
} else { } else {
$service = new Services(); $service = new Services();
...@@ -41,6 +44,9 @@ class AnnonceCreationController extends AbstractController ...@@ -41,6 +44,9 @@ class AnnonceCreationController extends AbstractController
$service->setDateDebut($form->get('date_debut')->getData()); $service->setDateDebut($form->get('date_debut')->getData());
$service->setFournisseur($user); $service->setFournisseur($user);
$service->setProprietaire($user); $service->setProprietaire($user);
$service->setTermine(false);
$service->setFournisseurValide(false);
$service->setClientValide(false);
$entityManager->persist($service); $entityManager->persist($service);
} }
$entityManager->flush(); $entityManager->flush();
... ...
......
...@@ -103,6 +103,14 @@ class AnnonceDetailController extends AbstractController ...@@ -103,6 +103,14 @@ class AnnonceDetailController extends AbstractController
$entityManager = $this->doctrine->getManager(); $entityManager = $this->doctrine->getManager();
$prestation = $data['annonce']; $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 = new Notification();
$notification->setDescription("Annulation de la réservation de l'annonce " . $prestation->getTitre() . " par " . $this->getUser()->getLogin()); $notification->setDescription("Annulation de la réservation de l'annonce " . $prestation->getTitre() . " par " . $this->getUser()->getLogin());
$notification->setType("Annulation réservation annonce"); $notification->setType("Annulation réservation annonce");
...@@ -120,6 +128,10 @@ class AnnonceDetailController extends AbstractController ...@@ -120,6 +128,10 @@ class AnnonceDetailController extends AbstractController
} else { } else {
if ($interet) { if ($interet) {
$data['annonce']->setIdClient($data['user']); $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 = new Notification();
$notification->setDescription("Réservation de l'annonce " . $data['annonce']->getTitre() . " par " . $this->getUser()->getLogin()); $notification->setDescription("Réservation de l'annonce " . $data['annonce']->getTitre() . " par " . $this->getUser()->getLogin());
$notification->setType("Réservation annonce"); $notification->setType("Réservation annonce");
...@@ -160,4 +172,32 @@ class AnnonceDetailController extends AbstractController ...@@ -160,4 +172,32 @@ class AnnonceDetailController extends AbstractController
$data['entityManager']->flush(); $data['entityManager']->flush();
return $this->redirectToRoute('annonce_detail', ['id' => $id]); 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]);
}
} }
...@@ -86,11 +86,13 @@ class LitigeDetailController extends AbstractController ...@@ -86,11 +86,13 @@ class LitigeDetailController extends AbstractController
$fournisseurs = $utilisateurSuppr->getPrestationsFournisseur(); $fournisseurs = $utilisateurSuppr->getPrestationsFournisseur();
foreach($fournisseurs as $f){ foreach($fournisseurs as $f){
$f->setFournisseur(null); $f->setFournisseur(null);
$f->setFournisseurValide(false);
} }
$clients = $utilisateurSuppr->getPrestationsClient(); $clients = $utilisateurSuppr->getPrestationsClient();
foreach($clients as $c){ foreach($clients as $c){
$c->setIdClient(null); $c->setIdClient(null);
$c->setClientValide(false);
} }
$litiges = $utilisateurSuppr->getLitiges(); $litiges = $utilisateurSuppr->getLitiges();
...@@ -109,9 +111,16 @@ class LitigeDetailController extends AbstractController ...@@ -109,9 +111,16 @@ class LitigeDetailController extends AbstractController
$entityManager = $this->doctrine->getManager(); $entityManager = $this->doctrine->getManager();
$litige = $entityManager->getRepository(Litige::class)->find($id); $litige = $entityManager->getRepository(Litige::class)->find($id);
$prestation = $litige->getIdPrestation();
$entityManager->remove($litige); $entityManager->remove($litige);
$entityManager->flush(); $entityManager->flush();
$prestation->checkValide();
$entityManager->persist($prestation);
$entityManager->flush();
return $this->redirectToRoute('app_home_page'); return $this->redirectToRoute('app_home_page');
} }
} }
...@@ -56,6 +56,15 @@ class Prestations ...@@ -56,6 +56,15 @@ class Prestations
#[ORM\ManyToMany(targetEntity: Utilisateur::class, mappedBy: 'prestations_aimees')] #[ORM\ManyToMany(targetEntity: Utilisateur::class, mappedBy: 'prestations_aimees')]
private Collection $utilisateurs_aimant; 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() public function __construct()
{ {
$this->litiges = new ArrayCollection(); $this->litiges = new ArrayCollection();
...@@ -250,4 +259,49 @@ class Prestations ...@@ -250,4 +259,49 @@ class Prestations
return $this; 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;
}
} }
...@@ -12,6 +12,33 @@ ...@@ -12,6 +12,33 @@
<div class="annonce_img"> <div class="annonce_img">
<h1>{{ annonce.Titre }}</h1> <h1>{{ annonce.Titre }}</h1>
<img src={{asset('/img/logo.png')}} alt="logo eco-presto" width="50%"/> <img src={{asset('/img/logo.png')}} alt="logo eco-presto" width="50%"/>
{% 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'))%} {% 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> <button class="btn-suppression" id="deleteTransactionButton">Supprimer l'annonce</button>
...@@ -45,10 +72,13 @@ ...@@ -45,10 +72,13 @@
{% if not is_granted('ROLE_ADMIN') and (annonce.fournisseur != NULL) and (annonce.IdClient != NULL) %} {% 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> <a href="{{ path('app_litige_creation', {'id': annonce.id}) }}"><button class="btn-suppression" id="btnCreerLitige">Créer un litige</button></a>
{% endif %} {% endif %}
{% endif %}
</div> </div>
<div class="annonce_desc"> <div class="annonce_desc">
{% if user %} {% if user and not is_granted ("ROLE_ADMIN") %}
{% if user.id != annonce.proprietaire.id %} {% if user.id != annonce.proprietaire.id %}
<a href="{{ path('app_aimer_prestation', {'id': annonce.id}) }}"><button class="btn-like"> <a href="{{ path('app_aimer_prestation', {'id': annonce.id}) }}"><button class="btn-like">
{% if user.aimePrestation(annonce) %} {% if user.aimePrestation(annonce) %}
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment