summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2023-07-04 15:52:55 +0200
committerpolo <ordipolo@gmx.fr>2023-07-04 15:52:55 +0200
commit884493c1fb985adaaa537c11f4350d940cc68cb1 (patch)
tree0f69be88efac2577ed0c203e094b08dcbda1af96 /src
parent22b941b3526dd3aaf6976eb4ed30aa2ecc30f921 (diff)
downloadAppliGestionPHP-884493c1fb985adaaa537c11f4350d940cc68cb1.zip
fonctions fichiers séparées
Diffstat (limited to 'src')
-rw-r--r--src/Latex.php35
-rw-r--r--src/files.php38
-rw-r--r--src/functions.php63
-rw-r--r--src/latex_templates/devis.php2
-rw-r--r--src/latex_templates/enveloppe_recto.php2
-rw-r--r--src/latex_templates/facture.php2
-rw-r--r--src/latex_templates/location.php2
-rwxr-xr-xsrc/main.php5
-rw-r--r--src/model/File.php96
-rw-r--r--src/sections/1_new_service.php28
10 files changed, 211 insertions, 62 deletions
diff --git a/src/Latex.php b/src/Latex.php
index 9ae9435..a766fd6 100644
--- a/src/Latex.php
+++ b/src/Latex.php
@@ -9,6 +9,30 @@ abstract class Latex
9 protected $latexPath = ''; 9 protected $latexPath = '';
10 protected $pdfPath = ''; 10 protected $pdfPath = '';
11 11
12 static function makeLatexSubClass(string $type): Object
13 {
14 switch($type)
15 {
16 // documents pour les clients
17 case 'devis':
18 return new DevisLatex();
19 case 'facture':
20 return new FactireLatex();
21 case 'location':
22 return new LocationLatex();
23 case 'enveloppe_recto':
24 return new EnveloppeRectoLatex();
25 case 'enveloppe_verso':
26 return new EnveloppeVersoLatex();
27
28 // documents pour la compta
29
30 // erreur
31 default:
32 echo 'erreur, la sous-classe latex à initialiser n\'existe pas';
33 }
34 }
35
12 protected function createFile(string $latex, string $fileName, string $latexPath) 36 protected function createFile(string $latex, string $fileName, string $latexPath)
13 { 37 {
14 // nom du fichier créé = nom.tex 38 // nom du fichier créé = nom.tex
@@ -24,6 +48,7 @@ abstract class Latex
24} 48}
25 49
26 50
51
27abstract class PrestaLatex extends Latex 52abstract class PrestaLatex extends Latex
28{ 53{
29 public function __construct(string $quoi, string $codePresta) 54 public function __construct(string $quoi, string $codePresta)
@@ -38,21 +63,23 @@ abstract class PrestaLatex extends Latex
38 } 63 }
39} 64}
40 65
66//~ class PrestaClassFactory extends PrestaLatex
67//~ {}
68
41class DevisLatex extends PrestaLatex 69class DevisLatex extends PrestaLatex
42{} 70{}
43
44class FactureLatex extends PrestaLatex 71class FactureLatex extends PrestaLatex
45{} 72{}
46
47class LocationLatex extends PrestaLatex 73class LocationLatex extends PrestaLatex
48{} 74{}
49 75
50class EnveloppeRectoLatex extends PrestaLatex 76class EnveloppeRectoLatex// extends PrestaLatex
51{} 77{}
52class EnveloppeVersoLatex extends PrestaLatex 78class EnveloppeVersoLatex// extends PrestaLatex
53{} 79{}
54 80
55 81
82
56abstract class ComptaLatex extends Latex 83abstract class ComptaLatex extends Latex
57{ 84{
58 public function __construct(string $quoi, string $annee, int $numeroMois = 0) 85 public function __construct(string $quoi, string $annee, int $numeroMois = 0)
diff --git a/src/files.php b/src/files.php
new file mode 100644
index 0000000..9e1a3f5
--- /dev/null
+++ b/src/files.php
@@ -0,0 +1,38 @@
1<?php
2// src/files.php
3//
4// fonctions pour manipuler les fichiers latex et pdf
5
6function makeFile($path, $file_name, $data)
7{
8 file_put_contents($path. $file_name, $data);
9 chmod($path . $file_name, 0644); // droits en octal
10}
11
12function makeFolder(string $path)
13{
14 if(!file_exists($path))
15 {
16 mkdir($path);
17 chmod($path, 0755); // droits en octal
18 }
19}
20
21// commande système pdflatex
22function latexToPdf(string $latex_path, string $file_name, string $pdf_path)
23{
24 $output_dir = '';
25 if($pdf_path !== '')
26 {
27 $output_dir = '-output-directory=' . $pdf_path . ' ';
28 }
29
30 // compilation
31 //echo 'pdflatex ' . $output_dir . $latex_path . $file_name . "\n";
32 exec('pdflatex ' . $output_dir . $latex_path . $file_name);
33
34 // nettoyage
35 $basename = basename($file_name, '.tex');
36 unlink($pdf_path . $basename . '.aux');
37 unlink($pdf_path . $basename . '.log');
38}
diff --git a/src/functions.php b/src/functions.php
index 0b075b5..1bbb40c 100644
--- a/src/functions.php
+++ b/src/functions.php
@@ -100,7 +100,9 @@ function rechercheClient(string $input, Clients $Client): array
100 return($result); 100 return($result);
101} 101}
102 102
103function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = null, $PrestaDetails = null) 103
104// remplacer par une classe Latex
105function makeLatexAndPdfDocuments(Clients $Client = null, Prestations $Presta = null, $PrestaDetails = null)
104{ 106{
105 $latex = ''; 107 $latex = '';
106 $year = ''; 108 $year = '';
@@ -111,7 +113,10 @@ function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = n
111 // verso d'une enveloppe 113 // verso d'une enveloppe
112 $latex = makeLatex('enveloppe_verso'); // pas de données transmises, elles sont dans la classe Config 114 $latex = makeLatex('enveloppe_verso'); // pas de données transmises, elles sont dans la classe Config
113 $file_name = 'enveloppe_verso.tex'; 115 $file_name = 'enveloppe_verso.tex';
114 makeFiles($latex_path, $pdf_path, $file_name, $latex); 116 makeFile($latex_path, $file_name, $latex);
117
118 latexToPdf($latex_path, $file_name, $pdf_path);
119
115 120
116 if($Client !== null) 121 if($Client !== null)
117 { 122 {
@@ -119,11 +124,16 @@ function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = n
119 124
120 // recto d'une enveloppe 125 // recto d'une enveloppe
121 $latex_recto_path = $latex_path . 'enveloppes_recto/'; 126 $latex_recto_path = $latex_path . 'enveloppes_recto/';
122 $pdf_verso_path = $pdf_path . 'enveloppes_recto/'; 127 $pdf_recto_path = $pdf_path . 'enveloppes_recto/';
123 $data['code_postal'] = implode(' \ ', str_split($data['code_postal'])); // code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0 128 $data['code_postal_espaces'] = implode(' \ ', str_split($data['code_postal'])); // code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0
129
124 $latex = makeLatex('enveloppe_recto', $data); // injection des variables 130 $latex = makeLatex('enveloppe_recto', $data); // injection des variables
125 $file_name = $Client->getCodeClient() . '.tex'; 131 $file_name = $Client->getCodeClient() . '.tex';
126 makeFiles($latex_recto_path, $pdf_verso_path, $file_name, $latex); 132 makeFolder($latex_recto_path);
133 makeFile($latex_recto_path, $file_name, $latex);
134
135 makeFolder($pdf_recto_path);
136 latexToPdf($latex_recto_path, $file_name, $pdf_recto_path);
127 137
128 // facture, devis, location 138 // facture, devis, location
129 if($Presta !== null && $PrestaDetails !== null) 139 if($Presta !== null && $PrestaDetails !== null)
@@ -138,9 +148,14 @@ function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = n
138 $latex_year_path = $latex_path . $year . '/'; // un sous-dossier par année 148 $latex_year_path = $latex_path . $year . '/'; // un sous-dossier par année
139 $pdf_year_path = $pdf_path . $year . '/'; 149 $pdf_year_path = $pdf_path . $year . '/';
140 $data = array_merge($data, $PrestaDetails->getAll()); 150 $data = array_merge($data, $PrestaDetails->getAll());
151
141 $latex = makeLatex($type, $data, $Date); // injection des variables 152 $latex = makeLatex($type, $data, $Date); // injection des variables
142 $file_name = $Presta->getCodePresta() . '.tex'; 153 $file_name = $Presta->getCodePresta() . '.tex';
143 makeFiles($latex_year_path, $pdf_year_path, $file_name, $latex); 154 makeFolder($latex_year_path);
155 makeFile($latex_year_path, $file_name, $latex);
156
157 makeFolder($pdf_year_path);
158 latexToPdf($latex_year_path, $file_name, $pdf_year_path);
144 } 159 }
145 elseif($type === 'cesu' || $type === 'non_vendue') 160 elseif($type === 'cesu' || $type === 'non_vendue')
146 {} // pas de document 161 {} // pas de document
@@ -153,7 +168,6 @@ function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = n
153 } 168 }
154} 169}
155 170
156
157function makeLatex(string $type, array $data = [], Dates $Date = null) 171function makeLatex(string $type, array $data = [], Dates $Date = null)
158{ 172{
159 $date = ''; 173 $date = '';
@@ -172,38 +186,3 @@ function makeLatex(string $type, array $data = [], Dates $Date = null)
172 // normallement le code PHP inséré avec include est nettoyé en quittant la fonction 186 // normallement le code PHP inséré avec include est nettoyé en quittant la fonction
173 return($latex); 187 return($latex);
174} 188}
175
176function makeFiles($latex_path, $pdf_path, $file_name, $latex)
177{
178 makeFolder($latex_path);
179 makeFolder($pdf_path);
180 file_put_contents($latex_path. $file_name, $latex); // écriture du fichier
181 latexToPdf($latex_path, $file_name, $pdf_path);
182}
183
184function makeFolder(string $path)
185{
186 if(!file_exists($path))
187 {
188 mkdir($path);
189 chmod($path, 0755); // droits en octal
190 }
191}
192
193// compilation à partir d'un fichier .tex
194function latexToPdf(string $latexPath, string $fileName, string $pdfPath)
195{
196 $outputDir = '';
197 if($pdfPath !== '')
198 {
199 $outputDir = '-output-directory=' . $pdfPath . ' ';
200 }
201
202 // compilation
203 exec('pdflatex ' . $outputDir . $latexPath . $fileName);
204
205 // nettoyage
206 $basename = basename($fileName, '.tex');
207 unlink($pdfPath . $basename . '.aux');
208 unlink($pdfPath . $basename . '.log');
209}
diff --git a/src/latex_templates/devis.php b/src/latex_templates/devis.php
index bb6f5f4..1bf2f94 100644
--- a/src/latex_templates/devis.php
+++ b/src/latex_templates/devis.php
@@ -1,5 +1,5 @@
1<?php 1<?php
2// latex_templates/devis.php 2// src/latex_templates/devis.php
3 3
4if($data['total_main_d_oeuvre'] != 0) 4if($data['total_main_d_oeuvre'] != 0)
5{ 5{
diff --git a/src/latex_templates/enveloppe_recto.php b/src/latex_templates/enveloppe_recto.php
index 520dd68..6da6a08 100644
--- a/src/latex_templates/enveloppe_recto.php
+++ b/src/latex_templates/enveloppe_recto.php
@@ -23,7 +23,7 @@ ob_start();
23 \setlength{\parindent}{7,9cm} 23 \setlength{\parindent}{7,9cm}
24 \begin{minipage}[b][5,8cm]{12cm} 24 \begin{minipage}[b][5,8cm]{12cm}
25 \LARGE{<?= $data['prenom_nom'] ?>\\<?= $data['adresse'] ?>\\\\\\} 25 \LARGE{<?= $data['prenom_nom'] ?>\\<?= $data['adresse'] ?>\\\\\\}
26 \LARGE{<?= $data['code_postal'] ?> \ \ \ \ <?php echo(mb_strtoupper($data['ville'])); ?>} 26 \LARGE{<?= $data['code_postal_espaces'] ?> \ \ \ \ <?php echo(mb_strtoupper($data['ville'])); ?>}
27 \end{minipage} 27 \end{minipage}
28\end{document} 28\end{document}
29<?php 29<?php
diff --git a/src/latex_templates/facture.php b/src/latex_templates/facture.php
index bbc20ce..db75cc3 100644
--- a/src/latex_templates/facture.php
+++ b/src/latex_templates/facture.php
@@ -1,5 +1,5 @@
1<?php 1<?php
2// latex_templates/facture.php 2// src/latex_templates/facture.php
3 3
4if($data['total_main_d_oeuvre'] != 0) 4if($data['total_main_d_oeuvre'] != 0)
5{ 5{
diff --git a/src/latex_templates/location.php b/src/latex_templates/location.php
index 2f7eb52..9b2c485 100644
--- a/src/latex_templates/location.php
+++ b/src/latex_templates/location.php
@@ -1,5 +1,5 @@
1<?php 1<?php
2// latex_templates/location.php 2// src/latex_templates/location.php
3 3
4if($data['valeur'] != 0) 4if($data['valeur'] != 0)
5{ 5{
diff --git a/src/main.php b/src/main.php
index 13d77c3..86509dd 100755
--- a/src/main.php
+++ b/src/main.php
@@ -2,8 +2,9 @@
2<?php 2<?php
3// src/main.php 3// src/main.php
4 4
5//require('model/File.php');
6require('files.php');
5require('functions.php'); 7require('functions.php');
6require('model/File.php');
7 8
8// configuration du programme par l'utilisateur 9// configuration du programme par l'utilisateur
9require('Config.php'); // classe structure de données, lit config.php et préviens les erreurs (par exemple les / aux chemins manquants) 10require('Config.php'); // classe structure de données, lit config.php et préviens les erreurs (par exemple les / aux chemins manquants)
@@ -23,6 +24,7 @@ Config::$db_path .= Config::$db_name . '.' . Config::$sgbd;
23$sqlitebrowser_enable = false; 24$sqlitebrowser_enable = false;
24$sqlite_cli = ''; // commande sqlite ou sqlite3 25$sqlite_cli = ''; // commande sqlite ou sqlite3
25$x_term_command = ''; // commande terminal en mode graphique 26$x_term_command = ''; // commande terminal en mode graphique
27
26require('dependances.php'); // vérification des dépendances 28require('dependances.php'); // vérification des dépendances
27require('Dates.php'); // gère dates et timestamps 29require('Dates.php'); // gère dates et timestamps
28Dates::$date_format = Config::$date_format; // dates européennes ou américaines 30Dates::$date_format = Config::$date_format; // dates européennes ou américaines
@@ -45,7 +47,6 @@ require('model/Locations.php');
45require('view/Zenity.php'); // commande système zenity 47require('view/Zenity.php'); // commande système zenity
46require('view/ZenitySetup.php'); // texte dans les fenêtres ET instanciation (un objet = une commande) 48require('view/ZenitySetup.php'); // texte dans les fenêtres ET instanciation (un objet = une commande)
47 49
48// factoriser et créer une classe
49//require('Latex.php'); // générer le code LaTeX 50//require('Latex.php'); // générer le code LaTeX
50 51
51require('sections/1_new_service.php'); 52require('sections/1_new_service.php');
diff --git a/src/model/File.php b/src/model/File.php
index 8bcdead..31691dc 100644
--- a/src/model/File.php
+++ b/src/model/File.php
@@ -4,4 +4,98 @@
4// manipulations des fichiers 4// manipulations des fichiers
5 5
6class File 6class File
7{} 7{
8 private $file_name = '';
9 private $path = '';
10 private $data = ''; // écriture de binaire (blob) non prévue
11 private $file_rights = 0644;
12 private $folder_rights = 0755; // droits en octal
13 private $write_mod = 0; // 0 = écraser, 1 = ajouter à la suite, 2 = nouveau fichier
14
15
16 public function __construct(string $file_name, string $path)
17 {
18 $this->file_name = $file_name;
19 $this->path = $path;
20 }
21
22 // getters
23 public function getData(): string
24 {
25 return $this->data;
26 }
27
28 // setters
29 public function setFileName($file_name)
30 {
31 $this->file_name = $file_name;
32 }
33
34 public function setPath($path)
35 {
36 $this->path = $path;
37 }
38
39 public function setData($data)
40 {
41 $this->data = $data;
42 }
43
44 public function setFileRights(int $octal)
45 {
46 $this->file_rights($octal);
47 }
48 public function setFolderRights(int $octal)
49 {
50 $this->folder_rights($octal);
51 }
52
53 public function setWriteMod(int $mod)
54 {
55 $this->write_mod = $mod;
56 }
57
58
59 // fichiers
60 public function readFile(): string
61 {}
62
63 public function writeFile()
64 {
65 file_put_contents($this->path. $this->file_name, $data);
66 chmod($this->path, $this->file_rights);
67 }
68
69
70 // dossiers
71 public function makeFolder()
72 {
73 if(!file_exists($this->path))
74 {
75 mkdir($this->path);
76 chmod($this->path, $this->folder_rights);
77 }
78 }
79}
80
81// compilation à partir d'un fichier .tex
82class latexToPdf extends File
83{
84 public function __construct(string $latex_path, string $file_name, string $pdf_path)
85 {}
86
87 $output_dir = '';
88 if($pdf_path !== '')
89 {
90 $output_dir = '-output-directory=' . $pdf_path . ' ';
91 }
92
93 // compilation
94 //echo 'pdflatex ' . $output_dir . $latex_path . $file_name . "\n";
95 exec('pdflatex ' . $output_dir . $latex_path . $file_name);
96
97 // nettoyage
98 $basename = basename($file_name, '.tex');
99 unlink($pdf_path . $basename . '.aux');
100 unlink($pdf_path . $basename . '.log');
101}
diff --git a/src/sections/1_new_service.php b/src/sections/1_new_service.php
index f9105b7..e7e3564 100644
--- a/src/sections/1_new_service.php
+++ b/src/sections/1_new_service.php
@@ -130,7 +130,14 @@ function newService(): int // code de retour, si 0 retour menu principal, si 2 a
130 130
131 // -- partie 3: LaTeX -- 131 // -- partie 3: LaTeX --
132 132
133 makeLatexAndPdfDocument($Client, $Presta, $PrestaDetails); 133 makeLatexAndPdfDocuments($Client, $Presta, $PrestaDetails);
134
135 // fabrique d'objets (sans connaître les noms des classes)
136
137 //~ $EnveloppeRecto = Latex::makeLatexSubClass('enveloppe_recto');
138 //~ $EnveloppeVerso = Latex::makeLatexSubClass('enveloppe_verso');
139 //~ $DocumentPresta = Latex::makeLatexSubClass($Presta->getTypePresta()); // $type = facture, devis, location
140
134 141
135 // -- partie 4: récapitulatif -- 142 // -- partie 4: récapitulatif --
136 143
@@ -142,14 +149,17 @@ function newService(): int // code de retour, si 0 retour menu principal, si 2 a
142 //~ $imprimer_enveloppe = exec('zenity --question --width=250 --title="Base de données mise à jour" --text="Imprimer l\'adresse sur une enveloppe? (insérer une enveloppe DL sans fenêtre dans l\'imprimante"'); 149 //~ $imprimer_enveloppe = exec('zenity --question --width=250 --title="Base de données mise à jour" --text="Imprimer l\'adresse sur une enveloppe? (insérer une enveloppe DL sans fenêtre dans l\'imprimante"');
143 150
144 151
152 // -- partie 5: on fait quoi maintenant --
153
145 // possibilité de modification 154 // possibilité de modification
146 // zenityQuestion 155 // zenityQuestion
147 if(exec($QuestionModifierPrestation->get()) == '0') 156 //~ if(exec($QuestionModifierPrestation->get()) == '0')
148 { 157 //~ {
149 return 3; // section "Modifier un enregistrement" 158 //~ return 3; // section "Modifier un enregistrement"
150 } 159 //~ }
151 else 160 //~ else
152 { 161 //~ {
153 return 0; // menu principal 162 //~ return 0; // menu principal
154 } 163 //~ }
164 return 0; // menu principal
155} 165}