From 0161ac4d632af7d45f4fe9d68c1ba3a86f094fc4 Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 20 Oct 2026 21:49:17 +0200 Subject: =?UTF-8?q?mise=20en=20place=20de=20l'h=C3=A9ritage=202,=20nombreu?= =?UTF-8?q?ses=20simplifications=20et=20factorisations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/entities/Facture.php | 113 +++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 71 deletions(-) (limited to 'src/model/entities/Facture.php') 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 @@ // src/entities/Facture.php use Doctrine\ORM\Mapping as ORM; -use Doctrine\ORM\EntityManager; #[ORM\Entity] #[ORM\Table(name: 'factures')] @@ -29,17 +28,14 @@ class Facture extends Prestation #[ORM\Column] private float $total_HT; - public static EntityManager $entityManager; + private bool $from_quotation; - public function __construct(?Prestation $presta = null){ - $this->setPresta($presta); + public function __construct(Client $client, bool $from_quotation){ + parent::__construct($client); + $this->from_quotation = $from_quotation; } // 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 @@ -60,20 +56,8 @@ class Facture extends Prestation 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 [ + $common_data = parent::getAllWithWindowFields(); + return array_merge($common_data, [ "Tâches:" => $this->taches, "PC:" => $this->machine, "OS:" => $this->OS, @@ -83,11 +67,11 @@ class Facture extends Prestation "Pièces:" => $this->pieces, "Total des pièces:" => $this->total_pieces, "Déplacement:" => $this->deplacement, - "Total HT:" => $this->total_HT]; + "Total HT:" => $this->total_HT]); } // setters - public function set(string $entry, string $input) // trouve la bonne méthode + public function set(string $entry, string $input): void // trouve la bonne méthode { $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide switch($entry) @@ -122,68 +106,66 @@ class Facture extends Prestation case "Total HT:": $this->setTotalHT($input); break; + default: // gérer les champ dans Prestation + parent::set($entry, $input); } } - public function setPresta(Prestation $input) // private? - { - $this->presta = $input; - } - public function setTaches(string $value) + public function setTaches(string $value): Facture { $this->taches = $value; return($this); } - public function setMachine(string $value) + public function setMachine(string $value): Facture { $this->machine = $value; return($this); } - public function setOS(string $value) + public function setOS(string $value): Facture { $this->OS = $value; return($this); } - public function setDonnees(string $value) + public function setDonnees(string $value): Facture { $this->donnees = $value; return($this); } - public function setClesLicences(string $value) + public function setClesLicences(string $value): Facture { $this->cles_licences = $value; return($this); } - public function setTotalMainDOeuvre($value) + public function setTotalMainDOeuvre(string $value): Facture { $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) + public function setPieces(string $value): Facture { $this->pieces = $value; return($this); } - public function setTotalPieces($value) + public function setTotalPieces(string $value): Facture { $value = str_replace(',', '.', $value); $this->total_pieces = (float) $value; return($this); } - public function setDeplacement($value) + public function setDeplacement(string $value): Facture { $value = str_replace(',', '.', $value); $this->deplacement = (float) $value; return($this); } - public function setTotalHT($value) + public function setTotalHT(string $value): Facture { $value = str_replace(',', '.', $value); $this->total_HT = (float) $value; return($this); } - private function setAll(array $input) // private? + private function setService(array $input): void // private? { $this->taches = $input[0]; $this->machine = $input[1]; @@ -196,7 +178,7 @@ class Facture extends Prestation $this->deplacement = (float)$input[8]; $this->total_HT = (float)$input[9]; } - private function setServiceFromQuotation(array $input) // private? + private function setServiceFromQuotation(array $input): void // private? { $this->machine = $input[0]; $this->OS = $input[1]; @@ -204,50 +186,39 @@ class Facture extends Prestation $this->cles_licences = $input[3]; } - // à mettre plus tard dans une classe mère - protected function cleanSpecialChars(string $data): string + public function validateForm(array $data_array): bool { - $search = ['"']; - return str_replace($search, '', $data); + if(!$this->from_quotation && count($data_array) === 11){ // facture normale + return true; + } + elseif(count($data_array) === 5){ // facture à partir d'un devis + return true; + } + else{ + echo "erreur de Facture::validateForm(), le tableau \$data_array n'a pas la taille attendue.\n"; + return false; + } } + // à mettre plus tard dans une classe mère - public function hydrate(string $answers): void + public function hydrate(array $data_array): void { - $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; - } - $data_array = explode('|', $answers); // array - - if(count($data_array) === 11) // facture normale - { - $this->getPresta()->setModePaiement($data_array[10]); + if(!$this->from_quotation){ // facture normale + $this->setModePaiement($data_array[10]); //array_pop($data_array); // supprime la dernière case unset($data_array[10]); - $this->setAll($data_array); + $this->setService($data_array); } - elseif(count($data_array) === 5) // facture à partir d'un devis - { - $this->getPresta()->setModePaiement($data_array[4]); + else{ // facture à partir d'un devis + $this->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; - } - - //self::$entityManager->persist('Prestation'); - self::$entityManager->persist($this); // $Presta avec en cascade! - self::$entityManager->flush(); } - public function hydrateWithQuotation(Devis $QuotationDetails) + public function hydrateWithQuotation(Devis $Quotation): void { - $data = $QuotationDetails->getAll(); + $data = $Quotation->getAll(); //var_dump($data);die; $this->taches = $data['taches']; $this->total_main_d_oeuvre = $data['total_main_d_oeuvre']; -- cgit v1.2.3