From 1894fc377e6b938ea34df9980567a1634ec6ef48 Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 28 Dec 2022 05:19:55 +0100 Subject: =?UTF-8?q?r=C3=A9organisation=20+=20bient=C3=B4t=20finie=20la=20s?= =?UTF-8?q?ection=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/Prestations.php | 81 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 13 deletions(-) (limited to 'src/model/Prestations.php') diff --git a/src/model/Prestations.php b/src/model/Prestations.php index 32f9768..cbe8e6c 100644 --- a/src/model/Prestations.php +++ b/src/model/Prestations.php @@ -4,23 +4,56 @@ class Prestations extends Model { // lecture des données ou hydratation - private $ID; - private $IDClient; - private $combientieme_fois; - private $code_presta; - private $date; - private $type; - private $mode_paiement; - private $commentaires; + protected $ID_presta; // 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(); + } + + // getters + public function getIDPresta(): int + { + return $this->ID_presta; + } + public function getIDClient(): int + { + return $this->ID_client; + } + public function getCombientiemeFois(): int + { + return $this->combientieme_fois; + } + public function getDate(): int + { + return $this->date; + } // setters - public function setID(int $value) + public function setIDPresta(int $value = 0) { - $this->ID = $value; + if($value === 0) + { + $this->ID_presta = $this->db->lastInsertId(); // méthode de PDO + } + else + { + $this->ID_presta = $value; + } return($this); } + public function setIDClient(int $value) { $this->ID_client = $value; @@ -41,9 +74,9 @@ class Prestations extends Model $this->date = $value; return($this); } - public function setType(string $value) + public function setTypePresta(string $value) { - $this->type = $value; + $this->type_presta = $value; return($this); } public function setModePaiement(string $value) @@ -56,4 +89,26 @@ class Prestations extends Model $this->commentaires = $value; 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; + } + + // 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]; + $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