summaryrefslogtreecommitdiff
path: root/src/model/entities/Facture.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/entities/Facture.php')
-rw-r--r--src/model/entities/Facture.php261
1 files changed, 261 insertions, 0 deletions
diff --git a/src/model/entities/Facture.php b/src/model/entities/Facture.php
new file mode 100644
index 0000000..3a8a551
--- /dev/null
+++ b/src/model/entities/Facture.php
@@ -0,0 +1,261 @@
1<?php
2// src/entities/Facture.php
3
4use Doctrine\ORM\Mapping as ORM;
5use Doctrine\ORM\EntityManager;
6
7#[ORM\Entity]
8#[ORM\Table(name: 'factures')]
9class Facture
10{
11 #[ORM\Id]
12 #[ORM\Column(type: 'integer')]
13 #[ORM\GeneratedValue]
14 private int|null $id = null;
15
16 #[ORM\ManyToOne(targetEntity: Prestation::class, cascade: ['persist'])]
17 #[ORM\JoinColumn(name: 'id_presta', referencedColumnName: 'id')]
18 private Prestation|null $presta = null;
19
20 #[ORM\Column]
21 private string $taches;
22 #[ORM\Column]
23 private string $machine;
24 #[ORM\Column]
25 private string $OS;
26 #[ORM\Column]
27 private string $donnees;
28 #[ORM\Column]
29 private string $cles_licences;
30 #[ORM\Column]
31 private float $total_main_d_oeuvre;
32 #[ORM\Column]
33 private string $pieces;
34 #[ORM\Column]
35 private float $total_pieces;
36 #[ORM\Column]
37 private float $deplacement;
38 #[ORM\Column]
39 private float $total_HT;
40
41 public static EntityManager $entityManager;
42
43 public function __construct(Prestation $presta = null)
44 {
45 if($presta != null)
46 {
47 $this->setPresta($presta);
48 }
49 }
50
51 // getters
52 public function getPresta(): Prestation
53 {
54 return $this->presta;
55 }
56 public function getAll(): array
57 {
58 // n'utiliser get_object_vars() qu'avec une entité parce qu'on maîtrise le nombre de propriétés
59 return get_object_vars($this);
60 }
61
62 public function getAllWithWindowFields(): array
63 {
64 //~ $taches = ["Tâches:" => $this->taches];
65 //~ $champs_facture = [
66 //~ "PC:" => $this->machine,
67 //~ "OS:" => $this->OS,
68 //~ "Données:" => $this->donnees,
69 //~ "Clés de licences:" => $this->cles_licences];
70 //~ $champs_communs = [
71 //~ "Total Main d'oeuvre:" => $this->total_main_d_oeuvre,
72 //~ "Pièces:" => $this->pieces,
73 //~ "Total des pièces:" => $this->total_pieces,
74 //~ "Déplacement:" => $this->deplacement,
75 //~ "Total HT:" => $this->total_HT];
76 //return $taches + $champs_facture + $champs_communs;
77 return [
78 "Tâches:" => $this->taches,
79 "PC:" => $this->machine,
80 "OS:" => $this->OS,
81 "Données:" => $this->donnees,
82 "Clés de licences:" => $this->cles_licences,
83 "Total Main d'oeuvre:" => $this->total_main_d_oeuvre,
84 "Pièces:" => $this->pieces,
85 "Total des pièces:" => $this->total_pieces,
86 "Déplacement:" => $this->deplacement,
87 "Total HT:" => $this->total_HT];
88 }
89
90 // setters
91 public function set(string $entry, string $input) // trouve la bonne méthode
92 {
93 $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide
94 switch($entry)
95 {
96 case "Tâches:":
97 $this->setTaches($input);
98 break;
99 case "PC:":
100 $this->setMachine($input);
101 break;
102 case "OS:":
103 $this->setOS($input);
104 break;
105 case "Données:":
106 $this->setDonnees($input);
107 break;
108 case "Clés de licences:":
109 $this->setClesLicences($input);
110 break;
111 case "Total Main d'oeuvre:":
112 $this->setTotalMainDOeuvre($input);
113 break;
114 case "Pièces:":
115 $this->setPieces($input);
116 break;
117 case "Total des pièces:":
118 $this->setTotalPieces($input);
119 break;
120 case "Déplacement:":
121 $this->setDeplacement($input);
122 break;
123 case "Total HT:":
124 $this->setTotalHT($input);
125 break;
126 }
127 }
128 public function setPresta(Prestation $input) // private?
129 {
130 $this->presta = $input;
131 }
132 public function setTaches(string $value)
133 {
134 $this->taches = $value;
135 return($this);
136 }
137 public function setMachine(string $value)
138 {
139 $this->machine = $value;
140 return($this);
141 }
142 public function setOS(string $value)
143 {
144 $this->OS = $value;
145 return($this);
146 }
147 public function setDonnees(string $value)
148 {
149 $this->donnees = $value;
150 return($this);
151 }
152 public function setClesLicences(string $value)
153 {
154 $this->cles_licences = $value;
155 return($this);
156 }
157 public function setTotalMainDOeuvre($value)
158 {
159 $value = str_replace(',', '.', $value);
160 $this->total_main_d_oeuvre = (float) $value; // float "nettoie" tous les caractères après le dernier chiffre trouvé (ex: 50€ => 50, abc => 0)
161 return($this);
162 }
163 public function setPieces(string $value)
164 {
165 $this->pieces = $value;
166 return($this);
167 }
168 public function setTotalPieces($value)
169 {
170 $value = str_replace(',', '.', $value);
171 $this->total_pieces = (float) $value;
172 return($this);
173 }
174 public function setDeplacement($value)
175 {
176 $value = str_replace(',', '.', $value);
177 $this->deplacement = (float) $value;
178 return($this);
179 }
180 public function setTotalHT($value)
181 {
182 $value = str_replace(',', '.', $value);
183 $this->total_HT = (float) $value;
184 return($this);
185 }
186
187 private function setAll(array $input) // private?
188 {
189 $this->taches = $input[0];
190 $this->machine = $input[1];
191 $this->OS = $input[2];
192 $this->donnees = $input[3];
193 $this->cles_licences = $input[4];
194 $this->total_main_d_oeuvre = (float)$input[5];
195 $this->pieces = $input[6];
196 $this->total_pieces = (float)$input[7];
197 $this->deplacement = (float)$input[8];
198 $this->total_HT = (float)$input[9];
199 }
200 private function setServiceFromQuotation(array $input) // private?
201 {
202 $this->machine = $input[0];
203 $this->OS = $input[1];
204 $this->donnees = $input[2];
205 $this->cles_licences = $input[3];
206 }
207
208 // à mettre plus tard dans une classe mère
209 protected function cleanSpecialChars(string $data): string
210 {
211 $search = ['"'];
212 return str_replace($search, '', $data);
213 }
214 // à mettre plus tard dans une classe mère
215 public function hydrate(string $answers)
216 {
217 $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide
218 if($answers == '')
219 {
220 echo "erreur de Facture::hydrate(), la chaine \$answers est vide.\n";
221 return false;
222 }
223 $data_array = explode('|', $answers); // array
224
225 $check = false;
226 if(count($data_array) === 11) // facture normale
227 {
228 $this->getPresta()->setModePaiement($data_array[10]);
229 //array_pop($data_array); // supprime la dernière case
230 unset($data_array[10]);
231 $this->setAll($data_array);
232 }
233 elseif(count($data_array) === 5) // facture à partir d'un devis
234 {
235 $this->getPresta()->setModePaiement($data_array[4]);
236 unset($data_array[4]);
237 $this->setServiceFromQuotation($data_array);
238 }
239 else
240 {
241 echo "erreur de Facture::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n";
242 return false;
243 }
244
245 //self::$entityManager->persist('Prestation');
246 self::$entityManager->persist($this); // $Presta avec en cascade!
247 self::$entityManager->flush();
248 }
249
250 public function hydrateWithQuotation(Devis $QuotationDetails)
251 {
252 $data = $QuotationDetails->getAll();
253 //var_dump($data);die;
254 $this->taches = $data['taches'];
255 $this->total_main_d_oeuvre = $data['total_main_d_oeuvre'];
256 $this->pieces = $data['pieces'];
257 $this->total_pieces = $data['total_pieces'];
258 $this->deplacement = $data['deplacement'];
259 $this->total_HT = $data['total_HT'];
260 }
261}