summaryrefslogtreecommitdiff
path: root/src/sections
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
committerpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
commitbf6655a534a6775d30cafa67bd801276bda1d98d (patch)
treec6381e3f6c81c33eab72508f410b165ba05f7e9c /src/sections
parent94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff)
downloadAppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'src/sections')
-rw-r--r--src/sections/1_customer.php46
-rw-r--r--src/sections/2_service.php103
-rw-r--r--src/sections/3-1_windows.php6
-rw-r--r--src/sections/3_modify_data.php113
-rw-r--r--src/sections/4_get_document.php14
5 files changed, 147 insertions, 135 deletions
diff --git a/src/sections/1_customer.php b/src/sections/1_customer.php
index b0e3283..db5c448 100644
--- a/src/sections/1_customer.php
+++ b/src/sections/1_customer.php
@@ -3,42 +3,46 @@
3// 3//
4// -- SECTION 1: Fichier clients et propects -- 4// -- SECTION 1: Fichier clients et propects --
5 5
6use Doctrine\ORM\EntityManager;
7
6function newCustomer(): array 8function newCustomer(): array
7{ 9{
8 // fenêtres 10 // fenêtres
9 $TypeDeClient = new ZenityList(ZenitySetup::$type_client['text'], ZenitySetup::$type_client['entrees']); 11 //$TypeDeClient = new ZenityList(ZenitySetup::$type_client['text'], ZenitySetup::$type_client['entrees']);
12 $NouveauClient = new ZenityForms(ZenitySetup::$nouveau_client['text'], ZenitySetup::$nouveau_client['entrees']);
10 $FinSection1 = new ZenityList(ZenitySetup::$fin_section_1['text'], ZenitySetup::$fin_section_1['entrees']); 13 $FinSection1 = new ZenityList(ZenitySetup::$fin_section_1['text'], ZenitySetup::$fin_section_1['entrees']);
11 14
15 $Customer = new Client;
16
12 // -- partie 1: client ou prospect? -- 17 // -- partie 1: client ou prospect? --
13 $Client = new Clients; 18 //~ $choix_niv2 = exec($TypeDeClient->get());
14 $choix_niv2 = exec($TypeDeClient->get()); 19 //~ if($choix_niv2 === ZenitySetup::$type_client['entrees'][0])
15 if($choix_niv2 === ZenitySetup::$type_client['entrees'][0]) 20 //~ {
16 { 21 //~ echo "choix: " . $choix_niv2 . "\n";
17 echo "choix: " . $choix_niv2 . "\n"; 22 //~ $Customer->setType('client');
18 $Client->setType('client'); 23 //~ }
19 } 24 //~ elseif($choix_niv2 === ZenitySetup::$type_client['entrees'][1])
20 elseif($choix_niv2 === ZenitySetup::$type_client['entrees'][1]) 25 //~ {
21 { 26 //~ echo "choix: " . $choix_niv2 . "\n";
22 echo "choix: " . $choix_niv2 . "\n"; 27 //~ $Customer->setType('prospect');
23 $Client->setType('prospect'); 28 //~ }
24 } 29 //~ else
25 else 30 //~ {
26 { 31 //~ return [0, null]; // menu principal
27 return [0, null]; // menu principal 32 //~ }
28 }
29 33
30 // -- partie 2: saisie des infos -- 34 // -- partie 2: saisie des infos --
31 if(enterCustomer($Client)) 35 if($Customer->enterCustomer($NouveauClient))
32 { 36 {
33 // -- partie 3: on fait quoi maintenant -- 37 // -- partie 3: on fait quoi maintenant --
34 $choix_niv3 = exec($FinSection1->get()); 38 $choix_niv3 = exec($FinSection1->get());
35 if($choix_niv3 === ZenitySetup::$fin_section_1['entrees'][0]) 39 if($choix_niv3 === ZenitySetup::$fin_section_1['entrees'][0])
36 { 40 {
37 return [2, $Client]; // section 2: newService() 41 return [2, $Customer]; // section 2: newService()
38 } 42 }
39 elseif($choix_niv3 === ZenitySetup::$fin_section_1['entrees'][1]) 43 elseif($choix_niv3 === ZenitySetup::$fin_section_1['entrees'][1])
40 { 44 {
41 return [3, $Client]; // section 3: modifyData() 45 return [3, $Customer]; // section 3: modifyData()
42 } 46 }
43 elseif($choix_niv3 === ZenitySetup::$fin_section_1['entrees'][2]) 47 elseif($choix_niv3 === ZenitySetup::$fin_section_1['entrees'][2])
44 { 48 {
diff --git a/src/sections/2_service.php b/src/sections/2_service.php
index 3dd620d..e25d677 100644
--- a/src/sections/2_service.php
+++ b/src/sections/2_service.php
@@ -3,26 +3,33 @@
3// 3//
4// -- SECTION 2: Prestation et devis -- 4// -- SECTION 2: Prestation et devis --
5 5
6use Doctrine\ORM\EntityManager;
7
6function newService($Client): array // $Client est un Client ou null 8function newService($Client): array // $Client est un Client ou null
7{ 9{
10 // fenêtres recherche d'un client
11 $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client['text']);
12 $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client['text'], []);
13
8 // fenêtres 14 // fenêtres
9 $MenuEnregistrement = new ZenityList(ZenitySetup::$menu_enregistrement_text, ZenitySetup::$menu_enregistrement_entrees); 15 $MenuEnregistrement = new ZenityList(ZenitySetup::$menu_enregistrement['text'], ZenitySetup::$menu_enregistrement['entrees']);
10 $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section2']); 16 $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section2']);
11 $FormulaireDevis = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['devis_entrees']); 17 $FormulaireDevis = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['devis_entrees']);
12 $FormulaireFacture = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['facture_entrees']); 18 $FormulaireFacture = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['facture_entrees']);
13 $FormulaireFactureReduit = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['facture_entrees_reduit']); 19 $FormulaireFactureReduit = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['facture_entrees_reduit']);
14 $FormulaireCesu = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['cesu_entrees']); 20 $FormulaireCesu = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['cesu_entrees']);
15 $FormulaireLocation = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['location_entrees']); 21 $FormulaireLocation = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['location_entrees']);
16 $CommentairePrestation = new ZenityEntry(ZenitySetup::$commentaire_prestation_text); 22 $CommentairePrestation = new ZenityEntry(ZenitySetup::$commentaire_prestation['text']);
17 //$Recapitulatif = new ZenityList(ZenitySetup::$recapitulatif_text, ZenitySetup::$recapitulatif_entrees); // tableau à multiples colonnes 23 //$Recapitulatif = new ZenityList(ZenitySetup::$recapitulatif_text, ZenitySetup::$recapitulatif_entrees); // tableau à multiples colonnes
18 $FinSection2 = new ZenityList(ZenitySetup::$fin_section_2['text'], ZenitySetup::$fin_section_2['entrees']); 24 $FinSection2 = new ZenityList(ZenitySetup::$fin_section_2['text'], ZenitySetup::$fin_section_2['entrees']);
19 25
20 26
21 // -- partie 1: le client -- 27 // -- partie 1: le client --
22 if($Client == null || get_class($Client) !== 'Clients') 28 if($Client == null || get_class($Client) !== 'Client')
23 { 29 {
24 $Client = makeObjectClient(); // retourne 0 ou un objet "Clients" 30 $Client = Client::getObject($RechercheClient, $ResultatsRechercheClient); // retourne un Client ou 0
25 if($Client == 0) 31 //$ResultatsRechercheClient->cleanCommand(); // inutile parce qu'on ne boucle pas dans cette fonction
32 if($Client === 0)
26 { 33 {
27 echo "debug: annulation sélection client\n"; 34 echo "debug: annulation sélection client\n";
28 return [0, null]; // menu principal 35 return [0, null]; // menu principal
@@ -48,49 +55,50 @@ function newService($Client): array // $Client est un Client ou null
48 return [0, null]; // menu principal 55 return [0, null]; // menu principal
49 } 56 }
50 57
51 $Presta = new Prestations($Client->getId()); 58 $Presta = new Prestation($Client);
52 $Presta->setDate($Date->getTimestamp()); // un entier pour la BDD 59 //var_dump($Client);die;
60 //$Presta->setDate($Date->getTimestamp());
61 $Presta->setDate($Date); // envoi d'un objet, la BDD gardera le timestamp
53 62
54 // formulaire - étape 2/3 63 // formulaire - étape 2/3
55 switch($choix_niv2) 64 switch($choix_niv2)
56 { 65 {
57 // comparaison retour de $MenuEnregistrement->get() avec les noms des entrées du même menu 66 // comparaison retour de $MenuEnregistrement->get() avec les noms des entrées du même menu
58 case ZenitySetup::$menu_enregistrement_entrees[0]: // "Devis" 67 case ZenitySetup::$menu_enregistrement['entrees'][0]: // "Devis"
59 $PrestaDetails = new DevisFactures('devis'); 68 $PrestaDetails = new Devis($Presta);
60 $Presta->setTypePresta('devis'); 69 $Presta->setTypePresta('devis');
61 $answers = exec($FormulaireDevis->get()); 70 $answers = exec($FormulaireDevis->get());
62 break; 71 break;
63 case ZenitySetup::$menu_enregistrement_entrees[1]: // "Facture" 72 case ZenitySetup::$menu_enregistrement['entrees'][1]: // "Facture"
64 $PrestaDetails = new DevisFactures('factures'); // attention! type "facture" mais table "factures" 73 $PrestaDetails = new Facture($Presta);
65 $Presta->setTypePresta('facture'); 74 $Presta->setTypePresta('facture');
66 $answers = exec($FormulaireFacture->get()); 75 $answers = exec($FormulaireFacture->get());
67 break; 76 break;
68 case ZenitySetup::$menu_enregistrement_entrees[2]: // "Facture à partir d'un devis" 77 case ZenitySetup::$menu_enregistrement['entrees'][2]: // "Facture à partir d'un devis"
69 // recherche du devis 78 // recherche du devis
70 $Quotation = getServices($Client, 'devis'); // rechercher un devis, type 'devis' spécifié pour $Presta->getIdsByIdClient() 79 $Quotation = Prestation::getServices($Client, 'devis'); // rechercher un devis, type 'devis' spécifié
71 if(!is_object($Quotation) || get_class($Quotation) != 'Prestations' || $Quotation->getTypePresta() != 'devis') 80 if(!is_object($Quotation) || get_class($Quotation) != 'Prestation' || $Quotation->getTypePresta() != 'devis')
72 { 81 {
73 echo "debug: annulation sélection client\n"; 82 echo "debug: annulation sélection client\n";
74 return [2, $Client]; // menu précédent 83 return [2, $Client]; // menu précédent
75 } 84 }
76 $QuotationDetails = new DevisFactures('devis'); 85 $QuotationDetails = Devis::getQuotation($Quotation);
77 // facture: objet vide et formulaire 86 $PrestaDetails = new Facture($Presta);
78 $PrestaDetails = new DevisFactures('factures'); 87 $PrestaDetails->hydrateWithQuotation($QuotationDetails); // du devis à la facture
79 $Presta->setTypePresta('facture'); 88 $Presta->setTypePresta('facture');
80 $answers = exec($FormulaireFactureReduit->get()); 89 $answers = exec($FormulaireFactureReduit->get());
81 //var_dump($answers);
82 break; 90 break;
83 case ZenitySetup::$menu_enregistrement_entrees[3]: // "CESU" 91 case ZenitySetup::$menu_enregistrement['entrees'][3]: // "CESU"
84 $PrestaDetails = new CESU(); 92 $PrestaDetails = new CESU($Presta);
85 $Presta->setTypePresta('cesu'); 93 $Presta->setTypePresta('cesu');
86 $answers = exec($FormulaireCesu->get()); 94 $answers = exec($FormulaireCesu->get());
87 break; 95 break;
88 case ZenitySetup::$menu_enregistrement_entrees[4]: // "Location" 96 case ZenitySetup::$menu_enregistrement['entrees'][4]: // "Location"
89 $PrestaDetails = new Locations(); 97 $PrestaDetails = new Location($Presta);
90 $Presta->setTypePresta('location'); 98 $Presta->setTypePresta('location');
91 $answers = exec($FormulaireLocation->get()); 99 $answers = exec($FormulaireLocation->get());
92 break; 100 break;
93 case ZenitySetup::$menu_enregistrement_entrees[5]: // "Prestation non vendue" 101 case ZenitySetup::$menu_enregistrement['entrees'][5]: // "Prestation non vendue"
94 $Presta->setTypePresta('non_vendue'); 102 $Presta->setTypePresta('non_vendue');
95 break; 103 break;
96 default: // inutile normallement, cas déjà géré avant 104 default: // inutile normallement, cas déjà géré avant
@@ -98,7 +106,9 @@ function newService($Client): array // $Client est un Client ou null
98 return [0, null]; 106 return [0, null];
99 } 107 }
100 108
101 $Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre 109 //$Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre
110 //$Presta->makeCodePresta($Client->getCodeClient()); // d'un objet à l'autre
111 $Presta->setCodePresta(1); // d'un objet à l'autre
102 112
103 // commentaire - étape 3/3 113 // commentaire - étape 3/3
104 $comment = exec($CommentairePrestation->get()); 114 $comment = exec($CommentairePrestation->get());
@@ -120,48 +130,27 @@ function newService($Client): array // $Client est un Client ou null
120 //~ } 130 //~ }
121 $Presta->setCommentaires($comment); 131 $Presta->setCommentaires($comment);
122 132
123 // hydratation d'une facture à partir d'un devis
124 if($choix_niv2 === ZenitySetup::$menu_enregistrement_entrees[2]) // cas: facture à partir d'un devis
125 {
126 // devis retrouvé ($Quotation est déjà hydraté)
127 $QuotationDetails->setIdPresta($Quotation->getId());
128 $QuotationDetails->hydrate($QuotationDetails->getDetailsByIdPresta());
129
130 // facture avec le devis
131 $QuotationDetails->hydrateReceiptWithQuotation($PrestaDetails);
132 }
133
134 // hydratation avec la saisie du formulaire 133 // hydratation avec la saisie du formulaire
135 if($choix_niv2 != ZenitySetup::$menu_enregistrement_entrees[5]) // cas: tous les cas sauf presta non vendue 134 if($choix_niv2 != ZenitySetup::$menu_enregistrement['entrees'][5]) // cas: tous les cas sauf presta non vendue
136 { 135 {
136 //var_dump($answers);
137 $Client->typeToClient();
137 if($answers == '') // annulation 138 if($answers == '') // annulation
138 { 139 {
139 echo "debug: annulation lors de l'enregistrement des détails de la prestation\n"; 140 echo "debug: annulation lors de l'enregistrement des détails de la prestation\n";
140 return [0, null]; 141 return [0, null];
141 } 142 }
142 elseif(isset($PrestaDetails) && !$PrestaDetails->hydrateFromForm($answers, $Presta)) // echec de l'hydratation 143 $PrestaDetails->hydrate($answers);
143 { 144
144 echo "debug: erreur de hydrateFromForm()\n"; // messages d'erreur à mettre ici ou dans hydrateFromForm()? 145 // déléguer la synchronisation (flush) avec la BDD à une classe "Manager"
145 return [0, null];
146 }
147 }
148
149 // mise à jour base de données
150 $Presta->create();
151 $Presta->setId(); // sans paramètre, exécute un $this->db->lastInsertId()
152
153 if(isset($PrestaDetails)) // presta vendue
154 {
155 $PrestaDetails->setIdPresta($Presta->getId()); // d'un objet à l'autre
156 $PrestaDetails->create();
157 $PrestaDetails->setId(); // sans paramètre, exécute un $this->db->lastInsertId()
158 } 146 }
159 147
160 // si encore de type prospect, devient un type client 148 // si encore de type prospect, devient un type client
161 if($Client->typeToClient()) // utile si $Client est renvoyé dans le "return" 149 // déjà fait ailleurs je crois!
150 /*if($Client->typeToClient()) // utile si $Client est renvoyé dans le "return"
162 { 151 {
163 $Client->updateOneValue('type', 'client'); // base synchronisée 152 $Client->updateOneValue('type', 'client'); // base synchronisée
164 } 153 }*/
165 154
166 155
167 // -- partie 3: LaTeX -- 156 // -- partie 3: LaTeX --
@@ -213,7 +202,11 @@ function newService($Client): array // $Client est un Client ou null
213 { 202 {
214 return [3, $Client]; // section 3: modifyData() 203 return [3, $Client]; // section 3: modifyData()
215 } 204 }
216 elseif($choix_niv2 === ZenitySetup::$fin_section_2['entrees'][2]) // enregistrer une autre prestation 205 elseif($choix_niv2 === ZenitySetup::$fin_section_2['entrees'][2]) // enregistrer une autre prestation (même client)
206 {
207 return [2, $Client]; // relancer section 2: newService()
208 }
209 elseif($choix_niv2 === ZenitySetup::$fin_section_2['entrees'][3]) // enregistrer une autre prestation (autre client)
217 { 210 {
218 return [2, null]; // relancer section 2: newService() 211 return [2, null]; // relancer section 2: newService()
219 } 212 }
diff --git a/src/sections/3-1_windows.php b/src/sections/3-1_windows.php
index 31c6cee..76d01dd 100644
--- a/src/sections/3-1_windows.php
+++ b/src/sections/3-1_windows.php
@@ -1,9 +1,9 @@
1<?php 1<?php
2// src/sections/3-1_windows.php 2// src/sections/3-1_windows.php
3// 3//
4// fonctions pour 3_modify_data.php 4// fonctions pour src/sections/3_modify_data.php
5 5
6function makeModifyCustomerWindow(Clients $Customer): ZenityList 6function makeModifyCustomerWindow(Client $Customer): ZenityList
7{ 7{
8 // fenêtre 8 // fenêtre
9 $ModifyCustomer = new ZenityList(ZenitySetup::$modification_client['text'], []); 9 $ModifyCustomer = new ZenityList(ZenitySetup::$modification_client['text'], []);
@@ -27,7 +27,7 @@ function makeModifyCustomerWindow(Clients $Customer): ZenityList
27 return $ModifyCustomer; 27 return $ModifyCustomer;
28} 28}
29 29
30function makeModifyServiceWindow(Prestations $Service, $ServiceDetails = null): ZenityList 30function makeModifyServiceWindow(Prestation $Service, $ServiceDetails = null): 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'], []);
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 @@
5 5
6require('3-1_windows.php'); 6require('3-1_windows.php');
7 7
8use Doctrine\ORM\EntityManager;
9
8function modifyData($Client): array 10function modifyData($Client): array
9{ 11{
10 // fenêtres fixes 12 // -- partie 1: rechercher un client --
13
14 // fenêtres statiques
15 // recherche d'un client
16 $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client['text']);
17 $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client['text'], []);
18 // modification de données
11 $TypeDeClient = new ZenityList(ZenitySetup::$type_client['text'], ZenitySetup::$type_client['entrees']); 19 $TypeDeClient = new ZenityList(ZenitySetup::$type_client['text'], ZenitySetup::$type_client['entrees']);
12 $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section3']); 20 $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section3']);
13 21
14 22 if($Client == null || get_class($Client) !== 'Client') // étape sautable
15 // -- partie 1: rechercher un client --
16 if($Client == null || get_class($Client) !== 'Clients') // étape sautable
17 { 23 {
18 $Client = makeObjectClient(); // = 0 ou type "Clients" 24 $Client = Client::getObject($RechercheClient, $ResultatsRechercheClient); // = 0 ou type "Client"
19 if(!is_object($Client) || !get_class($Client) == 'Clients') 25 //$ResultatsRechercheClient->cleanCommand(); // inutile parce qu'on ne boucle pas dans cette fonction
26 //if(!is_object($Client) || !get_class($Client) == 'Client')
27 if($Client === 0)
20 { 28 {
21 echo "debug: annulation sélection client\n"; 29 echo "debug: annulation sélection client\n";
22 return [0, null]; // menu principal 30 return [0, null]; // menu principal
@@ -26,7 +34,7 @@ function modifyData($Client): array
26 34
27 // -- partie 2: modifier un client -- 35 // -- partie 2: modifier un client --
28 36
29 // fenêtre 37 // fenêtre dynamique
30 $ModificationClientMenu = makeModifyCustomerWindow($Client); 38 $ModificationClientMenu = makeModifyCustomerWindow($Client);
31 39
32 $choix_niv2 = exec($ModificationClientMenu->get()); 40 $choix_niv2 = exec($ModificationClientMenu->get());
@@ -53,20 +61,22 @@ function modifyData($Client): array
53 { 61 {
54 echo "choix: annulation\n"; 62 echo "choix: annulation\n";
55 } 63 }
56 $Client->update(); 64 Client::$entityManager->flush(); // à mettre dans une classe Manager
65
57 return [3, $Client]; // menu précédent 66 return [3, $Client]; // menu précédent
58 } 67 }
59 elseif(is_string($choix_niv2) && $choix_niv2 != '') // autres choix, modifier une valeur 68 elseif(is_string($choix_niv2) && $choix_niv2 != '') // modifier autre chose chez le client
60 { 69 {
61 echo "choix: modifier" . $choix_niv2 . "\n"; 70 echo "choix: modifier " . $choix_niv2 . "\n";
62 $ModificationClient = new ZenityEntry($choix_niv2); 71 $ModificationClient = new ZenityEntry($choix_niv2);
63 $input = exec($ModificationClient->get()); 72 $input = exec($ModificationClient->get());
64 if(is_string($input) && $input != '') 73 if(is_string($input) && $input != '')
65 { 74 {
75 // entités et BDD
66 $Client->set($choix_niv2, $input); 76 $Client->set($choix_niv2, $input);
67 $Client->update(); 77 $Client::$entityManager->flush();
68 78
69 // mettre à jour les documents (il faudrait modifier tous les documents!!) 79 // documents (les factures, etc, ne sont pas modifiées ici)
70 $EnveloppeRecto = Latex::makeInstance('enveloppe_recto'); 80 $EnveloppeRecto = Latex::makeInstance('enveloppe_recto');
71 $EnveloppeRecto->setData($Client); 81 $EnveloppeRecto->setData($Client);
72 $EnveloppeRecto->makeLatex(); 82 $EnveloppeRecto->makeLatex();
@@ -86,36 +96,35 @@ function modifyData($Client): array
86 96
87 97
88 // -- partie 3: rechercher une prestation -- 98 // -- partie 3: rechercher une prestation --
89 $Presta = getServices($Client); // = 0 ou type "Prestations" 99 $Presta = Prestation::getServices($Client); // = 0 ou type "Prestation"
90 if(!is_object($Presta) || !get_class($Presta) == 'Prestations') 100 if(!is_object($Presta) || !get_class($Presta) == 'Prestation')
91 { 101 {
92 echo "debug: annulation sélection client\n"; 102 echo "debug: annulation sélection d'une prestation\n";
93 return [3, $Client]; // menu précédent 103 return [3, $Client]; // menu précédent
94 } 104 }
95 105 $type_presta = $Presta->getTypePresta();
96 $type = $Presta->getTypePresta(); 106 switch($type_presta)
97 switch($type)
98 { 107 {
99 case 'facture': 108 case 'facture':
100 $PrestaDetails = new DevisFactures('factures'); 109 $classe = 'Facture';
101 break; 110 break;
102 case 'devis': 111 case 'devis':
103 $PrestaDetails = new DevisFactures('devis'); 112 $classe = 'Devis';
104 break; 113 break;
105 case 'cesu': 114 case 'cesu':
106 $PrestaDetails = new CESU(); 115 $classe = 'CESU';
107 break; 116 break;
108 case 'location': 117 case 'location':
109 $PrestaDetails = new Locations(); 118 $classe = 'Location';
110 break; 119 break;
111 case 'non_vendue': 120 case 'non_vendue':
112 $PrestaDetails = null; 121 $PrestaDetails = null;
113 break; 122 break;
114 } 123 }
115 if($type != 'non_vendue') 124 if($type_presta != 'non_vendue')
116 { 125 {
117 $PrestaDetails->setIdPresta($Presta->getId()); 126 $repository = $classe::$entityManager->getRepository($classe);
118 $PrestaDetails->hydrate($PrestaDetails->getDetailsByIdPresta()); 127 $PrestaDetails = $repository->findOneBy(['presta' => $Presta->getId()]);
119 } 128 }
120 129
121 130
@@ -125,11 +134,7 @@ function modifyData($Client): array
125 $ModificationPrestaMenu = makeModifyServiceWindow($Presta, $PrestaDetails); 134 $ModificationPrestaMenu = makeModifyServiceWindow($Presta, $PrestaDetails);
126 135
127 $choix_niv3 = exec($ModificationPrestaMenu->get()); 136 $choix_niv3 = exec($ModificationPrestaMenu->get());
128 //~ if($choix_niv3 === ZenitySetup::$modification_presta['devis_facture']) // devis -> facture 137
129 //~ {
130 //~ echo "choix: changer un devis en facture\n";
131 //~ return [2, $Client]; // menu "client"
132 //~ }
133 if($choix_niv3 === 'Date:') 138 if($choix_niv3 === 'Date:')
134 { 139 {
135 $Date = new Dates(exec($Calendrier->get())); // exec() renvoie soit une chaîne soit un false 140 $Date = new Dates(exec($Calendrier->get())); // exec() renvoie soit une chaîne soit un false
@@ -139,50 +144,60 @@ function modifyData($Client): array
139 } 144 }
140 else 145 else
141 { 146 {
142 // mettre à jour la base de données 147 // entités et BDD
143 $Presta->setDate($Date->getTimestamp(), true); // un entier pour la BDD, "true" pour modifier le code_presta 148 $Presta->set($choix_niv3, $Date);
144 $Presta->update(); 149 $old_code = $Presta->getCodePresta();
150 $Presta->setCodePresta(0);
151 $Presta::$entityManager->flush();
145 152
146 // mettre à jour les documents 153 // documents
147 if($type === 'devis' || $type === 'facture' || $type === 'location') 154 if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location')
148 { 155 {
149 $DocumentPresta = Latex::makeInstance($Presta->getTypePresta()); // $type = facture, devis, location 156 $DocumentPresta = Latex::makeInstance($Presta->getTypePresta()); // $type = facture, devis, location
150 $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); 157 $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails);
151 $DocumentPresta->makeLatex(); 158 $DocumentPresta->makeLatex(); // en mémoire
152 makeTexAndPdf($DocumentPresta); 159
160 renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta());
161 makeTexAndPdf($DocumentPresta); // une nouvelle facture est créée, supprimer l'ancienne ou la renommer avec la nouvelle date
153 } 162 }
154 } 163 }
155 164
156 return [3, $Client]; // menu précédent 165 return [3, $Client]; // menu précédent
157 } 166 }
158 //~ elseif($choix_niv3 === 'Type de Presta:') // choix impossible pour le moment 167 //~ elseif($choix_niv3 === 'Type de Presta:') // compliqué! choix impossible pour le moment
159 //~ { 168 //~ {
160 //~ echo "choix: changer le type de prestation (devis, facture, etc)\n"; 169 //~ echo "choix: changer le type de prestation (devis, facture, etc)\n";
161 //~ return [3, $Client]; // menu "client" 170 //~ return [3, $Client]; // menu "client"
162 //~ } 171 //~ }
163 elseif(is_string($choix_niv3) && $choix_niv3 != '') // modifier une valeur 172 elseif(is_string($choix_niv3) && $choix_niv3 != '') // modifier une valeur
164 { 173 {
165 echo "choix: modifier" . $choix_niv3 . "\n"; 174 echo "choix: modifier " . $choix_niv3 . "\n";
166 $ModificationPrestaForm = new ZenityEntry($choix_niv3); 175 $ModificationPrestaForm = new ZenityEntry($choix_niv3);
167 $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 176 $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
168 if(is_string($input)) // chaine vide autorisée 177 if(is_string($input)) // chaîne vide autorisée
169 { 178 {
170 // mettre à jour la base de données 179 // enti©s et BDD
171 $Presta->set($choix_niv3, $input); 180 $Presta->set($choix_niv3, $input);
172 $Presta->update(); 181 $old_code = $Presta->getCodePresta();
173 182 $Presta->setCodePresta(0);
174 if($type != 'non_vendue') 183 if($type_presta != 'non_vendue')
175 { 184 {
176 $PrestaDetails->set($choix_niv3, $input); 185 $PrestaDetails->set($choix_niv3, $input);
177 $PrestaDetails->update(); 186 $PrestaDetails::$entityManager->flush();
187 }
188 else
189 {
190 $Presta::$entityManager->flush();
178 } 191 }
179 192
180 // mettre à jour les documents 193 // documents
181 if($type === 'devis' || $type === 'facture' || $type === 'location') 194 if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location')
182 { 195 {
183 $DocumentPresta = Latex::makeInstance($type); 196 $DocumentPresta = Latex::makeInstance($type_presta);
184 $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); 197 $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails);
185 $DocumentPresta->makeLatex(); 198 $DocumentPresta->makeLatex();
199
200 renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta());
186 makeTexAndPdf($DocumentPresta); 201 makeTexAndPdf($DocumentPresta);
187 } 202 }
188 } 203 }
diff --git a/src/sections/4_get_document.php b/src/sections/4_get_document.php
index baad117..e682d26 100644
--- a/src/sections/4_get_document.php
+++ b/src/sections/4_get_document.php
@@ -5,32 +5,32 @@
5 5
6function getOrPrintDocument(): array 6function getOrPrintDocument(): array
7{ 7{
8 $MenuDocuments = new ZenityList(ZenitySetup::$menu_documents_text, ZenitySetup::$menu_documents_entrees); 8 $MenuDocuments = new ZenityList(ZenitySetup::$menu_documents['text'], ZenitySetup::$menu_documents['entrees']);
9 9
10 // -- partie 1: type de document -- 10 // -- partie 1: type de document --
11 11
12 $choix_niv2 = exec($MenuDocuments->get()); 12 $choix_niv2 = exec($MenuDocuments->get());
13 if($choix_niv2 === ZenitySetup::$menu_documents_entrees[0]) 13 if($choix_niv2 === ZenitySetup::$menu_documents['entrees'][0])
14 { 14 {
15 15
16 } 16 }
17 elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[1]) // = Facture 17 elseif($choix_niv2 === ZenitySetup::$menu_documents['entrees'][1]) // = Facture, devis, etc
18 { 18 {
19 19
20 } 20 }
21 elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[2]) // = Lettre avec adresse 21 elseif($choix_niv2 === ZenitySetup::$menu_documents['entrees'][2]) // = Lettre avec adresse
22 { 22 {
23 23
24 } 24 }
25 elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[3]) // = Livre des recettes 25 elseif($choix_niv2 === ZenitySetup::$menu_documents['entrees'][3]) // = Livre des recettes
26 { 26 {
27 27
28 } 28 }
29 elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[4]) // = Registre des achats 29 elseif($choix_niv2 === ZenitySetup::$menu_documents['entrees'][4]) // = Registre des achats
30 { 30 {
31 31
32 } 32 }
33 elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[5]) // = Bilan annuel 33 elseif($choix_niv2 === ZenitySetup::$menu_documents['entrees'][5]) // = Bilan annuel
34 { 34 {
35 35
36 } 36 }