From 747674b450d6840ce9bd9aecd765cf31445ef8d3 Mon Sep 17 00:00:00 2001 From: polo Date: Sat, 22 Jul 2023 12:29:47 +0200 Subject: navigation entre sections, boucle principale, client ou prospect --- data/dev.sqlite | Bin 36864 -> 36864 bytes src/Dates.php | 10 +- src/Latex.php | 94 +++++++++++----- src/functions.php | 118 +++++++++++--------- src/main.php | 130 +--------------------- src/model/Clients.php | 6 + src/model/Model.php | 13 ++- src/model/StructTablesDB.php | 2 +- src/model/traits.php | 2 +- src/sections/1_customer.php | 48 ++++++++ src/sections/1_new_service.php | 209 ---------------------------------- src/sections/2_quotations.php | 9 -- src/sections/2_service.php | 229 ++++++++++++++++++++++++++++++++++++++ src/sections/3_modify_data.php | 9 ++ src/sections/3_modify_service.php | 9 -- src/sections/4_get_document.php | 55 +++++++++ src/sections/main_loop.php | 106 ++++++++++++++++++ src/view/ZenitySetup.php | 15 ++- 18 files changed, 614 insertions(+), 450 deletions(-) create mode 100644 src/sections/1_customer.php delete mode 100644 src/sections/1_new_service.php delete mode 100644 src/sections/2_quotations.php create mode 100644 src/sections/2_service.php create mode 100644 src/sections/3_modify_data.php delete mode 100644 src/sections/3_modify_service.php create mode 100644 src/sections/4_get_document.php create mode 100644 src/sections/main_loop.php diff --git a/data/dev.sqlite b/data/dev.sqlite index 841d187..857931f 100644 Binary files a/data/dev.sqlite and b/data/dev.sqlite differ diff --git a/src/Dates.php b/src/Dates.php index eb57ca8..2fe93cb 100644 --- a/src/Dates.php +++ b/src/Dates.php @@ -32,24 +32,24 @@ class Dates // getters public function getDate(): string { - return($this->date); + return $this->date; } public function getDay(): string { - return($this->day); + return $this->day; } public function getMonth(): string { - return($this->month); + return $this->month; } public function getYear(): string { - return($this->year); + return $this->year; } public function getTimestamp(): int { - return($this->timestamp); + return $this->timestamp; } diff --git a/src/Latex.php b/src/Latex.php index 051c48b..547c130 100644 --- a/src/Latex.php +++ b/src/Latex.php @@ -12,7 +12,7 @@ abstract class Latex protected $data = []; // données à insérer dans le template protected $latex = ''; // latex pur - static function makeLatexSubClass(string $type): Object + static function makeLatexSubClass(string $type) { switch($type) { @@ -27,16 +27,20 @@ abstract class Latex return new EnveloppeRectoLatex($type); case 'enveloppe_verso': return new EnveloppeVersoLatex($type); + // pas de document + case 'cesu': + return null; + case 'non_vendue': + return null; // documents pour la compta // erreur default: - echo 'erreur, la sous-classe latex à initialiser n\'existe pas'; + echo "erreur, la sous-classe latex à initialiser n'existe pas\n"; } } - // tester en private? public function __construct(string $type) { $this->type = $type; @@ -70,30 +74,28 @@ abstract class Latex { return $this->pdf_path; } - public function getLatex(): string { return $this->latex; } // setters - public function setFileName(string $file_name) - { - $this->file_name = $file_name; - } - public function setLatexPath(string $latex_path) - { - $this->latex_path = $latex_path; - } - public function setPdfPath(string $pdf_path) - { - $this->pdf_path = $pdf_path; - } + //~ public function setFileName(string $file_name) + //~ { + //~ $this->file_name = $file_name; + //~ } + //~ public function setLatexPath(string $latex_path) + //~ { + //~ $this->latex_path = $latex_path; + //~ } + //~ public function setPdfPath(string $pdf_path) + //~ { + //~ $this->pdf_path = $pdf_path; + //~ } public function setData(Object $Object) { $this->data = array_merge($this->data, $Object->getAll()); // nécessite des tableaux associatifs - //return $Object; // pour chainer les méthodes } } @@ -101,24 +103,36 @@ abstract class Latex abstract class PrestaLatex extends Latex { protected $Date; // sera un type "Dates" - protected $year = ''; - //~ public function __construct(string $type) // surcharge Latex::__construct() + //~ public function __construct(string $type) //~ { //~ $this->type = $type; - //~ $this->Date = new Dates(); - //~ $this->year = $this->Date->getYear(); //~ } - public function getYear(): string // parce que Dates::getDate() retourne une chaine + public function setData(Object $Object): self { - return $this->year; + $this->data = array_merge($this->data, $Object->getAll()); // nécessite des tableaux associatifs + + if(get_class($Object) === 'Prestations') + { + $this->file_name = $Object->getCodePresta() . '.tex'; + $this->makeDateInstance($Object->getDate()); // paramètre = int + + $this->latex_path = Config::$latex_path . $this->Date->getYear() . '/'; + $this->pdf_path = Config::$pdf_path . $this->Date->getYear() . '/'; + } + + return $this; // pour chainer les méthodes } - public function makeDateInstance(int $date) + //~ public function getYear(): string // parce que Dates::getDate() retourne une chaine + //~ { + //~ return $this->year; + //~ } + + protected function makeDateInstance(int $timestamp) { - $this->Date = new Dates($date); - $this->year = $this->Date->getYear(); + $this->Date = new Dates($timestamp); } // forme = code-presta.tex @@ -143,23 +157,45 @@ abstract class PrestaLatex extends Latex //return($latex); } } - class DevisLatex extends PrestaLatex // extends Latex {} class FactureLatex extends PrestaLatex // extends Latex {} class LocationLatex extends PrestaLatex // extends Latex {} + class EnveloppeRectoLatex extends Latex { + public function __construct(string $type) + { + $this->type = $type; + $this->latex_path = Config::$latex_path . 'enveloppes_recto/'; + $this->pdf_path = Config::$pdf_path . 'enveloppes_recto/'; + } + + public function setData(Object $Client) // ici de type Clients + { + $this->file_name = $Client->getCodeClient() . '.tex'; + $this->data = array_merge($this->data, $Client->getAll()); // nécessite des tableaux associatifs + $this->spacesInPostCode(); // nécessite $this->data + } + // code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0 - public function spacesInPostCode() + protected function spacesInPostCode() { $this->data['code_postal_espaces'] = implode(' \ ', str_split($this->data['code_postal'])); } } class EnveloppeVersoLatex extends Latex -{} +{ + public function __construct(string $type) + { + $this->type = $type; + $this->file_name = 'enveloppe_verso.tex'; + $this->latex_path = Config::$latex_path; + $this->pdf_path = Config::$pdf_path; + } +} diff --git a/src/functions.php b/src/functions.php index aaacb36..f78b23d 100644 --- a/src/functions.php +++ b/src/functions.php @@ -22,21 +22,45 @@ function windowAppCommand(string $app, string $path = ''): string return $command; } -function makeObjectCLient() +function enterCustomer($Client): bool +{ + // fenêtre + $NouveauClient = new ZenityForms(ZenitySetup::$nouveau_client_text, ZenitySetup::$nouveau_client_entrees); + + $input = exec($NouveauClient->get()); + if($input == '') + { + echo "debug: annulation lors de l'enregistrement d'un nouveau client\n"; + return false; + } + if(!$Client->hydrateFromForm($input)) + { + // messages d'erreur dans hydrateFromForm() + return false; + } + unset($input); + + $Client->create(); // écrire dans la base + $Client->setID(); // sans paramètre, exécute un $this->db->lastInsertId() + + return true; +} + +function makeObjectClient() { // fenêtres - $QuestionNouveauClient = new ZenityQuestion(ZenitySetup::$question_nouveau_client_text); + //~ $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); + //~ $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"; + //~ $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 == '') { @@ -45,7 +69,7 @@ function makeObjectCLient() } echo "debug: recherche effectuée\n"; - $ResultatsRechercheClient->setListRows(rechercheClient($input, $Client), $Client->getTable()); // recherche silencieuse + $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' @@ -59,31 +83,31 @@ function makeObjectCLient() echo "debug: client sélectionné\n"; $Client->hydrate($Client->findById($input)); - $client_inconnu = false; - } - else - { - echo "choix: nouveau client\n"; - } + //~ $client_inconnu = false; + //~ } + //~ else + //~ { + //~ echo "choix: nouveau client\n"; + //~ } // 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() - } + //~ 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() + //~ } return $Client; } @@ -93,7 +117,7 @@ function makeObjectCLient() // NOTE 3: la variable créée lors d'un "new" est elle-même une référence contenant un identifiant (= le pointeur?) // NOTE 4: l'objet est détruit lorsque la dernière référence est supprimée -function rechercheClient(string $input, Clients $Client): array +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 @@ -101,6 +125,17 @@ function rechercheClient(string $input, Clients $Client): array } +function makeTexAndPdf(Object $Object) +{ + if(get_class($Object) !== 'EnveloppeVersoLatex') + { + makeFolder($Object->getLatexPath()); + makeFolder($Object->getPdfPath()); + } + makeFile($Object->getLatexPath(), $Object->getFileName(), $Object->getLatex()); + latexToPdf($Object->getLatexPath(), $Object->getFileName(), $Object->getPdfPath()); +} + //~ function makeLatexAndPdfDocuments(Clients $Client = null, Prestations $Presta = null, $PrestaDetails = null) //~ { //~ $latex = ''; @@ -166,22 +201,3 @@ function rechercheClient(string $input, Clients $Client): array //~ } //~ } //~ } - -//~ function makeLatex(string $type, array $data = [], Dates $Date = null) -//~ { - //~ $date = ''; - //~ if($Date != null) - //~ { - //~ $date = $Date->getDate(); - //~ $date = preg_replace('#\D#', '/', $date); // date avec des slashs / parce que j'aime bien - //~ } - - //~ // on obtient la variable $latex avec ob_get_clean() - //~ // le include() ici, c'est du génie ou c'est moche ou les deux? - //~ // un nouveau fichier php est inséré à chaque itération - //~ include('latex_templates/' . $type . '.php'); - - //~ // on retourne le buffer - //~ // normallement le code PHP inséré avec include est nettoyé en quittant la fonction - //~ return($latex); -//~ } diff --git a/src/main.php b/src/main.php index 7bf8470..a0b973b 100755 --- a/src/main.php +++ b/src/main.php @@ -49,132 +49,6 @@ require('view/ZenitySetup.php'); // texte dans les fenêtres ET instanciation (u require('Latex.php'); // générer le code LaTeX -require('sections/1_new_service.php'); -require('sections/2_quotations.php'); -require('sections/3_modify_service.php'); -// boucle principale -$boucle = true; -$code_retour = 0; // 0 dirige vers le menu principal, 1 vers la section 1, etc -while($boucle) -{ - // niveau 1: menu principal - if($code_retour === 0) - { - $MenuPrincipal = new ZenityList(ZenitySetup::$menu_principal_text, ZenitySetup::$menu_principal_entrees); - $choix_niv1 = exec($MenuPrincipal->get()); - } - else - { - $choix_niv1 = ''; - } - - - // -- SECTION 1: Nouvelle prestation -- - if($choix_niv1 === ZenitySetup::$menu_principal_entrees[0] || $code_retour === 1) - { - echo("choix: $choix_niv1\n"); - $code_retour = newService(); - echo "debug: main.php: hello, code retour " . $code_retour . "\n"; - } - - // -- SECTION 2: Devis -- - elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[1] || $code_retour === 2) - { - echo("choix: $choix_niv1\n"); - $code_retour = modifyService(); - } - // -- SECTION 3: Modifier un enregistrement -- - elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[2] || $code_retour === 3) - { - echo("choix: $choix_niv1\n"); - $code_retour = modifyService(); - } - - // -- SECTION 4: Consulter/analyser les données -- - elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[3] || $code_retour === 4) - { - echo("choix: $choix_niv1\n"); - // quel affichage? des tableaux avec zenity? LaTeX? une page web? un autre outil servant à faire des tableaux et graphiques - } - - // -- SECTION 5: Imprimer -- - elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[4] || $code_retour === 5) // = Imprimer un document - { - echo("choix: $choix_niv1\n"); - $MenuDocuments = new ZenityList(ZenitySetup::$menu_documents_text, ZenitySetup::$menu_documents_entrees); - $choix_niv2 = exec($MenuDocuments->get()); - if($choix_niv2 === ZenitySetup::$menu_documents_entrees[0]) - { - - } - elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[1]) // = Facture - { - - } - elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[2]) // = Lettre avec adresse - { - - } - elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[3]) // = Livre des recettes - { - - } - elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[4]) // = Registre des achats - { - - } - elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[5]) // = Bilan annuel - { - - } - else - { - // retour menu principal - } - } - - // -- SECTION 6: Supports de communication -- - elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[5] || $code_retour === 6) // = Communication - { - echo("choix: $choix_niv1\n"); - $MenuCommunication = new ZenityList(ZenitySetup::$menu_communication_text, ZenitySetup::$menu_communication_entrees); - $choix_niv2 = exec($MenuCommunication->get()); - if($choix_niv2 === ZenitySetup::$menu_communication_entrees[0]) // = Flyer (nécessite gimp) - { - exec(windowAppCommand($image_editor, $flyer)); - } - elseif($choix_niv2 === ZenitySetup::$menu_communication_entrees[1]) // = Carte de visite (nécessite scribus) - { - exec(windowAppCommand($publishing, $business_card)); - } - elseif($choix_niv2 === ZenitySetup::$menu_communication_entrees[2]) // = Explorateur de fichiers - { - exec(windowAppCommand($file_explorer, $pub)); - } - else - { - // retour menu principal - } - } - - // -- SECTION 7: BDD -- - elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[6] || $code_retour === 7) // = Base de données - { - echo("choix: $choix_niv1\n"); - if($sqlitebrowser_enable) - { - exec(windowAppCommand(Config::$sqlite_gui, Config::$db_path)); - } - else - { - exec($x_term_command . ' ' . $sqlite_cli . ' ' . Config::$db_path); // correpond à priori à: xterm -e sqlite3 ~/ORDIPOLO/Appli_PHP/ordipolo.sqlite - } - } - - // arrêt - else - { - $boucle = false; - } -} +// action !! +require('sections/main_loop.php'); diff --git a/src/model/Clients.php b/src/model/Clients.php index d9dd28d..f36acc1 100644 --- a/src/model/Clients.php +++ b/src/model/Clients.php @@ -13,6 +13,7 @@ class Clients extends Model protected $telephone; protected $courriel; protected $apropos; + protected $type = 'prospect'; //~ use ModelChildren; @@ -81,6 +82,11 @@ class Clients extends Model $this->apropos = (string) $value; return $this; } + public function setType($value) + { + $this->type = (string) $value; + return $this; + } public function findByKeywords(array $keywords, string $field): array // n'hydrate pas les variables, on doit choisir un client et hydrater ensuite diff --git a/src/model/Model.php b/src/model/Model.php index 17d1292..3fb3bdf 100644 --- a/src/model/Model.php +++ b/src/model/Model.php @@ -43,7 +43,7 @@ abstract class Model extends DB foreach($data as $key => $value) { // nom du setter - // nom_du_champ devient setNomDuChamp + // nom_propriete => setPropriete // on sépare les mots par des espaces, ucwords met la première lettre de chaque mot en majuscule, puis on supprime les espaces $setter_name = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))); // ucwords: première lettre de chaque mot en majuscule if(method_exists($this, $setter_name)) @@ -207,7 +207,7 @@ abstract class Model extends DB // update UPDATE - public function update(int $id) + public function update(int $id) // utiliser plutôt $this->ID ? { $fields = []; $values = []; @@ -219,13 +219,18 @@ abstract class Model extends DB $values[] = $value; } } - $values[] = $id; + $values[] = $id; // cette syntaxe ajoute une valeur au tableau $field_list = implode(', ', $fields); - // UPDATE annonces SET titre = ?, description = ?, actif = ? WHERE id= ? + // UPDATE annonces SET titre = ?, description = ?, actif = ? WHERE id = ? return($this->execQuery('UPDATE ' . $this->table . ' SET ' . $field_list . ' WHERE id = ?', $values)); } + public function updateOneValue(string $field, $value) + { + return($this->execQuery('UPDATE ' . $this->table . ' SET ' . $field . ' = ? WHERE id = ?', [$value, $this->ID])); + } + // delete DELETE protected function delete(int $id) diff --git a/src/model/StructTablesDB.php b/src/model/StructTablesDB.php index 75a4383..769d502 100644 --- a/src/model/StructTablesDB.php +++ b/src/model/StructTablesDB.php @@ -9,7 +9,7 @@ class StructTablesDB static public $structureOfTables = [ // la table prestations est liée à la table clients // les tables devis_factures, cesu et locations sont liées à la table prestations - 'clients' => ['ID' => 'INTEGER', 'prenom_nom' => 'TEXT', 'code_client' => 'TEXT', 'adresse' => 'TEXT', 'code_postal' => 'TEXT', 'ville' => 'TEXT', 'telephone' => 'TEXT', 'courriel' => 'TEXT', 'apropos' => 'TEXT'], + 'clients' => ['ID' => 'INTEGER', 'prenom_nom' => 'TEXT', 'code_client' => 'TEXT', 'adresse' => 'TEXT', 'code_postal' => 'TEXT', 'ville' => 'TEXT', 'telephone' => 'TEXT', 'courriel' => 'TEXT', 'apropos' => 'TEXT', 'type' => 'TEXT DEFAULT prospect'], 'prestations' => ['ID' => 'INTEGER', 'ID_client' => 'INTEGER', 'code_presta' => 'TEXT', 'date' => 'INTEGER', 'type_presta' => 'TEXT', 'mode_paiement' => 'TEXT', 'commentaires' => 'TEXT'], 'devis' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'total_main_d_oeuvre' => 'REAL', 'pieces' => 'TEXT', 'total_pieces' => 'REAL', 'deplacement' => 'REAL', 'total_HT' => 'REAL', 'delai_livraison' => 'TEXT', 'validite_devis' => 'TEXT', 'signature_devis' => 'TEXT'], 'factures' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'machine' => 'TEXT', 'OS' => 'TEXT', 'donnees' => 'TEXT', 'cles_licences' => 'TEXT', 'total_main_d_oeuvre' => 'REAL', 'pieces' => 'TEXT', 'total_pieces' => 'REAL', 'deplacement' => 'REAL', 'total_HT' => 'REAL'], diff --git a/src/model/traits.php b/src/model/traits.php index 03121be..88451d9 100644 --- a/src/model/traits.php +++ b/src/model/traits.php @@ -1,7 +1,7 @@ get()) === 'Client') + { + $Client->setType('client'); + } + //~ else // + //~ { + //~ $Client->setType('prospect'); + //~ } + + // -- partie 2: saisie des infos -- + if(enterCustomer($Client)) + { + // -- partie 3: on fait quoi maintenant -- + $choix_niv2 = exec($FinSection1->get()); + if($choix_niv2 === ZenitySetup::$fin_section_1_entrees[0]) + { + return [2, $Client]; // section 2: newService() + } + elseif($choix_niv2 === ZenitySetup::$fin_section_1_entrees[1]) + { + return [3, $Client]; // section 3: modifyData() + } + elseif($choix_niv2 === ZenitySetup::$fin_section_1_entrees[2]) + { + return [1, null]; // relancer section 1: newCustomer() + } + else + { + return [0, null]; // menu principal + } + } + + return [0, null]; // menu principal +} 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 @@ -get()); - if($choix_niv2 === '') - { - echo "debug: annulation menu enregistrement\n"; - return 0; // menu principal - } - - $Presta = new Prestations($Client->getID()); - - // détail de la prestation - // calendrier - étape 1/3 - $Date = new Dates(exec($Calendrier->get())); // exec() renvoie soit une chaîne soit un false - if($Date->getDate() == '') // on n'a pas cliqué sur "annuler" - { - echo "debug: annulation à la saisie d'une date\n"; - return 0; // menu principal - } - - $Presta->setDate($Date->getTimestamp()); // un entier pour la BDD - - switch($choix_niv2) - { - // formulaire - étape 2/3 - //~ case ZenitySetup::$menu_enregistrement_entrees[0]: // "Devis" - //~ $PrestaDetails = new DevisFactures('devis'); - //~ $Presta->setTypePresta('devis'); - //~ $input = exec($FormulaireDevis->get()); - //~ break; - case ZenitySetup::$menu_enregistrement_entrees[0]: // "Facture" - $PrestaDetails = new DevisFactures('factures'); // 'factures' est le nom de la table, pas le type de presta - $Presta->setTypePresta('facture'); - $input =exec($FormulaireFacture->get()); - break; - case ZenitySetup::$menu_enregistrement_entrees[1]: // "CESU" - $PrestaDetails = new CESU(); - $Presta->setTypePresta('cesu'); - $input = exec($FormulaireCesu->get()); - break; - case ZenitySetup::$menu_enregistrement_entrees[2]: // "Location" - $PrestaDetails = new Locations(); - $Presta->setTypePresta('location'); - $input = exec($FormulaireLocation->get()); - break; - case ZenitySetup::$menu_enregistrement_entrees[3]: // "Prestation non vendue" - $Presta->setTypePresta('non_vendue'); - break; - default: // inutile normallement, cas déjà géré avant - echo "debug: sortie du menu enregistrement incorrect\n"; - return 0; - } - - $Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre - - if($choix_niv2 != ZenitySetup::$menu_enregistrement_entrees[3]) // si presta non vendue, saut étape 3/3 - { - if($input == '') // annulation - { - echo "debug: annulation lors de l'enregistrement des détails de la prestation\n"; - return 0; - } - elseif(isset($PrestaDetails) && !$PrestaDetails->hydrateFromForm($input, $Presta)) // echec de l'hydratation - { - echo "debug: erreur de hydrateFromForm()\n"; // messages d'erreur à mettre ici ou dans hydrateFromForm()? - return 0; - } - unset($input); - } - - // commentaire - étape 3/3 - $input = exec($CommentairePrestation->get()); - if($input == '') - { - echo "debug: pas de commentaire saisi\n"; - // on n'interrompt pas le script et on enregistre dans tous les cas (annulatation, chaîne vide) - } - // Cliquer sur annuler (ou appuyer sur échap) revient dont à valider avec une chaîne vide et enregistrer la prestation - // la commande 'echo $?' ($? est le code de sortie de la commande précédente) renvoit 1 si on annule avec la touche échap () - // 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) - // 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 - // 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) - // 2>&1 semble inutile, pas de sortie d'erreur de zenity --entry - //~ if(exec('echo $?') != 1) - //~ { - //~ echo "debug: annulation à la saisie d'un commentaire\n"; - //~ return 0; - //~ } - $Presta->setCommentaires($input); - unset($input); - - $Presta->create(); - $Presta->setID(); // sans paramètre, exécute un $this->db->lastInsertId() - - if(isset($PrestaDetails)) // presta non vendue - { - $PrestaDetails->setIDPresta($Presta->getID()); // d'un objet à l'autre - $PrestaDetails->create(); - $PrestaDetails->setID(); // sans paramètre, exécute un $this->db->lastInsertId() - } - - - // -- partie 3: LaTeX -- - - //makeLatexAndPdfDocuments($Client, $Presta, $PrestaDetails); - // factoriser tout ça - /* plusieurs parties: - * - une fonction ou on crée et manipule les objets (une classe par type de document) - * - manipulation des données - * - chemins et noms de fichiers - * - insertion des variables - * - écriture du fichier (+ dossier si nécessaire) - */ - // et pour bien faire ajouter aussi une interface - - // fabrique d'objets (sans connaître les noms des classes) - $EnveloppeRecto = Latex::makeLatexSubClass('enveloppe_recto'); - $EnveloppeVerso = Latex::makeLatexSubClass('enveloppe_verso'); - $DocumentPresta = Latex::makeLatexSubClass($Presta->getTypePresta()); // $type = facture, devis, location - - // génération du latex - $EnveloppeRecto->setData($Client); - $EnveloppeRecto->setFileName($Client->getCodeClient() . '.tex'); - $EnveloppeRecto->setLatexPath(Config::$latex_path . 'enveloppes_recto/'); - $EnveloppeRecto->setPdfPath(Config::$pdf_path . 'enveloppes_recto/'); - $EnveloppeRecto->spacesInPostCode(); - $EnveloppeRecto->makeLatex(); - - $EnveloppeVerso->setFileName('enveloppe_verso.tex'); - $EnveloppeVerso->setLatexPath(Config::$latex_path); - $EnveloppeVerso->setPdfPath(Config::$pdf_path); - $EnveloppeVerso->makeLatex(); - - $DocumentPresta->setData($Client); - $DocumentPresta->setData($Presta); - $DocumentPresta->setData($PrestaDetails); - $DocumentPresta->makeDateInstance($Presta->getDate()); // paramètre = int - $DocumentPresta->setFileName($Presta->getCodePresta() . '.tex'); - $DocumentPresta->setLatexPath(Config::$latex_path . $DocumentPresta->getYear() . '/'); - $DocumentPresta->setPdfPath(Config::$pdf_path . $DocumentPresta->getYear() . '/'); - $DocumentPresta->makeLatex(); - - // création des fichiers - makeFolder($EnveloppeRecto->getLatexPath()); - makeFolder($EnveloppeRecto->getPdfPath()); - makeFile($EnveloppeRecto->getLatexPath(), $EnveloppeRecto->getFileName(), $EnveloppeRecto->getLatex()); - latexToPdf($EnveloppeRecto->getLatexPath(), $EnveloppeRecto->getFileName(), $EnveloppeRecto->getPdfPath()); - - makeFile($EnveloppeVerso->getLatexPath(), $EnveloppeVerso->getFileName(), $EnveloppeVerso->getLatex()); - latexToPdf($EnveloppeVerso->getLatexPath(), $EnveloppeVerso->getFileName(), $EnveloppeVerso->getPdfPath()); - - makeFolder($DocumentPresta->getLatexPath()); - makeFolder($DocumentPresta->getPdfPath()); - makeFile($DocumentPresta->getLatexPath(), $DocumentPresta->getFileName(), $DocumentPresta->getLatex()); - latexToPdf($DocumentPresta->getLatexPath(), $DocumentPresta->getFileName(), $DocumentPresta->getPdfPath()); - - - // -- partie 4: récapitulatif -- - - // tableau récaptilatif - // ZenityList - - // imprimer? - //~ $imprimer_facture = exec('zenity --question --width=250 --title="Base de données mise à jour" --text="Imprimer la facture?"'); - //~ $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"'); - - - // -- partie 5: on fait quoi maintenant -- - - // possibilité de modification - // zenityQuestion - //~ if(exec($QuestionModifierPrestation->get()) == '0') - //~ { - //~ return 3; // section "Modifier un enregistrement" - //~ } - //~ else - //~ { - //~ return 0; // menu principal - //~ } - return 0; // menu principal -} diff --git a/src/sections/2_quotations.php b/src/sections/2_quotations.php deleted file mode 100644 index 76b66fd..0000000 --- a/src/sections/2_quotations.php +++ /dev/null @@ -1,9 +0,0 @@ -get()); + if($choix_niv2 === '') + { + echo "debug: annulation menu enregistrement\n"; + return [0, null]; // menu principal + } + + $Presta = new Prestations($Client->getID()); + + // détail de la prestation + // calendrier - étape 1/3 + $Date = new Dates(exec($Calendrier->get())); // exec() renvoie soit une chaîne soit un false + if($Date->getDate() == '') // on n'a pas cliqué sur "annuler" + { + echo "debug: annulation à la saisie d'une date\n"; + return [0, null]; // menu principal + } + + $Presta->setDate($Date->getTimestamp()); // un entier pour la BDD + + switch($choix_niv2) + { + // formulaire - étape 2/3 + //~ case ZenitySetup::$menu_enregistrement_entrees[0]: // "Devis" + //~ $PrestaDetails = new DevisFactures('devis'); + //~ $Presta->setTypePresta('devis'); + //~ $input = exec($FormulaireDevis->get()); + //~ break; + case ZenitySetup::$menu_enregistrement_entrees[0]: // "Facture" + $PrestaDetails = new DevisFactures('factures'); // 'factures' est le nom de la table, pas le type de presta + $Presta->setTypePresta('facture'); + $input =exec($FormulaireFacture->get()); + break; + case ZenitySetup::$menu_enregistrement_entrees[1]: // "CESU" + $PrestaDetails = new CESU(); + $Presta->setTypePresta('cesu'); + $input = exec($FormulaireCesu->get()); + break; + case ZenitySetup::$menu_enregistrement_entrees[2]: // "Location" + $PrestaDetails = new Locations(); + $Presta->setTypePresta('location'); + $input = exec($FormulaireLocation->get()); + break; + case ZenitySetup::$menu_enregistrement_entrees[3]: // "Prestation non vendue" + $Presta->setTypePresta('non_vendue'); + break; + default: // inutile normallement, cas déjà géré avant + echo "debug: sortie du menu enregistrement incorrect\n"; + return [0, null]; + } + + $Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre + + if($choix_niv2 != ZenitySetup::$menu_enregistrement_entrees[3]) // si presta non vendue, saut étape 3/3 + { + if($input == '') // annulation + { + echo "debug: annulation lors de l'enregistrement des détails de la prestation\n"; + return [0, null]; + } + elseif(isset($PrestaDetails) && !$PrestaDetails->hydrateFromForm($input, $Presta)) // echec de l'hydratation + { + echo "debug: erreur de hydrateFromForm()\n"; // messages d'erreur à mettre ici ou dans hydrateFromForm()? + return [0, null]; + } + unset($input); + } + + // commentaire - étape 3/3 + $input = exec($CommentairePrestation->get()); + if($input == '') + { + echo "debug: pas de commentaire saisi\n"; + // on n'interrompt pas le script et on enregistre dans tous les cas (annulatation, chaîne vide) + } + // Cliquer sur annuler (ou appuyer sur échap) revient dont à valider avec une chaîne vide et enregistrer la prestation + // la commande 'echo $?' ($? est le code de sortie de la commande précédente) renvoit 1 si on annule avec la touche échap () + // 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) + // 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 + // 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) + // 2>&1 semble inutile, pas de sortie d'erreur de zenity --entry + //~ if(exec('echo $?') != 1) + //~ { + //~ echo "debug: annulation à la saisie d'un commentaire\n"; + //~ return 0; + //~ } + $Presta->setCommentaires($input); + unset($input); + + $Presta->create(); + $Presta->setID(); // sans paramètre, exécute un $this->db->lastInsertId() + + if(isset($PrestaDetails)) // presta non vendue + { + $PrestaDetails->setIDPresta($Presta->getID()); // d'un objet à l'autre + $PrestaDetails->create(); + $PrestaDetails->setID(); // sans paramètre, exécute un $this->db->lastInsertId() + } + + // si encore de type prospect, devient un type client + //$Client->setType('client'); // inutile? + $Client->updateOneValue('type', 'client'); // modifier le type prospect en client + + + // -- partie 3: LaTeX -- + + //makeLatexAndPdfDocuments($Client, $Presta, $PrestaDetails); + // factoriser tout ça + /* plusieurs parties: + * - une fonction ou on crée et manipule les objets (une classe par type de document) + * - manipulation des données + * - chemins et noms de fichiers + * - insertion des variables + * - écriture du fichier (+ dossier si nécessaire) + */ + // et pour bien faire ajouter aussi une interface + + //~ function makeLatexSubClass(string $type) + //~ {} + + // fabrique d'objets (sans connaître les noms des classes) + $EnveloppeRecto = Latex::makeLatexSubClass('enveloppe_recto'); + $EnveloppeVerso = Latex::makeLatexSubClass('enveloppe_verso'); + $DocumentPresta = Latex::makeLatexSubClass($Presta->getTypePresta()); // $type = facture, devis, location + + // génération du latex + $EnveloppeRecto->setData($Client); + //~ $EnveloppeRecto->setFileName($Client->getCodeClient() . '.tex'); + //~ $EnveloppeRecto->setLatexPath(Config::$latex_path . 'enveloppes_recto/'); + //~ $EnveloppeRecto->setPdfPath(Config::$pdf_path . 'enveloppes_recto/'); + //~ $EnveloppeRecto->spacesInPostCode(); + $EnveloppeRecto->makeLatex(); + + //~ $EnveloppeVerso->setFileName('enveloppe_verso.tex'); + //~ $EnveloppeVerso->setLatexPath(Config::$latex_path); + //~ $EnveloppeVerso->setPdfPath(Config::$pdf_path); + $EnveloppeVerso->makeLatex(); + + if($DocumentPresta !== null) + { + $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); + //~ $DocumentPresta->setData($Client); + //~ $DocumentPresta->setData($Presta); + //~ $DocumentPresta->makeDateInstance($Presta->getDate()); // paramètre = int + //~ $DocumentPresta->setFileName($Presta->getCodePresta() . '.tex'); + //~ $DocumentPresta->setLatexPath(Config::$latex_path . $DocumentPresta->getYear() . '/'); + //~ $DocumentPresta->setPdfPath(Config::$pdf_path . $DocumentPresta->getYear() . '/'); + //~ $DocumentPresta->setData($PrestaDetails); + $DocumentPresta->makeLatex(); + } + + + // création des fichiers + // paramètre = Objet enfant de Latex + makeTexAndPdf($EnveloppeRecto); + makeTexAndPdf($EnveloppeVerso); + + if($DocumentPresta !== null) + { + makeTexAndPdf($DocumentPresta); + } + + + // -- partie 4: récapitulatif -- + + // tableau récaptilatif + // ZenityList + + // imprimer? + //~ $imprimer_facture = exec('zenity --question --width=250 --title="Base de données mise à jour" --text="Imprimer la facture?"'); + //~ $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"'); + + + // -- partie 5: on fait quoi maintenant -- + $choix_niv2 = exec($FinSection2->get()); + if($choix_niv2 === ZenitySetup::$fin_section_2_entrees[0]) + { + return [4, null]; // section 4: getDocument() + } + elseif($choix_niv2 === ZenitySetup::$fin_section_2_entrees[1]) + { + return [3, null]; // section 3: modifyData() + } + elseif($choix_niv2 === ZenitySetup::$fin_section_2_entrees[2]) + { + return [2, null]; // relancer section 2: newService() + } + else + { + return [0, null]; // menu principal + } + + return [0, null]; // menu principal +} diff --git a/src/sections/3_modify_data.php b/src/sections/3_modify_data.php new file mode 100644 index 0000000..cc95468 --- /dev/null +++ b/src/sections/3_modify_data.php @@ -0,0 +1,9 @@ +get()); + if($choix_niv2 === ZenitySetup::$menu_documents_entrees[0]) + { + + } + elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[1]) // = Facture + { + + } + elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[2]) // = Lettre avec adresse + { + + } + elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[3]) // = Livre des recettes + { + + } + elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[4]) // = Registre des achats + { + + } + elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[5]) // = Bilan annuel + { + + } + else + { + return [0, null]; // menu principal + } + + + // -- partie 2: régénérer les documents latex et pdf -- + + + // -- partie 3: afficher -- + + + // -- partie 4: imprimer -- + + + // -- partie 5: on fait quoi maintenant -- + + return [0, null]; // menu principal +} diff --git a/src/sections/main_loop.php b/src/sections/main_loop.php new file mode 100644 index 0000000..7dd1af0 --- /dev/null +++ b/src/sections/main_loop.php @@ -0,0 +1,106 @@ +get()); + } + else + { + $choix_niv1 = ''; + } + + + // -- SECTION 1: Clients et prospects -- + if($choix_niv1 === ZenitySetup::$menu_principal_entrees[0] || $returned[0] === 1) + { + echo("choix: ". ZenitySetup::$menu_principal_entrees[0] . "\n"); + $returned = newCustomer(); + } + + // -- SECTION 2: Prestations et devis -- + elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[1] || $returned[0] === 2) + { + echo("choix: ". ZenitySetup::$menu_principal_entrees[1] . "\n"); + $returned = newService($returned[1]); // $returned[1] vaut un type Clients ou null + } + + // -- SECTION 3: Modifier un enregistrement -- + elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[2] || $returned[0] === 3) + { + echo("choix: " . ZenitySetup::$menu_principal_entrees[2] . "\n"); + $returned = modifyData(); + } + + // -- SECTION 4: Consulter, Imprimer un document -- + elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[3] || $returned[0] === 4) // = Imprimer un document + { + echo("choix: ". ZenitySetup::$menu_principal_entrees[3] . "\n"); + $returned = getDocument(); + } + + // -- SECTION 5: Consulter/analyser les données -- + elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[4] || $returned[0] === 5) + { + echo("choix: ". ZenitySetup::$menu_principal_entrees[4] . "\n"); + // quel affichage? des tableaux avec zenity? LaTeX? une page web? un autre outil servant à faire des tableaux et graphiques + } + + // -- SECTION 6: Supports de communication -- + elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[5] || $returned[0] === 6) // = Communication + { + echo("choix: ". ZenitySetup::$menu_principal_entrees[5] . "\n"); + $MenuCommunication = new ZenityList(ZenitySetup::$menu_communication_text, ZenitySetup::$menu_communication_entrees); + $choix_niv2 = exec($MenuCommunication->get()); + if($choix_niv2 === ZenitySetup::$menu_communication_entrees[0]) // = Flyer (nécessite gimp) + { + exec(windowAppCommand($image_editor, $flyer)); + } + elseif($choix_niv2 === ZenitySetup::$menu_communication_entrees[1]) // = Carte de visite (nécessite scribus) + { + exec(windowAppCommand($publishing, $business_card)); + } + elseif($choix_niv2 === ZenitySetup::$menu_communication_entrees[2]) // = Explorateur de fichiers + { + exec(windowAppCommand($file_explorer, $pub)); + } + else + { + // retour menu principal + } + } + + // -- SECTION 7: BDD -- + elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[6] || $returned[0] === 7) // = Base de données + { + echo("choix: ". ZenitySetup::$menu_principal_entrees[6] . "\n"); + if($sqlitebrowser_enable) + { + exec(windowAppCommand(Config::$sqlite_gui, Config::$db_path)); + } + else + { + exec($x_term_command . ' ' . $sqlite_cli . ' ' . Config::$db_path); // correpond à priori à: xterm -e sqlite3 ~/ORDIPOLO/Appli_PHP/ordipolo.sqlite + } + } + + // arrêt + else + { + $main_loop = false; + } +} diff --git a/src/view/ZenitySetup.php b/src/view/ZenitySetup.php index b6d83f6..d0b785c 100644 --- a/src/view/ZenitySetup.php +++ b/src/view/ZenitySetup.php @@ -8,12 +8,14 @@ class ZenitySetup { static public $menu_principal_text = "Gestion d'une micro-entreprise"; - static public $menu_principal_entrees = ["Nouvelle prestation", "Devis", "Modifier un enregistrement", "Consulter/analyser les données", "Imprimer un document", "Communication", "Base de données"]; - static public $question_nouveau_client_text = "Ce client figure t\'il déjà dans le fichier clients?"; + static public $menu_principal_entrees = ["Clients et prospects", "Prestations et devis", "Modifier un enregistrement", "Consulter, imprimer un document", "Consulter/analyser les données", "Communication", "Base de données"]; + //~ static public $question_nouveau_client_text = "Ce client figure t\'il déjà dans le fichier clients?"; + static public $type_client_text = "Client ou prospect?"; + static public $type_client_entrees = ["Client", "Prospect"]; static public $menu_enregistrement_text = "Type d\'enregistrement?"; //static public $menu_enregistrement_entrees = ["Devis", "Facture", "CESU", "Location", "Prestation non vendue"]; static public $menu_enregistrement_entrees = ["Facture", "CESU", "Location", "Prestation non vendue"]; - static public $menu_documents_text = "Imprimer un document LaTeX"; + static public $menu_documents_text = "Consulter, imprimer un document LaTeX"; static public $menu_documents_entrees = ["Devis", "Facture", "Lettre avec adresse", "Livre des recettes", "Registre des achats", "Bilan annuel"]; static public $menu_communication_text = "Imprimer un support de communication"; static public $menu_communication_entrees = ["Flyer (nécessite gimp)", "Carte de visite (nécessite scribus)", "Explorateur de fichiers"]; @@ -30,5 +32,10 @@ class ZenitySetup static public $commentaire_prestation_text = 'Nouvelle prestation 3/3 - Commentaires'; static public $recapitulatif_text = "voici toutes les informations enregistrées"; static public $recapitulatif_entrees = []; - static public $question_modification_text = "Prestation enregistrée. Modifier les informations?"; + //static public $question_modification_text = "Prestation enregistrée. Modifier les informations?"; + + static public $fin_section_1_text = "Client enregistré"; + static public $fin_section_1_entrees = ["Ajouter une prestation pour ce client", "Modifier les informations", "Enregistrer un autre client", "Menu principal"]; + static public $fin_section_2_text = "Prestation/devis enregistré(e)"; + static public $fin_section_2_entrees = ["Afficher le document", "Modifier les informations", "Enregistrer une autre prestation/devis", "Menu principal"]; } -- cgit v1.2.3