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/Facture.php | 261 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 261 insertions(+) create mode 100644 src/model/entities/Facture.php (limited to 'src/model/entities/Facture.php') diff --git a/src/model/entities/Facture.php b/src/model/entities/Facture.php new file mode 100644 index 0000000..3a8a551 --- /dev/null +++ b/src/model/entities/Facture.php @@ -0,0 +1,261 @@ +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_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 [ + "Tâches:" => $this->taches, + "PC:" => $this->machine, + "OS:" => $this->OS, + "Données:" => $this->donnees, + "Clés de licences:" => $this->cles_licences, + "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]; + } + + // 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 "PC:": + $this->setMachine($input); + break; + case "OS:": + $this->setOS($input); + break; + case "Données:": + $this->setDonnees($input); + break; + case "Clés de licences:": + $this->setClesLicences($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 "Total HT:": + $this->setTotalHT($input); + break; + } + } + public function setPresta(Prestation $input) // private? + { + $this->presta = $input; + } + public function setTaches(string $value) + { + $this->taches = $value; + return($this); + } + public function setMachine(string $value) + { + $this->machine = $value; + return($this); + } + public function setOS(string $value) + { + $this->OS = $value; + return($this); + } + public function setDonnees(string $value) + { + $this->donnees = $value; + return($this); + } + public function setClesLicences(string $value) + { + $this->cles_licences = $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); + } + + private function setAll(array $input) // private? + { + $this->taches = $input[0]; + $this->machine = $input[1]; + $this->OS = $input[2]; + $this->donnees = $input[3]; + $this->cles_licences = $input[4]; + $this->total_main_d_oeuvre = (float)$input[5]; + $this->pieces = $input[6]; + $this->total_pieces = (float)$input[7]; + $this->deplacement = (float)$input[8]; + $this->total_HT = (float)$input[9]; + } + private function setServiceFromQuotation(array $input) // private? + { + $this->machine = $input[0]; + $this->OS = $input[1]; + $this->donnees = $input[2]; + $this->cles_licences = $input[3]; + } + + // à 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 Facture::hydrate(), la chaine \$answers est vide.\n"; + return false; + } + $data_array = explode('|', $answers); // array + + $check = false; + if(count($data_array) === 11) // facture normale + { + $this->getPresta()->setModePaiement($data_array[10]); + //array_pop($data_array); // supprime la dernière case + unset($data_array[10]); + $this->setAll($data_array); + } + elseif(count($data_array) === 5) // facture à partir d'un devis + { + $this->getPresta()->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 false; + } + + //self::$entityManager->persist('Prestation'); + self::$entityManager->persist($this); // $Presta avec en cascade! + self::$entityManager->flush(); + } + + public function hydrateWithQuotation(Devis $QuotationDetails) + { + $data = $QuotationDetails->getAll(); + //var_dump($data);die; + $this->taches = $data['taches']; + $this->total_main_d_oeuvre = $data['total_main_d_oeuvre']; + $this->pieces = $data['pieces']; + $this->total_pieces = $data['total_pieces']; + $this->deplacement = $data['deplacement']; + $this->total_HT = $data['total_HT']; + } +} -- cgit v1.2.3