54 lines
1.6 KiB
PHP
54 lines
1.6 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()
|
|
->back()
|
|
->with('message-info', 'Adjustment added successfully.');
|
|
}
|
|
|
|
public function destroy(ClientInvoiceAdjustment $adjustment)
|
|
{
|
|
abort_unless($this->hierarchyService->canViewClient(Auth::user(), $adjustment->client), 403);
|
|
|
|
$adjustment->delete();
|
|
|
|
return redirect()
|
|
->back()
|
|
->with('message-info', 'Adjustment deleted successfully.');
|
|
}
|
|
}
|