From b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878 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/Latex.php | 22 +++--- src/latex_templates/devis.php | 2 +- src/latex_templates/facture.php | 2 +- src/latex_templates/location.php | 2 +- src/main.php | 7 +- src/model/entities/CESU.php | 71 ++++++------------- src/model/entities/Devis.php | 98 +++++++-------------------- src/model/entities/Facture.php | 113 ++++++++++++------------------- src/model/entities/Location.php | 63 +++++------------ src/model/entities/NonVendue.php | 32 +++++++++ src/model/entities/Prestation.php | 139 +++++++++++++++----------------------- src/sections/2_service.php | 114 ++++++++++++++----------------- src/sections/3-1_windows.php | 30 +------- src/sections/3_modify_data.php | 128 +++++++++++------------------------ src/view/ZenitySetup.php | 3 +- "\303\240 faire.txt" | 10 ++- 16 files changed, 313 insertions(+), 523 deletions(-) diff --git a/src/Latex.php b/src/Latex.php index c638264..871a845 100644 --- a/src/Latex.php +++ b/src/Latex.php @@ -14,8 +14,7 @@ abstract class Latex static function makeInstance(string $type): ?Latex { - switch($type) - { + switch($type){ // documents pour les clients case 'devis': return new DevisLatex; @@ -120,9 +119,10 @@ abstract class Latex //~ $this->pdf_path = $pdf_path; //~ } - public function setData(Object $Object) + public function setData(Object $Object): Latex { $this->data = array_merge($this->data, $Object->getAll()); // nécessite des tableaux associatifs + return $this; // pour chainer les méthodes } } @@ -134,9 +134,11 @@ abstract class PrestaLatex extends Latex public function setData(Object $Object): Latex // polymorphisme { $this->data = array_merge($this->data, $Object->getAll()); // nécessite des tableaux associatifs - - if(get_class($Object) === 'Prestation') - { + if(isset($this->data['date'])){ + $this->data['date'] = str_replace('-', '/', $this->data['date']); // 17/10/2026, avec des / parce que j'aime bien + } + + if(in_array(get_class($Object), ['Facture', 'Devis', 'Location'])){ $this->file_name = $Object->getCodePresta() . '.tex'; $this->date_array = explode('-', $Object->getdate()); $this->latex_path = Config::$latex_path . $this->date_array[0] . DIRECTORY_SEPARATOR; @@ -152,10 +154,10 @@ abstract class PrestaLatex extends Latex //~ $this->fileName = $quoi . '-' . $codePresta . '.tex'; //~ } - public function makeLatex() + public function makeLatex(): void { $data = $this->data; - $date = preg_replace('#\D#', '/', $this->date_array[2] . '/' . $this->date_array[1] . '/' . $this->date_array[0]); // 17/10/2026, avec des / parce que j'aime bien + //$date = preg_replace('#\D#', '/', $this->date_array[2] . '/' . $this->date_array[1] . '/' . $this->date_array[0]); // on obtient la variable $latex avec ob_get_clean() // le include() ici, c'est du génie ou c'est moche ou les deux? @@ -189,11 +191,13 @@ class EnveloppeRectoLatex extends Latex $this->pdf_path = Config::$pdf_path . 'enveloppes_recto/'; } - public function setData(Object $Client) // ici de type Clients + public function setData(Object $Client): Latex // ici de type Clients { $this->file_name = $Client->getCodeClient() . '.tex'; $this->data = array_merge($this->data, $Client->getAll()); // nécessite des tableaux associatifs $this->spacesInPostCode(); // nécessite $this->data + + return $this; // pour chainer les méthodes } // code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0 diff --git a/src/latex_templates/devis.php b/src/latex_templates/devis.php index 43e9309..fafa5ba 100644 --- a/src/latex_templates/devis.php +++ b/src/latex_templates/devis.php @@ -69,7 +69,7 @@ ob_start(); \begin{tabularx}{\linewidth}{@{}X@{}@{}X@{}} Mme, M : \textcolor{vert}{} & - Date du devis : \textcolor{vert}{}\\ + Date du devis : \textcolor{vert}{}\\ \end{tabularx}\\ Adresse : \textcolor{vert}{}\\ \begin{tabularx}{\linewidth}{@{}X@{}@{}X@{}} diff --git a/src/latex_templates/facture.php b/src/latex_templates/facture.php index dba1e1f..d51a90a 100644 --- a/src/latex_templates/facture.php +++ b/src/latex_templates/facture.php @@ -61,7 +61,7 @@ ob_start(); \begin{tabularx}{\linewidth}{@{}X@{}@{}X@{}} Mme, M : \textcolor{vert}{} & - Date : \textcolor{vert}{}\\ + Date : \textcolor{vert}{}\\ \end{tabularx}\\ Adresse : \textcolor{vert}{}\\ diff --git a/src/latex_templates/location.php b/src/latex_templates/location.php index 47f6947..64a7736 100644 --- a/src/latex_templates/location.php +++ b/src/latex_templates/location.php @@ -79,7 +79,7 @@ ob_start(); \textbf{Le bénéficiaire de cette location s’engage à prendre soin du bien désigné et à en faire un usage strictement personnel.}\\ \begin{tabularx}{\linewidth}{@{}X@{}@{}X@{}} - Fait en deux exemplaires à : \textcolor{vert}{} & le : \textcolor{vert}{} \\ + Fait en deux exemplaires à : \textcolor{vert}{} & le : \textcolor{vert}{} \\ \end{tabularx}\\ \begin{tabularx}{\linewidth}{@{}X@{}@{}X@{}} diff --git a/src/main.php b/src/main.php index edf10f2..03d1efb 100644 --- a/src/main.php +++ b/src/main.php @@ -28,14 +28,9 @@ require 'src/dependances.php'; // vérification des dépendances require 'src/model/doctrine-bootstrap.php'; // contient aussi un autoloader spécial pour les entités // le require_once 'vendor/autoload.php'; doit être situé AVANT cette ligne pour être exécuté en second -// utiliser plus tard de nouvelles classes Manager au lieu des entités -// ET les faire hériter d'un unique parent +// $entityManager accessible partout (posibilité d'une classe Manager gérant ça et faisant les flush) Client::$entityManager = $entityManager; Prestation::$entityManager = $entityManager; -Devis::$entityManager = $entityManager; -Facture::$entityManager = $entityManager; -CESU::$entityManager = $entityManager; -Location::$entityManager = $entityManager; require 'src/functions.php'; //~ require 'src/view/Zenity.php'; // générer ler commandes système zenity diff --git a/src/model/entities/CESU.php b/src/model/entities/CESU.php index b840ac9..3e7ab10 100644 --- a/src/model/entities/CESU.php +++ b/src/model/entities/CESU.php @@ -2,7 +2,6 @@ // src/entities/CESU.php use Doctrine\ORM\Mapping as ORM; -use Doctrine\ORM\EntityManager; #[ORM\Entity] #[ORM\Table(name: 'cesu')] @@ -18,17 +17,7 @@ class CESU extends Prestation /*#[ORM\Column]*/ // pour plus tard private ?string $date_bulletin_paie = null; // format Y-m-d conservé tout du long: formulaire, BDD, affichage - public static EntityManager $entityManager; - - public function __construct(?Prestation $presta = null){ - $this->setPresta($presta); - } - // getters - public function getPresta(): ?Prestation - { - return $this->presta; - } public function getSalaire(): float { return $this->salaire; @@ -41,14 +30,15 @@ class CESU extends Prestation public function getAllWithWindowFields(): array { - return [ + $common_data = parent::getAllWithWindowFields(); + return array_merge($common_data, [ "Tâche effectuée:" => $this->taches, "Durée du travail:" => $this->duree_travail, - "Salaire:" => $this->salaire]; + "Salaire:" => $this->salaire]); } // setters - public function set(string $entry, string $input) + public function set(string $entry, string $input): void { $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide switch($entry) @@ -62,11 +52,9 @@ class CESU extends Prestation case "Salaire:": $this->setSalaire($input); break; - } - } - private function setPresta(Prestation $input): void - { - $this->presta = $input; + default: // gérer les champ dans Prestation + parent::set($entry, $input); + } } public function setTaches(string $value): CESU { @@ -78,7 +66,7 @@ class CESU extends Prestation $this->duree_travail = $value; return($this); } - public function setSalaire($value): CESU + public function setSalaire(string $value): CESU { $value = str_replace(',', '.', $value); $this->salaire = (float) $value; @@ -97,38 +85,23 @@ class CESU extends Prestation $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): void + public function validateForm(array $data_array): bool { - $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; - } - $data_array = explode('|', $answers); // array - - 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); + if(count($data_array) === 4){ + return true; } - else - { - echo "erreur de CESU::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; - return; + else{ + echo "erreur de CESU::validateForm(), 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(); + // à mettre plus tard dans une classe mère + public function hydrate(array $data_array): void + { + $this->setModePaiement($data_array[3]); + //array_pop($data_array); // supprime la dernière case + unset($data_array[3]); + $this->setAll($data_array); } } diff --git a/src/model/entities/Devis.php b/src/model/entities/Devis.php index f559243..3f051c2 100644 --- a/src/model/entities/Devis.php +++ b/src/model/entities/Devis.php @@ -2,7 +2,6 @@ // src/entities/Devis.php use Doctrine\ORM\Mapping as ORM; -use Doctrine\ORM\EntityManager; #[ORM\Entity] #[ORM\Table(name: 'devis')] @@ -29,17 +28,7 @@ class Devis extends Prestation #[ORM\Column (options: ['default' => 'non'])] // défaut dans le cas d'un requête SQL ignorant ce champ private string $signature_devis = 'non'; - public static EntityManager $entityManager; - - public function __construct(?Prestation $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 @@ -48,19 +37,8 @@ class Devis extends Prestation 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 [ + $common_data = parent::getAllWithWindowFields(); + return array_merge($common_data, [ "Tâches:" => $this->taches, // JUSTE AJOUTÉ "Total Main d'oeuvre:" => $this->total_main_d_oeuvre, "Pièces:" => $this->pieces, @@ -70,11 +48,11 @@ class Devis extends Prestation "Total HT:" => $this->total_HT, "Delai de livraison:" => $this->delai_livraison, "Durée de validité:" => $this->validite_devis, - "Devis signé:" => $this->signature_devis]; + "Devis signé:" => $this->signature_devis]); } // 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) @@ -109,41 +87,39 @@ class Devis extends Prestation case "Devis signé:": $this->setSignatureDevis($input); break; + default: // gérer les champ dans Prestation + parent::set($entry, $input); } } - private function setPresta(Prestation $input) // private? - { - $this->presta = $input; - } - public function setTaches(string $value) + public function setTaches(string $value): Devis { $this->taches = $value; return($this); } - public function setTotalMainDOeuvre($value) + public function setTotalMainDOeuvre(string $value): Devis { $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): Devis { $this->pieces = $value; return($this); } - public function setTotalPieces($value) + public function setTotalPieces(string $value): Devis { $value = str_replace(',', '.', $value); $this->total_pieces = (float) $value; return($this); } - public function setDeplacement($value) + public function setDeplacement(string $value): Devis { $value = str_replace(',', '.', $value); $this->deplacement = (float) $value; return($this); } - public function setTotalHT($value) + public function setTotalHT(string $value): Devis { $value = str_replace(',', '.', $value); $this->total_HT = (float) $value; @@ -155,23 +131,23 @@ class Devis extends Prestation $this->prix_devis = (float) $value; return($this); } - public function setDelaiLivraison(string $value) + public function setDelaiLivraison(string $value): Devis { $this->delai_livraison = $value; return($this); } - public function setValiditedevis(string $value) + public function setValiditedevis(string $value): Devis { $this->validite_devis = $value; return($this); } - public function setSignatureDevis(string $value) + public function setSignatureDevis(string $value): Devis { $this->signature_devis = $value; return($this); } - private function setAll(array $input) // private? + private function setAll(array $input): void // private? { $this->taches = $input[0]; $this->total_main_d_oeuvre = (float)$input[1]; @@ -186,43 +162,21 @@ class Devis extends Prestation // $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): void + public function validateForm(array $data_array): bool { - $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; + if(count($data_array) === 9){ + return true; } - $data_array = explode('|', $answers); // array - - if(count($data_array) === 9) // facture normale, "=== 9" = merdique - { - $this->getPresta()->setModePaiement(''); // sécurité, doctrine plante si "null" - $this->setAll($data_array); + else{ + echo "erreur de Devis::validateForm(), le tableau \$data_array n'a pas la taille attendue.\n"; + return false; } - else - { - echo "erreur de Devis::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(); } - // création d'une facture à partir d'un devis - public static function getQuotation(Prestation $Quotation) + // à mettre plus tard dans une classe mère + public function hydrate(array $data_array): void { - $repository = self::$entityManager->getRepository('Devis'); - return $repository->findOneBy(['presta' => $Quotation->getId()]); // ne peut y en avoir deux + //$this->setModePaiement(''); // vaut déjà '' + $this->setAll($data_array); } } 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']; diff --git a/src/model/entities/Location.php b/src/model/entities/Location.php index 3574272..c18c40a 100644 --- a/src/model/entities/Location.php +++ b/src/model/entities/Location.php @@ -2,7 +2,6 @@ // src/entities/Location.php use Doctrine\ORM\Mapping as ORM; -use Doctrine\ORM\EntityManager; #[ORM\Entity] #[ORM\Table(name: 'locations')] @@ -27,17 +26,7 @@ class Location extends Prestation #[ORM\Column] protected float $caution; - public static EntityManager $entityManager; - - public function __construct(?Prestation $presta = null){ - $this->setPresta($presta); - } - // getters - public function getPresta(): Prestation - { - return $this->presta; - } public function getLoyer(): float { return $this->loyer_hebdo; @@ -54,7 +43,8 @@ class Location extends Prestation public function getAllWithWindowFields(): array { - return [ + $common_data = parent::getAllWithWindowFields(); + return array_merge($common_data, [ "Désignation:" => $this->designation, "Description du modèle:" => $this->modele_description, "Valeur:" => $this->valeur, @@ -63,7 +53,7 @@ class Location extends Prestation "Durée de la location:" => $this->duree_location, "Loyer Hebdomadaire:" => $this->loyer_hebdo, "Loyers Payés:" => $this->loyers_payes, - "Caution:" => $this->caution]; + "Caution:" => $this->caution]); } // setters @@ -99,11 +89,9 @@ class Location extends Prestation case "Caution:": $this->setCaution($input); break; - } - } - private function setPresta(Prestation $input): void // private? - { - $this->presta = $input; + default: // gérer les champ dans Prestation + parent::set($entry, $input); + } } public function setDesignation(string $value): Location { @@ -168,36 +156,21 @@ class Location extends Prestation $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): void + public function validateForm(array $data_array): bool { - $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; - } - $data_array = explode('|', $answers); // array - - if(count($data_array) === 8) - { - $this->getPresta()->setModePaiement(''); // sécurité, doctrine plante si "null" - $this->setAll($data_array); + if(count($data_array) === 8){ + return true; } - else - { - echo "erreur de Location::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; - return; + else{ + echo "erreur de Location::validateForm(), 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(); + // à mettre plus tard dans une classe mère + public function hydrate(array $data_array): void + { + //$this->setModePaiement(''); // vaut déjà '' + $this->setAll($data_array); } } diff --git a/src/model/entities/NonVendue.php b/src/model/entities/NonVendue.php index b6b2612..5a8879e 100644 --- a/src/model/entities/NonVendue.php +++ b/src/model/entities/NonVendue.php @@ -9,4 +9,36 @@ class NonVendue extends Prestation { #[ORM\Column] private string $taches; + + public function getTaches(): string + { + return $this->taches; + } + public function getAllWithWindowFields(): array + { + $common_data = parent::getAllWithWindowFields(); + return array_merge($common_data, ["Tâches:" => $this->taches,]); + } + public function setTaches(string $value): NonVendue + { + $this->taches = $value; + return $this; + } + + //public function set(string $entry, string $input): void // pas nécessaire ici + + public function validateForm(array $data_array): bool + { + if(count($data_array) === 1){ + return true; + } + else{ + echo "erreur de NonVendue::validateForm(), le tableau \$data_array n'a pas la taille attendue.\n"; + return false; + } + } + public function hydrate(array $data_array): void + { + $this->setTaches($data_array[0]); + } } \ No newline at end of file diff --git a/src/model/entities/Prestation.php b/src/model/entities/Prestation.php index fe18b70..6fef8b6 100644 --- a/src/model/entities/Prestation.php +++ b/src/model/entities/Prestation.php @@ -28,19 +28,19 @@ abstract class Prestation #[ORM\ManyToOne(targetEntity: Client::class, cascade: ['persist'])] #[ORM\JoinColumn(name: 'id_client', referencedColumnName: 'id')] - private ?Client $client = null; // type int en SQL et dans la base + private Client $client; // type int en SQL et dans la base #[ORM\Column] - private string $code_presta; + protected string $code_presta; #[ORM\Column(type: 'string', length: 10)] // format 'aaaa-mm-jj' - private string $date; + protected string $date; #[ORM\Column] private string $mode_paiement = ''; // non renseigné quand on fait un devis #[ORM\Column] private string $commentaires; - public static EntityManager $entityManager; + public static EntityManager $entityManager; // inséré dans main.php - public function __construct(?Client $client = null){ + public function __construct(Client $client){ $this->setClient($client); } @@ -57,10 +57,17 @@ abstract class Prestation { return $this->date; } - /*public function getTypePresta(): string + public function getTypePresta(): string { - return $this->type_presta; - }*/ + return match (true) { + $this instanceof Devis => 'devis', + $this instanceof Facture => 'facture', + $this instanceof CESU => 'cesu', + $this instanceof Location => 'location', + $this instanceof NonVendue => 'non_vendue', + //default => throw new \LogicException('Type de prestation inconnu'), // impossible + }; + } public function getModePaiement(): string { return $this->mode_paiement; @@ -75,7 +82,7 @@ abstract class Prestation return get_object_vars($this); } - public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) + public function getAllWithWindowFields(): array // différent de getAll() qui retourne get_object_vars($this) { return [ //"Numéro prestation:" => end($code_presta_tableau), // crée des conflits, calcul automatique par setCodePresta() @@ -85,31 +92,7 @@ abstract class Prestation "Commentaires:" => $this->commentaires]; } - // une interface pour ça c'est bien aussi non? - public function getFacture(): ?Facture - { - return $this->facture; - } - public function getDevis(): ?Devis - { - return $this->devis; - } - public function getCesu(): ?CESU - { - return $this->cesu; - } - public function getLocation(): ?Location - { - return $this->location; - } - // setters - //~ public function setCodePresta(string $value) - //~ { - //~ $this->code_presta = $value; - //~ return $this; - //~ } - //public function setDate(int $value) public function setDate(string $date): Prestation { $this->date = $date; @@ -125,36 +108,24 @@ abstract class Prestation }*/ } - /*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) + public function setModePaiement(string $value): Prestation { $this->mode_paiement = $value; return $this; } - public function setCommentaires(string $input) + public function setCommentaires(string $input): void { $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? + private function setClient(Client $client): void // private? { - $this->client = $input; - //$input->typeToClient(); // on modifie $client ici (merci les références PHP) + $this->client = $client; } - /*public function set(string $entry, string $input): void + public function set(string $entry, string $input): void { $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide @@ -167,8 +138,7 @@ abstract class Prestation 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); + //~ case "Type de Presta:": // choix impossible pour le moment et pas anodin //~ break; case "Mode de paiement:": $this->setModePaiement($input); @@ -177,12 +147,13 @@ abstract class Prestation $this->setCommentaires($input); break; } - }*/ + } // code presta = année-mois-jour-codeclient-typedepresta-combientièmefois public function setCodePresta(int $increment): Prestation // 0 pour modif, 1 pour nouvelle presta { - $repository = self::$entityManager->getRepository('Prestation'); // prestas de tout type d'un client + $repository = self::$entityManager->getRepository('Prestation'); + // attention: il peut y avoir plusieurs prestations avec le même numéro au compteur, à améliorer $how_many_times = count($repository->findBy(['client' => $this->client->getId()])) + $increment; //var_dump($how_many_times); @@ -192,7 +163,7 @@ abstract class Prestation $date_array[1], // mois $date_array[2], // jour $this->client->getCodeClient(), // mise à jour éventuelle - //$this->type_presta, + $this->getTypePresta(), $how_many_times ]; $this->code_presta = implode('-', $array_code); @@ -208,37 +179,27 @@ abstract class Prestation //~ return $this; //~ } - public static function getServices(Client $Customer, string $type = '') + public static function getServices(Client $Customer, string $type_class = Prestation::class): ?Prestation // param par défaut = recherche tout 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;*/ + /*$query = self::$entityManager->createQuery('SELECT u FROM Prestation u WHERE u.client = :client AND u INSTANCE OF ' . $type_class); + $query->setParameter('client', $Customer); + $PrestaList = $query->getResult();*/ - $repository = self::$entityManager->getRepository('Prestation'); - $find_by = ['client' => $Customer->getId()]; - if($type != '') - { - //$find_by['type_presta'] = 'devis'; - } - $PrestaList = $repository->findBy($find_by); + $repository = self::$entityManager->getRepository($type_class); + $PrestaList = $repository->findBy(['client' => $Customer]); // le même tableau avec pour clés les id des objets $PrestaListIdKeys = []; - foreach($PrestaList as $Presta) - { - $id = $Presta->getId(); - $PrestaListIdKeys[$id] = $Presta; + foreach($PrestaList as $Presta){ + $PrestaListIdKeys[$Presta->getId()] = $Presta; } // fenêtre $entrees = []; - foreach($PrestaListIdKeys as $Presta) - { + foreach($PrestaListIdKeys as $Presta){ $id = $Presta->getId(); $entrees[$id][] = $id; $entrees[$id][] = $Presta->getDate(); @@ -252,22 +213,28 @@ abstract class Prestation // choix de l'utilisateur $input = exec($ResultatsRecherchePresta->get()); // $input est l'ID de la prestation - //echo "input = " . $input . "\n"; - if($input == '') - { + if($input == ''){ echo "debug: recherche annulée ou saisie vide\n"; - return 0; + return null; } - else - { + else{ return $PrestaListIdKeys[$input]; } } - - // à mettre plus tard dans une classe mère - private function cleanSpecialChars(string $data): string + + // nettoyage caractères spéciaux: " ` + public function cleanSpecialChars(string $answers): string { - $search = ['"']; - return str_replace($search, '', $data); + $targets = ['"', '`']; + return str_replace($targets, '', $answers); // possibilité que des input deviennent vide + } + + public function answersToArray(string $answers): array|false + { + if($answers === ''){ + echo "erreur: chaîne vide dans answersToArray()\n"; + return false; + } + return explode('|', $answers); } } diff --git a/src/sections/2_service.php b/src/sections/2_service.php index dc16fe8..e2d64f2 100644 --- a/src/sections/2_service.php +++ b/src/sections/2_service.php @@ -5,11 +5,9 @@ function newService(?Client $Client = null): array { - // fenêtres recherche d'un client + // fenêtres $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client['text']); $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client['text'], []); - - // fenêtres $MenuEnregistrement = new ZenityList(ZenitySetup::$menu_enregistrement['text'], ZenitySetup::$menu_enregistrement['entrees']); $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section2']); $FormulaireDevis = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['devis_entrees']); @@ -17,15 +15,16 @@ function newService(?Client $Client = null): array $FormulaireFactureReduit = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['facture_entrees_reduit']); $FormulaireCesu = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['cesu_entrees']); $FormulaireLocation = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['location_entrees']); + $FormulaireNonVendue = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['non_vendue_entrees']); $CommentairePrestation = new ZenityEntry(ZenitySetup::$commentaire_prestation['text']); //$Recapitulatif = new ZenityList(ZenitySetup::$recapitulatif_text, ZenitySetup::$recapitulatif_entrees); // tableau à multiples colonnes $FinSection2 = new ZenityList(ZenitySetup::$fin_section_2['text'], ZenitySetup::$fin_section_2['entrees']); - // -- partie 1: le client -- + // -- partie 1: rechercher un client -- if(!$Client) { - $Client = Client::find($RechercheClient, $ResultatsRechercheClient); // retourne un Client ou 0 + $Client = Client::find($RechercheClient, $ResultatsRechercheClient); //$ResultatsRechercheClient->cleanCommand(); // inutile parce qu'on ne boucle pas dans cette fonction if(!$Client) { @@ -51,69 +50,82 @@ function newService(?Client $Client = null): array echo "debug: annulation à la saisie d'une date\n"; return [2, $Client]; } - - $Presta = new Prestation($Client); - //var_dump($Client);die; - $Presta->setDate($date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]); // 2026-10-17 - + + // formulaire - étape 2/3 switch($choix_niv2) { - // comparaison retour de $MenuEnregistrement->get() avec les noms des entrées du même menu + // comparaison du retour de $MenuEnregistrement->get() avec les noms des entrées du même menu case ZenitySetup::$menu_enregistrement['entrees'][0]: // "Devis" - $PrestaDetails = new Devis($Presta); - $Presta->setTypePresta('devis'); + $Presta = new Devis($Client); $answers = exec($FormulaireDevis->get()); break; case ZenitySetup::$menu_enregistrement['entrees'][1]: // "Facture" - $PrestaDetails = new Facture($Presta); - $Presta->setTypePresta('facture'); + $Presta = new Facture($Client, false); $answers = exec($FormulaireFacture->get()); break; case ZenitySetup::$menu_enregistrement['entrees'][2]: // "Facture à partir d'un devis" - // recherche du devis - $Quotation = Prestation::getServices($Client, 'devis'); // rechercher un devis, type 'devis' spécifié - if(!is_object($Quotation) || get_class($Quotation) != 'Prestation' || $Quotation->getTypePresta() != 'devis') - { + $Quotation = Prestation::getServices($Client, Devis::class); + if(!is_object($Quotation) || $Quotation->getTypePresta() != 'devis'){ echo "debug: annulation sélection client\n"; return [2, $Client]; // menu précédent } - $QuotationDetails = Devis::getQuotation($Quotation); - $PrestaDetails = new Facture($Presta); - $PrestaDetails->hydrateWithQuotation($QuotationDetails); // du devis à la facture - $Presta->setTypePresta('facture'); + $Presta = new Facture($Client, true); // true = à partir d'un devis + $Presta->hydrateWithQuotation($Quotation); // du devis à la facture $answers = exec($FormulaireFactureReduit->get()); break; case ZenitySetup::$menu_enregistrement['entrees'][3]: // "CESU" - $PrestaDetails = new CESU($Presta); - $Presta->setTypePresta('cesu'); + $Presta = new CESU($Client); $answers = exec($FormulaireCesu->get()); break; case ZenitySetup::$menu_enregistrement['entrees'][4]: // "Location" - $PrestaDetails = new Location($Presta); - $Presta->setTypePresta('location'); + $Presta = new Location($Client); $answers = exec($FormulaireLocation->get()); break; case ZenitySetup::$menu_enregistrement['entrees'][5]: // "Prestation non vendue" - $Presta->setTypePresta('non_vendue'); + $Presta = new NonVendue($Client); + $answers = exec($FormulaireNonVendue->get()); break; default: // inutile normallement, cas déjà géré avant echo "debug: sortie du menu enregistrement incorrect\n"; return [0, null]; } + $Presta->setDate($date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]); // 2026-10-17 //$Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre //$Presta->makeCodePresta($Client->getCodeClient()); // d'un objet à l'autre $Presta->setCodePresta(1); // d'un objet à l'autre + + if($Presta->getTypePresta() !== 'devis'){ + $Client->setType('client'); // changer prospect en client + } + + $answers = $Presta->cleanSpecialChars($answers); + + $data_array = $Presta->answersToArray($answers); + if(!$data_array){ // annulation + echo "debug: annulation lors de l'enregistrement des détails de la prestation\n"; + return [0, null]; + } + + // attention risque d'erreur! les données n'ont pas de d'identifiant! + // leur ordre et leur nombre permettent d'insérer la bonne info au bon endroit + // toute modif du modèle ou d'un formulaire doit être répèrcutée ici + if(!$Presta->validateForm($data_array)){ + echo "erreur: les données du formulaire sont incompatibles avec le modèle\n"; + return [0, null]; + } + + // hydratation avec la saisie du formulaire + $Presta->hydrate($data_array); // commentaire - étape 3/3 $comment = exec($CommentairePrestation->get()); - if($comment == '') - { + if($comment == ''){ echo "debug: pas de commentaire saisi\n"; - // on n'interrompt pas le script et on enregistre dans tous les cas (annulatation comprise) + // on n'interrompt pas le script et on enregistre dans tous les cas (annulation comprise) } - // Cliquer sur annuler (ou appuyer sur échap) revient dont à valider avec une chaîne vide et enregistrer la prestation + // Cliquer sur annuler (ou appuyer sur échap) revient donc à valider avec une chaîne vide et enregistrer la prestation // la commande 'echo $?' ($? est le code de sortie de la commande précédente) renvoit 1 si on annule avec la touche échap () // elle renvoit 0 si la fenêtre est fermée correctement, qu'on valide une chaîne vide ou qu'on clique sur Annuler (on ne peut pas savoir) // malheureusement, si les deux commandes sont liées par un '&&' et qu'on annule la saisie, la 2è commande n'est pas exécutée @@ -125,31 +137,11 @@ function newService(?Client $Client = null): array //~ return 0; //~ } $Presta->setCommentaires($comment); - - // hydratation avec la saisie du formulaire - if($choix_niv2 != ZenitySetup::$menu_enregistrement['entrees'][5]) // cas: tous les cas sauf presta non vendue - { - //var_dump($answers); - if($Presta->getTypePresta() !== 'devis'){ - $Client->setType('client'); - } - if($answers == '') // annulation - { - echo "debug: annulation lors de l'enregistrement des détails de la prestation\n"; - return [0, null]; - } - $PrestaDetails->hydrate($answers); - - // déléguer la synchronisation (flush) avec la BDD à une classe "Manager" - } - - // si encore de type prospect, devient un type client - // déjà fait ailleurs je crois! - /*if($Client->typeToClient()) // utile si $Client est renvoyé dans le "return" - { - $Client->updateOneValue('type', 'client'); // base synchronisée - }*/ - + + // enregistrement + // déléguer la synchronisation (flush) avec la BDD à une classe "Manager"? + Prestation::$entityManager->persist($Presta); + Prestation::$entityManager->flush(); // -- partie 3: LaTeX -- @@ -162,9 +154,8 @@ function newService(?Client $Client = null): array $EnveloppeRecto->setData($Client); $EnveloppeRecto->makeLatex(); $EnveloppeVerso->makeLatex(); - if($DocumentPresta !== null) - { - $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); + if($DocumentPresta !== null){ // facture, devis ou location + $DocumentPresta->setData($Client)->setData($Presta); $DocumentPresta->makeLatex(); } @@ -172,8 +163,7 @@ function newService(?Client $Client = null): array $EnveloppeRecto->makeTexAndPdf(); $EnveloppeVerso->makeTexAndPdf(); - if($DocumentPresta !== null) - { + if($DocumentPresta !== null){ $DocumentPresta->makeTexAndPdf(); } diff --git a/src/sections/3-1_windows.php b/src/sections/3-1_windows.php index 76d01dd..152c3d3 100644 --- a/src/sections/3-1_windows.php +++ b/src/sections/3-1_windows.php @@ -22,12 +22,12 @@ function makeModifyCustomerWindow(Client $Customer): ZenityList $entries[$i][] = ''; //~ $entries[$i][] = ZenitySetup::$modification_client['return']; //~ $entries[$i][] = ''; - $ModifyCustomer->setListRows($entries, 2, 2.5); + $ModifyCustomer->setListRows($entries, 2, 2.5); return $ModifyCustomer; } -function makeModifyServiceWindow(Prestation $Service, $ServiceDetails = null): ZenityList +function makeModifyServiceWindow(Prestation $Service): ZenityList { // fenêtre $ModifyService = new ZenityList(ZenitySetup::$modification_presta['text'], []); @@ -42,31 +42,7 @@ function makeModifyServiceWindow(Prestation $Service, $ServiceDetails = null): Z $entrees[$i][] = $value; $i++; } - - if(is_object($ServiceDetails)) - { - $presta_data = $ServiceDetails->getAllWithWindowFields(); - //var_dump($presta_data); - foreach($presta_data as $key => $value) - { - $entrees[$i][] = $key; - $entrees[$i][] = $value; - $i++; - } - } - - //~ if($Service->getTypePresta() === 'devis') - //~ { - //~ $entrees[$i][] = ZenitySetup::$modification_presta['devis_facture']; // option créer une facture à partir du devis - //~ $entrees[$i][] = ''; - //~ } - - //~ $entrees[$i][] = ZenitySetup::$modification_presta['service']; - //~ $entrees[$i][] = ''; - //~ $i++; - //~ $entrees[$i][] = ZenitySetup::$modification_presta['return']; - //~ $entrees[$i][] = ''; - + $ModifyService->setListRows($entrees, 2, 2.5); return $ModifyService; } diff --git a/src/sections/3_modify_data.php b/src/sections/3_modify_data.php index d70c7d6..5651ed3 100644 --- a/src/sections/3_modify_data.php +++ b/src/sections/3_modify_data.php @@ -7,16 +7,14 @@ require('3-1_windows.php'); function modifyData(?Client $Client = null): array { - // -- partie 1: rechercher un client -- - - // fenêtres statiques - // recherche d'un client + // fenêtres $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client['text']); $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client['text'], []); - // modification de données $TypeDeClient = new ZenityList(ZenitySetup::$type_client['text'], ZenitySetup::$type_client['entrees']); $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section3']); + + // -- partie 1: rechercher un client -- if(!$Client) { $Client = Client::find($RechercheClient, $ResultatsRechercheClient); @@ -93,120 +91,72 @@ function modifyData(?Client $Client = null): array // -- partie 3: rechercher une prestation -- - $Presta = Prestation::getServices($Client); // = 0 ou type "Prestation" + $Presta = Prestation::getServices($Client); if(!is_object($Presta) || !get_class($Presta) == 'Prestation') { echo "debug: annulation sélection d'une prestation\n"; return [3, $Client]; // menu précédent } $type_presta = $Presta->getTypePresta(); - $classe = ''; - switch($type_presta){ - case 'facture': - $classe = 'Facture'; - break; - case 'devis': - $classe = 'Devis'; - break; - case 'cesu': - $classe = 'CESU'; - break; - case 'location': - $classe = 'Location'; - break; - case 'non_vendue': - $PrestaDetails = null; - break; - default: - echo "erreur: type de prestation buggué\n"; - } - if($type_presta != 'non_vendue') - { - $repository = $classe::$entityManager->getRepository($classe); - $PrestaDetails = $repository->findOneBy(['presta' => $Presta->getId()]); - } + $classe = match($type_presta){ + 'facture' => Facture::class, + 'devis' => Devis::class, + 'cesu' => CESU::class, + 'location' => Location::class, + 'non_vendue' => NonVendue::class, + }; + + $repository = Prestation::$entityManager->getRepository($classe); + $Presta = $repository->findOneBy(['id' => $Presta->getId()]); // -- partie 4: modifier une prestation -- // fenêtre - $ModificationPrestaMenu = makeModifyServiceWindow($Presta, $PrestaDetails); - + $ModificationPrestaMenu = makeModifyServiceWindow($Presta); $choix_niv3 = exec($ModificationPrestaMenu->get()); - - if($choix_niv3 === 'Date:') - { + if($choix_niv3 === 'Date:'){ $date_array = explode('/', exec($Calendrier->get())); // 17/10/2026 if(count($date_array) === 1){ echo "debug: annulation à la saisie d'une date\n"; return [3, $Client]; } - - // entités et BDD - $Presta->set($choix_niv3, $date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]); // 2026-10-09 - $old_code = $Presta->getCodePresta(); - $Presta->setCodePresta(0); - $Presta::$entityManager->flush(); - - // documents - if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location') - { - $DocumentPresta = Latex::makeInstance($Presta->getTypePresta()); // $type = facture, devis, location - $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); - $DocumentPresta->makeLatex(); // en mémoire - - File::renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); - $DocumentPresta->makeTexAndPdf(); // une nouvelle facture est créée, supprimer l'ancienne ou la renommer avec la nouvelle date - } - - return [3, $Client]; // menu précédent + $input = $date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]; // 2026-10-17 } //~ elseif($choix_niv3 === 'Type de Presta:') // compliqué! choix impossible pour le moment //~ { //~ echo "choix: changer le type de prestation (devis, facture, etc)\n"; //~ return [3, $Client]; // menu "client" //~ } - elseif(is_string($choix_niv3) && $choix_niv3 != '') // modifier une valeur - { + elseif(is_string($choix_niv3) && $choix_niv3 != ''){ // modifier une valeur echo "choix: modifier " . $choix_niv3 . "\n"; $ModificationPrestaForm = new ZenityEntry($choix_niv3); $input = shell_exec($ModificationPrestaForm->get()); // shell_exec() retourne null si la commande échoue, exec() retourne la dernière ligne de texte en sortie ou null si aucune commande ne réussit - if(is_string($input)) // chaîne vide autorisée - { - // entités et BDD - $Presta->set($choix_niv3, $input); - $old_code = $Presta->getCodePresta(); - $Presta->setCodePresta(0); - if($type_presta != 'non_vendue') - { - $PrestaDetails->set($choix_niv3, $input); - $PrestaDetails::$entityManager->flush(); - } - else - { - $Presta::$entityManager->flush(); - } - - // documents - if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location') - { - $DocumentPresta = Latex::makeInstance($type_presta); - $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); // polymorphisme - $DocumentPresta->makeLatex(); - - File::renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); - $DocumentPresta->makeTexAndPdf(); - } - } - else - { + if(!is_string($input)){ // chaîne vide autorisée echo "choix: annulation\n"; + return [3, $Client]; // menu précédent } - return [3, $Client]; // menu précédent } - else // annuler - { + else{ echo "annulation: retour au menu précédent\n"; return [3, $Client]; // menu précédent } + + // entités et BDD + $Presta->set($choix_niv3, $input); + $old_code = $Presta->getCodePresta(); + $Presta->setCodePresta(0); + $Presta::$entityManager->flush(); + + // documents + if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location'){ + $DocumentPresta = Latex::makeInstance($type_presta); + $DocumentPresta->setData($Client)->setData($Presta); + $DocumentPresta->makeLatex(); + + File::renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); + $DocumentPresta->makeTexAndPdf(); + } + + return [3, $Client]; // menu précédent } diff --git a/src/view/ZenitySetup.php b/src/view/ZenitySetup.php index 956c4f0..2a36f87 100644 --- a/src/view/ZenitySetup.php +++ b/src/view/ZenitySetup.php @@ -31,7 +31,8 @@ class ZenitySetup 'facture_entrees' => ["Tâches effectuées:", "Modèle du PC:", "OS:", "Données sauvegardées:", "Clés d\'activation:", "Total main d\'oeuvre (euros):", "Détail des pièces:", "Total pièces (euros):", "Déplacement (euros)", "Total HT (euros):", "Mode de paiement:"], 'facture_entrees_reduit' => ["Modèle du PC:", "OS:", "Données sauvegardées:", "Clés d\'activation:", "Mode de paiement:"], 'cesu_entrees' => ["Tâches effectuées:", "Duree de travail:", "Salaire net:", "Mode de paiement:"], // en fait je pourrais ajouter plein d'autres trucs - 'location_entrees' => ["Désignation du bien:", "Modèle, numéro de série, description:", "Valeur:", "État des lieux du début:", "Durée de la location en semaines:", "Loyer hebdomadaire:", "Nombre de loyers déjà payés:", "Montant du chèque de caution:"]]; + 'location_entrees' => ["Désignation du bien:", "Modèle, numéro de série, description:", "Valeur:", "État des lieux du début:", "Durée de la location en semaines:", "Loyer hebdomadaire:", "Nombre de loyers déjà payés:", "Montant du chèque de caution:"], + 'non_vendue_entrees' => ["Tâches effectuées:"]]; static public $commentaire_prestation = ['text' => 'Nouvelle prestation 3/3 - Commentaires']; static public $modification_client = ['text' => 'Modifier une information concernant un client', 'service' => "Modifier une prestation"]; diff --git "a/\303\240 faire.txt" "b/\303\240 faire.txt" index 15275a9..7f2279e 100644 --- "a/\303\240 faire.txt" +++ "b/\303\240 faire.txt" @@ -1,12 +1,18 @@ À FAIRE: -Prestations classe abstraite + héritage? +faire autre chose de ZenitySetup, passer fonctions en paramètres + +améliorer les validateForm() calcul correct des code presta si une ancienne facture est modifiée permettre de modifier le code_presta dans "Modifier une prestation" une classe CodePresta? structure BDD en anglais +appli toute en anglais + +pouvoir retyper une presta? +de facture à non vendue en cas d'impayé par exemple champ "date_bulletin_paie" dans la table cesu @@ -32,8 +38,6 @@ relier ZenitySetup et les fonctions getAllWithWindowFileds() changer les fichiers dans "pub" -factoriser la partie 4 dans 3_modify_data.php - src/dependances.php: tester les dépendances de texlive erreur de bash avec zenity: > -- cgit v1.2.3