From 85125c7d6bc7547f4c945eb8c22835d069ec11fb Mon Sep 17 00:00:00 2001 From: rudy Date: Sat, 15 Oct 2022 22:24:22 +0200 Subject: [PATCH] second --- assets/app.js | 10 ++ assets/js/getCodeBarre.js | 29 +++++ package.json | 1 + src/Controller/Api/ApiController.php | 174 +++++++++++++++++++++++++++ src/Controller/DmuCatController.php | 6 +- src/Controller/DonCatController.php | 2 +- src/Controller/DonController.php | 1 + src/Controller/FrontController.php | 16 +++ src/Controller/TubeController.php | 2 +- src/Entity/DmuCat.php | 6 +- src/Entity/Don.php | 18 +-- src/Entity/Patient.php | 8 +- src/Form/DmuCatType.php | 4 +- src/Form/DonType.php | 2 +- src/Form/PatientType.php | 9 +- templates/admin/crud/index.html.twig | 4 +- templates/base.html.twig | 1 + templates/front/index.html.twig | 28 +++++ yarn.lock | 5 + 19 files changed, 299 insertions(+), 27 deletions(-) create mode 100644 assets/js/getCodeBarre.js create mode 100644 src/Controller/Api/ApiController.php create mode 100644 src/Controller/FrontController.php create mode 100644 templates/front/index.html.twig diff --git a/assets/app.js b/assets/app.js index dc71202..0579afe 100644 --- a/assets/app.js +++ b/assets/app.js @@ -6,6 +6,16 @@ */ // any CSS you import will output into a single css file (app.css in this case) +import 'jquery'; // start the Stimulus application +import GetEvent from './js/getCodeBarre'; import './bootstrap'; + +$(document).ready(()=>{ + setTimeout(()=>{ + // utils.init(); + GetEvent.init() + + }, 200); +}) \ No newline at end of file diff --git a/assets/js/getCodeBarre.js b/assets/js/getCodeBarre.js new file mode 100644 index 0000000..5337254 --- /dev/null +++ b/assets/js/getCodeBarre.js @@ -0,0 +1,29 @@ +export default class GetEvent{ + static init(){ + this.getEvent() + } + + static getEvent(){ + console.log("test init"); + let saisie = $('#saisie'); + saisie.focus(); + let value; + document.addEventListener('keydown', function (event) { + saisie.focus(); + if(event.code == 'Tab'){ + value = saisie.val(); + saisie.val('') + $.ajax({ + url: '/api/get-code-barre-type', + method: "POST", + dataType: "json", + data: {'codeBarre': value}, + success: function(response){ + console.log(response) + } + + }) + } + }) + } +} \ No newline at end of file diff --git a/package.json b/package.json index 2040f8e..86109cb 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "@popperjs/core": "^2.11.6", "bootstrap": "^5.2.2", "jQuery": "^1.7.4", + "jquery": "^3.6.1", "tom-select": "^2.2.2" } } diff --git a/src/Controller/Api/ApiController.php b/src/Controller/Api/ApiController.php new file mode 100644 index 0000000..f800b3b --- /dev/null +++ b/src/Controller/Api/ApiController.php @@ -0,0 +1,174 @@ +dmuCatRepository = $dmuCatRepository; + $this->requestStack = $requestStack; + } + /** + * @Route("/get-code-barre-type", name="code_barre_type_", methods={"POST"}) + */ + public function GetCodeBarreType(Request $request) + { + $codeBarre = $request->request->get('codeBarre'); + $session = $request->getSession(); + $step = $session->get('step') ?? 0; + + if($step != 0 && preg_match(self::REGEX_DON, $codeBarre)){ + $this->init($session, $don = $this->dmuCatRepository->findOneByGiftNumber($codeBarre)); + return $this->json(['data'=>[ + 'nbre_tube'=>$don->getNbreTube(), + 'donneur'=>$don->getPatient()->getFirstname() . ' ' . $don->getPatient()->getLastname() + ]]); + } + switch($step){ + case 0: + if(preg_match(self::REGEX_DON, $codeBarre)){ + $don = $this->dmuCatRepository->findOneByGiftNumber($codeBarre); + $this->init($session, $don); + return $this->json(['data'=>[ + 'nbre_tube'=>$don->getNbreTube(), + 'donneur'=>$don->getPatient()->getFirstname() . ' ' . $don->getPatient()->getLastname() + ]]); + }else{ + return $this->json(['data'=>'error']); + } + break; + case 1: + if(preg_match(self::REGEX_GROUP_POCHE, $codeBarre)){ + $dmuCatNumber = $this->dmuCatRepository->findOneByCodeBarre($codeBarre)->getPocheNumber(); + $session->set('step', 2); + $session->set('nbre_poche' , $dmuCatNumber); + return $this->json(['data'=>[ + 'nbre_poche'=>$dmuCatNumber, + ]]); + }else{ + return $this->json(['data'=>'error']); + } + break; + case 2: + if(preg_match(self::REGEX_ETIQUETTE, $codeBarre)){ + $nbrePoche = $session->get('nbre_poche'); + + $listPoche = $session->get('list_poche'); + if(!in_array($codeBarre, $listPoche)){ + $listPoche[] = $codeBarre; + $session->set('liste_poche', $listPoche); + }else{ + return $this->json(['data'=>'doublon']); + } + if($nbrePoche == 1){ + $session->set('step', 3); + $session->set('nbre_poche', 0); + return $this->json(['data'=>[ + 'nbre_poche'=>$nbrePoche - 1, + 'poche'=>'success' + ] + ] + ); + }else{ + $session->set('nbre_poche', $nbrePoche - 1); + return $this->json(['data'=>[ + 'nbre_poche'=>$nbrePoche - 1 + ] + ]); + } + + }else{ + return $this->json(['data'=>'error']); + } + break; + case 3: + if(preg_match(self::REGEX_GROUP_POCHE, $codeBarre)){ + $session->set('step', 4); + return $this->json(['data'=>[ + 'tube'=>true, + ]]); + }else{ + return $this->json(['data'=>'error']); + } + break; + case 4: + if(preg_match(self::REGEX_ETIQUETTE, $codeBarre)){ + $nbreTube = $session->get('nbre_tube'); + + $listTube = $session->get('list_tube'); + if(!in_array($codeBarre, $listTube)){ + $listTube[] = $codeBarre; + $session->set('list_tube', $listTube); + }else{ + return $this->json(['data'=>'doublon']); + } + if($nbreTube == 1){ + $session->set('step', 0); + $session->set('nbre_tube', 0); + $session->clear(); + return $this->json(['data'=>[ + 'nbre_tube'=>$nbreTube - 1, + 'tube'=>'success' + ] + ] + ); + }else{ + $session->set('nbre_tube', $nbreTube - 1); + return $this->json(['data'=>[ + 'nbre_tube'=>$nbreTube - 1 + ] + ]); + } + }else{ + return $this->json(['data'=>'error']); + } + break; + default: + return $this->json(['data'=>'error']); + } + } + + public function init($session, Don $don) + { + $session->set('don' , $don->getId()); + $session->set('nbre_tube', $don->getNbreTube()); + $session->set('liste_poche', []); + $session->set('liste_tube', []); + $session->set('donneur', $don->getDonneur()->getFirstname() . ' ' . $don->getDonneur()->getLastname()); + $session->set('step', 1); + } + + // public function raz() + // { + // $session = $this->requestStack->getSession(); + // $session->remove('don' ); + // $session->remove('nbre_tube'); + // $session->remove('liste_poche'); + // $session->remove('liste_tube'); + // $session->remove('donneur'); + // $session->remove('step'); + + // } + +} \ No newline at end of file diff --git a/src/Controller/DmuCatController.php b/src/Controller/DmuCatController.php index c8a5e3f..d488fc9 100644 --- a/src/Controller/DmuCatController.php +++ b/src/Controller/DmuCatController.php @@ -54,7 +54,8 @@ class DmuCatController extends AbstractController ], 'fields' => [ 'Id' => 'Id', -'CodeBarre' => 'CodeBarre', + 'CodeBarre' => 'CodeBarre', + 'PocheNumber'=>'PocheNumber' ], 'title' => 'Tous les élements', @@ -100,10 +101,9 @@ class DmuCatController extends AbstractController * @Route("/edit/{id}", name="edit") * @param Request $request * @param DmuCat $dmuCat - * @param Tools $tools * @return Response */ - public function edit(Request $request, DmuCat $dmuCat, Tools $tools): Response + public function edit(Request $request, DmuCat $dmuCat, DmuCatHandler $dmuCatHandler): Response { $form = $this->createForm(DmuCatType::class, $dmuCat); if ($dmuCatHandler->edit($form, $request)) { diff --git a/src/Controller/DonCatController.php b/src/Controller/DonCatController.php index dcd05cc..a76c604 100644 --- a/src/Controller/DonCatController.php +++ b/src/Controller/DonCatController.php @@ -103,7 +103,7 @@ class DonCatController extends AbstractController * @param Tools $tools * @return Response */ - public function edit(Request $request, DonCat $donCat, Tools $tools): Response + public function edit(Request $request, DonCat $donCat,DonCatHandler $donCatHandler): Response { $form = $this->createForm(DonCatType::class, $donCat); if ($donCatHandler->edit($form, $request)) { diff --git a/src/Controller/DonController.php b/src/Controller/DonController.php index de3cffb..4a8a637 100644 --- a/src/Controller/DonController.php +++ b/src/Controller/DonController.php @@ -55,6 +55,7 @@ class DonController extends AbstractController 'fields' => [ 'Id' => 'Id', 'GiftNumber' => 'GiftNumber', + 'Nombre tube'=> 'NbreTube', 'Categorie' => 'DonCat', 'Donneur' => 'Donneur', diff --git a/src/Controller/FrontController.php b/src/Controller/FrontController.php new file mode 100644 index 0000000..8e02e2e --- /dev/null +++ b/src/Controller/FrontController.php @@ -0,0 +1,16 @@ +render('front/index.html.twig'); + } +} \ No newline at end of file diff --git a/src/Controller/TubeController.php b/src/Controller/TubeController.php index fed5f82..5ab9790 100644 --- a/src/Controller/TubeController.php +++ b/src/Controller/TubeController.php @@ -106,7 +106,7 @@ class TubeController extends AbstractController * @param Tools $tools * @return Response */ - public function edit(Request $request, Tube $tube, Tools $tools): Response + public function edit(Request $request, Tube $tube, TubeHandler $tubeHandler): Response { $form = $this->createForm(TubeType::class, $tube); if ($tubeHandler->edit($form, $request)) { diff --git a/src/Entity/DmuCat.php b/src/Entity/DmuCat.php index e2f8d19..26a8ec4 100644 --- a/src/Entity/DmuCat.php +++ b/src/Entity/DmuCat.php @@ -2,10 +2,10 @@ namespace App\Entity; -use App\Repository\TypeDmuRepository; +use App\Repository\DmuCatRepository; use Doctrine\ORM\Mapping as ORM; -#[ORM\Entity(repositoryClass: TypeDmuRepository::class)] +#[ORM\Entity(repositoryClass: DmuCatRepository::class)] class DmuCat { #[ORM\Id] @@ -13,7 +13,7 @@ class DmuCat #[ORM\Column] private ?int $id = null; - #[ORM\Column] + #[ORM\Column(nullable: true)] private ?int $pocheNumber = null; #[ORM\Column(length: 1000)] diff --git a/src/Entity/Don.php b/src/Entity/Don.php index 6b3d821..f1a38fa 100644 --- a/src/Entity/Don.php +++ b/src/Entity/Don.php @@ -14,7 +14,7 @@ class Don private ?int $id = null; #[ORM\Column] - private ?int $giftNumber = null; + private ?string $giftNumber = null; #[ORM\ManyToOne(inversedBy: 'dons')] #[ORM\JoinColumn(nullable: false)] @@ -24,20 +24,20 @@ class Don #[ORM\JoinColumn(nullable: false)] private ?Patient $donneur = null; - #[ORM\Column(length: 1000, nullable: true)] - private ?string $codeBarre = null; + #[ORM\Column] + private ?int $nbreTube = null; public function getId(): ?int { return $this->id; } - public function getGiftNumber(): ?int + public function getGiftNumber(): ?string { return $this->giftNumber; } - public function setGiftNumber(int $giftNumber): self + public function setGiftNumber(string $giftNumber): self { $this->giftNumber = $giftNumber; @@ -68,14 +68,14 @@ class Don return $this; } - public function getCodeBarre(): ?string + public function getNbreTube(): ?int { - return $this->codeBarre; + return $this->nbreTube; } - public function setCodeBarre(?string $codeBarre): self + public function setNbreTube(int $nbreTube): self { - $this->codeBarre = $codeBarre; + $this->nbreTube = $nbreTube; return $this; } diff --git a/src/Entity/Patient.php b/src/Entity/Patient.php index 55049ea..fbdffc5 100644 --- a/src/Entity/Patient.php +++ b/src/Entity/Patient.php @@ -26,7 +26,7 @@ class Patient private ?\DateTimeInterface $birthdate = null; #[ORM\Column] - private ?int $donneurNumber = null; + private ?string $donneurNumber = null; #[ORM\OneToMany(mappedBy: 'donneur', targetEntity: Don::class, orphanRemoval: true)] private Collection $dons; @@ -77,12 +77,12 @@ class Patient return $this; } - public function getDonneurNumber(): ?int + public function getDonneurNumber(): ?string { return $this->donneurNumber; } - public function setDonneurNumber(int $donneurNumber): self + public function setDonneurNumber(string $donneurNumber): self { $this->donneurNumber = $donneurNumber; @@ -118,7 +118,7 @@ class Patient return $this; } - + public function __toString() { return $this->firstname.' '.$this->lastname; diff --git a/src/Form/DmuCatType.php b/src/Form/DmuCatType.php index ed4c634..e024539 100644 --- a/src/Form/DmuCatType.php +++ b/src/Form/DmuCatType.php @@ -12,7 +12,9 @@ class DmuCatType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options): void { $builder - ->add('pocheNumber') + ->add('pocheNumber', null, [ + 'required'=>false, + ]) ->add('codeBarre') ; } diff --git a/src/Form/DonType.php b/src/Form/DonType.php index 121ce67..80b078c 100644 --- a/src/Form/DonType.php +++ b/src/Form/DonType.php @@ -16,11 +16,11 @@ class DonType extends AbstractType { $builder ->add('giftNumber') - ->add('codeBarre') ->add('donCat', EntityType::class, [ 'class'=> DonCat::class, 'choice_label'=> 'name' ]) + ->add('nbreTube') ->add('donneur', EntityType::class, [ 'class'=> Patient::class, ]) diff --git a/src/Form/PatientType.php b/src/Form/PatientType.php index 5fb2f7b..8133748 100644 --- a/src/Form/PatientType.php +++ b/src/Form/PatientType.php @@ -6,6 +6,8 @@ use App\Entity\Patient; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Form\Extension\Core\Type\DateType; +use Symfony\Component\Form\Extension\Core\Type\TextType; class PatientType extends AbstractType { @@ -14,8 +16,11 @@ class PatientType extends AbstractType $builder ->add('lastname') ->add('firstname') - ->add('birthdate') - ->add('donneurNumber') + ->add('birthdate', DateType::class, [ + 'years' => range(intval(date('Y')) - 10, 1920), + + ]) + ->add('donneurNumber', TextType::class) ; } diff --git a/templates/admin/crud/index.html.twig b/templates/admin/crud/index.html.twig index 0eebf25..654c3fd 100644 --- a/templates/admin/crud/index.html.twig +++ b/templates/admin/crud/index.html.twig @@ -114,10 +114,10 @@ - + -