diff options
author | polo <ordipolo@gmx.fr> | 2023-08-30 12:20:39 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2023-08-30 12:20:39 +0200 |
commit | 6f4cc3afffde36a13618458ffda72e6104624f36 (patch) | |
tree | fbf77181dee390e048bc5fa340ca60bd078ab22b /src/model | |
parent | 747674b450d6840ce9bd9aecd765cf31445ef8d3 (diff) | |
download | AppliGestionPHP-6f4cc3afffde36a13618458ffda72e6104624f36.zip |
section client à part, section modif en cours, bug dans Dates,
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/CESU.php | 12 | ||||
-rw-r--r-- | src/model/Clients.php | 49 | ||||
-rw-r--r-- | src/model/DevisFactures.php | 34 | ||||
-rw-r--r-- | src/model/Locations.php | 18 | ||||
-rw-r--r-- | src/model/Model.php | 25 | ||||
-rw-r--r-- | src/model/Prestations.php | 26 | ||||
-rw-r--r-- | src/model/StructTablesDB.php | 2 | ||||
-rw-r--r-- | src/model/traits.php | 13 |
8 files changed, 147 insertions, 32 deletions
diff --git a/src/model/CESU.php b/src/model/CESU.php index dbb4023..a8aa1e8 100644 --- a/src/model/CESU.php +++ b/src/model/CESU.php | |||
@@ -6,18 +6,26 @@ class CESU extends Model | |||
6 | //~ const TABLE = 'cesu'; | 6 | //~ const TABLE = 'cesu'; |
7 | 7 | ||
8 | // lecture des données ou hydratation | 8 | // lecture des données ou hydratation |
9 | protected $ID; | ||
9 | protected $ID_presta; | 10 | protected $ID_presta; |
10 | protected $taches; | 11 | protected $taches; |
11 | protected $duree_travail; | 12 | protected $duree_travail; |
12 | protected $salaire; | 13 | protected $salaire; |
13 | 14 | ||
14 | //~ use ModelChildren; | ||
15 | |||
16 | public function __construct() | 15 | public function __construct() |
17 | { | 16 | { |
18 | $this->table = strtolower(__CLASS__); // cesu | 17 | $this->table = strtolower(__CLASS__); // cesu |
19 | } | 18 | } |
20 | 19 | ||
20 | public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) | ||
21 | { | ||
22 | return [ | ||
23 | "Numéro CESU:" => $this->ID, | ||
24 | "Tâche effectuée:" => $this->taches, | ||
25 | "Durée du travail:" => $this->duree_travail, | ||
26 | "Salaire:" => $this->salaire]; | ||
27 | } | ||
28 | |||
21 | // setters | 29 | // setters |
22 | public function setIDPresta(int $value) | 30 | public function setIDPresta(int $value) |
23 | { | 31 | { |
diff --git a/src/model/Clients.php b/src/model/Clients.php index f36acc1..6a4dcf5 100644 --- a/src/model/Clients.php +++ b/src/model/Clients.php | |||
@@ -14,8 +14,6 @@ class Clients extends Model | |||
14 | protected $courriel; | 14 | protected $courriel; |
15 | protected $apropos; | 15 | protected $apropos; |
16 | protected $type = 'prospect'; | 16 | protected $type = 'prospect'; |
17 | |||
18 | //~ use ModelChildren; | ||
19 | 17 | ||
20 | public function __construct() | 18 | public function __construct() |
21 | { | 19 | { |
@@ -31,6 +29,52 @@ class Clients extends Model | |||
31 | { | 29 | { |
32 | return $this->code_client; | 30 | return $this->code_client; |
33 | } | 31 | } |
32 | public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) | ||
33 | { | ||
34 | return [ | ||
35 | "Prénom Nom:" => $this->prenom_nom, | ||
36 | "Code client (J.C.Dusse):" => $this->code_client, | ||
37 | "Adresse:" => $this->adresse, | ||
38 | "Code postal:" => $this->code_postal, | ||
39 | "Ville:" => $this->ville, | ||
40 | "Telephone:" => $this->telephone, | ||
41 | "Courriel:" => $this->courriel, | ||
42 | "À propos:" => $this->apropos, | ||
43 | "Client ou Prospect?" => $this->type]; | ||
44 | } | ||
45 | public function getSetterAndSet(string $entry, string $input) | ||
46 | { | ||
47 | switch($entry) | ||
48 | { | ||
49 | case "Prénom Nom:": | ||
50 | $this->setPrenomNom($input); | ||
51 | break; | ||
52 | case "Code client (J.C.Dusse):": | ||
53 | $this->setCodeClient($input); | ||
54 | break; | ||
55 | case "Adresse:": | ||
56 | $this->setAdresse($input); | ||
57 | break; | ||
58 | case "Code postal:": | ||
59 | $this->setCodePostal($input); | ||
60 | break; | ||
61 | case "Ville:": | ||
62 | $this->setVille($input); | ||
63 | break; | ||
64 | case "Telephone:": | ||
65 | $this->setTelephone($input); | ||
66 | break; | ||
67 | case "Courriel:": | ||
68 | $this->setCourriel($input); | ||
69 | break; | ||
70 | case "À propos:": | ||
71 | $this->setApropos($input); | ||
72 | break; | ||
73 | case "Client ou Prospect?": | ||
74 | $this->setType($input); | ||
75 | break; | ||
76 | } | ||
77 | } | ||
34 | 78 | ||
35 | // setters | 79 | // setters |
36 | public function setPrenomNom($value) | 80 | public function setPrenomNom($value) |
@@ -58,7 +102,6 @@ class Clients extends Model | |||
58 | $this->ville = (string) $value; | 102 | $this->ville = (string) $value; |
59 | return $this; | 103 | return $this; |
60 | } | 104 | } |
61 | |||
62 | public function setTelephone($value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début | 105 | public function setTelephone($value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début |
63 | { | 106 | { |
64 | if(is_numeric($value)) | 107 | if(is_numeric($value)) |
diff --git a/src/model/DevisFactures.php b/src/model/DevisFactures.php index c9b7d18..5769842 100644 --- a/src/model/DevisFactures.php +++ b/src/model/DevisFactures.php | |||
@@ -22,12 +22,42 @@ class DevisFactures extends Model | |||
22 | protected $validite_devis; | 22 | protected $validite_devis; |
23 | protected $signature_devis; | 23 | protected $signature_devis; |
24 | 24 | ||
25 | //~ use ModelChildren; | ||
26 | |||
27 | public function __construct(string $table) | 25 | public function __construct(string $table) |
28 | { | 26 | { |
29 | $this->table = $table; // deux tables séparées devis et factures | 27 | $this->table = $table; // deux tables séparées devis et factures |
30 | } | 28 | } |
29 | public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) | ||
30 | { | ||
31 | $champs_communs = [ | ||
32 | "Tâches:" => $this->taches, | ||
33 | "PC:" => $this->machine, | ||
34 | "OS:" => $this->OS, | ||
35 | "Données:" => $this->donnees, | ||
36 | "Clés de licences:" => $this->cles_licences, | ||
37 | "Total Main d'oeuvre:" => $this->total_main_d_oeuvre, | ||
38 | "Pièces" => $this->pieces, | ||
39 | "Total des pièces" => $this->total_pieces, | ||
40 | "Déplacement" => $this->deplacement, | ||
41 | "Total HT" => $this->total_HT]; | ||
42 | |||
43 | if($this->table === 'factures') | ||
44 | { | ||
45 | return ["Numéro facture:" => $this->ID] + $champs_communs; | ||
46 | } | ||
47 | elseif($this->table === 'devis') | ||
48 | { | ||
49 | $champs_devis = [ | ||
50 | "Delai de livraison" => $this->delai_livraison, | ||
51 | "Durée de validité" => $this->validite_devis, | ||
52 | "Devis signé?" => $this->signature_devis]; | ||
53 | |||
54 | return ["Numéro devis:" => $this->ID] + $champs_communs + $champs_devis; | ||
55 | } | ||
56 | else | ||
57 | { | ||
58 | return []; | ||
59 | } | ||
60 | } | ||
31 | 61 | ||
32 | // setters | 62 | // setters |
33 | public function setIDPresta(int $value) | 63 | public function setIDPresta(int $value) |
diff --git a/src/model/Locations.php b/src/model/Locations.php index b669e7c..e3c9507 100644 --- a/src/model/Locations.php +++ b/src/model/Locations.php | |||
@@ -4,6 +4,7 @@ | |||
4 | class Locations extends Model | 4 | class Locations extends Model |
5 | { | 5 | { |
6 | // lecture des données ou hydratation | 6 | // lecture des données ou hydratation |
7 | protected $ID; | ||
7 | protected $ID_presta; | 8 | protected $ID_presta; |
8 | protected $designation; | 9 | protected $designation; |
9 | protected $modele_description; | 10 | protected $modele_description; |
@@ -15,13 +16,26 @@ class Locations extends Model | |||
15 | protected $loyers_payes; | 16 | protected $loyers_payes; |
16 | protected $caution; | 17 | protected $caution; |
17 | 18 | ||
18 | //~ use ModelChildren; | ||
19 | |||
20 | public function __construct() | 19 | public function __construct() |
21 | { | 20 | { |
22 | $this->table = strtolower(__CLASS__); // locations | 21 | $this->table = strtolower(__CLASS__); // locations |
23 | } | 22 | } |
24 | 23 | ||
24 | public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) | ||
25 | { | ||
26 | return [ | ||
27 | "Numéro location:" => $this->ID, | ||
28 | "Désignation:" => $this->designation, | ||
29 | "Description du modèle:" => $this->modele_description, | ||
30 | "Valeur:" => $this->valeur, | ||
31 | "État des lieux de début:" => $this->etat_des_lieux_debut, | ||
32 | "État des lieux de fin:" => $this->etat_des_lieux_fin, | ||
33 | "Durée de la location:" => $this->duree_location, | ||
34 | "Loyer Mensuel" => $this->loyer_mensuel, | ||
35 | "Loyers Payés" => $this->loyers_payes, | ||
36 | "Caution" => $this->caution]; | ||
37 | } | ||
38 | |||
25 | // setters | 39 | // setters |
26 | public function setIDPresta(int $value) | 40 | public function setIDPresta(int $value) |
27 | { | 41 | { |
diff --git a/src/model/Model.php b/src/model/Model.php index 3fb3bdf..4c4a80c 100644 --- a/src/model/Model.php +++ b/src/model/Model.php | |||
@@ -19,7 +19,7 @@ abstract class Model extends DB | |||
19 | return $this->table; | 19 | return $this->table; |
20 | } | 20 | } |
21 | 21 | ||
22 | public function getAll(): array | 22 | public function getAll(): array // à améliorer pour ne pas renvoyer $db et $table |
23 | { | 23 | { |
24 | return get_object_vars($this); // retourne les propriétés de l'objet | 24 | return get_object_vars($this); // retourne les propriétés de l'objet |
25 | } | 25 | } |
@@ -29,7 +29,7 @@ abstract class Model extends DB | |||
29 | { | 29 | { |
30 | if($value === 0) | 30 | if($value === 0) |
31 | { | 31 | { |
32 | $this->ID = $this->db->lastInsertId(); // méthode de PDO (attention ne gère pas la concurence) | 32 | $this->ID = $this->db->lastInsertId(); // méthode de PDO, attention lastInsertId() ne gère pas la concurence |
33 | } | 33 | } |
34 | else | 34 | else |
35 | { | 35 | { |
@@ -183,9 +183,22 @@ abstract class Model extends DB | |||
183 | return($this->execQuery('SELECT * FROM ' . $this->table)->fetchAll()); // fonctionne aussi sans le point virgule dans le SQL!! | 183 | return($this->execQuery('SELECT * FROM ' . $this->table)->fetchAll()); // fonctionne aussi sans le point virgule dans le SQL!! |
184 | } | 184 | } |
185 | 185 | ||
186 | public function findById(int $id) // obtenir une entrée avec son ID | 186 | public function findById() // obtenir une entrée avec son ID |
187 | { | 187 | { |
188 | return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id = ' . $id)->fetch()); | 188 | return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id = ' . $this->ID)->fetch()); |
189 | } | ||
190 | public function getDetailsByIdPresta() | ||
191 | { | ||
192 | if($this->table == 'prestations') | ||
193 | { | ||
194 | // à l'occaz, rendre abstraite la classe Prestations | ||
195 | echo 'erreur: ne pas appeler Model::getDetailsByIdPresta() si la table ciblée est "prestations".'; | ||
196 | return 0; | ||
197 | } | ||
198 | else | ||
199 | { | ||
200 | return $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id_Presta = ' . $this->ID_presta)->fetch(); // type array | ||
201 | } | ||
189 | } | 202 | } |
190 | 203 | ||
191 | protected function find(array $criteria): array // obtenir une entrée avec un tableau associatif 'champ' => 'valeur' | 204 | protected function find(array $criteria): array // obtenir une entrée avec un tableau associatif 'champ' => 'valeur' |
@@ -207,7 +220,7 @@ abstract class Model extends DB | |||
207 | 220 | ||
208 | 221 | ||
209 | // update UPDATE | 222 | // update UPDATE |
210 | public function update(int $id) // utiliser plutôt $this->ID ? | 223 | public function update() |
211 | { | 224 | { |
212 | $fields = []; | 225 | $fields = []; |
213 | $values = []; | 226 | $values = []; |
@@ -219,7 +232,7 @@ abstract class Model extends DB | |||
219 | $values[] = $value; | 232 | $values[] = $value; |
220 | } | 233 | } |
221 | } | 234 | } |
222 | $values[] = $id; // cette syntaxe ajoute une valeur au tableau | 235 | $values[] = $this->ID; // cette syntaxe ajoute une valeur au tableau |
223 | $field_list = implode(', ', $fields); | 236 | $field_list = implode(', ', $fields); |
224 | 237 | ||
225 | // UPDATE annonces SET titre = ?, description = ?, actif = ? WHERE id = ? | 238 | // UPDATE annonces SET titre = ?, description = ?, actif = ? WHERE id = ? |
diff --git a/src/model/Prestations.php b/src/model/Prestations.php index 22865df..fe09133 100644 --- a/src/model/Prestations.php +++ b/src/model/Prestations.php | |||
@@ -11,8 +11,6 @@ class Prestations extends Model | |||
11 | protected $type_presta = ''; | 11 | protected $type_presta = ''; |
12 | protected $mode_paiement = ''; | 12 | protected $mode_paiement = ''; |
13 | protected $commentaires = ''; | 13 | protected $commentaires = ''; |
14 | |||
15 | //~ use ModelChildren; | ||
16 | 14 | ||
17 | public function __construct(int $ID_client) | 15 | public function __construct(int $ID_client) |
18 | { | 16 | { |
@@ -29,6 +27,16 @@ class Prestations extends Model | |||
29 | { | 27 | { |
30 | return $this->ID_client; | 28 | return $this->ID_client; |
31 | } | 29 | } |
30 | public function getIDsByIdClient() // obtenir une entrée avec son ID_client | ||
31 | { | ||
32 | $IDs = $this->execQuery('SELECT id FROM ' . $this->table . ' WHERE id_client = ' . $this->ID_client)->fetchAll(); | ||
33 | // changer le tableau de tableaux en tableau simple | ||
34 | for($i = 0; $i < count($IDs); $i++) | ||
35 | { | ||
36 | $IDs[$i] = $IDs[$i]['ID']; | ||
37 | } | ||
38 | return($IDs); | ||
39 | } | ||
32 | public function getCodePresta(): string | 40 | public function getCodePresta(): string |
33 | { | 41 | { |
34 | return $this->code_presta; | 42 | return $this->code_presta; |
@@ -41,6 +49,18 @@ class Prestations extends Model | |||
41 | { | 49 | { |
42 | return $this->type_presta; | 50 | return $this->type_presta; |
43 | } | 51 | } |
52 | public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) | ||
53 | { | ||
54 | $code_presta_tableau = explode('-', $this->code_presta); | ||
55 | $Date = new Dates($this->date); | ||
56 | |||
57 | return [ | ||
58 | "Numéro prestation:" => end($code_presta_tableau), // dernière case | ||
59 | "Date:" => $Date->getDate(), | ||
60 | "Type de Presta:" => $this->type_presta, | ||
61 | "Mode de paiement:" => $this->mode_paiement, | ||
62 | "Commentaires:" => $this->commentaires]; | ||
63 | } | ||
44 | 64 | ||
45 | // setters | 65 | // setters |
46 | //~ public function setID() -> dans le trait ModelChildren | 66 | //~ public function setID() -> dans le trait ModelChildren |
@@ -81,7 +101,7 @@ class Prestations extends Model | |||
81 | return $this; | 101 | return $this; |
82 | } | 102 | } |
83 | 103 | ||
84 | // code client = année-mois-jour-codeclient-combientièmefois | 104 | // code client = année-mois-jour-codeclient-typedepresta-combientièmefois |
85 | public function makeCodePresta(Dates $Date, string $code_client) | 105 | public function makeCodePresta(Dates $Date, string $code_client) |
86 | { | 106 | { |
87 | // on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente) | 107 | // on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente) |
diff --git a/src/model/StructTablesDB.php b/src/model/StructTablesDB.php index 769d502..679adde 100644 --- a/src/model/StructTablesDB.php +++ b/src/model/StructTablesDB.php | |||
@@ -11,7 +11,7 @@ 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', 'code_postal' => 'TEXT', 'ville' => 'TEXT', 'telephone' => 'TEXT', 'courriel' => 'TEXT', 'apropos' => 'TEXT', 'type' => 'TEXT DEFAULT prospect'], | 12 | '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'], |
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 | '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'], | 14 | '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 DEFAULT non'], |
15 | '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'], | 15 | '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'], |
16 | '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'], |
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' => 'TEXT', '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' => 'TEXT', 'loyer_mensuel' => 'REAL', 'loyers_payes' => 'INTEGER', 'caution' => 'INTEGER'] |
diff --git a/src/model/traits.php b/src/model/traits.php deleted file mode 100644 index 88451d9..0000000 --- a/src/model/traits.php +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | <?php | ||
2 | // src/model/traits.php | ||
3 | // | ||
4 | // fonctions "partagées" par les enfants de Model | ||
5 | |||
6 | trait ModelChildren | ||
7 | { | ||
8 | //~ public function __construct() | ||
9 | //~ { | ||
10 | //~ $this->table = strtolower(__CLASS__); | ||
11 | //~ echo "TABLE = " . $this->table . "\n"; | ||
12 | //~ } | ||
13 | } | ||