Entrega dashboard e correccoes transversais preservando Ofertas instalado
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -23,7 +23,7 @@ final class CompanyPreparation
|
||||
return ['version' => self::VERSION, 'forms' => config('company-comparison.forms'),
|
||||
'roles' => ['subscriber' => 'Titular, sócio ou accionista', 'administrator' => 'Administrador ou gerente', 'representative' => 'Representante', 'beneficial_owner' => 'Beneficiário efectivo declarado'],
|
||||
'source' => config('company-comparison.source'),
|
||||
'template_status' => 'source_pending', 'template_notice' => 'Os sete exemplares referidos no complemento ainda não foram fornecidos. Esta ficha prepara dados para revisão; não é uma minuta contratual, assinatura, registo ou licença.'];
|
||||
'template_status' => 'source_pending', 'template_notice' => 'Os modelos contratuais não estão disponíveis nesta preparação. Prepare os dados para revisão; esta preparação não é uma minuta contratual, assinatura, registo ou licença.'];
|
||||
}
|
||||
|
||||
/** Reuse only the already-authorized, frozen dossier values, never a fresh master lookup.
|
||||
@@ -36,8 +36,8 @@ final class CompanyPreparation
|
||||
$sources['case_proponent'] = ['name' => $payload['name'], 'kind' => 'person', 'reference' => $case->id,
|
||||
'version' => $payload['reuse_consent']['date'] ?? 'creation', 'origin' => 'Proponente conservado na criação do dossier'];
|
||||
}
|
||||
if ($case->company_id && ! empty($payload['company']['name'])) {
|
||||
$sources['case_company'] = ['name' => $payload['company']['name'], 'kind' => 'entity', 'reference' => $case->company_id,
|
||||
if (($case->company_id || ! empty($payload['investor_path']['context']['promoter_entity']['id'])) && ! empty($payload['company']['name'])) {
|
||||
$sources['case_company'] = ['name' => $payload['company']['name'], 'kind' => 'entity', 'reference' => $case->company_id ?? $payload['investor_path']['context']['promoter_entity']['id'],
|
||||
'version' => $payload['company_version'] ?? null, 'origin' => 'Declaração de empresa conservada no dossier'];
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ final class CompanyPreparation
|
||||
{
|
||||
$case = $this->desk->case($actor, $id);
|
||||
$payload = $this->desk->decode($case->payload);
|
||||
$v = Validator::make($input, ['revision' => 'nullable|uuid', 'history_before' => 'nullable|integer|min:1'])->validate();
|
||||
$v = Validator::make($input, ['revision' => 'nullable|uuid', 'history_before' => 'nullable|integer|min:1', 'form' => ['nullable', Rule::in(array_keys(config('company-comparison.forms')))]])->validate();
|
||||
$saved = $payload['company_preparation'] ?? null;
|
||||
if (! empty($v['revision'])) {
|
||||
$event = DB::table('desk_events')->where('case_id', $id)->where('action', self::EVENT)->where('id', $v['revision'])->first();
|
||||
@@ -228,11 +228,22 @@ final class CompanyPreparation
|
||||
$saved = $this->desk->decode($event->payload)['snapshot'];
|
||||
}
|
||||
$facts = $saved['facts'] ?? $this->facts(['facts' => []]);
|
||||
$entity = $payload['investor_path']['context']['promoter_entity'] ?? null;
|
||||
$context = app(InvestorContext::class)->state($case)['fields'];
|
||||
$existingEntity = in_array($entity['kind'] ?? '', ['company', 'organization'], true);
|
||||
if (! $saved && empty($v['revision'])) {
|
||||
foreach (['currency' => 'currency', 'activities' => 'products_services', 'seat' => 'location'] as $target => $source) {
|
||||
if (empty($facts[$target]) && ! empty($context[$source])) $facts[$target] = $context[$source];
|
||||
}
|
||||
$facts['proposed_name'] = $entity['snapshot']['name'] ?? $facts['proposed_name'];
|
||||
$knownForm = $entity['snapshot']['legal_form'] ?? null;
|
||||
$facts['form'] = $existingEntity ? $knownForm : ($v['form'] ?? $facts['form']);
|
||||
}
|
||||
$events = DB::table('desk_events')->where('case_id', $id)->where('action', self::EVENT)
|
||||
->when(! empty($v['history_before']), fn ($q) => $q->where('event_order', '<', $v['history_before']))
|
||||
->orderByDesc('event_order')->limit(26)->get(['id', 'payload', 'event_order']);
|
||||
|
||||
return ['case' => ['id' => $id, 'title' => $case->title, 'version' => (int) $case->version],
|
||||
return ['entity' => $entity, 'proposedForm' => ! $existingEntity ? ($v['form'] ?? null) : null, 'case' => ['id' => $id, 'title' => $case->title, 'version' => (int) $case->version],
|
||||
'canWrite' => ! $case->closed_at && $this->desk->owns($actor, $case), 'historical' => ! empty($v['revision']),
|
||||
'definition' => $saved['definition'] ?? $this->definition(), 'facts' => $facts, 'review' => $saved['review'] ?? $this->review($facts), 'saved' => $saved,
|
||||
'sources' => $this->sources($case), 'history' => $events->take(25)->map(function ($e) {
|
||||
@@ -265,6 +276,11 @@ final class CompanyPreparation
|
||||
$hash = hash('sha256', json_encode([(int) $v['version'], $facts], JSON_THROW_ON_ERROR));
|
||||
abort_if($case->closed_at || (int) $case->version !== (int) $v['version'], 409, 'O dossier mudou ou foi fechado. Os dados continuam no formulário; recupere a versão antes de guardar.');
|
||||
$payload = $this->desk->decode($case->payload);
|
||||
$entity = $payload['investor_path']['context']['promoter_entity'] ?? null;
|
||||
$registeredForm = $entity['snapshot']['legal_form'] ?? null;
|
||||
if (in_array($entity['kind'] ?? '', ['company', 'organization'], true) && $registeredForm) {
|
||||
abort_unless($facts['form'] === $registeredForm, 422, 'A forma jurídica da entidade existente não é alterada nesta preparação. Use o percurso próprio de alteração do cadastro.');
|
||||
}
|
||||
$previous = $payload['company_preparation'] ?? null;
|
||||
$resolved = $this->resolve($facts, $this->sources($case), $previous);
|
||||
$definition = $this->definition();
|
||||
|
||||
Reference in New Issue
Block a user