From bf6655a534a6775d30cafa67bd801276bda1d98d Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 13 Aug 2024 23:45:21 +0200 Subject: =?UTF-8?q?VERSION=200.2=20doctrine=20ORM=20et=20entit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sections/3_modify_data.php | 113 +++++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 49 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 c2f683a..00fe220 100644 --- a/src/sections/3_modify_data.php +++ b/src/sections/3_modify_data.php @@ -5,18 +5,26 @@ require('3-1_windows.php'); +use Doctrine\ORM\EntityManager; + function modifyData($Client): array { - // fenêtres fixes + // -- partie 1: rechercher un client -- + + // fenêtres statiques + // recherche d'un client + $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 == null || get_class($Client) !== 'Clients') // étape sautable + + if($Client == null || get_class($Client) !== 'Client') // étape sautable { - $Client = makeObjectClient(); // = 0 ou type "Clients" - if(!is_object($Client) || !get_class($Client) == 'Clients') + $Client = Client::getObject($RechercheClient, $ResultatsRechercheClient); // = 0 ou type "Client" + //$ResultatsRechercheClient->cleanCommand(); // inutile parce qu'on ne boucle pas dans cette fonction + //if(!is_object($Client) || !get_class($Client) == 'Client') + if($Client === 0) { echo "debug: annulation sélection client\n"; return [0, null]; // menu principal @@ -26,7 +34,7 @@ function modifyData($Client): array // -- partie 2: modifier un client -- - // fenêtre + // fenêtre dynamique $ModificationClientMenu = makeModifyCustomerWindow($Client); $choix_niv2 = exec($ModificationClientMenu->get()); @@ -53,20 +61,22 @@ function modifyData($Client): array { echo "choix: annulation\n"; } - $Client->update(); + Client::$entityManager->flush(); // à mettre dans une classe Manager + return [3, $Client]; // menu précédent } - elseif(is_string($choix_niv2) && $choix_niv2 != '') // autres choix, modifier une valeur + elseif(is_string($choix_niv2) && $choix_niv2 != '') // modifier autre chose chez le client { - echo "choix: modifier" . $choix_niv2 . "\n"; + echo "choix: modifier " . $choix_niv2 . "\n"; $ModificationClient = new ZenityEntry($choix_niv2); $input = exec($ModificationClient->get()); if(is_string($input) && $input != '') { + // entités et BDD $Client->set($choix_niv2, $input); - $Client->update(); + $Client::$entityManager->flush(); - // mettre à jour les documents (il faudrait modifier tous les documents!!) + // documents (les factures, etc, ne sont pas modifiées ici) $EnveloppeRecto = Latex::makeInstance('enveloppe_recto'); $EnveloppeRecto->setData($Client); $EnveloppeRecto->makeLatex(); @@ -86,36 +96,35 @@ function modifyData($Client): array // -- partie 3: rechercher une prestation -- - $Presta = getServices($Client); // = 0 ou type "Prestations" - if(!is_object($Presta) || !get_class($Presta) == 'Prestations') + $Presta = Prestation::getServices($Client); // = 0 ou type "Prestation" + if(!is_object($Presta) || !get_class($Presta) == 'Prestation') { - echo "debug: annulation sélection client\n"; + echo "debug: annulation sélection d'une prestation\n"; return [3, $Client]; // menu précédent } - - $type = $Presta->getTypePresta(); - switch($type) + $type_presta = $Presta->getTypePresta(); + switch($type_presta) { case 'facture': - $PrestaDetails = new DevisFactures('factures'); + $classe = 'Facture'; break; case 'devis': - $PrestaDetails = new DevisFactures('devis'); + $classe = 'Devis'; break; case 'cesu': - $PrestaDetails = new CESU(); + $classe = 'CESU'; break; case 'location': - $PrestaDetails = new Locations(); + $classe = 'Location'; break; case 'non_vendue': $PrestaDetails = null; break; } - if($type != 'non_vendue') + if($type_presta != 'non_vendue') { - $PrestaDetails->setIdPresta($Presta->getId()); - $PrestaDetails->hydrate($PrestaDetails->getDetailsByIdPresta()); + $repository = $classe::$entityManager->getRepository($classe); + $PrestaDetails = $repository->findOneBy(['presta' => $Presta->getId()]); } @@ -125,11 +134,7 @@ function modifyData($Client): array $ModificationPrestaMenu = makeModifyServiceWindow($Presta, $PrestaDetails); $choix_niv3 = exec($ModificationPrestaMenu->get()); - //~ if($choix_niv3 === ZenitySetup::$modification_presta['devis_facture']) // devis -> facture - //~ { - //~ echo "choix: changer un devis en facture\n"; - //~ return [2, $Client]; // menu "client" - //~ } + if($choix_niv3 === 'Date:') { $Date = new Dates(exec($Calendrier->get())); // exec() renvoie soit une chaîne soit un false @@ -139,50 +144,60 @@ function modifyData($Client): array } else { - // mettre à jour la base de données - $Presta->setDate($Date->getTimestamp(), true); // un entier pour la BDD, "true" pour modifier le code_presta - $Presta->update(); + // entités et BDD + $Presta->set($choix_niv3, $Date); + $old_code = $Presta->getCodePresta(); + $Presta->setCodePresta(0); + $Presta::$entityManager->flush(); - // mettre à jour les documents - if($type === 'devis' || $type === 'facture' || $type === 'location') + // 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(); - makeTexAndPdf($DocumentPresta); + $DocumentPresta->makeLatex(); // en mémoire + + renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); + makeTexAndPdf($DocumentPresta); // une nouvelle facture est créée, supprimer l'ancienne ou la renommer avec la nouvelle date } } return [3, $Client]; // menu précédent } - //~ elseif($choix_niv3 === 'Type de Presta:') // choix impossible pour le moment + //~ 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 { - echo "choix: modifier" . $choix_niv3 . "\n"; + 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)) // chaine vide autorisée + if(is_string($input)) // chaîne vide autorisée { - // mettre à jour la base de données + // entités et BDD $Presta->set($choix_niv3, $input); - $Presta->update(); - - if($type != 'non_vendue') + $old_code = $Presta->getCodePresta(); + $Presta->setCodePresta(0); + if($type_presta != 'non_vendue') { $PrestaDetails->set($choix_niv3, $input); - $PrestaDetails->update(); + $PrestaDetails::$entityManager->flush(); + } + else + { + $Presta::$entityManager->flush(); } - // mettre à jour les documents - if($type === 'devis' || $type === 'facture' || $type === 'location') + // documents + if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location') { - $DocumentPresta = Latex::makeInstance($type); + $DocumentPresta = Latex::makeInstance($type_presta); $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); $DocumentPresta->makeLatex(); + + renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); makeTexAndPdf($DocumentPresta); } } -- cgit v1.2.3