1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
<?php
// src/entities/Devis.php
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table(name: 'devis')]
class Devis extends Prestation
{
#[ORM\Column]
private string $taches;
#[ORM\Column]
private float $total_main_d_oeuvre;
#[ORM\Column]
private string $pieces;
#[ORM\Column]
private float $total_pieces;
#[ORM\Column]
private float $deplacement;
#[ORM\Column]
private float $prix_devis;
#[ORM\Column]
private float $total_HT;
#[ORM\Column]
private string $delai_livraison;
#[ORM\Column]
private string $validite_devis;
#[ORM\Column (options: ['default' => 'non'])] // défaut dans le cas d'un requête SQL ignorant ce champ
private string $signature_devis = 'non';
// getters
public function getAll(): array
{
// n'utiliser get_object_vars() qu'avec une entité parce qu'on maîtrise le nombre de propriétés
return get_object_vars($this);
}
public function getAllWithWindowFields(): array
{
$common_data = parent::getAllWithWindowFields();
return array_merge($common_data, [
"Tâches:" => $this->taches, // JUSTE AJOUTÉ
"Total Main d'oeuvre:" => $this->total_main_d_oeuvre,
"Pièces:" => $this->pieces,
"Total des pièces:" => $this->total_pieces,
"Déplacement:" => $this->deplacement,
"Prix du devis:" => $this->prix_devis,
"Total HT:" => $this->total_HT,
"Delai de livraison:" => $this->delai_livraison,
"Durée de validité:" => $this->validite_devis,
"Devis signé:" => $this->signature_devis]);
}
// setters
public function set(string $entry, string $input): void // trouve la bonne méthode
{
$input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide
switch($entry)
{
case "Tâches:":
$this->setTaches($input);
break;
case "Total Main d'oeuvre:":
$this->setTotalMainDOeuvre($input);
break;
case "Pièces:":
$this->setPieces($input);
break;
case "Total des pièces:":
$this->setTotalPieces($input);
break;
case "Déplacement:":
$this->setDeplacement($input);
break;
case "Prix du devis:":
$this->setPrixDevis($input);
break;
case "Total HT:":
$this->setTotalHT($input);
break;
case "Delai de livraison:":
$this->setDelaiLivraison($input);
break;
case "Durée de validité:":
$this->setValiditedevis($input);
break;
case "Devis signé:":
$this->setSignatureDevis($input);
break;
default: // gérer les champ dans Prestation
parent::set($entry, $input);
}
}
public function setTaches(string $value): Devis
{
$this->taches = $value;
return($this);
}
public function setTotalMainDOeuvre(string $value): Devis
{
$value = str_replace(',', '.', $value);
$this->total_main_d_oeuvre = (float) $value; // float "nettoie" tous les caractères après le dernier chiffre trouvé (ex: 50€ => 50, abc => 0)
return($this);
}
public function setPieces(string $value): Devis
{
$this->pieces = $value;
return($this);
}
public function setTotalPieces(string $value): Devis
{
$value = str_replace(',', '.', $value);
$this->total_pieces = (float) $value;
return($this);
}
public function setDeplacement(string $value): Devis
{
$value = str_replace(',', '.', $value);
$this->deplacement = (float) $value;
return($this);
}
public function setTotalHT(string $value): Devis
{
$value = str_replace(',', '.', $value);
$this->total_HT = (float) $value;
return($this);
}
public function setPrixDevis(string $value): Devis
{
$value = str_replace(',', '.', $value);
$this->prix_devis = (float) $value;
return($this);
}
public function setDelaiLivraison(string $value): Devis
{
$this->delai_livraison = $value;
return($this);
}
public function setValiditedevis(string $value): Devis
{
$this->validite_devis = $value;
return($this);
}
public function setSignatureDevis(string $value): Devis
{
$this->signature_devis = $value;
return($this);
}
private function setAll(array $input): void // private?
{
$this->taches = $input[0];
$this->total_main_d_oeuvre = (float)$input[1];
$this->pieces = $input[2];
$this->total_pieces = (float)$input[3];
$this->deplacement = (float)$input[4];
$this->prix_devis = (float)$input[5];
$this->total_HT = (float)$input[6];
$this->delai_livraison = $input[7];
$this->validite_devis = $input[8];
// $signature_devis est renseigné plus tard en modifiant le devis
}
public function validateForm(array $data_array): bool
{
if(count($data_array) === 9){
return true;
}
else{
echo "erreur de Devis::validateForm(), le tableau \$data_array n'a pas la taille attendue.\n";
return false;
}
}
// à mettre plus tard dans une classe mère
public function hydrate(array $data_array): void
{
//$this->setModePaiement(''); // vaut déjà ''
$this->setAll($data_array);
}
}
|