summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2026-10-20 21:49:17 +0200
committerpolo <ordipolo@gmx.fr>2026-10-20 21:49:17 +0200
commitb0f06b1d7dc3a790d6d8babe5f0855c08c5f7878 (patch)
treebbaea156e9d32edf14adad8fe5ce3338014e7710
parent79bc73d7985f51f2a6a1b3cb6e0115f59afb2ac4 (diff)
downloadAppliGestionPHP-b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878.tar.gz
AppliGestionPHP-b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878.tar.bz2
AppliGestionPHP-b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878.zip
mise en place de l'héritage 2, nombreuses simplifications et factorisations
-rw-r--r--src/Latex.php22
-rw-r--r--src/latex_templates/devis.php2
-rw-r--r--src/latex_templates/facture.php2
-rw-r--r--src/latex_templates/location.php2
-rw-r--r--src/main.php7
-rw-r--r--src/model/entities/CESU.php71
-rw-r--r--src/model/entities/Devis.php98
-rw-r--r--src/model/entities/Facture.php113
-rw-r--r--src/model/entities/Location.php63
-rw-r--r--src/model/entities/NonVendue.php32
-rw-r--r--src/model/entities/Prestation.php139
-rw-r--r--src/sections/2_service.php114
-rw-r--r--src/sections/3-1_windows.php30
-rw-r--r--src/sections/3_modify_data.php128
-rw-r--r--src/view/ZenitySetup.php3
-rw-r--r--à faire.txt10
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
14 14
15 static function makeInstance(string $type): ?Latex 15 static function makeInstance(string $type): ?Latex
16 { 16 {
17 switch($type) 17 switch($type){
18 {
19 // documents pour les clients 18 // documents pour les clients
20 case 'devis': 19 case 'devis':
21 return new DevisLatex; 20 return new DevisLatex;
@@ -120,9 +119,10 @@ abstract class Latex
120 //~ $this->pdf_path = $pdf_path; 119 //~ $this->pdf_path = $pdf_path;
121 //~ } 120 //~ }
122 121
123 public function setData(Object $Object) 122 public function setData(Object $Object): Latex
124 { 123 {
125 $this->data = array_merge($this->data, $Object->getAll()); // nécessite des tableaux associatifs 124 $this->data = array_merge($this->data, $Object->getAll()); // nécessite des tableaux associatifs
125 return $this; // pour chainer les méthodes
126 } 126 }
127} 127}
128 128
@@ -134,9 +134,11 @@ abstract class PrestaLatex extends Latex
134 public function setData(Object $Object): Latex // polymorphisme 134 public function setData(Object $Object): Latex // polymorphisme
135 { 135 {
136 $this->data = array_merge($this->data, $Object->getAll()); // nécessite des tableaux associatifs 136 $this->data = array_merge($this->data, $Object->getAll()); // nécessite des tableaux associatifs
137 137 if(isset($this->data['date'])){
138 if(get_class($Object) === 'Prestation') 138 $this->data['date'] = str_replace('-', '/', $this->data['date']); // 17/10/2026, avec des / parce que j'aime bien
139 { 139 }
140
141 if(in_array(get_class($Object), ['Facture', 'Devis', 'Location'])){
140 $this->file_name = $Object->getCodePresta() . '.tex'; 142 $this->file_name = $Object->getCodePresta() . '.tex';
141 $this->date_array = explode('-', $Object->getdate()); 143 $this->date_array = explode('-', $Object->getdate());
142 $this->latex_path = Config::$latex_path . $this->date_array[0] . DIRECTORY_SEPARATOR; 144 $this->latex_path = Config::$latex_path . $this->date_array[0] . DIRECTORY_SEPARATOR;
@@ -152,10 +154,10 @@ abstract class PrestaLatex extends Latex
152 //~ $this->fileName = $quoi . '-' . $codePresta . '.tex'; 154 //~ $this->fileName = $quoi . '-' . $codePresta . '.tex';
153 //~ } 155 //~ }
154 156
155 public function makeLatex() 157 public function makeLatex(): void
156 { 158 {
157 $data = $this->data; 159 $data = $this->data;
158 $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 160 //$date = preg_replace('#\D#', '/', $this->date_array[2] . '/' . $this->date_array[1] . '/' . $this->date_array[0]);
159 161
160 // on obtient la variable $latex avec ob_get_clean() 162 // on obtient la variable $latex avec ob_get_clean()
161 // le include() ici, c'est du génie ou c'est moche ou les deux? 163 // le include() ici, c'est du génie ou c'est moche ou les deux?
@@ -189,11 +191,13 @@ class EnveloppeRectoLatex extends Latex
189 $this->pdf_path = Config::$pdf_path . 'enveloppes_recto/'; 191 $this->pdf_path = Config::$pdf_path . 'enveloppes_recto/';
190 } 192 }
191 193
192 public function setData(Object $Client) // ici de type Clients 194 public function setData(Object $Client): Latex // ici de type Clients
193 { 195 {
194 $this->file_name = $Client->getCodeClient() . '.tex'; 196 $this->file_name = $Client->getCodeClient() . '.tex';
195 $this->data = array_merge($this->data, $Client->getAll()); // nécessite des tableaux associatifs 197 $this->data = array_merge($this->data, $Client->getAll()); // nécessite des tableaux associatifs
196 $this->spacesInPostCode(); // nécessite $this->data 198 $this->spacesInPostCode(); // nécessite $this->data
199
200 return $this; // pour chainer les méthodes
197 } 201 }
198 202
199 // code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0 203 // 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();
69 69
70 \begin{tabularx}{\linewidth}{@{}X@{}@{}X@{}} 70 \begin{tabularx}{\linewidth}{@{}X@{}@{}X@{}}
71 Mme, M : \textcolor{vert}{<?= $data['prenom_nom'] ?>} & 71 Mme, M : \textcolor{vert}{<?= $data['prenom_nom'] ?>} &
72 Date du devis : \textcolor{vert}{<?= $date ?>}\\ 72 Date du devis : \textcolor{vert}{<?= $data['date'] ?>}\\
73 \end{tabularx}\\ 73 \end{tabularx}\\
74 Adresse : \textcolor{vert}{<?php echo($data['adresse'] . ', ' . $data['code_postal'] . ' ' . $data['ville']); ?>}\\ 74 Adresse : \textcolor{vert}{<?php echo($data['adresse'] . ', ' . $data['code_postal'] . ' ' . $data['ville']); ?>}\\
75 \begin{tabularx}{\linewidth}{@{}X@{}@{}X@{}} 75 \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();
61 61
62 \begin{tabularx}{\linewidth}{@{}X@{}@{}X@{}} 62 \begin{tabularx}{\linewidth}{@{}X@{}@{}X@{}}
63 Mme, M : \textcolor{vert}{<?= $data['prenom_nom'] ?>} & 63 Mme, M : \textcolor{vert}{<?= $data['prenom_nom'] ?>} &
64 Date : \textcolor{vert}{<?= $date ?>}\\ 64 Date : \textcolor{vert}{<?= $data['date'] ?>}\\
65 \end{tabularx}\\ 65 \end{tabularx}\\
66 Adresse : \textcolor{vert}{<?php echo($data['adresse'] . ', ' . $data['code_postal'] . ' ' . $data['ville']); ?>}\\ 66 Adresse : \textcolor{vert}{<?php echo($data['adresse'] . ', ' . $data['code_postal'] . ' ' . $data['ville']); ?>}\\
67 67
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();
79 \textbf{Le bénéficiaire de cette location s’engage à prendre soin du bien désigné et à en faire un usage strictement personnel.}\\ 79 \textbf{Le bénéficiaire de cette location s’engage à prendre soin du bien désigné et à en faire un usage strictement personnel.}\\
80 80
81 \begin{tabularx}{\linewidth}{@{}X@{}@{}X@{}} 81 \begin{tabularx}{\linewidth}{@{}X@{}@{}X@{}}
82 Fait en deux exemplaires à : \textcolor{vert}{<?= Config::$business_city ?>} & le : \textcolor{vert}{<?= $date ?>} \\ 82 Fait en deux exemplaires à : \textcolor{vert}{<?= Config::$business_city ?>} & le : \textcolor{vert}{<?= $data['date'] ?>} \\
83 \end{tabularx}\\ 83 \end{tabularx}\\
84 84
85 \begin{tabularx}{\linewidth}{@{}X@{}@{}X@{}} 85 \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
28require 'src/model/doctrine-bootstrap.php'; // contient aussi un autoloader spécial pour les entités 28require 'src/model/doctrine-bootstrap.php'; // contient aussi un autoloader spécial pour les entités
29// le require_once 'vendor/autoload.php'; doit être situé AVANT cette ligne pour être exécuté en second 29// le require_once 'vendor/autoload.php'; doit être situé AVANT cette ligne pour être exécuté en second
30 30
31// utiliser plus tard de nouvelles classes Manager au lieu des entités 31// $entityManager accessible partout (posibilité d'une classe Manager gérant ça et faisant les flush)
32// ET les faire hériter d'un unique parent
33Client::$entityManager = $entityManager; 32Client::$entityManager = $entityManager;
34Prestation::$entityManager = $entityManager; 33Prestation::$entityManager = $entityManager;
35Devis::$entityManager = $entityManager;
36Facture::$entityManager = $entityManager;
37CESU::$entityManager = $entityManager;
38Location::$entityManager = $entityManager;
39 34
40require 'src/functions.php'; 35require 'src/functions.php';
41//~ require 'src/view/Zenity.php'; // générer ler commandes système zenity 36//~ 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 @@
2// src/entities/CESU.php 2// src/entities/CESU.php
3 3
4use Doctrine\ORM\Mapping as ORM; 4use Doctrine\ORM\Mapping as ORM;
5use Doctrine\ORM\EntityManager;
6 5
7#[ORM\Entity] 6#[ORM\Entity]
8#[ORM\Table(name: 'cesu')] 7#[ORM\Table(name: 'cesu')]
@@ -18,17 +17,7 @@ class CESU extends Prestation
18 /*#[ORM\Column]*/ // pour plus tard 17 /*#[ORM\Column]*/ // pour plus tard
19 private ?string $date_bulletin_paie = null; // format Y-m-d conservé tout du long: formulaire, BDD, affichage 18 private ?string $date_bulletin_paie = null; // format Y-m-d conservé tout du long: formulaire, BDD, affichage
20 19
21 public static EntityManager $entityManager;
22
23 public function __construct(?Prestation $presta = null){
24 $this->setPresta($presta);
25 }
26
27 // getters 20 // getters
28 public function getPresta(): ?Prestation
29 {
30 return $this->presta;
31 }
32 public function getSalaire(): float 21 public function getSalaire(): float
33 { 22 {
34 return $this->salaire; 23 return $this->salaire;
@@ -41,14 +30,15 @@ class CESU extends Prestation
41 30
42 public function getAllWithWindowFields(): array 31 public function getAllWithWindowFields(): array
43 { 32 {
44 return [ 33 $common_data = parent::getAllWithWindowFields();
34 return array_merge($common_data, [
45 "Tâche effectuée:" => $this->taches, 35 "Tâche effectuée:" => $this->taches,
46 "Durée du travail:" => $this->duree_travail, 36 "Durée du travail:" => $this->duree_travail,
47 "Salaire:" => $this->salaire]; 37 "Salaire:" => $this->salaire]);
48 } 38 }
49 39
50 // setters 40 // setters
51 public function set(string $entry, string $input) 41 public function set(string $entry, string $input): void
52 { 42 {
53 $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide 43 $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide
54 switch($entry) 44 switch($entry)
@@ -62,11 +52,9 @@ class CESU extends Prestation
62 case "Salaire:": 52 case "Salaire:":
63 $this->setSalaire($input); 53 $this->setSalaire($input);
64 break; 54 break;
65 } 55 default: // gérer les champ dans Prestation
66 } 56 parent::set($entry, $input);
67 private function setPresta(Prestation $input): void 57 }
68 {
69 $this->presta = $input;
70 } 58 }
71 public function setTaches(string $value): CESU 59 public function setTaches(string $value): CESU
72 { 60 {
@@ -78,7 +66,7 @@ class CESU extends Prestation
78 $this->duree_travail = $value; 66 $this->duree_travail = $value;
79 return($this); 67 return($this);
80 } 68 }
81 public function setSalaire($value): CESU 69 public function setSalaire(string $value): CESU
82 { 70 {
83 $value = str_replace(',', '.', $value); 71 $value = str_replace(',', '.', $value);
84 $this->salaire = (float) $value; 72 $this->salaire = (float) $value;
@@ -97,38 +85,23 @@ class CESU extends Prestation
97 $this->salaire = (float)$input[2]; 85 $this->salaire = (float)$input[2];
98 } 86 }
99 87
100 // à mettre plus tard dans une classe mère 88 public function validateForm(array $data_array): bool
101 protected function cleanSpecialChars(string $data): string
102 {
103 $search = ['"'];
104 return str_replace($search, '', $data);
105 }
106 // à mettre plus tard dans une classe mère
107 public function hydrate(string $answers): void
108 { 89 {
109 $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide 90 if(count($data_array) === 4){
110 if($answers == '') 91 return true;
111 {
112 echo "erreur de CESU::hydrate(), la chaine \$answers est vide.\n";
113 return;
114 }
115 $data_array = explode('|', $answers); // array
116
117 if(count($data_array) === 4) // facture normale
118 {
119 $this->getPresta()->setModePaiement($data_array[3]);
120 //array_pop($data_array); // supprime la dernière case
121 unset($data_array[3]);
122 $this->setAll($data_array);
123 } 92 }
124 else 93 else{
125 { 94 echo "erreur de CESU::validateForm(), le tableau \$data_array n'a pas la taille attendue.\n";
126 echo "erreur de CESU::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; 95 return false;
127 return;
128 } 96 }
97 }
129 98
130 //self::$entityManager->persist('Prestation'); 99 // à mettre plus tard dans une classe mère
131 self::$entityManager->persist($this); // $Presta avec en cascade! 100 public function hydrate(array $data_array): void
132 self::$entityManager->flush(); 101 {
102 $this->setModePaiement($data_array[3]);
103 //array_pop($data_array); // supprime la dernière case
104 unset($data_array[3]);
105 $this->setAll($data_array);
133 } 106 }
134} 107}
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 @@
2// src/entities/Devis.php 2// src/entities/Devis.php
3 3
4use Doctrine\ORM\Mapping as ORM; 4use Doctrine\ORM\Mapping as ORM;
5use Doctrine\ORM\EntityManager;
6 5
7#[ORM\Entity] 6#[ORM\Entity]
8#[ORM\Table(name: 'devis')] 7#[ORM\Table(name: 'devis')]
@@ -29,17 +28,7 @@ class Devis extends Prestation
29 #[ORM\Column (options: ['default' => 'non'])] // défaut dans le cas d'un requête SQL ignorant ce champ 28 #[ORM\Column (options: ['default' => 'non'])] // défaut dans le cas d'un requête SQL ignorant ce champ
30 private string $signature_devis = 'non'; 29 private string $signature_devis = 'non';
31 30
32 public static EntityManager $entityManager;
33
34 public function __construct(?Prestation $presta = null){
35 $this->setPresta($presta);
36 }
37
38 // getters 31 // getters
39 public function getPresta(): Prestation
40 {
41 return $this->presta;
42 }
43 public function getAll(): array 32 public function getAll(): array
44 { 33 {
45 // n'utiliser get_object_vars() qu'avec une entité parce qu'on maîtrise le nombre de propriétés 34 // 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
48 37
49 public function getAllWithWindowFields(): array 38 public function getAllWithWindowFields(): array
50 { 39 {
51 //~ $taches = ["Tâches:" => $this->taches]; 40 $common_data = parent::getAllWithWindowFields();
52 //~ $champs_communs = [ 41 return array_merge($common_data, [
53 //~ "Total Main d'oeuvre:" => $this->total_main_d_oeuvre,
54 //~ "Pièces:" => $this->pieces,
55 //~ "Total des pièces:" => $this->total_pieces,
56 //~ "Déplacement:" => $this->deplacement,
57 //~ "Total HT:" => $this->total_HT];
58 //~ $champs_devis = [
59 //~ "Delai de livraison:" => $this->delai_livraison,
60 //~ "Durée de validité:" => $this->validite_devis,
61 //~ "Devis signé:" => $this->signature_devis];
62 //~ return $champs_communs + $champs_devis;
63 return [
64 "Tâches:" => $this->taches, // JUSTE AJOUTÉ 42 "Tâches:" => $this->taches, // JUSTE AJOUTÉ
65 "Total Main d'oeuvre:" => $this->total_main_d_oeuvre, 43 "Total Main d'oeuvre:" => $this->total_main_d_oeuvre,
66 "Pièces:" => $this->pieces, 44 "Pièces:" => $this->pieces,
@@ -70,11 +48,11 @@ class Devis extends Prestation
70 "Total HT:" => $this->total_HT, 48 "Total HT:" => $this->total_HT,
71 "Delai de livraison:" => $this->delai_livraison, 49 "Delai de livraison:" => $this->delai_livraison,
72 "Durée de validité:" => $this->validite_devis, 50 "Durée de validité:" => $this->validite_devis,
73 "Devis signé:" => $this->signature_devis]; 51 "Devis signé:" => $this->signature_devis]);
74 } 52 }
75 53
76 // setters 54 // setters
77 public function set(string $entry, string $input) // trouve la bonne méthode 55 public function set(string $entry, string $input): void // trouve la bonne méthode
78 { 56 {
79 $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide 57 $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide
80 switch($entry) 58 switch($entry)
@@ -109,41 +87,39 @@ class Devis extends Prestation
109 case "Devis signé:": 87 case "Devis signé:":
110 $this->setSignatureDevis($input); 88 $this->setSignatureDevis($input);
111 break; 89 break;
90 default: // gérer les champ dans Prestation
91 parent::set($entry, $input);
112 } 92 }
113 } 93 }
114 private function setPresta(Prestation $input) // private? 94 public function setTaches(string $value): Devis
115 {
116 $this->presta = $input;
117 }
118 public function setTaches(string $value)
119 { 95 {
120 $this->taches = $value; 96 $this->taches = $value;
121 return($this); 97 return($this);
122 } 98 }
123 public function setTotalMainDOeuvre($value) 99 public function setTotalMainDOeuvre(string $value): Devis
124 { 100 {
125 $value = str_replace(',', '.', $value); 101 $value = str_replace(',', '.', $value);
126 $this->total_main_d_oeuvre = (float) $value; // float "nettoie" tous les caractères après le dernier chiffre trouvé (ex: 50€ => 50, abc => 0) 102 $this->total_main_d_oeuvre = (float) $value; // float "nettoie" tous les caractères après le dernier chiffre trouvé (ex: 50€ => 50, abc => 0)
127 return($this); 103 return($this);
128 } 104 }
129 public function setPieces(string $value) 105 public function setPieces(string $value): Devis
130 { 106 {
131 $this->pieces = $value; 107 $this->pieces = $value;
132 return($this); 108 return($this);
133 } 109 }
134 public function setTotalPieces($value) 110 public function setTotalPieces(string $value): Devis
135 { 111 {
136 $value = str_replace(',', '.', $value); 112 $value = str_replace(',', '.', $value);
137 $this->total_pieces = (float) $value; 113 $this->total_pieces = (float) $value;
138 return($this); 114 return($this);
139 } 115 }
140 public function setDeplacement($value) 116 public function setDeplacement(string $value): Devis
141 { 117 {
142 $value = str_replace(',', '.', $value); 118 $value = str_replace(',', '.', $value);
143 $this->deplacement = (float) $value; 119 $this->deplacement = (float) $value;
144 return($this); 120 return($this);
145 } 121 }
146 public function setTotalHT($value) 122 public function setTotalHT(string $value): Devis
147 { 123 {
148 $value = str_replace(',', '.', $value); 124 $value = str_replace(',', '.', $value);
149 $this->total_HT = (float) $value; 125 $this->total_HT = (float) $value;
@@ -155,23 +131,23 @@ class Devis extends Prestation
155 $this->prix_devis = (float) $value; 131 $this->prix_devis = (float) $value;
156 return($this); 132 return($this);
157 } 133 }
158 public function setDelaiLivraison(string $value) 134 public function setDelaiLivraison(string $value): Devis
159 { 135 {
160 $this->delai_livraison = $value; 136 $this->delai_livraison = $value;
161 return($this); 137 return($this);
162 } 138 }
163 public function setValiditedevis(string $value) 139 public function setValiditedevis(string $value): Devis
164 { 140 {
165 $this->validite_devis = $value; 141 $this->validite_devis = $value;
166 return($this); 142 return($this);
167 } 143 }
168 public function setSignatureDevis(string $value) 144 public function setSignatureDevis(string $value): Devis
169 { 145 {
170 $this->signature_devis = $value; 146 $this->signature_devis = $value;
171 return($this); 147 return($this);
172 } 148 }
173 149
174 private function setAll(array $input) // private? 150 private function setAll(array $input): void // private?
175 { 151 {
176 $this->taches = $input[0]; 152 $this->taches = $input[0];
177 $this->total_main_d_oeuvre = (float)$input[1]; 153 $this->total_main_d_oeuvre = (float)$input[1];
@@ -186,43 +162,21 @@ class Devis extends Prestation
186 // $signature_devis est renseigné plus tard en modifiant le devis 162 // $signature_devis est renseigné plus tard en modifiant le devis
187 } 163 }
188 164
189 // à mettre plus tard dans une classe mère 165 public function validateForm(array $data_array): bool
190 protected function cleanSpecialChars(string $data): string
191 {
192 $search = ['"'];
193 return str_replace($search, '', $data);
194 }
195 // à mettre plus tard dans une classe mère
196 public function hydrate(string $answers): void
197 { 166 {
198 $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide 167 if(count($data_array) === 9){
199 if($answers == '') 168 return true;
200 {
201 echo "erreur de Devis::hydrate(), la chaine \$answers est vide.\n";
202 return;
203 } 169 }
204 $data_array = explode('|', $answers); // array 170 else{
205 171 echo "erreur de Devis::validateForm(), le tableau \$data_array n'a pas la taille attendue.\n";
206 if(count($data_array) === 9) // facture normale, "=== 9" = merdique 172 return false;
207 {
208 $this->getPresta()->setModePaiement(''); // sécurité, doctrine plante si "null"
209 $this->setAll($data_array);
210 } 173 }
211 else
212 {
213 echo "erreur de Devis::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n";
214 return;
215 }
216
217 //self::$entityManager->persist('Prestation');
218 self::$entityManager->persist($this); // $Presta avec en cascade!
219 self::$entityManager->flush();
220 } 174 }
221 175
222 // création d'une facture à partir d'un devis 176 // à mettre plus tard dans une classe mère
223 public static function getQuotation(Prestation $Quotation) 177 public function hydrate(array $data_array): void
224 { 178 {
225 $repository = self::$entityManager->getRepository('Devis'); 179 //$this->setModePaiement(''); // vaut déjà ''
226 return $repository->findOneBy(['presta' => $Quotation->getId()]); // ne peut y en avoir deux 180 $this->setAll($data_array);
227 } 181 }
228} 182}
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 @@
2// src/entities/Facture.php 2// src/entities/Facture.php
3 3
4use Doctrine\ORM\Mapping as ORM; 4use Doctrine\ORM\Mapping as ORM;
5use Doctrine\ORM\EntityManager;
6 5
7#[ORM\Entity] 6#[ORM\Entity]
8#[ORM\Table(name: 'factures')] 7#[ORM\Table(name: 'factures')]
@@ -29,17 +28,14 @@ class Facture extends Prestation
29 #[ORM\Column] 28 #[ORM\Column]
30 private float $total_HT; 29 private float $total_HT;
31 30
32 public static EntityManager $entityManager; 31 private bool $from_quotation;
33 32
34 public function __construct(?Prestation $presta = null){ 33 public function __construct(Client $client, bool $from_quotation){
35 $this->setPresta($presta); 34 parent::__construct($client);
35 $this->from_quotation = $from_quotation;
36 } 36 }
37 37
38 // getters 38 // getters
39 public function getPresta(): Prestation
40 {
41 return $this->presta;
42 }
43 public function getAll(): array 39 public function getAll(): array
44 { 40 {
45 // n'utiliser get_object_vars() qu'avec une entité parce qu'on maîtrise le nombre de propriétés 41 // 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
60 56
61 public function getAllWithWindowFields(): array 57 public function getAllWithWindowFields(): array
62 { 58 {
63 //~ $taches = ["Tâches:" => $this->taches]; 59 $common_data = parent::getAllWithWindowFields();
64 //~ $champs_facture = [ 60 return array_merge($common_data, [
65 //~ "PC:" => $this->machine,
66 //~ "OS:" => $this->OS,
67 //~ "Données:" => $this->donnees,
68 //~ "Clés de licences:" => $this->cles_licences];
69 //~ $champs_communs = [
70 //~ "Total Main d'oeuvre:" => $this->total_main_d_oeuvre,
71 //~ "Pièces:" => $this->pieces,
72 //~ "Total des pièces:" => $this->total_pieces,
73 //~ "Déplacement:" => $this->deplacement,
74 //~ "Total HT:" => $this->total_HT];
75 //return $taches + $champs_facture + $champs_communs;
76 return [
77 "Tâches:" => $this->taches, 61 "Tâches:" => $this->taches,
78 "PC:" => $this->machine, 62 "PC:" => $this->machine,
79 "OS:" => $this->OS, 63 "OS:" => $this->OS,
@@ -83,11 +67,11 @@ class Facture extends Prestation
83 "Pièces:" => $this->pieces, 67 "Pièces:" => $this->pieces,
84 "Total des pièces:" => $this->total_pieces, 68 "Total des pièces:" => $this->total_pieces,
85 "Déplacement:" => $this->deplacement, 69 "Déplacement:" => $this->deplacement,
86 "Total HT:" => $this->total_HT]; 70 "Total HT:" => $this->total_HT]);
87 } 71 }
88 72
89 // setters 73 // setters
90 public function set(string $entry, string $input) // trouve la bonne méthode 74 public function set(string $entry, string $input): void // trouve la bonne méthode
91 { 75 {
92 $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide 76 $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide
93 switch($entry) 77 switch($entry)
@@ -122,68 +106,66 @@ class Facture extends Prestation
122 case "Total HT:": 106 case "Total HT:":
123 $this->setTotalHT($input); 107 $this->setTotalHT($input);
124 break; 108 break;
109 default: // gérer les champ dans Prestation
110 parent::set($entry, $input);
125 } 111 }
126 } 112 }
127 public function setPresta(Prestation $input) // private? 113 public function setTaches(string $value): Facture
128 {
129 $this->presta = $input;
130 }
131 public function setTaches(string $value)
132 { 114 {
133 $this->taches = $value; 115 $this->taches = $value;
134 return($this); 116 return($this);
135 } 117 }
136 public function setMachine(string $value) 118 public function setMachine(string $value): Facture
137 { 119 {
138 $this->machine = $value; 120 $this->machine = $value;
139 return($this); 121 return($this);
140 } 122 }
141 public function setOS(string $value) 123 public function setOS(string $value): Facture
142 { 124 {
143 $this->OS = $value; 125 $this->OS = $value;
144 return($this); 126 return($this);
145 } 127 }
146 public function setDonnees(string $value) 128 public function setDonnees(string $value): Facture
147 { 129 {
148 $this->donnees = $value; 130 $this->donnees = $value;
149 return($this); 131 return($this);
150 } 132 }
151 public function setClesLicences(string $value) 133 public function setClesLicences(string $value): Facture
152 { 134 {
153 $this->cles_licences = $value; 135 $this->cles_licences = $value;
154 return($this); 136 return($this);
155 } 137 }
156 public function setTotalMainDOeuvre($value) 138 public function setTotalMainDOeuvre(string $value): Facture
157 { 139 {
158 $value = str_replace(',', '.', $value); 140 $value = str_replace(',', '.', $value);
159 $this->total_main_d_oeuvre = (float) $value; // float "nettoie" tous les caractères après le dernier chiffre trouvé (ex: 50€ => 50, abc => 0) 141 $this->total_main_d_oeuvre = (float) $value; // float "nettoie" tous les caractères après le dernier chiffre trouvé (ex: 50€ => 50, abc => 0)
160 return($this); 142 return($this);
161 } 143 }
162 public function setPieces(string $value) 144 public function setPieces(string $value): Facture
163 { 145 {
164 $this->pieces = $value; 146 $this->pieces = $value;
165 return($this); 147 return($this);
166 } 148 }
167 public function setTotalPieces($value) 149 public function setTotalPieces(string $value): Facture
168 { 150 {
169 $value = str_replace(',', '.', $value); 151 $value = str_replace(',', '.', $value);
170 $this->total_pieces = (float) $value; 152 $this->total_pieces = (float) $value;
171 return($this); 153 return($this);
172 } 154 }
173 public function setDeplacement($value) 155 public function setDeplacement(string $value): Facture
174 { 156 {
175 $value = str_replace(',', '.', $value); 157 $value = str_replace(',', '.', $value);
176 $this->deplacement = (float) $value; 158 $this->deplacement = (float) $value;
177 return($this); 159 return($this);
178 } 160 }
179 public function setTotalHT($value) 161 public function setTotalHT(string $value): Facture
180 { 162 {
181 $value = str_replace(',', '.', $value); 163 $value = str_replace(',', '.', $value);
182 $this->total_HT = (float) $value; 164 $this->total_HT = (float) $value;
183 return($this); 165 return($this);
184 } 166 }
185 167
186 private function setAll(array $input) // private? 168 private function setService(array $input): void // private?
187 { 169 {
188 $this->taches = $input[0]; 170 $this->taches = $input[0];
189 $this->machine = $input[1]; 171 $this->machine = $input[1];
@@ -196,7 +178,7 @@ class Facture extends Prestation
196 $this->deplacement = (float)$input[8]; 178 $this->deplacement = (float)$input[8];
197 $this->total_HT = (float)$input[9]; 179 $this->total_HT = (float)$input[9];
198 } 180 }
199 private function setServiceFromQuotation(array $input) // private? 181 private function setServiceFromQuotation(array $input): void // private?
200 { 182 {
201 $this->machine = $input[0]; 183 $this->machine = $input[0];
202 $this->OS = $input[1]; 184 $this->OS = $input[1];
@@ -204,50 +186,39 @@ class Facture extends Prestation
204 $this->cles_licences = $input[3]; 186 $this->cles_licences = $input[3];
205 } 187 }
206 188
207 // à mettre plus tard dans une classe mère 189 public function validateForm(array $data_array): bool
208 protected function cleanSpecialChars(string $data): string
209 { 190 {
210 $search = ['"']; 191 if(!$this->from_quotation && count($data_array) === 11){ // facture normale
211 return str_replace($search, '', $data); 192 return true;
193 }
194 elseif(count($data_array) === 5){ // facture à partir d'un devis
195 return true;
196 }
197 else{
198 echo "erreur de Facture::validateForm(), le tableau \$data_array n'a pas la taille attendue.\n";
199 return false;
200 }
212 } 201 }
202
213 // à mettre plus tard dans une classe mère 203 // à mettre plus tard dans une classe mère
214 public function hydrate(string $answers): void 204 public function hydrate(array $data_array): void
215 { 205 {
216 $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide 206 if(!$this->from_quotation){ // facture normale
217 if($answers == '') 207 $this->setModePaiement($data_array[10]);
218 {
219 echo "erreur de Facture::hydrate(), la chaine \$answers est vide.\n";
220 return;
221 }
222 $data_array = explode('|', $answers); // array
223
224 if(count($data_array) === 11) // facture normale
225 {
226 $this->getPresta()->setModePaiement($data_array[10]);
227 //array_pop($data_array); // supprime la dernière case 208 //array_pop($data_array); // supprime la dernière case
228 unset($data_array[10]); 209 unset($data_array[10]);
229 $this->setAll($data_array); 210 $this->setService($data_array);
230 } 211 }
231 elseif(count($data_array) === 5) // facture à partir d'un devis 212 else{ // facture à partir d'un devis
232 { 213 $this->setModePaiement($data_array[4]);
233 $this->getPresta()->setModePaiement($data_array[4]);
234 unset($data_array[4]); 214 unset($data_array[4]);
235 $this->setServiceFromQuotation($data_array); 215 $this->setServiceFromQuotation($data_array);
236 } 216 }
237 else
238 {
239 echo "erreur de Facture::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n";
240 return;
241 }
242
243 //self::$entityManager->persist('Prestation');
244 self::$entityManager->persist($this); // $Presta avec en cascade!
245 self::$entityManager->flush();
246 } 217 }
247 218
248 public function hydrateWithQuotation(Devis $QuotationDetails) 219 public function hydrateWithQuotation(Devis $Quotation): void
249 { 220 {
250 $data = $QuotationDetails->getAll(); 221 $data = $Quotation->getAll();
251 //var_dump($data);die; 222 //var_dump($data);die;
252 $this->taches = $data['taches']; 223 $this->taches = $data['taches'];
253 $this->total_main_d_oeuvre = $data['total_main_d_oeuvre']; 224 $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 @@
2// src/entities/Location.php 2// src/entities/Location.php
3 3
4use Doctrine\ORM\Mapping as ORM; 4use Doctrine\ORM\Mapping as ORM;
5use Doctrine\ORM\EntityManager;
6 5
7#[ORM\Entity] 6#[ORM\Entity]
8#[ORM\Table(name: 'locations')] 7#[ORM\Table(name: 'locations')]
@@ -27,17 +26,7 @@ class Location extends Prestation
27 #[ORM\Column] 26 #[ORM\Column]
28 protected float $caution; 27 protected float $caution;
29 28
30 public static EntityManager $entityManager;
31
32 public function __construct(?Prestation $presta = null){
33 $this->setPresta($presta);
34 }
35
36 // getters 29 // getters
37 public function getPresta(): Prestation
38 {
39 return $this->presta;
40 }
41 public function getLoyer(): float 30 public function getLoyer(): float
42 { 31 {
43 return $this->loyer_hebdo; 32 return $this->loyer_hebdo;
@@ -54,7 +43,8 @@ class Location extends Prestation
54 43
55 public function getAllWithWindowFields(): array 44 public function getAllWithWindowFields(): array
56 { 45 {
57 return [ 46 $common_data = parent::getAllWithWindowFields();
47 return array_merge($common_data, [
58 "Désignation:" => $this->designation, 48 "Désignation:" => $this->designation,
59 "Description du modèle:" => $this->modele_description, 49 "Description du modèle:" => $this->modele_description,
60 "Valeur:" => $this->valeur, 50 "Valeur:" => $this->valeur,
@@ -63,7 +53,7 @@ class Location extends Prestation
63 "Durée de la location:" => $this->duree_location, 53 "Durée de la location:" => $this->duree_location,
64 "Loyer Hebdomadaire:" => $this->loyer_hebdo, 54 "Loyer Hebdomadaire:" => $this->loyer_hebdo,
65 "Loyers Payés:" => $this->loyers_payes, 55 "Loyers Payés:" => $this->loyers_payes,
66 "Caution:" => $this->caution]; 56 "Caution:" => $this->caution]);
67 } 57 }
68 58
69 // setters 59 // setters
@@ -99,11 +89,9 @@ class Location extends Prestation
99 case "Caution:": 89 case "Caution:":
100 $this->setCaution($input); 90 $this->setCaution($input);
101 break; 91 break;
102 } 92 default: // gérer les champ dans Prestation
103 } 93 parent::set($entry, $input);
104 private function setPresta(Prestation $input): void // private? 94 }
105 {
106 $this->presta = $input;
107 } 95 }
108 public function setDesignation(string $value): Location 96 public function setDesignation(string $value): Location
109 { 97 {
@@ -168,36 +156,21 @@ class Location extends Prestation
168 $this->caution = (int)$input[7]; 156 $this->caution = (int)$input[7];
169 } 157 }
170 158
171 // à mettre plus tard dans une classe mère 159 public function validateForm(array $data_array): bool
172 protected function cleanSpecialChars(string $data): string
173 {
174 $search = ['"'];
175 return str_replace($search, '', $data);
176 }
177 // à mettre plus tard dans une classe mère
178 public function hydrate(string $answers): void
179 { 160 {
180 $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide 161 if(count($data_array) === 8){
181 if($answers == '') 162 return true;
182 {
183 echo "erreur de Location::hydrate(), la chaine \$answers est vide.\n";
184 return;
185 }
186 $data_array = explode('|', $answers); // array
187
188 if(count($data_array) === 8)
189 {
190 $this->getPresta()->setModePaiement(''); // sécurité, doctrine plante si "null"
191 $this->setAll($data_array);
192 } 163 }
193 else 164 else{
194 { 165 echo "erreur de Location::validateForm(), le tableau \$data_array n'a pas la taille attendue.\n";
195 echo "erreur de Location::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; 166 return false;
196 return;
197 } 167 }
168 }
198 169
199 //self::$entityManager->persist('Prestation'); 170 // à mettre plus tard dans une classe mère
200 self::$entityManager->persist($this); // $Presta avec en cascade! 171 public function hydrate(array $data_array): void
201 self::$entityManager->flush(); 172 {
173 //$this->setModePaiement(''); // vaut déjà ''
174 $this->setAll($data_array);
202 } 175 }
203} 176}
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
9{ 9{
10 #[ORM\Column] 10 #[ORM\Column]
11 private string $taches; 11 private string $taches;
12
13 public function getTaches(): string
14 {
15 return $this->taches;
16 }
17 public function getAllWithWindowFields(): array
18 {
19 $common_data = parent::getAllWithWindowFields();
20 return array_merge($common_data, ["Tâches:" => $this->taches,]);
21 }
22 public function setTaches(string $value): NonVendue
23 {
24 $this->taches = $value;
25 return $this;
26 }
27
28 //public function set(string $entry, string $input): void // pas nécessaire ici
29
30 public function validateForm(array $data_array): bool
31 {
32 if(count($data_array) === 1){
33 return true;
34 }
35 else{
36 echo "erreur de NonVendue::validateForm(), le tableau \$data_array n'a pas la taille attendue.\n";
37 return false;
38 }
39 }
40 public function hydrate(array $data_array): void
41 {
42 $this->setTaches($data_array[0]);
43 }
12} \ No newline at end of file 44} \ 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
28 28
29 #[ORM\ManyToOne(targetEntity: Client::class, cascade: ['persist'])] 29 #[ORM\ManyToOne(targetEntity: Client::class, cascade: ['persist'])]
30 #[ORM\JoinColumn(name: 'id_client', referencedColumnName: 'id')] 30 #[ORM\JoinColumn(name: 'id_client', referencedColumnName: 'id')]
31 private ?Client $client = null; // type int en SQL et dans la base 31 private Client $client; // type int en SQL et dans la base
32 #[ORM\Column] 32 #[ORM\Column]
33 private string $code_presta; 33 protected string $code_presta;
34 #[ORM\Column(type: 'string', length: 10)] // format 'aaaa-mm-jj' 34 #[ORM\Column(type: 'string', length: 10)] // format 'aaaa-mm-jj'
35 private string $date; 35 protected string $date;
36 #[ORM\Column] 36 #[ORM\Column]
37 private string $mode_paiement = ''; // non renseigné quand on fait un devis 37 private string $mode_paiement = ''; // non renseigné quand on fait un devis
38 #[ORM\Column] 38 #[ORM\Column]
39 private string $commentaires; 39 private string $commentaires;
40 40
41 public static EntityManager $entityManager; 41 public static EntityManager $entityManager; // inséré dans main.php
42 42
43 public function __construct(?Client $client = null){ 43 public function __construct(Client $client){
44 $this->setClient($client); 44 $this->setClient($client);
45 } 45 }
46 46
@@ -57,10 +57,17 @@ abstract class Prestation
57 { 57 {
58 return $this->date; 58 return $this->date;
59 } 59 }
60 /*public function getTypePresta(): string 60 public function getTypePresta(): string
61 { 61 {
62 return $this->type_presta; 62 return match (true) {
63 }*/ 63 $this instanceof Devis => 'devis',
64 $this instanceof Facture => 'facture',
65 $this instanceof CESU => 'cesu',
66 $this instanceof Location => 'location',
67 $this instanceof NonVendue => 'non_vendue',
68 //default => throw new \LogicException('Type de prestation inconnu'), // impossible
69 };
70 }
64 public function getModePaiement(): string 71 public function getModePaiement(): string
65 { 72 {
66 return $this->mode_paiement; 73 return $this->mode_paiement;
@@ -75,7 +82,7 @@ abstract class Prestation
75 return get_object_vars($this); 82 return get_object_vars($this);
76 } 83 }
77 84
78 public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) 85 public function getAllWithWindowFields(): array // différent de getAll() qui retourne get_object_vars($this)
79 { 86 {
80 return [ 87 return [
81 //"Numéro prestation:" => end($code_presta_tableau), // crée des conflits, calcul automatique par setCodePresta() 88 //"Numéro prestation:" => end($code_presta_tableau), // crée des conflits, calcul automatique par setCodePresta()
@@ -85,31 +92,7 @@ abstract class Prestation
85 "Commentaires:" => $this->commentaires]; 92 "Commentaires:" => $this->commentaires];
86 } 93 }
87 94
88 // une interface pour ça c'est bien aussi non?
89 public function getFacture(): ?Facture
90 {
91 return $this->facture;
92 }
93 public function getDevis(): ?Devis
94 {
95 return $this->devis;
96 }
97 public function getCesu(): ?CESU
98 {
99 return $this->cesu;
100 }
101 public function getLocation(): ?Location
102 {
103 return $this->location;
104 }
105
106 // setters 95 // setters
107 //~ public function setCodePresta(string $value)
108 //~ {
109 //~ $this->code_presta = $value;
110 //~ return $this;
111 //~ }
112 //public function setDate(int $value)
113 public function setDate(string $date): Prestation 96 public function setDate(string $date): Prestation
114 { 97 {
115 $this->date = $date; 98 $this->date = $date;
@@ -125,36 +108,24 @@ abstract class Prestation
125 }*/ 108 }*/
126 } 109 }
127 110
128 /*public function setTypePresta(string $value) // appelée dans la section 2 uniquement, pour la 3 on verra plus tard 111 public function setModePaiement(string $value): Prestation
129 {
130 $this->type_presta = $value;
131 return $this;
132 }*/
133 public function setModePaiement(string $value)
134 { 112 {
135 $this->mode_paiement = $value; 113 $this->mode_paiement = $value;
136 return $this; 114 return $this;
137 } 115 }
138 public function setCommentaires(string $input) 116 public function setCommentaires(string $input): void
139 { 117 {
140 $this->commentaires = $input; 118 $this->commentaires = $input;
141 } 119 }
142 /*public function setAll(array $input) 120 /*public function setAll(array $input)
143 { 121 {}*/
144 $this->code_presta = $input[0];
145 $this->date = $input[1];
146 $this->type_presta = $input[2];
147 $this->mode_paiement = $input[3];
148 $this->commentaires = $input[4];
149 }*/
150 122
151 private function setClient(Client $input) // private? 123 private function setClient(Client $client): void // private?
152 { 124 {
153 $this->client = $input; 125 $this->client = $client;
154 //$input->typeToClient(); // on modifie $client ici (merci les références PHP)
155 } 126 }
156 127
157 /*public function set(string $entry, string $input): void 128 public function set(string $entry, string $input): void
158 { 129 {
159 $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide 130 $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide
160 131
@@ -167,8 +138,7 @@ abstract class Prestation
167 case "Date:": // inutile, setDate() est appelé directement après choix fenêtre calendrier 138 case "Date:": // inutile, setDate() est appelé directement après choix fenêtre calendrier
168 $this->setDate($input); 139 $this->setDate($input);
169 break; 140 break;
170 //~ case "Type de Presta:": // choix impossible pour le moment 141 //~ case "Type de Presta:": // choix impossible pour le moment et pas anodin
171 //~ $this->setTypePresta($input);
172 //~ break; 142 //~ break;
173 case "Mode de paiement:": 143 case "Mode de paiement:":
174 $this->setModePaiement($input); 144 $this->setModePaiement($input);
@@ -177,12 +147,13 @@ abstract class Prestation
177 $this->setCommentaires($input); 147 $this->setCommentaires($input);
178 break; 148 break;
179 } 149 }
180 }*/ 150 }
181 151
182 // code presta = année-mois-jour-codeclient-typedepresta-combientièmefois 152 // code presta = année-mois-jour-codeclient-typedepresta-combientièmefois
183 public function setCodePresta(int $increment): Prestation // 0 pour modif, 1 pour nouvelle presta 153 public function setCodePresta(int $increment): Prestation // 0 pour modif, 1 pour nouvelle presta
184 { 154 {
185 $repository = self::$entityManager->getRepository('Prestation'); // prestas de tout type d'un client 155 $repository = self::$entityManager->getRepository('Prestation');
156
186 // attention: il peut y avoir plusieurs prestations avec le même numéro au compteur, à améliorer 157 // attention: il peut y avoir plusieurs prestations avec le même numéro au compteur, à améliorer
187 $how_many_times = count($repository->findBy(['client' => $this->client->getId()])) + $increment; 158 $how_many_times = count($repository->findBy(['client' => $this->client->getId()])) + $increment;
188 //var_dump($how_many_times); 159 //var_dump($how_many_times);
@@ -192,7 +163,7 @@ abstract class Prestation
192 $date_array[1], // mois 163 $date_array[1], // mois
193 $date_array[2], // jour 164 $date_array[2], // jour
194 $this->client->getCodeClient(), // mise à jour éventuelle 165 $this->client->getCodeClient(), // mise à jour éventuelle
195 //$this->type_presta, 166 $this->getTypePresta(),
196 $how_many_times 167 $how_many_times
197 ]; 168 ];
198 $this->code_presta = implode('-', $array_code); 169 $this->code_presta = implode('-', $array_code);
@@ -208,37 +179,27 @@ abstract class Prestation
208 //~ return $this; 179 //~ return $this;
209 //~ } 180 //~ }
210 181
211 public static function getServices(Client $Customer, string $type = '') 182 public static function getServices(Client $Customer, string $type_class = Prestation::class): ?Prestation // param par défaut = recherche tout type
212 { 183 {
213 echo "debug: recherche d'une prestation\n"; 184 echo "debug: recherche d'une prestation\n";
214 185
215 // requête DQL qui fait la même chose que le findBy plus bas 186 // requête DQL qui fait la même chose que le findBy plus bas
216 /*$query = self::$entityManager->createQuery('SELECT u FROM Prestation u WHERE u.client = :id_client AND u.type_presta = :type_presta'); 187 /*$query = self::$entityManager->createQuery('SELECT u FROM Prestation u WHERE u.client = :client AND u INSTANCE OF ' . $type_class);
217 $query->setParameter('id_client', $Customer->getId()); 188 $query->setParameter('client', $Customer);
218 $query->setParameter('type_presta', $type); 189 $PrestaList = $query->getResult();*/
219 $query_result = $query->getResult();
220 var_dump($query_result);die;*/
221 190
222 $repository = self::$entityManager->getRepository('Prestation'); 191 $repository = self::$entityManager->getRepository($type_class);
223 $find_by = ['client' => $Customer->getId()]; 192 $PrestaList = $repository->findBy(['client' => $Customer]);
224 if($type != '')
225 {
226 //$find_by['type_presta'] = 'devis';
227 }
228 $PrestaList = $repository->findBy($find_by);
229 193
230 // le même tableau avec pour clés les id des objets 194 // le même tableau avec pour clés les id des objets
231 $PrestaListIdKeys = []; 195 $PrestaListIdKeys = [];
232 foreach($PrestaList as $Presta) 196 foreach($PrestaList as $Presta){
233 { 197 $PrestaListIdKeys[$Presta->getId()] = $Presta;
234 $id = $Presta->getId();
235 $PrestaListIdKeys[$id] = $Presta;
236 } 198 }
237 199
238 // fenêtre 200 // fenêtre
239 $entrees = []; 201 $entrees = [];
240 foreach($PrestaListIdKeys as $Presta) 202 foreach($PrestaListIdKeys as $Presta){
241 {
242 $id = $Presta->getId(); 203 $id = $Presta->getId();
243 $entrees[$id][] = $id; 204 $entrees[$id][] = $id;
244 $entrees[$id][] = $Presta->getDate(); 205 $entrees[$id][] = $Presta->getDate();
@@ -252,22 +213,28 @@ abstract class Prestation
252 213
253 // choix de l'utilisateur 214 // choix de l'utilisateur
254 $input = exec($ResultatsRecherchePresta->get()); // $input est l'ID de la prestation 215 $input = exec($ResultatsRecherchePresta->get()); // $input est l'ID de la prestation
255 //echo "input = " . $input . "\n"; 216 if($input == ''){
256 if($input == '')
257 {
258 echo "debug: recherche annulée ou saisie vide\n"; 217 echo "debug: recherche annulée ou saisie vide\n";
259 return 0; 218 return null;
260 } 219 }
261 else 220 else{
262 {
263 return $PrestaListIdKeys[$input]; 221 return $PrestaListIdKeys[$input];
264 } 222 }
265 } 223 }
266 224
267 // à mettre plus tard dans une classe mère 225 // nettoyage caractères spéciaux: " `
268 private function cleanSpecialChars(string $data): string 226 public function cleanSpecialChars(string $answers): string
269 { 227 {
270 $search = ['"']; 228 $targets = ['"', '`'];
271 return str_replace($search, '', $data); 229 return str_replace($targets, '', $answers); // possibilité que des input deviennent vide
230 }
231
232 public function answersToArray(string $answers): array|false
233 {
234 if($answers === ''){
235 echo "erreur: chaîne vide dans answersToArray()\n";
236 return false;
237 }
238 return explode('|', $answers);
272 } 239 }
273} 240}
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 @@
5 5
6function newService(?Client $Client = null): array 6function newService(?Client $Client = null): array
7{ 7{
8 // fenêtres recherche d'un client 8 // fenêtres
9 $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client['text']); 9 $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client['text']);
10 $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client['text'], []); 10 $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client['text'], []);
11
12 // fenêtres
13 $MenuEnregistrement = new ZenityList(ZenitySetup::$menu_enregistrement['text'], ZenitySetup::$menu_enregistrement['entrees']); 11 $MenuEnregistrement = new ZenityList(ZenitySetup::$menu_enregistrement['text'], ZenitySetup::$menu_enregistrement['entrees']);
14 $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section2']); 12 $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section2']);
15 $FormulaireDevis = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['devis_entrees']); 13 $FormulaireDevis = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['devis_entrees']);
@@ -17,15 +15,16 @@ function newService(?Client $Client = null): array
17 $FormulaireFactureReduit = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['facture_entrees_reduit']); 15 $FormulaireFactureReduit = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['facture_entrees_reduit']);
18 $FormulaireCesu = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['cesu_entrees']); 16 $FormulaireCesu = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['cesu_entrees']);
19 $FormulaireLocation = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['location_entrees']); 17 $FormulaireLocation = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['location_entrees']);
18 $FormulaireNonVendue = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['non_vendue_entrees']);
20 $CommentairePrestation = new ZenityEntry(ZenitySetup::$commentaire_prestation['text']); 19 $CommentairePrestation = new ZenityEntry(ZenitySetup::$commentaire_prestation['text']);
21 //$Recapitulatif = new ZenityList(ZenitySetup::$recapitulatif_text, ZenitySetup::$recapitulatif_entrees); // tableau à multiples colonnes 20 //$Recapitulatif = new ZenityList(ZenitySetup::$recapitulatif_text, ZenitySetup::$recapitulatif_entrees); // tableau à multiples colonnes
22 $FinSection2 = new ZenityList(ZenitySetup::$fin_section_2['text'], ZenitySetup::$fin_section_2['entrees']); 21 $FinSection2 = new ZenityList(ZenitySetup::$fin_section_2['text'], ZenitySetup::$fin_section_2['entrees']);
23 22
24 23
25 // -- partie 1: le client -- 24 // -- partie 1: rechercher un client --
26 if(!$Client) 25 if(!$Client)
27 { 26 {
28 $Client = Client::find($RechercheClient, $ResultatsRechercheClient); // retourne un Client ou 0 27 $Client = Client::find($RechercheClient, $ResultatsRechercheClient);
29 //$ResultatsRechercheClient->cleanCommand(); // inutile parce qu'on ne boucle pas dans cette fonction 28 //$ResultatsRechercheClient->cleanCommand(); // inutile parce qu'on ne boucle pas dans cette fonction
30 if(!$Client) 29 if(!$Client)
31 { 30 {
@@ -51,69 +50,82 @@ function newService(?Client $Client = null): array
51 echo "debug: annulation à la saisie d'une date\n"; 50 echo "debug: annulation à la saisie d'une date\n";
52 return [2, $Client]; 51 return [2, $Client];
53 } 52 }
54 53
55 $Presta = new Prestation($Client); 54
56 //var_dump($Client);die;
57 $Presta->setDate($date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]); // 2026-10-17
58
59 // formulaire - étape 2/3 55 // formulaire - étape 2/3
60 switch($choix_niv2) 56 switch($choix_niv2)
61 { 57 {
62 // comparaison retour de $MenuEnregistrement->get() avec les noms des entrées du même menu 58 // comparaison du retour de $MenuEnregistrement->get() avec les noms des entrées du même menu
63 case ZenitySetup::$menu_enregistrement['entrees'][0]: // "Devis" 59 case ZenitySetup::$menu_enregistrement['entrees'][0]: // "Devis"
64 $PrestaDetails = new Devis($Presta); 60 $Presta = new Devis($Client);
65 $Presta->setTypePresta('devis');
66 $answers = exec($FormulaireDevis->get()); 61 $answers = exec($FormulaireDevis->get());
67 break; 62 break;
68 case ZenitySetup::$menu_enregistrement['entrees'][1]: // "Facture" 63 case ZenitySetup::$menu_enregistrement['entrees'][1]: // "Facture"
69 $PrestaDetails = new Facture($Presta); 64 $Presta = new Facture($Client, false);
70 $Presta->setTypePresta('facture');
71 $answers = exec($FormulaireFacture->get()); 65 $answers = exec($FormulaireFacture->get());
72 break; 66 break;
73 case ZenitySetup::$menu_enregistrement['entrees'][2]: // "Facture à partir d'un devis" 67 case ZenitySetup::$menu_enregistrement['entrees'][2]: // "Facture à partir d'un devis"
74 // recherche du devis 68 $Quotation = Prestation::getServices($Client, Devis::class);
75 $Quotation = Prestation::getServices($Client, 'devis'); // rechercher un devis, type 'devis' spécifié 69 if(!is_object($Quotation) || $Quotation->getTypePresta() != 'devis'){
76 if(!is_object($Quotation) || get_class($Quotation) != 'Prestation' || $Quotation->getTypePresta() != 'devis')
77 {
78 echo "debug: annulation sélection client\n"; 70 echo "debug: annulation sélection client\n";
79 return [2, $Client]; // menu précédent 71 return [2, $Client]; // menu précédent
80 } 72 }
81 $QuotationDetails = Devis::getQuotation($Quotation); 73 $Presta = new Facture($Client, true); // true = à partir d'un devis
82 $PrestaDetails = new Facture($Presta); 74 $Presta->hydrateWithQuotation($Quotation); // du devis à la facture
83 $PrestaDetails->hydrateWithQuotation($QuotationDetails); // du devis à la facture
84 $Presta->setTypePresta('facture');
85 $answers = exec($FormulaireFactureReduit->get()); 75 $answers = exec($FormulaireFactureReduit->get());
86 break; 76 break;
87 case ZenitySetup::$menu_enregistrement['entrees'][3]: // "CESU" 77 case ZenitySetup::$menu_enregistrement['entrees'][3]: // "CESU"
88 $PrestaDetails = new CESU($Presta); 78 $Presta = new CESU($Client);
89 $Presta->setTypePresta('cesu');
90 $answers = exec($FormulaireCesu->get()); 79 $answers = exec($FormulaireCesu->get());
91 break; 80 break;
92 case ZenitySetup::$menu_enregistrement['entrees'][4]: // "Location" 81 case ZenitySetup::$menu_enregistrement['entrees'][4]: // "Location"
93 $PrestaDetails = new Location($Presta); 82 $Presta = new Location($Client);
94 $Presta->setTypePresta('location');
95 $answers = exec($FormulaireLocation->get()); 83 $answers = exec($FormulaireLocation->get());
96 break; 84 break;
97 case ZenitySetup::$menu_enregistrement['entrees'][5]: // "Prestation non vendue" 85 case ZenitySetup::$menu_enregistrement['entrees'][5]: // "Prestation non vendue"
98 $Presta->setTypePresta('non_vendue'); 86 $Presta = new NonVendue($Client);
87 $answers = exec($FormulaireNonVendue->get());
99 break; 88 break;
100 default: // inutile normallement, cas déjà géré avant 89 default: // inutile normallement, cas déjà géré avant
101 echo "debug: sortie du menu enregistrement incorrect\n"; 90 echo "debug: sortie du menu enregistrement incorrect\n";
102 return [0, null]; 91 return [0, null];
103 } 92 }
93 $Presta->setDate($date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]); // 2026-10-17
104 94
105 //$Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre 95 //$Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre
106 //$Presta->makeCodePresta($Client->getCodeClient()); // d'un objet à l'autre 96 //$Presta->makeCodePresta($Client->getCodeClient()); // d'un objet à l'autre
107 $Presta->setCodePresta(1); // d'un objet à l'autre 97 $Presta->setCodePresta(1); // d'un objet à l'autre
98
99 if($Presta->getTypePresta() !== 'devis'){
100 $Client->setType('client'); // changer prospect en client
101 }
102
103 $answers = $Presta->cleanSpecialChars($answers);
104
105 $data_array = $Presta->answersToArray($answers);
106 if(!$data_array){ // annulation
107 echo "debug: annulation lors de l'enregistrement des détails de la prestation\n";
108 return [0, null];
109 }
110
111 // attention risque d'erreur! les données n'ont pas de d'identifiant!
112 // leur ordre et leur nombre permettent d'insérer la bonne info au bon endroit
113 // toute modif du modèle ou d'un formulaire doit être répèrcutée ici
114 if(!$Presta->validateForm($data_array)){
115 echo "erreur: les données du formulaire sont incompatibles avec le modèle\n";
116 return [0, null];
117 }
118
119 // hydratation avec la saisie du formulaire
120 $Presta->hydrate($data_array);
108 121
109 // commentaire - étape 3/3 122 // commentaire - étape 3/3
110 $comment = exec($CommentairePrestation->get()); 123 $comment = exec($CommentairePrestation->get());
111 if($comment == '') 124 if($comment == ''){
112 {
113 echo "debug: pas de commentaire saisi\n"; 125 echo "debug: pas de commentaire saisi\n";
114 // on n'interrompt pas le script et on enregistre dans tous les cas (annulatation comprise) 126 // on n'interrompt pas le script et on enregistre dans tous les cas (annulation comprise)
115 } 127 }
116 // Cliquer sur annuler (ou appuyer sur échap) revient dont à valider avec une chaîne vide et enregistrer la prestation 128 // Cliquer sur annuler (ou appuyer sur échap) revient donc à valider avec une chaîne vide et enregistrer la prestation
117 // la commande 'echo $?' ($? est le code de sortie de la commande précédente) renvoit 1 si on annule avec la touche échap () 129 // la commande 'echo $?' ($? est le code de sortie de la commande précédente) renvoit 1 si on annule avec la touche échap ()
118 // 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) 130 // 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)
119 // 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 131 // 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
125 //~ return 0; 137 //~ return 0;
126 //~ } 138 //~ }
127 $Presta->setCommentaires($comment); 139 $Presta->setCommentaires($comment);
128 140
129 // hydratation avec la saisie du formulaire 141 // enregistrement
130 if($choix_niv2 != ZenitySetup::$menu_enregistrement['entrees'][5]) // cas: tous les cas sauf presta non vendue 142 // déléguer la synchronisation (flush) avec la BDD à une classe "Manager"?
131 { 143 Prestation::$entityManager->persist($Presta);
132 //var_dump($answers); 144 Prestation::$entityManager->flush();
133 if($Presta->getTypePresta() !== 'devis'){
134 $Client->setType('client');
135 }
136 if($answers == '') // annulation
137 {
138 echo "debug: annulation lors de l'enregistrement des détails de la prestation\n";
139 return [0, null];
140 }
141 $PrestaDetails->hydrate($answers);
142
143 // déléguer la synchronisation (flush) avec la BDD à une classe "Manager"
144 }
145
146 // si encore de type prospect, devient un type client
147 // déjà fait ailleurs je crois!
148 /*if($Client->typeToClient()) // utile si $Client est renvoyé dans le "return"
149 {
150 $Client->updateOneValue('type', 'client'); // base synchronisée
151 }*/
152
153 145
154 // -- partie 3: LaTeX -- 146 // -- partie 3: LaTeX --
155 147
@@ -162,9 +154,8 @@ function newService(?Client $Client = null): array
162 $EnveloppeRecto->setData($Client); 154 $EnveloppeRecto->setData($Client);
163 $EnveloppeRecto->makeLatex(); 155 $EnveloppeRecto->makeLatex();
164 $EnveloppeVerso->makeLatex(); 156 $EnveloppeVerso->makeLatex();
165 if($DocumentPresta !== null) 157 if($DocumentPresta !== null){ // facture, devis ou location
166 { 158 $DocumentPresta->setData($Client)->setData($Presta);
167 $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails);
168 $DocumentPresta->makeLatex(); 159 $DocumentPresta->makeLatex();
169 } 160 }
170 161
@@ -172,8 +163,7 @@ function newService(?Client $Client = null): array
172 $EnveloppeRecto->makeTexAndPdf(); 163 $EnveloppeRecto->makeTexAndPdf();
173 $EnveloppeVerso->makeTexAndPdf(); 164 $EnveloppeVerso->makeTexAndPdf();
174 165
175 if($DocumentPresta !== null) 166 if($DocumentPresta !== null){
176 {
177 $DocumentPresta->makeTexAndPdf(); 167 $DocumentPresta->makeTexAndPdf();
178 } 168 }
179 169
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
22 $entries[$i][] = ''; 22 $entries[$i][] = '';
23 //~ $entries[$i][] = ZenitySetup::$modification_client['return']; 23 //~ $entries[$i][] = ZenitySetup::$modification_client['return'];
24 //~ $entries[$i][] = ''; 24 //~ $entries[$i][] = '';
25 $ModifyCustomer->setListRows($entries, 2, 2.5);
26 25
26 $ModifyCustomer->setListRows($entries, 2, 2.5);
27 return $ModifyCustomer; 27 return $ModifyCustomer;
28} 28}
29 29
30function makeModifyServiceWindow(Prestation $Service, $ServiceDetails = null): ZenityList 30function makeModifyServiceWindow(Prestation $Service): ZenityList
31{ 31{
32 // fenêtre 32 // fenêtre
33 $ModifyService = new ZenityList(ZenitySetup::$modification_presta['text'], []); 33 $ModifyService = new ZenityList(ZenitySetup::$modification_presta['text'], []);
@@ -42,31 +42,7 @@ function makeModifyServiceWindow(Prestation $Service, $ServiceDetails = null): Z
42 $entrees[$i][] = $value; 42 $entrees[$i][] = $value;
43 $i++; 43 $i++;
44 } 44 }
45 45
46 if(is_object($ServiceDetails))
47 {
48 $presta_data = $ServiceDetails->getAllWithWindowFields();
49 //var_dump($presta_data);
50 foreach($presta_data as $key => $value)
51 {
52 $entrees[$i][] = $key;
53 $entrees[$i][] = $value;
54 $i++;
55 }
56 }
57
58 //~ if($Service->getTypePresta() === 'devis')
59 //~ {
60 //~ $entrees[$i][] = ZenitySetup::$modification_presta['devis_facture']; // option créer une facture à partir du devis
61 //~ $entrees[$i][] = '';
62 //~ }
63
64 //~ $entrees[$i][] = ZenitySetup::$modification_presta['service'];
65 //~ $entrees[$i][] = '';
66 //~ $i++;
67 //~ $entrees[$i][] = ZenitySetup::$modification_presta['return'];
68 //~ $entrees[$i][] = '';
69
70 $ModifyService->setListRows($entrees, 2, 2.5); 46 $ModifyService->setListRows($entrees, 2, 2.5);
71 return $ModifyService; 47 return $ModifyService;
72} 48}
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');
7 7
8function modifyData(?Client $Client = null): array 8function modifyData(?Client $Client = null): array
9{ 9{
10 // -- partie 1: rechercher un client -- 10 // fenêtres
11
12 // fenêtres statiques
13 // recherche d'un client
14 $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client['text']); 11 $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client['text']);
15 $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client['text'], []); 12 $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client['text'], []);
16 // modification de données
17 $TypeDeClient = new ZenityList(ZenitySetup::$type_client['text'], ZenitySetup::$type_client['entrees']); 13 $TypeDeClient = new ZenityList(ZenitySetup::$type_client['text'], ZenitySetup::$type_client['entrees']);
18 $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section3']); 14 $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section3']);
19 15
16
17 // -- partie 1: rechercher un client --
20 if(!$Client) 18 if(!$Client)
21 { 19 {
22 $Client = Client::find($RechercheClient, $ResultatsRechercheClient); 20 $Client = Client::find($RechercheClient, $ResultatsRechercheClient);
@@ -93,120 +91,72 @@ function modifyData(?Client $Client = null): array
93 91
94 92
95 // -- partie 3: rechercher une prestation -- 93 // -- partie 3: rechercher une prestation --
96 $Presta = Prestation::getServices($Client); // = 0 ou type "Prestation" 94 $Presta = Prestation::getServices($Client);
97 if(!is_object($Presta) || !get_class($Presta) == 'Prestation') 95 if(!is_object($Presta) || !get_class($Presta) == 'Prestation')
98 { 96 {
99 echo "debug: annulation sélection d'une prestation\n"; 97 echo "debug: annulation sélection d'une prestation\n";
100 return [3, $Client]; // menu précédent 98 return [3, $Client]; // menu précédent
101 } 99 }
102 $type_presta = $Presta->getTypePresta(); 100 $type_presta = $Presta->getTypePresta();
103 $classe = ''; 101 $classe = match($type_presta){
104 switch($type_presta){ 102 'facture' => Facture::class,
105 case 'facture': 103 'devis' => Devis::class,
106 $classe = 'Facture'; 104 'cesu' => CESU::class,
107 break; 105 'location' => Location::class,
108 case 'devis': 106 'non_vendue' => NonVendue::class,
109 $classe = 'Devis'; 107 };
110 break; 108
111 case 'cesu': 109 $repository = Prestation::$entityManager->getRepository($classe);
112 $classe = 'CESU'; 110 $Presta = $repository->findOneBy(['id' => $Presta->getId()]);
113 break;
114 case 'location':
115 $classe = 'Location';
116 break;
117 case 'non_vendue':
118 $PrestaDetails = null;
119 break;
120 default:
121 echo "erreur: type de prestation buggué\n";
122 }
123 if($type_presta != 'non_vendue')
124 {
125 $repository = $classe::$entityManager->getRepository($classe);
126 $PrestaDetails = $repository->findOneBy(['presta' => $Presta->getId()]);
127 }
128 111
129 112
130 // -- partie 4: modifier une prestation -- 113 // -- partie 4: modifier une prestation --
131 114
132 // fenêtre 115 // fenêtre
133 $ModificationPrestaMenu = makeModifyServiceWindow($Presta, $PrestaDetails); 116 $ModificationPrestaMenu = makeModifyServiceWindow($Presta);
134
135 $choix_niv3 = exec($ModificationPrestaMenu->get()); 117 $choix_niv3 = exec($ModificationPrestaMenu->get());
136 118 if($choix_niv3 === 'Date:'){
137 if($choix_niv3 === 'Date:')
138 {
139 $date_array = explode('/', exec($Calendrier->get())); // 17/10/2026 119 $date_array = explode('/', exec($Calendrier->get())); // 17/10/2026
140 if(count($date_array) === 1){ 120 if(count($date_array) === 1){
141 echo "debug: annulation à la saisie d'une date\n"; 121 echo "debug: annulation à la saisie d'une date\n";
142 return [3, $Client]; 122 return [3, $Client];
143 } 123 }
144 124 $input = $date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]; // 2026-10-17
145 // entités et BDD
146 $Presta->set($choix_niv3, $date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]); // 2026-10-09
147 $old_code = $Presta->getCodePresta();
148 $Presta->setCodePresta(0);
149 $Presta::$entityManager->flush();
150
151 // documents
152 if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location')
153 {
154 $DocumentPresta = Latex::makeInstance($Presta->getTypePresta()); // $type = facture, devis, location
155 $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails);
156 $DocumentPresta->makeLatex(); // en mémoire
157
158 File::renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta());
159 $DocumentPresta->makeTexAndPdf(); // une nouvelle facture est créée, supprimer l'ancienne ou la renommer avec la nouvelle date
160 }
161
162 return [3, $Client]; // menu précédent
163 } 125 }
164 //~ elseif($choix_niv3 === 'Type de Presta:') // compliqué! choix impossible pour le moment 126 //~ elseif($choix_niv3 === 'Type de Presta:') // compliqué! choix impossible pour le moment
165 //~ { 127 //~ {
166 //~ echo "choix: changer le type de prestation (devis, facture, etc)\n"; 128 //~ echo "choix: changer le type de prestation (devis, facture, etc)\n";
167 //~ return [3, $Client]; // menu "client" 129 //~ return [3, $Client]; // menu "client"
168 //~ } 130 //~ }
169 elseif(is_string($choix_niv3) && $choix_niv3 != '') // modifier une valeur 131 elseif(is_string($choix_niv3) && $choix_niv3 != ''){ // modifier une valeur
170 {
171 echo "choix: modifier " . $choix_niv3 . "\n"; 132 echo "choix: modifier " . $choix_niv3 . "\n";
172 $ModificationPrestaForm = new ZenityEntry($choix_niv3); 133 $ModificationPrestaForm = new ZenityEntry($choix_niv3);
173 $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 134 $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
174 if(is_string($input)) // chaîne vide autorisée 135 if(!is_string($input)){ // chaîne vide autorisée
175 {
176 // entités et BDD
177 $Presta->set($choix_niv3, $input);
178 $old_code = $Presta->getCodePresta();
179 $Presta->setCodePresta(0);
180 if($type_presta != 'non_vendue')
181 {
182 $PrestaDetails->set($choix_niv3, $input);
183 $PrestaDetails::$entityManager->flush();
184 }
185 else
186 {
187 $Presta::$entityManager->flush();
188 }
189
190 // documents
191 if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location')
192 {
193 $DocumentPresta = Latex::makeInstance($type_presta);
194 $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); // polymorphisme
195 $DocumentPresta->makeLatex();
196
197 File::renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta());
198 $DocumentPresta->makeTexAndPdf();
199 }
200 }
201 else
202 {
203 echo "choix: annulation\n"; 136 echo "choix: annulation\n";
137 return [3, $Client]; // menu précédent
204 } 138 }
205 return [3, $Client]; // menu précédent
206 } 139 }
207 else // annuler 140 else{
208 {
209 echo "annulation: retour au menu précédent\n"; 141 echo "annulation: retour au menu précédent\n";
210 return [3, $Client]; // menu précédent 142 return [3, $Client]; // menu précédent
211 } 143 }
144
145 // entités et BDD
146 $Presta->set($choix_niv3, $input);
147 $old_code = $Presta->getCodePresta();
148 $Presta->setCodePresta(0);
149 $Presta::$entityManager->flush();
150
151 // documents
152 if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location'){
153 $DocumentPresta = Latex::makeInstance($type_presta);
154 $DocumentPresta->setData($Client)->setData($Presta);
155 $DocumentPresta->makeLatex();
156
157 File::renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta());
158 $DocumentPresta->makeTexAndPdf();
159 }
160
161 return [3, $Client]; // menu précédent
212} 162}
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
31 '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:"], 31 '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:"],
32 'facture_entrees_reduit' => ["Modèle du PC:", "OS:", "Données sauvegardées:", "Clés d\'activation:", "Mode de paiement:"], 32 'facture_entrees_reduit' => ["Modèle du PC:", "OS:", "Données sauvegardées:", "Clés d\'activation:", "Mode de paiement:"],
33 'cesu_entrees' => ["Tâches effectuées:", "Duree de travail:", "Salaire net:", "Mode de paiement:"], // en fait je pourrais ajouter plein d'autres trucs 33 'cesu_entrees' => ["Tâches effectuées:", "Duree de travail:", "Salaire net:", "Mode de paiement:"], // en fait je pourrais ajouter plein d'autres trucs
34 '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:"]]; 34 '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:"],
35 'non_vendue_entrees' => ["Tâches effectuées:"]];
35 static public $commentaire_prestation = ['text' => 'Nouvelle prestation 3/3 - Commentaires']; 36 static public $commentaire_prestation = ['text' => 'Nouvelle prestation 3/3 - Commentaires'];
36 static public $modification_client = ['text' => 'Modifier une information concernant un client', 37 static public $modification_client = ['text' => 'Modifier une information concernant un client',
37 'service' => "Modifier une prestation"]; 38 'service' => "Modifier une prestation"];
diff --git a/à faire.txt b/à faire.txt
index 15275a9..7f2279e 100644
--- a/à faire.txt
+++ b/à faire.txt
@@ -1,12 +1,18 @@
1À FAIRE: 1À FAIRE:
2 2
3Prestations classe abstraite + héritage? 3faire autre chose de ZenitySetup, passer fonctions en paramètres
4
5améliorer les validateForm()
4 6
5calcul correct des code presta si une ancienne facture est modifiée 7calcul correct des code presta si une ancienne facture est modifiée
6permettre de modifier le code_presta dans "Modifier une prestation" 8permettre de modifier le code_presta dans "Modifier une prestation"
7une classe CodePresta? 9une classe CodePresta?
8 10
9structure BDD en anglais 11structure BDD en anglais
12appli toute en anglais
13
14pouvoir retyper une presta?
15de facture à non vendue en cas d'impayé par exemple
10 16
11champ "date_bulletin_paie" dans la table cesu 17champ "date_bulletin_paie" dans la table cesu
12 18
@@ -32,8 +38,6 @@ relier ZenitySetup et les fonctions getAllWithWindowFileds()
32 38
33changer les fichiers dans "pub" 39changer les fichiers dans "pub"
34 40
35factoriser la partie 4 dans 3_modify_data.php
36
37src/dependances.php: tester les dépendances de texlive 41src/dependances.php: tester les dépendances de texlive
38 42
39erreur de bash avec zenity: > 43erreur de bash avec zenity: >