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/CESU.php | 131 ++++++++++++++++ src/model/entities/Client.php | 314 ++++++++++++++++++++++++++++++++++++++ src/model/entities/Devis.php | 241 +++++++++++++++++++++++++++++ src/model/entities/Facture.php | 261 +++++++++++++++++++++++++++++++ src/model/entities/Location.php | 209 +++++++++++++++++++++++++ src/model/entities/Prestation.php | 252 ++++++++++++++++++++++++++++++ 6 files changed, 1408 insertions(+) create mode 100644 src/model/entities/CESU.php create mode 100644 src/model/entities/Client.php create mode 100644 src/model/entities/Devis.php create mode 100644 src/model/entities/Facture.php create mode 100644 src/model/entities/Location.php create mode 100644 src/model/entities/Prestation.php (limited to 'src/model/entities') diff --git a/src/model/entities/CESU.php b/src/model/entities/CESU.php new file mode 100644 index 0000000..09a2542 --- /dev/null +++ b/src/model/entities/CESU.php @@ -0,0 +1,131 @@ +setPresta($presta); + } + } + + // getters + public function getPresta(): Prestation + { + return $this->presta; + } + + public function getAllWithWindowFields(): array + { + return [ + "Tâche effectuée:" => $this->taches, + "Durée du travail:" => $this->duree_travail, + "Salaire:" => $this->salaire]; + } + + // setters + public function set(string $entry, string $input) + { + $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide + switch($entry) + { + case "Tâche effectuée:": + $this->setTaches($input); + break; + case "Durée du travail:": + $this->setDureeTravail($input); + break; + case "Salaire:": + $this->setSalaire($input); + break; + } + } + private function setPresta(Prestation $input) // private? + { + $this->presta = $input; + } + public function setTaches(string $value) + { + $this->taches = $value; + return($this); + } + public function setDureeTravail(string $value) + { + $this->duree_travail = $value; + return($this); + } + public function setSalaire($value) + { + $value = str_replace(',', '.', $value); + $this->salaire = (float) $value; + return($this); + } + + private function setAll(array $input) // private? + { + $this->taches = $input[0]; + $this->duree_travail = $input[1]; + $this->salaire = (float)$input[2]; + } + + // à 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 CESU::hydrate(), la chaine \$answers est vide.\n"; + return false; + } + $data_array = explode('|', $answers); // array + + $check = false; + if(count($data_array) === 4) // facture normale + { + $this->getPresta()->setModePaiement($data_array[3]); + //array_pop($data_array); // supprime la dernière case + unset($data_array[3]); + $this->setAll($data_array); + } + else + { + echo "erreur de CESU::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(); + } +} diff --git a/src/model/entities/Client.php b/src/model/entities/Client.php new file mode 100644 index 0000000..7dd3be6 --- /dev/null +++ b/src/model/entities/Client.php @@ -0,0 +1,314 @@ + 'prospect'])] + private string $type = 'prospect'; // valeur par défaut utilisée à l'instanciation, pas par doctrine + + public static EntityManager $entityManager; + + /*public function __construct() + { + global $entityManager; + self::$entityManager = $entityManager; + }*/ + + + // getters + public function getId(): int + { + return $this->id; + } + public function getPrenomNom(): string + { + return $this->prenom_nom; + } + public function getCodeClient(): string + { + return $this->code_client; + } + 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); + } + + // pour le GUI + public function getAllWithWindowFields(): array // différent de getAll() + { + return [ + "Prénom Nom:" => $this->prenom_nom, + "Code client (J.C.Dusse):" => $this->code_client, + "Adresse:" => $this->adresse, + "Code postal:" => $this->code_postal, + "Ville:" => $this->ville, + "Telephone:" => $this->telephone, + "Courriel:" => $this->courriel, + "À propos:" => $this->apropos, + "Client ou Prospect?" => $this->type]; + } + + // setters + public function set(string $entry, string $input) + { + $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide + switch($entry) + { + case "Prénom Nom:": + $this->setPrenomNom($input); + break; + case "Code client (J.C.Dusse):": + $this->setCodeClient($input); + break; + case "Adresse:": + $this->setAdresse($input); + break; + case "Code postal:": + $this->setCodePostal($input); + break; + case "Ville:": + $this->setVille($input); + break; + case "Telephone:": + $this->setTelephone($input); + break; + case "Courriel:": + $this->setCourriel($input); + break; + case "À propos:": + $this->setApropos($input); + break; + case "Client ou Prospect?": + $this->setType($input); + break; + } + //self::$entityManager->flush(); + } + public function setPrenomNom($value) + { + $this->prenom_nom = (string) $value; + return $this; + } + public function setCodeClient($value) + { + $this->code_client = (string) $value; + return $this; + } + public function setAdresse($value) + { + $this->adresse = (string) $value; + return $this; + } + public function setCodePostal($value) + { + $this->code_postal = (string) $value; + return $this; + } + public function setVille($value) + { + $this->ville = (string) $value; + return $this; + } + public function setTelephone($value) + { + // type string parce que: + // - zenity renvoie une chaine + // - permet de garder le 0 au début et d'inscrire plusieurs numéros + $this->telephone = (string) $value; + return $this; + } + public function setCourriel($value) + { + $this->courriel = (string) $value; + return $this; + } + public function setApropos($value) + { + $this->apropos = (string) $value; + return $this; + } + public function setType($value) + { + $this->type = (string) $value; + return $this; + } + + public function typeToClient() + { + if($this->type != 'client') + { + $this->type = 'client'; + } + } + + private function setAll(array $input) + { + $this->prenom_nom = $input[0]; + $this->code_client = $input[1]; + $this->adresse = $input[2]; + $this->code_postal = $input[3]; + $this->ville = $input[4]; + $this->telephone = $input[5]; + $this->courriel = $input[6]; + $this->apropos = $input[7]; + } + + // à mettre dans une classe mère Model? + protected function cleanSpecialChars(string $data): string + { + $search = ['"']; + return str_replace($search, '', $data); + } + + // une partie du code vient de Model::hydrateFromForm() + // à mettre dans une classe ClientManager? + public function enterCustomer(ZenityForms $Form): bool + { + $input = exec($Form->get()); + if($input == '') + { + echo "debug: annulation lors de l'enregistrement d'un nouveau client\n"; + return false; + } + + $data_array = explode('|', $input); // array + if($data_array[0] == '') + { + echo "debug: données insuffisantes, le nom du client doit au minimum être renseigné\n"; + return false; + } + else + { + $this->setAll($data_array); + } + + self::$entityManager->persist($this); + self::$entityManager->flush(); + + //$this->id = $this->db->lastInsertId(); // synchro automatique avec doctrine + + return true; + } + + public static function getObject(ZenityEntry $SearchCustomerForm, ZenityList $SearchCustomerResults) // renvoie un Client ou 0 + { + // fenêtres + /*$SearchCustomerForm = new ZenityEntry(ZenitySetup::$recherche_client_text); + $SearchCustomerResults = new ZenityList(ZenitySetup::$resultats_recherche_client_text, []);*/ + + $Customer = new self; // se serait bien d'hériter d'EntityManager? + + $input = exec($SearchCustomerForm->get()); + if($input == '') // commenter ce if pour qu'une saisie vide permette d'obtenir tous les clients + { + echo "debug: recherche annulée ou saisie vide\n"; + return 0; + } + echo "debug: recherche effectuée\n"; + + $MatchedObjects = self::searchCustomer($input, $Customer); + if(count($MatchedObjects) === 0) // si aucun client ne correspond, les prendre tous! + { + $repository = self::$entityManager->getRepository('Client'); + $MatchedObjects = $repository->findAll(); + + if(count($MatchedObjects) === 0) // toujours rien + { + echo "debug: aucun client dans la base de données\n"; + return 0; + } + } + + $clients_array = []; + foreach($MatchedObjects as $object) // d'objets en tableaux + { + $clients_array[] = get_object_vars($object); + } + + $SearchCustomerResults->setListRows( + $clients_array, + //count($clients_array[$id])); + count($clients_array[0])); + + // sélection parmi les résultats + $input = exec($SearchCustomerResults->get()); // renvoie l'id de la table 'clients' + if($input == '') + { + echo "debug: client pas trouvé ou pas sélectionné\n"; + return 0; + } + + echo "debug: client sélectionné\n"; + //$Customer->setId($input); + //$Customer->hydrate($Customer->findById()); + $Customer = $MatchedObjects[$input]; + //var_dump($Customer); + + return $Customer; + } + + private static function searchCustomer(string $input, Client $Customer): array + { + $input_array = explode(' ', $input); // si plusieurs mot, on les recherche tous l'un après l'autre + return $Customer->findByKeywords($input_array, 'prenom_nom'); // on obtient un tableau à deux dimensions avec les entrées trouvées + } + + private function findByKeywords(array $keywords, string $field): array // renvoie un tableau d'objets + { + $results = []; + for($i = 0; $i < count($keywords); $i++) + { + // tableau à deux dimensions obtenu pour un mot clé + //$query_result = $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE ' . $field . ' LIKE "%' . $keywords[$i] . '%"')->fetchAll(); + $query = self::$entityManager->createQuery('SELECT u FROM Client u WHERE u.' . $field . ' LIKE :expression'); + $query->setParameter('expression', '%' . $keywords[$i] . '%'); + $query_result = $query->getResult(); + + foreach($query_result as $object) + { + $id = $object->getId(); + $already_exist = false; + //for($j = 0; $j < count($results); $j++) + foreach($results as $one_result) // pour chaque tableau déjà enregistré dans le tableau $results + { + if($one_result->getId() === $id) + { + $already_exist = true; + } + } + if(!$already_exist) + { + $results[$id] = $object; + } + } + } + //var_dump($results); + return $results; + } +} 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 + } +} 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']; + } +} diff --git a/src/model/entities/Location.php b/src/model/entities/Location.php new file mode 100644 index 0000000..7ce6f0d --- /dev/null +++ b/src/model/entities/Location.php @@ -0,0 +1,209 @@ +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 + { + return [ + "Désignation:" => $this->designation, + "Description du modèle:" => $this->modele_description, + "Valeur:" => $this->valeur, + "État des lieux de début:" => $this->etat_des_lieux_debut, + "État des lieux de fin:" => $this->etat_des_lieux_fin, + "Durée de la location:" => $this->duree_location, + "Loyer Hebdomadaire:" => $this->loyer_hebdo, + "Loyers Payés:" => $this->loyers_payes, + "Caution:" => $this->caution]; + } + + // setters + public function set(string $entry, string $input) + { + $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide + switch($entry) + { + case "Désignation:": + $this->setDesignation($input); + break; + case "Description du modèle:": + $this->setModeleDescription($input); + break; + case "Valeur:": + $this->setValeur($input); + break; + case "État des lieux de début:": + $this->setEtatDesLieuxDebut($input); + break; + case "État des lieux de fin:": + $this->setEtatDesLieuxFin($input); + break; + case "Durée de la location:": + $this->setDureeLocation($input); + break; + case "Loyer Hebdomadaire:": + $this->setLoyerHebdo($input); + break; + case "Loyers Payés:": + $this->setLoyersPayes($input); + break; + case "Caution:": + $this->setCaution($input); + break; + } + } + private function setPresta(Prestation $input) // private? + { + $this->presta = $input; + } + public function setDesignation(string $value) + { + $this->designation = $value; + return($this); + } + public function setModeleDescription(string $value) + { + $this->modele_description = $value; + return($this); + } + public function setValeur($value) + { + $value = str_replace(',', '.', $value); + $this->valeur = (float) $value; + return($this); + } + public function setEtatDesLieuxDebut(string $value) + { + $this->etat_des_lieux_debut = $value; + return($this); + } + public function setEtatDesLieuxFin(string $value) + { + $this->etat_des_lieux_fin = $value; + return($this); + } + public function setDureeLocation(string $value) + { + $this->duree_location = $value; + return($this); + } + public function setLoyerMensuel($value) + { + $value = str_replace(',', '.', $value); + $this->loyer_mensuel = (float) $value; + return($this); + } + public function setLoyersPayes($value) + { + $value = str_replace(',', '.', $value); + $this->loyers_payes = (float) $value; + return($this); + } + public function setCaution($value) + { + $value = str_replace(',', '.', $value); + $this->caution = (float) $value; + return($this); + } + + private function setAll(array $input) // private? + { + $this->designation = $input[0]; + $this->modele_description = $input[1]; + $this->valeur = (float)$input[2]; + $this->etat_des_lieux_debut = $input[3]; + $this->etat_des_lieux_fin = ''; // sécurité + $this->duree_location = $input[4]; + $this->loyer_hebdo = (float)$input[5]; + $this->loyers_payes = (int)$input[6]; + $this->caution = (int)$input[7]; + } + + // à 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 Location::hydrate(), la chaine \$answers est vide.\n"; + return false; + } + $data_array = explode('|', $answers); // array + + $check = false; + if(count($data_array) === 8) + { + $this->getPresta()->setModePaiement(''); // sécurité, doctrine plante si "null" + $this->setAll($data_array); + } + else + { + echo "erreur de Location::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(); + } +} diff --git a/src/model/entities/Prestation.php b/src/model/entities/Prestation.php new file mode 100644 index 0000000..6d014d8 --- /dev/null +++ b/src/model/entities/Prestation.php @@ -0,0 +1,252 @@ +setClient($client); + } + } + + // getters + public function getId(): int + { + return $this->id; + } + public function getCodePresta(): string + { + return $this->code_presta; + } + public function getDate(): int + { + return $this->date; + } + public function getTypePresta(): string + { + return $this->type_presta; + } + public function getClient(): Client + { + return $this->client; + } + 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 // différent de Model::getAll() qui retourne get_object_vars($this) + { + $code_presta_tableau = explode('-', $this->code_presta); + $Date = new Dates($this->date); + + return [ + //"Numéro prestation:" => end($code_presta_tableau), // crée des conflits, calcul automatique par setCodePresta() + "Date:" => $Date->getDate(), + //"Type de Presta:" => $this->type_presta, // choix impossible pour le moment + "Mode de paiement:" => $this->mode_paiement, // non pertinent pour un devis + "Commentaires:" => $this->commentaires]; + } + + // setters + //~ public function setCodePresta(string $value) + //~ { + //~ $this->code_presta = $value; + //~ return $this; + //~ } + //public function setDate(int $value) + public function setDate(Dates $Date) + { + //$this->date = (int)$value; // attend un timestamp + $this->date = $Date->getTimestamp(); + return $this; + /*if($set_code_presta) + { + $code_presta_tableau = explode('-', $this->code_presta); + $Date = new Dates($value); + $code_presta_tableau[0] = $Date->getYear(); + $code_presta_tableau[1] = $Date->getMonth(); + $code_presta_tableau[2] = $Date->getDay(); + $this->code_presta = implode('-', $code_presta_tableau); + }*/ + } + + public function setTypePresta(string $value) // appelée dans la section 2 uniquement, pour la 3 on verra plus tard + { + $this->type_presta = $value; + return $this; + } + public function setModePaiement(string $value) + { + $this->mode_paiement = $value; + return $this; + } + public function setCommentaires(string $input) + { + $this->commentaires = $input; + } + /*public function setAll(array $input) + { + $this->code_presta = $input[0]; + $this->date = $input[1]; + $this->type_presta = $input[2]; + $this->mode_paiement = $input[3]; + $this->commentaires = $input[4]; + }*/ + + private function setClient(Client $input) // private? + { + $this->client = $input; + //$input->typeToClient(); // on modifie $client ici (merci les références PHP) + } + + public function set(string $entry, $input) // $input = chaîne ou entier + { + if(gettype($input) === 'string') + { + $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide + } + switch($entry) + { + // pas de cas "code presta" qui généré par setCodePresta, on peut modifier la date (ici) et le code client (ailleurs) + //~ case "Numéro prestation:": + //~ $this->setNumeroPresta($input); + //~ // modifier le code presta en conséquence + //~ break; + case "Date:": // inutile, setDate() est appelé directement après choix fenêtre calendrier + $this->setDate($input); + break; + //~ case "Type de Presta:": // choix impossible pour le moment + //~ $this->setTypePresta($input); + //~ break; + case "Mode de paiement:": + $this->setModePaiement($input); + break; + case "Commentaires:": + $this->setCommentaires($input); + break; + } + } + + // code presta = année-mois-jour-codeclient-typedepresta-combientièmefois + public function setCodePresta(int $increment) // 0 pour modif, 1 pour nouvelle presta + { + $Date = new Dates($this->date); + $repository = self::$entityManager->getRepository('Prestation'); // prestas de tout type d'un client + // attention: il peut y avoir plusieurs prestations avec le même numéro au compteur, à améliorer + $combientieme_fois = count($repository->findBy(['client' => $this->client->getId()])) + $increment; + //var_dump($combientieme_fois); + $array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $this->client->getCodeClient(), $this->type_presta, $combientieme_fois]; + //~ $array_code[0] = $Date->getYear(); + //~ $array_code[1] = $Date->getMonth(); + //~ $array_code[2] = $Date->getDay(); + //~ $array_code[3] = $this->client->getCodeClient(); // mise à jour éventuelle + //~ $array_code[4] = $this->type_presta; + $this->code_presta = implode('-', $array_code); + return $this; + } + // combientième fois au choix (ne fonctionne pas avec setCodePresta qui recalculera ce numéro automatiquement à la prochaine modification) + //~ public function setNumeroPresta($value) + //~ { + //~ // modifier le code presta, on pourrait aussi utiliser une regex + //~ $code_presta_tableau = explode('-', $this->code_presta); + //~ $code_presta_tableau[count($code_presta_tableau) - 1] = (int) $value; // dernière case du tableau + //~ $this->code_presta = implode('-', $code_presta_tableau); + //~ return $this; + //~ } + + public static function getServices(Client $Customer, string $type = '') + { + echo "debug: recherche d'une prestation\n"; + + // requête DQL qui fait la même chose que le findBy plus bas + /*$query = self::$entityManager->createQuery('SELECT u FROM Prestation u WHERE u.client = :id_client AND u.type_presta = :type_presta'); + $query->setParameter('id_client', $Customer->getId()); + $query->setParameter('type_presta', $type); + $query_result = $query->getResult(); + var_dump($query_result);die;*/ + + $repository = self::$entityManager->getRepository('Prestation'); + $find_by = ['client' => $Customer->getId()]; + if($type != '') + { + $find_by['type_presta'] = 'devis'; + } + $PrestaList = $repository->findBy($find_by); + + // le même tableau avec pour clés les id des objets + $PrestaListIdKeys = []; + foreach($PrestaList as $Presta) + { + $id = $Presta->getId(); + $PrestaListIdKeys[$id] = $Presta; + } + + // fenêtre + $entrees = []; + foreach($PrestaListIdKeys as $Presta) + { + $id = $Presta->getId(); + $entrees[$id][] = $id; + $Date = new Dates((int)$Presta->getDate()); // envoi du timestamp, (int) est là par sécurité + $entrees[$id][] = $Date->getDate(); + $entrees[$id][] = $Presta->getTypePresta(); + $entrees[$id][] = $Presta->getCodePresta(); + } + + // pas à la bonne place, couper la fonction en deux et mettre ça ailleurs! + $ResultatsRecherchePresta = new ZenityList(ZenitySetup::$resultats_recherche_presta['text'], []); + $ResultatsRecherchePresta->setListRows($entrees, 4); + + // choix de l'utilisateur + $input = exec($ResultatsRecherchePresta->get()); // $input est l'ID de la prestation + //echo "input = " . $input . "\n"; + if($input == '') + { + echo "debug: recherche annulée ou saisie vide\n"; + return 0; + } + else + { + return $PrestaListIdKeys[$input]; + } + } + + // à mettre plus tard dans une classe mère + private function cleanSpecialChars(string $data): string + { + $search = ['"']; + return str_replace($search, '', $data); + } +} -- cgit v1.2.3