from_quotation = $from_quotation; } // getters 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 getTotalMainDOeuvre(): float { return $this->total_main_d_oeuvre; } public function getTotalPieces(): float { return $this->total_pieces; } public function getTotalHT(): float { return $this->total_HT; } public function getAllWithWindowFields(): array { $common_data = parent::getAllWithWindowFields(); return array_merge($common_data, [ "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): void // 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; default: // gérer les champ dans Prestation parent::set($entry, $input); } } public function setTaches(string $value): Facture { $this->taches = $value; return($this); } public function setMachine(string $value): Facture { $this->machine = $value; return($this); } public function setOS(string $value): Facture { $this->OS = $value; return($this); } public function setDonnees(string $value): Facture { $this->donnees = $value; return($this); } public function setClesLicences(string $value): Facture { $this->cles_licences = $value; return($this); } 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): Facture { $this->pieces = $value; return($this); } public function setTotalPieces(string $value): Facture { $value = str_replace(',', '.', $value); $this->total_pieces = (float) $value; return($this); } public function setDeplacement(string $value): Facture { $value = str_replace(',', '.', $value); $this->deplacement = (float) $value; return($this); } public function setTotalHT(string $value): Facture { $value = str_replace(',', '.', $value); $this->total_HT = (float) $value; return($this); } private function setService(array $input): void // 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): void // private? { $this->machine = $input[0]; $this->OS = $input[1]; $this->donnees = $input[2]; $this->cles_licences = $input[3]; } public function validateForm(array $data_array): bool { 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(array $data_array): void { 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->setService($data_array); } else{ // facture à partir d'un devis $this->setModePaiement($data_array[4]); unset($data_array[4]); $this->setServiceFromQuotation($data_array); } } public function hydrateWithQuotation(Devis $Quotation): void { $data = $Quotation->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']; } }