diff --git a/app/Services/InvestorContext.php b/app/Services/InvestorContext.php index 6e972305..591525ef 100644 --- a/app/Services/InvestorContext.php +++ b/app/Services/InvestorContext.php @@ -26,6 +26,9 @@ final class InvestorContext public const FIELDS = ['promoter_entity_key', 'legal_name', 'legal_form', 'registration_number', 'products_services', 'investment_budget_min', 'investment_budget_max', 'project_title', 'project_summary', 'sector_id', 'sector', 'province_id', 'district_id', 'admin_post_id', 'locality_id', 'province', 'district', 'location', 'currency', 'expected_start_date', 'fiscal_period', 'fiscal_periodicity', 'fiscal_month', 'investor_origin', 'person_type', 'entity_stage', 'tax_residency_country', 'fiscal_residency_country', 'activity_id', 'project_type', 'maturity_stage', 'special_zone_id', 'investment_regime', ...PrivateInvestmentPreparation::FIELDS]; + /** The investor's primary intention: once chosen, later references may only propose a different one. */ + public const INTENTION_FIELDS = ['sector_id', 'sector', 'activity_id']; + public function __construct(private readonly VirtualDesk $desk) {} /** @@ -674,7 +677,9 @@ final class InvestorContext $provenance[$key] = ['kind' => 'process_declaration', 'actor_id' => $actor->id, 'context_revision' => $old['revision'] + 1]; } foreach ($proposed as $key => $value) { - if (($fields[$key] ?? '') === '' || (($provenance[$key]['kind'] ?? '') !== 'process_declaration' && ($provenance[$key]['kind'] ?? '') !== 'dossier') || in_array($key, $data['replace_fields'] ?? [], true)) { + // A hotel stays a hotel: another activity is only proposed, never swapped in silently. + $intention = in_array($key, self::INTENTION_FIELDS, true) && ($fields[$key] ?? '') !== ''; + if (($fields[$key] ?? '') === '' || (! $intention && ($provenance[$key]['kind'] ?? '') !== 'process_declaration' && ($provenance[$key]['kind'] ?? '') !== 'dossier') || in_array($key, $data['replace_fields'] ?? [], true)) { if (($fields[$key] ?? null) !== $value) { $replaced[] = ['field' => $key, 'before' => $fields[$key] ?? null, 'after' => $value]; }$fields[$key] = $value; @@ -685,7 +690,7 @@ final class InvestorContext } // Remove inherited subordinate geography only when its source was actually replaced. foreach ($fields as $key => $value) { - if (! array_key_exists($key, $proposed) && in_array($key, ['province_id', 'district_id', 'admin_post_id', 'locality_id', 'province', 'district', 'location', 'sector_id', 'sector', 'special_zone_id', 'investment_regime'], true) && isset($provenance[$key]['key'])) { + if (! array_key_exists($key, $proposed) && in_array($key, ['province_id', 'district_id', 'admin_post_id', 'locality_id', 'province', 'district', 'location', 'special_zone_id', 'investment_regime'], true) && isset($provenance[$key]['key'])) { unset($fields[$key],$provenance[$key]); } } diff --git a/resources/js/pages/investor-path/context.tsx b/resources/js/pages/investor-path/context.tsx index 95b727b7..c91deab4 100644 --- a/resources/js/pages/investor-path/context.tsx +++ b/resources/js/pages/investor-path/context.tsx @@ -1316,7 +1316,7 @@ function ScopedContextEditor({ Substituições explícitas de declarações
- Por defeito, uma seleção conserva o título e as + Por defeito, uma selecção conserva o título e as declarações do utilizador. Autorize somente os campos que pretende substituir pelo cadastro.
@@ -1337,10 +1337,40 @@ function ScopedContextEditor({ setPlan(null); }} />{' '} - Usar a fonte selecionada em{' '} + Usar a fonte seleccionada em{' '} {contextFieldNames[k].toLowerCase()} ))} + {view.context.fields.sector && ( + + )} {view.private_investment && (