diff options
Diffstat (limited to 'src/sections/1_new_service.php')
-rw-r--r-- | src/sections/1_new_service.php | 209 |
1 files changed, 0 insertions, 209 deletions
diff --git a/src/sections/1_new_service.php b/src/sections/1_new_service.php deleted file mode 100644 index 6f5a72c..0000000 --- a/src/sections/1_new_service.php +++ /dev/null | |||
@@ -1,209 +0,0 @@ | |||
1 | <?php | ||
2 | // src/sections/1_new_service.php | ||
3 | // | ||
4 | // -- SECTION 1: Nouvelle prestation -- | ||
5 | |||
6 | function newService(): int // code de retour, si 0 retour menu principal, si 2 aller à la section 2, etc | ||
7 | { | ||
8 | // fenêtres | ||
9 | $MenuEnregistrement = new ZenityList(ZenitySetup::$menu_enregistrement_text, ZenitySetup::$menu_enregistrement_entrees); | ||
10 | $Calendrier = new ZenityCalendar(ZenitySetup::$calendar_text); | ||
11 | $FormulaireDevis = new ZenityForms(ZenitySetup::$formulaire_text, ZenitySetup::$formulaire_devis_entrees); | ||
12 | $FormulaireFacture = new ZenityForms(ZenitySetup::$formulaire_text, ZenitySetup::$formulaire_facture_entrees); | ||
13 | $FormulaireCesu = new ZenityForms(ZenitySetup::$formulaire_text, ZenitySetup::$formulaire_cesu_entrees); | ||
14 | $FormulaireLocation = new ZenityForms(ZenitySetup::$formulaire_text, ZenitySetup::$formulaire_location_entrees); | ||
15 | $CommentairePrestation = new ZenityEntry(ZenitySetup::$commentaire_prestation_text); | ||
16 | $Recapitulatif = new ZenityList(ZenitySetup::$recapitulatif_text, ZenitySetup::$recapitulatif_entrees); // tableau à multiples colonnes | ||
17 | $QuestionModifierPrestation = new ZenityQuestion(ZenitySetup::$question_modification_text); | ||
18 | |||
19 | |||
20 | // -- partie 1: le client -- | ||
21 | $Client = makeObjectCLient(); | ||
22 | if($Client === 0) | ||
23 | { | ||
24 | return 0; // menu principal | ||
25 | } | ||
26 | |||
27 | |||
28 | // -- partie 2: la prestation -- | ||
29 | |||
30 | // niveau 2: type comptable d'enregistrement: devis, facture, cesu, location ou pas de prestation | ||
31 | $choix_niv2 = exec($MenuEnregistrement->get()); | ||
32 | if($choix_niv2 === '') | ||
33 | { | ||
34 | echo "debug: annulation menu enregistrement\n"; | ||
35 | return 0; // menu principal | ||
36 | } | ||
37 | |||
38 | $Presta = new Prestations($Client->getID()); | ||
39 | |||
40 | // détail de la prestation | ||
41 | // calendrier - étape 1/3 | ||
42 | $Date = new Dates(exec($Calendrier->get())); // exec() renvoie soit une chaîne soit un false | ||
43 | if($Date->getDate() == '') // on n'a pas cliqué sur "annuler" | ||
44 | { | ||
45 | echo "debug: annulation à la saisie d'une date\n"; | ||
46 | return 0; // menu principal | ||
47 | } | ||
48 | |||
49 | $Presta->setDate($Date->getTimestamp()); // un entier pour la BDD | ||
50 | |||
51 | switch($choix_niv2) | ||
52 | { | ||
53 | // formulaire - étape 2/3 | ||
54 | //~ case ZenitySetup::$menu_enregistrement_entrees[0]: // "Devis" | ||
55 | //~ $PrestaDetails = new DevisFactures('devis'); | ||
56 | //~ $Presta->setTypePresta('devis'); | ||
57 | //~ $input = exec($FormulaireDevis->get()); | ||
58 | //~ break; | ||
59 | case ZenitySetup::$menu_enregistrement_entrees[0]: // "Facture" | ||
60 | $PrestaDetails = new DevisFactures('factures'); // 'factures' est le nom de la table, pas le type de presta | ||
61 | $Presta->setTypePresta('facture'); | ||
62 | $input =exec($FormulaireFacture->get()); | ||
63 | break; | ||
64 | case ZenitySetup::$menu_enregistrement_entrees[1]: // "CESU" | ||
65 | $PrestaDetails = new CESU(); | ||
66 | $Presta->setTypePresta('cesu'); | ||
67 | $input = exec($FormulaireCesu->get()); | ||
68 | break; | ||
69 | case ZenitySetup::$menu_enregistrement_entrees[2]: // "Location" | ||
70 | $PrestaDetails = new Locations(); | ||
71 | $Presta->setTypePresta('location'); | ||
72 | $input = exec($FormulaireLocation->get()); | ||
73 | break; | ||
74 | case ZenitySetup::$menu_enregistrement_entrees[3]: // "Prestation non vendue" | ||
75 | $Presta->setTypePresta('non_vendue'); | ||
76 | break; | ||
77 | default: // inutile normallement, cas déjà géré avant | ||
78 | echo "debug: sortie du menu enregistrement incorrect\n"; | ||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | $Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre | ||
83 | |||
84 | if($choix_niv2 != ZenitySetup::$menu_enregistrement_entrees[3]) // si presta non vendue, saut étape 3/3 | ||
85 | { | ||
86 | if($input == '') // annulation | ||
87 | { | ||
88 | echo "debug: annulation lors de l'enregistrement des détails de la prestation\n"; | ||
89 | return 0; | ||
90 | } | ||
91 | elseif(isset($PrestaDetails) && !$PrestaDetails->hydrateFromForm($input, $Presta)) // echec de l'hydratation | ||
92 | { | ||
93 | echo "debug: erreur de hydrateFromForm()\n"; // messages d'erreur à mettre ici ou dans hydrateFromForm()? | ||
94 | return 0; | ||
95 | } | ||
96 | unset($input); | ||
97 | } | ||
98 | |||
99 | // commentaire - étape 3/3 | ||
100 | $input = exec($CommentairePrestation->get()); | ||
101 | if($input == '') | ||
102 | { | ||
103 | echo "debug: pas de commentaire saisi\n"; | ||
104 | // on n'interrompt pas le script et on enregistre dans tous les cas (annulatation, chaîne vide) | ||
105 | } | ||
106 | // Cliquer sur annuler (ou appuyer sur échap) revient dont à valider avec une chaîne vide et enregistrer la prestation | ||
107 | // la commande 'echo $?' ($? est le code de sortie de la commande précédente) renvoit 1 si on annule avec la touche échap () | ||
108 | // 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) | ||
109 | // 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 | ||
110 | // solution partielle si echo $? ne renvoit rien, c'est qu'echo n'a pas été exécuté parce qu'on a appuyé sur échap (ou que le programme) | ||
111 | // 2>&1 semble inutile, pas de sortie d'erreur de zenity --entry | ||
112 | //~ if(exec('echo $?') != 1) | ||
113 | //~ { | ||
114 | //~ echo "debug: annulation à la saisie d'un commentaire\n"; | ||
115 | //~ return 0; | ||
116 | //~ } | ||
117 | $Presta->setCommentaires($input); | ||
118 | unset($input); | ||
119 | |||
120 | $Presta->create(); | ||
121 | $Presta->setID(); // sans paramètre, exécute un $this->db->lastInsertId() | ||
122 | |||
123 | if(isset($PrestaDetails)) // presta non vendue | ||
124 | { | ||
125 | $PrestaDetails->setIDPresta($Presta->getID()); // d'un objet à l'autre | ||
126 | $PrestaDetails->create(); | ||
127 | $PrestaDetails->setID(); // sans paramètre, exécute un $this->db->lastInsertId() | ||
128 | } | ||
129 | |||
130 | |||
131 | // -- partie 3: LaTeX -- | ||
132 | |||
133 | //makeLatexAndPdfDocuments($Client, $Presta, $PrestaDetails); | ||
134 | // factoriser tout ça | ||
135 | /* plusieurs parties: | ||
136 | * - une fonction ou on crée et manipule les objets (une classe par type de document) | ||
137 | * - manipulation des données | ||
138 | * - chemins et noms de fichiers | ||
139 | * - insertion des variables | ||
140 | * - écriture du fichier (+ dossier si nécessaire) | ||
141 | */ | ||
142 | // et pour bien faire ajouter aussi une interface | ||
143 | |||
144 | // fabrique d'objets (sans connaître les noms des classes) | ||
145 | $EnveloppeRecto = Latex::makeLatexSubClass('enveloppe_recto'); | ||
146 | $EnveloppeVerso = Latex::makeLatexSubClass('enveloppe_verso'); | ||
147 | $DocumentPresta = Latex::makeLatexSubClass($Presta->getTypePresta()); // $type = facture, devis, location | ||
148 | |||
149 | // génération du latex | ||
150 | $EnveloppeRecto->setData($Client); | ||
151 | $EnveloppeRecto->setFileName($Client->getCodeClient() . '.tex'); | ||
152 | $EnveloppeRecto->setLatexPath(Config::$latex_path . 'enveloppes_recto/'); | ||
153 | $EnveloppeRecto->setPdfPath(Config::$pdf_path . 'enveloppes_recto/'); | ||
154 | $EnveloppeRecto->spacesInPostCode(); | ||
155 | $EnveloppeRecto->makeLatex(); | ||
156 | |||
157 | $EnveloppeVerso->setFileName('enveloppe_verso.tex'); | ||
158 | $EnveloppeVerso->setLatexPath(Config::$latex_path); | ||
159 | $EnveloppeVerso->setPdfPath(Config::$pdf_path); | ||
160 | $EnveloppeVerso->makeLatex(); | ||
161 | |||
162 | $DocumentPresta->setData($Client); | ||
163 | $DocumentPresta->setData($Presta); | ||
164 | $DocumentPresta->setData($PrestaDetails); | ||
165 | $DocumentPresta->makeDateInstance($Presta->getDate()); // paramètre = int | ||
166 | $DocumentPresta->setFileName($Presta->getCodePresta() . '.tex'); | ||
167 | $DocumentPresta->setLatexPath(Config::$latex_path . $DocumentPresta->getYear() . '/'); | ||
168 | $DocumentPresta->setPdfPath(Config::$pdf_path . $DocumentPresta->getYear() . '/'); | ||
169 | $DocumentPresta->makeLatex(); | ||
170 | |||
171 | // création des fichiers | ||
172 | makeFolder($EnveloppeRecto->getLatexPath()); | ||
173 | makeFolder($EnveloppeRecto->getPdfPath()); | ||
174 | makeFile($EnveloppeRecto->getLatexPath(), $EnveloppeRecto->getFileName(), $EnveloppeRecto->getLatex()); | ||
175 | latexToPdf($EnveloppeRecto->getLatexPath(), $EnveloppeRecto->getFileName(), $EnveloppeRecto->getPdfPath()); | ||
176 | |||
177 | makeFile($EnveloppeVerso->getLatexPath(), $EnveloppeVerso->getFileName(), $EnveloppeVerso->getLatex()); | ||
178 | latexToPdf($EnveloppeVerso->getLatexPath(), $EnveloppeVerso->getFileName(), $EnveloppeVerso->getPdfPath()); | ||
179 | |||
180 | makeFolder($DocumentPresta->getLatexPath()); | ||
181 | makeFolder($DocumentPresta->getPdfPath()); | ||
182 | makeFile($DocumentPresta->getLatexPath(), $DocumentPresta->getFileName(), $DocumentPresta->getLatex()); | ||
183 | latexToPdf($DocumentPresta->getLatexPath(), $DocumentPresta->getFileName(), $DocumentPresta->getPdfPath()); | ||
184 | |||
185 | |||
186 | // -- partie 4: récapitulatif -- | ||
187 | |||
188 | // tableau récaptilatif | ||
189 | // ZenityList | ||
190 | |||
191 | // imprimer? | ||
192 | //~ $imprimer_facture = exec('zenity --question --width=250 --title="Base de données mise à jour" --text="Imprimer la facture?"'); | ||
193 | //~ $imprimer_enveloppe = exec('zenity --question --width=250 --title="Base de données mise à jour" --text="Imprimer l\'adresse sur une enveloppe? (insérer une enveloppe DL sans fenêtre dans l\'imprimante"'); | ||
194 | |||
195 | |||
196 | // -- partie 5: on fait quoi maintenant -- | ||
197 | |||
198 | // possibilité de modification | ||
199 | // zenityQuestion | ||
200 | //~ if(exec($QuestionModifierPrestation->get()) == '0') | ||
201 | //~ { | ||
202 | //~ return 3; // section "Modifier un enregistrement" | ||
203 | //~ } | ||
204 | //~ else | ||
205 | //~ { | ||
206 | //~ return 0; // menu principal | ||
207 | //~ } | ||
208 | return 0; // menu principal | ||
209 | } | ||