- Created Note model and controller for handling notes. - Added routes for notes CRUD operations. - Implemented notes index view with search and pinning functionality. - Created migration for notes table with necessary fields. - Developed event creation form with client and contract options.
89 lines
3.1 KiB
PHP
89 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\InvoiceSettings;
|
|
use Illuminate\Http\JsonResponse;
|
|
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!');
|
|
}
|
|
|
|
public function uploadLogo(Request $request): JsonResponse
|
|
{
|
|
$request->validate(['header_logo' => 'required|image|max:2048']);
|
|
|
|
$settings = InvoiceSettings::instance();
|
|
|
|
if ($settings->header_logo) {
|
|
Storage::disk('public')->delete($settings->header_logo);
|
|
}
|
|
|
|
$path = $request->file('header_logo')->store('invoice-logos', 'public');
|
|
$settings->update(['header_logo' => $path]);
|
|
|
|
return response()->json([
|
|
'url' => asset('storage/' . $path),
|
|
]);
|
|
}
|
|
|
|
public function deleteLogo(): RedirectResponse
|
|
{
|
|
$settings = InvoiceSettings::instance();
|
|
|
|
if ($settings->header_logo) {
|
|
Storage::disk('public')->delete($settings->header_logo);
|
|
$settings->update(['header_logo' => null]);
|
|
}
|
|
|
|
return redirect()->route('invoice-settings.edit')
|
|
->with('success', '🗑️ Logo removed.');
|
|
}
|
|
}
|