diff options
Diffstat (limited to 'src/sections/3_modify_data.php')
-rw-r--r-- | src/sections/3_modify_data.php | 113 |
1 files changed, 64 insertions, 49 deletions
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 | ||
6 | require('3-1_windows.php'); | 6 | require('3-1_windows.php'); |
7 | 7 | ||
8 | use Doctrine\ORM\EntityManager; | ||
9 | |||
8 | function modifyData($Client): array | 10 | function 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 | // entité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 | } |