diff options
| author | polo <ordipolo@gmx.fr> | 2023-07-22 12:29:47 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2023-07-22 12:29:47 +0200 |
| commit | 747674b450d6840ce9bd9aecd765cf31445ef8d3 (patch) | |
| tree | 46e47fd65c751e1951d9aa8438aea1b8c2d8aece /src/sections/2_service.php | |
| parent | 9bdfb5196a2ee1cbfc403702e8d2ef88076d366f (diff) | |
| download | AppliGestionPHP-747674b450d6840ce9bd9aecd765cf31445ef8d3.tar.gz AppliGestionPHP-747674b450d6840ce9bd9aecd765cf31445ef8d3.tar.bz2 AppliGestionPHP-747674b450d6840ce9bd9aecd765cf31445ef8d3.zip | |
navigation entre sections, boucle principale, client ou prospect
Diffstat (limited to 'src/sections/2_service.php')
| -rw-r--r-- | src/sections/2_service.php | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/src/sections/2_service.php b/src/sections/2_service.php new file mode 100644 index 0000000..8109b31 --- /dev/null +++ b/src/sections/2_service.php | |||
| @@ -0,0 +1,229 @@ | |||
| 1 | <?php | ||
| 2 | // src/sections/2_service.php | ||
| 3 | // | ||
| 4 | // -- SECTION 2: Prestation et devis -- | ||
| 5 | |||
| 6 | function newService($Client): array // $Client est un Client ou null | ||
| 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 | $FinSection2 = new ZenityList(ZenitySetup::$fin_section_2_text, ZenitySetup::$fin_section_2_entrees); | ||
| 19 | |||
| 20 | |||
| 21 | // -- partie 1: le client -- | ||
| 22 | if($Client == null || get_class($Client) !== 'Clients') | ||
| 23 | { | ||
| 24 | $Client = makeObjectClient(); // retourne 0 ou un objet "Clients" | ||
| 25 | if($Client == 0) | ||
| 26 | { | ||
| 27 | echo "debug: annulation sélection client\n"; | ||
| 28 | return [0, null]; // menu principal | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | |||
| 33 | // -- partie 2: la prestation -- | ||
| 34 | |||
| 35 | // niveau 2: type comptable d'enregistrement: devis, facture, cesu, location ou pas de prestation | ||
| 36 | $choix_niv2 = exec($MenuEnregistrement->get()); | ||
| 37 | if($choix_niv2 === '') | ||
| 38 | { | ||
| 39 | echo "debug: annulation menu enregistrement\n"; | ||
| 40 | return [0, null]; // menu principal | ||
| 41 | } | ||
| 42 | |||
| 43 | $Presta = new Prestations($Client->getID()); | ||
| 44 | |||
| 45 | // détail de la prestation | ||
| 46 | // calendrier - étape 1/3 | ||
| 47 | $Date = new Dates(exec($Calendrier->get())); // exec() renvoie soit une chaîne soit un false | ||
| 48 | if($Date->getDate() == '') // on n'a pas cliqué sur "annuler" | ||
| 49 | { | ||
| 50 | echo "debug: annulation à la saisie d'une date\n"; | ||
| 51 | return [0, null]; // menu principal | ||
| 52 | } | ||
| 53 | |||
| 54 | $Presta->setDate($Date->getTimestamp()); // un entier pour la BDD | ||
| 55 | |||
| 56 | switch($choix_niv2) | ||
| 57 | { | ||
| 58 | // formulaire - étape 2/3 | ||
| 59 | //~ case ZenitySetup::$menu_enregistrement_entrees[0]: // "Devis" | ||
| 60 | //~ $PrestaDetails = new DevisFactures('devis'); | ||
| 61 | //~ $Presta->setTypePresta('devis'); | ||
| 62 | //~ $input = exec($FormulaireDevis->get()); | ||
| 63 | //~ break; | ||
| 64 | case ZenitySetup::$menu_enregistrement_entrees[0]: // "Facture" | ||
| 65 | $PrestaDetails = new DevisFactures('factures'); // 'factures' est le nom de la table, pas le type de presta | ||
| 66 | $Presta->setTypePresta('facture'); | ||
| 67 | $input =exec($FormulaireFacture->get()); | ||
| 68 | break; | ||
| 69 | case ZenitySetup::$menu_enregistrement_entrees[1]: // "CESU" | ||
| 70 | $PrestaDetails = new CESU(); | ||
| 71 | $Presta->setTypePresta('cesu'); | ||
| 72 | $input = exec($FormulaireCesu->get()); | ||
| 73 | break; | ||
| 74 | case ZenitySetup::$menu_enregistrement_entrees[2]: // "Location" | ||
| 75 | $PrestaDetails = new Locations(); | ||
| 76 | $Presta->setTypePresta('location'); | ||
| 77 | $input = exec($FormulaireLocation->get()); | ||
| 78 | break; | ||
| 79 | case ZenitySetup::$menu_enregistrement_entrees[3]: // "Prestation non vendue" | ||
| 80 | $Presta->setTypePresta('non_vendue'); | ||
| 81 | break; | ||
| 82 | default: // inutile normallement, cas déjà géré avant | ||
| 83 | echo "debug: sortie du menu enregistrement incorrect\n"; | ||
| 84 | return [0, null]; | ||
| 85 | } | ||
| 86 | |||
| 87 | $Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre | ||
| 88 | |||
| 89 | if($choix_niv2 != ZenitySetup::$menu_enregistrement_entrees[3]) // si presta non vendue, saut étape 3/3 | ||
| 90 | { | ||
| 91 | if($input == '') // annulation | ||
| 92 | { | ||
| 93 | echo "debug: annulation lors de l'enregistrement des détails de la prestation\n"; | ||
| 94 | return [0, null]; | ||
| 95 | } | ||
| 96 | elseif(isset($PrestaDetails) && !$PrestaDetails->hydrateFromForm($input, $Presta)) // echec de l'hydratation | ||
| 97 | { | ||
| 98 | echo "debug: erreur de hydrateFromForm()\n"; // messages d'erreur à mettre ici ou dans hydrateFromForm()? | ||
| 99 | return [0, null]; | ||
| 100 | } | ||
| 101 | unset($input); | ||
| 102 | } | ||
| 103 | |||
| 104 | // commentaire - étape 3/3 | ||
| 105 | $input = exec($CommentairePrestation->get()); | ||
| 106 | if($input == '') | ||
| 107 | { | ||
| 108 | echo "debug: pas de commentaire saisi\n"; | ||
| 109 | // on n'interrompt pas le script et on enregistre dans tous les cas (annulatation, chaîne vide) | ||
| 110 | } | ||
| 111 | // Cliquer sur annuler (ou appuyer sur échap) revient dont à valider avec une chaîne vide et enregistrer la prestation | ||
| 112 | // la commande 'echo $?' ($? est le code de sortie de la commande précédente) renvoit 1 si on annule avec la touche échap () | ||
| 113 | // 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) | ||
| 114 | // 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 | ||
| 115 | // 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) | ||
| 116 | // 2>&1 semble inutile, pas de sortie d'erreur de zenity --entry | ||
| 117 | //~ if(exec('echo $?') != 1) | ||
| 118 | //~ { | ||
| 119 | //~ echo "debug: annulation à la saisie d'un commentaire\n"; | ||
| 120 | //~ return 0; | ||
| 121 | //~ } | ||
| 122 | $Presta->setCommentaires($input); | ||
| 123 | unset($input); | ||
| 124 | |||
| 125 | $Presta->create(); | ||
| 126 | $Presta->setID(); // sans paramètre, exécute un $this->db->lastInsertId() | ||
| 127 | |||
| 128 | if(isset($PrestaDetails)) // presta non vendue | ||
| 129 | { | ||
| 130 | $PrestaDetails->setIDPresta($Presta->getID()); // d'un objet à l'autre | ||
| 131 | $PrestaDetails->create(); | ||
| 132 | $PrestaDetails->setID(); // sans paramètre, exécute un $this->db->lastInsertId() | ||
| 133 | } | ||
| 134 | |||
| 135 | // si encore de type prospect, devient un type client | ||
| 136 | //$Client->setType('client'); // inutile? | ||
| 137 | $Client->updateOneValue('type', 'client'); // modifier le type prospect en client | ||
| 138 | |||
| 139 | |||
| 140 | // -- partie 3: LaTeX -- | ||
| 141 | |||
| 142 | //makeLatexAndPdfDocuments($Client, $Presta, $PrestaDetails); | ||
| 143 | // factoriser tout ça | ||
| 144 | /* plusieurs parties: | ||
| 145 | * - une fonction ou on crée et manipule les objets (une classe par type de document) | ||
| 146 | * - manipulation des données | ||
| 147 | * - chemins et noms de fichiers | ||
| 148 | * - insertion des variables | ||
| 149 | * - écriture du fichier (+ dossier si nécessaire) | ||
| 150 | */ | ||
| 151 | // et pour bien faire ajouter aussi une interface | ||
| 152 | |||
| 153 | //~ function makeLatexSubClass(string $type) | ||
| 154 | //~ {} | ||
| 155 | |||
| 156 | // fabrique d'objets (sans connaître les noms des classes) | ||
| 157 | $EnveloppeRecto = Latex::makeLatexSubClass('enveloppe_recto'); | ||
| 158 | $EnveloppeVerso = Latex::makeLatexSubClass('enveloppe_verso'); | ||
| 159 | $DocumentPresta = Latex::makeLatexSubClass($Presta->getTypePresta()); // $type = facture, devis, location | ||
| 160 | |||
| 161 | // génération du latex | ||
| 162 | $EnveloppeRecto->setData($Client); | ||
| 163 | //~ $EnveloppeRecto->setFileName($Client->getCodeClient() . '.tex'); | ||
| 164 | //~ $EnveloppeRecto->setLatexPath(Config::$latex_path . 'enveloppes_recto/'); | ||
| 165 | //~ $EnveloppeRecto->setPdfPath(Config::$pdf_path . 'enveloppes_recto/'); | ||
| 166 | //~ $EnveloppeRecto->spacesInPostCode(); | ||
| 167 | $EnveloppeRecto->makeLatex(); | ||
| 168 | |||
| 169 | //~ $EnveloppeVerso->setFileName('enveloppe_verso.tex'); | ||
| 170 | //~ $EnveloppeVerso->setLatexPath(Config::$latex_path); | ||
| 171 | //~ $EnveloppeVerso->setPdfPath(Config::$pdf_path); | ||
| 172 | $EnveloppeVerso->makeLatex(); | ||
| 173 | |||
| 174 | if($DocumentPresta !== null) | ||
| 175 | { | ||
| 176 | $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); | ||
| 177 | //~ $DocumentPresta->setData($Client); | ||
| 178 | //~ $DocumentPresta->setData($Presta); | ||
| 179 | //~ $DocumentPresta->makeDateInstance($Presta->getDate()); // paramètre = int | ||
| 180 | //~ $DocumentPresta->setFileName($Presta->getCodePresta() . '.tex'); | ||
| 181 | //~ $DocumentPresta->setLatexPath(Config::$latex_path . $DocumentPresta->getYear() . '/'); | ||
| 182 | //~ $DocumentPresta->setPdfPath(Config::$pdf_path . $DocumentPresta->getYear() . '/'); | ||
| 183 | //~ $DocumentPresta->setData($PrestaDetails); | ||
| 184 | $DocumentPresta->makeLatex(); | ||
| 185 | } | ||
| 186 | |||
| 187 | |||
| 188 | // création des fichiers | ||
| 189 | // paramètre = Objet enfant de Latex | ||
| 190 | makeTexAndPdf($EnveloppeRecto); | ||
| 191 | makeTexAndPdf($EnveloppeVerso); | ||
| 192 | |||
| 193 | if($DocumentPresta !== null) | ||
| 194 | { | ||
| 195 | makeTexAndPdf($DocumentPresta); | ||
| 196 | } | ||
| 197 | |||
| 198 | |||
| 199 | // -- partie 4: récapitulatif -- | ||
| 200 | |||
| 201 | // tableau récaptilatif | ||
| 202 | // ZenityList | ||
| 203 | |||
| 204 | // imprimer? | ||
| 205 | //~ $imprimer_facture = exec('zenity --question --width=250 --title="Base de données mise à jour" --text="Imprimer la facture?"'); | ||
| 206 | //~ $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"'); | ||
| 207 | |||
| 208 | |||
| 209 | // -- partie 5: on fait quoi maintenant -- | ||
| 210 | $choix_niv2 = exec($FinSection2->get()); | ||
| 211 | if($choix_niv2 === ZenitySetup::$fin_section_2_entrees[0]) | ||
| 212 | { | ||
| 213 | return [4, null]; // section 4: getDocument() | ||
| 214 | } | ||
| 215 | elseif($choix_niv2 === ZenitySetup::$fin_section_2_entrees[1]) | ||
| 216 | { | ||
| 217 | return [3, null]; // section 3: modifyData() | ||
| 218 | } | ||
| 219 | elseif($choix_niv2 === ZenitySetup::$fin_section_2_entrees[2]) | ||
| 220 | { | ||
| 221 | return [2, null]; // relancer section 2: newService() | ||
| 222 | } | ||
| 223 | else | ||
| 224 | { | ||
| 225 | return [0, null]; // menu principal | ||
| 226 | } | ||
| 227 | |||
| 228 | return [0, null]; // menu principal | ||
| 229 | } | ||
