mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-08-04 07:02:13 +00:00
Generated files carried no document properties at all, so an archive of them showed a column of blank titles and no author. Title, Subject, Author and Creator are now written from the document number and company, on both drivers: dompdf via addInfo(), Gotenberg via metadata(). dompdf needed more than the API call. It reads Title from the <title> element during render(), which happens after addInfo(), so metadata set through the API alone was silently overwritten by whatever the template put there and the two drivers disagreed about what the file was called. The title is written into the markup as well, escaped. Also adds an archival format setting for Gotenberg: off, PDF/A-1b, -2b or -3b. PDF/A-3 is what the EU e-invoicing formats expect. Verified against a stock gotenberg:8 -- LibreOffice inside the image does the conversion and the output carries the right pdfaid:part in its XMP -- so no extra components are needed. A fixed list rather than free text, because the SDK forwards whatever it is given and an unsupported value would surface only as an HTTP error from the service at render time. Empty is a real choice meaning an ordinary PDF, so it overrides an env default rather than falling through it. Gotenberg only: dompdf cannot produce PDF/A. Claude-Session: https://claude.ai/code/session_01QmECndmNZwzN65Zz9P87dF
124 lines
4.4 KiB
PHP
124 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\FileDisk;
|
|
use App\Models\Setting;
|
|
use App\Services\Mail\MailConfigurationService;
|
|
use App\Services\Storage\FileDiskService;
|
|
use App\Support\Setup\InstallUtils;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class AppConfigProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Bootstrap services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
// Check if database is available
|
|
if (! InstallUtils::isDbCreated()) {
|
|
return;
|
|
}
|
|
|
|
$this->configureMailFromDatabase();
|
|
$this->configurePDFFromDatabase();
|
|
$this->configureFileSystemFromDatabase();
|
|
}
|
|
|
|
/**
|
|
* Configure mail settings from database
|
|
*/
|
|
protected function configureMailFromDatabase(): void
|
|
{
|
|
try {
|
|
app(MailConfigurationService::class)->applyGlobalConfig();
|
|
} catch (\Exception $e) {
|
|
// Silently fail if database is not available (during installation, migrations, etc.)
|
|
// This prevents the application from breaking during setup
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Configure PDF settings from database
|
|
*/
|
|
protected function configurePDFFromDatabase(): void
|
|
{
|
|
try {
|
|
$pageSettings = [
|
|
'pdf_paper_width' => 'pdf.page.paper_width',
|
|
'pdf_paper_height' => 'pdf.page.paper_height',
|
|
'pdf_orientation' => 'pdf.page.orientation',
|
|
'pdf_margin_top' => 'pdf.page.margin_top',
|
|
'pdf_margin_right' => 'pdf.page.margin_right',
|
|
'pdf_margin_bottom' => 'pdf.page.margin_bottom',
|
|
'pdf_margin_left' => 'pdf.page.margin_left',
|
|
];
|
|
|
|
$pdfSettings = Setting::getSettings(array_merge(
|
|
['pdf_driver', 'gotenberg_host', 'gotenberg_pdfa', 'pdf_page_numbers'],
|
|
array_keys($pageSettings),
|
|
));
|
|
|
|
if (! empty($pdfSettings['pdf_driver'])) {
|
|
Config::set('pdf.driver', $pdfSettings['pdf_driver']);
|
|
|
|
if ($pdfSettings['pdf_driver'] === 'gotenberg') {
|
|
if (! empty($pdfSettings['gotenberg_host'])) {
|
|
Config::set('pdf.connections.gotenberg.host', $pdfSettings['gotenberg_host']);
|
|
}
|
|
|
|
// Empty is a real choice here -- it means an ordinary PDF --
|
|
// so an explicitly stored blank must override an env default.
|
|
if (isset($pdfSettings['gotenberg_pdfa'])) {
|
|
Config::set('pdf.connections.gotenberg.pdfa', $pdfSettings['gotenberg_pdfa'] ?: null);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Page geometry is applied regardless of driver. Note the isset guard
|
|
// rather than !empty: a saved margin of "0mm" is a deliberate choice,
|
|
// and !empty() would discard it and silently fall back to the default.
|
|
foreach ($pageSettings as $setting => $configKey) {
|
|
if (isset($pdfSettings[$setting]) && trim((string) $pdfSettings[$setting]) !== '') {
|
|
Config::set($configKey, $pdfSettings[$setting]);
|
|
}
|
|
}
|
|
|
|
// Stored as a string, so cast rather than passing '0' through as a
|
|
// truthy value.
|
|
if (isset($pdfSettings['pdf_page_numbers'])) {
|
|
Config::set(
|
|
'pdf.page.page_numbers',
|
|
filter_var($pdfSettings['pdf_page_numbers'], FILTER_VALIDATE_BOOLEAN)
|
|
);
|
|
}
|
|
} catch (\Exception $e) {
|
|
// Silently fail if database is not available (during installation, migrations, etc.)
|
|
// This prevents the application from breaking during setup
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Configure file system settings from database
|
|
*/
|
|
protected function configureFileSystemFromDatabase(): void
|
|
{
|
|
try {
|
|
$fileDisk = FileDisk::whereSetAsDefault(true)->first();
|
|
|
|
if (! $fileDisk) {
|
|
return;
|
|
}
|
|
|
|
$diskName = app(FileDiskService::class)->registerDisk($fileDisk);
|
|
|
|
// Point Spatie Media Library at the resolved disk
|
|
config(['media-library.disk_name' => $diskName]);
|
|
} catch (\Exception $e) {
|
|
// Silently fail if database is not available (during installation, migrations, etc.)
|
|
}
|
|
}
|
|
}
|