From 945af9fda5146405ab9903d4d268bcb2fe95da25 Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 10 Jan 2023 13:08:54 +0100 Subject: enregistrement section 1 --- src/model/Prestations.php | 73 ++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 42 deletions(-) (limited to 'src/model/Prestations.php') 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 @@ class Prestations extends Model { // lecture des données ou hydratation - protected $ID_presta; // auto-incrémentée + protected $ID; // auto-incrémentée protected $ID_client = 0; - protected $combientieme_fois = 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->combientiemeFois(); } // getters - public function getIDPresta(): int + public function getID(): int { - return $this->ID_presta; + return $this->ID; } public function getIDClient(): int { return $this->ID_client; } - public function getCombientiemeFois(): int - { - return $this->combientieme_fois; - } + //~ public function getCombientiemeFois(): int + //~ { + //~ return $this->combientieme_fois; + //~ } public function getDate(): int { return $this->date; } - - // setters - public function setIDPresta(int $value = 0) + public function getTypePresta(): string { - if($value === 0) - { - $this->ID_presta = $this->db->lastInsertId(); // méthode de PDO - } - else - { - $this->ID_presta = $value; - } - return($this); + return $this->type_presta; } + + // setters + //~ public function setID() -> dans le trait ModelChildren public function setIDClient(int $value) { $this->ID_client = $value; return($this); } - public function setCombientiemeFois(int $value) - { - $this->combientieme_fois = $value; - return($this); - } + //~ public function setCombientiemeFois(int $value) + //~ { + //~ $this->combientieme_fois = $value; + //~ return($this); + //~ } public function setCodePresta(string $value) { $this->code_presta = $value; @@ -90,25 +83,21 @@ class Prestations extends Model return($this); } - protected function combientiemeFois() - { - // on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente) - $array = $this->find(['ID_client' => $this->ID_client]); - $this->combientieme_fois = count($array) + 1; - } + //~ protected function combientiemeFois() + //~ { + //~ // on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente) + //~ $array = $this->find(['ID_client' => $this->ID_client]); + //~ //$this->combientieme_fois = count($array) + 1; + //~ return count($array) + 1; + //~ } // code client = année-mois-jour-codeclient-combientièmefois public function makeCodePresta(Dates $Date, string $code_client) { - $array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $code_client, $this->combientieme_fois]; + // on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente) + $combientieme_fois = count($this->find(['ID_client' => $this->ID_client])) + 1; + + $array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $code_client, $combientieme_fois]; $this->code_presta = implode('-', $array_code); } - - //~ public function newRow(array $input) - //~ { - //~ $this->hydrate(['ID_client' => $input[0], 'code_presta' => $input[1], 'date' => $input[2], 'type_presta' => $input[3], 'mode_paiement' => $input[4], 'commentaires' => $input[5]]); - //~ $this->create(); - //~ // ID obtenu par auto-incrémentation - //~ $this->ID_presta = $this->db->lastInsertId(); // méthode de PDO - //~ } } -- cgit v1.2.3