diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 358c3ed..3da719c 100755 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -345,6 +345,7 @@ public function productVersionCreation(Request $request): Response } } + #[Route('admin/archive/{entityType}/{id}', name: 'archive_entity')] public function archiveEntity(Request $request, string $entityType, int $id): Response { @@ -355,9 +356,15 @@ public function archiveEntity(Request $request, string $entityType, int $id): Re return $this->redirect($originUrl); } else { $this->addFlash('success', 'L\'élément a bien été archivé'); - return $this->redirect($originUrl); + if ($entityType == "efnc") { + return $this->redirectToRoute('app_base', []); + } else { + return $this->redirect($originUrl); + } } } + + #[Route('admin/delete/{entityType}/{id}', name: 'delete_entity')] public function deleteEntity(Request $request, string $entityType, int $id): Response { @@ -371,6 +378,8 @@ public function deleteEntity(Request $request, string $entityType, int $id): Res return $this->redirect($originUrl); } } + + #[Route('admin/unarchive/{entityType}/{id}', name: 'unarchive_entity')] public function unarchiveEntity(Request $request, string $entityType, int $id): Response { @@ -384,4 +393,4 @@ public function unarchiveEntity(Request $request, string $entityType, int $id): return $this->redirect($originUrl); } } -} \ No newline at end of file +} diff --git a/src/Controller/EFNCController.php b/src/Controller/EFNCController.php index f64fe1f..df53829 100755 --- a/src/Controller/EFNCController.php +++ b/src/Controller/EFNCController.php @@ -91,20 +91,32 @@ public function formModificationDisplay(int $efncID, Request $request): Response 'EFNC' => $efnc, ]); } else if ($request->getMethod() == 'POST') { + if ($this->getUser() !== null) { + if ($this->authChecker->isGranted('ROLE_ADMIN')) { + $user = $this->getUser(); + $form1->handleRequest($request); + if ($form1->isValid() && $form1->isSubmitted()) { + $result = $this->formModificationService->modifyNCForm( + $efnc, + $request, + $form1, + $user + ); + } + if ($result === true) { - $form1->handleRequest($request); - if ($form1->isValid() && $form1->isSubmitted()) { - $result = $this->formModificationService->modifyNCForm( - $efnc, - $request, - $form1 - ); - } - if ($result === true) { - $this->addFlash('success', 'Fiche correctement modifiée!'); - return $this->redirectToRoute('app_base', []); + $this->addFlash('success', 'Fiche correctement modifiée!'); + return $this->redirectToRoute('app_base', []); + } else { + $this->addFlash('error', 'Erreur lors de la modification de la fiche!'); + return $this->redirectToRoute('app_base', []); + } + } else { + $this->addFlash('error', 'Vous n\'avez pas les droits pour modifier cette fiche!'); + return $this->redirectToRoute('app_base', []); + } } else { - $this->addFlash('error', 'Erreur lors de la modification de la fiche!'); + $this->addFlash('error', 'Vous devez êtres connecté pour modifier cette fiche!'); return $this->redirectToRoute('app_base', []); } } @@ -131,4 +143,29 @@ public function pictureView(int $pictureID): Response ); return $response; } + + #[Route('admin/close/{entityType}/{id}', name: 'close_entity')] + public function closeEntity(Request $request, string $entityType, int $id): Response + { + $originUrl = $request->headers->get('referer'); + + if ($this->getUser() !== null) { + if ($this->authChecker->isGranted('ROLE_MASTER_ADMIN')) { + $result = $this->entityDeletionService->closeEntity($entityType, $id); // Implement this method in your service + if ($result == false) { + $this->addFlash('danger', 'L\'élément n\'a pas pu être clôturé'); + return $this->redirectToRoute('app_base', []); + } else { + $this->addFlash('success', 'L\'élément a bien été clôturé'); + return $this->redirectToRoute('app_base', []); + } + } else { + $this->addFlash('error', 'Vous n\'avez pas les droits pour clôturer un élément'); + return $this->redirectToRoute('app_base', []); + } + } else { + $this->addFlash('error', 'Vous devez être connecté pour clôturer un élément'); + return $this->redirectToRoute('app_base', []); + } + } } diff --git a/src/Entity/EFNC.php b/src/Entity/EFNC.php index 8d7a1f1..0c4dc89 100755 --- a/src/Entity/EFNC.php +++ b/src/Entity/EFNC.php @@ -50,7 +50,6 @@ class EFNC #[ORM\OneToMany(mappedBy: 'EFNC', targetEntity: ImmediateConservatoryMeasures::class, cascade: ['persist', 'remove'])] private Collection $immediateConservatoryMeasures; - #[ORM\OneToMany(mappedBy: 'EFNC', targetEntity: BoughtComponent::class)] private Collection $boughtComponents; @@ -96,6 +95,9 @@ class EFNC #[ORM\Column(nullable: true)] private ?bool $archived = null; + #[ORM\ManyToOne(inversedBy: 'eFNCs')] + private ?User $lastModifier = null; + public function __construct() { @@ -361,7 +363,7 @@ public function setStatus(?bool $Status): static $this->Status = $Status; // If the status is set to true, we set the ClosedDate to the current date if ($Status === true) { - $this->ClosedDate = new \DateTimeInterface(); + $this->ClosedDate = new \DateTime(); } return $this; } @@ -524,4 +526,16 @@ public function setArchived(?bool $archived): static return $this; } -} \ No newline at end of file + + public function getLastModifier(): ?User + { + return $this->lastModifier; + } + + public function setLastModifier(?User $lastModifier): static + { + $this->lastModifier = $lastModifier; + + return $this; + } +} diff --git a/src/Entity/User.php b/src/Entity/User.php index cdaa9c0..ab08b05 100755 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -3,6 +3,8 @@ namespace App\Entity; use App\Repository\UserRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; @@ -37,6 +39,14 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(length: 255, nullable: true)] private ?string $emailAddress = null; + #[ORM\OneToMany(mappedBy: 'lastModifier', targetEntity: EFNC::class)] + private Collection $eFNCs; + + public function __construct() + { + $this->eFNCs = new ArrayCollection(); + } + public function getId(): ?int { return $this->id; @@ -119,4 +129,34 @@ public function setEmailAddress(?string $emailAddress): static return $this; } + + /** + * @return Collection + */ + public function getEFNCs(): Collection + { + return $this->eFNCs; + } + + public function addEFNC(EFNC $eFNC): static + { + if (!$this->eFNCs->contains($eFNC)) { + $this->eFNCs->add($eFNC); + $eFNC->setLastModifier($this); + } + + return $this; + } + + public function removeEFNC(EFNC $eFNC): static + { + if ($this->eFNCs->removeElement($eFNC)) { + // set the owning side to null (unless already changed) + if ($eFNC->getLastModifier() === $this) { + $eFNC->setLastModifier(null); + } + } + + return $this; + } } diff --git a/src/Service/EntityDeletionService.php b/src/Service/EntityDeletionService.php index 1a1ce5f..0a863ef 100755 --- a/src/Service/EntityDeletionService.php +++ b/src/Service/EntityDeletionService.php @@ -525,6 +525,36 @@ public function unarchiveEntity(string $entityType, int $id): bool } + $this->em->flush(); + + return true; + } + + + public function closeEntity(string $entityType, int $id): bool + { + $repository = null; + switch ($entityType) { + case "efnc": + $repository = $this->EFNCRepository; + break; + } + + // If the repository is not found or the entity is not found in the database, return false + if (!$repository) { + return false; + } + // Get the entity from the database + $entity = $repository->find($id); + if (!$entity) { + return false; + } + + if ($entityType === 'efnc') { + $entity->setArchived(true); + $entity->setStatus(true); + } + $this->em->flush(); return true; diff --git a/src/Service/FormModificationService.php b/src/Service/FormModificationService.php index bfacdf3..0d69114 100755 --- a/src/Service/FormModificationService.php +++ b/src/Service/FormModificationService.php @@ -15,6 +15,7 @@ use Doctrine\ORM\EntityManagerInterface; use App\Entity\EFNC; +use App\Entity\User; use App\Service\PictureService; @@ -49,7 +50,8 @@ public function __construct( public function modifyNCForm( EFNC $efnc, Request $request, - FormInterface $form1 + FormInterface $form1, + User $user ) { $now = new \DateTime(); @@ -91,10 +93,10 @@ public function modifyNCForm( $this->PictureService->pictureUpload($picture, $efnc, $efncFolderName, 'NC'); } } - + $efnc->setLastModifier($user); $this->em->persist($efnc); $this->em->flush(); return true; } -} \ No newline at end of file +} diff --git a/templates/services/efnc/modification/form_modification.html.twig b/templates/services/efnc/modification/form_modification.html.twig index 46cb3e9..208e271 100755 --- a/templates/services/efnc/modification/form_modification.html.twig +++ b/templates/services/efnc/modification/form_modification.html.twig @@ -4,20 +4,29 @@ {% endblock %} {% block body %} -

