@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\CommonFinanceAdministration;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Inertia;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class CommonFinanceAdministrationController extends Controller
|
||||
{
|
||||
public function show(Request $request, CommonFinanceAdministration $service): Response
|
||||
{
|
||||
$actor = $request->user('web');
|
||||
abort_unless($actor instanceof User, 403);
|
||||
$data = $request->validate(['user' => 'nullable|integer|min:1', 'q' => 'nullable|string|max:100',
|
||||
'users_page' => 'nullable|integer|min:1|max:1000000', 'history_page' => 'nullable|integer|min:1|max:1000000']);
|
||||
Inertia::encryptHistory();
|
||||
$response = Inertia::render('company/finance', $service->workspace($actor, isset($data['user']) ? (int) $data['user'] : null, $data['q'] ?? ''))->toResponse($request);
|
||||
$response->headers->set('Cache-Control', 'private, no-store, max-age=0');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function store(Request $request, string $kind, CommonFinanceAdministration $service): RedirectResponse
|
||||
{
|
||||
$actor = $request->user('web');
|
||||
abort_unless($actor instanceof User, 403);
|
||||
try {
|
||||
$service->save($actor, $kind, $request->all());
|
||||
} catch (\DomainException $error) {
|
||||
if ($request->header('X-Inertia')) {
|
||||
throw ValidationException::withMessages(['configuration' => $error->getMessage()]);
|
||||
}
|
||||
abort(409, $error->getMessage());
|
||||
} catch (\InvalidArgumentException $error) {
|
||||
if ($request->header('X-Inertia')) {
|
||||
throw ValidationException::withMessages(['configuration' => $error->getMessage()]);
|
||||
}
|
||||
abort(422, $error->getMessage());
|
||||
}
|
||||
|
||||
return back()->with('success', 'Configuração financeira registada com histórico.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user