diff options
author | polo <ordipolo@gmx.fr> | 2023-02-25 02:27:22 +0100 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2023-02-25 02:27:22 +0100 |
commit | 9d8133643773912d54fb0c7d86ef04e6acffa8c9 (patch) | |
tree | 8048a9eeded086e9e9c00ce0a68b9454c171d085 /src/model | |
parent | 209c0b93c529356a094d7133a717e8f6ee6d90c6 (diff) | |
download | AppliGestionPHP-9d8133643773912d54fb0c7d86ef04e6acffa8c9.zip |
lire tables, modifications BDD, création documents et enveloppes latex, suppression de traits.php
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/CESU.php | 29 | ||||
-rw-r--r-- | src/model/Clients.php | 31 | ||||
-rw-r--r-- | src/model/DB.php | 2 | ||||
-rw-r--r-- | src/model/DevisFactures.php | 44 | ||||
-rw-r--r-- | src/model/Locations.php | 69 | ||||
-rw-r--r-- | src/model/Model.php | 95 | ||||
-rw-r--r-- | src/model/Prestations.php | 14 | ||||
-rw-r--r-- | src/model/StructTablesDB.php | 6 | ||||
-rw-r--r-- | src/model/traits.php | 86 |
9 files changed, 190 insertions, 186 deletions
diff --git a/src/model/CESU.php b/src/model/CESU.php index 2be89c0..8771607 100644 --- a/src/model/CESU.php +++ b/src/model/CESU.php | |||
@@ -6,30 +6,24 @@ 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 | private $ID_cesu; | 9 | protected $ID_presta; |
10 | private $taches; | 10 | protected $taches; |
11 | private $duree_travail; | 11 | protected $duree_travail; |
12 | private $salaire; | 12 | protected $salaire; |
13 | 13 | ||
14 | use ModelChildren; | 14 | //~ use ModelChildren; |
15 | 15 | ||
16 | public function __construct(int $client_ID) | 16 | public function __construct() |
17 | { | 17 | { |
18 | parent::__construct($client_ID); | 18 | $this->table = strtolower(__CLASS__); // cesu |
19 | $this->type == 'cesu'; | ||
20 | } | 19 | } |
21 | 20 | ||
22 | // setters | 21 | // setters |
23 | public function setIDCesu(int $value) | 22 | public function setIDPresta(int $value) |
24 | { | 23 | { |
25 | $this->ID_cesu = $value; | 24 | $this->ID_presta = $value; |
26 | return($this); | 25 | return($this); |
27 | } | 26 | } |
28 | //~ public function setIDPresta(int $value) | ||
29 | //~ { | ||
30 | //~ $this->ID_presta = $value; | ||
31 | //~ return($this); | ||
32 | //~ } | ||
33 | public function setTaches(string $value) | 27 | public function setTaches(string $value) |
34 | { | 28 | { |
35 | $this->taches = $value; | 29 | $this->taches = $value; |
@@ -40,9 +34,10 @@ class CESU extends Model | |||
40 | $this->duree_travail = $value; | 34 | $this->duree_travail = $value; |
41 | return($this); | 35 | return($this); |
42 | } | 36 | } |
43 | public function setSalaire(float $value) | 37 | public function setSalaire($value) |
44 | { | 38 | { |
45 | $this->salaire = $value; | 39 | $value = str_replace(',', '.', $value); |
40 | $this->salaire = (float) $value; | ||
46 | return($this); | 41 | return($this); |
47 | } | 42 | } |
48 | } | 43 | } |
diff --git a/src/model/Clients.php b/src/model/Clients.php index 9661562..d841451 100644 --- a/src/model/Clients.php +++ b/src/model/Clients.php | |||
@@ -8,23 +8,19 @@ class Clients extends Model | |||
8 | protected $prenom_nom; | 8 | protected $prenom_nom; |
9 | protected $code_client; | 9 | protected $code_client; |
10 | protected $adresse; | 10 | protected $adresse; |
11 | protected $code_postal; | ||
12 | protected $ville; | ||
11 | protected $telephone; | 13 | protected $telephone; |
12 | protected $courriel; | 14 | protected $courriel; |
13 | protected $commentaires; | 15 | protected $apropos; |
14 | 16 | ||
15 | use ModelChildren; // pour hydrateFromForm() | 17 | //~ use ModelChildren; |
16 | 18 | ||
17 | public function __construct() | 19 | public function __construct() |
18 | { | 20 | { |
19 | $this->table = 'clients'; // à mettre dans ModelChildren | 21 | $this->table = strtolower(__CLASS__); // clients |
20 | } | 22 | } |
21 | 23 | ||
22 | //~ public function set(string $variable, $value) | ||
23 | //~ { | ||
24 | //~ $this->$variable = $value; | ||
25 | //~ return($this); | ||
26 | //~ } | ||
27 | |||
28 | // getters | 24 | // getters |
29 | public function getID(): int | 25 | public function getID(): int |
30 | { | 26 | { |
@@ -36,8 +32,6 @@ class Clients extends Model | |||
36 | } | 32 | } |
37 | 33 | ||
38 | // setters | 34 | // setters |
39 | //~ public function setID() -> dans le trait ModelChildren | ||
40 | |||
41 | public function setPrenomNom($value) | 35 | public function setPrenomNom($value) |
42 | { | 36 | { |
43 | $this->prenom_nom = (string) $value; | 37 | $this->prenom_nom = (string) $value; |
@@ -53,6 +47,17 @@ class Clients extends Model | |||
53 | $this->adresse = (string) $value; | 47 | $this->adresse = (string) $value; |
54 | return($this); | 48 | return($this); |
55 | } | 49 | } |
50 | public function setCodePostal($value) | ||
51 | { | ||
52 | $this->code_postal = (string) $value; | ||
53 | return($this); | ||
54 | } | ||
55 | public function setVille($value) | ||
56 | { | ||
57 | $this->ville = (string) $value; | ||
58 | return($this); | ||
59 | } | ||
60 | |||
56 | public function setTelephone($value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début | 61 | public function setTelephone($value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début |
57 | { | 62 | { |
58 | if(is_numeric($value)) | 63 | if(is_numeric($value)) |
@@ -71,9 +76,9 @@ class Clients extends Model | |||
71 | $this->courriel = (string) $value; | 76 | $this->courriel = (string) $value; |
72 | return($this); | 77 | return($this); |
73 | } | 78 | } |
74 | public function setCommentaires($value) | 79 | public function setApropos($value) |
75 | { | 80 | { |
76 | $this->commentaires = (string) $value; | 81 | $this->apropos = (string) $value; |
77 | return($this); | 82 | return($this); |
78 | } | 83 | } |
79 | 84 | ||
diff --git a/src/model/DB.php b/src/model/DB.php index 381623b..52d6479 100644 --- a/src/model/DB.php +++ b/src/model/DB.php | |||
@@ -1,7 +1,7 @@ | |||
1 | <?php | 1 | <?php |
2 | // php/DB.php | 2 | // php/DB.php |
3 | 3 | ||
4 | // cette classe suit le pattern "singleton" | 4 | // cette classe applique le pattern "singleton" |
5 | // but: ne permettre qu'une seule instance de la classe (laquelle sera éventuellement globale) | 5 | // but: ne permettre qu'une seule instance de la classe (laquelle sera éventuellement globale) |
6 | 6 | ||
7 | // comment? | 7 | // comment? |
diff --git a/src/model/DevisFactures.php b/src/model/DevisFactures.php index ff80960..92a5443 100644 --- a/src/model/DevisFactures.php +++ b/src/model/DevisFactures.php | |||
@@ -13,41 +13,28 @@ class DevisFactures extends Model | |||
13 | protected $OS; | 13 | protected $OS; |
14 | protected $donnees; | 14 | protected $donnees; |
15 | protected $cles_licences; | 15 | protected $cles_licences; |
16 | protected $temps; | ||
17 | protected $total_main_d_oeuvre; | 16 | protected $total_main_d_oeuvre; |
18 | protected $pieces; | 17 | protected $pieces; |
19 | protected $total_pieces; | 18 | protected $total_pieces; |
20 | protected $deplacement; | 19 | protected $deplacement; |
21 | protected $total_HT; | 20 | protected $total_HT; |
21 | protected $delai_livraison; | ||
22 | protected $validite_devis; | 22 | protected $validite_devis; |
23 | protected $signature_devis; | 23 | protected $signature_devis; |
24 | 24 | ||
25 | use ModelChildren; // pour hydrateFromForm() | 25 | //~ use ModelChildren; |
26 | 26 | ||
27 | public function __construct(int $ID_presta, string $table) | 27 | public function __construct(string $table) |
28 | { | 28 | { |
29 | $this->ID_presta = $ID_presta; | ||
30 | $this->table = $table; // deux tables séparées devis et factures | 29 | $this->table = $table; // deux tables séparées devis et factures |
31 | } | 30 | } |
32 | 31 | ||
33 | // setters | 32 | // setters |
34 | //~ public function setID() -> dans le trait ModelChildren | ||
35 | |||
36 | public function setIDPresta(int $value) | 33 | public function setIDPresta(int $value) |
37 | { | 34 | { |
38 | $this->ID_presta = $value; | 35 | $this->ID_presta = $value; |
39 | return($this); | 36 | return($this); |
40 | } | 37 | } |
41 | public function setValiditedevis(string $value) | ||
42 | { | ||
43 | $this->validite_devis = $value; | ||
44 | return($this); | ||
45 | } | ||
46 | public function setSignatureDevis(string $value) | ||
47 | { | ||
48 | $this->signature_devis = $value; | ||
49 | return($this); | ||
50 | } | ||
51 | public function setTaches(string $value) | 38 | public function setTaches(string $value) |
52 | { | 39 | { |
53 | $this->taches = $value; | 40 | $this->taches = $value; |
@@ -73,11 +60,11 @@ class DevisFactures extends Model | |||
73 | $this->cles_licences = $value; | 60 | $this->cles_licences = $value; |
74 | return($this); | 61 | return($this); |
75 | } | 62 | } |
76 | public function setTemps(string $value) | 63 | //~ public function setTemps(string $value) |
77 | { | 64 | //~ { |
78 | $this->temps = $value; | 65 | //~ $this->temps = $value; |
79 | return($this); | 66 | //~ return($this); |
80 | } | 67 | //~ } |
81 | public function setTotalMainDOeuvre($value) | 68 | public function setTotalMainDOeuvre($value) |
82 | { | 69 | { |
83 | $value = str_replace(',', '.', $value); | 70 | $value = str_replace(',', '.', $value); |
@@ -107,6 +94,21 @@ class DevisFactures extends Model | |||
107 | $this->total_HT = (float) $value; | 94 | $this->total_HT = (float) $value; |
108 | return($this); | 95 | return($this); |
109 | } | 96 | } |
97 | public function setDelaiLivraison(string $value) | ||
98 | { | ||
99 | $this->delai_livraison = $value; | ||
100 | return($this); | ||
101 | } | ||
102 | public function setValiditedevis(string $value) | ||
103 | { | ||
104 | $this->validite_devis = $value; | ||
105 | return($this); | ||
106 | } | ||
107 | public function setSignatureDevis(string $value) | ||
108 | { | ||
109 | $this->signature_devis = $value; | ||
110 | return($this); | ||
111 | } | ||
110 | 112 | ||
111 | //~ public function newRow(array $input) | 113 | //~ public function newRow(array $input) |
112 | //~ { | 114 | //~ { |
diff --git a/src/model/Locations.php b/src/model/Locations.php index 21e9b09..8ebf757 100644 --- a/src/model/Locations.php +++ b/src/model/Locations.php | |||
@@ -4,48 +4,44 @@ | |||
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 | private $ID_location; | 7 | protected $ID_presta; |
8 | private $nature_bien; | 8 | protected $designation; |
9 | private $modele; | 9 | protected $modele_description; |
10 | private $valeur; | 10 | protected $valeur; |
11 | private $etat_des_lieux_debut; | 11 | protected $etat_des_lieux_debut; |
12 | private $etat_des_lieux_fin; | 12 | protected $etat_des_lieux_fin; |
13 | private $duree_location; | 13 | protected $duree_location; |
14 | private $loyer_mensuel; | 14 | protected $loyer_mensuel; |
15 | private $total_HT; | 15 | protected $loyers_payes; |
16 | protected $caution; | ||
16 | 17 | ||
17 | use ModelChildren; | 18 | //~ use ModelChildren; |
18 | 19 | ||
19 | public function __construct(int $client_ID) | 20 | public function __construct() |
20 | { | 21 | { |
21 | parent::__construct($client_ID); | 22 | $this->table = strtolower(__CLASS__); // locations |
22 | $this->type == 'location'; | ||
23 | } | 23 | } |
24 | 24 | ||
25 | // setters | 25 | // setters |
26 | public function setIDLocation(int $value) | 26 | public function setIDPresta(int $value) |
27 | { | 27 | { |
28 | $this->ID_location = $value; | 28 | $this->ID_presta = $value; |
29 | return($this); | 29 | return($this); |
30 | } | 30 | } |
31 | //~ public function setIDPresta(int $value) | 31 | public function setDesignation(string $value) |
32 | //~ { | ||
33 | //~ $this->ID_presta = $value; | ||
34 | //~ return($this); | ||
35 | //~ } | ||
36 | public function setNatureBien(string $value) | ||
37 | { | 32 | { |
38 | $this->nature_bien = $value; | 33 | $this->designation = $value; |
39 | return($this); | 34 | return($this); |
40 | } | 35 | } |
41 | public function setModele(string $value) | 36 | public function setModeleDescription(string $value) |
42 | { | 37 | { |
43 | $this->modele = $value; | 38 | $this->modele_description = $value; |
44 | return($this); | 39 | return($this); |
45 | } | 40 | } |
46 | public function setValeur(float $value) | 41 | public function setValeur($value) |
47 | { | 42 | { |
48 | $this->valeur = $value; | 43 | $value = str_replace(',', '.', $value); |
44 | $this->valeur = (float) $value; | ||
49 | return($this); | 45 | return($this); |
50 | } | 46 | } |
51 | public function setEtatDesLieuxDebut(string $value) | 47 | public function setEtatDesLieuxDebut(string $value) |
@@ -58,19 +54,28 @@ class Locations extends Model | |||
58 | $this->etat_des_lieux_fin = $value; | 54 | $this->etat_des_lieux_fin = $value; |
59 | return($this); | 55 | return($this); |
60 | } | 56 | } |
61 | public function setDureeLocation(string $value) | 57 | public function setDureeLocation($value) |
62 | { | 58 | { |
63 | $this->duree_location = $value; | 59 | $value = str_replace(',', '.', $value); |
60 | $this->duree_location = (float) $value; | ||
64 | return($this); | 61 | return($this); |
65 | } | 62 | } |
66 | public function setlLyerMensuel(float $value) | 63 | public function setLoyerMensuel($value) |
67 | { | 64 | { |
68 | $this->loyer_mensuel = $value; | 65 | $value = str_replace(',', '.', $value); |
66 | $this->loyer_mensuel = (float) $value; | ||
69 | return($this); | 67 | return($this); |
70 | } | 68 | } |
71 | public function setTotalHT(float $value) | 69 | public function setLoyersPayes($value) |
72 | { | 70 | { |
73 | $this->total_HT = $value; | 71 | $value = str_replace(',', '.', $value); |
72 | $this->loyers_payes = (float) $value; | ||
73 | return($this); | ||
74 | } | ||
75 | public function setCaution($value) | ||
76 | { | ||
77 | $value = str_replace(',', '.', $value); | ||
78 | $this->caution = (float) $value; | ||
74 | return($this); | 79 | return($this); |
75 | } | 80 | } |
76 | } | 81 | } |
diff --git a/src/model/Model.php b/src/model/Model.php index 4c1fb4d..6a7907c 100644 --- a/src/model/Model.php +++ b/src/model/Model.php | |||
@@ -1,16 +1,16 @@ | |||
1 | <?php | 1 | <?php |
2 | // php/Model.php | 2 | // php/Model.php |
3 | 3 | ||
4 | class Model extends DB | 4 | abstract class Model extends DB |
5 | { | 5 | { |
6 | protected $db; // instance de PDO | 6 | protected $db; // instance de PDO |
7 | protected $table; // <= enfant | 7 | protected $table; // <= enfant |
8 | //static protected $tableStructure; | 8 | //static protected $tableStructure; |
9 | 9 | ||
10 | public function __construct() | 10 | public function __construct() // à surcharger |
11 | { | 11 | { |
12 | //~ $this->db = parent::getInstance(); // connexion | ||
13 | //~ $this->table = strtolower(__CLASS__); | 12 | //~ $this->table = strtolower(__CLASS__); |
13 | //~ echo "TABLE = " . $this->table . "\n"; | ||
14 | } | 14 | } |
15 | 15 | ||
16 | // getters | 16 | // getters |
@@ -19,7 +19,25 @@ class Model extends DB | |||
19 | return($this->table); | 19 | return($this->table); |
20 | } | 20 | } |
21 | 21 | ||
22 | public function getAll(): array | ||
23 | { | ||
24 | return get_object_vars($this); // retourne les propriétés de l'objet | ||
25 | } | ||
26 | |||
22 | // setters | 27 | // setters |
28 | public function setID(int $value = 0) | ||
29 | { | ||
30 | if($value === 0) | ||
31 | { | ||
32 | $this->ID = $this->db->lastInsertId(); // méthode de PDO (attention ne gère pas la concurence) | ||
33 | } | ||
34 | else | ||
35 | { | ||
36 | $this->ID = $value; | ||
37 | } | ||
38 | return($this); | ||
39 | } | ||
40 | |||
23 | public function hydrate(array $data): bool // $data = tableau associatif en entrée: nom_du_champ => valeur | 41 | public function hydrate(array $data): bool // $data = tableau associatif en entrée: nom_du_champ => valeur |
24 | { | 42 | { |
25 | foreach($data as $key => $value) | 43 | foreach($data as $key => $value) |
@@ -41,6 +59,71 @@ class Model extends DB | |||
41 | return true; | 59 | return true; |
42 | } | 60 | } |
43 | 61 | ||
62 | // cette fonction reçoit des données d'un tableau simple, permettant d'associer des champs de formulaires aux noms différents des champs de la BDD | ||
63 | function hydrateFromForm(string $data_string, Object $Presta = NULL): bool // quand l'objet est $Details, on hydrate aussi $Presta | ||
64 | { | ||
65 | //~ $tableSize = count(StructTablesDB::$structureOfTables[$this->getTable()]); // int | ||
66 | |||
67 | if($data_string !== '') | ||
68 | { | ||
69 | $data_array = explode('|', $data_string); // array | ||
70 | $check = false; | ||
71 | switch($this->getTable()) | ||
72 | { | ||
73 | case 'clients'; | ||
74 | if($data_array[0] == '') | ||
75 | { | ||
76 | echo "debug: données insuffisantes, le nom du client doit au minimum être renseigné\n"; | ||
77 | return false; | ||
78 | } | ||
79 | else | ||
80 | { | ||
81 | $check = $this->hydrate(['prenom_nom' => $data_array[0], 'code_client' => $data_array[1], 'adresse' => $data_array[2], 'code_postal' => $data_array[3], 'ville' => $data_array[4], 'telephone' => $data_array[5], 'courriel' => $data_array[6], 'apropos' => $data_array[7]]); | ||
82 | } | ||
83 | break; | ||
84 | case 'prestations'; // inutilisé | ||
85 | break; | ||
86 | case 'devis'; | ||
87 | $check = $Presta->hydrate(['mode_paiement' => $data_array[6]]); | ||
88 | if($check) | ||
89 | { | ||
90 | $check = $this->hydrate(['taches' => $data_array[0], 'total_main_d_oeuvre' => $data_array[1], 'pieces' => $data_array[2], 'total_pieces' => $data_array[3], 'deplacement' => $data_array[4], 'total_HT' => $data_array[5], 'delai_livraison' => $data_array[7], 'validite_devis' => $data_array[8], 'signature_devis' => $data_array[9]]); | ||
91 | } | ||
92 | break; | ||
93 | case 'factures'; | ||
94 | $check = $Presta->hydrate(['mode_paiement' => $data_array[10]]); | ||
95 | if($check) | ||
96 | { | ||
97 | $check = $this->hydrate(['taches' => $data_array[0], 'machine' => $data_array[1], 'OS' => $data_array[2], 'donnees' => $data_array[3], 'cles_licences' => $data_array[4], 'total_main_d_oeuvre' => $data_array[5], 'pieces' => $data_array[6], 'total_pieces' => $data_array[7], 'deplacement' => $data_array[8], 'total_HT' => $data_array[9]]); | ||
98 | } | ||
99 | break; | ||
100 | case 'cesu'; | ||
101 | $check = $Presta->hydrate(['mode_paiement' => $data_array[3]]); | ||
102 | if($check) | ||
103 | { | ||
104 | $check = $this->hydrate(['taches' => $data_array[0], 'duree_travail' => $data_array[1], 'salaire' => $data_array[2]]); | ||
105 | } | ||
106 | break; | ||
107 | case 'locations'; | ||
108 | //~ $check = $Presta->hydrate(['mode_paiement' => $data_array[11]]); | ||
109 | //~ if($check) | ||
110 | //~ { | ||
111 | $check = $this->hydrate(['designation' => $data_array[0], 'modele_description' => $data_array[1], 'valeur' => $data_array[2], 'etat_des_lieux_debut' => $data_array[3], 'etat_des_lieux_fin' => $data_array[4], 'duree_location' => $data_array[5], 'loyer_mensuel' => $data_array[6], 'loyers_payes' => $data_array[7], 'caution' => $data_array[8]]); | ||
112 | //~ } | ||
113 | break; | ||
114 | default: // inutilisé | ||
115 | echo "debug: table inconnue hydrateFromForm()"; | ||
116 | return false; | ||
117 | } | ||
118 | return $check; | ||
119 | } | ||
120 | else | ||
121 | { | ||
122 | echo "debug: annulation lors du formulaire\n"; | ||
123 | return false; | ||
124 | } | ||
125 | } | ||
126 | |||
44 | 127 | ||
45 | // exécuter le SQL | 128 | // exécuter le SQL |
46 | // les attributs correspondent aux ? dans les requêtes préparées | 129 | // les attributs correspondent aux ? dans les requêtes préparées |
@@ -51,8 +134,8 @@ class Model extends DB | |||
51 | 134 | ||
52 | if($attributes !== null) // requête préparée | 135 | if($attributes !== null) // requête préparée |
53 | { | 136 | { |
54 | var_dump($sql); | 137 | //~ var_dump($sql); |
55 | var_dump($attributes); | 138 | //~ var_dump($attributes); |
56 | $query = $this->db->prepare($sql); | 139 | $query = $this->db->prepare($sql); |
57 | $query->execute($attributes); | 140 | $query->execute($attributes); |
58 | return $query; | 141 | return $query; |
@@ -75,7 +158,7 @@ class Model extends DB | |||
75 | //~ var_dump($this); | 158 | //~ var_dump($this); |
76 | foreach($this as $field => $value) | 159 | foreach($this as $field => $value) |
77 | { | 160 | { |
78 | var_dump($field); var_dump($value); | 161 | //~ var_dump($field); var_dump($value); |
79 | // champs non renseignées et variables de l'objet qui ne sont pas des champs | 162 | // champs non renseignées et variables de l'objet qui ne sont pas des champs |
80 | // note: avec le !== (au lieu de !=) une valeur 0 est différente de null | 163 | // note: avec le !== (au lieu de !=) une valeur 0 est différente de null |
81 | if($value !== null && $field != 'db' && $field != 'table') | 164 | if($value !== null && $field != 'db' && $field != 'table') |
diff --git a/src/model/Prestations.php b/src/model/Prestations.php index 2f84daa..ddd785b 100644 --- a/src/model/Prestations.php +++ b/src/model/Prestations.php | |||
@@ -6,20 +6,18 @@ class Prestations extends Model | |||
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 $ID_client = 0; | 8 | protected $ID_client = 0; |
9 | //~ protected $combientieme_fois = 0; | ||
10 | protected $code_presta = ''; | 9 | protected $code_presta = ''; |
11 | protected $date = 0; // timestamp unix | 10 | protected $date = 0; // timestamp unix |
12 | protected $type_presta = ''; | 11 | protected $type_presta = ''; |
13 | protected $mode_paiement = ''; | 12 | protected $mode_paiement = ''; |
14 | protected $commentaires = ''; | 13 | protected $commentaires = ''; |
15 | 14 | ||
16 | use ModelChildren; | 15 | //~ use ModelChildren; |
17 | 16 | ||
18 | public function __construct(int $ID_client) | 17 | public function __construct(int $ID_client) |
19 | { | 18 | { |
20 | $this->table = 'prestations'; | ||
21 | $this->ID_client = $ID_client; | 19 | $this->ID_client = $ID_client; |
22 | //~ $this->combientiemeFois(); | 20 | $this->table = strtolower(__CLASS__); // prestations |
23 | } | 21 | } |
24 | 22 | ||
25 | // getters | 23 | // getters |
@@ -31,10 +29,10 @@ class Prestations extends Model | |||
31 | { | 29 | { |
32 | return $this->ID_client; | 30 | return $this->ID_client; |
33 | } | 31 | } |
34 | //~ public function getCombientiemeFois(): int | 32 | public function getCodePresta(): string |
35 | //~ { | 33 | { |
36 | //~ return $this->combientieme_fois; | 34 | return $this->code_presta; |
37 | //~ } | 35 | } |
38 | public function getDate(): int | 36 | public function getDate(): int |
39 | { | 37 | { |
40 | return $this->date; | 38 | return $this->date; |
diff --git a/src/model/StructTablesDB.php b/src/model/StructTablesDB.php index 00c5321..32ae92d 100644 --- a/src/model/StructTablesDB.php +++ b/src/model/StructTablesDB.php | |||
@@ -9,10 +9,10 @@ class StructTablesDB | |||
9 | static public $structureOfTables = [ | 9 | static public $structureOfTables = [ |
10 | // la table prestations est liée à la table clients | 10 | // la table prestations est liée à la table clients |
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', 'code_postal' => 'TEXT', 'ville' => 'TEXT', 'telephone' => 'TEXT', 'courriel' => 'TEXT', 'apropos' => '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 | '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'], | 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'], |
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 | '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' => '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'] |
18 | ]; | 18 | ]; |
diff --git a/src/model/traits.php b/src/model/traits.php index 41f1c35..a00032e 100644 --- a/src/model/traits.php +++ b/src/model/traits.php | |||
@@ -8,90 +8,6 @@ trait ModelChildren | |||
8 | //~ public function __construct() | 8 | //~ public function __construct() |
9 | //~ { | 9 | //~ { |
10 | //~ $this->table = strtolower(__CLASS__); | 10 | //~ $this->table = strtolower(__CLASS__); |
11 | //~ echo "TABLE = " . $this->table . "\n"; | ||
11 | //~ } | 12 | //~ } |
12 | |||
13 | //~ public function setIdFromLastInsertID() // à faire juste après l'écriture d'une nouvelle entrée | ||
14 | //~ { | ||
15 | //~ $this->db = parent::getInstance(); | ||
16 | //~ $this->ID = $this->db->lastInsertId(); // méthode de PDO | ||
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 | } | ||
97 | } | 13 | } |