mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-08 05:54:47 +00:00
Configurations cleanup & database configurations for mail and pdfs (#479)
* Move Mail, PDF configuration to Database, standardize configurations * Set default currency to USD on install * Pint code
This commit is contained in:
committed by
GitHub
parent
3da86965e1
commit
18d63a3375
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\V1\Admin\Settings;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\PDFConfigurationRequest;
|
||||
use App\Models\Setting;
|
||||
use App\Space\EnvironmentManager;
|
||||
|
||||
class PDFConfigurationController extends Controller
|
||||
@@ -34,11 +35,19 @@ class PDFConfigurationController extends Controller
|
||||
{
|
||||
$this->authorize('manage pdf config');
|
||||
|
||||
// Get PDF settings from database
|
||||
$pdfSettings = Setting::getSettings([
|
||||
'pdf_driver',
|
||||
'gotenberg_host',
|
||||
'gotenberg_papersize',
|
||||
'gotenberg_margins',
|
||||
]);
|
||||
|
||||
$config = [
|
||||
'pdf_driver' => config('pdf.driver'),
|
||||
'gotenberg_host' => config('pdf.gotenberg.host'),
|
||||
'gotenberg_margins' => config('pdf.gotenberg.margins'),
|
||||
'gotenberg_papersize' => config('pdf.gotenberg.papersize'),
|
||||
'pdf_driver' => $pdfSettings['pdf_driver'] ?? config('pdf.driver'),
|
||||
'gotenberg_host' => $pdfSettings['gotenberg_host'] ?? config('pdf.connections.gotenberg.host'),
|
||||
'gotenberg_margins' => $pdfSettings['gotenberg_margins'] ?? config('pdf.connections.gotenberg.margins'),
|
||||
'gotenberg_papersize' => $pdfSettings['gotenberg_papersize'] ?? config('pdf.connections.gotenberg.papersize'),
|
||||
];
|
||||
|
||||
return response()->json($config);
|
||||
@@ -47,8 +56,47 @@ class PDFConfigurationController extends Controller
|
||||
public function saveEnvironment(PDFConfigurationRequest $request)
|
||||
{
|
||||
$this->authorize('manage pdf config');
|
||||
$results = $this->environmentManager->savePDFVariables($request);
|
||||
|
||||
return response()->json($results);
|
||||
// Prepare PDF settings for database storage
|
||||
$pdfSettings = $this->preparePDFSettingsForDatabase($request);
|
||||
|
||||
// Save PDF settings to database
|
||||
Setting::setSettings($pdfSettings);
|
||||
|
||||
return response()->json([
|
||||
'success' => 'pdf_variables_save_successfully',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare PDF settings for database storage
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function preparePDFSettingsForDatabase(PDFConfigurationRequest $request)
|
||||
{
|
||||
$driver = $request->get('pdf_driver');
|
||||
|
||||
// Base settings that are always saved
|
||||
$settings = [
|
||||
'pdf_driver' => $driver,
|
||||
];
|
||||
|
||||
// Driver-specific settings
|
||||
switch ($driver) {
|
||||
case 'gotenberg':
|
||||
$settings = array_merge($settings, [
|
||||
'gotenberg_host' => $request->get('gotenberg_host'),
|
||||
'gotenberg_papersize' => $request->get('gotenberg_papersize'),
|
||||
'gotenberg_margins' => $request->get('gotenberg_margins'),
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'dompdf':
|
||||
// dompdf doesn't have additional configuration in the current setup
|
||||
break;
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user