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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
<?php
// src/entities/Facture.php
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\EntityManager;
#[ORM\Entity]
#[ORM\Table(name: 'factures')]
class Facture
{
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue]
private int|null $id = null;
#[ORM\ManyToOne(targetEntity: Prestation::class, cascade: ['persist'])]
#[ORM\JoinColumn(name: 'id_presta', referencedColumnName: 'id')]
private Prestation|null $presta = null;
#[ORM\Column]
private string $taches;
#[ORM\Column]
private string $machine;
#[ORM\Column]
private string $OS;
#[ORM\Column]
private string $donnees;
#[ORM\Column]
private string $cles_licences;
#[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 $total_HT;
public static EntityManager $entityManager;
public function __construct(Prestation $presta = null)
{
if($presta != null)
{
$this->setPresta($presta);
}
}
// getters
public function getPresta(): Prestation
{
return $this->presta;
}
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
{
//~ $taches = ["Tâches:" => $this->taches];
//~ $champs_facture = [
//~ "PC:" => $this->machine,
//~ "OS:" => $this->OS,
//~ "Données:" => $this->donnees,
//~ "Clés de licences:" => $this->cles_licences];
//~ $champs_communs = [
//~ "Total Main d'oeuvre:" => $this->total_main_d_oeuvre,
//~ "Pièces:" => $this->pieces,
//~ "Total des pièces:" => $this->total_pieces,
//~ "Déplacement:" => $this->deplacement,
//~ "Total HT:" => $this->total_HT];
//return $taches + $champs_facture + $champs_communs;
return [
"Tâches:" => $this->taches,
"PC:" => $this->machine,
"OS:" => $this->OS,
"Données:" => $this->donnees,
"Clés de licences:" => $this->cles_licences,
"Total Main d'oeuvre:" => $this->total_main_d_oeuvre,
"Pièces:" => $this->pieces,
"Total des pièces:" => $this->total_pieces,
"Déplacement:" => $this->deplacement,
"Total HT:" => $this->total_HT];
}
// setters
public function set(string $entry, string $input) // 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 "PC:":
$this->setMachine($input);
break;
case "OS:":
$this->setOS($input);
break;
case "Données:":
$this->setDonnees($input);
break;
case "Clés de licences:":
$this->setClesLicences($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 "Total HT:":
$this->setTotalHT($input);
break;
}
}
public function setPresta(Prestation $input) // private?
{
$this->presta = $input;
}
public function setTaches(string $value)
{
$this->taches = $value;
return($this);
}
public function setMachine(string $value)
{
$this->machine = $value;
return($this);
}
public function setOS(string $value)
{
$this->OS = $value;
return($this);
}
public function setDonnees(string $value)
{
$this->donnees = $value;
return($this);
}
public function setClesLicences(string $value)
{
$this->cles_licences = $value;
return($this);
}
public function setTotalMainDOeuvre($value)
{
$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)
{
$this->pieces = $value;
return($this);
}
public function setTotalPieces($value)
{
$value = str_replace(',', '.', $value);
$this->total_pieces = (float) $value;
return($this);
}
public function setDeplacement($value)
{
$value = str_replace(',', '.', $value);
$this->deplacement = (float) $value;
return($this);
}
public function setTotalHT($value)
{
$value = str_replace(',', '.', $value);
$this->total_HT = (float) $value;
return($this);
}
private function setAll(array $input) // private?
{
$this->taches = $input[0];
$this->machine = $input[1];
$this->OS = $input[2];
$this->donnees = $input[3];
$this->cles_licences = $input[4];
$this->total_main_d_oeuvre = (float)$input[5];
$this->pieces = $input[6];
$this->total_pieces = (float)$input[7];
$this->deplacement = (float)$input[8];
$this->total_HT = (float)$input[9];
}
private function setServiceFromQuotation(array $input) // private?
{
$this->machine = $input[0];
$this->OS = $input[1];
$this->donnees = $input[2];
$this->cles_licences = $input[3];
}
// à mettre plus tard dans une classe mère
protected function cleanSpecialChars(string $data): string
{
$search = ['"'];
return str_replace($search, '', $data);
}
// à mettre plus tard dans une classe mère
public function hydrate(string $answers)
{
$answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide
if($answers == '')
{
echo "erreur de Facture::hydrate(), la chaine \$answers est vide.\n";
return false;
}
$data_array = explode('|', $answers); // array
$check = false;
if(count($data_array) === 11) // facture normale
{
$this->getPresta()->setModePaiement($data_array[10]);
//array_pop($data_array); // supprime la dernière case
unset($data_array[10]);
$this->setAll($data_array);
}
elseif(count($data_array) === 5) // facture à partir d'un devis
{
$this->getPresta()->setModePaiement($data_array[4]);
unset($data_array[4]);
$this->setServiceFromQuotation($data_array);
}
else
{
echo "erreur de Facture::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n";
return false;
}
//self::$entityManager->persist('Prestation');
self::$entityManager->persist($this); // $Presta avec en cascade!
self::$entityManager->flush();
}
public function hydrateWithQuotation(Devis $QuotationDetails)
{
$data = $QuotationDetails->getAll();
//var_dump($data);die;
$this->taches = $data['taches'];
$this->total_main_d_oeuvre = $data['total_main_d_oeuvre'];
$this->pieces = $data['pieces'];
$this->total_pieces = $data['total_pieces'];
$this->deplacement = $data['deplacement'];
$this->total_HT = $data['total_HT'];
}
}
|