diff options
| author | polo <ordipolo@gmx.fr> | 2026-10-20 21:49:17 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-10-20 21:49:17 +0200 |
| commit | b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878 (patch) | |
| tree | bbaea156e9d32edf14adad8fe5ce3338014e7710 /src/sections/3_modify_data.php | |
| parent | 79bc73d7985f51f2a6a1b3cb6e0115f59afb2ac4 (diff) | |
| download | AppliGestionPHP-b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878.tar.gz AppliGestionPHP-b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878.tar.bz2 AppliGestionPHP-b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878.zip | |
mise en place de l'héritage 2, nombreuses simplifications et factorisations
Diffstat (limited to 'src/sections/3_modify_data.php')
| -rw-r--r-- | src/sections/3_modify_data.php | 128 |
1 files changed, 39 insertions, 89 deletions
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'); | |||
| 7 | 7 | ||
| 8 | function modifyData(?Client $Client = null): array | 8 | function modifyData(?Client $Client = null): array |
| 9 | { | 9 | { |
| 10 | // -- partie 1: rechercher un client -- | 10 | // fenêtres |
| 11 | |||
| 12 | // fenêtres statiques | ||
| 13 | // recherche d'un client | ||
| 14 | $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client['text']); | 11 | $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client['text']); |
| 15 | $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client['text'], []); | 12 | $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client['text'], []); |
| 16 | // modification de données | ||
| 17 | $TypeDeClient = new ZenityList(ZenitySetup::$type_client['text'], ZenitySetup::$type_client['entrees']); | 13 | $TypeDeClient = new ZenityList(ZenitySetup::$type_client['text'], ZenitySetup::$type_client['entrees']); |
| 18 | $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section3']); | 14 | $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section3']); |
| 19 | 15 | ||
| 16 | |||
| 17 | // -- partie 1: rechercher un client -- | ||
| 20 | if(!$Client) | 18 | if(!$Client) |
| 21 | { | 19 | { |
| 22 | $Client = Client::find($RechercheClient, $ResultatsRechercheClient); | 20 | $Client = Client::find($RechercheClient, $ResultatsRechercheClient); |
| @@ -93,120 +91,72 @@ function modifyData(?Client $Client = null): array | |||
| 93 | 91 | ||
| 94 | 92 | ||
| 95 | // -- partie 3: rechercher une prestation -- | 93 | // -- partie 3: rechercher une prestation -- |
| 96 | $Presta = Prestation::getServices($Client); // = 0 ou type "Prestation" | 94 | $Presta = Prestation::getServices($Client); |
| 97 | if(!is_object($Presta) || !get_class($Presta) == 'Prestation') | 95 | if(!is_object($Presta) || !get_class($Presta) == 'Prestation') |
| 98 | { | 96 | { |
| 99 | echo "debug: annulation sélection d'une prestation\n"; | 97 | echo "debug: annulation sélection d'une prestation\n"; |
| 100 | return [3, $Client]; // menu précédent | 98 | return [3, $Client]; // menu précédent |
| 101 | } | 99 | } |
| 102 | $type_presta = $Presta->getTypePresta(); | 100 | $type_presta = $Presta->getTypePresta(); |
| 103 | $classe = ''; | 101 | $classe = match($type_presta){ |
| 104 | switch($type_presta){ | 102 | 'facture' => Facture::class, |
| 105 | case 'facture': | 103 | 'devis' => Devis::class, |
| 106 | $classe = 'Facture'; | 104 | 'cesu' => CESU::class, |
| 107 | break; | 105 | 'location' => Location::class, |
| 108 | case 'devis': | 106 | 'non_vendue' => NonVendue::class, |
| 109 | $classe = 'Devis'; | 107 | }; |
| 110 | break; | 108 | |
| 111 | case 'cesu': | 109 | $repository = Prestation::$entityManager->getRepository($classe); |
| 112 | $classe = 'CESU'; | 110 | $Presta = $repository->findOneBy(['id' => $Presta->getId()]); |
| 113 | break; | ||
| 114 | case 'location': | ||
| 115 | $classe = 'Location'; | ||
| 116 | break; | ||
| 117 | case 'non_vendue': | ||
| 118 | $PrestaDetails = null; | ||
| 119 | break; | ||
| 120 | default: | ||
| 121 | echo "erreur: type de prestation buggué\n"; | ||
| 122 | } | ||
| 123 | if($type_presta != 'non_vendue') | ||
| 124 | { | ||
| 125 | $repository = $classe::$entityManager->getRepository($classe); | ||
| 126 | $PrestaDetails = $repository->findOneBy(['presta' => $Presta->getId()]); | ||
| 127 | } | ||
| 128 | 111 | ||
| 129 | 112 | ||
| 130 | // -- partie 4: modifier une prestation -- | 113 | // -- partie 4: modifier une prestation -- |
| 131 | 114 | ||
| 132 | // fenêtre | 115 | // fenêtre |
| 133 | $ModificationPrestaMenu = makeModifyServiceWindow($Presta, $PrestaDetails); | 116 | $ModificationPrestaMenu = makeModifyServiceWindow($Presta); |
| 134 | |||
| 135 | $choix_niv3 = exec($ModificationPrestaMenu->get()); | 117 | $choix_niv3 = exec($ModificationPrestaMenu->get()); |
| 136 | 118 | if($choix_niv3 === 'Date:'){ | |
| 137 | if($choix_niv3 === 'Date:') | ||
| 138 | { | ||
| 139 | $date_array = explode('/', exec($Calendrier->get())); // 17/10/2026 | 119 | $date_array = explode('/', exec($Calendrier->get())); // 17/10/2026 |
| 140 | if(count($date_array) === 1){ | 120 | if(count($date_array) === 1){ |
| 141 | echo "debug: annulation à la saisie d'une date\n"; | 121 | echo "debug: annulation à la saisie d'une date\n"; |
| 142 | return [3, $Client]; | 122 | return [3, $Client]; |
| 143 | } | 123 | } |
| 144 | 124 | $input = $date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]; // 2026-10-17 | |
| 145 | // entités et BDD | ||
| 146 | $Presta->set($choix_niv3, $date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]); // 2026-10-09 | ||
| 147 | $old_code = $Presta->getCodePresta(); | ||
| 148 | $Presta->setCodePresta(0); | ||
| 149 | $Presta::$entityManager->flush(); | ||
| 150 | |||
| 151 | // documents | ||
| 152 | if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location') | ||
| 153 | { | ||
| 154 | $DocumentPresta = Latex::makeInstance($Presta->getTypePresta()); // $type = facture, devis, location | ||
| 155 | $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); | ||
| 156 | $DocumentPresta->makeLatex(); // en mémoire | ||
| 157 | |||
| 158 | File::renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); | ||
| 159 | $DocumentPresta->makeTexAndPdf(); // une nouvelle facture est créée, supprimer l'ancienne ou la renommer avec la nouvelle date | ||
| 160 | } | ||
| 161 | |||
| 162 | return [3, $Client]; // menu précédent | ||
| 163 | } | 125 | } |
| 164 | //~ elseif($choix_niv3 === 'Type de Presta:') // compliqué! choix impossible pour le moment | 126 | //~ elseif($choix_niv3 === 'Type de Presta:') // compliqué! choix impossible pour le moment |
| 165 | //~ { | 127 | //~ { |
| 166 | //~ echo "choix: changer le type de prestation (devis, facture, etc)\n"; | 128 | //~ echo "choix: changer le type de prestation (devis, facture, etc)\n"; |
| 167 | //~ return [3, $Client]; // menu "client" | 129 | //~ return [3, $Client]; // menu "client" |
| 168 | //~ } | 130 | //~ } |
| 169 | elseif(is_string($choix_niv3) && $choix_niv3 != '') // modifier une valeur | 131 | elseif(is_string($choix_niv3) && $choix_niv3 != ''){ // modifier une valeur |
| 170 | { | ||
| 171 | echo "choix: modifier " . $choix_niv3 . "\n"; | 132 | echo "choix: modifier " . $choix_niv3 . "\n"; |
| 172 | $ModificationPrestaForm = new ZenityEntry($choix_niv3); | 133 | $ModificationPrestaForm = new ZenityEntry($choix_niv3); |
| 173 | $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 | 134 | $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 |
| 174 | if(is_string($input)) // chaîne vide autorisée | 135 | if(!is_string($input)){ // chaîne vide autorisée |
| 175 | { | ||
| 176 | // entités et BDD | ||
| 177 | $Presta->set($choix_niv3, $input); | ||
| 178 | $old_code = $Presta->getCodePresta(); | ||
| 179 | $Presta->setCodePresta(0); | ||
| 180 | if($type_presta != 'non_vendue') | ||
| 181 | { | ||
| 182 | $PrestaDetails->set($choix_niv3, $input); | ||
| 183 | $PrestaDetails::$entityManager->flush(); | ||
| 184 | } | ||
| 185 | else | ||
| 186 | { | ||
| 187 | $Presta::$entityManager->flush(); | ||
| 188 | } | ||
| 189 | |||
| 190 | // documents | ||
| 191 | if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location') | ||
| 192 | { | ||
| 193 | $DocumentPresta = Latex::makeInstance($type_presta); | ||
| 194 | $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); // polymorphisme | ||
| 195 | $DocumentPresta->makeLatex(); | ||
| 196 | |||
| 197 | File::renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); | ||
| 198 | $DocumentPresta->makeTexAndPdf(); | ||
| 199 | } | ||
| 200 | } | ||
| 201 | else | ||
| 202 | { | ||
| 203 | echo "choix: annulation\n"; | 136 | echo "choix: annulation\n"; |
| 137 | return [3, $Client]; // menu précédent | ||
| 204 | } | 138 | } |
| 205 | return [3, $Client]; // menu précédent | ||
| 206 | } | 139 | } |
| 207 | else // annuler | 140 | else{ |
| 208 | { | ||
| 209 | echo "annulation: retour au menu précédent\n"; | 141 | echo "annulation: retour au menu précédent\n"; |
| 210 | return [3, $Client]; // menu précédent | 142 | return [3, $Client]; // menu précédent |
| 211 | } | 143 | } |
| 144 | |||
| 145 | // entités et BDD | ||
| 146 | $Presta->set($choix_niv3, $input); | ||
| 147 | $old_code = $Presta->getCodePresta(); | ||
| 148 | $Presta->setCodePresta(0); | ||
| 149 | $Presta::$entityManager->flush(); | ||
| 150 | |||
| 151 | // documents | ||
| 152 | if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location'){ | ||
| 153 | $DocumentPresta = Latex::makeInstance($type_presta); | ||
| 154 | $DocumentPresta->setData($Client)->setData($Presta); | ||
| 155 | $DocumentPresta->makeLatex(); | ||
| 156 | |||
| 157 | File::renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); | ||
| 158 | $DocumentPresta->makeTexAndPdf(); | ||
| 159 | } | ||
| 160 | |||
| 161 | return [3, $Client]; // menu précédent | ||
| 212 | } | 162 | } |
