diff options
Diffstat (limited to 'src/model/entities/Devis.php')
-rw-r--r-- | src/model/entities/Devis.php | 241 |
1 files changed, 241 insertions, 0 deletions
diff --git a/src/model/entities/Devis.php b/src/model/entities/Devis.php new file mode 100644 index 0000000..7383410 --- /dev/null +++ b/src/model/entities/Devis.php | |||
@@ -0,0 +1,241 @@ | |||
1 | <?php | ||
2 | // src/entities/Devis.php | ||
3 | |||
4 | use Doctrine\ORM\Mapping as ORM; | ||
5 | use Doctrine\ORM\EntityManager; | ||
6 | |||
7 | #[ORM\Entity] | ||
8 | #[ORM\Table(name: 'devis')] | ||
9 | class Devis | ||
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 float $total_main_d_oeuvre; | ||
24 | #[ORM\Column] | ||
25 | private string $pieces; | ||
26 | #[ORM\Column] | ||
27 | private float $total_pieces; | ||
28 | #[ORM\Column] | ||
29 | private float $deplacement; | ||
30 | #[ORM\Column] | ||
31 | private float $prix_devis; | ||
32 | #[ORM\Column] | ||
33 | private float $total_HT; | ||
34 | #[ORM\Column] | ||
35 | private string $delai_livraison; | ||
36 | #[ORM\Column] | ||
37 | private string $validite_devis; | ||
38 | #[ORM\Column (options: ['default' => 'non'])] | ||
39 | private string $signature_devis = 'non'; | ||
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_communs = [ | ||
66 | //~ "Total Main d'oeuvre:" => $this->total_main_d_oeuvre, | ||
67 | //~ "Pièces:" => $this->pieces, | ||
68 | //~ "Total des pièces:" => $this->total_pieces, | ||
69 | //~ "Déplacement:" => $this->deplacement, | ||
70 | //~ "Total HT:" => $this->total_HT]; | ||
71 | //~ $champs_devis = [ | ||
72 | //~ "Delai de livraison:" => $this->delai_livraison, | ||
73 | //~ "Durée de validité:" => $this->validite_devis, | ||
74 | //~ "Devis signé:" => $this->signature_devis]; | ||
75 | //~ return $champs_communs + $champs_devis; | ||
76 | return [ | ||
77 | "Tâches:" => $this->taches, // JUSTE AJOUTÉ | ||
78 | "Total Main d'oeuvre:" => $this->total_main_d_oeuvre, | ||
79 | "Pièces:" => $this->pieces, | ||
80 | "Total des pièces:" => $this->total_pieces, | ||
81 | "Déplacement:" => $this->deplacement, | ||
82 | "Total HT:" => $this->total_HT, | ||
83 | "Delai de livraison:" => $this->delai_livraison, | ||
84 | "Durée de validité:" => $this->validite_devis, | ||
85 | "Devis signé:" => $this->signature_devis]; | ||
86 | } | ||
87 | |||
88 | // setters | ||
89 | public function set(string $entry, string $input) // trouve la bonne méthode | ||
90 | { | ||
91 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide | ||
92 | switch($entry) | ||
93 | { | ||
94 | case "Tâches:": | ||
95 | $this->setTaches($input); | ||
96 | break; | ||
97 | case "Total Main d'oeuvre:": | ||
98 | $this->setTotalMainDOeuvre($input); | ||
99 | break; | ||
100 | case "Pièces:": | ||
101 | $this->setPieces($input); | ||
102 | break; | ||
103 | case "Total des pièces:": | ||
104 | $this->setTotalPieces($input); | ||
105 | break; | ||
106 | case "Déplacement:": | ||
107 | $this->setDeplacement($input); | ||
108 | break; | ||
109 | case "Prix du devis:": | ||
110 | $this->setPrixDevis($input); | ||
111 | break; | ||
112 | case "Total HT:": | ||
113 | $this->setTotalHT($input); | ||
114 | break; | ||
115 | case "Delai de livraison:": | ||
116 | $this->setDelaiLivraison($input); | ||
117 | break; | ||
118 | case "Durée de validité:": | ||
119 | $this->setValiditedevis($input); | ||
120 | break; | ||
121 | case "Devis signé:": | ||
122 | $this->setSignatureDevis($input); | ||
123 | break; | ||
124 | } | ||
125 | } | ||
126 | private function setPresta(Prestation $input) // private? | ||
127 | { | ||
128 | $this->presta = $input; | ||
129 | } | ||
130 | public function setTaches(string $value) | ||
131 | { | ||
132 | $this->taches = $value; | ||
133 | return($this); | ||
134 | } | ||
135 | public function setTotalMainDOeuvre($value) | ||
136 | { | ||
137 | $value = str_replace(',', '.', $value); | ||
138 | $this->total_main_d_oeuvre = (float) $value; // float "nettoie" tous les caractères après le dernier chiffre trouvé (ex: 50€ => 50, abc => 0) | ||
139 | return($this); | ||
140 | } | ||
141 | public function setPieces(string $value) | ||
142 | { | ||
143 | $this->pieces = $value; | ||
144 | return($this); | ||
145 | } | ||
146 | public function setTotalPieces($value) | ||
147 | { | ||
148 | $value = str_replace(',', '.', $value); | ||
149 | $this->total_pieces = (float) $value; | ||
150 | return($this); | ||
151 | } | ||
152 | public function setDeplacement($value) | ||
153 | { | ||
154 | $value = str_replace(',', '.', $value); | ||
155 | $this->deplacement = (float) $value; | ||
156 | return($this); | ||
157 | } | ||
158 | public function setTotalHT($value) | ||
159 | { | ||
160 | $value = str_replace(',', '.', $value); | ||
161 | $this->total_HT = (float) $value; | ||
162 | return($this); | ||
163 | } | ||
164 | public function setPrixDevis($value) | ||
165 | { | ||
166 | $value = str_replace(',', '.', $value); | ||
167 | $this->prix_devis = (float) $value; | ||
168 | return($this); | ||
169 | } | ||
170 | public function setDelaiLivraison(string $value) | ||
171 | { | ||
172 | $this->delai_livraison = $value; | ||
173 | return($this); | ||
174 | } | ||
175 | public function setValiditedevis(string $value) | ||
176 | { | ||
177 | $this->validite_devis = $value; | ||
178 | return($this); | ||
179 | } | ||
180 | public function setSignatureDevis(string $value) | ||
181 | { | ||
182 | $this->signature_devis = $value; | ||
183 | return($this); | ||
184 | } | ||
185 | |||
186 | private function setAll(array $input) // private? | ||
187 | { | ||
188 | $this->taches = $input[0]; | ||
189 | $this->total_main_d_oeuvre = (float)$input[1]; | ||
190 | $this->pieces = $input[2]; | ||
191 | $this->total_pieces = (float)$input[3]; | ||
192 | $this->deplacement = (float)$input[4]; | ||
193 | $this->prix_devis = (float)$input[5]; | ||
194 | $this->total_HT = (float)$input[6]; | ||
195 | $this->delai_livraison = $input[7]; | ||
196 | $this->validite_devis = $input[8]; | ||
197 | |||
198 | // $signature_devis est renseigné plus tard en modifiant le devis | ||
199 | } | ||
200 | |||
201 | // à mettre plus tard dans une classe mère | ||
202 | protected function cleanSpecialChars(string $data): string | ||
203 | { | ||
204 | $search = ['"']; | ||
205 | return str_replace($search, '', $data); | ||
206 | } | ||
207 | // à mettre plus tard dans une classe mère | ||
208 | public function hydrate(string $answers) | ||
209 | { | ||
210 | $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide | ||
211 | if($answers == '') | ||
212 | { | ||
213 | echo "erreur de Devis::hydrate(), la chaine \$answers est vide.\n"; | ||
214 | return false; | ||
215 | } | ||
216 | $data_array = explode('|', $answers); // array | ||
217 | |||
218 | $check = false; | ||
219 | if(count($data_array) === 9) // facture normale | ||
220 | { | ||
221 | $this->getPresta()->setModePaiement(''); // sécurité, doctrine plante si "null" | ||
222 | $this->setAll($data_array); | ||
223 | } | ||
224 | else | ||
225 | { | ||
226 | echo "erreur de Devis::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; | ||
227 | return false; | ||
228 | } | ||
229 | |||
230 | //self::$entityManager->persist('Prestation'); | ||
231 | self::$entityManager->persist($this); // $Presta avec en cascade! | ||
232 | self::$entityManager->flush(); | ||
233 | } | ||
234 | |||
235 | // création d'une facture à partir d'un devis | ||
236 | public static function getQuotation(Prestation $Quotation) | ||
237 | { | ||
238 | $repository = self::$entityManager->getRepository('Devis'); | ||
239 | return $repository->findOneBy(['presta' => $Quotation->getId()]); // ne peut y en avoir deux | ||
240 | } | ||
241 | } | ||