From b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878 Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 20 Oct 2026 21:49:17 +0200 Subject: =?UTF-8?q?mise=20en=20place=20de=20l'h=C3=A9ritage=202,=20nombreu?= =?UTF-8?q?ses=20simplifications=20et=20factorisations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sections/3_modify_data.php | 128 +++++++++++++---------------------------- 1 file changed, 39 insertions(+), 89 deletions(-) (limited to 'src/sections/3_modify_data.php') diff --git a/src/sections/3_modify_data.php b/src/sections/3_modify_data.php index d70c7d6..5651ed3 100644 --- a/src/sections/3_modify_data.php +++ b/src/sections/3_modify_data.php @@ -7,16 +7,14 @@ require('3-1_windows.php'); function modifyData(?Client $Client = null): array { - // -- partie 1: rechercher un client -- - - // fenêtres statiques - // recherche d'un client + // fenêtres $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client['text']); $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client['text'], []); - // modification de données $TypeDeClient = new ZenityList(ZenitySetup::$type_client['text'], ZenitySetup::$type_client['entrees']); $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section3']); + + // -- partie 1: rechercher un client -- if(!$Client) { $Client = Client::find($RechercheClient, $ResultatsRechercheClient); @@ -93,120 +91,72 @@ function modifyData(?Client $Client = null): array // -- partie 3: rechercher une prestation -- - $Presta = Prestation::getServices($Client); // = 0 ou type "Prestation" + $Presta = Prestation::getServices($Client); if(!is_object($Presta) || !get_class($Presta) == 'Prestation') { echo "debug: annulation sélection d'une prestation\n"; return [3, $Client]; // menu précédent } $type_presta = $Presta->getTypePresta(); - $classe = ''; - switch($type_presta){ - case 'facture': - $classe = 'Facture'; - break; - case 'devis': - $classe = 'Devis'; - break; - case 'cesu': - $classe = 'CESU'; - break; - case 'location': - $classe = 'Location'; - break; - case 'non_vendue': - $PrestaDetails = null; - break; - default: - echo "erreur: type de prestation buggué\n"; - } - if($type_presta != 'non_vendue') - { - $repository = $classe::$entityManager->getRepository($classe); - $PrestaDetails = $repository->findOneBy(['presta' => $Presta->getId()]); - } + $classe = match($type_presta){ + 'facture' => Facture::class, + 'devis' => Devis::class, + 'cesu' => CESU::class, + 'location' => Location::class, + 'non_vendue' => NonVendue::class, + }; + + $repository = Prestation::$entityManager->getRepository($classe); + $Presta = $repository->findOneBy(['id' => $Presta->getId()]); // -- partie 4: modifier une prestation -- // fenêtre - $ModificationPrestaMenu = makeModifyServiceWindow($Presta, $PrestaDetails); - + $ModificationPrestaMenu = makeModifyServiceWindow($Presta); $choix_niv3 = exec($ModificationPrestaMenu->get()); - - if($choix_niv3 === 'Date:') - { + if($choix_niv3 === 'Date:'){ $date_array = explode('/', exec($Calendrier->get())); // 17/10/2026 if(count($date_array) === 1){ echo "debug: annulation à la saisie d'une date\n"; return [3, $Client]; } - - // entités et BDD - $Presta->set($choix_niv3, $date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]); // 2026-10-09 - $old_code = $Presta->getCodePresta(); - $Presta->setCodePresta(0); - $Presta::$entityManager->flush(); - - // documents - if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location') - { - $DocumentPresta = Latex::makeInstance($Presta->getTypePresta()); // $type = facture, devis, location - $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); - $DocumentPresta->makeLatex(); // en mémoire - - File::renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); - $DocumentPresta->makeTexAndPdf(); // une nouvelle facture est créée, supprimer l'ancienne ou la renommer avec la nouvelle date - } - - return [3, $Client]; // menu précédent + $input = $date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]; // 2026-10-17 } //~ elseif($choix_niv3 === 'Type de Presta:') // compliqué! choix impossible pour le moment //~ { //~ echo "choix: changer le type de prestation (devis, facture, etc)\n"; //~ return [3, $Client]; // menu "client" //~ } - elseif(is_string($choix_niv3) && $choix_niv3 != '') // modifier une valeur - { + elseif(is_string($choix_niv3) && $choix_niv3 != ''){ // modifier une valeur echo "choix: modifier " . $choix_niv3 . "\n"; $ModificationPrestaForm = new ZenityEntry($choix_niv3); $input = shell_exec($ModificationPrestaForm->get()); // shell_exec() retourne null si la commande échoue, exec() retourne la dernière ligne de texte en sortie ou null si aucune commande ne réussit - if(is_string($input)) // chaîne vide autorisée - { - // entités et BDD - $Presta->set($choix_niv3, $input); - $old_code = $Presta->getCodePresta(); - $Presta->setCodePresta(0); - if($type_presta != 'non_vendue') - { - $PrestaDetails->set($choix_niv3, $input); - $PrestaDetails::$entityManager->flush(); - } - else - { - $Presta::$entityManager->flush(); - } - - // documents - if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location') - { - $DocumentPresta = Latex::makeInstance($type_presta); - $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); // polymorphisme - $DocumentPresta->makeLatex(); - - File::renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); - $DocumentPresta->makeTexAndPdf(); - } - } - else - { + if(!is_string($input)){ // chaîne vide autorisée echo "choix: annulation\n"; + return [3, $Client]; // menu précédent } - return [3, $Client]; // menu précédent } - else // annuler - { + else{ echo "annulation: retour au menu précédent\n"; return [3, $Client]; // menu précédent } + + // entités et BDD + $Presta->set($choix_niv3, $input); + $old_code = $Presta->getCodePresta(); + $Presta->setCodePresta(0); + $Presta::$entityManager->flush(); + + // documents + if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location'){ + $DocumentPresta = Latex::makeInstance($type_presta); + $DocumentPresta->setData($Client)->setData($Presta); + $DocumentPresta->makeLatex(); + + File::renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); + $DocumentPresta->makeTexAndPdf(); + } + + return [3, $Client]; // menu précédent } -- cgit v1.2.3