Files
Kol-Manager/app/Http/Controllers/InvoiceSettingsController.php

57 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers;
use App\Models\InvoiceSettings;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\View\View;
class InvoiceSettingsController extends Controller
{
public function edit(): View
{
$settings = InvoiceSettings::instance();
return view('invoices.settings', compact('settings'));
}
public function update(Request $request): RedirectResponse
{
$validated = $request->validate([
'invoice_prefix' => 'required|string|max:20',
'invoice_next_number' => 'required|integer|min:1',
'header_name' => 'nullable|string|max:100',
'header_title' => 'nullable|string|max:150',
'header_logo' => 'nullable|image|max:2048',
'accent_color' => 'nullable|string|max:20',
'default_tax_rate' => 'nullable|numeric|min:0|max:100',
'default_currency' => 'nullable|string|max:10',
'default_service_description'=> 'nullable|string|max:255',
'default_bank_name' => 'nullable|string|max:100',
'default_branch_name' => 'nullable|string|max:100',
'default_bank_account' => 'nullable|string|max:50',
'default_bank_holder' => 'nullable|string|max:100',
'default_notes' => 'nullable|string|max:1000',
]);
$settings = InvoiceSettings::instance();
if ($request->hasFile('header_logo')) {
// Delete old logo if exists
if ($settings->header_logo) {
Storage::disk('public')->delete($settings->header_logo);
}
$path = $request->file('header_logo')->store('invoice-logos', 'public');
$validated['header_logo'] = $path;
}
$settings->update($validated);
return redirect()->route('invoice-settings.edit')
->with('success', '🧾 Invoice settings saved!');
}
}