From 6f4cc3afffde36a13618458ffda72e6104624f36 Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 30 Aug 2023 12:20:39 +0200 Subject: =?UTF-8?q?section=20client=20=C3=A0=20part,=20section=20modif=20e?= =?UTF-8?q?n=20cours,=20bug=20dans=20Dates,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/CESU.php | 12 +++++++++-- src/model/Clients.php | 49 +++++++++++++++++++++++++++++++++++++++++--- src/model/DevisFactures.php | 34 ++++++++++++++++++++++++++++-- src/model/Locations.php | 18 ++++++++++++++-- src/model/Model.php | 25 ++++++++++++++++------ src/model/Prestations.php | 26 ++++++++++++++++++++--- src/model/StructTablesDB.php | 2 +- src/model/traits.php | 13 ------------ 8 files changed, 147 insertions(+), 32 deletions(-) delete mode 100644 src/model/traits.php (limited to 'src/model') 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 //~ const TABLE = 'cesu'; // lecture des données ou hydratation + protected $ID; protected $ID_presta; protected $taches; protected $duree_travail; protected $salaire; - //~ use ModelChildren; - public function __construct() { $this->table = strtolower(__CLASS__); // cesu } + public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) + { + return [ + "Numéro CESU:" => $this->ID, + "Tâche effectuée:" => $this->taches, + "Durée du travail:" => $this->duree_travail, + "Salaire:" => $this->salaire]; + } + // setters public function setIDPresta(int $value) { 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 protected $courriel; protected $apropos; protected $type = 'prospect'; - - //~ use ModelChildren; public function __construct() { @@ -31,6 +29,52 @@ class Clients extends Model { return $this->code_client; } + public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) + { + return [ + "Prénom Nom:" => $this->prenom_nom, + "Code client (J.C.Dusse):" => $this->code_client, + "Adresse:" => $this->adresse, + "Code postal:" => $this->code_postal, + "Ville:" => $this->ville, + "Telephone:" => $this->telephone, + "Courriel:" => $this->courriel, + "À propos:" => $this->apropos, + "Client ou Prospect?" => $this->type]; + } + public function getSetterAndSet(string $entry, string $input) + { + switch($entry) + { + case "Prénom Nom:": + $this->setPrenomNom($input); + break; + case "Code client (J.C.Dusse):": + $this->setCodeClient($input); + break; + case "Adresse:": + $this->setAdresse($input); + break; + case "Code postal:": + $this->setCodePostal($input); + break; + case "Ville:": + $this->setVille($input); + break; + case "Telephone:": + $this->setTelephone($input); + break; + case "Courriel:": + $this->setCourriel($input); + break; + case "À propos:": + $this->setApropos($input); + break; + case "Client ou Prospect?": + $this->setType($input); + break; + } + } // setters public function setPrenomNom($value) @@ -58,7 +102,6 @@ class Clients extends Model $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)) 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 protected $validite_devis; protected $signature_devis; - //~ use ModelChildren; - public function __construct(string $table) { $this->table = $table; // deux tables séparées devis et factures } + public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) + { + $champs_communs = [ + "Tâches:" => $this->taches, + "PC:" => $this->machine, + "OS:" => $this->OS, + "Données:" => $this->donnees, + "Clés de licences:" => $this->cles_licences, + "Total Main d'oeuvre:" => $this->total_main_d_oeuvre, + "Pièces" => $this->pieces, + "Total des pièces" => $this->total_pieces, + "Déplacement" => $this->deplacement, + "Total HT" => $this->total_HT]; + + if($this->table === 'factures') + { + return ["Numéro facture:" => $this->ID] + $champs_communs; + } + elseif($this->table === 'devis') + { + $champs_devis = [ + "Delai de livraison" => $this->delai_livraison, + "Durée de validité" => $this->validite_devis, + "Devis signé?" => $this->signature_devis]; + + return ["Numéro devis:" => $this->ID] + $champs_communs + $champs_devis; + } + else + { + return []; + } + } // setters 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 @@ class Locations extends Model { // lecture des données ou hydratation + protected $ID; protected $ID_presta; protected $designation; protected $modele_description; @@ -15,13 +16,26 @@ class Locations extends Model protected $loyers_payes; protected $caution; - //~ use ModelChildren; - public function __construct() { $this->table = strtolower(__CLASS__); // locations } + public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) + { + return [ + "Numéro location:" => $this->ID, + "Désignation:" => $this->designation, + "Description du modèle:" => $this->modele_description, + "Valeur:" => $this->valeur, + "État des lieux de début:" => $this->etat_des_lieux_debut, + "État des lieux de fin:" => $this->etat_des_lieux_fin, + "Durée de la location:" => $this->duree_location, + "Loyer Mensuel" => $this->loyer_mensuel, + "Loyers Payés" => $this->loyers_payes, + "Caution" => $this->caution]; + } + // setters public function setIDPresta(int $value) { 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 return $this->table; } - public function getAll(): array + public function getAll(): array // à améliorer pour ne pas renvoyer $db et $table { return get_object_vars($this); // retourne les propriétés de l'objet } @@ -29,7 +29,7 @@ abstract class Model extends DB { if($value === 0) { - $this->ID = $this->db->lastInsertId(); // méthode de PDO (attention ne gère pas la concurence) + $this->ID = $this->db->lastInsertId(); // méthode de PDO, attention lastInsertId() ne gère pas la concurence } else { @@ -183,9 +183,22 @@ abstract class Model extends DB return($this->execQuery('SELECT * FROM ' . $this->table)->fetchAll()); // fonctionne aussi sans le point virgule dans le SQL!! } - public function findById(int $id) // obtenir une entrée avec son ID + public function findById() // obtenir une entrée avec son ID { - return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id = ' . $id)->fetch()); + return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id = ' . $this->ID)->fetch()); + } + public function getDetailsByIdPresta() + { + if($this->table == 'prestations') + { + // à l'occaz, rendre abstraite la classe Prestations + echo 'erreur: ne pas appeler Model::getDetailsByIdPresta() si la table ciblée est "prestations".'; + return 0; + } + else + { + return $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id_Presta = ' . $this->ID_presta)->fetch(); // type array + } } 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 // update UPDATE - public function update(int $id) // utiliser plutôt $this->ID ? + public function update() { $fields = []; $values = []; @@ -219,7 +232,7 @@ abstract class Model extends DB $values[] = $value; } } - $values[] = $id; // cette syntaxe ajoute une valeur au tableau + $values[] = $this->ID; // cette syntaxe ajoute une valeur au tableau $field_list = implode(', ', $fields); // 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 protected $type_presta = ''; protected $mode_paiement = ''; protected $commentaires = ''; - - //~ use ModelChildren; public function __construct(int $ID_client) { @@ -29,6 +27,16 @@ class Prestations extends Model { return $this->ID_client; } + public function getIDsByIdClient() // obtenir une entrée avec son ID_client + { + $IDs = $this->execQuery('SELECT id FROM ' . $this->table . ' WHERE id_client = ' . $this->ID_client)->fetchAll(); + // changer le tableau de tableaux en tableau simple + for($i = 0; $i < count($IDs); $i++) + { + $IDs[$i] = $IDs[$i]['ID']; + } + return($IDs); + } public function getCodePresta(): string { return $this->code_presta; @@ -41,6 +49,18 @@ class Prestations extends Model { return $this->type_presta; } + public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) + { + $code_presta_tableau = explode('-', $this->code_presta); + $Date = new Dates($this->date); + + return [ + "Numéro prestation:" => end($code_presta_tableau), // dernière case + "Date:" => $Date->getDate(), + "Type de Presta:" => $this->type_presta, + "Mode de paiement:" => $this->mode_paiement, + "Commentaires:" => $this->commentaires]; + } // setters //~ public function setID() -> dans le trait ModelChildren @@ -81,7 +101,7 @@ class Prestations extends Model return $this; } - // code client = année-mois-jour-codeclient-combientièmefois + // code client = année-mois-jour-codeclient-typedepresta-combientièmefois public function makeCodePresta(Dates $Date, string $code_client) { // 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 // les tables devis_factures, cesu et locations sont liées à la table prestations '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'], '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', 'total_main_d_oeuvre' => 'REAL', 'pieces' => 'TEXT', 'total_pieces' => 'REAL', 'deplacement' => 'REAL', 'total_HT' => 'REAL', 'delai_livraison' => 'TEXT', 'validite_devis' => 'TEXT', 'signature_devis' => 'TEXT'], + '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'], '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' => '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 @@ -table = strtolower(__CLASS__); - //~ echo "TABLE = " . $this->table . "\n"; - //~ } -} -- cgit v1.2.3