- Modification de la Fiche de Non-Conformité : +

+ + Modification de la Fiche de Non-Conformité : +

-
-
-
+
+
+
{{ form_start(form1, { attr: { id: 'formModificationForm', method: 'POST', enctype: 'multipart/form-data' }, action: path('app_form_modification_display', {'efncID': EFNC.id}) }) }} -
+

- Enregistrement de la Non-Conformité: + + Enregistrement de la Non-Conformité: +

{% set fields = [ 'Creator', 'DetectionDate', 'DetectionTime', 'Team','UAP', @@ -28,74 +37,164 @@ {{ form_row(form1[field]) }} {% endfor %}

- Description du Problème : + + Description du Problème : +

{% set problemDetails = ['AnomalyType', 'Quantity', 'QuantityToBlock', 'DetailedDescription'] %} {% for detail in problemDetails %} {{ form_row(form1[detail]) }} {% endfor %} -
- +
+ {% if EFNC.pictures is defined and EFNC.pictures is not empty %} {% for picture in EFNC.pictures %} {% if picture.category is same as('traceability') %} - Image de traçabilité obligatoire + Image de traçabilité obligatoire {% endif %} {% if picture.category is same as(null) %} - Image de traçabilité obligatoire + Image de traçabilité obligatoire {% endif %} {% endfor %} {% endif %} - -
+ +
-
- +
+ {% if EFNC.pictures is defined and EFNC.pictures is not empty %} {% for picture in EFNC.pictures %} {% if picture.category is same as('NC') %} - Image de traçabilité obligatoire + Image de traçabilité obligatoire {% endif %} {% endfor %} {% endif %} - -
+ +

- Mesures Conservatoire Immediates: + + Mesures Conservatoire Immediates: +

-
+
{% for imcomeFormEntry in form1.immediateConservatoryMeasures %} -
- {{ form_widget(imcomeFormEntry, {'attr': {'class': 'row'}}) }} +
+ {{ form_widget(imcomeFormEntry, {'attr': {'class': 'row'}} + ) }}
{% endfor %}
- +

- Priorisation de la non-conformité : + + Priorisation de la non-conformité : +

{% for riskWeightingFormEntry in form1.riskWeighting %} {{ form_row(riskWeightingFormEntry) }} {% endfor %} -
-
- Risque Élevé: - Réaliser une analyse 8D.
-
- Risque Moyen: - Réaliser une analyse de causes potentielles.
-
- Risque Faible: - Pas d'analyse, affichage au poste : Alerte d'un Problème.
-
-
- +
+
+ + Risque Élevé: + + Réaliser une analyse 8D. +
+
+ + Risque Moyen: + + Réaliser une analyse de causes potentielles. +
+
+ + Risque Faible: + + Pas d'analyse, affichage au poste : Alerte d'un Problème. +
+ {% if is_granted('ROLE_ADMIN') %} -
- Archiver +
+ Derniere modification effectué par + {{ EFNC.LastModifier.username|capitalize|split('.')|first }} + {{ EFNC.LastModifier.username|upper|split('.')|last }} +
+
+
+
+ + Archiver + + {% if is_granted('ROLE_MASTER_ADMIN') %} + + + Cloturer + +
+ {% endif %} {% endif %}
{{ form_end(form1) }}