diff options
| author | polo <ordipolo@gmx.fr> | 2026-10-20 21:49:17 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-10-20 22:49:21 +0200 |
| commit | 0161ac4d632af7d45f4fe9d68c1ba3a86f094fc4 (patch) | |
| tree | bbaea156e9d32edf14adad8fe5ce3338014e7710 /src/model/entities/Devis.php | |
| parent | 87eb9864d7c738d7897be33c9a1aa06e33378acc (diff) | |
| download | AppliGestionPHP-0161ac4d632af7d45f4fe9d68c1ba3a86f094fc4.tar.gz AppliGestionPHP-0161ac4d632af7d45f4fe9d68c1ba3a86f094fc4.tar.bz2 AppliGestionPHP-0161ac4d632af7d45f4fe9d68c1ba3a86f094fc4.zip | |
mise en place de l'héritage 2, nombreuses simplifications et factorisations
Diffstat (limited to 'src/model/entities/Devis.php')
| -rw-r--r-- | src/model/entities/Devis.php | 98 |
1 files changed, 26 insertions, 72 deletions
diff --git a/src/model/entities/Devis.php b/src/model/entities/Devis.php index f559243..3f051c2 100644 --- a/src/model/entities/Devis.php +++ b/src/model/entities/Devis.php | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | // src/entities/Devis.php | 2 | // src/entities/Devis.php |
| 3 | 3 | ||
| 4 | use Doctrine\ORM\Mapping as ORM; | 4 | use Doctrine\ORM\Mapping as ORM; |
| 5 | use Doctrine\ORM\EntityManager; | ||
| 6 | 5 | ||
| 7 | #[ORM\Entity] | 6 | #[ORM\Entity] |
| 8 | #[ORM\Table(name: 'devis')] | 7 | #[ORM\Table(name: 'devis')] |
| @@ -29,17 +28,7 @@ class Devis extends Prestation | |||
| 29 | #[ORM\Column (options: ['default' => 'non'])] // défaut dans le cas d'un requête SQL ignorant ce champ | 28 | #[ORM\Column (options: ['default' => 'non'])] // défaut dans le cas d'un requête SQL ignorant ce champ |
| 30 | private string $signature_devis = 'non'; | 29 | private string $signature_devis = 'non'; |
| 31 | 30 | ||
| 32 | public static EntityManager $entityManager; | ||
| 33 | |||
| 34 | public function __construct(?Prestation $presta = null){ | ||
| 35 | $this->setPresta($presta); | ||
| 36 | } | ||
| 37 | |||
| 38 | // getters | 31 | // getters |
| 39 | public function getPresta(): Prestation | ||
| 40 | { | ||
| 41 | return $this->presta; | ||
| 42 | } | ||
| 43 | public function getAll(): array | 32 | public function getAll(): array |
| 44 | { | 33 | { |
| 45 | // n'utiliser get_object_vars() qu'avec une entité parce qu'on maîtrise le nombre de propriétés | 34 | // n'utiliser get_object_vars() qu'avec une entité parce qu'on maîtrise le nombre de propriétés |
| @@ -48,19 +37,8 @@ class Devis extends Prestation | |||
| 48 | 37 | ||
| 49 | public function getAllWithWindowFields(): array | 38 | public function getAllWithWindowFields(): array |
| 50 | { | 39 | { |
| 51 | //~ $taches = ["Tâches:" => $this->taches]; | 40 | $common_data = parent::getAllWithWindowFields(); |
| 52 | //~ $champs_communs = [ | 41 | return array_merge($common_data, [ |
| 53 | //~ "Total Main d'oeuvre:" => $this->total_main_d_oeuvre, | ||
| 54 | //~ "Pièces:" => $this->pieces, | ||
| 55 | //~ "Total des pièces:" => $this->total_pieces, | ||
| 56 | //~ "Déplacement:" => $this->deplacement, | ||
| 57 | //~ "Total HT:" => $this->total_HT]; | ||
| 58 | //~ $champs_devis = [ | ||
| 59 | //~ "Delai de livraison:" => $this->delai_livraison, | ||
| 60 | //~ "Durée de validité:" => $this->validite_devis, | ||
| 61 | //~ "Devis signé:" => $this->signature_devis]; | ||
| 62 | //~ return $champs_communs + $champs_devis; | ||
| 63 | return [ | ||
| 64 | "Tâches:" => $this->taches, // JUSTE AJOUTÉ | 42 | "Tâches:" => $this->taches, // JUSTE AJOUTÉ |
| 65 | "Total Main d'oeuvre:" => $this->total_main_d_oeuvre, | 43 | "Total Main d'oeuvre:" => $this->total_main_d_oeuvre, |
| 66 | "Pièces:" => $this->pieces, | 44 | "Pièces:" => $this->pieces, |
| @@ -70,11 +48,11 @@ class Devis extends Prestation | |||
| 70 | "Total HT:" => $this->total_HT, | 48 | "Total HT:" => $this->total_HT, |
| 71 | "Delai de livraison:" => $this->delai_livraison, | 49 | "Delai de livraison:" => $this->delai_livraison, |
| 72 | "Durée de validité:" => $this->validite_devis, | 50 | "Durée de validité:" => $this->validite_devis, |
| 73 | "Devis signé:" => $this->signature_devis]; | 51 | "Devis signé:" => $this->signature_devis]); |
| 74 | } | 52 | } |
| 75 | 53 | ||
| 76 | // setters | 54 | // setters |
| 77 | public function set(string $entry, string $input) // trouve la bonne méthode | 55 | public function set(string $entry, string $input): void // trouve la bonne méthode |
| 78 | { | 56 | { |
| 79 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide | 57 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide |
| 80 | switch($entry) | 58 | switch($entry) |
| @@ -109,41 +87,39 @@ class Devis extends Prestation | |||
| 109 | case "Devis signé:": | 87 | case "Devis signé:": |
| 110 | $this->setSignatureDevis($input); | 88 | $this->setSignatureDevis($input); |
| 111 | break; | 89 | break; |
| 90 | default: // gérer les champ dans Prestation | ||
| 91 | parent::set($entry, $input); | ||
| 112 | } | 92 | } |
| 113 | } | 93 | } |
| 114 | private function setPresta(Prestation $input) // private? | 94 | public function setTaches(string $value): Devis |
| 115 | { | ||
| 116 | $this->presta = $input; | ||
| 117 | } | ||
| 118 | public function setTaches(string $value) | ||
| 119 | { | 95 | { |
| 120 | $this->taches = $value; | 96 | $this->taches = $value; |
| 121 | return($this); | 97 | return($this); |
| 122 | } | 98 | } |
| 123 | public function setTotalMainDOeuvre($value) | 99 | public function setTotalMainDOeuvre(string $value): Devis |
| 124 | { | 100 | { |
| 125 | $value = str_replace(',', '.', $value); | 101 | $value = str_replace(',', '.', $value); |
| 126 | $this->total_main_d_oeuvre = (float) $value; // float "nettoie" tous les caractères après le dernier chiffre trouvé (ex: 50€ => 50, abc => 0) | 102 | $this->total_main_d_oeuvre = (float) $value; // float "nettoie" tous les caractères après le dernier chiffre trouvé (ex: 50€ => 50, abc => 0) |
| 127 | return($this); | 103 | return($this); |
| 128 | } | 104 | } |
| 129 | public function setPieces(string $value) | 105 | public function setPieces(string $value): Devis |
| 130 | { | 106 | { |
| 131 | $this->pieces = $value; | 107 | $this->pieces = $value; |
| 132 | return($this); | 108 | return($this); |
| 133 | } | 109 | } |
| 134 | public function setTotalPieces($value) | 110 | public function setTotalPieces(string $value): Devis |
| 135 | { | 111 | { |
| 136 | $value = str_replace(',', '.', $value); | 112 | $value = str_replace(',', '.', $value); |
| 137 | $this->total_pieces = (float) $value; | 113 | $this->total_pieces = (float) $value; |
| 138 | return($this); | 114 | return($this); |
| 139 | } | 115 | } |
| 140 | public function setDeplacement($value) | 116 | public function setDeplacement(string $value): Devis |
| 141 | { | 117 | { |
| 142 | $value = str_replace(',', '.', $value); | 118 | $value = str_replace(',', '.', $value); |
| 143 | $this->deplacement = (float) $value; | 119 | $this->deplacement = (float) $value; |
| 144 | return($this); | 120 | return($this); |
| 145 | } | 121 | } |
| 146 | public function setTotalHT($value) | 122 | public function setTotalHT(string $value): Devis |
| 147 | { | 123 | { |
| 148 | $value = str_replace(',', '.', $value); | 124 | $value = str_replace(',', '.', $value); |
| 149 | $this->total_HT = (float) $value; | 125 | $this->total_HT = (float) $value; |
| @@ -155,23 +131,23 @@ class Devis extends Prestation | |||
| 155 | $this->prix_devis = (float) $value; | 131 | $this->prix_devis = (float) $value; |
| 156 | return($this); | 132 | return($this); |
| 157 | } | 133 | } |
| 158 | public function setDelaiLivraison(string $value) | 134 | public function setDelaiLivraison(string $value): Devis |
| 159 | { | 135 | { |
| 160 | $this->delai_livraison = $value; | 136 | $this->delai_livraison = $value; |
| 161 | return($this); | 137 | return($this); |
| 162 | } | 138 | } |
| 163 | public function setValiditedevis(string $value) | 139 | public function setValiditedevis(string $value): Devis |
| 164 | { | 140 | { |
| 165 | $this->validite_devis = $value; | 141 | $this->validite_devis = $value; |
| 166 | return($this); | 142 | return($this); |
| 167 | } | 143 | } |
| 168 | public function setSignatureDevis(string $value) | 144 | public function setSignatureDevis(string $value): Devis |
| 169 | { | 145 | { |
| 170 | $this->signature_devis = $value; | 146 | $this->signature_devis = $value; |
| 171 | return($this); | 147 | return($this); |
| 172 | } | 148 | } |
| 173 | 149 | ||
| 174 | private function setAll(array $input) // private? | 150 | private function setAll(array $input): void // private? |
| 175 | { | 151 | { |
| 176 | $this->taches = $input[0]; | 152 | $this->taches = $input[0]; |
| 177 | $this->total_main_d_oeuvre = (float)$input[1]; | 153 | $this->total_main_d_oeuvre = (float)$input[1]; |
| @@ -186,43 +162,21 @@ class Devis extends Prestation | |||
| 186 | // $signature_devis est renseigné plus tard en modifiant le devis | 162 | // $signature_devis est renseigné plus tard en modifiant le devis |
| 187 | } | 163 | } |
| 188 | 164 | ||
| 189 | // à mettre plus tard dans une classe mère | 165 | public function validateForm(array $data_array): bool |
| 190 | protected function cleanSpecialChars(string $data): string | ||
| 191 | { | ||
| 192 | $search = ['"']; | ||
| 193 | return str_replace($search, '', $data); | ||
| 194 | } | ||
| 195 | // à mettre plus tard dans une classe mère | ||
| 196 | public function hydrate(string $answers): void | ||
| 197 | { | 166 | { |
| 198 | $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide | 167 | if(count($data_array) === 9){ |
| 199 | if($answers == '') | 168 | return true; |
| 200 | { | ||
| 201 | echo "erreur de Devis::hydrate(), la chaine \$answers est vide.\n"; | ||
| 202 | return; | ||
| 203 | } | 169 | } |
| 204 | $data_array = explode('|', $answers); // array | 170 | else{ |
| 205 | 171 | echo "erreur de Devis::validateForm(), le tableau \$data_array n'a pas la taille attendue.\n"; | |
| 206 | if(count($data_array) === 9) // facture normale, "=== 9" = merdique | 172 | return false; |
| 207 | { | ||
| 208 | $this->getPresta()->setModePaiement(''); // sécurité, doctrine plante si "null" | ||
| 209 | $this->setAll($data_array); | ||
| 210 | } | 173 | } |
| 211 | else | ||
| 212 | { | ||
| 213 | echo "erreur de Devis::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; | ||
| 214 | return; | ||
| 215 | } | ||
| 216 | |||
| 217 | //self::$entityManager->persist('Prestation'); | ||
| 218 | self::$entityManager->persist($this); // $Presta avec en cascade! | ||
| 219 | self::$entityManager->flush(); | ||
| 220 | } | 174 | } |
| 221 | 175 | ||
| 222 | // création d'une facture à partir d'un devis | 176 | // à mettre plus tard dans une classe mère |
| 223 | public static function getQuotation(Prestation $Quotation) | 177 | public function hydrate(array $data_array): void |
| 224 | { | 178 | { |
| 225 | $repository = self::$entityManager->getRepository('Devis'); | 179 | //$this->setModePaiement(''); // vaut déjà '' |
| 226 | return $repository->findOneBy(['presta' => $Quotation->getId()]); // ne peut y en avoir deux | 180 | $this->setAll($data_array); |
| 227 | } | 181 | } |
| 228 | } | 182 | } |
