summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2023-07-05 01:39:29 +0200
committerpolo <ordipolo@gmx.fr>2023-07-05 01:39:29 +0200
commit9bdfb5196a2ee1cbfc403702e8d2ef88076d366f (patch)
tree6a92d8011dae746e5fe7a618eb4af2b77e922572
parent884493c1fb985adaaa537c11f4350d940cc68cb1 (diff)
downloadAppliGestionPHP-9bdfb5196a2ee1cbfc403702e8d2ef88076d366f.zip
classe Latex "fonctionnelle"
-rw-r--r--data/dev.sqlitebin36864 -> 36864 bytes
-rw-r--r--src/Latex.php177
-rw-r--r--src/files.php14
-rw-r--r--src/functions.php143
-rw-r--r--src/latex_templates/enveloppe_recto.php2
-rwxr-xr-xsrc/main.php2
-rw-r--r--src/model/Clients.php18
-rw-r--r--src/model/Model.php4
-rw-r--r--src/model/Prestations.php22
-rw-r--r--src/sections/1_new_service.php54
10 files changed, 283 insertions, 153 deletions
diff --git a/data/dev.sqlite b/data/dev.sqlite
index 7802e1e..841d187 100644
--- a/data/dev.sqlite
+++ b/data/dev.sqlite
Binary files differ
diff --git a/src/Latex.php b/src/Latex.php
index a766fd6..051c48b 100644
--- a/src/Latex.php
+++ b/src/Latex.php
@@ -5,9 +5,12 @@
5 5
6abstract class Latex 6abstract class Latex
7{ 7{
8 protected $fileName = ''; 8 protected $type = '';
9 protected $latexPath = ''; 9 protected $file_name = '';
10 protected $pdfPath = ''; 10 protected $latex_path = '';
11 protected $pdf_path = '';
12 protected $data = []; // données à insérer dans le template
13 protected $latex = ''; // latex pur
11 14
12 static function makeLatexSubClass(string $type): Object 15 static function makeLatexSubClass(string $type): Object
13 { 16 {
@@ -15,15 +18,15 @@ abstract class Latex
15 { 18 {
16 // documents pour les clients 19 // documents pour les clients
17 case 'devis': 20 case 'devis':
18 return new DevisLatex(); 21 return new DevisLatex($type);
19 case 'facture': 22 case 'facture':
20 return new FactireLatex(); 23 return new FactureLatex($type);
21 case 'location': 24 case 'location':
22 return new LocationLatex(); 25 return new LocationLatex($type);
23 case 'enveloppe_recto': 26 case 'enveloppe_recto':
24 return new EnveloppeRectoLatex(); 27 return new EnveloppeRectoLatex($type);
25 case 'enveloppe_verso': 28 case 'enveloppe_verso':
26 return new EnveloppeVersoLatex(); 29 return new EnveloppeVersoLatex($type);
27 30
28 // documents pour la compta 31 // documents pour la compta
29 32
@@ -33,72 +36,152 @@ abstract class Latex
33 } 36 }
34 } 37 }
35 38
36 protected function createFile(string $latex, string $fileName, string $latexPath) 39 // tester en private?
40 public function __construct(string $type)
37 { 41 {
38 // nom du fichier créé = nom.tex 42 $this->type = $type;
39 // pour les devis, factures et enveloppes, le nom est le code la prestation 43 }
40 // pour les livre de recettes et registres des achats mensuels: 44
41 // le nom du fichier suit cet exemple: "Recettes-2022-06-Juin.tex" 45 public function makeLatex()
42 // pour le livre de recette ou le registre des achats annuel, même principe: "Achats-2022.tex" 46 {
43 // pour le bilan comptable annuel, ça donne: "Bilan-2022.tex" 47 $data = $this->data;
44 $fichier = fopen($latexPath . $fileName, "w+"); 48
45 fputs($fichier, $latex); 49 // on obtient la variable $latex avec ob_get_clean()
46 fclose($fichier); 50 // le include() ici, c'est du génie ou c'est moche ou les deux?
51 // un nouveau fichier php est inséré à chaque itération
52 include('latex_templates/' . $this->type . '.php');
53
54 // on retourne le buffer
55 // normallement le code PHP inséré avec include est nettoyé en quittant la fonction
56 $this->latex = $latex;
57 //return($latex);
58 }
59
60 // getters
61 public function getFileName(): string
62 {
63 return $this->file_name;
64 }
65 public function getLatexPath(): string
66 {
67 return $this->latex_path;
68 }
69 public function getPdfPath(): string
70 {
71 return $this->pdf_path;
72 }
73
74 public function getLatex(): string
75 {
76 return $this->latex;
77 }
78
79 // setters
80 public function setFileName(string $file_name)
81 {
82 $this->file_name = $file_name;
83 }
84 public function setLatexPath(string $latex_path)
85 {
86 $this->latex_path = $latex_path;
87 }
88 public function setPdfPath(string $pdf_path)
89 {
90 $this->pdf_path = $pdf_path;
91 }
92
93 public function setData(Object $Object)
94 {
95 $this->data = array_merge($this->data, $Object->getAll()); // nécessite des tableaux associatifs
96 //return $Object; // pour chainer les méthodes
47 } 97 }
48} 98}
49 99
50 100
51
52abstract class PrestaLatex extends Latex 101abstract class PrestaLatex extends Latex
53{ 102{
54 public function __construct(string $quoi, string $codePresta) 103 protected $Date; // sera un type "Dates"
104 protected $year = '';
105
106 //~ public function __construct(string $type) // surcharge Latex::__construct()
107 //~ {
108 //~ $this->type = $type;
109 //~ $this->Date = new Dates();
110 //~ $this->year = $this->Date->getYear();
111 //~ }
112
113 public function getYear(): string // parce que Dates::getDate() retourne une chaine
55 { 114 {
56 nameTheFile($quoi, $codePresta); 115 return $this->year;
116 }
117
118 public function makeDateInstance(int $date)
119 {
120 $this->Date = new Dates($date);
121 $this->year = $this->Date->getYear();
57 } 122 }
58 123
59 // forme = code-presta.tex 124 // forme = code-presta.tex
60 protected function nameTheFile(string $quoi, string $codePresta) 125 //~ protected function nameTheFile(string $quoi, string $codePresta)
126 //~ {
127 //~ $this->fileName = $quoi . '-' . $codePresta . '.tex';
128 //~ }
129
130 public function makeLatex()
61 { 131 {
62 $this->fileName = $quoi . '-' . $codePresta . '.tex'; 132 $data = $this->data;
133 $date = preg_replace('#\D#', '/', $this->Date->getDate()); // date avec des slashs / parce que j'aime bien
134
135 // on obtient la variable $latex avec ob_get_clean()
136 // le include() ici, c'est du génie ou c'est moche ou les deux?
137 // un nouveau fichier php est inséré à chaque itération
138 include('latex_templates/' . $this->type . '.php');
139
140 // on retourne le buffer
141 // normallement le code PHP inséré avec include est nettoyé en quittant la fonction
142 $this->latex = $latex;
143 //return($latex);
63 } 144 }
64} 145}
65 146
66//~ class PrestaClassFactory extends PrestaLatex 147class DevisLatex extends PrestaLatex // extends Latex
67//~ {}
68
69class DevisLatex extends PrestaLatex
70{} 148{}
71class FactureLatex extends PrestaLatex 149class FactureLatex extends PrestaLatex // extends Latex
72{} 150{}
73class LocationLatex extends PrestaLatex 151class LocationLatex extends PrestaLatex // extends Latex
74{}
75
76class EnveloppeRectoLatex// extends PrestaLatex
77{} 152{}
78class EnveloppeVersoLatex// extends PrestaLatex 153class EnveloppeRectoLatex extends Latex
154{
155 // code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0
156 public function spacesInPostCode()
157 {
158 $this->data['code_postal_espaces'] = implode(' \ ', str_split($this->data['code_postal']));
159 }
160}
161class EnveloppeVersoLatex extends Latex
79{} 162{}
80 163
81 164
82 165
83abstract class ComptaLatex extends Latex 166abstract class ComptaLatex extends Latex
84{ 167{
85 public function __construct(string $quoi, string $annee, int $numeroMois = 0) 168 //~ public function __construct(string $quoi, string $annee, int $numeroMois = 0)
86 { 169 //~ {
87 nameTheFile($quoi, $annee, $numeroMois); 170 //~ nameTheFile($quoi, $annee, $numeroMois);
88 } 171 //~ }
89 172
90 // forme = Recettes-2022-06-Juin.tex ou Recettes-2022.tex 173 // forme = Recettes-2022-06-Juin.tex ou Recettes-2022.tex
91 // type de 'annee'? 174 // type de 'annee'?
92 protected function nameTheFile(string $quoi, string $annee, int $numeroMois = 0) 175 //~ protected function nameTheFile(string $quoi, string $annee, int $numeroMois = 0)
93 { 176 //~ {
94 $this->fileName = $quoi . '-' . $annee; 177 //~ $this->fileName = $quoi . '-' . $annee;
95 $mois = ['', 'Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre']; 178 //~ $mois = ['', 'Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'];
96 if($numeroMois > 0 && $numeroMois <= 12) 179 //~ if($numeroMois > 0 && $numeroMois <= 12)
97 { 180 //~ {
98 $this->fileName .= '-' . $numeroMois . '-' . $mois[$numeroMois]; 181 //~ $this->fileName .= '-' . $numeroMois . '-' . $mois[$numeroMois];
99 } 182 //~ }
100 $this->fileName .= '.tex'; 183 //~ $this->fileName .= '.tex';
101 } 184 //~ }
102} 185}
103 186
104class LivreRecettesLatex extends ComptaLatex 187class LivreRecettesLatex extends ComptaLatex
diff --git a/src/files.php b/src/files.php
index 9e1a3f5..2d12280 100644
--- a/src/files.php
+++ b/src/files.php
@@ -7,6 +7,19 @@ function makeFile($path, $file_name, $data)
7{ 7{
8 file_put_contents($path. $file_name, $data); 8 file_put_contents($path. $file_name, $data);
9 chmod($path . $file_name, 0644); // droits en octal 9 chmod($path . $file_name, 0644); // droits en octal
10
11 //~ protected function createFile(string $latex, string $file_name, string $latexPath)
12 //~ {
13 //~ // nom du fichier créé = nom.tex
14 //~ // pour les devis, factures et enveloppes, le nom est le code la prestation
15 //~ // pour les livre de recettes et registres des achats mensuels:
16 //~ // le nom du fichier suit cet exemple: "Recettes-2022-06-Juin.tex"
17 //~ // pour le livre de recette ou le registre des achats annuel, même principe: "Achats-2022.tex"
18 //~ // pour le bilan comptable annuel, ça donne: "Bilan-2022.tex"
19 //~ $fichier = fopen($latexPath . $file_name, "w+");
20 //~ fputs($fichier, $latex);
21 //~ fclose($fichier);
22 //~ }
10} 23}
11 24
12function makeFolder(string $path) 25function makeFolder(string $path)
@@ -21,6 +34,7 @@ function makeFolder(string $path)
21// commande système pdflatex 34// commande système pdflatex
22function latexToPdf(string $latex_path, string $file_name, string $pdf_path) 35function latexToPdf(string $latex_path, string $file_name, string $pdf_path)
23{ 36{
37 // paramètre optionnel
24 $output_dir = ''; 38 $output_dir = '';
25 if($pdf_path !== '') 39 if($pdf_path !== '')
26 { 40 {
diff --git a/src/functions.php b/src/functions.php
index 1bbb40c..aaacb36 100644
--- a/src/functions.php
+++ b/src/functions.php
@@ -101,88 +101,87 @@ function rechercheClient(string $input, Clients $Client): array
101} 101}
102 102
103 103
104// remplacer par une classe Latex 104//~ function makeLatexAndPdfDocuments(Clients $Client = null, Prestations $Presta = null, $PrestaDetails = null)
105function makeLatexAndPdfDocuments(Clients $Client = null, Prestations $Presta = null, $PrestaDetails = null) 105//~ {
106{ 106 //~ $latex = '';
107 $latex = ''; 107 //~ $year = '';
108 $year = ''; 108 //~ $data = [];
109 $data = []; 109 //~ $latex_path = Config::$latex_path;
110 $latex_path = Config::$latex_path; 110 //~ $pdf_path = Config::$pdf_path;
111 $pdf_path = Config::$pdf_path;
112 111
113 // verso d'une enveloppe 112 //~ // verso d'une enveloppe
114 $latex = makeLatex('enveloppe_verso'); // pas de données transmises, elles sont dans la classe Config 113 //~ $latex = makeLatex('enveloppe_verso'); // pas de données transmises, elles sont dans la classe Config
115 $file_name = 'enveloppe_verso.tex'; 114 //~ $file_name = 'enveloppe_verso.tex';
116 makeFile($latex_path, $file_name, $latex); 115 //~ makeFile($latex_path, $file_name, $latex);
117 116
118 latexToPdf($latex_path, $file_name, $pdf_path); 117 //~ latexToPdf($latex_path, $file_name, $pdf_path);
119 118
120 119
121 if($Client !== null) 120 //~ if($Client !== null)
122 { 121 //~ {
123 $data = $Client->getAll(); 122 //~ $data = $Client->getAll();
124 123
125 // recto d'une enveloppe 124 //~ // recto d'une enveloppe
126 $latex_recto_path = $latex_path . 'enveloppes_recto/'; 125 //~ $latex_recto_path = $latex_path . 'enveloppes_recto/';
127 $pdf_recto_path = $pdf_path . 'enveloppes_recto/'; 126 //~ $pdf_recto_path = $pdf_path . 'enveloppes_recto/';
128 $data['code_postal_espaces'] = implode(' \ ', str_split($data['code_postal'])); // code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0 127 //~ $data['code_postal_espaces'] = implode(' \ ', str_split($data['code_postal'])); // code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0
129 128
130 $latex = makeLatex('enveloppe_recto', $data); // injection des variables 129 //~ $latex = makeLatex('enveloppe_recto', $data); // injection des variables
131 $file_name = $Client->getCodeClient() . '.tex'; 130 //~ $file_name = $Client->getCodeClient() . '.tex';
132 makeFolder($latex_recto_path); 131 //~ makeFolder($latex_recto_path);
133 makeFile($latex_recto_path, $file_name, $latex); 132 //~ makeFile($latex_recto_path, $file_name, $latex);
134 133
135 makeFolder($pdf_recto_path); 134 //~ makeFolder($pdf_recto_path);
136 latexToPdf($latex_recto_path, $file_name, $pdf_recto_path); 135 //~ latexToPdf($latex_recto_path, $file_name, $pdf_recto_path);
137 136
138 // facture, devis, location 137 //~ // facture, devis, location
139 if($Presta !== null && $PrestaDetails !== null) 138 //~ if($Presta !== null && $PrestaDetails !== null)
140 { 139 //~ {
141 $type = $Presta->getTypePresta(); 140 //~ $type = $Presta->getTypePresta();
142 $file_name = $type . '.tex'; 141 //~ $file_name = $type . '.tex';
143 if($type === 'facture' || $type === 'devis' || $type === 'location') 142 //~ if($type === 'facture' || $type === 'devis' || $type === 'location')
144 { 143 //~ {
145 $data = array_merge($data, $Presta->getAll()); 144 //~ $data = array_merge($data, $Presta->getAll());
146 $Date = new Dates($Presta->getDate()); // entrée = timestamp (doit être un "int"!!) 145 //~ $Date = new Dates($Presta->getDate()); // entrée = timestamp (doit être un "int"!!)
147 $year = $Date->getYear(); 146 //~ $year = $Date->getYear();
148 $latex_year_path = $latex_path . $year . '/'; // un sous-dossier par année 147 //~ $latex_year_path = $latex_path . $year . '/'; // un sous-dossier par année
149 $pdf_year_path = $pdf_path . $year . '/'; 148 //~ $pdf_year_path = $pdf_path . $year . '/';
150 $data = array_merge($data, $PrestaDetails->getAll()); 149 //~ $data = array_merge($data, $PrestaDetails->getAll());
151 150
152 $latex = makeLatex($type, $data, $Date); // injection des variables 151 //~ $latex = makeLatex($type, $data, $Date); // injection des variables
153 $file_name = $Presta->getCodePresta() . '.tex'; 152 //~ $file_name = $Presta->getCodePresta() . '.tex';
154 makeFolder($latex_year_path); 153 //~ makeFolder($latex_year_path);
155 makeFile($latex_year_path, $file_name, $latex); 154 //~ makeFile($latex_year_path, $file_name, $latex);
156 155
157 makeFolder($pdf_year_path); 156 //~ makeFolder($pdf_year_path);
158 latexToPdf($latex_year_path, $file_name, $pdf_year_path); 157 //~ latexToPdf($latex_year_path, $file_name, $pdf_year_path);
159 } 158 //~ }
160 elseif($type === 'cesu' || $type === 'non_vendue') 159 //~ elseif($type === 'cesu' || $type === 'non_vendue')
161 {} // pas de document 160 //~ {} // pas de document
162 else 161 //~ else
163 { 162 //~ {
164 echo "debug: erreur génération latex, type de prestation \n"; 163 //~ echo "debug: erreur génération latex, type de prestation \n";
165 return 0; 164 //~ return 0;
166 } 165 //~ }
167 } 166 //~ }
168 } 167 //~ }
169} 168//~ }
170 169
171function makeLatex(string $type, array $data = [], Dates $Date = null) 170//~ function makeLatex(string $type, array $data = [], Dates $Date = null)
172{ 171//~ {
173 $date = ''; 172 //~ $date = '';
174 if($Date != null) 173 //~ if($Date != null)
175 { 174 //~ {
176 $date = $Date->getDate(); 175 //~ $date = $Date->getDate();
177 $date = preg_replace('#\D#', '/', $date); // date avec des slashs / parce que j'aime bien 176 //~ $date = preg_replace('#\D#', '/', $date); // date avec des slashs / parce que j'aime bien
178 } 177 //~ }
179 178
180 // on obtient la variable $latex avec ob_get_clean() 179 //~ // on obtient la variable $latex avec ob_get_clean()
181 // le include() ici, c'est du génie ou c'est moche ou les deux? 180 //~ // le include() ici, c'est du génie ou c'est moche ou les deux?
182 // un nouveau fichier php est inséré à chaque itération 181 //~ // un nouveau fichier php est inséré à chaque itération
183 include('latex_templates/' . $type . '.php'); 182 //~ include('latex_templates/' . $type . '.php');
184 183
185 // on retourne le buffer 184 //~ // on retourne le buffer
186 // normallement le code PHP inséré avec include est nettoyé en quittant la fonction 185 //~ // normallement le code PHP inséré avec include est nettoyé en quittant la fonction
187 return($latex); 186 //~ return($latex);
188} 187//~ }
diff --git a/src/latex_templates/enveloppe_recto.php b/src/latex_templates/enveloppe_recto.php
index 6da6a08..294e589 100644
--- a/src/latex_templates/enveloppe_recto.php
+++ b/src/latex_templates/enveloppe_recto.php
@@ -1,8 +1,6 @@
1<?php 1<?php
2// src/latex_templates/enveloppe_recto.php 2// src/latex_templates/enveloppe_recto.php
3 3
4//~ $data['adresse']
5
6ob_start(); 4ob_start();
7?> 5?>
8\documentclass[]{report} 6\documentclass[]{report}
diff --git a/src/main.php b/src/main.php
index 86509dd..7bf8470 100755
--- a/src/main.php
+++ b/src/main.php
@@ -47,7 +47,7 @@ require('model/Locations.php');
47require('view/Zenity.php'); // commande système zenity 47require('view/Zenity.php'); // commande système zenity
48require('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)
49 49
50//require('Latex.php'); // générer le code LaTeX 50require('Latex.php'); // générer le code LaTeX
51 51
52require('sections/1_new_service.php'); 52require('sections/1_new_service.php');
53require('sections/2_quotations.php'); 53require('sections/2_quotations.php');
diff --git a/src/model/Clients.php b/src/model/Clients.php
index 8f460c6..d9dd28d 100644
--- a/src/model/Clients.php
+++ b/src/model/Clients.php
@@ -35,27 +35,27 @@ class Clients extends Model
35 public function setPrenomNom($value) 35 public function setPrenomNom($value)
36 { 36 {
37 $this->prenom_nom = (string) $value; 37 $this->prenom_nom = (string) $value;
38 return($this); 38 return $this;
39 } 39 }
40 public function setCodeClient($value) 40 public function setCodeClient($value)
41 { 41 {
42 $this->code_client = (string) $value; 42 $this->code_client = (string) $value;
43 return($this); 43 return $this;
44 } 44 }
45 public function setAdresse($value) 45 public function setAdresse($value)
46 { 46 {
47 $this->adresse = (string) $value; 47 $this->adresse = (string) $value;
48 return($this); 48 return $this;
49 } 49 }
50 public function setCodePostal($value) 50 public function setCodePostal($value)
51 { 51 {
52 $this->code_postal = (string) $value; 52 $this->code_postal = (string) $value;
53 return($this); 53 return $this;
54 } 54 }
55 public function setVille($value) 55 public function setVille($value)
56 { 56 {
57 $this->ville = (string) $value; 57 $this->ville = (string) $value;
58 return($this); 58 return $this;
59 } 59 }
60 60
61 public function setTelephone($value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début 61 public function setTelephone($value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début
@@ -69,17 +69,17 @@ class Clients extends Model
69 $this->telephone = ''; 69 $this->telephone = '';
70 echo 'debug: le champ "telephone" ne doit comporter que des nombres, aucun numéro ne sera utilisé' . "\n"; 70 echo 'debug: le champ "telephone" ne doit comporter que des nombres, aucun numéro ne sera utilisé' . "\n";
71 } 71 }
72 return($this); 72 return $this;
73 } 73 }
74 public function setCourriel($value) 74 public function setCourriel($value)
75 { 75 {
76 $this->courriel = (string) $value; 76 $this->courriel = (string) $value;
77 return($this); 77 return $this;
78 } 78 }
79 public function setApropos($value) 79 public function setApropos($value)
80 { 80 {
81 $this->apropos = (string) $value; 81 $this->apropos = (string) $value;
82 return($this); 82 return $this;
83 } 83 }
84 84
85 85
@@ -106,6 +106,6 @@ class Clients extends Model
106 } 106 }
107 } 107 }
108 } 108 }
109 return($result); 109 return $result;
110 } 110 }
111} 111}
diff --git a/src/model/Model.php b/src/model/Model.php
index 40a9fcb..17d1292 100644
--- a/src/model/Model.php
+++ b/src/model/Model.php
@@ -16,7 +16,7 @@ abstract class Model extends DB
16 // getters 16 // getters
17 public function getTable(): string 17 public function getTable(): string
18 { 18 {
19 return($this->table); 19 return $this->table;
20 } 20 }
21 21
22 public function getAll(): array 22 public function getAll(): array
@@ -35,7 +35,7 @@ abstract class Model extends DB
35 { 35 {
36 $this->ID = $value; 36 $this->ID = $value;
37 } 37 }
38 return($this); 38 return $this;
39 } 39 }
40 40
41 public function hydrate(array $data): bool // $data = tableau associatif en entrée: nom_du_champ => valeur 41 public function hydrate(array $data): bool // $data = tableau associatif en entrée: nom_du_champ => valeur
diff --git a/src/model/Prestations.php b/src/model/Prestations.php
index 94dd805..22865df 100644
--- a/src/model/Prestations.php
+++ b/src/model/Prestations.php
@@ -33,7 +33,7 @@ class Prestations extends Model
33 { 33 {
34 return $this->code_presta; 34 return $this->code_presta;
35 } 35 }
36 public function getDate(): int 36 public function getDate(): int // timestamp unix
37 { 37 {
38 return $this->date; 38 return $this->date;
39 } 39 }
@@ -48,7 +48,7 @@ class Prestations extends Model
48 public function setIDClient(int $value) 48 public function setIDClient(int $value)
49 { 49 {
50 $this->ID_client = $value; 50 $this->ID_client = $value;
51 return($this); 51 return $this;
52 } 52 }
53 //~ public function setCombientiemeFois(int $value) 53 //~ public function setCombientiemeFois(int $value)
54 //~ { 54 //~ {
@@ -58,37 +58,29 @@ class Prestations extends Model
58 public function setCodePresta(string $value) 58 public function setCodePresta(string $value)
59 { 59 {
60 $this->code_presta = $value; 60 $this->code_presta = $value;
61 return($this); 61 return $this;
62 } 62 }
63 public function setDate(int $value) 63 public function setDate(int $value)
64 { 64 {
65 $this->date = $value; 65 $this->date = $value;
66 return($this); 66 return $this;
67 } 67 }
68 public function setTypePresta(string $value) 68 public function setTypePresta(string $value)
69 { 69 {
70 $this->type_presta = $value; 70 $this->type_presta = $value;
71 return($this); 71 return $this;
72 } 72 }
73 public function setModePaiement(string $value) 73 public function setModePaiement(string $value)
74 { 74 {
75 $this->mode_paiement = $value; 75 $this->mode_paiement = $value;
76 return($this); 76 return $this;
77 } 77 }
78 public function setCommentaires(string $value) 78 public function setCommentaires(string $value)
79 { 79 {
80 $this->commentaires = $value; 80 $this->commentaires = $value;
81 return($this); 81 return $this;
82 } 82 }
83 83
84 //~ protected function combientiemeFois()
85 //~ {
86 //~ // on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente)
87 //~ $array = $this->find(['ID_client' => $this->ID_client]);
88 //~ //$this->combientieme_fois = count($array) + 1;
89 //~ return count($array) + 1;
90 //~ }
91
92 // code client = année-mois-jour-codeclient-combientièmefois 84 // code client = année-mois-jour-codeclient-combientièmefois
93 public function makeCodePresta(Dates $Date, string $code_client) 85 public function makeCodePresta(Dates $Date, string $code_client)
94 { 86 {
diff --git a/src/sections/1_new_service.php b/src/sections/1_new_service.php
index e7e3564..6f5a72c 100644
--- a/src/sections/1_new_service.php
+++ b/src/sections/1_new_service.php
@@ -130,13 +130,57 @@ 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 makeLatexAndPdfDocuments($Client, $Presta, $PrestaDetails); 133 //makeLatexAndPdfDocuments($Client, $Presta, $PrestaDetails);
134 // factoriser tout ça
135 /* plusieurs parties:
136 * - une fonction ou on crée et manipule les objets (une classe par type de document)
137 * - manipulation des données
138 * - chemins et noms de fichiers
139 * - insertion des variables
140 * - écriture du fichier (+ dossier si nécessaire)
141 */
142 // et pour bien faire ajouter aussi une interface
134 143
135 // fabrique d'objets (sans connaître les noms des classes) 144 // fabrique d'objets (sans connaître les noms des classes)
136 145 $EnveloppeRecto = Latex::makeLatexSubClass('enveloppe_recto');
137 //~ $EnveloppeRecto = Latex::makeLatexSubClass('enveloppe_recto'); 146 $EnveloppeVerso = Latex::makeLatexSubClass('enveloppe_verso');
138 //~ $EnveloppeVerso = Latex::makeLatexSubClass('enveloppe_verso'); 147 $DocumentPresta = Latex::makeLatexSubClass($Presta->getTypePresta()); // $type = facture, devis, location
139 //~ $DocumentPresta = Latex::makeLatexSubClass($Presta->getTypePresta()); // $type = facture, devis, location 148
149 // génération du latex
150 $EnveloppeRecto->setData($Client);
151 $EnveloppeRecto->setFileName($Client->getCodeClient() . '.tex');
152 $EnveloppeRecto->setLatexPath(Config::$latex_path . 'enveloppes_recto/');
153 $EnveloppeRecto->setPdfPath(Config::$pdf_path . 'enveloppes_recto/');
154 $EnveloppeRecto->spacesInPostCode();
155 $EnveloppeRecto->makeLatex();
156
157 $EnveloppeVerso->setFileName('enveloppe_verso.tex');
158 $EnveloppeVerso->setLatexPath(Config::$latex_path);
159 $EnveloppeVerso->setPdfPath(Config::$pdf_path);
160 $EnveloppeVerso->makeLatex();
161
162 $DocumentPresta->setData($Client);
163 $DocumentPresta->setData($Presta);
164 $DocumentPresta->setData($PrestaDetails);
165 $DocumentPresta->makeDateInstance($Presta->getDate()); // paramètre = int
166 $DocumentPresta->setFileName($Presta->getCodePresta() . '.tex');
167 $DocumentPresta->setLatexPath(Config::$latex_path . $DocumentPresta->getYear() . '/');
168 $DocumentPresta->setPdfPath(Config::$pdf_path . $DocumentPresta->getYear() . '/');
169 $DocumentPresta->makeLatex();
170
171 // création des fichiers
172 makeFolder($EnveloppeRecto->getLatexPath());
173 makeFolder($EnveloppeRecto->getPdfPath());
174 makeFile($EnveloppeRecto->getLatexPath(), $EnveloppeRecto->getFileName(), $EnveloppeRecto->getLatex());
175 latexToPdf($EnveloppeRecto->getLatexPath(), $EnveloppeRecto->getFileName(), $EnveloppeRecto->getPdfPath());
176
177 makeFile($EnveloppeVerso->getLatexPath(), $EnveloppeVerso->getFileName(), $EnveloppeVerso->getLatex());
178 latexToPdf($EnveloppeVerso->getLatexPath(), $EnveloppeVerso->getFileName(), $EnveloppeVerso->getPdfPath());
179
180 makeFolder($DocumentPresta->getLatexPath());
181 makeFolder($DocumentPresta->getPdfPath());
182 makeFile($DocumentPresta->getLatexPath(), $DocumentPresta->getFileName(), $DocumentPresta->getLatex());
183 latexToPdf($DocumentPresta->getLatexPath(), $DocumentPresta->getFileName(), $DocumentPresta->getPdfPath());
140 184
141 185
142 // -- partie 4: récapitulatif -- 186 // -- partie 4: récapitulatif --