Merge branch 'main' of https://git.tempo.co.mz/nala/Investidor-V2 into front
This commit is contained in:
@@ -34,7 +34,11 @@ final class DemographyController extends Controller
|
||||
}
|
||||
$territories = $service->territories()->orderBy('name')->get(['id', 'name', 'parent_id', 'location_type']);
|
||||
|
||||
return Inertia::render('investment/demography', ['sectorReadings' => app(SectorContentAnalysis::class)->forTerritories($data['territories'] ?? []), 'evidence' => $evidence, 'filters' => $data, 'territories' => $territories, 'sectors' => DemographicEvidence::sectors()]);
|
||||
$sector = $data['sector'] ?? 'general';
|
||||
$slug = ['commerce' => 'comercio-e-servicos', 'tourism' => 'turismo', 'industry' => 'industria', 'agriculture' => 'agronegocio', 'education' => 'educacao', 'health' => 'saude'][$sector] ?? null;
|
||||
$entrySector = $slug ? DB::table('sectors')->where('slug', $slug)->where('is_active', true)->value('slug') : null;
|
||||
|
||||
return Inertia::render('investment/demography', ['entrySector' => $entrySector, 'sectorReadings' => app(SectorContentAnalysis::class)->forTerritories($data['territories'] ?? [], $sector), 'evidence' => $evidence, 'filters' => $data, 'territories' => $territories, 'sectors' => DemographicEvidence::sectors()]);
|
||||
}
|
||||
|
||||
public function management(Request $request, DemographicImport $service): Response|RedirectResponse
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\Opportunity;
|
||||
use App\Models\Project;
|
||||
use App\Services\ClusterCompetitiveness;
|
||||
use App\Services\CorridorAgribusinessOpportunities;
|
||||
use App\Services\InvestmentCatalogue;
|
||||
use App\Services\InvestmentComplements;
|
||||
use App\Services\InvestmentGeography;
|
||||
use App\Services\InvestmentRelations;
|
||||
@@ -92,7 +93,37 @@ class InvestmentPortfolioController extends Controller
|
||||
app(PublicSearchMetrics::class)->candidate($request, 'portfolio', $results->total(), $filters);
|
||||
}
|
||||
|
||||
return Inertia::render('portfolio/index', ['records' => $results,
|
||||
$publishedOpportunities = null;
|
||||
if (! $management) {
|
||||
// Embedded results reuse public visibility and direct territorial evidence.
|
||||
// A corridor's influence area never assigns a site to an opportunity.
|
||||
$opportunityFilters = array_intersect_key($filters, array_flip(['q', 'province_id', 'district_id', 'admin_post_id', 'locality_id']));
|
||||
$catalogue = app(InvestmentCatalogue::class);
|
||||
$opportunityQuery = $catalogue->query([...$opportunityFilters, 'territory_basis' => $territorySelection !== [] ? 'direct' : 'all', 'include_national' => false]);
|
||||
if (! empty($filters['sector'])) {
|
||||
$opportunityQuery->whereHas('sector', fn ($sector) => $sector->where('name', $filters['sector'])->orWhere('slug', $filters['sector']));
|
||||
}
|
||||
if (! empty($filters['kind'])) {
|
||||
$dossiers = (clone $query)->get();
|
||||
$opportunityQuery->where(function ($associated) use ($dossiers): void {
|
||||
$associated->whereRaw('false');
|
||||
foreach (['corridors' => 'corridor_id', 'clusters' => 'cluster_id', 'projects' => 'project_id'] as $relation => $foreign) {
|
||||
$associated->orWhereIn('opportunities.id', DB::table('opportunity_'.$relation)->whereIn($foreign, $dossiers->pluck($foreign)->filter())->select('opportunity_id'));
|
||||
}
|
||||
foreach ($dossiers as $dossier) {
|
||||
$associated->orWhereIn('opportunities.id', app(CorridorAgribusinessOpportunities::class)->portfolioOpportunityIds($dossier));
|
||||
}
|
||||
});
|
||||
}
|
||||
$publishedOpportunities = $opportunityQuery->orderBy('opportunities.title')
|
||||
->paginate(12, ['opportunities.*'], 'opportunities_page')->withQueryString();
|
||||
$publishedOpportunities->through(function ($opportunity) use ($catalogue): array {
|
||||
return ['id' => $opportunity->id, 'slug' => $opportunity->slug, 'title' => $opportunity->title,
|
||||
'summary' => $opportunity->summary, 'location' => $catalogue->locationPresentation($opportunity)['summary']];
|
||||
});
|
||||
}
|
||||
|
||||
return Inertia::render('portfolio/index', ['publicReferenceNames' => $management ? [] : $this->publicReferenceNames(), 'records' => $results, 'publishedOpportunities' => $publishedOpportunities,
|
||||
'management' => $management, 'filters' => $filters, 'sectors' => $sectorOptions, 'territorySelection' => $territorySelection]);
|
||||
}
|
||||
|
||||
@@ -152,7 +183,7 @@ class InvestmentPortfolioController extends Controller
|
||||
->orderByDesc('updated_at')->limit(10)->get(['id', 'version', 'updated_at'])
|
||||
: collect();
|
||||
|
||||
return Inertia::render('portfolio/show', ['editorialEnabled' => $editorial, 'complements' => $management ? [] : app(InvestmentComplements::class)->options('portfolio:'.$record->id), 'record' => $record, 'related' => $related, 'management' => $management, 'zones' => $zones,
|
||||
return Inertia::render('portfolio/show', ['publicReferenceNames' => $management ? [] : $this->publicReferenceNames(), 'editorialEnabled' => $editorial, 'complements' => $management ? [] : app(InvestmentComplements::class)->options('portfolio:'.$record->id), 'record' => $record, 'related' => $related, 'management' => $management, 'zones' => $zones,
|
||||
'anchorProject' => $anchorProject, 'existingSubmissions' => $existingSubmissions,
|
||||
'competitiveness' => $record->cluster_id ? app(ClusterCompetitiveness::class)->publicData($record->cluster_id) : null,
|
||||
'geography' => app(InvestmentRelations::class)->dossier($record, $management),
|
||||
@@ -187,6 +218,13 @@ class InvestmentPortfolioController extends Controller
|
||||
return back()->with('success', 'Rascunho guardado. A publicacao aguarda um revisor diferente do editor.');
|
||||
}
|
||||
|
||||
/** Resolve public cross-references for display without rewriting editorial content. */
|
||||
private function publicReferenceNames(): array
|
||||
{
|
||||
return self::visible()->get(['title', 'content'])->filter(fn ($row) => ! empty($row->content['code']))
|
||||
->mapWithKeys(fn ($row) => [$row->content['code'] => $row->title])->all();
|
||||
}
|
||||
|
||||
public function publish(Request $request, InvestmentDossier $dossier): RedirectResponse
|
||||
{
|
||||
abort_if(app(PortalEditorialWorkflow::class)->portfolioWrites($dossier->id), 409, 'Use a aprovação e publicação separadas da edição no circuito editorial.');
|
||||
|
||||
@@ -130,7 +130,11 @@ class InvestmentZoneController extends Controller
|
||||
|
||||
return $management ? $zone : [...app(InvestmentZoneOperationalProfile::class)->publicDetails($zone->toArray()), 'operational_details_public' => app(InvestmentZoneOperationalDetails::class)->publicData($zone)];
|
||||
});
|
||||
$props = ['detailsInstallation' => $management ? app(InvestmentZoneOperationalDetailsInstallation::class)->preview($request->user()) : null, 'installation' => $management ? app(InvestmentZoneProfileInstallation::class)->preview($request->user()) : null, 'records' => $rows, 'filters' => $filters, 'management' => $management, 'territorySelection' => $path,
|
||||
$groupAvailability = [];
|
||||
foreach (['zee', 'zfi', 'industrial_park'] as $category) {
|
||||
$groupAvailability[$category] = $zones->search(array_replace($filters, ['category' => $category]), $management)->count();
|
||||
}
|
||||
$props = ['groupAvailability' => $groupAvailability, 'detailsInstallation' => $management ? app(InvestmentZoneOperationalDetailsInstallation::class)->preview($request->user()) : null, 'installation' => $management ? app(InvestmentZoneProfileInstallation::class)->preview($request->user()) : null, 'records' => $rows, 'filters' => $filters, 'management' => $management, 'territorySelection' => $path,
|
||||
'zoneExtensionsAvailable' => Schema::hasColumn('investment_zones', 'source_evidence')];
|
||||
|
||||
return $request->is('api/*') ? response()->json($props) : Inertia::render('investment/zones', $props);
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Requests;
|
||||
use App\Services\CountryCatalogue;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class StoreSimulationFormDraftRequest extends FormRequest
|
||||
@@ -137,7 +138,7 @@ class StoreSimulationFormDraftRequest extends FormRequest
|
||||
'economic_snapshot.public_fields_confirmation' => ['nullable', 'in:yes,no'],
|
||||
'economic_snapshot.validation_acknowledged' => ['nullable', 'in:yes,no'],
|
||||
'economic_snapshot.investment_budget_min' => ['nullable', 'numeric', 'min:0'],
|
||||
'economic_snapshot.investment_budget_max' => ['nullable', 'numeric', 'min:0', \Illuminate\Validation\Rule::when($this->filled('economic_snapshot.investment_budget_min'), 'gte:economic_snapshot.investment_budget_min')],
|
||||
'economic_snapshot.investment_budget_max' => ['nullable', 'numeric', 'min:0', Rule::when($this->filled('economic_snapshot.investment_budget_min'), 'gte:economic_snapshot.investment_budget_min')],
|
||||
'economic_snapshot.currency' => ['nullable', 'string', 'regex:/^[A-Z]{3}$/'],
|
||||
'economic_snapshot.opportunity_currency' => ['nullable', 'string', 'regex:/^[A-Z]{3}$/'],
|
||||
'economic_snapshot.rate' => ['nullable', 'numeric', 'between:0,100'],
|
||||
@@ -217,11 +218,13 @@ class StoreSimulationFormDraftRequest extends FormRequest
|
||||
foreach ([
|
||||
'project_team_snapshot' => [
|
||||
'keys' => ['competency', 'state', 'action', 'estimated_cost', 'due_date'],
|
||||
'optional' => ['department', 'quantity', 'monthly_salary', 'start_month', 'end_month'],
|
||||
'states' => ['available', 'gap', 'unknown'],
|
||||
'amounts' => ['estimated_cost'],
|
||||
'amounts' => ['estimated_cost', 'monthly_salary'],
|
||||
],
|
||||
'project_execution_snapshot' => [
|
||||
'keys' => ['title', 'due_date', 'status', 'planned_amount', 'actual_amount'],
|
||||
'optional' => ['start_date', 'responsible', 'department'],
|
||||
'states' => ['planned', 'in_progress', 'completed'],
|
||||
'amounts' => ['planned_amount', 'actual_amount'],
|
||||
],
|
||||
@@ -232,7 +235,7 @@ class StoreSimulationFormDraftRequest extends FormRequest
|
||||
$rows = json_decode((string) $economic[$field], true);
|
||||
$valid = is_array($rows) && count($rows) <= 100;
|
||||
foreach (is_array($rows) ? $rows : [] as $row) {
|
||||
if (! is_array($row) || array_diff(array_keys($row), $schema['keys']) !== []
|
||||
if (! is_array($row) || array_diff(array_keys($row), array_merge($schema['keys'], $schema['optional'])) !== []
|
||||
|| array_diff($schema['keys'], array_keys($row)) !== []
|
||||
|| array_filter($row, fn ($value) => ! is_string($value) || mb_strlen($value) > 500) !== []) {
|
||||
$valid = false;
|
||||
@@ -244,12 +247,19 @@ class StoreSimulationFormDraftRequest extends FormRequest
|
||||
break;
|
||||
}
|
||||
foreach ($schema['amounts'] as $amountKey) {
|
||||
if ($row[$amountKey] !== '' && (! is_numeric($row[$amountKey]) || (float) $row[$amountKey] < 0)) {
|
||||
if (isset($row[$amountKey]) && $row[$amountKey] !== '' && ($amountKey === 'monthly_salary'
|
||||
? ! preg_match('/^\d+(?:\.\d{1,2})?$/', $row[$amountKey])
|
||||
: (! is_numeric($row[$amountKey]) || (float) $row[$amountKey] < 0))) {
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
foreach (['due_date'] as $dateKey) {
|
||||
if ($row[$dateKey] !== '' && ! preg_match('/^\d{4}-\d{2}-\d{2}$/', $row[$dateKey])) {
|
||||
foreach (['quantity', 'start_month', 'end_month'] as $integerKey) {
|
||||
if (isset($row[$integerKey]) && $row[$integerKey] !== '' && (! preg_match('/^\d+$/', $row[$integerKey]) || (float) $row[$integerKey] > ($integerKey === 'quantity' ? 1000000 : 60) || ($integerKey !== 'quantity' && (int) $row[$integerKey] < 1))) {
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
foreach (['due_date', 'start_date'] as $dateKey) {
|
||||
if (isset($row[$dateKey]) && $row[$dateKey] !== '' && ! preg_match('/^\d{4}-\d{2}-\d{2}$/', $row[$dateKey])) {
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ final class DemographicEvidence
|
||||
/** @return array<string,string> */
|
||||
public static function sectors(): array
|
||||
{
|
||||
return ['commerce' => 'Comércio e serviços', 'industry' => 'Indústria', 'agriculture' => 'Agricultura e agro-indústria', 'education' => 'Educação', 'health' => 'Saúde', 'general' => 'Contexto geral'];
|
||||
return ['commerce' => 'Comércio e serviços', 'tourism' => 'Turismo', 'industry' => 'Indústria', 'agriculture' => 'Agricultura e agro-indústria', 'education' => 'Educação', 'health' => 'Saúde', 'general' => 'Contexto geral'];
|
||||
}
|
||||
|
||||
/** Broader administrative evidence stays labelled as context, never local data.
|
||||
@@ -122,7 +122,7 @@ final class DemographicEvidence
|
||||
foreach (array_slice($result['territories'], $i + 1) as $right) {
|
||||
foreach ($left['series'] as $a) {
|
||||
foreach ($right['series'] as $b) {
|
||||
foreach (array_unique([$start, $end]) as $year) {
|
||||
foreach (range($start, $end) as $year) {
|
||||
$isTotal = fn ($r) => $r['year'] === $year && $r['indicator'] === 'population' && $r['age_group'] === 'all' && $r['residence'] === 'all';
|
||||
$x = array_values(array_filter($a['values'], $isTotal))[0] ?? null;
|
||||
$y = array_values(array_filter($b['values'], $isTotal))[0] ?? null;
|
||||
|
||||
@@ -329,12 +329,14 @@ final class InvestorPath
|
||||
'snapshot_sha256' => $draft->snapshot_sha256, 'financial_snapshot' => $snapshot,
|
||||
'context_opportunity' => $opportunity,
|
||||
'currency' => $economic['currency'] ?? null, 'engine' => 'financial-calculators:v1',
|
||||
'preparation_snapshot' => Arr::only($economic, ['total_investment', 'secured_amount', 'planned_funding', 'requested_funding', 'approved_funding', 'planning_loan', 'annual_revenue', 'annual_operating_costs', 'investment_budget_min', 'investment_budget_max', 'initial_budget_snapshot', 'planning_assumptions_snapshot']),
|
||||
'preparation_snapshot' => Arr::only($economic, ['total_investment', 'secured_amount', 'planned_funding', 'requested_funding', 'approved_funding', 'planning_loan', 'annual_revenue', 'annual_operating_costs', 'investment_budget_min', 'investment_budget_max', 'initial_budget_snapshot', 'planning_assumptions_snapshot', 'business_plan_snapshot', 'project_team_snapshot', 'project_execution_snapshot']),
|
||||
'kind' => 'local_calculation_inputs', 'context_state' => 'current', 'context_revision' => $context['revision'], 'context_dependency_hash' => $context['dependency_hash'] ?? app(InvestorContext::class)->dependencyHash([]), 'recorded_at' => now()->toIso8601String()];
|
||||
$payload['investor_path']['results'][] = $result;
|
||||
abort_unless(count($payload['investor_path']['results']) <= 100, 422, 'Limite de evidências financeiras deste dossier atingido.');
|
||||
$this->savePayload($case, $payload);
|
||||
$this->desk->event($this->desk->case($actor, $id), $actor, 'tool_evidence_returned', array_diff_key($result, ['financial_snapshot' => true]));
|
||||
$eventResult = $result;
|
||||
$eventResult['preparation_snapshot'] = Arr::except($eventResult['preparation_snapshot'], ['business_plan_snapshot', 'project_team_snapshot', 'project_execution_snapshot']);
|
||||
$this->desk->event($this->desk->case($actor, $id), $actor, 'tool_evidence_returned', array_diff_key($eventResult, ['financial_snapshot' => true]));
|
||||
|
||||
return $result;
|
||||
});
|
||||
|
||||
@@ -198,7 +198,7 @@ final class SectorContentAnalysis
|
||||
* @param list<string> $ids
|
||||
* @return list<array<string,mixed>>
|
||||
*/
|
||||
public function forTerritories(array $ids): array
|
||||
public function forTerritories(array $ids, string $sector = 'general'): array
|
||||
{
|
||||
if (! app(LegacyContent::class)->available() || $ids === []) {
|
||||
return [];
|
||||
@@ -213,7 +213,9 @@ final class SectorContentAnalysis
|
||||
}
|
||||
$result = [];
|
||||
foreach (config('legacy_content.articles', []) as $slug => $identity) {
|
||||
if ($identity['group'] !== 'turismo') {
|
||||
// Provincial articles currently cover tourism only. Never substitute
|
||||
// those ideas for another economic intention or infer missing offers.
|
||||
if ($sector !== 'tourism' || $identity['group'] !== 'turismo') {
|
||||
continue;
|
||||
}
|
||||
preg_match('/post-(\d+)-/', $identity['external_id'], $match);
|
||||
|
||||
Reference in New Issue
Block a user