From bf6655a534a6775d30cafa67bd801276bda1d98d Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 13 Aug 2024 23:45:21 +0200 Subject: =?UTF-8?q?VERSION=200.2=20doctrine=20ORM=20et=20entit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/entities/Devis.php | 241 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 src/model/entities/Devis.php (limited to 'src/model/entities/Devis.php') 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 @@ + 'non'])] + private string $signature_devis = 'non'; + + public static EntityManager $entityManager; + + public function __construct(Prestation $presta = null) + { + if($presta != null) + { + $this->setPresta($presta); + } + } + + // 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 + return get_object_vars($this); + } + + public function getAllWithWindowFields(): array + { + //~ $taches = ["Tâches:" => $this->taches]; + //~ $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]; + //~ $champs_devis = [ + //~ "Delai de livraison:" => $this->delai_livraison, + //~ "Durée de validité:" => $this->validite_devis, + //~ "Devis signé:" => $this->signature_devis]; + //~ return $champs_communs + $champs_devis; + return [ + "Tâches:" => $this->taches, // JUSTE AJOUTÉ + "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, + "Delai de livraison:" => $this->delai_livraison, + "Durée de validité:" => $this->validite_devis, + "Devis signé:" => $this->signature_devis]; + } + + // setters + public function set(string $entry, string $input) // trouve la bonne méthode + { + $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide + switch($entry) + { + case "Tâches:": + $this->setTaches($input); + break; + case "Total Main d'oeuvre:": + $this->setTotalMainDOeuvre($input); + break; + case "Pièces:": + $this->setPieces($input); + break; + case "Total des pièces:": + $this->setTotalPieces($input); + break; + case "Déplacement:": + $this->setDeplacement($input); + break; + case "Prix du devis:": + $this->setPrixDevis($input); + break; + case "Total HT:": + $this->setTotalHT($input); + break; + case "Delai de livraison:": + $this->setDelaiLivraison($input); + break; + case "Durée de validité:": + $this->setValiditedevis($input); + break; + case "Devis signé:": + $this->setSignatureDevis($input); + break; + } + } + private function setPresta(Prestation $input) // private? + { + $this->presta = $input; + } + public function setTaches(string $value) + { + $this->taches = $value; + return($this); + } + public function setTotalMainDOeuvre($value) + { + $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) + { + $this->pieces = $value; + return($this); + } + public function setTotalPieces($value) + { + $value = str_replace(',', '.', $value); + $this->total_pieces = (float) $value; + return($this); + } + public function setDeplacement($value) + { + $value = str_replace(',', '.', $value); + $this->deplacement = (float) $value; + return($this); + } + public function setTotalHT($value) + { + $value = str_replace(',', '.', $value); + $this->total_HT = (float) $value; + return($this); + } + public function setPrixDevis($value) + { + $value = str_replace(',', '.', $value); + $this->prix_devis = (float) $value; + return($this); + } + public function setDelaiLivraison(string $value) + { + $this->delai_livraison = $value; + return($this); + } + public function setValiditedevis(string $value) + { + $this->validite_devis = $value; + return($this); + } + public function setSignatureDevis(string $value) + { + $this->signature_devis = $value; + return($this); + } + + private function setAll(array $input) // private? + { + $this->taches = $input[0]; + $this->total_main_d_oeuvre = (float)$input[1]; + $this->pieces = $input[2]; + $this->total_pieces = (float)$input[3]; + $this->deplacement = (float)$input[4]; + $this->prix_devis = (float)$input[5]; + $this->total_HT = (float)$input[6]; + $this->delai_livraison = $input[7]; + $this->validite_devis = $input[8]; + + // $signature_devis est renseigné plus tard en modifiant le devis + } + + // à mettre plus tard dans une classe mère + protected function cleanSpecialChars(string $data): string + { + $search = ['"']; + return str_replace($search, '', $data); + } + // à mettre plus tard dans une classe mère + public function hydrate(string $answers) + { + $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide + if($answers == '') + { + echo "erreur de Devis::hydrate(), la chaine \$answers est vide.\n"; + return false; + } + $data_array = explode('|', $answers); // array + + $check = false; + if(count($data_array) === 9) // facture normale + { + $this->getPresta()->setModePaiement(''); // sécurité, doctrine plante si "null" + $this->setAll($data_array); + } + else + { + echo "erreur de Devis::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; + return false; + } + + //self::$entityManager->persist('Prestation'); + self::$entityManager->persist($this); // $Presta avec en cascade! + self::$entityManager->flush(); + } + + // création d'une facture à partir d'un devis + public static function getQuotation(Prestation $Quotation) + { + $repository = self::$entityManager->getRepository('Devis'); + return $repository->findOneBy(['presta' => $Quotation->getId()]); // ne peut y en avoir deux + } +} -- cgit v1.2.3