mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-12-02 21:30:16 +09:00
Move and update paths for Invoice PDF templates (#3355)
* Move invoice PDF templates and update paths * Migrate Invoice PDF templates to new location * Bump `last_patch` to 51 in install SQL
This commit is contained in:
1 parent
4f88416349
commit
f3e32ec43a
5 files changed
+31
-12
No files matched your search
@@ -310,7 +310,7 @@ LOCK TABLES `setting` WRITE;
|
||||
|
||||
INSERT INTO `setting` (`id`, `param`, `value`, `public`, `category`, `hash`, `created_at`, `updated_at`)
|
||||
VALUES
|
||||
(1,'last_patch','50',0,NULL,NULL,'2024-12-30 12:00:00','2024-12-30 12:00:00'),
|
||||
(1,'last_patch','51',0,NULL,NULL,'2024-12-30 12:00:00','2024-12-30 12:00:00'),
|
||||
(2,'company_name','Company Name',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'),
|
||||
(3,'company_email','support@yourcompany.com',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'),
|
||||
(4,'company_signature','FOSSBilling.org - Client Management, Invoicing and Support Software',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'),
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace FOSSBilling;
|
||||
use Symfony\Component\Filesystem\Exception\IOException;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Filesystem\Path;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
class UpdatePatcher implements InjectionAwareInterface
|
||||
@@ -654,9 +655,6 @@ class UpdatePatcher implements InjectionAwareInterface
|
||||
}
|
||||
},
|
||||
49 => function (): void {
|
||||
// Patch to update logo and favicon paths from assets/ to assets/build/ for huraga theme
|
||||
// This is needed because the esbuild migration moved assets to a build directory
|
||||
// @see https://github.com/FOSSBilling/FOSSBilling/pull/XXXX
|
||||
$q = "UPDATE setting SET value = 'themes/huraga/assets/build/img/logo.svg' WHERE param = 'company_logo' AND value = 'themes/huraga/assets/img/logo.svg';";
|
||||
$this->executeSql($q);
|
||||
|
||||
@@ -672,6 +670,27 @@ class UpdatePatcher implements InjectionAwareInterface
|
||||
'meta_key' => 'config',
|
||||
]);
|
||||
},
|
||||
51 => function (): void {
|
||||
$oldDir = Path::join(PATH_MODS, 'Invoice', 'pdf_template');
|
||||
$newDir = Path::join(PATH_MODS, 'Invoice', 'templates', 'pdf');
|
||||
|
||||
if (!$this->filesystem->exists($oldDir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fileActions = [
|
||||
Path::join($oldDir, 'custom-pdf.twig') => Path::join($newDir, 'custom-invoice.twig'),
|
||||
Path::join($oldDir, 'custom-pdf.css') => Path::join($newDir, 'custom-invoice.css'),
|
||||
Path::join($oldDir, 'default-pdf.twig') => 'unlink',
|
||||
Path::join($oldDir, 'default-pdf.css') => 'unlink',
|
||||
];
|
||||
$this->executeFileActions($fileActions);
|
||||
|
||||
$finder = new Finder();
|
||||
if (!$finder->in($oldDir)->depth('== 0')->hasResults()) {
|
||||
$this->filesystem->remove($oldDir);
|
||||
}
|
||||
},
|
||||
];
|
||||
ksort($patches, SORT_NATURAL);
|
||||
|
||||
|
||||
@@ -1351,7 +1351,7 @@ class Service implements InjectionAwareInterface
|
||||
'invoice' => $invoice,
|
||||
];
|
||||
|
||||
$loader = new FilesystemLoader(Path::join(__DIR__, 'pdf_template'));
|
||||
$loader = new FilesystemLoader(Path::join(__DIR__, 'templates', 'pdf'));
|
||||
$twig = $this->di['twig'];
|
||||
$twig->setLoader($loader);
|
||||
$html = $twig->render($this->getPdfTemplate(), $vars);
|
||||
@@ -1592,9 +1592,9 @@ class Service implements InjectionAwareInterface
|
||||
// Start of PDF related functions
|
||||
private function getPdfCss(): string
|
||||
{
|
||||
$basePath = Path::join(__DIR__, 'pdf_template');
|
||||
$customCssPath = Path::join($basePath, 'custom-pdf.css');
|
||||
$defaultCssPath = Path::join($basePath, 'default-pdf.css');
|
||||
$basePath = Path::join(__DIR__, 'templates', 'pdf');
|
||||
$customCssPath = Path::join($basePath, 'custom-invoice.css');
|
||||
$defaultCssPath = Path::join($basePath, 'default-invoice.css');
|
||||
|
||||
if ($this->filesystem->exists($customCssPath)) {
|
||||
$CSS = $this->filesystem->readFile($customCssPath);
|
||||
@@ -1611,11 +1611,11 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
private function getPdfTemplate(): string
|
||||
{
|
||||
if ($this->filesystem->exists(Path::join(__DIR__, 'pdf_template', 'custom-pdf.twig'))) {
|
||||
return 'custom-pdf.twig';
|
||||
if ($this->filesystem->exists(Path::join(__DIR__, 'templates', 'pdf', 'custom-invoice.twig'))) {
|
||||
return 'custom-invoice.twig';
|
||||
}
|
||||
|
||||
return 'default-pdf.twig';
|
||||
return 'default-invoice.twig';
|
||||
}
|
||||
|
||||
private function getPdfLogoSource(string $originalUrl): array
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* This file contains the default CSS used for the PDF generator.
|
||||
* You can copy and rename this file to 'custom-pdf.css' and customize the CSS as you wish.
|
||||
* You can copy and rename this file to 'custom-invoice.css' and customize the CSS as you wish.
|
||||
* The file will be loaded and inserted into the <style> tags for the PDF generation.
|
||||
* The backend used for PDF generation is Dompdf, which has fairly limited CSS support, roughly CSS 2.1
|
||||
*/
|
||||
File renamed without changes.
Reference in new issue
Block a user