diff options
author | polo <ordipolo@gmx.fr> | 2023-06-22 15:22:23 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2023-06-22 15:22:23 +0200 |
commit | 22b941b3526dd3aaf6976eb4ed30aa2ecc30f921 (patch) | |
tree | f345f53c2f4c0ecdeabf9b2d1aac280a4b708a56 /src/sections | |
parent | ee372629d665ea0b77889e3cc6e9b1738310a68e (diff) | |
download | AppliGestionPHP-22b941b3526dd3aaf6976eb4ed30aa2ecc30f921.zip |
factorisation 1_new_service.php vers functions.php
Diffstat (limited to 'src/sections')
-rw-r--r-- | src/sections/1_new_service.php | 153 | ||||
-rw-r--r-- | src/sections/2_quotations.php | 9 | ||||
-rw-r--r-- | src/sections/3_modify_service.php (renamed from src/sections/2_modify_service.php) | 4 |
3 files changed, 42 insertions, 124 deletions
diff --git a/src/sections/1_new_service.php b/src/sections/1_new_service.php index ae2d2ef..f9105b7 100644 --- a/src/sections/1_new_service.php +++ b/src/sections/1_new_service.php | |||
@@ -1,15 +1,11 @@ | |||
1 | <?php | 1 | <?php |
2 | // sections/1_new_service.php | 2 | // src/sections/1_new_service.php |
3 | // | 3 | // |
4 | // -- SECTION 1: Nouvelle prestation -- | 4 | // -- SECTION 1: Nouvelle prestation -- |
5 | 5 | ||
6 | function newService(): int // code de retour, si 0 retour menu principal, si 2 aller à la section 2, etc | 6 | function newService(): int // code de retour, si 0 retour menu principal, si 2 aller à la section 2, etc |
7 | { | 7 | { |
8 | // fenêtres | 8 | // fenêtres |
9 | $QuestionNouveauClient = new ZenityQuestion(ZenitySetup::$question_nouveau_client_text); | ||
10 | $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client_text); | ||
11 | $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client_text, []); | ||
12 | $NouveauClient = new ZenityForms(ZenitySetup::$nouveau_client_text, ZenitySetup::$nouveau_client_entrees); | ||
13 | $MenuEnregistrement = new ZenityList(ZenitySetup::$menu_enregistrement_text, ZenitySetup::$menu_enregistrement_entrees); | 9 | $MenuEnregistrement = new ZenityList(ZenitySetup::$menu_enregistrement_text, ZenitySetup::$menu_enregistrement_entrees); |
14 | $Calendrier = new ZenityCalendar(ZenitySetup::$calendar_text); | 10 | $Calendrier = new ZenityCalendar(ZenitySetup::$calendar_text); |
15 | $FormulaireDevis = new ZenityForms(ZenitySetup::$formulaire_text, ZenitySetup::$formulaire_devis_entrees); | 11 | $FormulaireDevis = new ZenityForms(ZenitySetup::$formulaire_text, ZenitySetup::$formulaire_devis_entrees); |
@@ -20,63 +16,12 @@ function newService(): int // code de retour, si 0 retour menu principal, si 2 a | |||
20 | $Recapitulatif = new ZenityList(ZenitySetup::$recapitulatif_text, ZenitySetup::$recapitulatif_entrees); // tableau à multiples colonnes | 16 | $Recapitulatif = new ZenityList(ZenitySetup::$recapitulatif_text, ZenitySetup::$recapitulatif_entrees); // tableau à multiples colonnes |
21 | $QuestionModifierPrestation = new ZenityQuestion(ZenitySetup::$question_modification_text); | 17 | $QuestionModifierPrestation = new ZenityQuestion(ZenitySetup::$question_modification_text); |
22 | 18 | ||
23 | $Client = new Clients; | ||
24 | |||
25 | 19 | ||
26 | // -- partie 1: le client -- | 20 | // -- partie 1: le client -- |
27 | 21 | $Client = makeObjectCLient(); | |
28 | // est ce que le client est déjà dans la base? | 22 | if($Client === 0) |
29 | $client_inconnu = true; | ||
30 | if(exec($QuestionNouveauClient->get()) == '0') // $? = 0 signifie oui, double égal == pour le transtypage | ||
31 | { | 23 | { |
32 | echo "choix: recherche d'une client\n"; | 24 | return 0; // menu principal |
33 | $input = exec($RechercheClient->get()); | ||
34 | if($input == '') | ||
35 | { | ||
36 | echo "debug: recherche annulée ou saisie vide\n"; | ||
37 | return(0); | ||
38 | } | ||
39 | |||
40 | echo "debug: recherche effectuée\n"; | ||
41 | $ResultatsRechercheClient->setListRows(rechercheClient($input, $Client), $Client->getTable()); // recherche silencieuse | ||
42 | unset($input); | ||
43 | |||
44 | // niveau 4: sélection parmi les résultats | ||
45 | $choix_niv4 = exec($ResultatsRechercheClient->get()); // renvoie l'ID de la table 'clients' | ||
46 | $ResultatsRechercheClient->cleanCommand(); | ||
47 | |||
48 | if($choix_niv4 == '') | ||
49 | { | ||
50 | echo "debug: client pas trouvé ou pas sélectionné\n"; | ||
51 | return(0); | ||
52 | } | ||
53 | |||
54 | echo "debug: client sélectionné\n"; | ||
55 | $Client->hydrate($Client->findById($choix_niv4)); | ||
56 | $client_inconnu = false; | ||
57 | } | ||
58 | else | ||
59 | { | ||
60 | echo "choix: nouveau client\n"; | ||
61 | } | ||
62 | |||
63 | // on n'a pas cherché OU on n'a pas trouvé | ||
64 | if($client_inconnu) | ||
65 | { | ||
66 | $input = exec($NouveauClient->get()); | ||
67 | if($input == '') | ||
68 | { | ||
69 | echo "debug: annulation lors de l'enregistrement d'un nouveau client\n"; | ||
70 | return(0); | ||
71 | } | ||
72 | if(!$Client->hydrateFromForm($input)) | ||
73 | { | ||
74 | // messages d'erreur dans hydrateFromForm() | ||
75 | return(0); | ||
76 | } | ||
77 | unset($input); | ||
78 | $Client->create(); | ||
79 | $Client->setID(); // sans paramètre, exécute un $this->db->lastInsertId() | ||
80 | } | 25 | } |
81 | 26 | ||
82 | 27 | ||
@@ -87,7 +32,7 @@ function newService(): int // code de retour, si 0 retour menu principal, si 2 a | |||
87 | if($choix_niv2 === '') | 32 | if($choix_niv2 === '') |
88 | { | 33 | { |
89 | echo "debug: annulation menu enregistrement\n"; | 34 | echo "debug: annulation menu enregistrement\n"; |
90 | return(0); // menu principal | 35 | return 0; // menu principal |
91 | } | 36 | } |
92 | 37 | ||
93 | $Presta = new Prestations($Client->getID()); | 38 | $Presta = new Prestations($Client->getID()); |
@@ -98,7 +43,7 @@ function newService(): int // code de retour, si 0 retour menu principal, si 2 a | |||
98 | if($Date->getDate() == '') // on n'a pas cliqué sur "annuler" | 43 | if($Date->getDate() == '') // on n'a pas cliqué sur "annuler" |
99 | { | 44 | { |
100 | echo "debug: annulation à la saisie d'une date\n"; | 45 | echo "debug: annulation à la saisie d'une date\n"; |
101 | return(0); // menu principal | 46 | return 0; // menu principal |
102 | } | 47 | } |
103 | 48 | ||
104 | $Presta->setDate($Date->getTimestamp()); // un entier pour la BDD | 49 | $Presta->setDate($Date->getTimestamp()); // un entier pour la BDD |
@@ -106,47 +51,47 @@ function newService(): int // code de retour, si 0 retour menu principal, si 2 a | |||
106 | switch($choix_niv2) | 51 | switch($choix_niv2) |
107 | { | 52 | { |
108 | // formulaire - étape 2/3 | 53 | // formulaire - étape 2/3 |
109 | case ZenitySetup::$menu_enregistrement_entrees[0]: // "Devis" | 54 | //~ case ZenitySetup::$menu_enregistrement_entrees[0]: // "Devis" |
110 | $Details = new DevisFactures('devis'); | 55 | //~ $PrestaDetails = new DevisFactures('devis'); |
111 | $Presta->setTypePresta('devis'); | 56 | //~ $Presta->setTypePresta('devis'); |
112 | $input = exec($FormulaireDevis->get()); | 57 | //~ $input = exec($FormulaireDevis->get()); |
113 | break; | 58 | //~ break; |
114 | case ZenitySetup::$menu_enregistrement_entrees[1]: // "Facture" | 59 | case ZenitySetup::$menu_enregistrement_entrees[0]: // "Facture" |
115 | $Details = new DevisFactures('factures'); // 'factures' est le nom de la table, pas le type de presta | 60 | $PrestaDetails = new DevisFactures('factures'); // 'factures' est le nom de la table, pas le type de presta |
116 | $Presta->setTypePresta('facture'); | 61 | $Presta->setTypePresta('facture'); |
117 | $input =exec($FormulaireFacture->get()); | 62 | $input =exec($FormulaireFacture->get()); |
118 | break; | 63 | break; |
119 | case ZenitySetup::$menu_enregistrement_entrees[2]: // "CESU" | 64 | case ZenitySetup::$menu_enregistrement_entrees[1]: // "CESU" |
120 | $Details = new CESU(); | 65 | $PrestaDetails = new CESU(); |
121 | $Presta->setTypePresta('cesu'); | 66 | $Presta->setTypePresta('cesu'); |
122 | $input = exec($FormulaireCesu->get()); | 67 | $input = exec($FormulaireCesu->get()); |
123 | break; | 68 | break; |
124 | case ZenitySetup::$menu_enregistrement_entrees[3]: // "Location" | 69 | case ZenitySetup::$menu_enregistrement_entrees[2]: // "Location" |
125 | $Details = new Locations(); | 70 | $PrestaDetails = new Locations(); |
126 | $Presta->setTypePresta('location'); | 71 | $Presta->setTypePresta('location'); |
127 | $input = exec($FormulaireLocation->get()); | 72 | $input = exec($FormulaireLocation->get()); |
128 | break; | 73 | break; |
129 | case ZenitySetup::$menu_enregistrement_entrees[4]: // "Prestation non vendue" | 74 | case ZenitySetup::$menu_enregistrement_entrees[3]: // "Prestation non vendue" |
130 | $Presta->setTypePresta('non_vendue'); | 75 | $Presta->setTypePresta('non_vendue'); |
131 | break; | 76 | break; |
132 | default: // inutile normallement, cas déjà géré avant | 77 | default: // inutile normallement, cas déjà géré avant |
133 | echo "debug: sortie du menu enregistrement incorrect\n"; | 78 | echo "debug: sortie du menu enregistrement incorrect\n"; |
134 | return(0); | 79 | return 0; |
135 | } | 80 | } |
136 | 81 | ||
137 | $Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre | 82 | $Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre |
138 | 83 | ||
139 | if($choix_niv2 != ZenitySetup::$menu_enregistrement_entrees[4]) // si presta non vendue, saut étape 3/3 | 84 | if($choix_niv2 != ZenitySetup::$menu_enregistrement_entrees[3]) // si presta non vendue, saut étape 3/3 |
140 | { | 85 | { |
141 | if($input == '') // annulation | 86 | if($input == '') // annulation |
142 | { | 87 | { |
143 | echo "debug: annulation lors de l'enregistrement des détails de la prestation\n"; | 88 | echo "debug: annulation lors de l'enregistrement des détails de la prestation\n"; |
144 | return(0); | 89 | return 0; |
145 | } | 90 | } |
146 | elseif(isset($Details) && !$Details->hydrateFromForm($input, $Presta)) // echec de l'hydratation | 91 | elseif(isset($PrestaDetails) && !$PrestaDetails->hydrateFromForm($input, $Presta)) // echec de l'hydratation |
147 | { | 92 | { |
148 | echo "debug: erreur de hydrateFromForm()\n"; // messages d'erreur à mettre ici ou dans hydrateFromForm()? | 93 | echo "debug: erreur de hydrateFromForm()\n"; // messages d'erreur à mettre ici ou dans hydrateFromForm()? |
149 | return(0); | 94 | return 0; |
150 | } | 95 | } |
151 | unset($input); | 96 | unset($input); |
152 | } | 97 | } |
@@ -167,7 +112,7 @@ function newService(): int // code de retour, si 0 retour menu principal, si 2 a | |||
167 | //~ if(exec('echo $?') != 1) | 112 | //~ if(exec('echo $?') != 1) |
168 | //~ { | 113 | //~ { |
169 | //~ echo "debug: annulation à la saisie d'un commentaire\n"; | 114 | //~ echo "debug: annulation à la saisie d'un commentaire\n"; |
170 | //~ return(0); | 115 | //~ return 0; |
171 | //~ } | 116 | //~ } |
172 | $Presta->setCommentaires($input); | 117 | $Presta->setCommentaires($input); |
173 | unset($input); | 118 | unset($input); |
@@ -175,53 +120,17 @@ function newService(): int // code de retour, si 0 retour menu principal, si 2 a | |||
175 | $Presta->create(); | 120 | $Presta->create(); |
176 | $Presta->setID(); // sans paramètre, exécute un $this->db->lastInsertId() | 121 | $Presta->setID(); // sans paramètre, exécute un $this->db->lastInsertId() |
177 | 122 | ||
178 | if(isset($Details)) // presta non vendue | 123 | if(isset($PrestaDetails)) // presta non vendue |
179 | { | 124 | { |
180 | $Details->setIDPresta($Presta->getID()); // d'un objet à l'autre | 125 | $PrestaDetails->setIDPresta($Presta->getID()); // d'un objet à l'autre |
181 | $Details->create(); | 126 | $PrestaDetails->create(); |
182 | $Details->setID(); // sans paramètre, exécute un $this->db->lastInsertId() | 127 | $PrestaDetails->setID(); // sans paramètre, exécute un $this->db->lastInsertId() |
183 | } | 128 | } |
184 | 129 | ||
185 | 130 | ||
186 | // -- partie 3: LaTeX -- | 131 | // -- partie 3: LaTeX -- |
187 | 132 | ||
188 | // document de la prestation | 133 | makeLatexAndPdfDocument($Client, $Presta, $PrestaDetails); |
189 | switch($choix_niv2) | ||
190 | { | ||
191 | case ZenitySetup::$menu_enregistrement_entrees[0]: // "Devis" | ||
192 | $type = 'devis'; | ||
193 | makeLatexAndPdfDocument($type, $Client, $Presta, $Details); | ||
194 | break; | ||
195 | case ZenitySetup::$menu_enregistrement_entrees[1]: // "Facture" | ||
196 | $type = 'facture'; | ||
197 | makeLatexAndPdfDocument($type, $Client, $Presta, $Details); | ||
198 | break; | ||
199 | case ZenitySetup::$menu_enregistrement_entrees[2]: // "CESU" | ||
200 | // pas de facture | ||
201 | break; | ||
202 | case ZenitySetup::$menu_enregistrement_entrees[3]: // "Location" | ||
203 | $type = 'location'; | ||
204 | makeLatexAndPdfDocument($type, $Client, $Presta, $Details); | ||
205 | break; | ||
206 | case ZenitySetup::$menu_enregistrement_entrees[4]: // "Prestation non vendue" | ||
207 | // pas de facture | ||
208 | break; | ||
209 | default: // inutile normallement, cas déjà géré avant | ||
210 | echo "debug: sortie du menu enregistrement incorrect\n"; | ||
211 | return(0); | ||
212 | } | ||
213 | |||
214 | // enveloppe recto | ||
215 | $type = 'enveloppe_recto'; | ||
216 | makeLatexAndPdfDocument($type, $Client); | ||
217 | |||
218 | // le verso ne dépend pas du client mais de l'entreprise, dans la classe Config | ||
219 | if(!file_exists(Config::$pdf_path . 'enveloppe_verso.pdf')) | ||
220 | { | ||
221 | $type = 'enveloppe_verso'; | ||
222 | makeLatexAndPdfDocument($type); | ||
223 | } | ||
224 | |||
225 | 134 | ||
226 | // -- partie 4: récapitulatif -- | 135 | // -- partie 4: récapitulatif -- |
227 | 136 | ||
@@ -237,10 +146,10 @@ function newService(): int // code de retour, si 0 retour menu principal, si 2 a | |||
237 | // zenityQuestion | 146 | // zenityQuestion |
238 | if(exec($QuestionModifierPrestation->get()) == '0') | 147 | if(exec($QuestionModifierPrestation->get()) == '0') |
239 | { | 148 | { |
240 | return(2); // section 2 | 149 | return 3; // section "Modifier un enregistrement" |
241 | } | 150 | } |
242 | else | 151 | else |
243 | { | 152 | { |
244 | return(0); // menu principal | 153 | return 0; // menu principal |
245 | } | 154 | } |
246 | } | 155 | } |
diff --git a/src/sections/2_quotations.php b/src/sections/2_quotations.php new file mode 100644 index 0000000..76b66fd --- /dev/null +++ b/src/sections/2_quotations.php | |||
@@ -0,0 +1,9 @@ | |||
1 | <?php | ||
2 | // src/sections/2_quotations.php | ||
3 | // | ||
4 | // -- SECTION 2: Devis -- | ||
5 | |||
6 | function quotation(): int // code de retour, si 2 aller à la section 2, etc | ||
7 | { | ||
8 | return(0); // menu principal | ||
9 | } | ||
diff --git a/src/sections/2_modify_service.php b/src/sections/3_modify_service.php index 72e2605..3147969 100644 --- a/src/sections/2_modify_service.php +++ b/src/sections/3_modify_service.php | |||
@@ -1,7 +1,7 @@ | |||
1 | <?php | 1 | <?php |
2 | // sections/2_modify_service.php | 2 | // src/sections/3_modify_service.php |
3 | // | 3 | // |
4 | // -- SECTION 2: Modifier une prestation -- | 4 | // -- SECTION 3: Modifier une prestation -- |
5 | 5 | ||
6 | function modifyService(): int // code de retour, si 2 aller à la section 2, etc | 6 | function modifyService(): int // code de retour, si 2 aller à la section 2, etc |
7 | { | 7 | { |