@@ -15,6 +15,33 @@ use Opis\JsonSchema\Errors\ValidationError;
|
||||
/** Explicit adapter of §25/26 to existing IDs and resource collections; never renumbers records. */
|
||||
class OpportunityCanonicalContract
|
||||
{
|
||||
public const BASE_CATEGORIES = ['investment_project', 'real_estate', 'land_rights', 'business_sale', 'business_partnership', 'franchise'];
|
||||
|
||||
/** Availability of this bounded base-category delivery, without rewriting existing contracts/data. */
|
||||
public function deliveryBlockers(array $payload): array
|
||||
{
|
||||
$errors = [];
|
||||
if (! in_array($payload['opportunity_category'] ?? '', self::BASE_CATEGORIES, true) && ! app(OpportunityModularProfiles::class)->enabled()) {
|
||||
$errors['canonical.opportunity_category'] = 'Categoria fora desta entrega: concessão, financiamento, fornecimento e outros permanecem indisponíveis. Os registos anteriores são preservados.';
|
||||
}
|
||||
if (($payload['opportunity_category'] ?? '') === 'real_estate') {
|
||||
$property = $payload['real_estate'] ?? [];
|
||||
foreach (['construction_status' => ['completed'], 'occupancy_status' => ['vacant'], 'transaction_type' => ['sale', 'lease']] as $field => $values) {
|
||||
if (! empty($property[$field]) && ! in_array($property[$field], $values, true)) {
|
||||
$errors['canonical.real_estate.'.$field] = 'Variante indisponível para submissão nesta entrega. Pode guardar e recuperar a preparação; estão incluídas venda e arrendamento de imóvel concluído e desocupado.';
|
||||
}
|
||||
}
|
||||
if (array_filter($property['encumbrances'] ?? [], fn ($row) => ! empty($row['type']) && $row['type'] !== 'none')) {
|
||||
$errors['canonical.real_estate.encumbrances'] = 'Imóvel com encargos: pode preparar e guardar; a submissão deste ramo não está incluída nesta entrega.';
|
||||
}
|
||||
if (! empty($property['max_built_area']) || ! empty($property['urban_limit_document_id'])) {
|
||||
$errors['canonical.real_estate.max_built_area'] = 'Limitações urbanísticas adicionais: preparação disponível; este ramo de submissão aguarda demonstração própria.';
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
public const VERSION = 'opportunity-canonical-adapter-20261010-semantic1';
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
@@ -178,7 +205,7 @@ class OpportunityCanonicalContract
|
||||
}
|
||||
};
|
||||
$check(($payload['opportunity_category'] ?? null) === $record->opportunity_category, 'opportunity_category', 'A categoria deve coincidir com o registo e a autorização.');
|
||||
$check(($payload['promoter_id'] ?? null) === ($record->organization_id ?? (int) $record->owner_user_id), 'promoter_id', 'Use a organização representada ou o autor individual; não outra identidade.');
|
||||
$check(($payload['promoter_id'] ?? null) === ($record->organization_id ?? (int) $record->owner_user_id), 'promoter_id', 'Identifique o promotor real da oportunidade; o operador do portal não o substitui.');
|
||||
$sector = DB::table('sectors')->where('id', $payload['sector_id'])->whereNull('deleted_at')->where('is_active', true)->first();
|
||||
$subsector = DB::table('economic_activities')->where('id', $payload['subsector_id'])->where('status', 'published')->first();
|
||||
$activity = DB::table('economic_activities')->where('id', $payload['economic_activity_id'])->where('status', 'published')->first();
|
||||
@@ -244,11 +271,18 @@ class OpportunityCanonicalContract
|
||||
'payload' => $payload, 'resources' => $resources];
|
||||
if (isset(OpportunityModularProfiles::PROFILES[$record->opportunity_category]) || ($payload['module_profile_version'] ?? '') === OpportunityModularProfiles::HISTORY_VERSION) {
|
||||
$snapshot['qa_extension'] = ['version' => OpportunityModularProfiles::VERSION, 'profile_version' => $payload['module_profile_version'],
|
||||
'functional_decision' => 'User recommendations accepted for QA, 10/10/2026; no active approval or security-holder nomination',
|
||||
'functional_decision' => 'Experimental QA proposal; functional approval of modular contracts and SLA remains pending. Legacy integration authorization does not approve these modules.',
|
||||
'gates' => $this->gates($record)];
|
||||
if ($record->opportunity_category === 'other') {
|
||||
$snapshot['qa_extension']['subtype'] = config('portal.opportunity_other_qa_subtypes.'.($payload['module_details']['subtype'] ?? ''), []);
|
||||
}
|
||||
// A documentary correction must not rewrite the checksum of an already
|
||||
// signed, unchanged version. Its historical annotation is explicitly
|
||||
// reconciled by the read adapter; new/changed content uses the current note.
|
||||
$prior = $record->workflow_context['submission'] ?? [];
|
||||
if (isset($prior['qa_extension']) && ($prior['payload'] ?? null) == $snapshot['payload'] && ($prior['resources'] ?? null) == $snapshot['resources']) {
|
||||
$snapshot['qa_extension']['functional_decision'] = $prior['qa_extension']['functional_decision'];
|
||||
}
|
||||
}
|
||||
$snapshot['hash'] = hash('sha256', json_encode($snapshot, JSON_THROW_ON_ERROR));
|
||||
|
||||
@@ -297,8 +331,16 @@ class OpportunityCanonicalContract
|
||||
}
|
||||
if ($category === 'real_estate') {
|
||||
$re = $p['real_estate'];
|
||||
if (($re['transaction_type'] === 'sale' && ($re['price'] ?? 0) <= 0) || ($re['transaction_type'] === 'lease' && (($re['rent'] ?? 0) <= 0 || empty($re['rent_periodicity'])))) {
|
||||
$errors['canonical.real_estate.price'] = 'Venda exige preço positivo; arrendamento exige renda positiva e periodicidade.';
|
||||
if ($re['transaction_type'] === 'sale' && ($re['price'] ?? 0) <= 0) {
|
||||
$errors['canonical.real_estate.price'] = 'Venda exige preço positivo.';
|
||||
}
|
||||
if ($re['transaction_type'] === 'lease') {
|
||||
if (($re['rent'] ?? 0) <= 0) {
|
||||
$errors['canonical.real_estate.rent'] = 'Arrendamento exige renda positiva.';
|
||||
}
|
||||
if (empty($re['rent_periodicity'])) {
|
||||
$errors['canonical.real_estate.rent_periodicity'] = 'Indique a periodicidade da renda.';
|
||||
}
|
||||
}
|
||||
if (in_array($re['construction_status'], ['completed', 'occupied', 'renovation'], true) && empty($re['property_condition'])) {
|
||||
$errors['canonical.real_estate.property_condition'] = 'Imóvel existente exige condição identificada.';
|
||||
@@ -438,6 +480,10 @@ class OpportunityCanonicalContract
|
||||
public function options(User $actor, ?Opportunity $record): array
|
||||
{
|
||||
$orgs = array_values(array_unique(array_column(app(PortalProfileAccess::class)->navigation($actor)['contexts'] ?? [], 'organization_id')));
|
||||
if (! $record && (app(PortalProfileAccess::class)->navigation($actor)['internalPromoter'] ?? false)) {
|
||||
// A staff creation scope does not expose unrelated private contact lists.
|
||||
$orgs = [];
|
||||
}
|
||||
if ($record?->organization_id) {
|
||||
$orgs = [$record->organization_id];
|
||||
}
|
||||
@@ -451,7 +497,8 @@ class OpportunityCanonicalContract
|
||||
'schema' => $this->schema(true)['$defs']['opportunityCreate'],
|
||||
'definitions' => $this->schema(true)['$defs'],
|
||||
'activities' => DB::table('economic_activities')->where('status', 'published')->get(['id', 'parent_id', 'sector_id', 'label_pt_mz', 'catalog_version_id']),
|
||||
'contacts' => $contacts, 'countries' => app(CountryCatalogue::class)->all(),
|
||||
'contacts' => $contacts, 'contactInvestors' => $record?->organization_id ? DB::table('investors')->where('organization_id', $record->organization_id)->whereNull('deleted_at')->whereIn('status', ['prospect', 'active'])->get(['id', 'legal_name']) : [],
|
||||
'countries' => app(CountryCatalogue::class)->all(),
|
||||
'authorities' => DB::table('authorities')->where('status', 'published')->get(['id', 'label_pt_mz']),
|
||||
'gates' => $record ? $this->gates($record) : [], 'resources' => $record ? array_combine(['locations', 'documents', 'images'], array_map(fn ($k) => array_values(array_filter(app(OpportunityResources::class)->listing($record->id, $k), fn ($row) => empty($row->deleted_at))), ['locations', 'documents', 'images'])) : []];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user