From 9d8133643773912d54fb0c7d86ef04e6acffa8c9 Mon Sep 17 00:00:00 2001 From: polo Date: Sat, 25 Feb 2023 02:27:22 +0100 Subject: =?UTF-8?q?lire=20tables,=20modifications=20BDD,=20cr=C3=A9ation?= =?UTF-8?q?=20documents=20et=20enveloppes=20latex,=20suppression=20de=20tr?= =?UTF-8?q?aits.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/CESU.php | 29 ++++++-------- src/model/Clients.php | 31 +++++++++------ src/model/DB.php | 2 +- src/model/DevisFactures.php | 44 ++++++++++---------- src/model/Locations.php | 69 +++++++++++++++++--------------- src/model/Model.php | 95 +++++++++++++++++++++++++++++++++++++++++--- src/model/Prestations.php | 14 +++---- src/model/StructTablesDB.php | 6 +-- src/model/traits.php | 86 +-------------------------------------- 9 files changed, 190 insertions(+), 186 deletions(-) (limited to 'src/model') 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 //~ const TABLE = 'cesu'; // lecture des données ou hydratation - private $ID_cesu; - private $taches; - private $duree_travail; - private $salaire; + protected $ID_presta; + protected $taches; + protected $duree_travail; + protected $salaire; - use ModelChildren; + //~ use ModelChildren; - public function __construct(int $client_ID) + public function __construct() { - parent::__construct($client_ID); - $this->type == 'cesu'; + $this->table = strtolower(__CLASS__); // cesu } // setters - public function setIDCesu(int $value) + public function setIDPresta(int $value) { - $this->ID_cesu = $value; + $this->ID_presta = $value; return($this); } - //~ public function setIDPresta(int $value) - //~ { - //~ $this->ID_presta = $value; - //~ return($this); - //~ } public function setTaches(string $value) { $this->taches = $value; @@ -40,9 +34,10 @@ class CESU extends Model $this->duree_travail = $value; return($this); } - public function setSalaire(float $value) + public function setSalaire($value) { - $this->salaire = $value; + $value = str_replace(',', '.', $value); + $this->salaire = (float) $value; return($this); } } 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 protected $prenom_nom; protected $code_client; protected $adresse; + protected $code_postal; + protected $ville; protected $telephone; protected $courriel; - protected $commentaires; + protected $apropos; - use ModelChildren; // pour hydrateFromForm() + //~ use ModelChildren; public function __construct() { - $this->table = 'clients'; // à mettre dans ModelChildren + $this->table = strtolower(__CLASS__); // clients } - //~ public function set(string $variable, $value) - //~ { - //~ $this->$variable = $value; - //~ return($this); - //~ } - // getters public function getID(): int { @@ -36,8 +32,6 @@ class Clients extends Model } // setters - //~ public function setID() -> dans le trait ModelChildren - public function setPrenomNom($value) { $this->prenom_nom = (string) $value; @@ -53,6 +47,17 @@ class Clients extends Model $this->adresse = (string) $value; return($this); } + public function setCodePostal($value) + { + $this->code_postal = (string) $value; + return($this); + } + public function setVille($value) + { + $this->ville = (string) $value; + return($this); + } + public function setTelephone($value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début { if(is_numeric($value)) @@ -71,9 +76,9 @@ class Clients extends Model $this->courriel = (string) $value; return($this); } - public function setCommentaires($value) + public function setApropos($value) { - $this->commentaires = (string) $value; + $this->apropos = (string) $value; return($this); } 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 @@ ID_presta = $ID_presta; $this->table = $table; // deux tables séparées devis et factures } // setters - //~ public function setID() -> dans le trait ModelChildren - public function setIDPresta(int $value) { $this->ID_presta = $value; return($this); } - public function setValiditedevis(string $value) - { - $this->validite_devis = $value; - return($this); - } - public function setSignatureDevis(string $value) - { - $this->signature_devis = $value; - return($this); - } public function setTaches(string $value) { $this->taches = $value; @@ -73,11 +60,11 @@ class DevisFactures extends Model $this->cles_licences = $value; return($this); } - public function setTemps(string $value) - { - $this->temps = $value; - return($this); - } + //~ public function setTemps(string $value) + //~ { + //~ $this->temps = $value; + //~ return($this); + //~ } public function setTotalMainDOeuvre($value) { $value = str_replace(',', '.', $value); @@ -107,6 +94,21 @@ class DevisFactures extends Model $this->total_HT = (float) $value; return($this); } + public function setDelaiLivraison(string $value) + { + $this->delai_livraison = $value; + return($this); + } + public function setValiditedevis(string $value) + { + $this->validite_devis = $value; + return($this); + } + public function setSignatureDevis(string $value) + { + $this->signature_devis = $value; + return($this); + } //~ public function newRow(array $input) //~ { 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 @@ class Locations extends Model { // lecture des données ou hydratation - private $ID_location; - private $nature_bien; - private $modele; - private $valeur; - private $etat_des_lieux_debut; - private $etat_des_lieux_fin; - private $duree_location; - private $loyer_mensuel; - private $total_HT; + protected $ID_presta; + protected $designation; + protected $modele_description; + protected $valeur; + protected $etat_des_lieux_debut; + protected $etat_des_lieux_fin; + protected $duree_location; + protected $loyer_mensuel; + protected $loyers_payes; + protected $caution; - use ModelChildren; + //~ use ModelChildren; - public function __construct(int $client_ID) + public function __construct() { - parent::__construct($client_ID); - $this->type == 'location'; + $this->table = strtolower(__CLASS__); // locations } // setters - public function setIDLocation(int $value) + public function setIDPresta(int $value) { - $this->ID_location = $value; + $this->ID_presta = $value; return($this); } - //~ public function setIDPresta(int $value) - //~ { - //~ $this->ID_presta = $value; - //~ return($this); - //~ } - public function setNatureBien(string $value) + public function setDesignation(string $value) { - $this->nature_bien = $value; + $this->designation = $value; return($this); } - public function setModele(string $value) + public function setModeleDescription(string $value) { - $this->modele = $value; + $this->modele_description = $value; return($this); } - public function setValeur(float $value) + public function setValeur($value) { - $this->valeur = $value; + $value = str_replace(',', '.', $value); + $this->valeur = (float) $value; return($this); } public function setEtatDesLieuxDebut(string $value) @@ -58,19 +54,28 @@ class Locations extends Model $this->etat_des_lieux_fin = $value; return($this); } - public function setDureeLocation(string $value) + public function setDureeLocation($value) { - $this->duree_location = $value; + $value = str_replace(',', '.', $value); + $this->duree_location = (float) $value; return($this); } - public function setlLyerMensuel(float $value) + public function setLoyerMensuel($value) { - $this->loyer_mensuel = $value; + $value = str_replace(',', '.', $value); + $this->loyer_mensuel = (float) $value; return($this); } - public function setTotalHT(float $value) + public function setLoyersPayes($value) { - $this->total_HT = $value; + $value = str_replace(',', '.', $value); + $this->loyers_payes = (float) $value; + return($this); + } + public function setCaution($value) + { + $value = str_replace(',', '.', $value); + $this->caution = (float) $value; return($this); } } 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 @@ db = parent::getInstance(); // connexion //~ $this->table = strtolower(__CLASS__); + //~ echo "TABLE = " . $this->table . "\n"; } // getters @@ -19,7 +19,25 @@ class Model extends DB return($this->table); } + public function getAll(): array + { + return get_object_vars($this); // retourne les propriétés de l'objet + } + // setters + public function setID(int $value = 0) + { + if($value === 0) + { + $this->ID = $this->db->lastInsertId(); // méthode de PDO (attention ne gère pas la concurence) + } + else + { + $this->ID = $value; + } + return($this); + } + public function hydrate(array $data): bool // $data = tableau associatif en entrée: nom_du_champ => valeur { foreach($data as $key => $value) @@ -41,6 +59,71 @@ class Model extends DB return true; } + // 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 + function hydrateFromForm(string $data_string, Object $Presta = NULL): bool // quand l'objet est $Details, on hydrate aussi $Presta + { + //~ $tableSize = count(StructTablesDB::$structureOfTables[$this->getTable()]); // int + + if($data_string !== '') + { + $data_array = explode('|', $data_string); // array + $check = false; + switch($this->getTable()) + { + case 'clients'; + if($data_array[0] == '') + { + echo "debug: données insuffisantes, le nom du client doit au minimum être renseigné\n"; + return false; + } + else + { + $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]]); + } + break; + case 'prestations'; // inutilisé + break; + case 'devis'; + $check = $Presta->hydrate(['mode_paiement' => $data_array[6]]); + if($check) + { + $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]]); + } + break; + case 'factures'; + $check = $Presta->hydrate(['mode_paiement' => $data_array[10]]); + if($check) + { + $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]]); + } + break; + case 'cesu'; + $check = $Presta->hydrate(['mode_paiement' => $data_array[3]]); + if($check) + { + $check = $this->hydrate(['taches' => $data_array[0], 'duree_travail' => $data_array[1], 'salaire' => $data_array[2]]); + } + break; + case 'locations'; + //~ $check = $Presta->hydrate(['mode_paiement' => $data_array[11]]); + //~ if($check) + //~ { + $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]]); + //~ } + break; + default: // inutilisé + echo "debug: table inconnue hydrateFromForm()"; + return false; + } + return $check; + } + else + { + echo "debug: annulation lors du formulaire\n"; + return false; + } + } + // exécuter le SQL // les attributs correspondent aux ? dans les requêtes préparées @@ -51,8 +134,8 @@ class Model extends DB if($attributes !== null) // requête préparée { - var_dump($sql); - var_dump($attributes); + //~ var_dump($sql); + //~ var_dump($attributes); $query = $this->db->prepare($sql); $query->execute($attributes); return $query; @@ -75,7 +158,7 @@ class Model extends DB //~ var_dump($this); foreach($this as $field => $value) { - var_dump($field); var_dump($value); + //~ var_dump($field); var_dump($value); // champs non renseignées et variables de l'objet qui ne sont pas des champs // note: avec le !== (au lieu de !=) une valeur 0 est différente de null 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 // lecture des données ou hydratation protected $ID; // auto-incrémentée protected $ID_client = 0; - //~ protected $combientieme_fois = 0; protected $code_presta = ''; protected $date = 0; // timestamp unix protected $type_presta = ''; protected $mode_paiement = ''; protected $commentaires = ''; - use ModelChildren; + //~ use ModelChildren; public function __construct(int $ID_client) { - $this->table = 'prestations'; $this->ID_client = $ID_client; - //~ $this->combientiemeFois(); + $this->table = strtolower(__CLASS__); // prestations } // getters @@ -31,10 +29,10 @@ class Prestations extends Model { return $this->ID_client; } - //~ public function getCombientiemeFois(): int - //~ { - //~ return $this->combientieme_fois; - //~ } + public function getCodePresta(): string + { + return $this->code_presta; + } public function getDate(): int { 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 static public $structureOfTables = [ // la table prestations est liée à la table clients // les tables devis_factures, cesu et locations sont liées à la table prestations - 'clients' => ['ID' => 'INTEGER', 'prenom_nom' => 'TEXT', 'code_client' => 'TEXT', 'adresse' => 'TEXT', 'telephone' => 'TEXT', 'courriel' => 'TEXT', 'commentaires' => 'TEXT'], + 'clients' => ['ID' => 'INTEGER', 'prenom_nom' => 'TEXT', 'code_client' => 'TEXT', 'adresse' => 'TEXT', 'code_postal' => 'TEXT', 'ville' => 'TEXT', 'telephone' => 'TEXT', 'courriel' => 'TEXT', 'apropos' => 'TEXT'], 'prestations' => ['ID' => 'INTEGER', 'ID_client' => 'INTEGER', 'code_presta' => 'TEXT', 'date' => 'INTEGER', 'type_presta' => 'TEXT', 'mode_paiement' => 'TEXT', 'commentaires' => 'TEXT'], - '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'], - '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'], + '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'], + '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'], 'cesu' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'duree_travail' => 'TEXT', 'salaire' => 'REAL'], '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'] ]; 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 //~ public function __construct() //~ { //~ $this->table = strtolower(__CLASS__); + //~ echo "TABLE = " . $this->table . "\n"; //~ } - - //~ public function setIdFromLastInsertID() // à faire juste après l'écriture d'une nouvelle entrée - //~ { - //~ $this->db = parent::getInstance(); - //~ $this->ID = $this->db->lastInsertId(); // méthode de PDO - //~ } - - public function setID(int $value = 0) - { - if($value === 0) - { - $this->ID = $this->db->lastInsertId(); // méthode de PDO - } - else - { - $this->ID = $value; - } - return($this); - } - - function hydrateFromForm(string $data_string, Object $Presta = NULL): bool // quand l'objet est $DetailsPresta, on hydrate aussi $Presta - { - //~ $tableSize = count(StructTablesDB::$structureOfTables[$this->getTable()]); // int - - if($data_string !== '') - { - $data_array = explode('|', $data_string); // array - //~ var_dump($data_array); - //~ if(count($data_array) === $tableSize - 1) // nombre de champs sauf ID qui est auto-incrémenté automatiquement - //~ { - //~ var_dump($this->getTable()); - //~ var_dump($data_array); - $check = false; - switch($this->getTable()) - { - case 'clients'; - if($data_array[0] == '') - { - echo "debug: données insuffisantes, le nom du client doit au minimum être renseigné\n"; - return false; - } - else - { - $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]]); - } - break; - case 'prestations'; // inutilisé - break; - case 'devis'; - $check = $Presta->hydrate(['mode_paiement' => $data_array[11]]); - if($check) - { - $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], - 'validite_devis' => $data_array[12], 'signature_devis' => $data_array[13]]); - } - break; - case 'factures'; - $check = $Presta->hydrate(['mode_paiement' => $data_array[11]]); - if($check) - { - $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]]); - } - break; - case 'cesu'; - break; - case 'locations'; - break; - default: // inutilisé - echo "debug: table inconnue hydrateFromForm()"; - return false; - } - return $check; - //~ } - //~ else - //~ { - //~ echo "debug: mauvais tableau, il doit avoir " . $tableSize - 1 . " cases\n"; // ou -3 pour les factures - //~ return false; - //~ } - } - else - { - echo "debug: annulation lors du formulaire\n"; - return false; - } - } } -- cgit v1.2.3