diff options
| author | polo <ordipolo@gmx.fr> | 2026-10-20 21:49:17 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-10-20 21:49:17 +0200 |
| commit | b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878 (patch) | |
| tree | bbaea156e9d32edf14adad8fe5ce3338014e7710 /src/model/entities/Facture.php | |
| parent | 79bc73d7985f51f2a6a1b3cb6e0115f59afb2ac4 (diff) | |
| download | AppliGestionPHP-b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878.tar.gz AppliGestionPHP-b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878.tar.bz2 AppliGestionPHP-b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878.zip | |
mise en place de l'héritage 2, nombreuses simplifications et factorisations
Diffstat (limited to 'src/model/entities/Facture.php')
| -rw-r--r-- | src/model/entities/Facture.php | 113 |
1 files changed, 42 insertions, 71 deletions
diff --git a/src/model/entities/Facture.php b/src/model/entities/Facture.php index fe04508..abe37fb 100644 --- a/src/model/entities/Facture.php +++ b/src/model/entities/Facture.php | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | // src/entities/Facture.php | 2 | // src/entities/Facture.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: 'factures')] | 7 | #[ORM\Table(name: 'factures')] |
| @@ -29,17 +28,14 @@ class Facture extends Prestation | |||
| 29 | #[ORM\Column] | 28 | #[ORM\Column] |
| 30 | private float $total_HT; | 29 | private float $total_HT; |
| 31 | 30 | ||
| 32 | public static EntityManager $entityManager; | 31 | private bool $from_quotation; |
| 33 | 32 | ||
| 34 | public function __construct(?Prestation $presta = null){ | 33 | public function __construct(Client $client, bool $from_quotation){ |
| 35 | $this->setPresta($presta); | 34 | parent::__construct($client); |
| 35 | $this->from_quotation = $from_quotation; | ||
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | // getters | 38 | // getters |
| 39 | public function getPresta(): Prestation | ||
| 40 | { | ||
| 41 | return $this->presta; | ||
| 42 | } | ||
| 43 | public function getAll(): array | 39 | public function getAll(): array |
| 44 | { | 40 | { |
| 45 | // n'utiliser get_object_vars() qu'avec une entité parce qu'on maîtrise le nombre de propriétés | 41 | // n'utiliser get_object_vars() qu'avec une entité parce qu'on maîtrise le nombre de propriétés |
| @@ -60,20 +56,8 @@ class Facture extends Prestation | |||
| 60 | 56 | ||
| 61 | public function getAllWithWindowFields(): array | 57 | public function getAllWithWindowFields(): array |
| 62 | { | 58 | { |
| 63 | //~ $taches = ["Tâches:" => $this->taches]; | 59 | $common_data = parent::getAllWithWindowFields(); |
| 64 | //~ $champs_facture = [ | 60 | return array_merge($common_data, [ |
| 65 | //~ "PC:" => $this->machine, | ||
| 66 | //~ "OS:" => $this->OS, | ||
| 67 | //~ "Données:" => $this->donnees, | ||
| 68 | //~ "Clés de licences:" => $this->cles_licences]; | ||
| 69 | //~ $champs_communs = [ | ||
| 70 | //~ "Total Main d'oeuvre:" => $this->total_main_d_oeuvre, | ||
| 71 | //~ "Pièces:" => $this->pieces, | ||
| 72 | //~ "Total des pièces:" => $this->total_pieces, | ||
| 73 | //~ "Déplacement:" => $this->deplacement, | ||
| 74 | //~ "Total HT:" => $this->total_HT]; | ||
| 75 | //return $taches + $champs_facture + $champs_communs; | ||
| 76 | return [ | ||
| 77 | "Tâches:" => $this->taches, | 61 | "Tâches:" => $this->taches, |
| 78 | "PC:" => $this->machine, | 62 | "PC:" => $this->machine, |
| 79 | "OS:" => $this->OS, | 63 | "OS:" => $this->OS, |
| @@ -83,11 +67,11 @@ class Facture extends Prestation | |||
| 83 | "Pièces:" => $this->pieces, | 67 | "Pièces:" => $this->pieces, |
| 84 | "Total des pièces:" => $this->total_pieces, | 68 | "Total des pièces:" => $this->total_pieces, |
| 85 | "Déplacement:" => $this->deplacement, | 69 | "Déplacement:" => $this->deplacement, |
| 86 | "Total HT:" => $this->total_HT]; | 70 | "Total HT:" => $this->total_HT]); |
| 87 | } | 71 | } |
| 88 | 72 | ||
| 89 | // setters | 73 | // setters |
| 90 | public function set(string $entry, string $input) // trouve la bonne méthode | 74 | public function set(string $entry, string $input): void // trouve la bonne méthode |
| 91 | { | 75 | { |
| 92 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide | 76 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide |
| 93 | switch($entry) | 77 | switch($entry) |
| @@ -122,68 +106,66 @@ class Facture extends Prestation | |||
| 122 | case "Total HT:": | 106 | case "Total HT:": |
| 123 | $this->setTotalHT($input); | 107 | $this->setTotalHT($input); |
| 124 | break; | 108 | break; |
| 109 | default: // gérer les champ dans Prestation | ||
| 110 | parent::set($entry, $input); | ||
| 125 | } | 111 | } |
| 126 | } | 112 | } |
| 127 | public function setPresta(Prestation $input) // private? | 113 | public function setTaches(string $value): Facture |
| 128 | { | ||
| 129 | $this->presta = $input; | ||
| 130 | } | ||
| 131 | public function setTaches(string $value) | ||
| 132 | { | 114 | { |
| 133 | $this->taches = $value; | 115 | $this->taches = $value; |
| 134 | return($this); | 116 | return($this); |
| 135 | } | 117 | } |
| 136 | public function setMachine(string $value) | 118 | public function setMachine(string $value): Facture |
| 137 | { | 119 | { |
| 138 | $this->machine = $value; | 120 | $this->machine = $value; |
| 139 | return($this); | 121 | return($this); |
| 140 | } | 122 | } |
| 141 | public function setOS(string $value) | 123 | public function setOS(string $value): Facture |
| 142 | { | 124 | { |
| 143 | $this->OS = $value; | 125 | $this->OS = $value; |
| 144 | return($this); | 126 | return($this); |
| 145 | } | 127 | } |
| 146 | public function setDonnees(string $value) | 128 | public function setDonnees(string $value): Facture |
| 147 | { | 129 | { |
| 148 | $this->donnees = $value; | 130 | $this->donnees = $value; |
| 149 | return($this); | 131 | return($this); |
| 150 | } | 132 | } |
| 151 | public function setClesLicences(string $value) | 133 | public function setClesLicences(string $value): Facture |
| 152 | { | 134 | { |
| 153 | $this->cles_licences = $value; | 135 | $this->cles_licences = $value; |
| 154 | return($this); | 136 | return($this); |
| 155 | } | 137 | } |
| 156 | public function setTotalMainDOeuvre($value) | 138 | public function setTotalMainDOeuvre(string $value): Facture |
| 157 | { | 139 | { |
| 158 | $value = str_replace(',', '.', $value); | 140 | $value = str_replace(',', '.', $value); |
| 159 | $this->total_main_d_oeuvre = (float) $value; // float "nettoie" tous les caractères après le dernier chiffre trouvé (ex: 50€ => 50, abc => 0) | 141 | $this->total_main_d_oeuvre = (float) $value; // float "nettoie" tous les caractères après le dernier chiffre trouvé (ex: 50€ => 50, abc => 0) |
| 160 | return($this); | 142 | return($this); |
| 161 | } | 143 | } |
| 162 | public function setPieces(string $value) | 144 | public function setPieces(string $value): Facture |
| 163 | { | 145 | { |
| 164 | $this->pieces = $value; | 146 | $this->pieces = $value; |
| 165 | return($this); | 147 | return($this); |
| 166 | } | 148 | } |
| 167 | public function setTotalPieces($value) | 149 | public function setTotalPieces(string $value): Facture |
| 168 | { | 150 | { |
| 169 | $value = str_replace(',', '.', $value); | 151 | $value = str_replace(',', '.', $value); |
| 170 | $this->total_pieces = (float) $value; | 152 | $this->total_pieces = (float) $value; |
| 171 | return($this); | 153 | return($this); |
| 172 | } | 154 | } |
| 173 | public function setDeplacement($value) | 155 | public function setDeplacement(string $value): Facture |
| 174 | { | 156 | { |
| 175 | $value = str_replace(',', '.', $value); | 157 | $value = str_replace(',', '.', $value); |
| 176 | $this->deplacement = (float) $value; | 158 | $this->deplacement = (float) $value; |
| 177 | return($this); | 159 | return($this); |
| 178 | } | 160 | } |
| 179 | public function setTotalHT($value) | 161 | public function setTotalHT(string $value): Facture |
| 180 | { | 162 | { |
| 181 | $value = str_replace(',', '.', $value); | 163 | $value = str_replace(',', '.', $value); |
| 182 | $this->total_HT = (float) $value; | 164 | $this->total_HT = (float) $value; |
| 183 | return($this); | 165 | return($this); |
| 184 | } | 166 | } |
| 185 | 167 | ||
| 186 | private function setAll(array $input) // private? | 168 | private function setService(array $input): void // private? |
| 187 | { | 169 | { |
| 188 | $this->taches = $input[0]; | 170 | $this->taches = $input[0]; |
| 189 | $this->machine = $input[1]; | 171 | $this->machine = $input[1]; |
| @@ -196,7 +178,7 @@ class Facture extends Prestation | |||
| 196 | $this->deplacement = (float)$input[8]; | 178 | $this->deplacement = (float)$input[8]; |
| 197 | $this->total_HT = (float)$input[9]; | 179 | $this->total_HT = (float)$input[9]; |
| 198 | } | 180 | } |
| 199 | private function setServiceFromQuotation(array $input) // private? | 181 | private function setServiceFromQuotation(array $input): void // private? |
| 200 | { | 182 | { |
| 201 | $this->machine = $input[0]; | 183 | $this->machine = $input[0]; |
| 202 | $this->OS = $input[1]; | 184 | $this->OS = $input[1]; |
| @@ -204,50 +186,39 @@ class Facture extends Prestation | |||
| 204 | $this->cles_licences = $input[3]; | 186 | $this->cles_licences = $input[3]; |
| 205 | } | 187 | } |
| 206 | 188 | ||
| 207 | // à mettre plus tard dans une classe mère | 189 | public function validateForm(array $data_array): bool |
| 208 | protected function cleanSpecialChars(string $data): string | ||
| 209 | { | 190 | { |
| 210 | $search = ['"']; | 191 | if(!$this->from_quotation && count($data_array) === 11){ // facture normale |
| 211 | return str_replace($search, '', $data); | 192 | return true; |
| 193 | } | ||
| 194 | elseif(count($data_array) === 5){ // facture à partir d'un devis | ||
| 195 | return true; | ||
| 196 | } | ||
| 197 | else{ | ||
| 198 | echo "erreur de Facture::validateForm(), le tableau \$data_array n'a pas la taille attendue.\n"; | ||
| 199 | return false; | ||
| 200 | } | ||
| 212 | } | 201 | } |
| 202 | |||
| 213 | // à mettre plus tard dans une classe mère | 203 | // à mettre plus tard dans une classe mère |
| 214 | public function hydrate(string $answers): void | 204 | public function hydrate(array $data_array): void |
| 215 | { | 205 | { |
| 216 | $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide | 206 | if(!$this->from_quotation){ // facture normale |
| 217 | if($answers == '') | 207 | $this->setModePaiement($data_array[10]); |
| 218 | { | ||
| 219 | echo "erreur de Facture::hydrate(), la chaine \$answers est vide.\n"; | ||
| 220 | return; | ||
| 221 | } | ||
| 222 | $data_array = explode('|', $answers); // array | ||
| 223 | |||
| 224 | if(count($data_array) === 11) // facture normale | ||
| 225 | { | ||
| 226 | $this->getPresta()->setModePaiement($data_array[10]); | ||
| 227 | //array_pop($data_array); // supprime la dernière case | 208 | //array_pop($data_array); // supprime la dernière case |
| 228 | unset($data_array[10]); | 209 | unset($data_array[10]); |
| 229 | $this->setAll($data_array); | 210 | $this->setService($data_array); |
| 230 | } | 211 | } |
| 231 | elseif(count($data_array) === 5) // facture à partir d'un devis | 212 | else{ // facture à partir d'un devis |
| 232 | { | 213 | $this->setModePaiement($data_array[4]); |
| 233 | $this->getPresta()->setModePaiement($data_array[4]); | ||
| 234 | unset($data_array[4]); | 214 | unset($data_array[4]); |
| 235 | $this->setServiceFromQuotation($data_array); | 215 | $this->setServiceFromQuotation($data_array); |
| 236 | } | 216 | } |
| 237 | else | ||
| 238 | { | ||
| 239 | echo "erreur de Facture::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; | ||
| 240 | return; | ||
| 241 | } | ||
| 242 | |||
| 243 | //self::$entityManager->persist('Prestation'); | ||
| 244 | self::$entityManager->persist($this); // $Presta avec en cascade! | ||
| 245 | self::$entityManager->flush(); | ||
| 246 | } | 217 | } |
| 247 | 218 | ||
| 248 | public function hydrateWithQuotation(Devis $QuotationDetails) | 219 | public function hydrateWithQuotation(Devis $Quotation): void |
| 249 | { | 220 | { |
| 250 | $data = $QuotationDetails->getAll(); | 221 | $data = $Quotation->getAll(); |
| 251 | //var_dump($data);die; | 222 | //var_dump($data);die; |
| 252 | $this->taches = $data['taches']; | 223 | $this->taches = $data['taches']; |
| 253 | $this->total_main_d_oeuvre = $data['total_main_d_oeuvre']; | 224 | $this->total_main_d_oeuvre = $data['total_main_d_oeuvre']; |
