Integrate supplied institutions by location category and type through investor dossiers

This commit is contained in:
2026-11-10 20:59:24 +02:00
parent 5ff9402fd0
commit 5a5cc9e815
26 changed files with 33731 additions and 80 deletions
@@ -0,0 +1,195 @@
import { card, input } from '@/pages/investment/shared';
export const financialCategories: Record<string, string> = {
banking: 'Banca',
credit: 'Crédito e microfinanças',
investment: 'Gestão de investimento',
pensions: 'Fundos de pensões',
insurance: 'Seguros e resseguros',
intermediation: 'Mediação de seguros',
exchange: 'Câmbio',
payments: 'Pagamentos e serviços interbancários',
supervision: 'Supervisão',
other: 'Outras instituições',
};
export const financialTypes: Record<string, string> = {
commercial_bank: 'Banco comercial',
investment_bank: 'Banco de investimento',
bank: 'Banco (tipo não especificado)',
microbank: 'Microbanco',
cooperative: 'Cooperativa de crédito',
savings: 'Organização de poupança e empréstimo',
investment_manager: 'Gestora de fundos de investimento',
investment_company: 'Sociedade de investimento',
pension_manager: 'Gestora de fundos de pensões',
insurer: 'Seguradora',
reinsurer: 'Resseguradora',
microinsurer: 'Micro-seguradora',
broker: 'Corretora de seguros',
agent: 'Agente de seguros',
reinsurance_broker: 'Corretor de resseguro',
exchange_house: 'Casa de câmbio',
electronic_money: 'Instituição de moeda electrónica',
interbank: 'Serviços interbancários',
supervisor: 'Supervisor',
other: 'Outro tipo documentado',
};
export type Classification = {
institution_categories?: string[];
institution_types?: string[];
institution_services?: string[];
institution_status?: string;
successor_key?: string | null;
register_reference?: string | null;
source_document_name?: string | null;
source_document_sha256?: string | null;
aliases?: string[];
source_rows?: { id: string; section: string; text: string }[];
};
export const evidenceLabels: Record<string, string> = {
reported: 'Reportado no documento',
to_confirm: 'A confirmar',
historical: 'Referência histórica',
conflict: 'Informação divergente/identidade por confirmar',
unlocated: 'Localização por confirmar',
};
export function ClassificationSummary({ value }: { value: Classification }) {
return (
<section className={card}>
<h2>Categoria e tipo da instituição</h2>
<p>
Categorias:{' '}
{(value.institution_categories ?? [])
.map((k) => financialCategories[k] ?? k)
.join(' · ') || 'Por classificar'}
</p>
<p>
Tipos:{' '}
{(value.institution_types ?? [])
.map((k) => financialTypes[k] ?? k)
.join(' · ') || 'Por classificar'}
</p>
<p>
Situação segundo a fonte:{' '}
{value.institution_status === 'merged'
? 'Fundida/extinta segundo o documento; não apresentar como instituição activa'
: value.institution_status === 'historical'
? 'Registo histórico'
: value.institution_status === 'unknown'
? 'Situação actual por confirmar'
: 'Reportada no documento; não é confirmação independente de licença actual'}
{value.successor_key
? ` · Sucessora indicada: ${value.successor_key}`
: ''}
</p>
{value.register_reference && (
<p>
Referência de registo no documento:{' '}
{value.register_reference}
</p>
)}
<details>
<summary>
Rastrear o conteúdo até ao documento e à linha de origem
</summary>
<p>
{value.source_document_name} · SHA-256{' '}
{value.source_document_sha256}
</p>
{(value.source_rows ?? []).map((row) => (
<article key={row.id}>
<h3>{row.section}</h3>
<p>{row.id}</p>
<p>{row.text}</p>
</article>
))}
</details>
<p>
Categoria e presença física não confirmam cobertura de crédito,
oferta de seguro específica, garantia ou aceitação do processo.
</p>
</section>
);
}
export function ClassificationFields({
value,
change,
needs,
}: {
value: Classification;
change: (patch: Partial<Classification>) => void;
needs: Record<string, string>;
}) {
const multiple = (
key:
| 'institution_categories'
| 'institution_types'
| 'institution_services',
label: string,
options: Record<string, string>,
) => (
<label className="my-3 block">
{label}
<select
multiple
className={input}
value={value[key] ?? []}
onChange={(e) =>
change({
[key]: Array.from(
e.target.selectedOptions,
(o) => o.value,
),
})
}
>
{Object.entries(options).map(([id, title]) => (
<option key={id} value={id}>
{title}
</option>
))}
</select>
</label>
);
return (
<details className={card}>
<summary>Categoria, tipo e serviço — Alterar</summary>
{multiple(
'institution_categories',
'Categorias documentadas',
financialCategories,
)}
{multiple(
'institution_types',
'Tipos documentados',
financialTypes,
)}
{multiple(
'institution_services',
'Serviços identificados (não é oferta garantida)',
needs,
)}
<label>
Situação
<select
className={input}
value={value.institution_status ?? 'unknown'}
onChange={(e) =>
change({ institution_status: e.target.value })
}
>
<option value="unknown">Por confirmar</option>
<option value="reported">Reportada no documento</option>
<option value="historical">Histórica</option>
<option value="merged">
Fundida/extinta segundo a fonte
</option>
</select>
</label>
<p>
As linhas originais e as classificações anteriores conservam-se
nas versões. Não complete lacunas por inferência.
</p>
</details>
);
}
@@ -27,6 +27,7 @@ export function FundingDossierChoice({
}) {
const [need, setNeed] = useState(selection.need ?? '');
const [product, setProduct] = useState('');
const [location, setLocation] = useState('');
const [consent, setConsent] = useState(false);
const [busy, setBusy] = useState(false);
const [error, setError] = useState('');
@@ -42,6 +43,8 @@ export function FundingDossierChoice({
version: dossier.version,
version_id: record.version_id,
product: product || null,
location_id: location || null,
location_mode: selection.location_mode ?? 'coverage',
need,
territory: selection.territory,
consent,
@@ -164,12 +167,46 @@ export function FundingDossierChoice({
</select>
</label>
)}
{record.payload.kind === 'institution' && (
<label>
Sede/balcão a conservar na preparação
<select
className={input}
value={location}
onChange={(e) =>
setLocation(e.target.value)
}
>
<option value="">
Sem local específico seleccionado / por
confirmar
</option>
{(record.payload.locations ?? [])
.filter((l) => l.id)
.map((l) => (
<option key={l.id} value={l.id}>
{l.label} ·{' '}
{l.location_text ||
l.territory_path
?.map((n) => n.name)
.join(' / ') ||
'Local por confirmar'}{' '}
·{' '}
{l.evidence_status ===
'to_confirm'
? 'A confirmar'
: ''}
</option>
))}
</select>
</label>
)}
<p>
Local seleccionado:{' '}
{selection.territory
? selection.territory_label ||
'Conservado da pesquisa; consulte a cobertura do produto.'
: 'Volte à pesquisa e escolha a localização antes de guardar.'}
: 'Local de interesse por identificar; a referência fica guardada com essa lacuna explícita.'}
</p>
<label>
<input
@@ -187,8 +224,7 @@ export function FundingDossierChoice({
disabled={
busy ||
dossier.closed ||
(!pending.current &&
(!consent || !need || !selection.territory))
(!pending.current && (!consent || !need))
}
onClick={() => void save()}
>
+114 -31
View File
@@ -1,12 +1,26 @@
import {
ClassificationFields,
ClassificationSummary,
evidenceLabels,
type Classification,
} from '@/components/funding-classification';
import { card, input, button } from '@/pages/investment/shared';
export type FundingSource = {
source_url: string;
source_url: string | null;
source_document_name?: string | null;
source_document_sha256?: string | null;
evidence_status?: string | null;
origin?: string;
source_refs?: string[];
source_reference: string;
checked_on: string;
};
export type FundingContact = FundingSource & { kind: string; value: string };
export type FundingLocation = FundingSource & {
id?: string;
location_text?: string;
hours?: string;
role: string;
label: string;
address: string;
@@ -27,7 +41,7 @@ export type FundingProduct = FundingSource & {
availability: string;
contact_url: string;
};
export type InstitutionDetails = {
export type InstitutionDetails = Classification & {
institution_key: string;
institution_nature: string;
contacts: FundingContact[];
@@ -83,9 +97,45 @@ function Sources({
<Text
label="Endereço da fonte"
type="url"
value={value.source_url}
value={value.source_url ?? ''}
change={(source_url) => change({ source_url })}
/>
{!value.source_url && (
<>
<Text
label="Documento de origem"
value={value.source_document_name ?? ''}
change={(source_document_name) =>
change({ source_document_name })
}
/>
<Text
label="SHA-256 do original"
value={value.source_document_sha256 ?? ''}
change={(source_document_sha256) =>
change({ source_document_sha256 })
}
/>
</>
)}
{value.source_document_sha256 && (
<label>
Situação desta informação
<select
className={input}
value={value.evidence_status ?? 'to_confirm'}
onChange={(e) =>
change({ evidence_status: e.target.value })
}
>
{Object.entries(evidenceLabels).map(([key, label]) => (
<option key={key} value={key}>
{label}
</option>
))}
</select>
</label>
)}
<Text
label="Referência/edição"
value={value.source_reference}
@@ -130,6 +180,7 @@ export function InstitutionFields({
A sede ou balcão não determina a cobertura do financiamento. Não
preencha condições desconhecidas por inferência.
</p>
<ClassificationFields value={value} change={change} needs={needs} />
<Text
label="Identidade estável da instituição (referência do cadastro/fonte)"
value={value.institution_key}
@@ -502,40 +553,63 @@ export function InstitutionFields({
}
function Source({ value }: { value: FundingSource }) {
return (
<p>
<a
className="underline"
href={value.source_url}
target="_blank"
rel="noopener noreferrer"
>
{value.source_reference}
</a>{' '}
· consulta {value.checked_on}
</p>
<div>
<p>
{value.source_url ? (
<a
className="underline"
href={value.source_url}
target="_blank"
rel="noopener noreferrer"
>
{value.source_reference}
</a>
) : (
value.source_reference
)}{' '}
· consulta {value.checked_on}
</p>
{value.source_document_name && (
<p>
Documento: {value.source_document_name} · SHA-256{' '}
{value.source_document_sha256}
</p>
)}
{value.evidence_status && (
<p>
{evidenceLabels[value.evidence_status] ??
value.evidence_status}{' '}
· {value.origin}
</p>
)}
</div>
);
}
export function InstitutionView({ value }: { value: InstitutionDetails }) {
return (
<section className={card}>
<h2>Instituição financeira</h2>
<p>
Natureza:{' '}
{
(
{
bank: 'Banco',
credit: 'Instituição de crédito',
microfinance: 'Microfinanças',
investment_fund: 'Fundo de investimento',
development:
'Agência de desenvolvimento/financiamento',
other: 'Outra natureza documentada',
unknown: 'Por confirmar',
} as Record<string, string>
)[value.institution_nature]
}
</p>
<ClassificationSummary value={value} />
{!value.institution_types?.length && (
<p>
Natureza:{' '}
{
(
{
bank: 'Banco',
credit: 'Instituição de crédito',
microfinance: 'Microfinanças',
investment_fund: 'Fundo de investimento',
development:
'Agência de desenvolvimento/financiamento',
other: 'Outra natureza documentada',
unknown: 'Por confirmar',
} as Record<string, string>
)[value.institution_nature]
}
</p>
)}
<h3>Contactos</h3>
{value.contacts.length === 0 && <p>Contactos por confirmar.</p>}
{value.contacts.map((c, i) => (
@@ -575,6 +649,15 @@ export function InstitutionView({ value }: { value: InstitutionDetails }) {
{l.territory_path?.map((n) => n.name).join(' / ') ||
'Correspondência ao cadastro territorial por confirmar'}
</p>
{l.location_text && (
<p>Local indicado: {l.location_text}</p>
)}
{l.hours && (
<p>
Horário indicado na fonte (pode ter mudado):{' '}
{l.hours}
</p>
)}
<Source value={l} />
</article>
))}