summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Config.php1
-rw-r--r--src/Dates.php140
-rw-r--r--src/Latex.php26
-rw-r--r--src/main.php2
-rw-r--r--src/model/entities/Prestation.php43
-rw-r--r--src/sections/2_service.php10
-rw-r--r--src/sections/3_modify_data.php44
7 files changed, 53 insertions, 213 deletions
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
20 static public string $publishing = 'scribus'; 20 static public string $publishing = 'scribus';
21 static public string $sgbd = 'sqlite'; 21 static public string $sgbd = 'sqlite';
22 static public string $sqlite_gui = 'sqlitebrowser'; // ne pas utiliser si le sgbd n'est pas sqlite 22 static public string $sqlite_gui = 'sqlitebrowser'; // ne pas utiliser si le sgbd n'est pas sqlite
23 static public string $date_format = 'euro';
24 static public string $file_explorer = 'xdg-open'; // ouvre l'explorateur de fichiers par défaut quand suivi d'un chemin en paramètre 23 static public string $file_explorer = 'xdg-open'; // ouvre l'explorateur de fichiers par défaut quand suivi d'un chemin en paramètre
25 24
26 // ça pourrait être bien de founir sqlite avec l'application pour supprimer une dépendance 25 // ç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 @@
1<?php
2// src/DateTimestamp.php
3//
4// attention à strtotime(), php "devine" le format de la date selon qu'elle comporte des slashs / ou des tirets -
5// pour php une date avec des slashs / est américaine, mais si on fait comme ça aussi par ici
6
7class Dates
8{
9 private $date = '';
10 static public $date_format = 'euro'; // dates européennes jj-mm-aaaa (EU) ou américaines mm/dd/yyyy (US)
11
12 private $day = '';
13 private $month = '';
14 private $year = '';
15
16 private $timestamp = 0; // valeurs négatives autorisées => dates avant 1970
17
18 public function __construct($input = NULL)
19 {
20 if(gettype($input) === 'string' && $input !== '') // une date est attendue
21 {
22 $this->setDate($input);
23 }
24 elseif(gettype($input) === 'integer' && $input !== 0)
25 {
26 $this->setTimestamp($input);
27 $this->setDayMonthYear($this->date);
28 }
29 }
30
31
32 // getters
33 public function getDate(): string
34 {
35 return $this->date;
36 }
37 public function getDay(): string
38 {
39 return $this->day;
40 }
41 public function getMonth(): string
42 {
43 return $this->month;
44 }
45 public function getYear(): string
46 {
47 return $this->year;
48 }
49
50 public function getTimestamp(): int
51 {
52 return $this->timestamp;
53 }
54
55
56 // setters
57 public function setDate(string $input)
58 {
59 $input = $this->dashOrSlash($input); // formate pour strtotime()
60 $this->setDayMonthYear($input);
61
62 if(checkdate($this->month, $this->day, $this->year)) // checkdate() veut un format américain
63 {
64 $this->date = $input;
65 $this->timestamp = strtotime($input); // date (string) -> timestamp (int)
66 // strtotime() devine le format en analysant la chaîne en entrée, on l'aide un peu
67 // avec des /, php considère que la date est américaine
68 // avec des - ou des ., php considère que la date est européenne
69 }
70 else
71 {
72 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.");
73 die();
74 }
75 }
76
77 public function setTimestamp(int $input)
78 {
79 $this->timestamp = $input;
80 $this->date = $this->timestampToDate($input); // timestamp (int) -> date (string)
81 }
82
83 public function setDayMonthYear(string $input)
84 {
85 $splitedDate = preg_split('#\D#', $input); // \D = tout sauf chiffre
86
87 if(self::$date_format === 'euro')
88 {
89 $this->day = $splitedDate[0];
90 $this->month = $splitedDate[1];
91 }
92 elseif(self::$date_format === 'usa')
93 {
94 $this->day = $splitedDate[1];
95 $this->month = $splitedDate[0];
96 }
97 else
98 {
99 echo("Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur 'euro' ou 'usa'");
100 die(); // brutal
101 }
102 $this->year = $splitedDate[2];
103 }
104
105 private function dashOrSlash(string $date): string
106 {
107 if(self::$date_format === 'euro')
108 {
109 // change jj/mm/aaaa en jj-mm-aaaa
110 return(preg_replace('#\D#', '-', $date)); // \D = tout sauf chiffre
111 }
112 elseif(self::$date_format === 'usa')
113 {
114 // change mm-dd.yyyy en mm/dd/yyyy
115 return(preg_replace('#\D#', '/', $date));
116 }
117 else
118 {
119 echo("Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur 'euro' ou 'usa'");
120 die(); // brutal
121 }
122 }
123
124 private function timestampToDate(int $timestamp): string
125 {
126 if(self::$date_format === 'euro')
127 {
128 return(date("d-m-Y", $timestamp));
129 }
130 elseif(self::$date_format === 'usa')
131 {
132 return(date("m/d/Y", $timestamp));
133 }
134 else
135 {
136 echo("Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur 'euro' ou 'usa'");
137 die(); // brutal
138 }
139 }
140}
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
12 protected array $data = []; // données à insérer dans le template 12 protected array $data = []; // données à insérer dans le template
13 protected string $latex; // latex pur 13 protected string $latex; // latex pur
14 14
15 static function makeInstance(string $type) 15 static function makeInstance(string $type): ?Latex
16 { 16 {
17 switch($type) 17 switch($type)
18 { 18 {
@@ -38,6 +38,7 @@ abstract class Latex
38 // erreur 38 // erreur
39 default: 39 default:
40 echo "erreur, la sous-classe latex à initialiser n'existe pas\n"; 40 echo "erreur, la sous-classe latex à initialiser n'existe pas\n";
41 return null;
41 } 42 }
42 } 43 }
43 44
@@ -98,34 +99,23 @@ abstract class Latex
98 99
99abstract class PrestaLatex extends Latex 100abstract class PrestaLatex extends Latex
100{ 101{
101 protected Dates $Date; 102 protected array $date_array; // [année, mois, jour]
102 103
103 public function setData(Object $Object): self 104 public function setData(Object $Object): Latex // polymorphisme
104 { 105 {
105 $this->data = array_merge($this->data, $Object->getAll()); // nécessite des tableaux associatifs 106 $this->data = array_merge($this->data, $Object->getAll()); // nécessite des tableaux associatifs
106 107
107 if(get_class($Object) === 'Prestation') 108 if(get_class($Object) === 'Prestation')
108 { 109 {
109 $this->file_name = $Object->getCodePresta() . '.tex'; 110 $this->file_name = $Object->getCodePresta() . '.tex';
110 $this->makeDateInstance($Object->getDate()); // paramètre = int 111 $this->date_array = explode('-', $Object->getdate());
111 112 $this->latex_path = Config::$latex_path . $this->date_array[0] . '/';
112 $this->latex_path = Config::$latex_path . $this->Date->getYear() . '/'; 113 $this->pdf_path = Config::$pdf_path . $this->date_array[0] . '/';
113 $this->pdf_path = Config::$pdf_path . $this->Date->getYear() . '/';
114 } 114 }
115 115
116 return $this; // pour chainer les méthodes 116 return $this; // pour chainer les méthodes
117 } 117 }
118 118
119 //~ public function getYear(): string // parce que Dates::getDate() retourne une chaine
120 //~ {
121 //~ return $this->year;
122 //~ }
123
124 protected function makeDateInstance(int $timestamp)
125 {
126 $this->Date = new Dates($timestamp);
127 }
128
129 // forme = code-presta.tex 119 // forme = code-presta.tex
130 //~ protected function nameTheFile(string $quoi, string $codePresta) 120 //~ protected function nameTheFile(string $quoi, string $codePresta)
131 //~ { 121 //~ {
@@ -135,7 +125,7 @@ abstract class PrestaLatex extends Latex
135 public function makeLatex() 125 public function makeLatex()
136 { 126 {
137 $data = $this->data; 127 $data = $this->data;
138 $date = preg_replace('#\D#', '/', $this->Date->getDate()); // date avec des slashs / parce que j'aime bien 128 $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
139 129
140 // on obtient la variable $latex avec ob_get_clean() 130 // on obtient la variable $latex avec ob_get_clean()
141 // le include() ici, c'est du génie ou c'est moche ou les deux? 131 // 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
25$x_term_command = ''; // commande terminal en mode graphique 25$x_term_command = ''; // commande terminal en mode graphique
26 26
27require 'src/dependances.php'; // vérification des dépendances 27require 'src/dependances.php'; // vérification des dépendances
28//~ require 'src/Dates.php'; // gère dates et timestamps
29Dates::$date_format = Config::$date_format; // dates européennes ou américaines
30 28
31// entités doctrine 29// entités doctrine
32require 'src/model/doctrine-bootstrap.php'; // contient aussi un autoloader spécial pour les entités 30require '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
52 { 52 {
53 return $this->code_presta; 53 return $this->code_presta;
54 } 54 }
55 public function getDate(): int 55 public function getDate(): string
56 { 56 {
57 return $this->date; 57 return $this->date;
58 } 58 }
@@ -76,12 +76,9 @@ class Prestation
76 76
77 public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) 77 public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this)
78 { 78 {
79 //$code_presta_tableau = explode('-', $this->code_presta);
80 $Date = new Dates($this->date);
81
82 return [ 79 return [
83 //"Numéro prestation:" => end($code_presta_tableau), // crée des conflits, calcul automatique par setCodePresta() 80 //"Numéro prestation:" => end($code_presta_tableau), // crée des conflits, calcul automatique par setCodePresta()
84 "Date:" => $Date->getDate(), 81 "Date:" => $this->date,
85 //"Type de Presta:" => $this->type_presta, // choix impossible pour le moment 82 //"Type de Presta:" => $this->type_presta, // choix impossible pour le moment
86 "Mode de paiement:" => $this->mode_paiement, // non pertinent pour un devis 83 "Mode de paiement:" => $this->mode_paiement, // non pertinent pour un devis
87 "Commentaires:" => $this->commentaires]; 84 "Commentaires:" => $this->commentaires];
@@ -112,10 +109,9 @@ class Prestation
112 //~ return $this; 109 //~ return $this;
113 //~ } 110 //~ }
114 //public function setDate(int $value) 111 //public function setDate(int $value)
115 public function setDate(Dates $Date) 112 public function setDate(string $date): Prestation
116 { 113 {
117 //$this->date = (int)$value; // attend un timestamp 114 $this->date = $date;
118 $this->date = $Date->getTimestamp();
119 return $this; 115 return $this;
120 /*if($set_code_presta) 116 /*if($set_code_presta)
121 { 117 {
@@ -157,11 +153,9 @@ class Prestation
157 //$input->typeToClient(); // on modifie $client ici (merci les références PHP) 153 //$input->typeToClient(); // on modifie $client ici (merci les références PHP)
158 } 154 }
159 155
160 public function set(string $entry, string|Dates $input): void 156 public function set(string $entry, string $input): void
161 { 157 {
162 if(gettype($input) === 'string'){ 158 $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide
163 $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide
164 }
165 159
166 switch($entry){ 160 switch($entry){
167 // pas de cas "code presta" qui généré par setCodePresta, on peut modifier la date (ici) et le code client (ailleurs) 161 // 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
185 } 179 }
186 180
187 // code presta = année-mois-jour-codeclient-typedepresta-combientièmefois 181 // code presta = année-mois-jour-codeclient-typedepresta-combientièmefois
188 public function setCodePresta(int $increment) // 0 pour modif, 1 pour nouvelle presta 182 public function setCodePresta(int $increment): Prestation // 0 pour modif, 1 pour nouvelle presta
189 { 183 {
190 $Date = new Dates($this->date);
191 $repository = self::$entityManager->getRepository('Prestation'); // prestas de tout type d'un client 184 $repository = self::$entityManager->getRepository('Prestation'); // prestas de tout type d'un client
192 // attention: il peut y avoir plusieurs prestations avec le même numéro au compteur, à améliorer 185 // attention: il peut y avoir plusieurs prestations avec le même numéro au compteur, à améliorer
193 $combientieme_fois = count($repository->findBy(['client' => $this->client->getId()])) + $increment; 186 $how_many_times = count($repository->findBy(['client' => $this->client->getId()])) + $increment;
194 //var_dump($combientieme_fois); 187 //var_dump($how_many_times);
195 $array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $this->client->getCodeClient(), $this->type_presta, $combientieme_fois]; 188 $date_array = explode('-', $this->date);
196 //~ $array_code[0] = $Date->getYear(); 189 $array_code = [
197 //~ $array_code[1] = $Date->getMonth(); 190 $date_array[0], // année
198 //~ $array_code[2] = $Date->getDay(); 191 $date_array[1], // mois
199 //~ $array_code[3] = $this->client->getCodeClient(); // mise à jour éventuelle 192 $date_array[2], // jour
200 //~ $array_code[4] = $this->type_presta; 193 $this->client->getCodeClient(), // mise à jour éventuelle
194 $this->type_presta,
195 $how_many_times
196 ];
201 $this->code_presta = implode('-', $array_code); 197 $this->code_presta = implode('-', $array_code);
202 return $this; 198 return $this;
203 } 199 }
@@ -244,8 +240,7 @@ class Prestation
244 { 240 {
245 $id = $Presta->getId(); 241 $id = $Presta->getId();
246 $entrees[$id][] = $id; 242 $entrees[$id][] = $id;
247 $Date = new Dates((int)$Presta->getDate()); // envoi du timestamp, (int) est là par sécurité 243 $entrees[$id][] = $Presta->getDate();
248 $entrees[$id][] = $Date->getDate();
249 $entrees[$id][] = $Presta->getTypePresta(); 244 $entrees[$id][] = $Presta->getTypePresta();
250 $entrees[$id][] = $Presta->getCodePresta(); 245 $entrees[$id][] = $Presta->getCodePresta();
251 } 246 }
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
46 } 46 }
47 47
48 // calendrier - étape 1/3 48 // calendrier - étape 1/3
49 $Date = new Dates(exec($Calendrier->get())); // exec() renvoie soit une chaîne soit un false 49 $date_array = explode('/', exec($Calendrier->get())); // 17/10/2026
50 if($Date->getDate() == '') // on n'a pas cliqué sur "annuler" 50 if(count($date_array) === 1){
51 {
52 echo "debug: annulation à la saisie d'une date\n"; 51 echo "debug: annulation à la saisie d'une date\n";
53 return [0, null]; // menu principal 52 return [2, $Client];
54 } 53 }
55 54
56 $Presta = new Prestation($Client); 55 $Presta = new Prestation($Client);
57 //var_dump($Client);die; 56 //var_dump($Client);die;
58 //$Presta->setDate($Date->getTimestamp()); 57 $Presta->setDate($date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]); // 2026-10-17
59 $Presta->setDate($Date); // envoi d'un objet, la BDD gardera le timestamp
60 58
61 // formulaire - étape 2/3 59 // formulaire - étape 2/3
62 switch($choix_niv2) 60 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
100 return [3, $Client]; // menu précédent 100 return [3, $Client]; // menu précédent
101 } 101 }
102 $type_presta = $Presta->getTypePresta(); 102 $type_presta = $Presta->getTypePresta();
103 switch($type_presta) 103 $classe = '';
104 { 104 switch($type_presta){
105 case 'facture': 105 case 'facture':
106 $classe = 'Facture'; 106 $classe = 'Facture';
107 break; 107 break;
@@ -117,6 +117,8 @@ function modifyData(?Client $Client = null): array
117 case 'non_vendue': 117 case 'non_vendue':
118 $PrestaDetails = null; 118 $PrestaDetails = null;
119 break; 119 break;
120 default:
121 echo "erreur: type de prestation buggué\n";
120 } 122 }
121 if($type_presta != 'non_vendue') 123 if($type_presta != 'non_vendue')
122 { 124 {
@@ -134,29 +136,27 @@ function modifyData(?Client $Client = null): array
134 136
135 if($choix_niv3 === 'Date:') 137 if($choix_niv3 === 'Date:')
136 { 138 {
137 $Date = new Dates(exec($Calendrier->get())); // exec() renvoie soit une chaîne soit un false 139 $date_array = explode('/', exec($Calendrier->get())); // 17/10/2026
138 if($Date->getDate() == '') // clic sur "annuler", touche "échap" 140 if(count($date_array) === 1){
139 {
140 echo "debug: annulation à la saisie d'une date\n"; 141 echo "debug: annulation à la saisie d'une date\n";
142 return [3, $Client];
141 } 143 }
142 else 144
145 // entités et BDD
146 $Presta->set($choix_niv3, $date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]); // 2026-10-09
147 $old_code = $Presta->getCodePresta();
148 $Presta->setCodePresta(0);
149 $Presta::$entityManager->flush();
150
151 // documents
152 if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location')
143 { 153 {
144 // entités et BDD 154 $DocumentPresta = Latex::makeInstance($Presta->getTypePresta()); // $type = facture, devis, location
145 $Presta->set($choix_niv3, $Date); 155 $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails);
146 $old_code = $Presta->getCodePresta(); 156 $DocumentPresta->makeLatex(); // en mémoire
147 $Presta->setCodePresta(0);
148 $Presta::$entityManager->flush();
149 157
150 // documents 158 renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta());
151 if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location') 159 makeTexAndPdf($DocumentPresta); // une nouvelle facture est créée, supprimer l'ancienne ou la renommer avec la nouvelle date
152 {
153 $DocumentPresta = Latex::makeInstance($Presta->getTypePresta()); // $type = facture, devis, location
154 $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails);
155 $DocumentPresta->makeLatex(); // en mémoire
156
157 renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta());
158 makeTexAndPdf($DocumentPresta); // une nouvelle facture est créée, supprimer l'ancienne ou la renommer avec la nouvelle date
159 }
160 } 160 }
161 161
162 return [3, $Client]; // menu précédent 162 return [3, $Client]; // menu précédent
@@ -191,7 +191,7 @@ function modifyData(?Client $Client = null): array
191 if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location') 191 if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location')
192 { 192 {
193 $DocumentPresta = Latex::makeInstance($type_presta); 193 $DocumentPresta = Latex::makeInstance($type_presta);
194 $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); 194 $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); // polymorphisme
195 $DocumentPresta->makeLatex(); 195 $DocumentPresta->makeLatex();
196 196
197 renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); 197 renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta());