@@ -6,6 +6,7 @@ use App\Models\Opportunity;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Opis\JsonSchema\CompliantValidator;
|
||||
use Opis\JsonSchema\Errors\ErrorFormatter;
|
||||
@@ -29,6 +30,7 @@ class OpportunityCanonicalContract
|
||||
$schema['$defs'][$name.'Create']['allOf'] = $schema['$defs'][$name]['allOf'] ?? [];
|
||||
}
|
||||
$schema = app(OpportunityCategoryFields::class)->enrich($schema);
|
||||
$schema = app(OpportunityModularProfiles::class)->extend($schema);
|
||||
$schema = $this->writeSchema($schema, $draft);
|
||||
$properties = &$schema['$defs']['opportunityCreate']['properties'];
|
||||
unset($properties['mutation_context']); // Actor, audit reason and revision are server-owned.
|
||||
@@ -240,6 +242,14 @@ class OpportunityCanonicalContract
|
||||
ksort($payload);
|
||||
$snapshot = ['adapter_version' => self::VERSION, 'schema_sha256' => hash_file('sha256', resource_path('data/investmoz-opportunity-modular.schema.json')),
|
||||
'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',
|
||||
'gates' => $this->gates($record)];
|
||||
if ($record->opportunity_category === 'other') {
|
||||
$snapshot['qa_extension']['subtype'] = config('portal.opportunity_other_qa_subtypes.'.($payload['module_details']['subtype'] ?? ''), []);
|
||||
}
|
||||
}
|
||||
$snapshot['hash'] = hash('sha256', json_encode($snapshot, JSON_THROW_ON_ERROR));
|
||||
|
||||
return $snapshot;
|
||||
@@ -253,9 +263,7 @@ class OpportunityCanonicalContract
|
||||
private function categoryRules(array $p, Opportunity $record, array $resources, array &$errors): void
|
||||
{
|
||||
$category = $p['opportunity_category'];
|
||||
if (in_array($category, ['concession', 'financing', 'supply', 'other'], true)) {
|
||||
$errors['canonical.module_profile_version'] = '§25.4: não existe perfil modular aprovado/configurado. O rascunho permanece disponível; não inventar regras.';
|
||||
}
|
||||
app(OpportunityModularProfiles::class)->validate($p, $resources, $errors);
|
||||
foreach (['real_estate', 'land_rights', 'business_transaction'] as $module) {
|
||||
$applicable = match ($module) {
|
||||
'real_estate' => ['real_estate'], 'land_rights' => ['land_rights'], default => ['business_sale', 'business_partnership', 'franchise']
|
||||
@@ -346,6 +354,7 @@ class OpportunityCanonicalContract
|
||||
$p = $snapshot['payload'];
|
||||
$errors = [];
|
||||
app(OpportunityCategoryFields::class)->publication($p, $errors);
|
||||
app(OpportunityModularProfiles::class)->publication($p, $errors);
|
||||
foreach ($snapshot['resources']['documents'] ?? [] as $id => $document) {
|
||||
if (! empty($document['payload']['valid_until']) && $document['payload']['valid_until'] < today()->toDateString()) {
|
||||
$errors['documents.'.$id] = 'Documento incluído expirou; preserve o original e reveja a versão.';
|
||||
@@ -400,7 +409,7 @@ class OpportunityCanonicalContract
|
||||
'business_sale' => ['corporate_screening', 'financial_review', 'legal_tax_due_diligence', 'confidentiality_clearance'],
|
||||
'business_partnership' => ['corporate_screening', 'financial_review', 'partnership_governance_review', 'legal_tax_due_diligence'],
|
||||
'franchise' => ['brand_license_review', 'financial_review', 'franchise_legal_review', 'confidentiality_clearance'],
|
||||
default => [],
|
||||
default => app(OpportunityModularProfiles::class)->gates($record),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -411,7 +420,17 @@ class OpportunityCanonicalContract
|
||||
{
|
||||
$business = isset($payload['business_transaction']) && ($payload['visibility'] ?? '') === 'public';
|
||||
|
||||
return ['title' => (string) ($payload['official_title'] ?? ''), 'summary' => (string) ($business ? ($payload['business_transaction']['teaser'] ?? '') : ($payload['executive_summary'] ?? '')),
|
||||
$label = match ($payload['module_details']['mode'] ?? '') {
|
||||
'intention_call' => 'Intenção/chamada em preparação — não é direito atribuído. ',
|
||||
'awarded_right' => 'Concessão com ato competente documentado. ',
|
||||
'seeking_funding' => 'Procura de financiamento. ', 'funding_offer' => 'Oferta de financiamento — sujeita a análise do beneficiário. ',
|
||||
'purchase_request' => 'Pedido de compra. ', 'supply_offer' => 'Oferta de fornecimento. ', default => '',
|
||||
};
|
||||
if (($payload['module_details']['conditions_status'] ?? '') === 'proposed') {
|
||||
$label .= 'Valores e condições propostos, sem compromisso assumido. ';
|
||||
}
|
||||
|
||||
return ['title' => (string) ($payload['official_title'] ?? ''), 'summary' => Str::limit($label.(string) ($business ? ($payload['business_transaction']['teaser'] ?? '') : ($payload['executive_summary'] ?? '')), 499, '…'),
|
||||
'description' => (string) ($business ? ($payload['business_transaction']['teaser'] ?? '') : ($payload['demand_statement'] ?? ''))];
|
||||
}
|
||||
|
||||
@@ -427,7 +446,9 @@ class OpportunityCanonicalContract
|
||||
->orWhereExists(fn ($i) => $i->selectRaw('1')->from('investor_contacts as ic')->join('investors as inv', 'inv.id', '=', 'ic.investor_id')->whereColumn('ic.contact_id', 'contacts.id')->whereIn('inv.organization_id', $orgs)->whereNull('inv.deleted_at'));
|
||||
})->get(['id', 'full_name']);
|
||||
|
||||
return ['version' => self::VERSION, 'schema' => $this->schema(true)['$defs']['opportunityCreate'],
|
||||
return ['version' => self::VERSION, 'modularProfiles' => app(OpportunityModularProfiles::class)->enabled() ? OpportunityModularProfiles::PROFILES : [],
|
||||
'historyVersion' => app(OpportunityModularProfiles::class)->enabled() ? OpportunityModularProfiles::HISTORY_VERSION : null,
|
||||
'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(),
|
||||
|
||||
Reference in New Issue
Block a user