From 884493c1fb985adaaa537c11f4350d940cc68cb1 Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 4 Jul 2023 15:52:55 +0200 Subject: =?UTF-8?q?fonctions=20fichiers=20s=C3=A9par=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/dev.sqlite | Bin 36864 -> 36864 bytes src/Latex.php | 35 ++++++++++-- src/files.php | 38 +++++++++++++ src/functions.php | 63 +++++++-------------- src/latex_templates/devis.php | 2 +- src/latex_templates/enveloppe_recto.php | 2 +- src/latex_templates/facture.php | 2 +- src/latex_templates/location.php | 2 +- src/main.php | 5 +- src/model/File.php | 96 +++++++++++++++++++++++++++++++- src/sections/1_new_service.php | 28 +++++++--- 11 files changed, 211 insertions(+), 62 deletions(-) create mode 100644 src/files.php diff --git a/data/dev.sqlite b/data/dev.sqlite index c933839..7802e1e 100644 Binary files a/data/dev.sqlite and b/data/dev.sqlite differ 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 protected $latexPath = ''; protected $pdfPath = ''; + static function makeLatexSubClass(string $type): Object + { + switch($type) + { + // documents pour les clients + case 'devis': + return new DevisLatex(); + case 'facture': + return new FactireLatex(); + case 'location': + return new LocationLatex(); + case 'enveloppe_recto': + return new EnveloppeRectoLatex(); + case 'enveloppe_verso': + return new EnveloppeVersoLatex(); + + // documents pour la compta + + // erreur + default: + echo 'erreur, la sous-classe latex à initialiser n\'existe pas'; + } + } + protected function createFile(string $latex, string $fileName, string $latexPath) { // nom du fichier créé = nom.tex @@ -24,6 +48,7 @@ abstract class Latex } + abstract class PrestaLatex extends Latex { public function __construct(string $quoi, string $codePresta) @@ -38,21 +63,23 @@ abstract class PrestaLatex extends Latex } } +//~ class PrestaClassFactory extends PrestaLatex +//~ {} + class DevisLatex extends PrestaLatex {} - class FactureLatex extends PrestaLatex {} - class LocationLatex extends PrestaLatex {} -class EnveloppeRectoLatex extends PrestaLatex +class EnveloppeRectoLatex// extends PrestaLatex {} -class EnveloppeVersoLatex extends PrestaLatex +class EnveloppeVersoLatex// extends PrestaLatex {} + abstract class ComptaLatex extends Latex { 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 @@ +getCodeClient() . '.tex'; - makeFiles($latex_recto_path, $pdf_verso_path, $file_name, $latex); + makeFolder($latex_recto_path); + makeFile($latex_recto_path, $file_name, $latex); + + makeFolder($pdf_recto_path); + latexToPdf($latex_recto_path, $file_name, $pdf_recto_path); // facture, devis, location if($Presta !== null && $PrestaDetails !== null) @@ -138,9 +148,14 @@ function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = n $latex_year_path = $latex_path . $year . '/'; // un sous-dossier par année $pdf_year_path = $pdf_path . $year . '/'; $data = array_merge($data, $PrestaDetails->getAll()); + $latex = makeLatex($type, $data, $Date); // injection des variables $file_name = $Presta->getCodePresta() . '.tex'; - makeFiles($latex_year_path, $pdf_year_path, $file_name, $latex); + makeFolder($latex_year_path); + makeFile($latex_year_path, $file_name, $latex); + + makeFolder($pdf_year_path); + latexToPdf($latex_year_path, $file_name, $pdf_year_path); } elseif($type === 'cesu' || $type === 'non_vendue') {} // pas de document @@ -153,7 +168,6 @@ function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = n } } - function makeLatex(string $type, array $data = [], Dates $Date = null) { $date = ''; @@ -172,38 +186,3 @@ function makeLatex(string $type, array $data = [], Dates $Date = null) // normallement le code PHP inséré avec include est nettoyé en quittant la fonction return($latex); } - -function makeFiles($latex_path, $pdf_path, $file_name, $latex) -{ - makeFolder($latex_path); - makeFolder($pdf_path); - file_put_contents($latex_path. $file_name, $latex); // écriture du fichier - latexToPdf($latex_path, $file_name, $pdf_path); -} - -function makeFolder(string $path) -{ - if(!file_exists($path)) - { - mkdir($path); - chmod($path, 0755); // droits en octal - } -} - -// compilation à partir d'un fichier .tex -function latexToPdf(string $latexPath, string $fileName, string $pdfPath) -{ - $outputDir = ''; - if($pdfPath !== '') - { - $outputDir = '-output-directory=' . $pdfPath . ' '; - } - - // compilation - exec('pdflatex ' . $outputDir . $latexPath . $fileName); - - // nettoyage - $basename = basename($fileName, '.tex'); - unlink($pdfPath . $basename . '.aux'); - unlink($pdfPath . $basename . '.log'); -} 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 @@ \\\\\\\\} - \LARGE{ \ \ \ \ } + \LARGE{ \ \ \ \ } \end{minipage} \end{document} file_name = $file_name; + $this->path = $path; + } + + // getters + public function getData(): string + { + return $this->data; + } + + // setters + public function setFileName($file_name) + { + $this->file_name = $file_name; + } + + public function setPath($path) + { + $this->path = $path; + } + + public function setData($data) + { + $this->data = $data; + } + + public function setFileRights(int $octal) + { + $this->file_rights($octal); + } + public function setFolderRights(int $octal) + { + $this->folder_rights($octal); + } + + public function setWriteMod(int $mod) + { + $this->write_mod = $mod; + } + + + // fichiers + public function readFile(): string + {} + + public function writeFile() + { + file_put_contents($this->path. $this->file_name, $data); + chmod($this->path, $this->file_rights); + } + + + // dossiers + public function makeFolder() + { + if(!file_exists($this->path)) + { + mkdir($this->path); + chmod($this->path, $this->folder_rights); + } + } +} + +// compilation à partir d'un fichier .tex +class latexToPdf extends File +{ + public function __construct(string $latex_path, string $file_name, string $pdf_path) + {} + + $output_dir = ''; + if($pdf_path !== '') + { + $output_dir = '-output-directory=' . $pdf_path . ' '; + } + + // compilation + //echo 'pdflatex ' . $output_dir . $latex_path . $file_name . "\n"; + exec('pdflatex ' . $output_dir . $latex_path . $file_name); + + // nettoyage + $basename = basename($file_name, '.tex'); + unlink($pdf_path . $basename . '.aux'); + unlink($pdf_path . $basename . '.log'); +} 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 // -- partie 3: LaTeX -- - makeLatexAndPdfDocument($Client, $Presta, $PrestaDetails); + makeLatexAndPdfDocuments($Client, $Presta, $PrestaDetails); + + // fabrique d'objets (sans connaître les noms des classes) + + //~ $EnveloppeRecto = Latex::makeLatexSubClass('enveloppe_recto'); + //~ $EnveloppeVerso = Latex::makeLatexSubClass('enveloppe_verso'); + //~ $DocumentPresta = Latex::makeLatexSubClass($Presta->getTypePresta()); // $type = facture, devis, location + // -- partie 4: récapitulatif -- @@ -142,14 +149,17 @@ function newService(): int // code de retour, si 0 retour menu principal, si 2 a //~ $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"'); + // -- partie 5: on fait quoi maintenant -- + // possibilité de modification // zenityQuestion - if(exec($QuestionModifierPrestation->get()) == '0') - { - return 3; // section "Modifier un enregistrement" - } - else - { - return 0; // menu principal - } + //~ if(exec($QuestionModifierPrestation->get()) == '0') + //~ { + //~ return 3; // section "Modifier un enregistrement" + //~ } + //~ else + //~ { + //~ return 0; // menu principal + //~ } + return 0; // menu principal } -- cgit v1.2.3