diff options
| author | polo <ordipolo@gmx.fr> | 2022-12-28 05:19:55 +0100 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2022-12-28 05:19:55 +0100 |
| commit | 1894fc377e6b938ea34df9980567a1634ec6ef48 (patch) | |
| tree | 812db64208797ecbdabbc9673a5247fbc18ebf8b /src/sections/1_new_service.php | |
| parent | 7d564efbccc4b361d2fa2db2902fb35882304aae (diff) | |
| download | AppliGestionPHP-1894fc377e6b938ea34df9980567a1634ec6ef48.tar.gz AppliGestionPHP-1894fc377e6b938ea34df9980567a1634ec6ef48.tar.bz2 AppliGestionPHP-1894fc377e6b938ea34df9980567a1634ec6ef48.zip | |
réorganisation + bientôt finie la section 1
Diffstat (limited to 'src/sections/1_new_service.php')
| -rw-r--r-- | src/sections/1_new_service.php | 241 |
1 files changed, 241 insertions, 0 deletions
diff --git a/src/sections/1_new_service.php b/src/sections/1_new_service.php new file mode 100644 index 0000000..172402a --- /dev/null +++ b/src/sections/1_new_service.php | |||
| @@ -0,0 +1,241 @@ | |||
| 1 | <?php | ||
| 2 | // sections/1_new_service.php | ||
| 3 | // | ||
| 4 | // -- SECTION 1: Nouvelle prestation -- | ||
| 5 | |||
| 6 | function newService() | ||
| 7 | { | ||
| 8 | // fenêtres | ||
| 9 | $QuestionNouveauClient = new ZenityQuestion(ZenitySetup::$question_nouveau_client_text); | ||
| 10 | $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client_text); | ||
| 11 | $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client_text, []); | ||
| 12 | $NouveauClient = new ZenityForms(ZenitySetup::$nouveau_client_text, ZenitySetup::$nouveau_client_entrees); | ||
| 13 | $MenuEnregistrement = new ZenityList(ZenitySetup::$menu_enregistrement_text, ZenitySetup::$menu_enregistrement_entrees); | ||
| 14 | $Calendrier = new ZenityCalendar(ZenitySetup::$calendar_text); | ||
| 15 | $FormulaireDevis = new ZenityForms(ZenitySetup::$formulaire_text, array_merge(ZenitySetup::$formulaire_devis_entrees, ZenitySetup::$formulaire_facture_entrees)); | ||
| 16 | $FormulaireFacture = new ZenityForms(ZenitySetup::$formulaire_text, ZenitySetup::$formulaire_facture_entrees); | ||
| 17 | $FormulaireCesu = new ZenityForms(ZenitySetup::$formulaire_text, ZenitySetup::$formulaire_cesu_entrees); | ||
| 18 | $FormulaireLocation = new ZenityForms(ZenitySetup::$formulaire_text, ZenitySetup::$formulaire_location_entrees); | ||
| 19 | $CommentairePrestation = new ZenityEntry(ZenitySetup::$commentaire_prestation_text); | ||
| 20 | |||
| 21 | $Client = new Clients; // modèle de la table 'clients' | ||
| 22 | |||
| 23 | $continuer = false; | ||
| 24 | // niveau 2: est ce que le client est déjà dans la base? | ||
| 25 | if(exec($QuestionNouveauClient->get()) == '0') // $? = 0 signifie oui, double égal == pour le transtypage | ||
| 26 | { | ||
| 27 | echo "debug: recherche souhaitée\n"; | ||
| 28 | |||
| 29 | // niveau 3: saisie du nom du client | ||
| 30 | $nom_client = exec($RechercheClient->get()); | ||
| 31 | if($nom_client !== '') | ||
| 32 | { | ||
| 33 | echo "debug: recherche effectuée\n"; | ||
| 34 | $ResultatsRechercheClient->setListRows(rechercheClient($nom_client, $Client), $Client->getTable()); // recherche silencieuse | ||
| 35 | unset($nom_client); | ||
| 36 | |||
| 37 | // niveau 4: sélection parmi les résultats | ||
| 38 | $choix_niv4 = exec($ResultatsRechercheClient->get()); // renvoie l'ID de la table 'clients' | ||
| 39 | $ResultatsRechercheClient->cleanCommand(); | ||
| 40 | |||
| 41 | if($choix_niv4 !== '') | ||
| 42 | { | ||
| 43 | echo "debug: client sélectionné\n"; | ||
| 44 | $Client->hydrate($Client->findById($choix_niv4)); | ||
| 45 | $continuer = true; | ||
| 46 | } | ||
| 47 | else | ||
| 48 | { | ||
| 49 | echo "debug: client pas trouvé ou pas sélectionné\n"; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | else | ||
| 53 | { | ||
| 54 | echo "debug: recherche annulée ou saisie vide\n"; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | else | ||
| 58 | { | ||
| 59 | echo "debug: nouveau client\n"; | ||
| 60 | } | ||
| 61 | |||
| 62 | // niveau 2: on n'a pas cherché OU on n'a pas trouvé | ||
| 63 | if(!$continuer) | ||
| 64 | { | ||
| 65 | $data_string = exec($NouveauClient->get()); | ||
| 66 | //~ $data_array = explode('|', $data_string); | ||
| 67 | //~ if(controlFormInput($data_array)) | ||
| 68 | //~ { | ||
| 69 | //~ $Client->newRow($data_array); // écriture dans la BDD | ||
| 70 | //~ $continuer = true; | ||
| 71 | //~ } | ||
| 72 | |||
| 73 | if($data_string !== '') | ||
| 74 | { | ||
| 75 | $data_array = explode('|', $data_string); | ||
| 76 | $data_string = ''; // nettoyage | ||
| 77 | |||
| 78 | if(count($data_array) === count(StructTablesDB::$structureOfTables[$Client->getTable()]) - 1) | ||
| 79 | { | ||
| 80 | if($data_array[0] != "") // le champ "prenom_nom" ne doit pas être vide | ||
| 81 | { | ||
| 82 | $Client->newRow($data_array); // écriture dans la BDD | ||
| 83 | $continuer = true; | ||
| 84 | } | ||
| 85 | else | ||
| 86 | { | ||
| 87 | echo "debug: données insuffisantes, le nom du client doit au minimum être renseigné\n"; | ||
| 88 | $continuer = false; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | else | ||
| 92 | { | ||
| 93 | echo "debug: le nombre d'informations à enregistrer du nombre de champs à renseigner dans la table\n"; | ||
| 94 | $continuer = false; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | else | ||
| 98 | { | ||
| 99 | echo "debug: annulation lors du formulaire\n"; | ||
| 100 | $continuer = false; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | // niveau 2: type comptable d'enregistrement: devis, facture, cesu, location ou pas de prestation | ||
| 105 | if($continuer) | ||
| 106 | { | ||
| 107 | $choix_niv2 = exec($MenuEnregistrement->get()); | ||
| 108 | $continuer = false; | ||
| 109 | $Presta = new Prestations($Client->getID()); | ||
| 110 | |||
| 111 | switch($choix_niv2) | ||
| 112 | { | ||
| 113 | case ZenitySetup::$menu_enregistrement_entrees[0]: // "Devis" | ||
| 114 | $DetailsPresta = new DevisFactures($Client->getID()); | ||
| 115 | $Presta->setTypePresta('devis'); | ||
| 116 | $continuer = true; | ||
| 117 | break; | ||
| 118 | case ZenitySetup::$menu_enregistrement_entrees[1]: // "Facture" | ||
| 119 | $DetailsPresta = new DevisFactures($Client->getID()); | ||
| 120 | $Presta->setTypePresta('facture'); | ||
| 121 | $continuer = true; | ||
| 122 | break; | ||
| 123 | case ZenitySetup::$menu_enregistrement_entrees[2]: // "CESU" | ||
| 124 | $DetailsPresta = new CESU($Client->getID()); | ||
| 125 | $Presta->setTypePresta('cesu'); | ||
| 126 | $continuer = true; | ||
| 127 | break; | ||
| 128 | case ZenitySetup::$menu_enregistrement_entrees[3]: // "Location" | ||
| 129 | $DetailsPresta = new Locations($Client->getID()); | ||
| 130 | $Presta->setTypePresta('location'); | ||
| 131 | $continuer = true; | ||
| 132 | break; | ||
| 133 | case ZenitySetup::$menu_enregistrement_entrees[4]: // "non_vendue" | ||
| 134 | // objet $Presta uniquement | ||
| 135 | $Presta->setTypePresta('non_vendue'); | ||
| 136 | $continuer = true; | ||
| 137 | break; | ||
| 138 | default: | ||
| 139 | $continuer = false; // annulation, retour menu principal | ||
| 140 | } | ||
| 141 | |||
| 142 | if($continuer) | ||
| 143 | { | ||
| 144 | // niveau 3: détail de la prestation | ||
| 145 | // noter que exec() renvoie toujours une chaîne, sauf en cas d'erreur où il renvoie un "false" | ||
| 146 | $Date = new Dates(exec($Calendrier->get())); | ||
| 147 | if($Date->getDate() !== '') // on n'a pas cliqué sur "annuler" | ||
| 148 | { | ||
| 149 | $Presta->setDate($Date->getTimestamp()); // un entier pour la BDD | ||
| 150 | $Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre | ||
| 151 | |||
| 152 | // on continue si le formulaire précédent a été rempli | ||
| 153 | switch($choix_niv2) | ||
| 154 | { | ||
| 155 | case $Presta->getType = 'devis'; | ||
| 156 | $data_string = exec($FormulaireDevis->get()); | ||
| 157 | break; | ||
| 158 | case $Presta->getType = 'facture'; | ||
| 159 | $data_string = exec($FormulaireFacture->get()); // tester si c'est vide ou clic sur 'Annuler' | ||
| 160 | break; | ||
| 161 | case $Presta->getType = 'cesu'; | ||
| 162 | $data_string = exec($FormulaireCesu->get()); | ||
| 163 | break; | ||
| 164 | case $Presta->getType = 'location'; | ||
| 165 | $data_string = exec($FormulaireLocation->get()); | ||
| 166 | break; | ||
| 167 | case $data_string->getType = 'non_vendue'; | ||
| 168 | // ne rien faire | ||
| 169 | break; | ||
| 170 | default: | ||
| 171 | $continuer = false; // annulation, retour menu principal | ||
| 172 | } | ||
| 173 | |||
| 174 | if($continuer) | ||
| 175 | { | ||
| 176 | // dans $Presta | ||
| 177 | $comment = exec($CommentairePrestation->get()); | ||
| 178 | if(!empty($comment)) | ||
| 179 | { | ||
| 180 | $Presta->setCommentaires($comment); | ||
| 181 | } | ||
| 182 | else | ||
| 183 | { | ||
| 184 | $continuer = false; // annulation, retour menu principal | ||
| 185 | } | ||
| 186 | } | ||
| 187 | } | ||
| 188 | $Presta->create(); | ||
| 189 | $Presta->setIDPresta(); // sans paramètre pour récupérer le dernier ID inséré | ||
| 190 | |||
| 191 | if($data_string !== '') | ||
| 192 | { | ||
| 193 | $data_array = explode('|', $data_string); | ||
| 194 | |||
| 195 | if(count($data_array) === count(StructTablesDB::$structureOfTables[$DetailsPresta->getTable()]) - 1) | ||
| 196 | { | ||
| 197 | if($data_array[0] != "") // le champ "prenom_nom" ne doit pas être vide | ||
| 198 | { | ||
| 199 | $DetailsPresta->newRow($data_array); // INSUFFISANT | ||
| 200 | $continuer = true; | ||
| 201 | } | ||
| 202 | else | ||
| 203 | { | ||
| 204 | echo "debug: données insuffisantes, le nom du client doit au minimum être renseigné\n"; | ||
| 205 | $continuer = false; | ||
| 206 | } | ||
| 207 | } | ||
| 208 | else | ||
| 209 | { | ||
| 210 | echo "debug: le nombre d'informations à enregistrer du nombre de champs à renseigner dans la table\n"; | ||
| 211 | $continuer = false; | ||
| 212 | } | ||
| 213 | } | ||
| 214 | else | ||
| 215 | { | ||
| 216 | echo "debug: annulation lors du formulaire\n"; | ||
| 217 | $continuer = false; | ||
| 218 | } | ||
| 219 | $DetailsPresta->setIDPresta($Presta->getIDPresta()); // d'un objet à l'autre | ||
| 220 | $DetailsPresta->create(); | ||
| 221 | |||
| 222 | |||
| 223 | // tableau récaptilatif, possibilité de modification | ||
| 224 | //ZenityList | ||
| 225 | |||
| 226 | |||
| 227 | // création fichiers LaTeX et PDF | ||
| 228 | //~ $latex_path = '../data/latex/'; // noms de variables dans le config.php | ||
| 229 | //~ $file_name = 'devis.tex'; | ||
| 230 | //~ $template = 'devis'; // vaut 'devis' ou 'enveloppe_recto' ou 'enveloppe_verso' ou 'facture' ou 'location' | ||
| 231 | //~ $latex = getLatexFromTemplate($template); | ||
| 232 | //~ file_put_contents($latex_path . $file_name, $latex); // injection des variables & écriture du fichier | ||
| 233 | //~ $pdf_path = '../data/pdf/'; | ||
| 234 | //~ latexToPdf($latex_path, $file_name, $pdf_path); | ||
| 235 | |||
| 236 | // imprimer? | ||
| 237 | //~ $imprimer_facture = exec('zenity --question --width=250 --title="Base de données mise à jour" --text="Imprimer la facture?"'); | ||
| 238 | //~ $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"'); | ||
| 239 | } | ||
| 240 | } | ||
| 241 | } | ||
