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 | |
| 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')
| -rw-r--r-- | src/sections/2_service.php | 114 | ||||
| -rw-r--r-- | src/sections/3-1_windows.php | 30 | ||||
| -rw-r--r-- | src/sections/3_modify_data.php | 128 |
3 files changed, 94 insertions, 178 deletions
diff --git a/src/sections/2_service.php b/src/sections/2_service.php index dc16fe8..e2d64f2 100644 --- a/src/sections/2_service.php +++ b/src/sections/2_service.php | |||
| @@ -5,11 +5,9 @@ | |||
| 5 | 5 | ||
| 6 | function newService(?Client $Client = null): array | 6 | function newService(?Client $Client = null): array |
| 7 | { | 7 | { |
| 8 | // fenêtres recherche d'un client | 8 | // fenêtres |
| 9 | $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client['text']); | 9 | $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client['text']); |
| 10 | $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client['text'], []); | 10 | $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client['text'], []); |
| 11 | |||
| 12 | // fenêtres | ||
| 13 | $MenuEnregistrement = new ZenityList(ZenitySetup::$menu_enregistrement['text'], ZenitySetup::$menu_enregistrement['entrees']); | 11 | $MenuEnregistrement = new ZenityList(ZenitySetup::$menu_enregistrement['text'], ZenitySetup::$menu_enregistrement['entrees']); |
| 14 | $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section2']); | 12 | $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section2']); |
| 15 | $FormulaireDevis = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['devis_entrees']); | 13 | $FormulaireDevis = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['devis_entrees']); |
| @@ -17,15 +15,16 @@ function newService(?Client $Client = null): array | |||
| 17 | $FormulaireFactureReduit = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['facture_entrees_reduit']); | 15 | $FormulaireFactureReduit = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['facture_entrees_reduit']); |
| 18 | $FormulaireCesu = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['cesu_entrees']); | 16 | $FormulaireCesu = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['cesu_entrees']); |
| 19 | $FormulaireLocation = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['location_entrees']); | 17 | $FormulaireLocation = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['location_entrees']); |
| 18 | $FormulaireNonVendue = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['non_vendue_entrees']); | ||
| 20 | $CommentairePrestation = new ZenityEntry(ZenitySetup::$commentaire_prestation['text']); | 19 | $CommentairePrestation = new ZenityEntry(ZenitySetup::$commentaire_prestation['text']); |
| 21 | //$Recapitulatif = new ZenityList(ZenitySetup::$recapitulatif_text, ZenitySetup::$recapitulatif_entrees); // tableau à multiples colonnes | 20 | //$Recapitulatif = new ZenityList(ZenitySetup::$recapitulatif_text, ZenitySetup::$recapitulatif_entrees); // tableau à multiples colonnes |
| 22 | $FinSection2 = new ZenityList(ZenitySetup::$fin_section_2['text'], ZenitySetup::$fin_section_2['entrees']); | 21 | $FinSection2 = new ZenityList(ZenitySetup::$fin_section_2['text'], ZenitySetup::$fin_section_2['entrees']); |
| 23 | 22 | ||
| 24 | 23 | ||
| 25 | // -- partie 1: le client -- | 24 | // -- partie 1: rechercher un client -- |
| 26 | if(!$Client) | 25 | if(!$Client) |
| 27 | { | 26 | { |
| 28 | $Client = Client::find($RechercheClient, $ResultatsRechercheClient); // retourne un Client ou 0 | 27 | $Client = Client::find($RechercheClient, $ResultatsRechercheClient); |
| 29 | //$ResultatsRechercheClient->cleanCommand(); // inutile parce qu'on ne boucle pas dans cette fonction | 28 | //$ResultatsRechercheClient->cleanCommand(); // inutile parce qu'on ne boucle pas dans cette fonction |
| 30 | if(!$Client) | 29 | if(!$Client) |
| 31 | { | 30 | { |
| @@ -51,69 +50,82 @@ function newService(?Client $Client = null): array | |||
| 51 | echo "debug: annulation à la saisie d'une date\n"; | 50 | echo "debug: annulation à la saisie d'une date\n"; |
| 52 | return [2, $Client]; | 51 | return [2, $Client]; |
| 53 | } | 52 | } |
| 54 | 53 | ||
| 55 | $Presta = new Prestation($Client); | 54 | |
| 56 | //var_dump($Client);die; | ||
| 57 | $Presta->setDate($date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]); // 2026-10-17 | ||
| 58 | |||
| 59 | // formulaire - étape 2/3 | 55 | // formulaire - étape 2/3 |
| 60 | switch($choix_niv2) | 56 | switch($choix_niv2) |
| 61 | { | 57 | { |
| 62 | // comparaison retour de $MenuEnregistrement->get() avec les noms des entrées du même menu | 58 | // comparaison du retour de $MenuEnregistrement->get() avec les noms des entrées du même menu |
| 63 | case ZenitySetup::$menu_enregistrement['entrees'][0]: // "Devis" | 59 | case ZenitySetup::$menu_enregistrement['entrees'][0]: // "Devis" |
| 64 | $PrestaDetails = new Devis($Presta); | 60 | $Presta = new Devis($Client); |
| 65 | $Presta->setTypePresta('devis'); | ||
| 66 | $answers = exec($FormulaireDevis->get()); | 61 | $answers = exec($FormulaireDevis->get()); |
| 67 | break; | 62 | break; |
| 68 | case ZenitySetup::$menu_enregistrement['entrees'][1]: // "Facture" | 63 | case ZenitySetup::$menu_enregistrement['entrees'][1]: // "Facture" |
| 69 | $PrestaDetails = new Facture($Presta); | 64 | $Presta = new Facture($Client, false); |
| 70 | $Presta->setTypePresta('facture'); | ||
| 71 | $answers = exec($FormulaireFacture->get()); | 65 | $answers = exec($FormulaireFacture->get()); |
| 72 | break; | 66 | break; |
| 73 | case ZenitySetup::$menu_enregistrement['entrees'][2]: // "Facture à partir d'un devis" | 67 | case ZenitySetup::$menu_enregistrement['entrees'][2]: // "Facture à partir d'un devis" |
| 74 | // recherche du devis | 68 | $Quotation = Prestation::getServices($Client, Devis::class); |
| 75 | $Quotation = Prestation::getServices($Client, 'devis'); // rechercher un devis, type 'devis' spécifié | 69 | if(!is_object($Quotation) || $Quotation->getTypePresta() != 'devis'){ |
| 76 | if(!is_object($Quotation) || get_class($Quotation) != 'Prestation' || $Quotation->getTypePresta() != 'devis') | ||
| 77 | { | ||
| 78 | echo "debug: annulation sélection client\n"; | 70 | echo "debug: annulation sélection client\n"; |
| 79 | return [2, $Client]; // menu précédent | 71 | return [2, $Client]; // menu précédent |
| 80 | } | 72 | } |
| 81 | $QuotationDetails = Devis::getQuotation($Quotation); | 73 | $Presta = new Facture($Client, true); // true = à partir d'un devis |
| 82 | $PrestaDetails = new Facture($Presta); | 74 | $Presta->hydrateWithQuotation($Quotation); // du devis à la facture |
| 83 | $PrestaDetails->hydrateWithQuotation($QuotationDetails); // du devis à la facture | ||
| 84 | $Presta->setTypePresta('facture'); | ||
| 85 | $answers = exec($FormulaireFactureReduit->get()); | 75 | $answers = exec($FormulaireFactureReduit->get()); |
| 86 | break; | 76 | break; |
| 87 | case ZenitySetup::$menu_enregistrement['entrees'][3]: // "CESU" | 77 | case ZenitySetup::$menu_enregistrement['entrees'][3]: // "CESU" |
| 88 | $PrestaDetails = new CESU($Presta); | 78 | $Presta = new CESU($Client); |
| 89 | $Presta->setTypePresta('cesu'); | ||
| 90 | $answers = exec($FormulaireCesu->get()); | 79 | $answers = exec($FormulaireCesu->get()); |
| 91 | break; | 80 | break; |
| 92 | case ZenitySetup::$menu_enregistrement['entrees'][4]: // "Location" | 81 | case ZenitySetup::$menu_enregistrement['entrees'][4]: // "Location" |
| 93 | $PrestaDetails = new Location($Presta); | 82 | $Presta = new Location($Client); |
| 94 | $Presta->setTypePresta('location'); | ||
| 95 | $answers = exec($FormulaireLocation->get()); | 83 | $answers = exec($FormulaireLocation->get()); |
| 96 | break; | 84 | break; |
| 97 | case ZenitySetup::$menu_enregistrement['entrees'][5]: // "Prestation non vendue" | 85 | case ZenitySetup::$menu_enregistrement['entrees'][5]: // "Prestation non vendue" |
| 98 | $Presta->setTypePresta('non_vendue'); | 86 | $Presta = new NonVendue($Client); |
| 87 | $answers = exec($FormulaireNonVendue->get()); | ||
| 99 | break; | 88 | break; |
| 100 | default: // inutile normallement, cas déjà géré avant | 89 | default: // inutile normallement, cas déjà géré avant |
| 101 | echo "debug: sortie du menu enregistrement incorrect\n"; | 90 | echo "debug: sortie du menu enregistrement incorrect\n"; |
| 102 | return [0, null]; | 91 | return [0, null]; |
| 103 | } | 92 | } |
| 93 | $Presta->setDate($date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]); // 2026-10-17 | ||
| 104 | 94 | ||
| 105 | //$Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre | 95 | //$Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre |
| 106 | //$Presta->makeCodePresta($Client->getCodeClient()); // d'un objet à l'autre | 96 | //$Presta->makeCodePresta($Client->getCodeClient()); // d'un objet à l'autre |
| 107 | $Presta->setCodePresta(1); // d'un objet à l'autre | 97 | $Presta->setCodePresta(1); // d'un objet à l'autre |
| 98 | |||
| 99 | if($Presta->getTypePresta() !== 'devis'){ | ||
| 100 | $Client->setType('client'); // changer prospect en client | ||
| 101 | } | ||
| 102 | |||
| 103 | $answers = $Presta->cleanSpecialChars($answers); | ||
| 104 | |||
| 105 | $data_array = $Presta->answersToArray($answers); | ||
| 106 | if(!$data_array){ // annulation | ||
| 107 | echo "debug: annulation lors de l'enregistrement des détails de la prestation\n"; | ||
| 108 | return [0, null]; | ||
| 109 | } | ||
| 110 | |||
| 111 | // attention risque d'erreur! les données n'ont pas de d'identifiant! | ||
| 112 | // leur ordre et leur nombre permettent d'insérer la bonne info au bon endroit | ||
| 113 | // toute modif du modèle ou d'un formulaire doit être répèrcutée ici | ||
| 114 | if(!$Presta->validateForm($data_array)){ | ||
| 115 | echo "erreur: les données du formulaire sont incompatibles avec le modèle\n"; | ||
| 116 | return [0, null]; | ||
| 117 | } | ||
| 118 | |||
| 119 | // hydratation avec la saisie du formulaire | ||
| 120 | $Presta->hydrate($data_array); | ||
| 108 | 121 | ||
| 109 | // commentaire - étape 3/3 | 122 | // commentaire - étape 3/3 |
| 110 | $comment = exec($CommentairePrestation->get()); | 123 | $comment = exec($CommentairePrestation->get()); |
| 111 | if($comment == '') | 124 | if($comment == ''){ |
| 112 | { | ||
| 113 | echo "debug: pas de commentaire saisi\n"; | 125 | echo "debug: pas de commentaire saisi\n"; |
| 114 | // on n'interrompt pas le script et on enregistre dans tous les cas (annulatation comprise) | 126 | // on n'interrompt pas le script et on enregistre dans tous les cas (annulation comprise) |
| 115 | } | 127 | } |
| 116 | // Cliquer sur annuler (ou appuyer sur échap) revient dont à valider avec une chaîne vide et enregistrer la prestation | 128 | // Cliquer sur annuler (ou appuyer sur échap) revient donc à valider avec une chaîne vide et enregistrer la prestation |
| 117 | // la commande 'echo $?' ($? est le code de sortie de la commande précédente) renvoit 1 si on annule avec la touche échap () | 129 | // la commande 'echo $?' ($? est le code de sortie de la commande précédente) renvoit 1 si on annule avec la touche échap () |
| 118 | // elle renvoit 0 si la fenêtre est fermée correctement, qu'on valide une chaîne vide ou qu'on clique sur Annuler (on ne peut pas savoir) | 130 | // elle renvoit 0 si la fenêtre est fermée correctement, qu'on valide une chaîne vide ou qu'on clique sur Annuler (on ne peut pas savoir) |
| 119 | // malheureusement, si les deux commandes sont liées par un '&&' et qu'on annule la saisie, la 2è commande n'est pas exécutée | 131 | // malheureusement, si les deux commandes sont liées par un '&&' et qu'on annule la saisie, la 2è commande n'est pas exécutée |
| @@ -125,31 +137,11 @@ function newService(?Client $Client = null): array | |||
| 125 | //~ return 0; | 137 | //~ return 0; |
| 126 | //~ } | 138 | //~ } |
| 127 | $Presta->setCommentaires($comment); | 139 | $Presta->setCommentaires($comment); |
| 128 | 140 | ||
| 129 | // hydratation avec la saisie du formulaire | 141 | // enregistrement |
| 130 | if($choix_niv2 != ZenitySetup::$menu_enregistrement['entrees'][5]) // cas: tous les cas sauf presta non vendue | 142 | // déléguer la synchronisation (flush) avec la BDD à une classe "Manager"? |
| 131 | { | 143 | Prestation::$entityManager->persist($Presta); |
| 132 | //var_dump($answers); | 144 | Prestation::$entityManager->flush(); |
| 133 | if($Presta->getTypePresta() !== 'devis'){ | ||
| 134 | $Client->setType('client'); | ||
| 135 | } | ||
| 136 | if($answers == '') // annulation | ||
| 137 | { | ||
| 138 | echo "debug: annulation lors de l'enregistrement des détails de la prestation\n"; | ||
| 139 | return [0, null]; | ||
| 140 | } | ||
| 141 | $PrestaDetails->hydrate($answers); | ||
| 142 | |||
| 143 | // déléguer la synchronisation (flush) avec la BDD à une classe "Manager" | ||
| 144 | } | ||
| 145 | |||
| 146 | // si encore de type prospect, devient un type client | ||
| 147 | // déjà fait ailleurs je crois! | ||
| 148 | /*if($Client->typeToClient()) // utile si $Client est renvoyé dans le "return" | ||
| 149 | { | ||
| 150 | $Client->updateOneValue('type', 'client'); // base synchronisée | ||
| 151 | }*/ | ||
| 152 | |||
| 153 | 145 | ||
| 154 | // -- partie 3: LaTeX -- | 146 | // -- partie 3: LaTeX -- |
| 155 | 147 | ||
| @@ -162,9 +154,8 @@ function newService(?Client $Client = null): array | |||
| 162 | $EnveloppeRecto->setData($Client); | 154 | $EnveloppeRecto->setData($Client); |
| 163 | $EnveloppeRecto->makeLatex(); | 155 | $EnveloppeRecto->makeLatex(); |
| 164 | $EnveloppeVerso->makeLatex(); | 156 | $EnveloppeVerso->makeLatex(); |
| 165 | if($DocumentPresta !== null) | 157 | if($DocumentPresta !== null){ // facture, devis ou location |
| 166 | { | 158 | $DocumentPresta->setData($Client)->setData($Presta); |
| 167 | $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); | ||
| 168 | $DocumentPresta->makeLatex(); | 159 | $DocumentPresta->makeLatex(); |
| 169 | } | 160 | } |
| 170 | 161 | ||
| @@ -172,8 +163,7 @@ function newService(?Client $Client = null): array | |||
| 172 | $EnveloppeRecto->makeTexAndPdf(); | 163 | $EnveloppeRecto->makeTexAndPdf(); |
| 173 | $EnveloppeVerso->makeTexAndPdf(); | 164 | $EnveloppeVerso->makeTexAndPdf(); |
| 174 | 165 | ||
| 175 | if($DocumentPresta !== null) | 166 | if($DocumentPresta !== null){ |
| 176 | { | ||
| 177 | $DocumentPresta->makeTexAndPdf(); | 167 | $DocumentPresta->makeTexAndPdf(); |
| 178 | } | 168 | } |
| 179 | 169 | ||
diff --git a/src/sections/3-1_windows.php b/src/sections/3-1_windows.php index 76d01dd..152c3d3 100644 --- a/src/sections/3-1_windows.php +++ b/src/sections/3-1_windows.php | |||
| @@ -22,12 +22,12 @@ function makeModifyCustomerWindow(Client $Customer): ZenityList | |||
| 22 | $entries[$i][] = ''; | 22 | $entries[$i][] = ''; |
| 23 | //~ $entries[$i][] = ZenitySetup::$modification_client['return']; | 23 | //~ $entries[$i][] = ZenitySetup::$modification_client['return']; |
| 24 | //~ $entries[$i][] = ''; | 24 | //~ $entries[$i][] = ''; |
| 25 | $ModifyCustomer->setListRows($entries, 2, 2.5); | ||
| 26 | 25 | ||
| 26 | $ModifyCustomer->setListRows($entries, 2, 2.5); | ||
| 27 | return $ModifyCustomer; | 27 | return $ModifyCustomer; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | function makeModifyServiceWindow(Prestation $Service, $ServiceDetails = null): ZenityList | 30 | function makeModifyServiceWindow(Prestation $Service): ZenityList |
| 31 | { | 31 | { |
| 32 | // fenêtre | 32 | // fenêtre |
| 33 | $ModifyService = new ZenityList(ZenitySetup::$modification_presta['text'], []); | 33 | $ModifyService = new ZenityList(ZenitySetup::$modification_presta['text'], []); |
| @@ -42,31 +42,7 @@ function makeModifyServiceWindow(Prestation $Service, $ServiceDetails = null): Z | |||
| 42 | $entrees[$i][] = $value; | 42 | $entrees[$i][] = $value; |
| 43 | $i++; | 43 | $i++; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | if(is_object($ServiceDetails)) | ||
| 47 | { | ||
| 48 | $presta_data = $ServiceDetails->getAllWithWindowFields(); | ||
| 49 | //var_dump($presta_data); | ||
| 50 | foreach($presta_data as $key => $value) | ||
| 51 | { | ||
| 52 | $entrees[$i][] = $key; | ||
| 53 | $entrees[$i][] = $value; | ||
| 54 | $i++; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | //~ if($Service->getTypePresta() === 'devis') | ||
| 59 | //~ { | ||
| 60 | //~ $entrees[$i][] = ZenitySetup::$modification_presta['devis_facture']; // option créer une facture à partir du devis | ||
| 61 | //~ $entrees[$i][] = ''; | ||
| 62 | //~ } | ||
| 63 | |||
| 64 | //~ $entrees[$i][] = ZenitySetup::$modification_presta['service']; | ||
| 65 | //~ $entrees[$i][] = ''; | ||
| 66 | //~ $i++; | ||
| 67 | //~ $entrees[$i][] = ZenitySetup::$modification_presta['return']; | ||
| 68 | //~ $entrees[$i][] = ''; | ||
| 69 | |||
| 70 | $ModifyService->setListRows($entrees, 2, 2.5); | 46 | $ModifyService->setListRows($entrees, 2, 2.5); |
| 71 | return $ModifyService; | 47 | return $ModifyService; |
| 72 | } | 48 | } |
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 | } |
