inspiren-sem-tool/app/Http/Controllers/ClientInvoiceAdjustmentController.php

55 lines
1.7 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\ClientInvoiceAdjustment;
use App\Models\Client;
use App\Services\UserHierarchyService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;
class ClientInvoiceAdjustmentController extends Controller
{
public function __construct(private UserHierarchyService $hierarchyService)
{
}
public function store(Request $request, Client $client)
{
abort_unless($this->hierarchyService->canViewClient(Auth::user(), $client), 403);
$validated = $request->validate([
'entry_type' => ['required', 'string', Rule::in([
ClientInvoiceAdjustment::TYPE_DEBIT,
ClientInvoiceAdjustment::TYPE_CREDIT,
])],
'amount' => ['required', 'numeric', 'min:0'],
'remark' => ['nullable', 'string'],
]);
ClientInvoiceAdjustment::create([
'client_id' => $client->id,
'entry_type' => $validated['entry_type'],
'amount' => $validated['amount'],
'remark' => $validated['remark'] ?? null,
]);
return redirect()
->route('google-ads.accounts.show', ['id' => $client->customer_id])
->with('message-info', 'Adjustment added successfully.');
}
public function destroy(ClientInvoiceAdjustment $adjustment)
{
abort_unless($this->hierarchyService->canViewClient(Auth::user(), $adjustment->client), 403);
$client = $adjustment->client;
$adjustment->delete();
return redirect()
->route('google-ads.accounts.show', ['id' => $client->customer_id])
->with('message-info', 'Adjustment deleted successfully.');
}
}