From bf6655a534a6775d30cafa67bd801276bda1d98d Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 13 Aug 2024 23:45:21 +0200 Subject: =?UTF-8?q?VERSION=200.2=20doctrine=20ORM=20et=20entit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/version 0.1/Prestations.php | 159 ++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 src/model/version 0.1/Prestations.php (limited to 'src/model/version 0.1/Prestations.php') diff --git a/src/model/version 0.1/Prestations.php b/src/model/version 0.1/Prestations.php new file mode 100644 index 0000000..18bc787 --- /dev/null +++ b/src/model/version 0.1/Prestations.php @@ -0,0 +1,159 @@ +id_client = $id_client; + $this->table = strtolower(__CLASS__); // prestations + } + + // getters + public function getId(): int + { + return $this->id; + } + public function getIdClient(): int + { + return $this->id_client; + } + public function getIdsByIdClient() // obtenir une entrée avec son id_client, comportement différent si le type est connu + { + $sql = 'SELECT id FROM ' . $this->table . ' WHERE id_client = ' . $this->id_client; + if($this->type_presta != '') + { + $sql .= " AND type_presta = '" . $this->type_presta . "'"; + } + $data = $this->execQuery($sql)->fetchAll(); // tableau de tableaux + + $IDs = []; // si $IDs reste vide, ne pas être de type NULL + for($i = 0; $i < count($data); $i++) + { + $IDs[$i] = $data[$i]['id']; // tableau simple + } + return($IDs); + } + public function getCodePresta(): string + { + return $this->code_presta; + } + public function getDate(): int // timestamp unix + { + return $this->date; + } + public function getTypePresta(): string + { + 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, // choix impossible pour le moment + "Mode de paiement:" => $this->mode_paiement, // non pertinent pour un devis + "Commentaires:" => $this->commentaires]; + } + public function set(string $entry, string $input) + { + $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide + switch($entry) + { + case "Numéro prestation:": + $this->setNumeroPresta($input); + break; + //~ case "Date:": // inutile, setDate() est appelé directement après choix fenêtre calendrier + //~ $this->setDate($input); + //~ break; + //~ case "Type de Presta:": // choix impossible pour le moment + //~ $this->setTypePresta($input); + //~ break; + case "Mode de paiement:": + $this->setModePaiement($input); + break; + case "Commentaires:": + $this->setCommentaires($input); + break; + } + } + + // setters + public function setIdClient(int $value) + { + $this->id_client = $value; + return $this; + } + //~ public function setCombientiemeFois(int $value) + //~ { + //~ $this->combientieme_fois = $value; + //~ return($this); + //~ } + public function setCodePresta(string $value) + { + $this->code_presta = $value; + return $this; + } + public function setDate($value, bool $set_code_presta = false) // attend un timestamp + { + $this->date = (int) $value; + + if($set_code_presta) + { + $code_presta_tableau = explode('-', $this->code_presta); + $Date = new Dates($value); + $code_presta_tableau[0] = $Date->getYear(); + $code_presta_tableau[1] = $Date->getMonth(); + $code_presta_tableau[2] = $Date->getDay(); + $this->code_presta = implode('-', $code_presta_tableau); + } + + return $this; + } + public function setTypePresta(string $value) + { + $this->type_presta = $value; + return $this; + } + public function setModePaiement(string $value) + { + $this->mode_paiement = $value; + return $this; + } + public function setCommentaires(string $value) + { + $this->commentaires = $this->cleanSpecialChars($value); // nettoyage ici parce que pas possible ailleurs + return $this; + } + public function setNumeroPresta($value) + { + // modifier le code presta, on pourrait aussi utiliser une regex + $code_presta_tableau = explode('-', $this->code_presta); + $code_presta_tableau[count($code_presta_tableau) - 1] = (int) $value; + $this->code_presta = implode('-', $code_presta_tableau); + return $this; + } + + // code presta = 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) + // inconvénient: il peut y avoir plusieurs prestations avec le même numéro au compteur, à améliorer + $combientieme_fois = count($this->find(['id_client' => $this->id_client])) + 1; + + $array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $code_client, $this->type_presta, $combientieme_fois]; + $this->code_presta = implode('-', $array_code); + } +} -- cgit v1.2.3