From 32843e50aa981f190bdb4fbc9adbeacc06fdf775 Mon Sep 17 00:00:00 2001 From: polo Date: Sat, 17 Oct 2026 23:47:31 +0200 Subject: =?UTF-8?q?retypage=20date=20prestations=20en=20string=203,=20clas?= =?UTF-8?q?se=20Dates=20supprim=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Config.php | 1 - src/Dates.php | 140 -------------------------------------- src/Latex.php | 26 +++---- src/main.php | 2 - src/model/entities/Prestation.php | 43 ++++++------ src/sections/2_service.php | 10 ++- src/sections/3_modify_data.php | 44 ++++++------ 7 files changed, 53 insertions(+), 213 deletions(-) delete mode 100644 src/Dates.php (limited to 'src') diff --git a/src/Config.php b/src/Config.php index eea90bd..0ad6183 100644 --- a/src/Config.php +++ b/src/Config.php @@ -20,7 +20,6 @@ class Config static public string $publishing = 'scribus'; static public string $sgbd = 'sqlite'; static public string $sqlite_gui = 'sqlitebrowser'; // ne pas utiliser si le sgbd n'est pas sqlite - static public string $date_format = 'euro'; static public string $file_explorer = 'xdg-open'; // ouvre l'explorateur de fichiers par défaut quand suivi d'un chemin en paramètre // ça pourrait être bien de founir sqlite avec l'application pour supprimer une dépendance diff --git a/src/Dates.php b/src/Dates.php deleted file mode 100644 index d7ed6c7..0000000 --- a/src/Dates.php +++ /dev/null @@ -1,140 +0,0 @@ - dates avant 1970 - - public function __construct($input = NULL) - { - if(gettype($input) === 'string' && $input !== '') // une date est attendue - { - $this->setDate($input); - } - elseif(gettype($input) === 'integer' && $input !== 0) - { - $this->setTimestamp($input); - $this->setDayMonthYear($this->date); - } - } - - - // getters - public function getDate(): string - { - return $this->date; - } - public function getDay(): string - { - return $this->day; - } - public function getMonth(): string - { - return $this->month; - } - public function getYear(): string - { - return $this->year; - } - - public function getTimestamp(): int - { - return $this->timestamp; - } - - - // setters - public function setDate(string $input) - { - $input = $this->dashOrSlash($input); // formate pour strtotime() - $this->setDayMonthYear($input); - - if(checkdate($this->month, $this->day, $this->year)) // checkdate() veut un format américain - { - $this->date = $input; - $this->timestamp = strtotime($input); // date (string) -> timestamp (int) - // strtotime() devine le format en analysant la chaîne en entrée, on l'aide un peu - // avec des /, php considère que la date est américaine - // avec des - ou des ., php considère que la date est européenne - } - else - { - echo("Date incorrecte, le format de la date dans le fichier config.php est " . self::$date_format . ".\nLes choix possibles sont 'euro' pour Europe et 'usa' pour États-Unis."); - die(); - } - } - - public function setTimestamp(int $input) - { - $this->timestamp = $input; - $this->date = $this->timestampToDate($input); // timestamp (int) -> date (string) - } - - public function setDayMonthYear(string $input) - { - $splitedDate = preg_split('#\D#', $input); // \D = tout sauf chiffre - - if(self::$date_format === 'euro') - { - $this->day = $splitedDate[0]; - $this->month = $splitedDate[1]; - } - elseif(self::$date_format === 'usa') - { - $this->day = $splitedDate[1]; - $this->month = $splitedDate[0]; - } - else - { - echo("Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur 'euro' ou 'usa'"); - die(); // brutal - } - $this->year = $splitedDate[2]; - } - - private function dashOrSlash(string $date): string - { - if(self::$date_format === 'euro') - { - // change jj/mm/aaaa en jj-mm-aaaa - return(preg_replace('#\D#', '-', $date)); // \D = tout sauf chiffre - } - elseif(self::$date_format === 'usa') - { - // change mm-dd.yyyy en mm/dd/yyyy - return(preg_replace('#\D#', '/', $date)); - } - else - { - echo("Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur 'euro' ou 'usa'"); - die(); // brutal - } - } - - private function timestampToDate(int $timestamp): string - { - if(self::$date_format === 'euro') - { - return(date("d-m-Y", $timestamp)); - } - elseif(self::$date_format === 'usa') - { - return(date("m/d/Y", $timestamp)); - } - else - { - echo("Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur 'euro' ou 'usa'"); - die(); // brutal - } - } -} diff --git a/src/Latex.php b/src/Latex.php index 261d35e..f49fdea 100644 --- a/src/Latex.php +++ b/src/Latex.php @@ -12,7 +12,7 @@ abstract class Latex protected array $data = []; // données à insérer dans le template protected string $latex; // latex pur - static function makeInstance(string $type) + static function makeInstance(string $type): ?Latex { switch($type) { @@ -38,6 +38,7 @@ abstract class Latex // erreur default: echo "erreur, la sous-classe latex à initialiser n'existe pas\n"; + return null; } } @@ -98,34 +99,23 @@ abstract class Latex abstract class PrestaLatex extends Latex { - protected Dates $Date; + protected array $date_array; // [année, mois, jour] - public function setData(Object $Object): self + public function setData(Object $Object): Latex // polymorphisme { $this->data = array_merge($this->data, $Object->getAll()); // nécessite des tableaux associatifs if(get_class($Object) === 'Prestation') { $this->file_name = $Object->getCodePresta() . '.tex'; - $this->makeDateInstance($Object->getDate()); // paramètre = int - - $this->latex_path = Config::$latex_path . $this->Date->getYear() . '/'; - $this->pdf_path = Config::$pdf_path . $this->Date->getYear() . '/'; + $this->date_array = explode('-', $Object->getdate()); + $this->latex_path = Config::$latex_path . $this->date_array[0] . '/'; + $this->pdf_path = Config::$pdf_path . $this->date_array[0] . '/'; } return $this; // pour chainer les méthodes } - //~ public function getYear(): string // parce que Dates::getDate() retourne une chaine - //~ { - //~ return $this->year; - //~ } - - protected function makeDateInstance(int $timestamp) - { - $this->Date = new Dates($timestamp); - } - // forme = code-presta.tex //~ protected function nameTheFile(string $quoi, string $codePresta) //~ { @@ -135,7 +125,7 @@ abstract class PrestaLatex extends Latex public function makeLatex() { $data = $this->data; - $date = preg_replace('#\D#', '/', $this->Date->getDate()); // date avec des slashs / parce que j'aime bien + $date = preg_replace('#\D#', '/', $this->date_array[2] . '/' . $this->date_array[1] . '/' . $this->date_array[0]); // 17/10/2026, avec des / parce que j'aime bien // on obtient la variable $latex avec ob_get_clean() // le include() ici, c'est du génie ou c'est moche ou les deux? diff --git a/src/main.php b/src/main.php index 306038c..9b8cf8e 100644 --- a/src/main.php +++ b/src/main.php @@ -25,8 +25,6 @@ $sqlite_cli = ''; // commande sqlite ou sqlite3 $x_term_command = ''; // commande terminal en mode graphique require 'src/dependances.php'; // vérification des dépendances -//~ require 'src/Dates.php'; // gère dates et timestamps -Dates::$date_format = Config::$date_format; // dates européennes ou américaines // entités doctrine require 'src/model/doctrine-bootstrap.php'; // contient aussi un autoloader spécial pour les entités diff --git a/src/model/entities/Prestation.php b/src/model/entities/Prestation.php index fad7d7c..a0489d3 100644 --- a/src/model/entities/Prestation.php +++ b/src/model/entities/Prestation.php @@ -52,7 +52,7 @@ class Prestation { return $this->code_presta; } - public function getDate(): int + public function getDate(): string { return $this->date; } @@ -76,12 +76,9 @@ class Prestation public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) { - //$code_presta_tableau = explode('-', $this->code_presta); - $Date = new Dates($this->date); - return [ //"Numéro prestation:" => end($code_presta_tableau), // crée des conflits, calcul automatique par setCodePresta() - "Date:" => $Date->getDate(), + "Date:" => $this->date, //"Type de Presta:" => $this->type_presta, // choix impossible pour le moment "Mode de paiement:" => $this->mode_paiement, // non pertinent pour un devis "Commentaires:" => $this->commentaires]; @@ -112,10 +109,9 @@ class Prestation //~ return $this; //~ } //public function setDate(int $value) - public function setDate(Dates $Date) + public function setDate(string $date): Prestation { - //$this->date = (int)$value; // attend un timestamp - $this->date = $Date->getTimestamp(); + $this->date = $date; return $this; /*if($set_code_presta) { @@ -157,11 +153,9 @@ class Prestation //$input->typeToClient(); // on modifie $client ici (merci les références PHP) } - public function set(string $entry, string|Dates $input): void + public function set(string $entry, string $input): void { - if(gettype($input) === 'string'){ - $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide - } + $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide switch($entry){ // pas de cas "code presta" qui généré par setCodePresta, on peut modifier la date (ici) et le code client (ailleurs) @@ -185,19 +179,21 @@ class Prestation } // code presta = année-mois-jour-codeclient-typedepresta-combientièmefois - public function setCodePresta(int $increment) // 0 pour modif, 1 pour nouvelle presta + public function setCodePresta(int $increment): Prestation // 0 pour modif, 1 pour nouvelle presta { - $Date = new Dates($this->date); $repository = self::$entityManager->getRepository('Prestation'); // prestas de tout type d'un client // attention: il peut y avoir plusieurs prestations avec le même numéro au compteur, à améliorer - $combientieme_fois = count($repository->findBy(['client' => $this->client->getId()])) + $increment; - //var_dump($combientieme_fois); - $array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $this->client->getCodeClient(), $this->type_presta, $combientieme_fois]; - //~ $array_code[0] = $Date->getYear(); - //~ $array_code[1] = $Date->getMonth(); - //~ $array_code[2] = $Date->getDay(); - //~ $array_code[3] = $this->client->getCodeClient(); // mise à jour éventuelle - //~ $array_code[4] = $this->type_presta; + $how_many_times = count($repository->findBy(['client' => $this->client->getId()])) + $increment; + //var_dump($how_many_times); + $date_array = explode('-', $this->date); + $array_code = [ + $date_array[0], // année + $date_array[1], // mois + $date_array[2], // jour + $this->client->getCodeClient(), // mise à jour éventuelle + $this->type_presta, + $how_many_times + ]; $this->code_presta = implode('-', $array_code); return $this; } @@ -244,8 +240,7 @@ class Prestation { $id = $Presta->getId(); $entrees[$id][] = $id; - $Date = new Dates((int)$Presta->getDate()); // envoi du timestamp, (int) est là par sécurité - $entrees[$id][] = $Date->getDate(); + $entrees[$id][] = $Presta->getDate(); $entrees[$id][] = $Presta->getTypePresta(); $entrees[$id][] = $Presta->getCodePresta(); } diff --git a/src/sections/2_service.php b/src/sections/2_service.php index 9269503..4dccdb9 100644 --- a/src/sections/2_service.php +++ b/src/sections/2_service.php @@ -46,17 +46,15 @@ function newService(?Client $Client = null): array } // calendrier - étape 1/3 - $Date = new Dates(exec($Calendrier->get())); // exec() renvoie soit une chaîne soit un false - if($Date->getDate() == '') // on n'a pas cliqué sur "annuler" - { + $date_array = explode('/', exec($Calendrier->get())); // 17/10/2026 + if(count($date_array) === 1){ echo "debug: annulation à la saisie d'une date\n"; - return [0, null]; // menu principal + return [2, $Client]; } $Presta = new Prestation($Client); //var_dump($Client);die; - //$Presta->setDate($Date->getTimestamp()); - $Presta->setDate($Date); // envoi d'un objet, la BDD gardera le timestamp + $Presta->setDate($date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]); // 2026-10-17 // formulaire - étape 2/3 switch($choix_niv2) diff --git a/src/sections/3_modify_data.php b/src/sections/3_modify_data.php index 607638b..af40ebd 100644 --- a/src/sections/3_modify_data.php +++ b/src/sections/3_modify_data.php @@ -100,8 +100,8 @@ function modifyData(?Client $Client = null): array return [3, $Client]; // menu précédent } $type_presta = $Presta->getTypePresta(); - switch($type_presta) - { + $classe = ''; + switch($type_presta){ case 'facture': $classe = 'Facture'; break; @@ -117,6 +117,8 @@ function modifyData(?Client $Client = null): array case 'non_vendue': $PrestaDetails = null; break; + default: + echo "erreur: type de prestation buggué\n"; } if($type_presta != 'non_vendue') { @@ -134,29 +136,27 @@ function modifyData(?Client $Client = null): array if($choix_niv3 === 'Date:') { - $Date = new Dates(exec($Calendrier->get())); // exec() renvoie soit une chaîne soit un false - if($Date->getDate() == '') // clic sur "annuler", touche "échap" - { + $date_array = explode('/', exec($Calendrier->get())); // 17/10/2026 + if(count($date_array) === 1){ echo "debug: annulation à la saisie d'une date\n"; + return [3, $Client]; } - else + + // entités et BDD + $Presta->set($choix_niv3, $date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]); // 2026-10-09 + $old_code = $Presta->getCodePresta(); + $Presta->setCodePresta(0); + $Presta::$entityManager->flush(); + + // documents + if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location') { - // entités et BDD - $Presta->set($choix_niv3, $Date); - $old_code = $Presta->getCodePresta(); - $Presta->setCodePresta(0); - $Presta::$entityManager->flush(); + $DocumentPresta = Latex::makeInstance($Presta->getTypePresta()); // $type = facture, devis, location + $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); + $DocumentPresta->makeLatex(); // en mémoire - // documents - if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location') - { - $DocumentPresta = Latex::makeInstance($Presta->getTypePresta()); // $type = facture, devis, location - $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); - $DocumentPresta->makeLatex(); // en mémoire - - renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); - makeTexAndPdf($DocumentPresta); // une nouvelle facture est créée, supprimer l'ancienne ou la renommer avec la nouvelle date - } + renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); + makeTexAndPdf($DocumentPresta); // une nouvelle facture est créée, supprimer l'ancienne ou la renommer avec la nouvelle date } return [3, $Client]; // menu précédent @@ -191,7 +191,7 @@ function modifyData(?Client $Client = null): array if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location') { $DocumentPresta = Latex::makeInstance($type_presta); - $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); + $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); // polymorphisme $DocumentPresta->makeLatex(); renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); -- cgit v1.2.3