47 lines
2.6 KiB
PHP
47 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\InvestmentLegalSource;
|
|
use App\Services\SimulationTaxGovernanceAccess;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
/** Explicit fiscal curation of an identified official source; not an independent legal opinion. */
|
|
final class SimulationFiscalSourceController extends Controller
|
|
{
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
SimulationTaxGovernanceAccess::requireRole($request->user(), 'editors');
|
|
$data = $request->validate([
|
|
'title' => ['required', 'string', 'max:255'], 'url' => ['required', 'url:https', 'max:2000'],
|
|
'diploma' => ['required', 'string', 'max:255'], 'article' => ['required', 'string', 'max:255'],
|
|
'competent_entity' => ['required', 'string', 'max:255'], 'valid_from' => ['required', 'date_format:Y-m-d'],
|
|
'valid_until' => ['nullable', 'date_format:Y-m-d', 'after_or_equal:valid_from'],
|
|
'sha256' => ['required', 'regex:/^[a-f0-9]{64}$/D'],
|
|
'citation' => ['required', 'string', 'min:10', 'max:2000'],
|
|
'official_origin' => ['required', 'string', 'min:10', 'max:2000'],
|
|
]);
|
|
|
|
return DB::transaction(function () use ($request, $data): JsonResponse {
|
|
$actor = $request->user();
|
|
$acceptance = ['scope' => 'fiscal_parameters', 'basis' => 'Tempo-official-sources-20261008',
|
|
'responsible_user_id' => $actor->id, 'sha256' => $data['sha256'], 'citation' => $data['citation'],
|
|
'official_origin' => $data['official_origin'], 'accepted_at' => now()->toISOString(),
|
|
'legal_opinion' => false, 'independent_review' => false];
|
|
unset($data['sha256'], $data['citation'], $data['official_origin']);
|
|
$source = InvestmentLegalSource::create([...$data, 'owner_id' => $actor->id, 'validator_id' => null,
|
|
'validation_status' => 'pending', 'validated_at' => null, 'version_no' => 1, 'fiscal_acceptance' => $acceptance]);
|
|
DB::table('audit_events')->insert(['source_system' => 'simulation-fiscal-maintenance',
|
|
'entity_type' => 'investment_legal_sources', 'entity_id' => $source->id, 'actor_user_id' => $actor->id,
|
|
'action' => 'official_source_acceptance', 'after_data' => json_encode([
|
|
'source' => $source->attributesToArray(), 'basis' => $acceptance,
|
|
'sha256' => hash('sha256', $source->toJson()),
|
|
], JSON_THROW_ON_ERROR)]);
|
|
|
|
return response()->json($source->fresh(), 201);
|
|
});
|
|
}
|
|
}
|