From 6f4cc3afffde36a13618458ffda72e6104624f36 Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 30 Aug 2023 12:20:39 +0200 Subject: =?UTF-8?q?section=20client=20=C3=A0=20part,=20section=20modif=20e?= =?UTF-8?q?n=20cours,=20bug=20dans=20Dates,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions.php | 199 ++++++++++++++++++++---------------------------------- 1 file changed, 75 insertions(+), 124 deletions(-) (limited to 'src/functions.php') 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 @@ // commande pour lancer une application graphique en ouvrant un fichier function windowAppCommand(string $app, string $path = ''): string { - // attention, la syntaxe utilisée est la plus simple: "app fichier" - // ça fonctionne avec les logiciels choisis: gimp, scribus - // mais ça pourrait ne pas convenir pour d'autres + // attention, ne supporte que la syntaxe la plus simple avec un seul paramètre:"app fichier" + // fonctionne avec choisis: gimp, scribus, sqlite, "l'explorateur de fichiers par défaut" $command = 'nohup ' . $app; // détache l'appli du script PHP if($path !== '') @@ -49,65 +48,36 @@ function enterCustomer($Client): bool function makeObjectClient() { // fenêtres - //~ $QuestionNouveauClient = new ZenityQuestion(ZenitySetup::$question_nouveau_client_text); $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client_text); $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client_text, []); - //~ $NouveauClient = new ZenityForms(ZenitySetup::$nouveau_client_text, ZenitySetup::$nouveau_client_entrees); $Client = new Clients; - // est ce que le client est déjà dans la base? - //~ $client_inconnu = true; - //~ if(exec($QuestionNouveauClient->get()) == '0') // $? = 0 signifie oui, double égal == pour le transtypage - //~ { - //~ echo "choix: recherche d'une client\n"; - $input = exec($RechercheClient->get()); - if($input == '') - { - echo "debug: recherche annulée ou saisie vide\n"; - return 0; - } - - echo "debug: recherche effectuée\n"; - $ResultatsRechercheClient->setListRows(searchCustomer($input, $Client), $Client->getTable()); // recherche silencieuse - - // sélection parmi les résultats - $input = exec($ResultatsRechercheClient->get()); // renvoie l'ID de la table 'clients' - $ResultatsRechercheClient->cleanCommand(); - - if($input == '') - { - echo "debug: client pas trouvé ou pas sélectionné\n"; - return 0; - } - - echo "debug: client sélectionné\n"; - $Client->hydrate($Client->findById($input)); - //~ $client_inconnu = false; - //~ } - //~ else - //~ { - //~ echo "choix: nouveau client\n"; - //~ } + $input = exec($RechercheClient->get()); + if($input == '') + { + echo "debug: recherche annulée ou saisie vide\n"; + return 0; + } + + echo "debug: recherche effectuée\n"; + $ResultatsRechercheClient->setListRows( + searchCustomer($input, $Client), + count(StructTablesDB::$structureOfTables[$Client->getTable()])); // 2è paramètre = nombre de colonnes + + // sélection parmi les résultats + $input = exec($ResultatsRechercheClient->get()); // renvoie l'ID de la table 'clients' + $ResultatsRechercheClient->cleanCommand(); + + if($input == '') + { + echo "debug: client pas trouvé ou pas sélectionné\n"; + return 0; + } - // on n'a pas cherché OU on n'a pas trouvé - //~ if($client_inconnu) - //~ { - //~ $input = exec($NouveauClient->get()); - //~ if($input == '') - //~ { - //~ echo "debug: annulation lors de l'enregistrement d'un nouveau client\n"; - //~ return 0; - //~ } - //~ if(!$Client->hydrateFromForm($input)) - //~ { - //~ // messages d'erreur dans hydrateFromForm() - //~ return 0; - //~ } - //~ unset($input); - //~ $Client->create(); - //~ $Client->setID(); // sans paramètre, exécute un $this->db->lastInsertId() - //~ } + echo "debug: client sélectionné\n"; + $Client->setID($input); + $Client->hydrate($Client->findById()); return $Client; } @@ -121,10 +91,57 @@ function searchCustomer(string $input, Clients $Client): array { $input_array = explode(' ', $input); // si plusieurs mot, on les recherche tous l'un après l'autre $result = $Client->findByKeywords($input_array, 'prenom_nom'); // on obtient un tableau à deux dimensions avec les entrées trouvées + //var_dump($result); return($result); } +function getServices(Clients $Client) +{ + echo "debug: recherche d'une prestation\n"; + + // recherche dans la table 'prestations' avec 'ID_client' les ID des prestas + $Presta = new Prestations($Client->getID()); + $IDs = $Presta->getIDsByIdClient(); + unset($Presta); + + // mettres toutes les données dans un tableau + $PrestaList = []; + foreach($IDs as $id) + { + $PrestaList[$id] = new Prestations($Client->getID()); // renseigne 'ID_client' + $PrestaList[$id]->setID($id); // ID de la prestation = clé du tableau + $PrestaList[$id]->hydrate($PrestaList[$id]->findById()); // données copiés de la table à l'objet + } + + // fenêtre + $entrees = []; + foreach($PrestaList as $Presta) + { + $id = $Presta->getID(); + $entrees[$id][] = $id; + $Date = new Dates((int)$Presta->getDate()); // envoi du timestamp, (int) est là par sécurité + $entrees[$id][] = $Date->getDate(); + $entrees[$id][] = $Presta->getTypePresta(); + $entrees[$id][] = $Presta->getCodePresta(); + } + $ResultatsRecherchePresta = new ZenityList(ZenitySetup::$resultats_recherche_presta_text, []); + $ResultatsRecherchePresta->setListRows($entrees, 4); + + // choix de l'utilisateur + $input = exec($ResultatsRecherchePresta->get()); // $input est l'ID de la prestation + if($input == '') + { + echo "debug: recherche annulée ou saisie vide\n"; + return 0; + } + else + { + return $PrestaList[$input]; + } +} + + function makeTexAndPdf(Object $Object) { if(get_class($Object) !== 'EnveloppeVersoLatex') @@ -132,72 +149,6 @@ function makeTexAndPdf(Object $Object) makeFolder($Object->getLatexPath()); makeFolder($Object->getPdfPath()); } - makeFile($Object->getLatexPath(), $Object->getFileName(), $Object->getLatex()); - latexToPdf($Object->getLatexPath(), $Object->getFileName(), $Object->getPdfPath()); + makeFile($Object->getLatexPath(), $Object->getFileName(), $Object->getLatex()); // fichier .tex + latexToPdf($Object->getLatexPath(), $Object->getFileName(), $Object->getPdfPath()); // fichier .pdf avec pdflatex } - -//~ function makeLatexAndPdfDocuments(Clients $Client = null, Prestations $Presta = null, $PrestaDetails = null) -//~ { - //~ $latex = ''; - //~ $year = ''; - //~ $data = []; - //~ $latex_path = Config::$latex_path; - //~ $pdf_path = Config::$pdf_path; - - //~ // verso d'une enveloppe - //~ $latex = makeLatex('enveloppe_verso'); // pas de données transmises, elles sont dans la classe Config - //~ $file_name = 'enveloppe_verso.tex'; - //~ makeFile($latex_path, $file_name, $latex); - - //~ latexToPdf($latex_path, $file_name, $pdf_path); - - - //~ if($Client !== null) - //~ { - //~ $data = $Client->getAll(); - - //~ // recto d'une enveloppe - //~ $latex_recto_path = $latex_path . 'enveloppes_recto/'; - //~ $pdf_recto_path = $pdf_path . 'enveloppes_recto/'; - //~ $data['code_postal_espaces'] = implode(' \ ', str_split($data['code_postal'])); // code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0 - - //~ $latex = makeLatex('enveloppe_recto', $data); // injection des variables - //~ $file_name = $Client->getCodeClient() . '.tex'; - //~ makeFolder($latex_recto_path); - //~ makeFile($latex_recto_path, $file_name, $latex); - - //~ makeFolder($pdf_recto_path); - //~ latexToPdf($latex_recto_path, $file_name, $pdf_recto_path); - - //~ // facture, devis, location - //~ if($Presta !== null && $PrestaDetails !== null) - //~ { - //~ $type = $Presta->getTypePresta(); - //~ $file_name = $type . '.tex'; - //~ if($type === 'facture' || $type === 'devis' || $type === 'location') - //~ { - //~ $data = array_merge($data, $Presta->getAll()); - //~ $Date = new Dates($Presta->getDate()); // entrée = timestamp (doit être un "int"!!) - //~ $year = $Date->getYear(); - //~ $latex_year_path = $latex_path . $year . '/'; // un sous-dossier par année - //~ $pdf_year_path = $pdf_path . $year . '/'; - //~ $data = array_merge($data, $PrestaDetails->getAll()); - - //~ $latex = makeLatex($type, $data, $Date); // injection des variables - //~ $file_name = $Presta->getCodePresta() . '.tex'; - //~ makeFolder($latex_year_path); - //~ makeFile($latex_year_path, $file_name, $latex); - - //~ makeFolder($pdf_year_path); - //~ latexToPdf($latex_year_path, $file_name, $pdf_year_path); - //~ } - //~ elseif($type === 'cesu' || $type === 'non_vendue') - //~ {} // pas de document - //~ else - //~ { - //~ echo "debug: erreur génération latex, type de prestation \n"; - //~ return 0; - //~ } - //~ } - //~ } -//~ } -- cgit v1.2.3