diff options
| author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
| commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
| tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /src/model/entities | |
| parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
| download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.gz AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.bz2 AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip | |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'src/model/entities')
| -rw-r--r-- | src/model/entities/CESU.php | 131 | ||||
| -rw-r--r-- | src/model/entities/Client.php | 314 | ||||
| -rw-r--r-- | src/model/entities/Devis.php | 241 | ||||
| -rw-r--r-- | src/model/entities/Facture.php | 261 | ||||
| -rw-r--r-- | src/model/entities/Location.php | 209 | ||||
| -rw-r--r-- | src/model/entities/Prestation.php | 252 |
6 files changed, 1408 insertions, 0 deletions
diff --git a/src/model/entities/CESU.php b/src/model/entities/CESU.php new file mode 100644 index 0000000..09a2542 --- /dev/null +++ b/src/model/entities/CESU.php | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | <?php | ||
| 2 | // src/entities/CESU.php | ||
| 3 | |||
| 4 | use Doctrine\ORM\Mapping as ORM; | ||
| 5 | use Doctrine\ORM\EntityManager; | ||
| 6 | |||
| 7 | #[ORM\Entity] | ||
| 8 | #[ORM\Table(name: 'cesu')] | ||
| 9 | class CESU | ||
| 10 | { | ||
| 11 | #[ORM\Id] | ||
| 12 | #[ORM\Column(type: 'integer')] | ||
| 13 | #[ORM\GeneratedValue] | ||
| 14 | private int|null $id = null; | ||
| 15 | |||
| 16 | #[ORM\ManyToOne(targetEntity: Prestation::class, cascade: ['persist'])] | ||
| 17 | #[ORM\JoinColumn(name: 'id_presta', referencedColumnName: 'id')] | ||
| 18 | private Prestation|null $presta = null; | ||
| 19 | |||
| 20 | #[ORM\Column] | ||
| 21 | private string $taches; | ||
| 22 | #[ORM\Column] | ||
| 23 | private string $duree_travail; | ||
| 24 | #[ORM\Column] | ||
| 25 | private float $salaire; | ||
| 26 | |||
| 27 | public static EntityManager $entityManager; | ||
| 28 | |||
| 29 | public function __construct(Prestation $presta = null) | ||
| 30 | { | ||
| 31 | if($presta != null) | ||
| 32 | { | ||
| 33 | $this->setPresta($presta); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | // getters | ||
| 38 | public function getPresta(): Prestation | ||
| 39 | { | ||
| 40 | return $this->presta; | ||
| 41 | } | ||
| 42 | |||
| 43 | public function getAllWithWindowFields(): array | ||
| 44 | { | ||
| 45 | return [ | ||
| 46 | "Tâche effectuée:" => $this->taches, | ||
| 47 | "Durée du travail:" => $this->duree_travail, | ||
| 48 | "Salaire:" => $this->salaire]; | ||
| 49 | } | ||
| 50 | |||
| 51 | // setters | ||
| 52 | public function set(string $entry, string $input) | ||
| 53 | { | ||
| 54 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide | ||
| 55 | switch($entry) | ||
| 56 | { | ||
| 57 | case "Tâche effectuée:": | ||
| 58 | $this->setTaches($input); | ||
| 59 | break; | ||
| 60 | case "Durée du travail:": | ||
| 61 | $this->setDureeTravail($input); | ||
| 62 | break; | ||
| 63 | case "Salaire:": | ||
| 64 | $this->setSalaire($input); | ||
| 65 | break; | ||
| 66 | } | ||
| 67 | } | ||
| 68 | private function setPresta(Prestation $input) // private? | ||
| 69 | { | ||
| 70 | $this->presta = $input; | ||
| 71 | } | ||
| 72 | public function setTaches(string $value) | ||
| 73 | { | ||
| 74 | $this->taches = $value; | ||
| 75 | return($this); | ||
| 76 | } | ||
| 77 | public function setDureeTravail(string $value) | ||
| 78 | { | ||
| 79 | $this->duree_travail = $value; | ||
| 80 | return($this); | ||
| 81 | } | ||
| 82 | public function setSalaire($value) | ||
| 83 | { | ||
| 84 | $value = str_replace(',', '.', $value); | ||
| 85 | $this->salaire = (float) $value; | ||
| 86 | return($this); | ||
| 87 | } | ||
| 88 | |||
| 89 | private function setAll(array $input) // private? | ||
| 90 | { | ||
| 91 | $this->taches = $input[0]; | ||
| 92 | $this->duree_travail = $input[1]; | ||
| 93 | $this->salaire = (float)$input[2]; | ||
| 94 | } | ||
| 95 | |||
| 96 | // à mettre plus tard dans une classe mère | ||
| 97 | protected function cleanSpecialChars(string $data): string | ||
| 98 | { | ||
| 99 | $search = ['"']; | ||
| 100 | return str_replace($search, '', $data); | ||
| 101 | } | ||
| 102 | // à mettre plus tard dans une classe mère | ||
| 103 | public function hydrate(string $answers) | ||
| 104 | { | ||
| 105 | $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide | ||
| 106 | if($answers == '') | ||
| 107 | { | ||
| 108 | echo "erreur de CESU::hydrate(), la chaine \$answers est vide.\n"; | ||
| 109 | return false; | ||
| 110 | } | ||
| 111 | $data_array = explode('|', $answers); // array | ||
| 112 | |||
| 113 | $check = false; | ||
| 114 | if(count($data_array) === 4) // facture normale | ||
| 115 | { | ||
| 116 | $this->getPresta()->setModePaiement($data_array[3]); | ||
| 117 | //array_pop($data_array); // supprime la dernière case | ||
| 118 | unset($data_array[3]); | ||
| 119 | $this->setAll($data_array); | ||
| 120 | } | ||
| 121 | else | ||
| 122 | { | ||
| 123 | echo "erreur de CESU::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; | ||
| 124 | return false; | ||
| 125 | } | ||
| 126 | |||
| 127 | //self::$entityManager->persist('Prestation'); | ||
| 128 | self::$entityManager->persist($this); // $Presta avec en cascade! | ||
| 129 | self::$entityManager->flush(); | ||
| 130 | } | ||
| 131 | } | ||
diff --git a/src/model/entities/Client.php b/src/model/entities/Client.php new file mode 100644 index 0000000..7dd3be6 --- /dev/null +++ b/src/model/entities/Client.php | |||
| @@ -0,0 +1,314 @@ | |||
| 1 | <?php | ||
| 2 | // src/entities/Client.php | ||
| 3 | |||
| 4 | use Doctrine\ORM\Mapping as ORM; | ||
| 5 | use Doctrine\ORM\EntityManager; // pour ClientManager? | ||
| 6 | |||
| 7 | #[ORM\Entity] | ||
| 8 | #[ORM\Table(name: 'clients')] | ||
| 9 | class Client | ||
| 10 | { | ||
| 11 | #[ORM\Id] | ||
| 12 | #[ORM\Column(type: 'integer')] | ||
| 13 | #[ORM\GeneratedValue] | ||
| 14 | private int|null $id = null; | ||
| 15 | #[ORM\Column] | ||
| 16 | private string $prenom_nom; | ||
| 17 | #[ORM\Column] | ||
| 18 | private string $code_client; | ||
| 19 | #[ORM\Column] | ||
| 20 | private string $adresse; | ||
| 21 | #[ORM\Column] | ||
| 22 | private string $code_postal; | ||
| 23 | #[ORM\Column] | ||
| 24 | private string $ville; | ||
| 25 | #[ORM\Column] | ||
| 26 | private string $telephone; | ||
| 27 | #[ORM\Column] | ||
| 28 | private string $courriel; | ||
| 29 | #[ORM\Column] | ||
| 30 | private string $apropos; | ||
| 31 | #[ORM\Column(options: ['default' => 'prospect'])] | ||
| 32 | private string $type = 'prospect'; // valeur par défaut utilisée à l'instanciation, pas par doctrine | ||
| 33 | |||
| 34 | public static EntityManager $entityManager; | ||
| 35 | |||
| 36 | /*public function __construct() | ||
| 37 | { | ||
| 38 | global $entityManager; | ||
| 39 | self::$entityManager = $entityManager; | ||
| 40 | }*/ | ||
| 41 | |||
| 42 | |||
| 43 | // getters | ||
| 44 | public function getId(): int | ||
| 45 | { | ||
| 46 | return $this->id; | ||
| 47 | } | ||
| 48 | public function getPrenomNom(): string | ||
| 49 | { | ||
| 50 | return $this->prenom_nom; | ||
| 51 | } | ||
| 52 | public function getCodeClient(): string | ||
| 53 | { | ||
| 54 | return $this->code_client; | ||
| 55 | } | ||
| 56 | public function getAll(): array | ||
| 57 | { | ||
| 58 | // n'utiliser get_object_vars() qu'avec une entité parce qu'on maîtrise le nombre de propriétés | ||
| 59 | return get_object_vars($this); | ||
| 60 | } | ||
| 61 | |||
| 62 | // pour le GUI | ||
| 63 | public function getAllWithWindowFields(): array // différent de getAll() | ||
| 64 | { | ||
| 65 | return [ | ||
| 66 | "Prénom Nom:" => $this->prenom_nom, | ||
| 67 | "Code client (J.C.Dusse):" => $this->code_client, | ||
| 68 | "Adresse:" => $this->adresse, | ||
| 69 | "Code postal:" => $this->code_postal, | ||
| 70 | "Ville:" => $this->ville, | ||
| 71 | "Telephone:" => $this->telephone, | ||
| 72 | "Courriel:" => $this->courriel, | ||
| 73 | "À propos:" => $this->apropos, | ||
| 74 | "Client ou Prospect?" => $this->type]; | ||
| 75 | } | ||
| 76 | |||
| 77 | // setters | ||
| 78 | public function set(string $entry, string $input) | ||
| 79 | { | ||
| 80 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide | ||
| 81 | switch($entry) | ||
| 82 | { | ||
| 83 | case "Prénom Nom:": | ||
| 84 | $this->setPrenomNom($input); | ||
| 85 | break; | ||
| 86 | case "Code client (J.C.Dusse):": | ||
| 87 | $this->setCodeClient($input); | ||
| 88 | break; | ||
| 89 | case "Adresse:": | ||
| 90 | $this->setAdresse($input); | ||
| 91 | break; | ||
| 92 | case "Code postal:": | ||
| 93 | $this->setCodePostal($input); | ||
| 94 | break; | ||
| 95 | case "Ville:": | ||
| 96 | $this->setVille($input); | ||
| 97 | break; | ||
| 98 | case "Telephone:": | ||
| 99 | $this->setTelephone($input); | ||
| 100 | break; | ||
| 101 | case "Courriel:": | ||
| 102 | $this->setCourriel($input); | ||
| 103 | break; | ||
| 104 | case "À propos:": | ||
| 105 | $this->setApropos($input); | ||
| 106 | break; | ||
| 107 | case "Client ou Prospect?": | ||
| 108 | $this->setType($input); | ||
| 109 | break; | ||
| 110 | } | ||
| 111 | //self::$entityManager->flush(); | ||
| 112 | } | ||
| 113 | public function setPrenomNom($value) | ||
| 114 | { | ||
| 115 | $this->prenom_nom = (string) $value; | ||
| 116 | return $this; | ||
| 117 | } | ||
| 118 | public function setCodeClient($value) | ||
| 119 | { | ||
| 120 | $this->code_client = (string) $value; | ||
| 121 | return $this; | ||
| 122 | } | ||
| 123 | public function setAdresse($value) | ||
| 124 | { | ||
| 125 | $this->adresse = (string) $value; | ||
| 126 | return $this; | ||
| 127 | } | ||
| 128 | public function setCodePostal($value) | ||
| 129 | { | ||
| 130 | $this->code_postal = (string) $value; | ||
| 131 | return $this; | ||
| 132 | } | ||
| 133 | public function setVille($value) | ||
| 134 | { | ||
| 135 | $this->ville = (string) $value; | ||
| 136 | return $this; | ||
| 137 | } | ||
| 138 | public function setTelephone($value) | ||
| 139 | { | ||
| 140 | // type string parce que: | ||
| 141 | // - zenity renvoie une chaine | ||
| 142 | // - permet de garder le 0 au début et d'inscrire plusieurs numéros | ||
| 143 | $this->telephone = (string) $value; | ||
| 144 | return $this; | ||
| 145 | } | ||
| 146 | public function setCourriel($value) | ||
| 147 | { | ||
| 148 | $this->courriel = (string) $value; | ||
| 149 | return $this; | ||
| 150 | } | ||
| 151 | public function setApropos($value) | ||
| 152 | { | ||
| 153 | $this->apropos = (string) $value; | ||
| 154 | return $this; | ||
| 155 | } | ||
| 156 | public function setType($value) | ||
| 157 | { | ||
| 158 | $this->type = (string) $value; | ||
| 159 | return $this; | ||
| 160 | } | ||
| 161 | |||
| 162 | public function typeToClient() | ||
| 163 | { | ||
| 164 | if($this->type != 'client') | ||
| 165 | { | ||
| 166 | $this->type = 'client'; | ||
| 167 | } | ||
| 168 | } | ||
| 169 | |||
| 170 | private function setAll(array $input) | ||
| 171 | { | ||
| 172 | $this->prenom_nom = $input[0]; | ||
| 173 | $this->code_client = $input[1]; | ||
| 174 | $this->adresse = $input[2]; | ||
| 175 | $this->code_postal = $input[3]; | ||
| 176 | $this->ville = $input[4]; | ||
| 177 | $this->telephone = $input[5]; | ||
| 178 | $this->courriel = $input[6]; | ||
| 179 | $this->apropos = $input[7]; | ||
| 180 | } | ||
| 181 | |||
| 182 | // à mettre dans une classe mère Model? | ||
| 183 | protected function cleanSpecialChars(string $data): string | ||
| 184 | { | ||
| 185 | $search = ['"']; | ||
| 186 | return str_replace($search, '', $data); | ||
| 187 | } | ||
| 188 | |||
| 189 | // une partie du code vient de Model::hydrateFromForm() | ||
| 190 | // à mettre dans une classe ClientManager? | ||
| 191 | public function enterCustomer(ZenityForms $Form): bool | ||
| 192 | { | ||
| 193 | $input = exec($Form->get()); | ||
| 194 | if($input == '') | ||
| 195 | { | ||
| 196 | echo "debug: annulation lors de l'enregistrement d'un nouveau client\n"; | ||
| 197 | return false; | ||
| 198 | } | ||
| 199 | |||
| 200 | $data_array = explode('|', $input); // array | ||
| 201 | if($data_array[0] == '') | ||
| 202 | { | ||
| 203 | echo "debug: données insuffisantes, le nom du client doit au minimum être renseigné\n"; | ||
| 204 | return false; | ||
| 205 | } | ||
| 206 | else | ||
| 207 | { | ||
| 208 | $this->setAll($data_array); | ||
| 209 | } | ||
| 210 | |||
| 211 | self::$entityManager->persist($this); | ||
| 212 | self::$entityManager->flush(); | ||
| 213 | |||
| 214 | //$this->id = $this->db->lastInsertId(); // synchro automatique avec doctrine | ||
| 215 | |||
| 216 | return true; | ||
| 217 | } | ||
| 218 | |||
| 219 | public static function getObject(ZenityEntry $SearchCustomerForm, ZenityList $SearchCustomerResults) // renvoie un Client ou 0 | ||
| 220 | { | ||
| 221 | // fenêtres | ||
| 222 | /*$SearchCustomerForm = new ZenityEntry(ZenitySetup::$recherche_client_text); | ||
| 223 | $SearchCustomerResults = new ZenityList(ZenitySetup::$resultats_recherche_client_text, []);*/ | ||
| 224 | |||
| 225 | $Customer = new self; // se serait bien d'hériter d'EntityManager? | ||
| 226 | |||
| 227 | $input = exec($SearchCustomerForm->get()); | ||
| 228 | if($input == '') // commenter ce if pour qu'une saisie vide permette d'obtenir tous les clients | ||
| 229 | { | ||
| 230 | echo "debug: recherche annulée ou saisie vide\n"; | ||
| 231 | return 0; | ||
| 232 | } | ||
| 233 | echo "debug: recherche effectuée\n"; | ||
| 234 | |||
| 235 | $MatchedObjects = self::searchCustomer($input, $Customer); | ||
| 236 | if(count($MatchedObjects) === 0) // si aucun client ne correspond, les prendre tous! | ||
| 237 | { | ||
| 238 | $repository = self::$entityManager->getRepository('Client'); | ||
| 239 | $MatchedObjects = $repository->findAll(); | ||
| 240 | |||
| 241 | if(count($MatchedObjects) === 0) // toujours rien | ||
| 242 | { | ||
| 243 | echo "debug: aucun client dans la base de données\n"; | ||
| 244 | return 0; | ||
| 245 | } | ||
| 246 | } | ||
| 247 | |||
| 248 | $clients_array = []; | ||
| 249 | foreach($MatchedObjects as $object) // d'objets en tableaux | ||
| 250 | { | ||
| 251 | $clients_array[] = get_object_vars($object); | ||
| 252 | } | ||
| 253 | |||
| 254 | $SearchCustomerResults->setListRows( | ||
| 255 | $clients_array, | ||
| 256 | //count($clients_array[$id])); | ||
| 257 | count($clients_array[0])); | ||
| 258 | |||
| 259 | // sélection parmi les résultats | ||
| 260 | $input = exec($SearchCustomerResults->get()); // renvoie l'id de la table 'clients' | ||
| 261 | if($input == '') | ||
| 262 | { | ||
| 263 | echo "debug: client pas trouvé ou pas sélectionné\n"; | ||
| 264 | return 0; | ||
| 265 | } | ||
| 266 | |||
| 267 | echo "debug: client sélectionné\n"; | ||
| 268 | //$Customer->setId($input); | ||
| 269 | //$Customer->hydrate($Customer->findById()); | ||
| 270 | $Customer = $MatchedObjects[$input]; | ||
| 271 | //var_dump($Customer); | ||
| 272 | |||
| 273 | return $Customer; | ||
| 274 | } | ||
| 275 | |||
| 276 | private static function searchCustomer(string $input, Client $Customer): array | ||
| 277 | { | ||
| 278 | $input_array = explode(' ', $input); // si plusieurs mot, on les recherche tous l'un après l'autre | ||
| 279 | return $Customer->findByKeywords($input_array, 'prenom_nom'); // on obtient un tableau à deux dimensions avec les entrées trouvées | ||
| 280 | } | ||
| 281 | |||
| 282 | private function findByKeywords(array $keywords, string $field): array // renvoie un tableau d'objets | ||
| 283 | { | ||
| 284 | $results = []; | ||
| 285 | for($i = 0; $i < count($keywords); $i++) | ||
| 286 | { | ||
| 287 | // tableau à deux dimensions obtenu pour un mot clé | ||
| 288 | //$query_result = $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE ' . $field . ' LIKE "%' . $keywords[$i] . '%"')->fetchAll(); | ||
| 289 | $query = self::$entityManager->createQuery('SELECT u FROM Client u WHERE u.' . $field . ' LIKE :expression'); | ||
| 290 | $query->setParameter('expression', '%' . $keywords[$i] . '%'); | ||
| 291 | $query_result = $query->getResult(); | ||
| 292 | |||
| 293 | foreach($query_result as $object) | ||
| 294 | { | ||
| 295 | $id = $object->getId(); | ||
| 296 | $already_exist = false; | ||
| 297 | //for($j = 0; $j < count($results); $j++) | ||
| 298 | foreach($results as $one_result) // pour chaque tableau déjà enregistré dans le tableau $results | ||
| 299 | { | ||
| 300 | if($one_result->getId() === $id) | ||
| 301 | { | ||
| 302 | $already_exist = true; | ||
| 303 | } | ||
| 304 | } | ||
| 305 | if(!$already_exist) | ||
| 306 | { | ||
| 307 | $results[$id] = $object; | ||
| 308 | } | ||
| 309 | } | ||
| 310 | } | ||
| 311 | //var_dump($results); | ||
| 312 | return $results; | ||
| 313 | } | ||
| 314 | } | ||
diff --git a/src/model/entities/Devis.php b/src/model/entities/Devis.php new file mode 100644 index 0000000..7383410 --- /dev/null +++ b/src/model/entities/Devis.php | |||
| @@ -0,0 +1,241 @@ | |||
| 1 | <?php | ||
| 2 | // src/entities/Devis.php | ||
| 3 | |||
| 4 | use Doctrine\ORM\Mapping as ORM; | ||
| 5 | use Doctrine\ORM\EntityManager; | ||
| 6 | |||
| 7 | #[ORM\Entity] | ||
| 8 | #[ORM\Table(name: 'devis')] | ||
| 9 | class Devis | ||
| 10 | { | ||
| 11 | #[ORM\Id] | ||
| 12 | #[ORM\Column(type: 'integer')] | ||
| 13 | #[ORM\GeneratedValue] | ||
| 14 | private int|null $id = null; | ||
| 15 | |||
| 16 | #[ORM\ManyToOne(targetEntity: Prestation::class, cascade: ['persist'])] | ||
| 17 | #[ORM\JoinColumn(name: 'id_presta', referencedColumnName: 'id')] | ||
| 18 | private Prestation|null $presta = null; | ||
| 19 | |||
| 20 | #[ORM\Column] | ||
| 21 | private string $taches; | ||
| 22 | #[ORM\Column] | ||
| 23 | private float $total_main_d_oeuvre; | ||
| 24 | #[ORM\Column] | ||
| 25 | private string $pieces; | ||
| 26 | #[ORM\Column] | ||
| 27 | private float $total_pieces; | ||
| 28 | #[ORM\Column] | ||
| 29 | private float $deplacement; | ||
| 30 | #[ORM\Column] | ||
| 31 | private float $prix_devis; | ||
| 32 | #[ORM\Column] | ||
| 33 | private float $total_HT; | ||
| 34 | #[ORM\Column] | ||
| 35 | private string $delai_livraison; | ||
| 36 | #[ORM\Column] | ||
| 37 | private string $validite_devis; | ||
| 38 | #[ORM\Column (options: ['default' => 'non'])] | ||
| 39 | private string $signature_devis = 'non'; | ||
| 40 | |||
| 41 | public static EntityManager $entityManager; | ||
| 42 | |||
| 43 | public function __construct(Prestation $presta = null) | ||
| 44 | { | ||
| 45 | if($presta != null) | ||
| 46 | { | ||
| 47 | $this->setPresta($presta); | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | // getters | ||
| 52 | public function getPresta(): Prestation | ||
| 53 | { | ||
| 54 | return $this->presta; | ||
| 55 | } | ||
| 56 | public function getAll(): array | ||
| 57 | { | ||
| 58 | // n'utiliser get_object_vars() qu'avec une entité parce qu'on maîtrise le nombre de propriétés | ||
| 59 | return get_object_vars($this); | ||
| 60 | } | ||
| 61 | |||
| 62 | public function getAllWithWindowFields(): array | ||
| 63 | { | ||
| 64 | //~ $taches = ["Tâches:" => $this->taches]; | ||
| 65 | //~ $champs_communs = [ | ||
| 66 | //~ "Total Main d'oeuvre:" => $this->total_main_d_oeuvre, | ||
| 67 | //~ "Pièces:" => $this->pieces, | ||
| 68 | //~ "Total des pièces:" => $this->total_pieces, | ||
| 69 | //~ "Déplacement:" => $this->deplacement, | ||
| 70 | //~ "Total HT:" => $this->total_HT]; | ||
| 71 | //~ $champs_devis = [ | ||
| 72 | //~ "Delai de livraison:" => $this->delai_livraison, | ||
| 73 | //~ "Durée de validité:" => $this->validite_devis, | ||
| 74 | //~ "Devis signé:" => $this->signature_devis]; | ||
| 75 | //~ return $champs_communs + $champs_devis; | ||
| 76 | return [ | ||
| 77 | "Tâches:" => $this->taches, // JUSTE AJOUTÉ | ||
| 78 | "Total Main d'oeuvre:" => $this->total_main_d_oeuvre, | ||
| 79 | "Pièces:" => $this->pieces, | ||
| 80 | "Total des pièces:" => $this->total_pieces, | ||
| 81 | "Déplacement:" => $this->deplacement, | ||
| 82 | "Total HT:" => $this->total_HT, | ||
| 83 | "Delai de livraison:" => $this->delai_livraison, | ||
| 84 | "Durée de validité:" => $this->validite_devis, | ||
| 85 | "Devis signé:" => $this->signature_devis]; | ||
| 86 | } | ||
| 87 | |||
| 88 | // setters | ||
| 89 | public function set(string $entry, string $input) // trouve la bonne méthode | ||
| 90 | { | ||
| 91 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide | ||
| 92 | switch($entry) | ||
| 93 | { | ||
| 94 | case "Tâches:": | ||
| 95 | $this->setTaches($input); | ||
| 96 | break; | ||
| 97 | case "Total Main d'oeuvre:": | ||
| 98 | $this->setTotalMainDOeuvre($input); | ||
| 99 | break; | ||
| 100 | case "Pièces:": | ||
| 101 | $this->setPieces($input); | ||
| 102 | break; | ||
| 103 | case "Total des pièces:": | ||
| 104 | $this->setTotalPieces($input); | ||
| 105 | break; | ||
| 106 | case "Déplacement:": | ||
| 107 | $this->setDeplacement($input); | ||
| 108 | break; | ||
| 109 | case "Prix du devis:": | ||
| 110 | $this->setPrixDevis($input); | ||
| 111 | break; | ||
| 112 | case "Total HT:": | ||
| 113 | $this->setTotalHT($input); | ||
| 114 | break; | ||
| 115 | case "Delai de livraison:": | ||
| 116 | $this->setDelaiLivraison($input); | ||
| 117 | break; | ||
| 118 | case "Durée de validité:": | ||
| 119 | $this->setValiditedevis($input); | ||
| 120 | break; | ||
| 121 | case "Devis signé:": | ||
| 122 | $this->setSignatureDevis($input); | ||
| 123 | break; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | private function setPresta(Prestation $input) // private? | ||
| 127 | { | ||
| 128 | $this->presta = $input; | ||
| 129 | } | ||
| 130 | public function setTaches(string $value) | ||
| 131 | { | ||
| 132 | $this->taches = $value; | ||
| 133 | return($this); | ||
| 134 | } | ||
| 135 | public function setTotalMainDOeuvre($value) | ||
| 136 | { | ||
| 137 | $value = str_replace(',', '.', $value); | ||
| 138 | $this->total_main_d_oeuvre = (float) $value; // float "nettoie" tous les caractères après le dernier chiffre trouvé (ex: 50€ => 50, abc => 0) | ||
| 139 | return($this); | ||
| 140 | } | ||
| 141 | public function setPieces(string $value) | ||
| 142 | { | ||
| 143 | $this->pieces = $value; | ||
| 144 | return($this); | ||
| 145 | } | ||
| 146 | public function setTotalPieces($value) | ||
| 147 | { | ||
| 148 | $value = str_replace(',', '.', $value); | ||
| 149 | $this->total_pieces = (float) $value; | ||
| 150 | return($this); | ||
| 151 | } | ||
| 152 | public function setDeplacement($value) | ||
| 153 | { | ||
| 154 | $value = str_replace(',', '.', $value); | ||
| 155 | $this->deplacement = (float) $value; | ||
| 156 | return($this); | ||
| 157 | } | ||
| 158 | public function setTotalHT($value) | ||
| 159 | { | ||
| 160 | $value = str_replace(',', '.', $value); | ||
| 161 | $this->total_HT = (float) $value; | ||
| 162 | return($this); | ||
| 163 | } | ||
| 164 | public function setPrixDevis($value) | ||
| 165 | { | ||
| 166 | $value = str_replace(',', '.', $value); | ||
| 167 | $this->prix_devis = (float) $value; | ||
| 168 | return($this); | ||
| 169 | } | ||
| 170 | public function setDelaiLivraison(string $value) | ||
| 171 | { | ||
| 172 | $this->delai_livraison = $value; | ||
| 173 | return($this); | ||
| 174 | } | ||
| 175 | public function setValiditedevis(string $value) | ||
| 176 | { | ||
| 177 | $this->validite_devis = $value; | ||
| 178 | return($this); | ||
| 179 | } | ||
| 180 | public function setSignatureDevis(string $value) | ||
| 181 | { | ||
| 182 | $this->signature_devis = $value; | ||
| 183 | return($this); | ||
| 184 | } | ||
| 185 | |||
| 186 | private function setAll(array $input) // private? | ||
| 187 | { | ||
| 188 | $this->taches = $input[0]; | ||
| 189 | $this->total_main_d_oeuvre = (float)$input[1]; | ||
| 190 | $this->pieces = $input[2]; | ||
| 191 | $this->total_pieces = (float)$input[3]; | ||
| 192 | $this->deplacement = (float)$input[4]; | ||
| 193 | $this->prix_devis = (float)$input[5]; | ||
| 194 | $this->total_HT = (float)$input[6]; | ||
| 195 | $this->delai_livraison = $input[7]; | ||
| 196 | $this->validite_devis = $input[8]; | ||
| 197 | |||
| 198 | // $signature_devis est renseigné plus tard en modifiant le devis | ||
| 199 | } | ||
| 200 | |||
| 201 | // à mettre plus tard dans une classe mère | ||
| 202 | protected function cleanSpecialChars(string $data): string | ||
| 203 | { | ||
| 204 | $search = ['"']; | ||
| 205 | return str_replace($search, '', $data); | ||
| 206 | } | ||
| 207 | // à mettre plus tard dans une classe mère | ||
| 208 | public function hydrate(string $answers) | ||
| 209 | { | ||
| 210 | $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide | ||
| 211 | if($answers == '') | ||
| 212 | { | ||
| 213 | echo "erreur de Devis::hydrate(), la chaine \$answers est vide.\n"; | ||
| 214 | return false; | ||
| 215 | } | ||
| 216 | $data_array = explode('|', $answers); // array | ||
| 217 | |||
| 218 | $check = false; | ||
| 219 | if(count($data_array) === 9) // facture normale | ||
| 220 | { | ||
| 221 | $this->getPresta()->setModePaiement(''); // sécurité, doctrine plante si "null" | ||
| 222 | $this->setAll($data_array); | ||
| 223 | } | ||
| 224 | else | ||
| 225 | { | ||
| 226 | echo "erreur de Devis::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; | ||
| 227 | return false; | ||
| 228 | } | ||
| 229 | |||
| 230 | //self::$entityManager->persist('Prestation'); | ||
| 231 | self::$entityManager->persist($this); // $Presta avec en cascade! | ||
| 232 | self::$entityManager->flush(); | ||
| 233 | } | ||
| 234 | |||
| 235 | // création d'une facture à partir d'un devis | ||
| 236 | public static function getQuotation(Prestation $Quotation) | ||
| 237 | { | ||
| 238 | $repository = self::$entityManager->getRepository('Devis'); | ||
| 239 | return $repository->findOneBy(['presta' => $Quotation->getId()]); // ne peut y en avoir deux | ||
| 240 | } | ||
| 241 | } | ||
diff --git a/src/model/entities/Facture.php b/src/model/entities/Facture.php new file mode 100644 index 0000000..3a8a551 --- /dev/null +++ b/src/model/entities/Facture.php | |||
| @@ -0,0 +1,261 @@ | |||
| 1 | <?php | ||
| 2 | // src/entities/Facture.php | ||
| 3 | |||
| 4 | use Doctrine\ORM\Mapping as ORM; | ||
| 5 | use Doctrine\ORM\EntityManager; | ||
| 6 | |||
| 7 | #[ORM\Entity] | ||
| 8 | #[ORM\Table(name: 'factures')] | ||
| 9 | class Facture | ||
| 10 | { | ||
| 11 | #[ORM\Id] | ||
| 12 | #[ORM\Column(type: 'integer')] | ||
| 13 | #[ORM\GeneratedValue] | ||
| 14 | private int|null $id = null; | ||
| 15 | |||
| 16 | #[ORM\ManyToOne(targetEntity: Prestation::class, cascade: ['persist'])] | ||
| 17 | #[ORM\JoinColumn(name: 'id_presta', referencedColumnName: 'id')] | ||
| 18 | private Prestation|null $presta = null; | ||
| 19 | |||
| 20 | #[ORM\Column] | ||
| 21 | private string $taches; | ||
| 22 | #[ORM\Column] | ||
| 23 | private string $machine; | ||
| 24 | #[ORM\Column] | ||
| 25 | private string $OS; | ||
| 26 | #[ORM\Column] | ||
| 27 | private string $donnees; | ||
| 28 | #[ORM\Column] | ||
| 29 | private string $cles_licences; | ||
| 30 | #[ORM\Column] | ||
| 31 | private float $total_main_d_oeuvre; | ||
| 32 | #[ORM\Column] | ||
| 33 | private string $pieces; | ||
| 34 | #[ORM\Column] | ||
| 35 | private float $total_pieces; | ||
| 36 | #[ORM\Column] | ||
| 37 | private float $deplacement; | ||
| 38 | #[ORM\Column] | ||
| 39 | private float $total_HT; | ||
| 40 | |||
| 41 | public static EntityManager $entityManager; | ||
| 42 | |||
| 43 | public function __construct(Prestation $presta = null) | ||
| 44 | { | ||
| 45 | if($presta != null) | ||
| 46 | { | ||
| 47 | $this->setPresta($presta); | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | // getters | ||
| 52 | public function getPresta(): Prestation | ||
| 53 | { | ||
| 54 | return $this->presta; | ||
| 55 | } | ||
| 56 | public function getAll(): array | ||
| 57 | { | ||
| 58 | // n'utiliser get_object_vars() qu'avec une entité parce qu'on maîtrise le nombre de propriétés | ||
| 59 | return get_object_vars($this); | ||
| 60 | } | ||
| 61 | |||
| 62 | public function getAllWithWindowFields(): array | ||
| 63 | { | ||
| 64 | //~ $taches = ["Tâches:" => $this->taches]; | ||
| 65 | //~ $champs_facture = [ | ||
| 66 | //~ "PC:" => $this->machine, | ||
| 67 | //~ "OS:" => $this->OS, | ||
| 68 | //~ "Données:" => $this->donnees, | ||
| 69 | //~ "Clés de licences:" => $this->cles_licences]; | ||
| 70 | //~ $champs_communs = [ | ||
| 71 | //~ "Total Main d'oeuvre:" => $this->total_main_d_oeuvre, | ||
| 72 | //~ "Pièces:" => $this->pieces, | ||
| 73 | //~ "Total des pièces:" => $this->total_pieces, | ||
| 74 | //~ "Déplacement:" => $this->deplacement, | ||
| 75 | //~ "Total HT:" => $this->total_HT]; | ||
| 76 | //return $taches + $champs_facture + $champs_communs; | ||
| 77 | return [ | ||
| 78 | "Tâches:" => $this->taches, | ||
| 79 | "PC:" => $this->machine, | ||
| 80 | "OS:" => $this->OS, | ||
| 81 | "Données:" => $this->donnees, | ||
| 82 | "Clés de licences:" => $this->cles_licences, | ||
| 83 | "Total Main d'oeuvre:" => $this->total_main_d_oeuvre, | ||
| 84 | "Pièces:" => $this->pieces, | ||
| 85 | "Total des pièces:" => $this->total_pieces, | ||
| 86 | "Déplacement:" => $this->deplacement, | ||
| 87 | "Total HT:" => $this->total_HT]; | ||
| 88 | } | ||
| 89 | |||
| 90 | // setters | ||
| 91 | public function set(string $entry, string $input) // trouve la bonne méthode | ||
| 92 | { | ||
| 93 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide | ||
| 94 | switch($entry) | ||
| 95 | { | ||
| 96 | case "Tâches:": | ||
| 97 | $this->setTaches($input); | ||
| 98 | break; | ||
| 99 | case "PC:": | ||
| 100 | $this->setMachine($input); | ||
| 101 | break; | ||
| 102 | case "OS:": | ||
| 103 | $this->setOS($input); | ||
| 104 | break; | ||
| 105 | case "Données:": | ||
| 106 | $this->setDonnees($input); | ||
| 107 | break; | ||
| 108 | case "Clés de licences:": | ||
| 109 | $this->setClesLicences($input); | ||
| 110 | break; | ||
| 111 | case "Total Main d'oeuvre:": | ||
| 112 | $this->setTotalMainDOeuvre($input); | ||
| 113 | break; | ||
| 114 | case "Pièces:": | ||
| 115 | $this->setPieces($input); | ||
| 116 | break; | ||
| 117 | case "Total des pièces:": | ||
| 118 | $this->setTotalPieces($input); | ||
| 119 | break; | ||
| 120 | case "Déplacement:": | ||
| 121 | $this->setDeplacement($input); | ||
| 122 | break; | ||
| 123 | case "Total HT:": | ||
| 124 | $this->setTotalHT($input); | ||
| 125 | break; | ||
| 126 | } | ||
| 127 | } | ||
| 128 | public function setPresta(Prestation $input) // private? | ||
| 129 | { | ||
| 130 | $this->presta = $input; | ||
| 131 | } | ||
| 132 | public function setTaches(string $value) | ||
| 133 | { | ||
| 134 | $this->taches = $value; | ||
| 135 | return($this); | ||
| 136 | } | ||
| 137 | public function setMachine(string $value) | ||
| 138 | { | ||
| 139 | $this->machine = $value; | ||
| 140 | return($this); | ||
| 141 | } | ||
| 142 | public function setOS(string $value) | ||
| 143 | { | ||
| 144 | $this->OS = $value; | ||
| 145 | return($this); | ||
| 146 | } | ||
| 147 | public function setDonnees(string $value) | ||
| 148 | { | ||
| 149 | $this->donnees = $value; | ||
| 150 | return($this); | ||
| 151 | } | ||
| 152 | public function setClesLicences(string $value) | ||
| 153 | { | ||
| 154 | $this->cles_licences = $value; | ||
| 155 | return($this); | ||
| 156 | } | ||
| 157 | public function setTotalMainDOeuvre($value) | ||
| 158 | { | ||
| 159 | $value = str_replace(',', '.', $value); | ||
| 160 | $this->total_main_d_oeuvre = (float) $value; // float "nettoie" tous les caractères après le dernier chiffre trouvé (ex: 50€ => 50, abc => 0) | ||
| 161 | return($this); | ||
| 162 | } | ||
| 163 | public function setPieces(string $value) | ||
| 164 | { | ||
| 165 | $this->pieces = $value; | ||
| 166 | return($this); | ||
| 167 | } | ||
| 168 | public function setTotalPieces($value) | ||
| 169 | { | ||
| 170 | $value = str_replace(',', '.', $value); | ||
| 171 | $this->total_pieces = (float) $value; | ||
| 172 | return($this); | ||
| 173 | } | ||
| 174 | public function setDeplacement($value) | ||
| 175 | { | ||
| 176 | $value = str_replace(',', '.', $value); | ||
| 177 | $this->deplacement = (float) $value; | ||
| 178 | return($this); | ||
| 179 | } | ||
| 180 | public function setTotalHT($value) | ||
| 181 | { | ||
| 182 | $value = str_replace(',', '.', $value); | ||
| 183 | $this->total_HT = (float) $value; | ||
| 184 | return($this); | ||
| 185 | } | ||
| 186 | |||
| 187 | private function setAll(array $input) // private? | ||
| 188 | { | ||
| 189 | $this->taches = $input[0]; | ||
| 190 | $this->machine = $input[1]; | ||
| 191 | $this->OS = $input[2]; | ||
| 192 | $this->donnees = $input[3]; | ||
| 193 | $this->cles_licences = $input[4]; | ||
| 194 | $this->total_main_d_oeuvre = (float)$input[5]; | ||
| 195 | $this->pieces = $input[6]; | ||
| 196 | $this->total_pieces = (float)$input[7]; | ||
| 197 | $this->deplacement = (float)$input[8]; | ||
| 198 | $this->total_HT = (float)$input[9]; | ||
| 199 | } | ||
| 200 | private function setServiceFromQuotation(array $input) // private? | ||
| 201 | { | ||
| 202 | $this->machine = $input[0]; | ||
| 203 | $this->OS = $input[1]; | ||
| 204 | $this->donnees = $input[2]; | ||
| 205 | $this->cles_licences = $input[3]; | ||
| 206 | } | ||
| 207 | |||
| 208 | // à mettre plus tard dans une classe mère | ||
| 209 | protected function cleanSpecialChars(string $data): string | ||
| 210 | { | ||
| 211 | $search = ['"']; | ||
| 212 | return str_replace($search, '', $data); | ||
| 213 | } | ||
| 214 | // à mettre plus tard dans une classe mère | ||
| 215 | public function hydrate(string $answers) | ||
| 216 | { | ||
| 217 | $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide | ||
| 218 | if($answers == '') | ||
| 219 | { | ||
| 220 | echo "erreur de Facture::hydrate(), la chaine \$answers est vide.\n"; | ||
| 221 | return false; | ||
| 222 | } | ||
| 223 | $data_array = explode('|', $answers); // array | ||
| 224 | |||
| 225 | $check = false; | ||
| 226 | if(count($data_array) === 11) // facture normale | ||
| 227 | { | ||
| 228 | $this->getPresta()->setModePaiement($data_array[10]); | ||
| 229 | //array_pop($data_array); // supprime la dernière case | ||
| 230 | unset($data_array[10]); | ||
| 231 | $this->setAll($data_array); | ||
| 232 | } | ||
| 233 | elseif(count($data_array) === 5) // facture à partir d'un devis | ||
| 234 | { | ||
| 235 | $this->getPresta()->setModePaiement($data_array[4]); | ||
| 236 | unset($data_array[4]); | ||
| 237 | $this->setServiceFromQuotation($data_array); | ||
| 238 | } | ||
| 239 | else | ||
| 240 | { | ||
| 241 | echo "erreur de Facture::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; | ||
| 242 | return false; | ||
| 243 | } | ||
| 244 | |||
| 245 | //self::$entityManager->persist('Prestation'); | ||
| 246 | self::$entityManager->persist($this); // $Presta avec en cascade! | ||
| 247 | self::$entityManager->flush(); | ||
| 248 | } | ||
| 249 | |||
| 250 | public function hydrateWithQuotation(Devis $QuotationDetails) | ||
| 251 | { | ||
| 252 | $data = $QuotationDetails->getAll(); | ||
| 253 | //var_dump($data);die; | ||
| 254 | $this->taches = $data['taches']; | ||
| 255 | $this->total_main_d_oeuvre = $data['total_main_d_oeuvre']; | ||
| 256 | $this->pieces = $data['pieces']; | ||
| 257 | $this->total_pieces = $data['total_pieces']; | ||
| 258 | $this->deplacement = $data['deplacement']; | ||
| 259 | $this->total_HT = $data['total_HT']; | ||
| 260 | } | ||
| 261 | } | ||
diff --git a/src/model/entities/Location.php b/src/model/entities/Location.php new file mode 100644 index 0000000..7ce6f0d --- /dev/null +++ b/src/model/entities/Location.php | |||
| @@ -0,0 +1,209 @@ | |||
| 1 | <?php | ||
| 2 | // src/entities/Location.php | ||
| 3 | |||
| 4 | use Doctrine\ORM\Mapping as ORM; | ||
| 5 | use Doctrine\ORM\EntityManager; | ||
| 6 | |||
| 7 | #[ORM\Entity] | ||
| 8 | #[ORM\Table(name: 'locations')] | ||
| 9 | class Location | ||
| 10 | { | ||
| 11 | #[ORM\Id] | ||
| 12 | #[ORM\Column(type: 'integer')] | ||
| 13 | #[ORM\GeneratedValue] | ||
| 14 | private int|null $id = null; | ||
| 15 | |||
| 16 | #[ORM\ManyToOne(targetEntity: Prestation::class, cascade: ['persist'])] | ||
| 17 | #[ORM\JoinColumn(name: 'id_presta', referencedColumnName: 'id')] | ||
| 18 | private Prestation|null $presta = null; | ||
| 19 | |||
| 20 | #[ORM\Column] | ||
| 21 | protected string $designation; | ||
| 22 | #[ORM\Column] | ||
| 23 | protected string $modele_description; | ||
| 24 | #[ORM\Column] | ||
| 25 | protected float $valeur; | ||
| 26 | #[ORM\Column] | ||
| 27 | protected string $etat_des_lieux_debut; | ||
| 28 | #[ORM\Column] | ||
| 29 | protected string $etat_des_lieux_fin = ''; | ||
| 30 | #[ORM\Column] | ||
| 31 | protected string $duree_location; | ||
| 32 | #[ORM\Column] | ||
| 33 | protected float $loyer_hebdo; | ||
| 34 | #[ORM\Column] | ||
| 35 | protected int $loyers_payes; | ||
| 36 | #[ORM\Column] | ||
| 37 | protected int $caution; | ||
| 38 | |||
| 39 | public static EntityManager $entityManager; | ||
| 40 | |||
| 41 | public function __construct(Prestation $presta = null) | ||
| 42 | { | ||
| 43 | if($presta != null) | ||
| 44 | { | ||
| 45 | $this->setPresta($presta); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | // getters | ||
| 50 | public function getPresta(): Prestation | ||
| 51 | { | ||
| 52 | return $this->presta; | ||
| 53 | } | ||
| 54 | public function getAll(): array | ||
| 55 | { | ||
| 56 | // n'utiliser get_object_vars() qu'avec une entité parce qu'on maîtrise le nombre de propriétés | ||
| 57 | return get_object_vars($this); | ||
| 58 | } | ||
| 59 | |||
| 60 | public function getAllWithWindowFields(): array | ||
| 61 | { | ||
| 62 | return [ | ||
| 63 | "Désignation:" => $this->designation, | ||
| 64 | "Description du modèle:" => $this->modele_description, | ||
| 65 | "Valeur:" => $this->valeur, | ||
| 66 | "État des lieux de début:" => $this->etat_des_lieux_debut, | ||
| 67 | "État des lieux de fin:" => $this->etat_des_lieux_fin, | ||
| 68 | "Durée de la location:" => $this->duree_location, | ||
| 69 | "Loyer Hebdomadaire:" => $this->loyer_hebdo, | ||
| 70 | "Loyers Payés:" => $this->loyers_payes, | ||
| 71 | "Caution:" => $this->caution]; | ||
| 72 | } | ||
| 73 | |||
| 74 | // setters | ||
| 75 | public function set(string $entry, string $input) | ||
| 76 | { | ||
| 77 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide | ||
| 78 | switch($entry) | ||
| 79 | { | ||
| 80 | case "Désignation:": | ||
| 81 | $this->setDesignation($input); | ||
| 82 | break; | ||
| 83 | case "Description du modèle:": | ||
| 84 | $this->setModeleDescription($input); | ||
| 85 | break; | ||
| 86 | case "Valeur:": | ||
| 87 | $this->setValeur($input); | ||
| 88 | break; | ||
| 89 | case "État des lieux de début:": | ||
| 90 | $this->setEtatDesLieuxDebut($input); | ||
| 91 | break; | ||
| 92 | case "État des lieux de fin:": | ||
| 93 | $this->setEtatDesLieuxFin($input); | ||
| 94 | break; | ||
| 95 | case "Durée de la location:": | ||
| 96 | $this->setDureeLocation($input); | ||
| 97 | break; | ||
| 98 | case "Loyer Hebdomadaire:": | ||
| 99 | $this->setLoyerHebdo($input); | ||
| 100 | break; | ||
| 101 | case "Loyers Payés:": | ||
| 102 | $this->setLoyersPayes($input); | ||
| 103 | break; | ||
| 104 | case "Caution:": | ||
| 105 | $this->setCaution($input); | ||
| 106 | break; | ||
| 107 | } | ||
| 108 | } | ||
| 109 | private function setPresta(Prestation $input) // private? | ||
| 110 | { | ||
| 111 | $this->presta = $input; | ||
| 112 | } | ||
| 113 | public function setDesignation(string $value) | ||
| 114 | { | ||
| 115 | $this->designation = $value; | ||
| 116 | return($this); | ||
| 117 | } | ||
| 118 | public function setModeleDescription(string $value) | ||
| 119 | { | ||
| 120 | $this->modele_description = $value; | ||
| 121 | return($this); | ||
| 122 | } | ||
| 123 | public function setValeur($value) | ||
| 124 | { | ||
| 125 | $value = str_replace(',', '.', $value); | ||
| 126 | $this->valeur = (float) $value; | ||
| 127 | return($this); | ||
| 128 | } | ||
| 129 | public function setEtatDesLieuxDebut(string $value) | ||
| 130 | { | ||
| 131 | $this->etat_des_lieux_debut = $value; | ||
| 132 | return($this); | ||
| 133 | } | ||
| 134 | public function setEtatDesLieuxFin(string $value) | ||
| 135 | { | ||
| 136 | $this->etat_des_lieux_fin = $value; | ||
| 137 | return($this); | ||
| 138 | } | ||
| 139 | public function setDureeLocation(string $value) | ||
| 140 | { | ||
| 141 | $this->duree_location = $value; | ||
| 142 | return($this); | ||
| 143 | } | ||
| 144 | public function setLoyerMensuel($value) | ||
| 145 | { | ||
| 146 | $value = str_replace(',', '.', $value); | ||
| 147 | $this->loyer_mensuel = (float) $value; | ||
| 148 | return($this); | ||
| 149 | } | ||
| 150 | public function setLoyersPayes($value) | ||
| 151 | { | ||
| 152 | $value = str_replace(',', '.', $value); | ||
| 153 | $this->loyers_payes = (float) $value; | ||
| 154 | return($this); | ||
| 155 | } | ||
| 156 | public function setCaution($value) | ||
| 157 | { | ||
| 158 | $value = str_replace(',', '.', $value); | ||
| 159 | $this->caution = (float) $value; | ||
| 160 | return($this); | ||
| 161 | } | ||
| 162 | |||
| 163 | private function setAll(array $input) // private? | ||
| 164 | { | ||
| 165 | $this->designation = $input[0]; | ||
| 166 | $this->modele_description = $input[1]; | ||
| 167 | $this->valeur = (float)$input[2]; | ||
| 168 | $this->etat_des_lieux_debut = $input[3]; | ||
| 169 | $this->etat_des_lieux_fin = ''; // sécurité | ||
| 170 | $this->duree_location = $input[4]; | ||
| 171 | $this->loyer_hebdo = (float)$input[5]; | ||
| 172 | $this->loyers_payes = (int)$input[6]; | ||
| 173 | $this->caution = (int)$input[7]; | ||
| 174 | } | ||
| 175 | |||
| 176 | // à mettre plus tard dans une classe mère | ||
| 177 | protected function cleanSpecialChars(string $data): string | ||
| 178 | { | ||
| 179 | $search = ['"']; | ||
| 180 | return str_replace($search, '', $data); | ||
| 181 | } | ||
| 182 | // à mettre plus tard dans une classe mère | ||
| 183 | public function hydrate(string $answers) | ||
| 184 | { | ||
| 185 | $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide | ||
| 186 | if($answers == '') | ||
| 187 | { | ||
| 188 | echo "erreur de Location::hydrate(), la chaine \$answers est vide.\n"; | ||
| 189 | return false; | ||
| 190 | } | ||
| 191 | $data_array = explode('|', $answers); // array | ||
| 192 | |||
| 193 | $check = false; | ||
| 194 | if(count($data_array) === 8) | ||
| 195 | { | ||
| 196 | $this->getPresta()->setModePaiement(''); // sécurité, doctrine plante si "null" | ||
| 197 | $this->setAll($data_array); | ||
| 198 | } | ||
| 199 | else | ||
| 200 | { | ||
| 201 | echo "erreur de Location::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; | ||
| 202 | return false; | ||
| 203 | } | ||
| 204 | |||
| 205 | //self::$entityManager->persist('Prestation'); | ||
| 206 | self::$entityManager->persist($this); // $Presta avec en cascade! | ||
| 207 | self::$entityManager->flush(); | ||
| 208 | } | ||
| 209 | } | ||
diff --git a/src/model/entities/Prestation.php b/src/model/entities/Prestation.php new file mode 100644 index 0000000..6d014d8 --- /dev/null +++ b/src/model/entities/Prestation.php | |||
| @@ -0,0 +1,252 @@ | |||
| 1 | <?php | ||
| 2 | // src/entities/Prestation.php | ||
| 3 | |||
| 4 | use Doctrine\ORM\Mapping as ORM; | ||
| 5 | use Doctrine\ORM\EntityManager; | ||
| 6 | |||
| 7 | #[ORM\Entity] | ||
| 8 | #[ORM\Table(name: 'prestations')] | ||
| 9 | class Prestation | ||
| 10 | { | ||
| 11 | #[ORM\Id] | ||
| 12 | #[ORM\Column(type: 'integer')] | ||
| 13 | #[ORM\GeneratedValue] | ||
| 14 | private int|null $id = null; | ||
| 15 | |||
| 16 | #[ORM\ManyToOne(targetEntity: Client::class, cascade: ['persist'])] | ||
| 17 | #[ORM\JoinColumn(name: 'id_client', referencedColumnName: 'id')] | ||
| 18 | private Client|null $client = null; // type int en SQL et dans la base | ||
| 19 | |||
| 20 | #[ORM\Column] | ||
| 21 | private string $code_presta; | ||
| 22 | #[ORM\Column] | ||
| 23 | private int $date; // timestamp unix | ||
| 24 | #[ORM\Column] | ||
| 25 | private string $type_presta; | ||
| 26 | #[ORM\Column] | ||
| 27 | private string $mode_paiement = ''; // non renseigné quand on fait un devis | ||
| 28 | #[ORM\Column] | ||
| 29 | private string $commentaires; | ||
| 30 | |||
| 31 | public static EntityManager $entityManager; | ||
| 32 | |||
| 33 | |||
| 34 | public function __construct(Client $client = null) | ||
| 35 | { | ||
| 36 | if($client != null) | ||
| 37 | { | ||
| 38 | $this->setClient($client); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | // getters | ||
| 43 | public function getId(): int | ||
| 44 | { | ||
| 45 | return $this->id; | ||
| 46 | } | ||
| 47 | public function getCodePresta(): string | ||
| 48 | { | ||
| 49 | return $this->code_presta; | ||
| 50 | } | ||
| 51 | public function getDate(): int | ||
| 52 | { | ||
| 53 | return $this->date; | ||
| 54 | } | ||
| 55 | public function getTypePresta(): string | ||
| 56 | { | ||
| 57 | return $this->type_presta; | ||
| 58 | } | ||
| 59 | public function getClient(): Client | ||
| 60 | { | ||
| 61 | return $this->client; | ||
| 62 | } | ||
| 63 | public function getAll(): array | ||
| 64 | { | ||
| 65 | // n'utiliser get_object_vars() qu'avec une entité parce qu'on maîtrise le nombre de propriétés | ||
| 66 | return get_object_vars($this); | ||
| 67 | } | ||
| 68 | |||
| 69 | public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) | ||
| 70 | { | ||
| 71 | $code_presta_tableau = explode('-', $this->code_presta); | ||
| 72 | $Date = new Dates($this->date); | ||
| 73 | |||
| 74 | return [ | ||
| 75 | //"Numéro prestation:" => end($code_presta_tableau), // crée des conflits, calcul automatique par setCodePresta() | ||
| 76 | "Date:" => $Date->getDate(), | ||
| 77 | //"Type de Presta:" => $this->type_presta, // choix impossible pour le moment | ||
| 78 | "Mode de paiement:" => $this->mode_paiement, // non pertinent pour un devis | ||
| 79 | "Commentaires:" => $this->commentaires]; | ||
| 80 | } | ||
| 81 | |||
| 82 | // setters | ||
| 83 | //~ public function setCodePresta(string $value) | ||
| 84 | //~ { | ||
| 85 | //~ $this->code_presta = $value; | ||
| 86 | //~ return $this; | ||
| 87 | //~ } | ||
| 88 | //public function setDate(int $value) | ||
| 89 | public function setDate(Dates $Date) | ||
| 90 | { | ||
| 91 | //$this->date = (int)$value; // attend un timestamp | ||
| 92 | $this->date = $Date->getTimestamp(); | ||
| 93 | return $this; | ||
| 94 | /*if($set_code_presta) | ||
| 95 | { | ||
| 96 | $code_presta_tableau = explode('-', $this->code_presta); | ||
| 97 | $Date = new Dates($value); | ||
| 98 | $code_presta_tableau[0] = $Date->getYear(); | ||
| 99 | $code_presta_tableau[1] = $Date->getMonth(); | ||
| 100 | $code_presta_tableau[2] = $Date->getDay(); | ||
| 101 | $this->code_presta = implode('-', $code_presta_tableau); | ||
| 102 | }*/ | ||
| 103 | } | ||
| 104 | |||
| 105 | public function setTypePresta(string $value) // appelée dans la section 2 uniquement, pour la 3 on verra plus tard | ||
| 106 | { | ||
| 107 | $this->type_presta = $value; | ||
| 108 | return $this; | ||
| 109 | } | ||
| 110 | public function setModePaiement(string $value) | ||
| 111 | { | ||
| 112 | $this->mode_paiement = $value; | ||
| 113 | return $this; | ||
| 114 | } | ||
| 115 | public function setCommentaires(string $input) | ||
| 116 | { | ||
| 117 | $this->commentaires = $input; | ||
| 118 | } | ||
| 119 | /*public function setAll(array $input) | ||
| 120 | { | ||
| 121 | $this->code_presta = $input[0]; | ||
| 122 | $this->date = $input[1]; | ||
| 123 | $this->type_presta = $input[2]; | ||
| 124 | $this->mode_paiement = $input[3]; | ||
| 125 | $this->commentaires = $input[4]; | ||
| 126 | }*/ | ||
| 127 | |||
| 128 | private function setClient(Client $input) // private? | ||
| 129 | { | ||
| 130 | $this->client = $input; | ||
| 131 | //$input->typeToClient(); // on modifie $client ici (merci les références PHP) | ||
| 132 | } | ||
| 133 | |||
| 134 | public function set(string $entry, $input) // $input = chaîne ou entier | ||
| 135 | { | ||
| 136 | if(gettype($input) === 'string') | ||
| 137 | { | ||
| 138 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide | ||
| 139 | } | ||
| 140 | switch($entry) | ||
| 141 | { | ||
| 142 | // pas de cas "code presta" qui généré par setCodePresta, on peut modifier la date (ici) et le code client (ailleurs) | ||
| 143 | //~ case "Numéro prestation:": | ||
| 144 | //~ $this->setNumeroPresta($input); | ||
| 145 | //~ // modifier le code presta en conséquence | ||
| 146 | //~ break; | ||
| 147 | case "Date:": // inutile, setDate() est appelé directement après choix fenêtre calendrier | ||
| 148 | $this->setDate($input); | ||
| 149 | break; | ||
| 150 | //~ case "Type de Presta:": // choix impossible pour le moment | ||
| 151 | //~ $this->setTypePresta($input); | ||
| 152 | //~ break; | ||
| 153 | case "Mode de paiement:": | ||
| 154 | $this->setModePaiement($input); | ||
| 155 | break; | ||
| 156 | case "Commentaires:": | ||
| 157 | $this->setCommentaires($input); | ||
| 158 | break; | ||
| 159 | } | ||
| 160 | } | ||
| 161 | |||
| 162 | // code presta = année-mois-jour-codeclient-typedepresta-combientièmefois | ||
| 163 | public function setCodePresta(int $increment) // 0 pour modif, 1 pour nouvelle presta | ||
| 164 | { | ||
| 165 | $Date = new Dates($this->date); | ||
| 166 | $repository = self::$entityManager->getRepository('Prestation'); // prestas de tout type d'un client | ||
| 167 | // attention: il peut y avoir plusieurs prestations avec le même numéro au compteur, à améliorer | ||
| 168 | $combientieme_fois = count($repository->findBy(['client' => $this->client->getId()])) + $increment; | ||
| 169 | //var_dump($combientieme_fois); | ||
| 170 | $array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $this->client->getCodeClient(), $this->type_presta, $combientieme_fois]; | ||
| 171 | //~ $array_code[0] = $Date->getYear(); | ||
| 172 | //~ $array_code[1] = $Date->getMonth(); | ||
| 173 | //~ $array_code[2] = $Date->getDay(); | ||
| 174 | //~ $array_code[3] = $this->client->getCodeClient(); // mise à jour éventuelle | ||
| 175 | //~ $array_code[4] = $this->type_presta; | ||
| 176 | $this->code_presta = implode('-', $array_code); | ||
| 177 | return $this; | ||
| 178 | } | ||
| 179 | // combientième fois au choix (ne fonctionne pas avec setCodePresta qui recalculera ce numéro automatiquement à la prochaine modification) | ||
| 180 | //~ public function setNumeroPresta($value) | ||
| 181 | //~ { | ||
| 182 | //~ // modifier le code presta, on pourrait aussi utiliser une regex | ||
| 183 | //~ $code_presta_tableau = explode('-', $this->code_presta); | ||
| 184 | //~ $code_presta_tableau[count($code_presta_tableau) - 1] = (int) $value; // dernière case du tableau | ||
| 185 | //~ $this->code_presta = implode('-', $code_presta_tableau); | ||
| 186 | //~ return $this; | ||
| 187 | //~ } | ||
| 188 | |||
| 189 | public static function getServices(Client $Customer, string $type = '') | ||
| 190 | { | ||
| 191 | echo "debug: recherche d'une prestation\n"; | ||
| 192 | |||
| 193 | // requête DQL qui fait la même chose que le findBy plus bas | ||
| 194 | /*$query = self::$entityManager->createQuery('SELECT u FROM Prestation u WHERE u.client = :id_client AND u.type_presta = :type_presta'); | ||
| 195 | $query->setParameter('id_client', $Customer->getId()); | ||
| 196 | $query->setParameter('type_presta', $type); | ||
| 197 | $query_result = $query->getResult(); | ||
| 198 | var_dump($query_result);die;*/ | ||
| 199 | |||
| 200 | $repository = self::$entityManager->getRepository('Prestation'); | ||
| 201 | $find_by = ['client' => $Customer->getId()]; | ||
| 202 | if($type != '') | ||
| 203 | { | ||
| 204 | $find_by['type_presta'] = 'devis'; | ||
| 205 | } | ||
| 206 | $PrestaList = $repository->findBy($find_by); | ||
| 207 | |||
| 208 | // le même tableau avec pour clés les id des objets | ||
| 209 | $PrestaListIdKeys = []; | ||
| 210 | foreach($PrestaList as $Presta) | ||
| 211 | { | ||
| 212 | $id = $Presta->getId(); | ||
| 213 | $PrestaListIdKeys[$id] = $Presta; | ||
| 214 | } | ||
| 215 | |||
| 216 | // fenêtre | ||
| 217 | $entrees = []; | ||
| 218 | foreach($PrestaListIdKeys as $Presta) | ||
| 219 | { | ||
| 220 | $id = $Presta->getId(); | ||
| 221 | $entrees[$id][] = $id; | ||
| 222 | $Date = new Dates((int)$Presta->getDate()); // envoi du timestamp, (int) est là par sécurité | ||
| 223 | $entrees[$id][] = $Date->getDate(); | ||
| 224 | $entrees[$id][] = $Presta->getTypePresta(); | ||
| 225 | $entrees[$id][] = $Presta->getCodePresta(); | ||
| 226 | } | ||
| 227 | |||
| 228 | // pas à la bonne place, couper la fonction en deux et mettre ça ailleurs! | ||
| 229 | $ResultatsRecherchePresta = new ZenityList(ZenitySetup::$resultats_recherche_presta['text'], []); | ||
| 230 | $ResultatsRecherchePresta->setListRows($entrees, 4); | ||
| 231 | |||
| 232 | // choix de l'utilisateur | ||
| 233 | $input = exec($ResultatsRecherchePresta->get()); // $input est l'ID de la prestation | ||
| 234 | //echo "input = " . $input . "\n"; | ||
| 235 | if($input == '') | ||
| 236 | { | ||
| 237 | echo "debug: recherche annulée ou saisie vide\n"; | ||
| 238 | return 0; | ||
| 239 | } | ||
| 240 | else | ||
| 241 | { | ||
| 242 | return $PrestaListIdKeys[$input]; | ||
| 243 | } | ||
| 244 | } | ||
| 245 | |||
| 246 | // à mettre plus tard dans une classe mère | ||
| 247 | private function cleanSpecialChars(string $data): string | ||
| 248 | { | ||
| 249 | $search = ['"']; | ||
| 250 | return str_replace($search, '', $data); | ||
| 251 | } | ||
| 252 | } | ||
