summaryrefslogtreecommitdiff
path: root/src/model/version 0.1/Prestations.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/version 0.1/Prestations.php')
-rw-r--r--src/model/version 0.1/Prestations.php159
1 files changed, 159 insertions, 0 deletions
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 @@
1<?php
2// src/model/Prestations.php
3
4class Prestations extends Model
5{
6 // lecture des données ou hydratation
7 protected $id; // auto-incrémentée
8 protected $id_client = 0;
9 protected $code_presta = '';
10 protected $date = 0; // timestamp unix
11 protected $type_presta = '';
12 protected $mode_paiement = '';
13 protected $commentaires = '';
14 //protected $numero_presta = 0;
15
16 public function __construct(int $id_client)
17 { $this->id_client = $id_client;
18 $this->table = strtolower(__CLASS__); // prestations
19 }
20
21 // getters
22 public function getId(): int
23 {
24 return $this->id;
25 }
26 public function getIdClient(): int
27 {
28 return $this->id_client;
29 }
30 public function getIdsByIdClient() // obtenir une entrée avec son id_client, comportement différent si le type est connu
31 {
32 $sql = 'SELECT id FROM ' . $this->table . ' WHERE id_client = ' . $this->id_client;
33 if($this->type_presta != '')
34 {
35 $sql .= " AND type_presta = '" . $this->type_presta . "'";
36 }
37 $data = $this->execQuery($sql)->fetchAll(); // tableau de tableaux
38
39 $IDs = []; // si $IDs reste vide, ne pas être de type NULL
40 for($i = 0; $i < count($data); $i++)
41 {
42 $IDs[$i] = $data[$i]['id']; // tableau simple
43 }
44 return($IDs);
45 }
46 public function getCodePresta(): string
47 {
48 return $this->code_presta;
49 }
50 public function getDate(): int // timestamp unix
51 {
52 return $this->date;
53 }
54 public function getTypePresta(): string
55 {
56 return $this->type_presta;
57 }
58 public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this)
59 {
60 $code_presta_tableau = explode('-', $this->code_presta);
61 $Date = new Dates($this->date);
62
63 return [
64 "Numéro prestation:" => end($code_presta_tableau), // dernière case
65 "Date:" => $Date->getDate(),
66 //"Type de Presta:" => $this->type_presta, // choix impossible pour le moment
67 "Mode de paiement:" => $this->mode_paiement, // non pertinent pour un devis
68 "Commentaires:" => $this->commentaires];
69 }
70 public function set(string $entry, string $input)
71 {
72 $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide
73 switch($entry)
74 {
75 case "Numéro prestation:":
76 $this->setNumeroPresta($input);
77 break;
78 //~ case "Date:": // inutile, setDate() est appelé directement après choix fenêtre calendrier
79 //~ $this->setDate($input);
80 //~ break;
81 //~ case "Type de Presta:": // choix impossible pour le moment
82 //~ $this->setTypePresta($input);
83 //~ break;
84 case "Mode de paiement:":
85 $this->setModePaiement($input);
86 break;
87 case "Commentaires:":
88 $this->setCommentaires($input);
89 break;
90 }
91 }
92
93 // setters
94 public function setIdClient(int $value)
95 {
96 $this->id_client = $value;
97 return $this;
98 }
99 //~ public function setCombientiemeFois(int $value)
100 //~ {
101 //~ $this->combientieme_fois = $value;
102 //~ return($this);
103 //~ }
104 public function setCodePresta(string $value)
105 {
106 $this->code_presta = $value;
107 return $this;
108 }
109 public function setDate($value, bool $set_code_presta = false) // attend un timestamp
110 {
111 $this->date = (int) $value;
112
113 if($set_code_presta)
114 {
115 $code_presta_tableau = explode('-', $this->code_presta);
116 $Date = new Dates($value);
117 $code_presta_tableau[0] = $Date->getYear();
118 $code_presta_tableau[1] = $Date->getMonth();
119 $code_presta_tableau[2] = $Date->getDay();
120 $this->code_presta = implode('-', $code_presta_tableau);
121 }
122
123 return $this;
124 }
125 public function setTypePresta(string $value)
126 {
127 $this->type_presta = $value;
128 return $this;
129 }
130 public function setModePaiement(string $value)
131 {
132 $this->mode_paiement = $value;
133 return $this;
134 }
135 public function setCommentaires(string $value)
136 {
137 $this->commentaires = $this->cleanSpecialChars($value); // nettoyage ici parce que pas possible ailleurs
138 return $this;
139 }
140 public function setNumeroPresta($value)
141 {
142 // modifier le code presta, on pourrait aussi utiliser une regex
143 $code_presta_tableau = explode('-', $this->code_presta);
144 $code_presta_tableau[count($code_presta_tableau) - 1] = (int) $value;
145 $this->code_presta = implode('-', $code_presta_tableau);
146 return $this;
147 }
148
149 // code presta = année-mois-jour-codeclient-typedepresta-combientièmefois
150 public function makeCodePresta(Dates $Date, string $code_client)
151 {
152 // on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente)
153 // inconvénient: il peut y avoir plusieurs prestations avec le même numéro au compteur, à améliorer
154 $combientieme_fois = count($this->find(['id_client' => $this->id_client])) + 1;
155
156 $array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $code_client, $this->type_presta, $combientieme_fois];
157 $this->code_presta = implode('-', $array_code);
158 }
159}