diff options
| author | polo <ordipolo@gmx.fr> | 2026-10-20 21:49:17 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-10-20 22:49:21 +0200 |
| commit | 0161ac4d632af7d45f4fe9d68c1ba3a86f094fc4 (patch) | |
| tree | bbaea156e9d32edf14adad8fe5ce3338014e7710 /src/model | |
| parent | 87eb9864d7c738d7897be33c9a1aa06e33378acc (diff) | |
| download | AppliGestionPHP-0161ac4d632af7d45f4fe9d68c1ba3a86f094fc4.tar.gz AppliGestionPHP-0161ac4d632af7d45f4fe9d68c1ba3a86f094fc4.tar.bz2 AppliGestionPHP-0161ac4d632af7d45f4fe9d68c1ba3a86f094fc4.zip | |
mise en place de l'héritage 2, nombreuses simplifications et factorisations
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/entities/CESU.php | 71 | ||||
| -rw-r--r-- | src/model/entities/Devis.php | 98 | ||||
| -rw-r--r-- | src/model/entities/Facture.php | 113 | ||||
| -rw-r--r-- | src/model/entities/Location.php | 63 | ||||
| -rw-r--r-- | src/model/entities/NonVendue.php | 32 | ||||
| -rw-r--r-- | src/model/entities/Prestation.php | 139 |
6 files changed, 193 insertions, 323 deletions
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 | ||
| 4 | use Doctrine\ORM\Mapping as ORM; | 4 | use Doctrine\ORM\Mapping as ORM; |
| 5 | use 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 | ||
| 4 | use Doctrine\ORM\Mapping as ORM; | 4 | use Doctrine\ORM\Mapping as ORM; |
| 5 | use 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 | ||
| 4 | use Doctrine\ORM\Mapping as ORM; | 4 | use Doctrine\ORM\Mapping as ORM; |
| 5 | use 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 | ||
| 4 | use Doctrine\ORM\Mapping as ORM; | 4 | use Doctrine\ORM\Mapping as ORM; |
| 5 | use 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 | } |
