diff options
Diffstat (limited to 'src/functions.php')
-rw-r--r-- | src/functions.php | 199 |
1 files changed, 75 insertions, 124 deletions
diff --git a/src/functions.php b/src/functions.php index f78b23d..c847403 100644 --- a/src/functions.php +++ b/src/functions.php | |||
@@ -7,9 +7,8 @@ | |||
7 | // commande pour lancer une application graphique en ouvrant un fichier | 7 | // commande pour lancer une application graphique en ouvrant un fichier |
8 | function windowAppCommand(string $app, string $path = ''): string | 8 | function windowAppCommand(string $app, string $path = ''): string |
9 | { | 9 | { |
10 | // attention, la syntaxe utilisée est la plus simple: "app fichier" | 10 | // attention, ne supporte que la syntaxe la plus simple avec un seul paramètre:"app fichier" |
11 | // ça fonctionne avec les logiciels choisis: gimp, scribus | 11 | // fonctionne avec choisis: gimp, scribus, sqlite, "l'explorateur de fichiers par défaut" |
12 | // mais ça pourrait ne pas convenir pour d'autres | ||
13 | 12 | ||
14 | $command = 'nohup ' . $app; // détache l'appli du script PHP | 13 | $command = 'nohup ' . $app; // détache l'appli du script PHP |
15 | if($path !== '') | 14 | if($path !== '') |
@@ -49,65 +48,36 @@ function enterCustomer($Client): bool | |||
49 | function makeObjectClient() | 48 | function makeObjectClient() |
50 | { | 49 | { |
51 | // fenêtres | 50 | // fenêtres |
52 | //~ $QuestionNouveauClient = new ZenityQuestion(ZenitySetup::$question_nouveau_client_text); | ||
53 | $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client_text); | 51 | $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client_text); |
54 | $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client_text, []); | 52 | $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client_text, []); |
55 | //~ $NouveauClient = new ZenityForms(ZenitySetup::$nouveau_client_text, ZenitySetup::$nouveau_client_entrees); | ||
56 | 53 | ||
57 | $Client = new Clients; | 54 | $Client = new Clients; |
58 | 55 | ||
59 | // est ce que le client est déjà dans la base? | 56 | $input = exec($RechercheClient->get()); |
60 | //~ $client_inconnu = true; | 57 | if($input == '') |
61 | //~ if(exec($QuestionNouveauClient->get()) == '0') // $? = 0 signifie oui, double égal == pour le transtypage | 58 | { |
62 | //~ { | 59 | echo "debug: recherche annulée ou saisie vide\n"; |
63 | //~ echo "choix: recherche d'une client\n"; | 60 | return 0; |
64 | $input = exec($RechercheClient->get()); | 61 | } |
65 | if($input == '') | 62 | |
66 | { | 63 | echo "debug: recherche effectuée\n"; |
67 | echo "debug: recherche annulée ou saisie vide\n"; | 64 | $ResultatsRechercheClient->setListRows( |
68 | return 0; | 65 | searchCustomer($input, $Client), |
69 | } | 66 | count(StructTablesDB::$structureOfTables[$Client->getTable()])); // 2è paramètre = nombre de colonnes |
70 | 67 | ||
71 | echo "debug: recherche effectuée\n"; | 68 | // sélection parmi les résultats |
72 | $ResultatsRechercheClient->setListRows(searchCustomer($input, $Client), $Client->getTable()); // recherche silencieuse | 69 | $input = exec($ResultatsRechercheClient->get()); // renvoie l'ID de la table 'clients' |
73 | 70 | $ResultatsRechercheClient->cleanCommand(); | |
74 | // sélection parmi les résultats | 71 | |
75 | $input = exec($ResultatsRechercheClient->get()); // renvoie l'ID de la table 'clients' | 72 | if($input == '') |
76 | $ResultatsRechercheClient->cleanCommand(); | 73 | { |
77 | 74 | echo "debug: client pas trouvé ou pas sélectionné\n"; | |
78 | if($input == '') | 75 | return 0; |
79 | { | 76 | } |
80 | echo "debug: client pas trouvé ou pas sélectionné\n"; | ||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | echo "debug: client sélectionné\n"; | ||
85 | $Client->hydrate($Client->findById($input)); | ||
86 | //~ $client_inconnu = false; | ||
87 | //~ } | ||
88 | //~ else | ||
89 | //~ { | ||
90 | //~ echo "choix: nouveau client\n"; | ||
91 | //~ } | ||
92 | 77 | ||
93 | // on n'a pas cherché OU on n'a pas trouvé | 78 | echo "debug: client sélectionné\n"; |
94 | //~ if($client_inconnu) | 79 | $Client->setID($input); |
95 | //~ { | 80 | $Client->hydrate($Client->findById()); |
96 | //~ $input = exec($NouveauClient->get()); | ||
97 | //~ if($input == '') | ||
98 | //~ { | ||
99 | //~ echo "debug: annulation lors de l'enregistrement d'un nouveau client\n"; | ||
100 | //~ return 0; | ||
101 | //~ } | ||
102 | //~ if(!$Client->hydrateFromForm($input)) | ||
103 | //~ { | ||
104 | //~ // messages d'erreur dans hydrateFromForm() | ||
105 | //~ return 0; | ||
106 | //~ } | ||
107 | //~ unset($input); | ||
108 | //~ $Client->create(); | ||
109 | //~ $Client->setID(); // sans paramètre, exécute un $this->db->lastInsertId() | ||
110 | //~ } | ||
111 | 81 | ||
112 | return $Client; | 82 | return $Client; |
113 | } | 83 | } |
@@ -121,10 +91,57 @@ function searchCustomer(string $input, Clients $Client): array | |||
121 | { | 91 | { |
122 | $input_array = explode(' ', $input); // si plusieurs mot, on les recherche tous l'un après l'autre | 92 | $input_array = explode(' ', $input); // si plusieurs mot, on les recherche tous l'un après l'autre |
123 | $result = $Client->findByKeywords($input_array, 'prenom_nom'); // on obtient un tableau à deux dimensions avec les entrées trouvées | 93 | $result = $Client->findByKeywords($input_array, 'prenom_nom'); // on obtient un tableau à deux dimensions avec les entrées trouvées |
94 | //var_dump($result); | ||
124 | return($result); | 95 | return($result); |
125 | } | 96 | } |
126 | 97 | ||
127 | 98 | ||
99 | function getServices(Clients $Client) | ||
100 | { | ||
101 | echo "debug: recherche d'une prestation\n"; | ||
102 | |||
103 | // recherche dans la table 'prestations' avec 'ID_client' les ID des prestas | ||
104 | $Presta = new Prestations($Client->getID()); | ||
105 | $IDs = $Presta->getIDsByIdClient(); | ||
106 | unset($Presta); | ||
107 | |||
108 | // mettres toutes les données dans un tableau | ||
109 | $PrestaList = []; | ||
110 | foreach($IDs as $id) | ||
111 | { | ||
112 | $PrestaList[$id] = new Prestations($Client->getID()); // renseigne 'ID_client' | ||
113 | $PrestaList[$id]->setID($id); // ID de la prestation = clé du tableau | ||
114 | $PrestaList[$id]->hydrate($PrestaList[$id]->findById()); // données copiés de la table à l'objet | ||
115 | } | ||
116 | |||
117 | // fenêtre | ||
118 | $entrees = []; | ||
119 | foreach($PrestaList as $Presta) | ||
120 | { | ||
121 | $id = $Presta->getID(); | ||
122 | $entrees[$id][] = $id; | ||
123 | $Date = new Dates((int)$Presta->getDate()); // envoi du timestamp, (int) est là par sécurité | ||
124 | $entrees[$id][] = $Date->getDate(); | ||
125 | $entrees[$id][] = $Presta->getTypePresta(); | ||
126 | $entrees[$id][] = $Presta->getCodePresta(); | ||
127 | } | ||
128 | $ResultatsRecherchePresta = new ZenityList(ZenitySetup::$resultats_recherche_presta_text, []); | ||
129 | $ResultatsRecherchePresta->setListRows($entrees, 4); | ||
130 | |||
131 | // choix de l'utilisateur | ||
132 | $input = exec($ResultatsRecherchePresta->get()); // $input est l'ID de la prestation | ||
133 | if($input == '') | ||
134 | { | ||
135 | echo "debug: recherche annulée ou saisie vide\n"; | ||
136 | return 0; | ||
137 | } | ||
138 | else | ||
139 | { | ||
140 | return $PrestaList[$input]; | ||
141 | } | ||
142 | } | ||
143 | |||
144 | |||
128 | function makeTexAndPdf(Object $Object) | 145 | function makeTexAndPdf(Object $Object) |
129 | { | 146 | { |
130 | if(get_class($Object) !== 'EnveloppeVersoLatex') | 147 | if(get_class($Object) !== 'EnveloppeVersoLatex') |
@@ -132,72 +149,6 @@ function makeTexAndPdf(Object $Object) | |||
132 | makeFolder($Object->getLatexPath()); | 149 | makeFolder($Object->getLatexPath()); |
133 | makeFolder($Object->getPdfPath()); | 150 | makeFolder($Object->getPdfPath()); |
134 | } | 151 | } |
135 | makeFile($Object->getLatexPath(), $Object->getFileName(), $Object->getLatex()); | 152 | makeFile($Object->getLatexPath(), $Object->getFileName(), $Object->getLatex()); // fichier .tex |
136 | latexToPdf($Object->getLatexPath(), $Object->getFileName(), $Object->getPdfPath()); | 153 | latexToPdf($Object->getLatexPath(), $Object->getFileName(), $Object->getPdfPath()); // fichier .pdf avec pdflatex |
137 | } | 154 | } |
138 | |||
139 | //~ function makeLatexAndPdfDocuments(Clients $Client = null, Prestations $Presta = null, $PrestaDetails = null) | ||
140 | //~ { | ||
141 | //~ $latex = ''; | ||
142 | //~ $year = ''; | ||
143 | //~ $data = []; | ||
144 | //~ $latex_path = Config::$latex_path; | ||
145 | //~ $pdf_path = Config::$pdf_path; | ||
146 | |||
147 | //~ // verso d'une enveloppe | ||
148 | //~ $latex = makeLatex('enveloppe_verso'); // pas de données transmises, elles sont dans la classe Config | ||
149 | //~ $file_name = 'enveloppe_verso.tex'; | ||
150 | //~ makeFile($latex_path, $file_name, $latex); | ||
151 | |||
152 | //~ latexToPdf($latex_path, $file_name, $pdf_path); | ||
153 | |||
154 | |||
155 | //~ if($Client !== null) | ||
156 | //~ { | ||
157 | //~ $data = $Client->getAll(); | ||
158 | |||
159 | //~ // recto d'une enveloppe | ||
160 | //~ $latex_recto_path = $latex_path . 'enveloppes_recto/'; | ||
161 | //~ $pdf_recto_path = $pdf_path . 'enveloppes_recto/'; | ||
162 | //~ $data['code_postal_espaces'] = implode(' \ ', str_split($data['code_postal'])); // code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0 | ||
163 | |||
164 | //~ $latex = makeLatex('enveloppe_recto', $data); // injection des variables | ||
165 | //~ $file_name = $Client->getCodeClient() . '.tex'; | ||
166 | //~ makeFolder($latex_recto_path); | ||
167 | //~ makeFile($latex_recto_path, $file_name, $latex); | ||
168 | |||
169 | //~ makeFolder($pdf_recto_path); | ||
170 | //~ latexToPdf($latex_recto_path, $file_name, $pdf_recto_path); | ||
171 | |||
172 | //~ // facture, devis, location | ||
173 | //~ if($Presta !== null && $PrestaDetails !== null) | ||
174 | //~ { | ||
175 | //~ $type = $Presta->getTypePresta(); | ||
176 | //~ $file_name = $type . '.tex'; | ||
177 | //~ if($type === 'facture' || $type === 'devis' || $type === 'location') | ||
178 | //~ { | ||
179 | //~ $data = array_merge($data, $Presta->getAll()); | ||
180 | //~ $Date = new Dates($Presta->getDate()); // entrée = timestamp (doit être un "int"!!) | ||
181 | //~ $year = $Date->getYear(); | ||
182 | //~ $latex_year_path = $latex_path . $year . '/'; // un sous-dossier par année | ||
183 | //~ $pdf_year_path = $pdf_path . $year . '/'; | ||
184 | //~ $data = array_merge($data, $PrestaDetails->getAll()); | ||
185 | |||
186 | //~ $latex = makeLatex($type, $data, $Date); // injection des variables | ||
187 | //~ $file_name = $Presta->getCodePresta() . '.tex'; | ||
188 | //~ makeFolder($latex_year_path); | ||
189 | //~ makeFile($latex_year_path, $file_name, $latex); | ||
190 | |||
191 | //~ makeFolder($pdf_year_path); | ||
192 | //~ latexToPdf($latex_year_path, $file_name, $pdf_year_path); | ||
193 | //~ } | ||
194 | //~ elseif($type === 'cesu' || $type === 'non_vendue') | ||
195 | //~ {} // pas de document | ||
196 | //~ else | ||
197 | //~ { | ||
198 | //~ echo "debug: erreur génération latex, type de prestation \n"; | ||
199 | //~ return 0; | ||
200 | //~ } | ||
201 | //~ } | ||
202 | //~ } | ||
203 | //~ } | ||