diff options
| author | polo <ordipolo@gmx.fr> | 2023-01-10 13:08:54 +0100 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2023-01-10 13:08:54 +0100 |
| commit | 945af9fda5146405ab9903d4d268bcb2fe95da25 (patch) | |
| tree | 0c3af5ae3e4068e65c3e066c83c7d72058339a7d /src | |
| parent | 1894fc377e6b938ea34df9980567a1634ec6ef48 (diff) | |
| download | AppliGestionPHP-945af9fda5146405ab9903d4d268bcb2fe95da25.tar.gz AppliGestionPHP-945af9fda5146405ab9903d4d268bcb2fe95da25.tar.bz2 AppliGestionPHP-945af9fda5146405ab9903d4d268bcb2fe95da25.zip | |
enregistrement section 1
Diffstat (limited to 'src')
| -rw-r--r-- | src/functions.php | 35 | ||||
| -rwxr-xr-x | src/main.php | 37 | ||||
| -rw-r--r-- | src/model/Clients.php | 65 | ||||
| -rw-r--r-- | src/model/DevisFactures.php | 102 | ||||
| -rw-r--r-- | src/model/Model.php | 30 | ||||
| -rw-r--r-- | src/model/Prestations.php | 73 | ||||
| -rw-r--r-- | src/model/StructTablesDB.php | 3 | ||||
| -rw-r--r-- | src/model/traits.php | 83 | ||||
| -rw-r--r-- | src/sections/1_new_service.php | 354 | ||||
| -rw-r--r-- | src/sections/2_modify_service.php | 9 | ||||
| -rw-r--r-- | src/view/ZenitySetup.php | 9 |
11 files changed, 417 insertions, 383 deletions
diff --git a/src/functions.php b/src/functions.php index bdcd594..0ec280f 100644 --- a/src/functions.php +++ b/src/functions.php | |||
| @@ -22,42 +22,17 @@ function windowAppCommand(string $app, string $path = ''): string | |||
| 22 | return $command; | 22 | return $command; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | function rechercheClient(string $input, Clients $Client): array | ||
| 26 | { | ||
| 27 | $input_array = explode(' ', $input); // si plusieurs mot, on les recherche tous l'un après l'autre | ||
| 28 | |||
| 29 | $result = $Client->findByKeywords($input_array, 'prenom_nom'); // on obtient un tableau à deux dimensions avec les entrées trouvées | ||
| 30 | return($result); | ||
| 31 | } | ||
| 32 | |||
| 33 | // NOTE 1: en PHP les objets sont passés aux fonctions par référence par défaut, toutefois ce n'est pas entièrement vrai | 25 | // NOTE 1: en PHP les objets sont passés aux fonctions par référence par défaut, toutefois ce n'est pas entièrement vrai |
| 34 | // NOTE 2: PHP n'a pas de pointeur mais des références, une référence est un alias qui ne contient pas l'objet lui-même | 26 | // NOTE 2: PHP n'a pas de pointeur mais des références, une référence est un alias qui ne contient pas l'objet lui-même |
| 35 | // NOTE 3: la variable créée lors d'un "new" est elle-même une référence contenant un identifiant (= le pointeur?) | 27 | // NOTE 3: la variable créée lors d'un "new" est elle-même une référence contenant un identifiant (= le pointeur?) |
| 36 | // NOTE 4: l'objet est détruit lorsque la dernière référence est supprimée | 28 | // NOTE 4: l'objet est détruit lorsque la dernière référence est supprimée |
| 37 | 29 | ||
| 38 | function controlFormInput(array $data): bool | 30 | function rechercheClient(string $input, Clients $Client): array |
| 39 | { | 31 | { |
| 40 | $tableSize = count(StructTablesDB::$structureOfTables[$table]); // int | 32 | $input_array = explode(' ', $input); // si plusieurs mot, on les recherche tous l'un après l'autre |
| 41 | if($data !== '') | 33 | |
| 42 | { | 34 | $result = $Client->findByKeywords($input_array, 'prenom_nom'); // on obtient un tableau à deux dimensions avec les entrées trouvées |
| 43 | $dataArray = explode('|', $data); | 35 | return($result); |
| 44 | |||
| 45 | if(count($dataArray) === $tableSize - 1) // nombre de champs sauf ID qui est auto-incrémenté automatiquement | ||
| 46 | { | ||
| 47 | |||
| 48 | |||
| 49 | } | ||
| 50 | else | ||
| 51 | { | ||
| 52 | echo "debug: mauvais tableau, il doit avoir " . $tableSize - 1 . " cases\n"; | ||
| 53 | return false; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | else | ||
| 57 | { | ||
| 58 | echo "debug: pas de données saisies\n"; | ||
| 59 | return false; | ||
| 60 | } | ||
| 61 | } | 36 | } |
| 62 | 37 | ||
| 63 | function getLatexFromTemplate(string $template) | 38 | function getLatexFromTemplate(string $template) |
diff --git a/src/main.php b/src/main.php index 12715f3..0a8ae09 100755 --- a/src/main.php +++ b/src/main.php | |||
| @@ -43,38 +43,49 @@ require('view/ZenitySetup.php'); // texte dans les fenêtres ET instanciation (u | |||
| 43 | require('Latex.php'); // générer le code LaTeX | 43 | require('Latex.php'); // générer le code LaTeX |
| 44 | 44 | ||
| 45 | require('sections/1_new_service.php'); | 45 | require('sections/1_new_service.php'); |
| 46 | 46 | require('sections/2_modify_service.php'); | |
| 47 | 47 | ||
| 48 | // boucle principale | 48 | // boucle principale |
| 49 | $boucle = true; | 49 | $boucle = true; |
| 50 | $code_retour = 0; // 0 dirige vers le menu principal, 1 vers la section 1, etc | ||
| 50 | while($boucle) | 51 | while($boucle) |
| 51 | { | 52 | { |
| 52 | // niveau 1: menu principal | 53 | // niveau 1: menu principal |
| 53 | $MenuPrincipal = new ZenityList(ZenitySetup::$menu_principal_text, ZenitySetup::$menu_principal_entrees); | 54 | if($code_retour === 0) |
| 54 | $choix_niv1 = exec($MenuPrincipal->get()); | 55 | { |
| 56 | $MenuPrincipal = new ZenityList(ZenitySetup::$menu_principal_text, ZenitySetup::$menu_principal_entrees); | ||
| 57 | $choix_niv1 = exec($MenuPrincipal->get()); | ||
| 58 | } | ||
| 59 | else | ||
| 60 | { | ||
| 61 | $choix_niv1 = ''; | ||
| 62 | } | ||
| 63 | |||
| 55 | 64 | ||
| 56 | // -- SECTION 1: Nouvelle prestation -- | 65 | // -- SECTION 1: Nouvelle prestation -- |
| 57 | if($choix_niv1 === ZenitySetup::$menu_principal_entrees[0]) | 66 | if($choix_niv1 === ZenitySetup::$menu_principal_entrees[0] || $code_retour === 1) |
| 58 | { | 67 | { |
| 59 | echo("choix: $choix_niv1\n"); | 68 | echo("choix: $choix_niv1\n"); |
| 60 | newService(); | 69 | $code_retour = newService(); |
| 70 | echo "hello, code retour: " . $code_retour . "\n"; | ||
| 61 | } | 71 | } |
| 62 | 72 | ||
| 63 | // -- SECTION 2: Modifier un enregistrement -- | 73 | // -- SECTION 2: Modifier un enregistrement -- |
| 64 | elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[1]) | 74 | elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[1] || $code_retour === 2) |
| 65 | { | 75 | { |
| 66 | echo("choix: $choix_niv1\n"); | 76 | echo("choix: $choix_niv1\n"); |
| 77 | $code_retour = modifyService(); | ||
| 67 | } | 78 | } |
| 68 | 79 | ||
| 69 | // -- SECTION 3: Fichier clients -- | 80 | // -- SECTION 3: Consulter/analyser les données -- |
| 70 | elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[2]) | 81 | elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[2] || $code_retour === 3) |
| 71 | { | 82 | { |
| 72 | echo("choix: $choix_niv1\n"); | 83 | echo("choix: $choix_niv1\n"); |
| 73 | // quel affichage? un grand tableau avec zenity? une page web? un document LaTeX? | 84 | // quel affichage? des tableaux avec zenity? LaTeX? une page web? un autre outil servant à faire des tableaux et graphiques |
| 74 | } | 85 | } |
| 75 | 86 | ||
| 76 | // -- SECTION 4: documents à imprimer -- | 87 | // -- SECTION 4: Imprimer -- |
| 77 | elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[3]) // = Créer/imprimer un document | 88 | elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[3] || $code_retour === 4) // = Imprimer un document |
| 78 | { | 89 | { |
| 79 | echo("choix: $choix_niv1\n"); | 90 | echo("choix: $choix_niv1\n"); |
| 80 | $MenuDocuments = new ZenityList(ZenitySetup::$menu_documents_text, ZenitySetup::$menu_documents_entrees); | 91 | $MenuDocuments = new ZenityList(ZenitySetup::$menu_documents_text, ZenitySetup::$menu_documents_entrees); |
| @@ -110,7 +121,7 @@ while($boucle) | |||
| 110 | } | 121 | } |
| 111 | 122 | ||
| 112 | // -- SECTION 5: Supports de communication -- | 123 | // -- SECTION 5: Supports de communication -- |
| 113 | elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[4]) // = Communication | 124 | elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[4] || $code_retour === 5) // = Communication |
| 114 | { | 125 | { |
| 115 | echo("choix: $choix_niv1\n"); | 126 | echo("choix: $choix_niv1\n"); |
| 116 | $MenuCommunication = new ZenityList(ZenitySetup::$menu_communication_text, ZenitySetup::$menu_communication_entrees); | 127 | $MenuCommunication = new ZenityList(ZenitySetup::$menu_communication_text, ZenitySetup::$menu_communication_entrees); |
| @@ -134,7 +145,7 @@ while($boucle) | |||
| 134 | } | 145 | } |
| 135 | 146 | ||
| 136 | // -- SECTION 6: BDD -- | 147 | // -- SECTION 6: BDD -- |
| 137 | elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[5]) // = Base de données | 148 | elseif($choix_niv1 === ZenitySetup::$menu_principal_entrees[5] || $code_retour === 6) // = Base de données |
| 138 | { | 149 | { |
| 139 | echo("choix: $choix_niv1\n"); | 150 | echo("choix: $choix_niv1\n"); |
| 140 | if($sqlitebrowser_enable) | 151 | if($sqlitebrowser_enable) |
diff --git a/src/model/Clients.php b/src/model/Clients.php index aeb39c1..9661562 100644 --- a/src/model/Clients.php +++ b/src/model/Clients.php | |||
| @@ -5,18 +5,18 @@ class Clients extends Model | |||
| 5 | { | 5 | { |
| 6 | // lecture des données ou hydratation | 6 | // lecture des données ou hydratation |
| 7 | protected $ID; // auto-incrémentée | 7 | protected $ID; // auto-incrémentée |
| 8 | protected $prenom_nom = ''; | 8 | protected $prenom_nom; |
| 9 | protected $code_client = ''; | 9 | protected $code_client; |
| 10 | protected $adresse = ''; | 10 | protected $adresse; |
| 11 | protected $telephone = ''; | 11 | protected $telephone; |
| 12 | protected $courriel = ''; | 12 | protected $courriel; |
| 13 | protected $commentaires = ''; | 13 | protected $commentaires; |
| 14 | 14 | ||
| 15 | use ModelChildren; // renseigne parent::table | 15 | use ModelChildren; // pour hydrateFromForm() |
| 16 | 16 | ||
| 17 | public function __construct() | 17 | public function __construct() |
| 18 | { | 18 | { |
| 19 | $this->table = 'clients'; | 19 | $this->table = 'clients'; // à mettre dans ModelChildren |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | //~ public function set(string $variable, $value) | 22 | //~ public function set(string $variable, $value) |
| @@ -36,59 +36,48 @@ class Clients extends Model | |||
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | // setters | 38 | // setters |
| 39 | public function setID(int $value) // inutile? il s'autoincrémente | 39 | //~ public function setID() -> dans le trait ModelChildren |
| 40 | { | 40 | |
| 41 | $this->ID = $value; | 41 | public function setPrenomNom($value) |
| 42 | return($this); | ||
| 43 | } | ||
| 44 | public function setPrenom_nom(string $value) | ||
| 45 | { | 42 | { |
| 46 | $this->prenom_nom = $value; | 43 | $this->prenom_nom = (string) $value; |
| 47 | return($this); | 44 | return($this); |
| 48 | } | 45 | } |
| 49 | public function setCode_client(string $value) | 46 | public function setCodeClient($value) |
| 50 | { | 47 | { |
| 51 | $this->code_client = $value; | 48 | $this->code_client = (string) $value; |
| 52 | return($this); | 49 | return($this); |
| 53 | } | 50 | } |
| 54 | public function setAdresse(string $value) | 51 | public function setAdresse($value) |
| 55 | { | 52 | { |
| 56 | $this->adresse = $value; | 53 | $this->adresse = (string) $value; |
| 57 | return($this); | 54 | return($this); |
| 58 | } | 55 | } |
| 59 | public function setTelephone(string $value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début | 56 | public function setTelephone($value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début |
| 60 | { | 57 | { |
| 61 | if(is_numeric($value)) | 58 | if(is_numeric($value)) |
| 62 | { | 59 | { |
| 63 | $this->telephone = $value; | 60 | $this->telephone = (string) $value; |
| 61 | } | ||
| 62 | else | ||
| 63 | { | ||
| 64 | $this->telephone = ''; | ||
| 65 | echo 'debug: le champ "telephone" ne doit comporter que des nombres, aucun numéro ne sera utilisé' . "\n"; | ||
| 64 | } | 66 | } |
| 65 | return($this); | 67 | return($this); |
| 66 | } | 68 | } |
| 67 | public function setCourriel(string $value) | 69 | public function setCourriel($value) |
| 68 | { | 70 | { |
| 69 | $this->courriel = $value; | 71 | $this->courriel = (string) $value; |
| 70 | return($this); | 72 | return($this); |
| 71 | } | 73 | } |
| 72 | public function setCommentaires(string $value) | 74 | public function setCommentaires($value) |
| 73 | { | 75 | { |
| 74 | $this->commentaires = $value; | 76 | $this->commentaires = (string) $value; |
| 75 | return($this); | 77 | return($this); |
| 76 | } | 78 | } |
| 77 | 79 | ||
| 78 | 80 | ||
| 79 | public function newRow(array $input) | ||
| 80 | { | ||
| 81 | $this->hydrate(['prenom_nom' => $input[0], 'code_client' => $input[1], 'adresse' => $input[2], 'telephone' => $input[3], 'courriel' => $input[4], 'commentaires' => $input[5]]); | ||
| 82 | $this->create(); | ||
| 83 | // ID obtenu par auto-incrémentation | ||
| 84 | $this->ID = $this->db->lastInsertId(); // méthode de PDO | ||
| 85 | } | ||
| 86 | //~ public function setIdFromLastInsertID() // à faire juste après l'écriture d'une nouvelle entrée | ||
| 87 | //~ { | ||
| 88 | //~ $this->db = parent::getInstance(); // $db est créée dans Model::execQuery() | ||
| 89 | //~ $this->ID = $this->db->lastInsertId(); // méthode de PDO | ||
| 90 | //~ } | ||
| 91 | |||
| 92 | public function findByKeywords(array $keywords, string $field): array // n'hydrate pas les variables, on doit choisir un client et hydrater ensuite | 81 | public function findByKeywords(array $keywords, string $field): array // n'hydrate pas les variables, on doit choisir un client et hydrater ensuite |
| 93 | { | 82 | { |
| 94 | $result = []; | 83 | $result = []; |
diff --git a/src/model/DevisFactures.php b/src/model/DevisFactures.php index 1ed3a5c..ff80960 100644 --- a/src/model/DevisFactures.php +++ b/src/model/DevisFactures.php | |||
| @@ -3,49 +3,42 @@ | |||
| 3 | 3 | ||
| 4 | class DevisFactures extends Model | 4 | class DevisFactures extends Model |
| 5 | { | 5 | { |
| 6 | //~ public $type = ''; // deux tables séparées devis ou factures | ||
| 7 | |||
| 6 | // lecture des données ou hydratation | 8 | // lecture des données ou hydratation |
| 7 | private $ID_devis_facture; // auto-incrémentée | 9 | protected $ID; // auto-incrémentée |
| 8 | private $ID_presta = 0; | 10 | protected $ID_presta; |
| 9 | private $validite_devis; | 11 | protected $taches; |
| 10 | private $signature_devis; | 12 | protected $machine; |
| 11 | private $taches; | 13 | protected $OS; |
| 12 | private $machine; | 14 | protected $donnees; |
| 13 | private $OS; | 15 | protected $cles_licences; |
| 14 | private $donnees; | 16 | protected $temps; |
| 15 | private $cles_licences; | 17 | protected $total_main_d_oeuvre; |
| 16 | private $total_main_d_oeuvre; | 18 | protected $pieces; |
| 17 | private $pieces; | 19 | protected $total_pieces; |
| 18 | private $total_pieces; | 20 | protected $deplacement; |
| 19 | private $deplacement; | 21 | protected $total_HT; |
| 20 | private $total_HT; | 22 | protected $validite_devis; |
| 23 | protected $signature_devis; | ||
| 21 | 24 | ||
| 22 | //~ use ModelChildren; | 25 | use ModelChildren; // pour hydrateFromForm() |
| 23 | 26 | ||
| 24 | public function __construct(int $ID_presta) | 27 | public function __construct(int $ID_presta, string $table) |
| 25 | { | 28 | { |
| 26 | $this->table = 'devisfactures'; | ||
| 27 | $this->ID_presta = $ID_presta; | 29 | $this->ID_presta = $ID_presta; |
| 30 | $this->table = $table; // deux tables séparées devis et factures | ||
| 28 | } | 31 | } |
| 29 | 32 | ||
| 30 | // setters | 33 | // setters |
| 31 | public function setIDDevisFacture(int $value = 0) | 34 | //~ public function setID() -> dans le trait ModelChildren |
| 32 | { | 35 | |
| 33 | if($value === 0) | ||
| 34 | { | ||
| 35 | $this->ID_devis_facture = $this->db->lastInsertId(); // méthode de PDO | ||
| 36 | } | ||
| 37 | else | ||
| 38 | { | ||
| 39 | $this->ID_devis_facture = $value; | ||
| 40 | } | ||
| 41 | return($this); | ||
| 42 | } | ||
| 43 | public function setIDPresta(int $value) | 36 | public function setIDPresta(int $value) |
| 44 | { | 37 | { |
| 45 | $this->ID_presta = $value; | 38 | $this->ID_presta = $value; |
| 46 | return($this); | 39 | return($this); |
| 47 | } | 40 | } |
| 48 | public function setValiditeDdevis(string $value) | 41 | public function setValiditedevis(string $value) |
| 49 | { | 42 | { |
| 50 | $this->validite_devis = $value; | 43 | $this->validite_devis = $value; |
| 51 | return($this); | 44 | return($this); |
| @@ -80,9 +73,15 @@ class DevisFactures extends Model | |||
| 80 | $this->cles_licences = $value; | 73 | $this->cles_licences = $value; |
| 81 | return($this); | 74 | return($this); |
| 82 | } | 75 | } |
| 83 | public function setTotalMainDOeuvre(float $value) | 76 | public function setTemps(string $value) |
| 84 | { | 77 | { |
| 85 | $this->total_main_d_oeuvre = $value; | 78 | $this->temps = $value; |
| 79 | return($this); | ||
| 80 | } | ||
| 81 | public function setTotalMainDOeuvre($value) | ||
| 82 | { | ||
| 83 | $value = str_replace(',', '.', $value); | ||
| 84 | $this->total_main_d_oeuvre = (float) $value; // float "nettoie" tous les caractères après le dernier chiffre trouvé (ex: 50€ => 50, abc => 0) | ||
| 86 | return($this); | 85 | return($this); |
| 87 | } | 86 | } |
| 88 | public function setPieces(string $value) | 87 | public function setPieces(string $value) |
| @@ -90,28 +89,39 @@ class DevisFactures extends Model | |||
| 90 | $this->pieces = $value; | 89 | $this->pieces = $value; |
| 91 | return($this); | 90 | return($this); |
| 92 | } | 91 | } |
| 93 | public function setTotalPieces(float $value) | 92 | public function setTotalPieces($value) |
| 94 | { | 93 | { |
| 95 | $this->total_pieces = $value; | 94 | $value = str_replace(',', '.', $value); |
| 95 | $this->total_pieces = (float) $value; | ||
| 96 | return($this); | 96 | return($this); |
| 97 | } | 97 | } |
| 98 | public function setDeplacement(float $value) | 98 | public function setDeplacement($value) |
| 99 | { | 99 | { |
| 100 | $this->deplacement = $value; | 100 | $value = str_replace(',', '.', $value); |
| 101 | $this->deplacement = (float) $value; | ||
| 101 | return($this); | 102 | return($this); |
| 102 | } | 103 | } |
| 103 | public function setTotalHT(float $value) | 104 | public function setTotalHT($value) |
| 104 | { | 105 | { |
| 105 | $this->total_HT = $value; | 106 | $value = str_replace(',', '.', $value); |
| 107 | $this->total_HT = (float) $value; | ||
| 106 | return($this); | 108 | return($this); |
| 107 | } | 109 | } |
| 108 | 110 | ||
| 109 | public function newRow(array $input, array $quotations_input = []) | 111 | //~ public function newRow(array $input) |
| 110 | { | 112 | //~ { |
| 111 | if(!empty($quotations_input)) // cas d'un devis | 113 | //~ if($this->table === 'devis') // comme la table 'factures' avec deux champs en plus |
| 112 | { | 114 | //~ { |
| 113 | $this->hydrate(['validite_devis' => $quotations_input[0], 'signature_devis' => $quotations_input[1]]); | 115 | //~ $this->hydrate(['ID' => $input[0], 'ID_presta' => $input[1], 'taches' => $input[2], 'machine' => $input[3], 'OS' => $input[4], 'donnees' => $input[5], 'cles_licences' => $input[6], 'total_main_d_oeuvre' => $input[7], 'pieces' => $input[8], 'total_pieces' => $input[9], 'deplacement' => $input[10], 'total_HT' => $input[11]], |
| 114 | } | 116 | //~ ['validite_devis' => $input[12], 'signature_devis' => $input[13]]); |
| 115 | $this->hydrate([]); | 117 | //~ $this->hydrate(['validite_devis' => $quotations_input[0], 'signature_devis' => $quotations_input[1]]); |
| 116 | } | 118 | //~ } |
| 119 | //~ elseif($this->table === 'factures') | ||
| 120 | //~ { | ||
| 121 | //~ $this->hydrate(['ID' => $input[0], 'ID_presta' => $input[1], 'taches' => $input[2], 'machine' => $input[3], 'OS' => $input[4], 'donnees' => $input[5], 'cles_licences' => $input[6], 'total_main_d_oeuvre' => $input[7], 'pieces' => $input[8], 'total_pieces' => $input[9], 'deplacement' => $input[10], 'total_HT' => $input[11]]); | ||
| 122 | //~ } | ||
| 123 | //~ $this->hydrate(['ID' => $input[0], 'ID_presta' => $input[1], 'taches' => $input[2], 'machine' => $input[3], 'OS' => $input[4], 'donnees' => $input[5], 'cles_licences' => $input[6], 'total_main_d_oeuvre' => $input[7], 'pieces' => $input[8], 'total_pieces' => $input[9], 'deplacement' => $input[10], 'total_HT' => $input[11]]); | ||
| 124 | //~ $this->create(); | ||
| 125 | //~ $this->ID_devis_facture = $this->db->lastInsertId(); // méthode de PDO | ||
| 126 | //~ } | ||
| 117 | } | 127 | } |
diff --git a/src/model/Model.php b/src/model/Model.php index 938e3dd..4c1fb4d 100644 --- a/src/model/Model.php +++ b/src/model/Model.php | |||
| @@ -19,22 +19,26 @@ class Model extends DB | |||
| 19 | return($this->table); | 19 | return($this->table); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | // setters (plusieurs en même temps) | 22 | // setters |
| 23 | public function hydrate(array $data) // $data = tableau associatif en entrée: nom_du_champ => valeur | 23 | public function hydrate(array $data): bool // $data = tableau associatif en entrée: nom_du_champ => valeur |
| 24 | { | 24 | { |
| 25 | foreach($data as $key => $value) | 25 | foreach($data as $key => $value) |
| 26 | { | 26 | { |
| 27 | // nom d'un setter, forme "setMachin()" | 27 | // nom du setter |
| 28 | $setterName = 'set' . ucfirst($key); // ucfirst met la première lettre en majuscule | 28 | // nom_du_champ devient setNomDuChamp |
| 29 | // détection | 29 | // on sépare les mots par des espaces, ucwords met la première lettre de chaque mot en majuscule, puis on supprime les espaces |
| 30 | if(method_exists($this, $setterName) && $value != NULL) // on trouve aussi la méthode is_callable() | 30 | $setter_name = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))); // ucwords: première lettre de chaque mot en majuscule |
| 31 | if(method_exists($this, $setter_name)) | ||
| 31 | { | 32 | { |
| 32 | //~ var_dump($value); | 33 | $this->$setter_name($value); |
| 33 | // on renseigne les propriétés des l'instance | ||
| 34 | $this->$setterName($value); // nom d'une méthode dans une variable | ||
| 35 | } | 34 | } |
| 35 | else | ||
| 36 | { | ||
| 37 | echo "debug: la méthode $setter_name n'existe pas\n"; | ||
| 38 | return false; | ||
| 39 | } | ||
| 36 | } | 40 | } |
| 37 | return($this); | 41 | return true; |
| 38 | } | 42 | } |
| 39 | 43 | ||
| 40 | 44 | ||
| @@ -47,6 +51,8 @@ class Model extends DB | |||
| 47 | 51 | ||
| 48 | if($attributes !== null) // requête préparée | 52 | if($attributes !== null) // requête préparée |
| 49 | { | 53 | { |
| 54 | var_dump($sql); | ||
| 55 | var_dump($attributes); | ||
| 50 | $query = $this->db->prepare($sql); | 56 | $query = $this->db->prepare($sql); |
| 51 | $query->execute($attributes); | 57 | $query->execute($attributes); |
| 52 | return $query; | 58 | return $query; |
| @@ -66,10 +72,12 @@ class Model extends DB | |||
| 66 | $fields = []; | 72 | $fields = []; |
| 67 | $question_marks = []; // ? | 73 | $question_marks = []; // ? |
| 68 | $values = []; | 74 | $values = []; |
| 75 | //~ var_dump($this); | ||
| 69 | foreach($this as $field => $value) | 76 | foreach($this as $field => $value) |
| 70 | { | 77 | { |
| 78 | var_dump($field); var_dump($value); | ||
| 71 | // champs non renseignées et variables de l'objet qui ne sont pas des champs | 79 | // champs non renseignées et variables de l'objet qui ne sont pas des champs |
| 72 | // note: avec le !== (au lieu de !=) une valeur 0 passe le filtre | 80 | // note: avec le !== (au lieu de !=) une valeur 0 est différente de null |
| 73 | if($value !== null && $field != 'db' && $field != 'table') | 81 | if($value !== null && $field != 'db' && $field != 'table') |
| 74 | { | 82 | { |
| 75 | $fields[] = $field; // push | 83 | $fields[] = $field; // push |
diff --git a/src/model/Prestations.php b/src/model/Prestations.php index cbe8e6c..2f84daa 100644 --- a/src/model/Prestations.php +++ b/src/model/Prestations.php | |||
| @@ -4,66 +4,59 @@ | |||
| 4 | class Prestations extends Model | 4 | class Prestations extends Model |
| 5 | { | 5 | { |
| 6 | // lecture des données ou hydratation | 6 | // lecture des données ou hydratation |
| 7 | protected $ID_presta; // auto-incrémentée | 7 | protected $ID; // auto-incrémentée |
| 8 | protected $ID_client = 0; | 8 | protected $ID_client = 0; |
| 9 | protected $combientieme_fois = 0; | 9 | //~ protected $combientieme_fois = 0; |
| 10 | protected $code_presta = ''; | 10 | protected $code_presta = ''; |
| 11 | protected $date = 0; // timestamp unix | 11 | protected $date = 0; // timestamp unix |
| 12 | protected $type_presta = ''; | 12 | protected $type_presta = ''; |
| 13 | protected $mode_paiement = ''; | 13 | protected $mode_paiement = ''; |
| 14 | protected $commentaires = ''; | 14 | protected $commentaires = ''; |
| 15 | 15 | ||
| 16 | //~ use ModelChildren; | 16 | use ModelChildren; |
| 17 | 17 | ||
| 18 | public function __construct(int $ID_client) | 18 | public function __construct(int $ID_client) |
| 19 | { | 19 | { |
| 20 | $this->table = 'prestations'; | 20 | $this->table = 'prestations'; |
| 21 | $this->ID_client = $ID_client; | 21 | $this->ID_client = $ID_client; |
| 22 | $this->combientiemeFois(); | 22 | //~ $this->combientiemeFois(); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | // getters | 25 | // getters |
| 26 | public function getIDPresta(): int | 26 | public function getID(): int |
| 27 | { | 27 | { |
| 28 | return $this->ID_presta; | 28 | return $this->ID; |
| 29 | } | 29 | } |
| 30 | public function getIDClient(): int | 30 | public function getIDClient(): int |
| 31 | { | 31 | { |
| 32 | return $this->ID_client; | 32 | return $this->ID_client; |
| 33 | } | 33 | } |
| 34 | public function getCombientiemeFois(): int | 34 | //~ public function getCombientiemeFois(): int |
| 35 | { | 35 | //~ { |
| 36 | return $this->combientieme_fois; | 36 | //~ return $this->combientieme_fois; |
| 37 | } | 37 | //~ } |
| 38 | public function getDate(): int | 38 | public function getDate(): int |
| 39 | { | 39 | { |
| 40 | return $this->date; | 40 | return $this->date; |
| 41 | } | 41 | } |
| 42 | 42 | public function getTypePresta(): string | |
| 43 | // setters | ||
| 44 | public function setIDPresta(int $value = 0) | ||
| 45 | { | 43 | { |
| 46 | if($value === 0) | 44 | return $this->type_presta; |
| 47 | { | ||
| 48 | $this->ID_presta = $this->db->lastInsertId(); // méthode de PDO | ||
| 49 | } | ||
| 50 | else | ||
| 51 | { | ||
| 52 | $this->ID_presta = $value; | ||
| 53 | } | ||
| 54 | return($this); | ||
| 55 | } | 45 | } |
| 46 | |||
| 47 | // setters | ||
| 48 | //~ public function setID() -> dans le trait ModelChildren | ||
| 56 | 49 | ||
| 57 | public function setIDClient(int $value) | 50 | public function setIDClient(int $value) |
| 58 | { | 51 | { |
| 59 | $this->ID_client = $value; | 52 | $this->ID_client = $value; |
| 60 | return($this); | 53 | return($this); |
| 61 | } | 54 | } |
| 62 | public function setCombientiemeFois(int $value) | 55 | //~ public function setCombientiemeFois(int $value) |
| 63 | { | 56 | //~ { |
| 64 | $this->combientieme_fois = $value; | 57 | //~ $this->combientieme_fois = $value; |
| 65 | return($this); | 58 | //~ return($this); |
| 66 | } | 59 | //~ } |
| 67 | public function setCodePresta(string $value) | 60 | public function setCodePresta(string $value) |
| 68 | { | 61 | { |
| 69 | $this->code_presta = $value; | 62 | $this->code_presta = $value; |
| @@ -90,25 +83,21 @@ class Prestations extends Model | |||
| 90 | return($this); | 83 | return($this); |
| 91 | } | 84 | } |
| 92 | 85 | ||
| 93 | protected function combientiemeFois() | 86 | //~ protected function combientiemeFois() |
| 94 | { | 87 | //~ { |
| 95 | // on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente) | 88 | //~ // on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente) |
| 96 | $array = $this->find(['ID_client' => $this->ID_client]); | 89 | //~ $array = $this->find(['ID_client' => $this->ID_client]); |
| 97 | $this->combientieme_fois = count($array) + 1; | 90 | //~ //$this->combientieme_fois = count($array) + 1; |
| 98 | } | 91 | //~ return count($array) + 1; |
| 92 | //~ } | ||
| 99 | 93 | ||
| 100 | // code client = année-mois-jour-codeclient-combientièmefois | 94 | // code client = année-mois-jour-codeclient-combientièmefois |
| 101 | public function makeCodePresta(Dates $Date, string $code_client) | 95 | public function makeCodePresta(Dates $Date, string $code_client) |
| 102 | { | 96 | { |
| 103 | $array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $code_client, $this->combientieme_fois]; | 97 | // on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente) |
| 98 | $combientieme_fois = count($this->find(['ID_client' => $this->ID_client])) + 1; | ||
| 99 | |||
| 100 | $array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $code_client, $combientieme_fois]; | ||
| 104 | $this->code_presta = implode('-', $array_code); | 101 | $this->code_presta = implode('-', $array_code); |
| 105 | } | 102 | } |
| 106 | |||
| 107 | //~ public function newRow(array $input) | ||
| 108 | //~ { | ||
| 109 | //~ $this->hydrate(['ID_client' => $input[0], 'code_presta' => $input[1], 'date' => $input[2], 'type_presta' => $input[3], 'mode_paiement' => $input[4], 'commentaires' => $input[5]]); | ||
| 110 | //~ $this->create(); | ||
| 111 | //~ // ID obtenu par auto-incrémentation | ||
| 112 | //~ $this->ID_presta = $this->db->lastInsertId(); // méthode de PDO | ||
| 113 | //~ } | ||
| 114 | } | 103 | } |
diff --git a/src/model/StructTablesDB.php b/src/model/StructTablesDB.php index 0f13b80..00c5321 100644 --- a/src/model/StructTablesDB.php +++ b/src/model/StructTablesDB.php | |||
| @@ -11,7 +11,8 @@ class StructTablesDB | |||
| 11 | // les tables devis_factures, cesu et locations sont liées à la table prestations | 11 | // les tables devis_factures, cesu et locations sont liées à la table prestations |
| 12 | 'clients' => ['ID' => 'INTEGER', 'prenom_nom' => 'TEXT', 'code_client' => 'TEXT', 'adresse' => 'TEXT', 'telephone' => 'TEXT', 'courriel' => 'TEXT', 'commentaires' => 'TEXT'], | 12 | 'clients' => ['ID' => 'INTEGER', 'prenom_nom' => 'TEXT', 'code_client' => 'TEXT', 'adresse' => 'TEXT', 'telephone' => 'TEXT', 'courriel' => 'TEXT', 'commentaires' => 'TEXT'], |
| 13 | 'prestations' => ['ID' => 'INTEGER', 'ID_client' => 'INTEGER', 'code_presta' => 'TEXT', 'date' => 'INTEGER', 'type_presta' => 'TEXT', 'mode_paiement' => 'TEXT', 'commentaires' => 'TEXT'], | 13 | 'prestations' => ['ID' => 'INTEGER', 'ID_client' => 'INTEGER', 'code_presta' => 'TEXT', 'date' => 'INTEGER', 'type_presta' => 'TEXT', 'mode_paiement' => 'TEXT', 'commentaires' => 'TEXT'], |
| 14 | 'devisfactures' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'validite_devis' => 'TEXT', 'signature_devis' => 'TEXT', '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'], | 14 | 'devis' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'machine' => 'TEXT', 'OS' => 'TEXT', 'donnees' => 'TEXT', 'cles_licences' => 'TEXT', 'temps' => 'TEXT', 'total_main_d_oeuvre' => 'REAL', 'pieces' => 'TEXT', 'total_pieces' => 'REAL', 'deplacement' => 'REAL', 'total_HT' => 'REAL', 'validite_devis' => 'TEXT', 'signature_devis' => 'TEXT'], |
| 15 | 'factures' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'machine' => 'TEXT', 'OS' => 'TEXT', 'donnees' => 'TEXT', 'cles_licences' => 'TEXT', 'temps' => 'TEXT', 'total_main_d_oeuvre' => 'REAL', 'pieces' => 'TEXT', 'total_pieces' => 'REAL', 'deplacement' => 'REAL', 'total_HT' => 'REAL'], | ||
| 15 | 'cesu' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'duree_travail' => 'TEXT', 'salaire' => 'REAL'], | 16 | 'cesu' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'duree_travail' => 'TEXT', 'salaire' => 'REAL'], |
| 16 | 'locations' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'designation' => 'TEXT', 'modele_description' => 'TEXT', 'valeur' => 'REAL', 'etat_des_lieux_debut' => 'TEXT', 'etat_des_lieux_fin' => 'TEXT', 'duree_location' => 'INTEGER', 'loyer_mensuel' => 'REAL', 'loyers_payes' => 'INTEGER', 'caution' => 'INTEGER'] | 17 | 'locations' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'designation' => 'TEXT', 'modele_description' => 'TEXT', 'valeur' => 'REAL', 'etat_des_lieux_debut' => 'TEXT', 'etat_des_lieux_fin' => 'TEXT', 'duree_location' => 'INTEGER', 'loyer_mensuel' => 'REAL', 'loyers_payes' => 'INTEGER', 'caution' => 'INTEGER'] |
| 17 | ]; | 18 | ]; |
diff --git a/src/model/traits.php b/src/model/traits.php index 3d446c1..41f1c35 100644 --- a/src/model/traits.php +++ b/src/model/traits.php | |||
| @@ -1,7 +1,9 @@ | |||
| 1 | <?php | 1 | <?php |
| 2 | // model/traits.php | 2 | // model/traits.php |
| 3 | // | ||
| 4 | // fonctions à utiliser par les enfants de Model | ||
| 3 | 5 | ||
| 4 | trait ModelChildren // pour ne pas toucher au constructeur de la classe Model | 6 | trait ModelChildren |
| 5 | { | 7 | { |
| 6 | //~ public function __construct() | 8 | //~ public function __construct() |
| 7 | //~ { | 9 | //~ { |
| @@ -13,4 +15,83 @@ trait ModelChildren // pour ne pas toucher au constructeur de la classe Model | |||
| 13 | //~ $this->db = parent::getInstance(); | 15 | //~ $this->db = parent::getInstance(); |
| 14 | //~ $this->ID = $this->db->lastInsertId(); // méthode de PDO | 16 | //~ $this->ID = $this->db->lastInsertId(); // méthode de PDO |
| 15 | //~ } | 17 | //~ } |
| 18 | |||
| 19 | public function setID(int $value = 0) | ||
| 20 | { | ||
| 21 | if($value === 0) | ||
| 22 | { | ||
| 23 | $this->ID = $this->db->lastInsertId(); // méthode de PDO | ||
| 24 | } | ||
| 25 | else | ||
| 26 | { | ||
| 27 | $this->ID = $value; | ||
| 28 | } | ||
| 29 | return($this); | ||
| 30 | } | ||
| 31 | |||
| 32 | function hydrateFromForm(string $data_string, Object $Presta = NULL): bool // quand l'objet est $DetailsPresta, on hydrate aussi $Presta | ||
| 33 | { | ||
| 34 | //~ $tableSize = count(StructTablesDB::$structureOfTables[$this->getTable()]); // int | ||
| 35 | |||
| 36 | if($data_string !== '') | ||
| 37 | { | ||
| 38 | $data_array = explode('|', $data_string); // array | ||
| 39 | //~ var_dump($data_array); | ||
| 40 | //~ if(count($data_array) === $tableSize - 1) // nombre de champs sauf ID qui est auto-incrémenté automatiquement | ||
| 41 | //~ { | ||
| 42 | //~ var_dump($this->getTable()); | ||
| 43 | //~ var_dump($data_array); | ||
| 44 | $check = false; | ||
| 45 | switch($this->getTable()) | ||
| 46 | { | ||
| 47 | case 'clients'; | ||
| 48 | if($data_array[0] == '') | ||
| 49 | { | ||
| 50 | echo "debug: données insuffisantes, le nom du client doit au minimum être renseigné\n"; | ||
| 51 | return false; | ||
| 52 | } | ||
| 53 | else | ||
| 54 | { | ||
| 55 | $check = $this->hydrate(['prenom_nom' => $data_array[0], 'code_client' => $data_array[1], 'adresse' => $data_array[2], 'telephone' => $data_array[3], 'courriel' => $data_array[4], 'commentaires' => $data_array[5]]); | ||
| 56 | } | ||
| 57 | break; | ||
| 58 | case 'prestations'; // inutilisé | ||
| 59 | break; | ||
| 60 | case 'devis'; | ||
| 61 | $check = $Presta->hydrate(['mode_paiement' => $data_array[11]]); | ||
| 62 | if($check) | ||
| 63 | { | ||
| 64 | $check = $this->hydrate(['taches' => $data_array[0], 'machine' => $data_array[1], 'OS' => $data_array[2], 'donnees' => $data_array[3], 'cles_licences' => $data_array[4], 'temps' => $data_array[5], 'total_main_d_oeuvre' => $data_array[6], 'pieces' => $data_array[7], 'total_pieces' => $data_array[8], 'deplacement' => $data_array[9], 'total_HT' => $data_array[10], | ||
| 65 | 'validite_devis' => $data_array[12], 'signature_devis' => $data_array[13]]); | ||
| 66 | } | ||
| 67 | break; | ||
| 68 | case 'factures'; | ||
| 69 | $check = $Presta->hydrate(['mode_paiement' => $data_array[11]]); | ||
| 70 | if($check) | ||
| 71 | { | ||
| 72 | $check = $this->hydrate(['taches' => $data_array[0], 'machine' => $data_array[1], 'OS' => $data_array[2], 'donnees' => $data_array[3], 'cles_licences' => $data_array[4], 'temps' => $data_array[5], 'total_main_d_oeuvre' => $data_array[6], 'pieces' => $data_array[7], 'total_pieces' => $data_array[8], 'deplacement' => $data_array[9], 'total_HT' => $data_array[10]]); | ||
| 73 | } | ||
| 74 | break; | ||
| 75 | case 'cesu'; | ||
| 76 | break; | ||
| 77 | case 'locations'; | ||
| 78 | break; | ||
| 79 | default: // inutilisé | ||
| 80 | echo "debug: table inconnue hydrateFromForm()"; | ||
| 81 | return false; | ||
| 82 | } | ||
| 83 | return $check; | ||
| 84 | //~ } | ||
| 85 | //~ else | ||
| 86 | //~ { | ||
| 87 | //~ echo "debug: mauvais tableau, il doit avoir " . $tableSize - 1 . " cases\n"; // ou -3 pour les factures | ||
| 88 | //~ return false; | ||
| 89 | //~ } | ||
| 90 | } | ||
| 91 | else | ||
| 92 | { | ||
| 93 | echo "debug: annulation lors du formulaire\n"; | ||
| 94 | return false; | ||
| 95 | } | ||
| 96 | } | ||
| 16 | } | 97 | } |
diff --git a/src/sections/1_new_service.php b/src/sections/1_new_service.php index 172402a..aaf441a 100644 --- a/src/sections/1_new_service.php +++ b/src/sections/1_new_service.php | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | // | 3 | // |
| 4 | // -- SECTION 1: Nouvelle prestation -- | 4 | // -- SECTION 1: Nouvelle prestation -- |
| 5 | 5 | ||
| 6 | function newService() | 6 | function newService(): int // code de retour, si 0 retour menu principal, si 2 aller à la section 2, etc |
| 7 | { | 7 | { |
| 8 | // fenêtres | 8 | // fenêtres |
| 9 | $QuestionNouveauClient = new ZenityQuestion(ZenitySetup::$question_nouveau_client_text); | 9 | $QuestionNouveauClient = new ZenityQuestion(ZenitySetup::$question_nouveau_client_text); |
| @@ -12,230 +12,188 @@ function newService() | |||
| 12 | $NouveauClient = new ZenityForms(ZenitySetup::$nouveau_client_text, ZenitySetup::$nouveau_client_entrees); | 12 | $NouveauClient = new ZenityForms(ZenitySetup::$nouveau_client_text, ZenitySetup::$nouveau_client_entrees); |
| 13 | $MenuEnregistrement = new ZenityList(ZenitySetup::$menu_enregistrement_text, ZenitySetup::$menu_enregistrement_entrees); | 13 | $MenuEnregistrement = new ZenityList(ZenitySetup::$menu_enregistrement_text, ZenitySetup::$menu_enregistrement_entrees); |
| 14 | $Calendrier = new ZenityCalendar(ZenitySetup::$calendar_text); | 14 | $Calendrier = new ZenityCalendar(ZenitySetup::$calendar_text); |
| 15 | $FormulaireDevis = new ZenityForms(ZenitySetup::$formulaire_text, array_merge(ZenitySetup::$formulaire_devis_entrees, ZenitySetup::$formulaire_facture_entrees)); | 15 | $FormulaireDevis = new ZenityForms(ZenitySetup::$formulaire_text, array_merge(ZenitySetup::$formulaire_facture_entrees, ZenitySetup::$formulaire_devis_entrees)); |
| 16 | $FormulaireFacture = new ZenityForms(ZenitySetup::$formulaire_text, 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); | 17 | $FormulaireCesu = new ZenityForms(ZenitySetup::$formulaire_text, ZenitySetup::$formulaire_cesu_entrees); |
| 18 | $FormulaireLocation = new ZenityForms(ZenitySetup::$formulaire_text, ZenitySetup::$formulaire_location_entrees); | 18 | $FormulaireLocation = new ZenityForms(ZenitySetup::$formulaire_text, ZenitySetup::$formulaire_location_entrees); |
| 19 | $CommentairePrestation = new ZenityEntry(ZenitySetup::$commentaire_prestation_text); | 19 | $CommentairePrestation = new ZenityEntry(ZenitySetup::$commentaire_prestation_text); |
| 20 | $Recapitulatif = new ZenityList(ZenitySetup::$recapitulatif_text, ZenitySetup::$recapitulatif_entrees); // tableau à multiples colonnes | ||
| 21 | $QuestionModifierPrestation = new ZenityQuestion(ZenitySetup::$question_modification_text); | ||
| 20 | 22 | ||
| 21 | $Client = new Clients; // modèle de la table 'clients' | 23 | $Client = new Clients; |
| 22 | 24 | ||
| 23 | $continuer = false; | 25 | |
| 24 | // niveau 2: est ce que le client est déjà dans la base? | 26 | // -- partie 1: le client -- |
| 27 | |||
| 28 | // est ce que le client est déjà dans la base? | ||
| 29 | $client_inconnu = true; | ||
| 25 | if(exec($QuestionNouveauClient->get()) == '0') // $? = 0 signifie oui, double égal == pour le transtypage | 30 | if(exec($QuestionNouveauClient->get()) == '0') // $? = 0 signifie oui, double égal == pour le transtypage |
| 26 | { | 31 | { |
| 27 | echo "debug: recherche souhaitée\n"; | 32 | echo "debug: recherche souhaitée\n"; |
| 28 | 33 | $input = exec($RechercheClient->get()); | |
| 29 | // niveau 3: saisie du nom du client | 34 | if($input == '') |
| 30 | $nom_client = exec($RechercheClient->get()); | ||
| 31 | if($nom_client !== '') | ||
| 32 | { | 35 | { |
| 33 | echo "debug: recherche effectuée\n"; | 36 | echo "debug: recherche annulée ou saisie vide\n"; |
| 34 | $ResultatsRechercheClient->setListRows(rechercheClient($nom_client, $Client), $Client->getTable()); // recherche silencieuse | 37 | return(0); |
| 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 | } | 38 | } |
| 52 | else | 39 | |
| 40 | echo "debug: recherche effectuée\n"; | ||
| 41 | $ResultatsRechercheClient->setListRows(rechercheClient($input, $Client), $Client->getTable()); // recherche silencieuse | ||
| 42 | unset($input); | ||
| 43 | |||
| 44 | // niveau 4: sélection parmi les résultats | ||
| 45 | $choix_niv4 = exec($ResultatsRechercheClient->get()); // renvoie l'ID de la table 'clients' | ||
| 46 | $ResultatsRechercheClient->cleanCommand(); | ||
| 47 | |||
| 48 | if($choix_niv4 == '') | ||
| 53 | { | 49 | { |
| 54 | echo "debug: recherche annulée ou saisie vide\n"; | 50 | echo "debug: client pas trouvé ou pas sélectionné\n"; |
| 51 | return(0); | ||
| 55 | } | 52 | } |
| 53 | |||
| 54 | echo "debug: client sélectionné\n"; | ||
| 55 | $Client->hydrate($Client->findById($choix_niv4)); | ||
| 56 | $client_inconnu = false; | ||
| 56 | } | 57 | } |
| 57 | else | 58 | else |
| 58 | { | 59 | { |
| 59 | echo "debug: nouveau client\n"; | 60 | echo "debug: nouveau client\n"; |
| 60 | } | 61 | } |
| 61 | 62 | ||
| 62 | // niveau 2: on n'a pas cherché OU on n'a pas trouvé | 63 | // on n'a pas cherché OU on n'a pas trouvé |
| 63 | if(!$continuer) | 64 | if($client_inconnu) |
| 64 | { | 65 | { |
| 65 | $data_string = exec($NouveauClient->get()); | 66 | $input = exec($NouveauClient->get()); |
| 66 | //~ $data_array = explode('|', $data_string); | 67 | if($input == '') |
| 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 | { | 68 | { |
| 75 | $data_array = explode('|', $data_string); | 69 | echo "debug: annulation lors de l'enregistrement d'un nouveau client\n"; |
| 76 | $data_string = ''; // nettoyage | 70 | return(0); |
| 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 | } | 71 | } |
| 97 | else | 72 | if(!$Client->hydrateFromForm($input)) |
| 98 | { | 73 | { |
| 99 | echo "debug: annulation lors du formulaire\n"; | 74 | // messages d'erreur dans hydrateFromForm() |
| 100 | $continuer = false; | 75 | return(0); |
| 101 | } | 76 | } |
| 77 | unset($input); | ||
| 78 | $Client->create(); | ||
| 79 | $Client->setID(); // sans paramètre, exécute un $this->db->lastInsertId() | ||
| 102 | } | 80 | } |
| 103 | 81 | ||
| 82 | |||
| 83 | // -- partie 2: la prestation -- | ||
| 84 | |||
| 104 | // niveau 2: type comptable d'enregistrement: devis, facture, cesu, location ou pas de prestation | 85 | // niveau 2: type comptable d'enregistrement: devis, facture, cesu, location ou pas de prestation |
| 105 | if($continuer) | 86 | $choix_niv2 = exec($MenuEnregistrement->get()); |
| 87 | if($choix_niv2 === '') | ||
| 106 | { | 88 | { |
| 107 | $choix_niv2 = exec($MenuEnregistrement->get()); | 89 | echo "debug: annulation menu enregistrement\n"; |
| 108 | $continuer = false; | 90 | return(0); // menu principal |
| 109 | $Presta = new Prestations($Client->getID()); | 91 | } |
| 110 | 92 | ||
| 111 | switch($choix_niv2) | 93 | $Presta = new Prestations($Client->getID()); |
| 112 | { | 94 | |
| 113 | case ZenitySetup::$menu_enregistrement_entrees[0]: // "Devis" | 95 | // détail de la prestation |
| 114 | $DetailsPresta = new DevisFactures($Client->getID()); | 96 | // calendrier - étape 1/3 |
| 115 | $Presta->setTypePresta('devis'); | 97 | $Date = new Dates(exec($Calendrier->get())); // exec() renvoie soit une chaîne soit un false |
| 116 | $continuer = true; | 98 | if($Date->getDate() == '') // on n'a pas cliqué sur "annuler" |
| 117 | break; | 99 | { |
| 118 | case ZenitySetup::$menu_enregistrement_entrees[1]: // "Facture" | 100 | echo "debug: annulation à la saisie d'une date\n"; |
| 119 | $DetailsPresta = new DevisFactures($Client->getID()); | 101 | return(0); // menu principal |
| 120 | $Presta->setTypePresta('facture'); | 102 | } |
| 121 | $continuer = true; | 103 | |
| 122 | break; | 104 | $Presta->setDate($Date->getTimestamp()); // un entier pour la BDD |
| 123 | case ZenitySetup::$menu_enregistrement_entrees[2]: // "CESU" | 105 | $Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre |
| 124 | $DetailsPresta = new CESU($Client->getID()); | 106 | |
| 125 | $Presta->setTypePresta('cesu'); | 107 | switch($choix_niv2) |
| 126 | $continuer = true; | 108 | { |
| 127 | break; | 109 | // formulaire - étape 2/3 |
| 128 | case ZenitySetup::$menu_enregistrement_entrees[3]: // "Location" | 110 | case ZenitySetup::$menu_enregistrement_entrees[0]: // "Devis" |
| 129 | $DetailsPresta = new Locations($Client->getID()); | 111 | $Details = new DevisFactures($Client->getID(), 'devis'); |
| 130 | $Presta->setTypePresta('location'); | 112 | $Presta->setTypePresta('devis'); |
| 131 | $continuer = true; | 113 | $input = exec($FormulaireDevis->get()); |
| 132 | break; | 114 | break; |
| 133 | case ZenitySetup::$menu_enregistrement_entrees[4]: // "non_vendue" | 115 | case ZenitySetup::$menu_enregistrement_entrees[1]: // "Facture" |
| 134 | // objet $Presta uniquement | 116 | $Details = new DevisFactures($Client->getID(), 'factures'); // 'factures' est le nom de la table, pas le type de presta |
| 135 | $Presta->setTypePresta('non_vendue'); | 117 | $Presta->setTypePresta('facture'); |
| 136 | $continuer = true; | 118 | $input =exec($FormulaireFacture->get()); |
| 137 | break; | 119 | break; |
| 138 | default: | 120 | case ZenitySetup::$menu_enregistrement_entrees[2]: // "CESU" |
| 139 | $continuer = false; // annulation, retour menu principal | 121 | $Details = new CESU($Client->getID()); |
| 140 | } | 122 | $Presta->setTypePresta('cesu'); |
| 141 | 123 | $input = exec($FormulaireCesu->get()); | |
| 142 | if($continuer) | 124 | break; |
| 143 | { | 125 | case ZenitySetup::$menu_enregistrement_entrees[3]: // "Location" |
| 144 | // niveau 3: détail de la prestation | 126 | $Details = new Locations($Client->getID()); |
| 145 | // noter que exec() renvoie toujours une chaîne, sauf en cas d'erreur où il renvoie un "false" | 127 | $Presta->setTypePresta('location'); |
| 146 | $Date = new Dates(exec($Calendrier->get())); | 128 | $input = exec($FormulaireLocation->get()); |
| 147 | if($Date->getDate() !== '') // on n'a pas cliqué sur "annuler" | 129 | break; |
| 148 | { | 130 | case ZenitySetup::$menu_enregistrement_entrees[4]: // "Prestation non vendue" |
| 149 | $Presta->setDate($Date->getTimestamp()); // un entier pour la BDD | 131 | $Presta->setTypePresta('non_vendue'); |
| 150 | $Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre | 132 | break; |
| 151 | 133 | default: // inutile normallement, cas déjà géré plus haut | |
| 152 | // on continue si le formulaire précédent a été rempli | 134 | echo "debug: sortie du menu enregistrement incorrect\n"; |
| 153 | switch($choix_niv2) | 135 | return(0); |
| 154 | { | 136 | } |
| 155 | case $Presta->getType = 'devis'; | 137 | |
| 156 | $data_string = exec($FormulaireDevis->get()); | 138 | if($input == '') |
| 157 | break; | 139 | { |
| 158 | case $Presta->getType = 'facture'; | 140 | echo "debug: annulation lors de l'enregistrement des détails de la prestation\n"; |
| 159 | $data_string = exec($FormulaireFacture->get()); // tester si c'est vide ou clic sur 'Annuler' | 141 | return(0); |
| 160 | break; | 142 | } |
| 161 | case $Presta->getType = 'cesu'; | 143 | elseif(isset($Details) && !$Details->hydrateFromForm($input, $Presta)) |
| 162 | $data_string = exec($FormulaireCesu->get()); | 144 | { |
| 163 | break; | 145 | // messages d'erreur dans hydrateFromForm() |
| 164 | case $Presta->getType = 'location'; | 146 | return(0); |
| 165 | $data_string = exec($FormulaireLocation->get()); | 147 | } |
| 166 | break; | 148 | unset($input); |
| 167 | case $data_string->getType = 'non_vendue'; | 149 | |
| 168 | // ne rien faire | 150 | // commentaire - étape 3/3 |
| 169 | break; | 151 | $input = exec($CommentairePrestation->get()); |
| 170 | default: | 152 | //~ if($input == '') |
| 171 | $continuer = false; // annulation, retour menu principal | 153 | //~ { |
| 172 | } | 154 | //~ echo "debug: annulation à la saisie d'un commentaire\n"; |
| 173 | 155 | //~ return(0); | |
| 174 | if($continuer) | 156 | //~ } |
| 175 | { | 157 | $Presta->setCommentaires($input); |
| 176 | // dans $Presta | 158 | unset($input); |
| 177 | $comment = exec($CommentairePrestation->get()); | 159 | |
| 178 | if(!empty($comment)) | 160 | $Presta->create(); |
| 179 | { | 161 | $Presta->setID(); // sans paramètre, exécute un $this->db->lastInsertId() |
| 180 | $Presta->setCommentaires($comment); | 162 | |
| 181 | } | 163 | $Details->setIDPresta($Presta->getID()); // d'un objet à l'autre |
| 182 | else | 164 | $Details->create(); |
| 183 | { | 165 | $Details->setID(); // sans paramètre, exécute un $this->db->lastInsertId() |
| 184 | $continuer = false; // annulation, retour menu principal | 166 | |
| 185 | } | 167 | |
| 186 | } | 168 | // -- partie 3: LaTeX -- |
| 187 | } | 169 | |
| 188 | $Presta->create(); | 170 | // création fichiers LaTeX et PDF |
| 189 | $Presta->setIDPresta(); // sans paramètre pour récupérer le dernier ID inséré | 171 | //~ $latex_path = '../data/latex/'; // noms de variables dans le config.php |
| 190 | 172 | //~ $file_name = 'devis.tex'; | |
| 191 | if($data_string !== '') | 173 | //~ $template = 'devis'; // vaut 'devis' ou 'enveloppe_recto' ou 'enveloppe_verso' ou 'facture' ou 'location' |
| 192 | { | 174 | //~ $latex = getLatexFromTemplate($template); |
| 193 | $data_array = explode('|', $data_string); | 175 | //~ file_put_contents($latex_path . $file_name, $latex); // injection des variables & écriture du fichier |
| 194 | 176 | //~ $pdf_path = '../data/pdf/'; | |
| 195 | if(count($data_array) === count(StructTablesDB::$structureOfTables[$DetailsPresta->getTable()]) - 1) | 177 | //~ latexToPdf($latex_path, $file_name, $pdf_path); |
| 196 | { | 178 | |
| 197 | if($data_array[0] != "") // le champ "prenom_nom" ne doit pas être vide | 179 | |
| 198 | { | 180 | // -- partie 4: récapitulatif -- |
| 199 | $DetailsPresta->newRow($data_array); // INSUFFISANT | 181 | |
| 200 | $continuer = true; | 182 | // tableau récaptilatif |
| 201 | } | 183 | // ZenityList |
| 202 | else | 184 | |
| 203 | { | 185 | // imprimer? |
| 204 | echo "debug: données insuffisantes, le nom du client doit au minimum être renseigné\n"; | 186 | //~ $imprimer_facture = exec('zenity --question --width=250 --title="Base de données mise à jour" --text="Imprimer la facture?"'); |
| 205 | $continuer = false; | 187 | //~ $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"'); |
| 206 | } | 188 | |
| 207 | } | 189 | // possibilité de modification |
| 208 | else | 190 | // zenityQuestion |
| 209 | { | 191 | if(exec($QuestionModifierPrestation->get()) == '0') |
| 210 | echo "debug: le nombre d'informations à enregistrer du nombre de champs à renseigner dans la table\n"; | 192 | { |
| 211 | $continuer = false; | 193 | return(2); // section 2 |
| 212 | } | 194 | } |
| 213 | } | 195 | else |
| 214 | else | 196 | { |
| 215 | { | 197 | return(0); // menu principal |
| 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 | } | 198 | } |
| 241 | } | 199 | } |
diff --git a/src/sections/2_modify_service.php b/src/sections/2_modify_service.php new file mode 100644 index 0000000..72e2605 --- /dev/null +++ b/src/sections/2_modify_service.php | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | <?php | ||
| 2 | // sections/2_modify_service.php | ||
| 3 | // | ||
| 4 | // -- SECTION 2: Modifier une prestation -- | ||
| 5 | |||
| 6 | function modifyService(): int // code de retour, si 2 aller à la section 2, etc | ||
| 7 | { | ||
| 8 | return(0); // menu principal | ||
| 9 | } | ||
diff --git a/src/view/ZenitySetup.php b/src/view/ZenitySetup.php index e8a3ddb..518cfbb 100644 --- a/src/view/ZenitySetup.php +++ b/src/view/ZenitySetup.php | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | class ZenitySetup | 8 | class ZenitySetup |
| 9 | { | 9 | { |
| 10 | static public $menu_principal_text = "Gestion d'une micro-entreprise"; | 10 | static public $menu_principal_text = "Gestion d'une micro-entreprise"; |
| 11 | static public $menu_principal_entrees = ["Nouvelle prestation", "Modifier enregistrement", "Fichier clients", "Créer/imprimer un document", "Communication", "Base de données"]; | 11 | static public $menu_principal_entrees = ["Nouvelle prestation", "Modifier enregistrement", "Consulter/analyser les données", "Imprimer un document", "Communication", "Base de données"]; |
| 12 | static public $question_nouveau_client_text = "Ce client figure t\'il déjà dans le fichier clients?"; | 12 | static public $question_nouveau_client_text = "Ce client figure t\'il déjà dans le fichier clients?"; |
| 13 | static public $menu_enregistrement_text = "Type d\'enregistrement?"; | 13 | static public $menu_enregistrement_text = "Type d\'enregistrement?"; |
| 14 | static public $menu_enregistrement_entrees = ["Devis", "Facture", "CESU", "Location", "Prestation non vendue"]; | 14 | static public $menu_enregistrement_entrees = ["Devis", "Facture", "CESU", "Location", "Prestation non vendue"]; |
| @@ -22,9 +22,12 @@ class ZenitySetup | |||
| 22 | static public $nouveau_client_entrees = ["Prénom Nom:", "Code client, exemple: J.P.Duchmol", "Adresse::", "Telephone:", "Courriel:", "Commentaires:"]; | 22 | static public $nouveau_client_entrees = ["Prénom Nom:", "Code client, exemple: J.P.Duchmol", "Adresse::", "Telephone:", "Courriel:", "Commentaires:"]; |
| 23 | static public $calendar_text = 'Nouvelle prestation étape 1/3 - Choisir une date'; | 23 | static public $calendar_text = 'Nouvelle prestation étape 1/3 - Choisir une date'; |
| 24 | static public $formulaire_text = 'Nouvelle prestation 2/3 - Détail des travaux'; | 24 | static public $formulaire_text = 'Nouvelle prestation 2/3 - Détail des travaux'; |
| 25 | static public $formulaire_facture_entrees = ["Tâches effectuées:", "Modèle du PC:", "OS:", "Données sauvegardées:", "Clés d\'activation:", "Temps main d\'oeuvre (heures):", "Total main d\'oeuvre (euros):", "Total pièces (euros):", "Déplacement (euros)", "Total HT (euros):", "Mode de paiement", "Commentaires"]; | 25 | static public $formulaire_devis_entrees = ["Durée de validite du devis:", "Devis signé (oui ou non):"]; |
| 26 | static public $formulaire_devis_entrees = ["Validite du devis:", "Devis signé?:"]; | 26 | static public $formulaire_facture_entrees = ["Tâches effectuées:", "Modèle du PC:", "OS:", "Données sauvegardées:", "Clés d\'activation:", "Nombre d'heures:", "Total main d\'oeuvre (euros):", "Détail des pièces:", "Total pièces (euros):", "Déplacement (euros)", "Total HT (euros):", "Mode de paiement"]; |
| 27 | static public $formulaire_cesu_entrees = ["Tâches effectuées:", "Duree de travail:", "Salaire net"]; | 27 | static public $formulaire_cesu_entrees = ["Tâches effectuées:", "Duree de travail:", "Salaire net"]; |
| 28 | static public $formulaire_location_entrees = ["Désignation du bien", "Modèle, numéro de série, description:", "Valeur", "État des lieux du début:", "État des lieux de fin:", "Durée de la location en mois:", "Loyer mensuel:", "Nombre de loyers déjà payés:", "Montant du chèque de caution:"]; | 28 | static public $formulaire_location_entrees = ["Désignation du bien", "Modèle, numéro de série, description:", "Valeur", "État des lieux du début:", "État des lieux de fin:", "Durée de la location en mois:", "Loyer mensuel:", "Nombre de loyers déjà payés:", "Montant du chèque de caution:"]; |
| 29 | static public $commentaire_prestation_text = 'Nouvelle prestation 3/3 - Commentaires'; | 29 | static public $commentaire_prestation_text = 'Nouvelle prestation 3/3 - Commentaires'; |
| 30 | static public $recapitulatif_text = "voici toutes les informations enregistrées"; | ||
| 31 | static public $recapitulatif_entrees = []; | ||
| 32 | static public $question_modification_text = "Prestation enregistrée. Modifier les informations?"; | ||
| 30 | } | 33 | } |
