diff options
Diffstat (limited to 'src/model/Prestations.php')
-rw-r--r-- | src/model/Prestations.php | 81 |
1 files changed, 68 insertions, 13 deletions
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 @@ | |||
4 | class Prestations extends Model | 4 | class Prestations extends Model |
5 | { | 5 | { |
6 | // lecture des données ou hydratation | 6 | // lecture des données ou hydratation |
7 | private $ID; | 7 | protected $ID_presta; // auto-incrémentée |
8 | private $IDClient; | 8 | protected $ID_client = 0; |
9 | private $combientieme_fois; | 9 | protected $combientieme_fois = 0; |
10 | private $code_presta; | 10 | protected $code_presta = ''; |
11 | private $date; | 11 | protected $date = 0; // timestamp unix |
12 | private $type; | 12 | protected $type_presta = ''; |
13 | private $mode_paiement; | 13 | protected $mode_paiement = ''; |
14 | private $commentaires; | 14 | protected $commentaires = ''; |
15 | 15 | ||
16 | use ModelChildren; | 16 | //~ use ModelChildren; |
17 | |||
18 | public function __construct(int $ID_client) | ||
19 | { | ||
20 | $this->table = 'prestations'; | ||
21 | $this->ID_client = $ID_client; | ||
22 | $this->combientiemeFois(); | ||
23 | } | ||
24 | |||
25 | // getters | ||
26 | public function getIDPresta(): int | ||
27 | { | ||
28 | return $this->ID_presta; | ||
29 | } | ||
30 | public function getIDClient(): int | ||
31 | { | ||
32 | return $this->ID_client; | ||
33 | } | ||
34 | public function getCombientiemeFois(): int | ||
35 | { | ||
36 | return $this->combientieme_fois; | ||
37 | } | ||
38 | public function getDate(): int | ||
39 | { | ||
40 | return $this->date; | ||
41 | } | ||
17 | 42 | ||
18 | // setters | 43 | // setters |
19 | public function setID(int $value) | 44 | public function setIDPresta(int $value = 0) |
20 | { | 45 | { |
21 | $this->ID = $value; | 46 | if($value === 0) |
47 | { | ||
48 | $this->ID_presta = $this->db->lastInsertId(); // méthode de PDO | ||
49 | } | ||
50 | else | ||
51 | { | ||
52 | $this->ID_presta = $value; | ||
53 | } | ||
22 | return($this); | 54 | return($this); |
23 | } | 55 | } |
56 | |||
24 | public function setIDClient(int $value) | 57 | public function setIDClient(int $value) |
25 | { | 58 | { |
26 | $this->ID_client = $value; | 59 | $this->ID_client = $value; |
@@ -41,9 +74,9 @@ class Prestations extends Model | |||
41 | $this->date = $value; | 74 | $this->date = $value; |
42 | return($this); | 75 | return($this); |
43 | } | 76 | } |
44 | public function setType(string $value) | 77 | public function setTypePresta(string $value) |
45 | { | 78 | { |
46 | $this->type = $value; | 79 | $this->type_presta = $value; |
47 | return($this); | 80 | return($this); |
48 | } | 81 | } |
49 | public function setModePaiement(string $value) | 82 | public function setModePaiement(string $value) |
@@ -56,4 +89,26 @@ class Prestations extends Model | |||
56 | $this->commentaires = $value; | 89 | $this->commentaires = $value; |
57 | return($this); | 90 | return($this); |
58 | } | 91 | } |
92 | |||
93 | protected function combientiemeFois() | ||
94 | { | ||
95 | // on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente) | ||
96 | $array = $this->find(['ID_client' => $this->ID_client]); | ||
97 | $this->combientieme_fois = count($array) + 1; | ||
98 | } | ||
99 | |||
100 | // code client = année-mois-jour-codeclient-combientièmefois | ||
101 | public function makeCodePresta(Dates $Date, string $code_client) | ||
102 | { | ||
103 | $array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $code_client, $this->combientieme_fois]; | ||
104 | $this->code_presta = implode('-', $array_code); | ||
105 | } | ||
106 | |||
107 | //~ public function newRow(array $input) | ||
108 | //~ { | ||
109 | //~ $this->hydrate(['ID_client' => $input[0], 'code_presta' => $input[1], 'date' => $input[2], 'type_presta' => $input[3], 'mode_paiement' => $input[4], 'commentaires' => $input[5]]); | ||
110 | //~ $this->create(); | ||
111 | //~ // ID obtenu par auto-incrémentation | ||
112 | //~ $this->ID_presta = $this->db->lastInsertId(); // méthode de PDO | ||
113 | //~ } | ||
59 | } | 114 | } |