Files
Investidor-V2/resources/js/pages/land-assistance/print.tsx
T

272 lines
12 KiB
TypeScript

import { InvestmentConsumerIdentity } from '@/components/investment-consumer-identity';
import { displayValue } from '@/lib/display-value';
import type { ReactNode } from 'react';
type Props = {
case: {
reference: string;
version: number;
payload: Record<string, any>;
updated_at: string;
};
disclaimer: string;
modelVersion: string;
country: { code: string | null; name: string };
declaredOrigin: { code: string | null; name: string };
};
export default function PrintCase({
case: record,
disclaimer,
modelVersion,
country,
declaredOrigin,
}: Props) {
const p = record.payload ?? {};
const text = (value: unknown): string =>
value === null || value === undefined || value === ''
? 'Não informado'
: Array.isArray(value)
? value.map(text).join(', ')
: typeof value === 'object'
? Object.values(value as Record<string, unknown>)
.map(text)
.filter((x) => x !== 'Não informado')
.join(' · ')
: displayValue(value);
return (
<main
data-land-print
className="mx-auto max-w-4xl space-y-5 p-8 print:max-w-none print:p-0"
>
<div className="flex justify-end print:hidden">
<button
className="rounded border px-4 py-2"
onClick={() => window.print()}
>
Imprimir / guardar como PDF
</button>
</div>
<InvestmentConsumerIdentity raw={p.context_opportunity_snapshot} />
<header className="space-y-2 border-b pb-4">
<p>InvesteMoz · modelo de preparação · {modelVersion}</p>
<h1 className="text-2xl font-bold">
Terra e DUAT — dados preenchidos pelo requerente
</h1>
<p>
Referência interna: {record.reference} · versão{' '}
{record.version} · actualizada em{' '}
{new Date(record.updated_at).toLocaleString('pt-MZ')}
</p>
<p className="font-semibold">{disclaimer}</p>
<p>
Esta cópia reflecte os dados guardados no InvesteMoz e não é
requerimento oficialmente recebido, título, parecer, prova
de consulta ou decisão.
</p>
</header>
<Section title="A. Pedido e requerente">
{[
['Tipo de apoio', p.support_kind],
['Descrição', p.request_description],
['Projecto/oportunidade', p.project_reference],
['Categoria', p.applicant_category],
['Nome/denominação', p.full_name],
[
'País do requerente',
country.code
? `${country.name} (${country.code})`
: p.country
? `${p.country} (valor anteriormente registado)`
: country.name,
],
[
'Origem declarada desta solicitação',
declaredOrigin.code
? `${declaredOrigin.name} (${declaredOrigin.code})`
: declaredOrigin.name,
],
['Contacto', p.contact_person],
['Email', p.email],
['Telefone', p.phone],
['Canal preferido', p.preferred_contact],
[
'Representante/função',
`${text(p.representative_name)} / ${text(p.representative_role)}`,
],
['NUIT (se informado)', p.nuit],
].map(([label, value]) => (
<Field
key={String(label)}
label={String(label)}
value={text(value)}
/>
))}
</Section>
<Section title="B. Localização e situação declaradas">
{[
['Situação da localização', p.area_status],
['Uso pretendido', p.purpose],
['Actividade', p.activity],
[
'Ocupantes/utilizações',
`${text(p.known_occupants)} — ${text(p.occupant_description)}`,
],
[
'Benfeitorias/usos',
`${text(p.known_improvements)} — ${text(p.improvements_description)}`,
],
[
'Antecedentes',
`${text(p.prior_right_status)} — ${text(p.prior_right_description)}`,
],
[
'Conflito comunicado',
`${text(p.conflict_status)} — ${text(p.conflict_description)}`,
],
].map(([label, value]) => (
<Field
key={String(label)}
label={String(label)}
value={text(value)}
/>
))}
</Section>
<Section title="Parcelas (declarações do requerente)">
{(p.parcels ?? []).map((parcel: any, index: number) => (
<article key={index} className="space-y-1 border-b pb-3">
<h3 className="font-semibold">Parcela {index + 1}</h3>
<p>{text(parcel.place_description)}</p>
<p>
Área: {text(parcel.area)} {text(parcel.area_unit)} ·
Referência: {text(parcel.cadastral_reference)}
</p>
<p>
Coordenadas/planta: {text(parcel.coordinates)} ·
Precisão indicada:{' '}
{text(parcel.geometry_confidence)}
</p>
<p className="text-sm">
A selecção no catálogo não verifica titularidade,
limites ou disponibilidade.
</p>
</article>
))}
</Section>
<Section title="C. Processo externo indicado pelo requerente">
{[
['Número', p.official_process?.official_reference],
['Entidade', p.official_process?.receiving_entity],
['Data indicada', p.official_process?.presented_at],
['Estado comunicado', p.official_process?.reported_status],
[
'Pendências comunicadas',
p.official_process?.pending_items,
],
].map(([label, value]) => (
<Field
key={String(label)}
label={String(label)}
value={text(value)}
/>
))}
</Section>
<Section title="D. Plano de exploração facultativo">
{(p.exploration_plan?.activity_rows ?? []).length === 0 ? (
<p>Sem linhas fornecidas.</p>
) : (
(p.exploration_plan.activity_rows ?? []).map(
(row: any, index: number) => (
<article key={index} className="border-b pb-2">
<p>
<strong>{text(row.activity)}</strong> ·
período {text(row.period)} ·{' '}
{text(row.stage)}
</p>
<p>
Área {text(row.area)} {text(row.area_unit)}{' '}
· metas: {text(row.targets)} · estruturas:{' '}
{text(row.structures)} · investimento
declarado: {text(row.investment)}
</p>
</article>
),
)
)}
<Field label="Notas" value={text(p.exploration_plan?.notes)} />
</Section>
<Section title="E. Consulta — preparação/informação indicada">
{[
['Estado', p.consultation?.status],
[
'Comunidade/local/data',
[
p.consultation?.community,
p.consultation?.location,
p.consultation?.date,
]
.map(text)
.join(' / '),
],
['Língua/tradução', p.consultation?.language],
[
'Participantes',
(p.consultation?.participants ?? [])
.map(
(x: any) => `${x.name ?? ''} (${x.role ?? ''})`,
)
.join('; '),
],
['Intervenções', p.consultation?.interventions],
['Divergências/oposição', p.consultation?.opposition],
['Acordos comunicados', p.consultation?.agreements],
[
'Acta/pareceres referidos',
[
p.consultation?.minutes_reference,
p.consultation?.opinions_received,
]
.map(text)
.join(' / '),
],
].map(([label, value]) => (
<Field
key={String(label)}
label={String(label)}
value={text(value)}
/>
))}
</Section>
<Section title="F. Informação complementar">
<p>{text(p.additional_information)}</p>
</Section>
<footer className="space-y-2 border-t pt-4">
<p>
Gerado a partir dos dados guardados; sem assinatura
electrónica ou validação de terceiros.
</p>
<p className="font-semibold">{disclaimer}</p>
</footer>
<style>
{
'@media print { main[data-land-print] { font-size: 11pt; line-height: 1.4; } main[data-land-print] button { display: none } main[data-land-print] section { break-inside: auto; box-shadow: none; } main[data-land-print] section > div, main[data-land-print] footer { break-inside: avoid; } main[data-land-print] h2, main[data-land-print] h3 { break-after: avoid; } }'
}
</style>
</main>
);
}
function Section({ title, children }: { title: string; children: ReactNode }) {
return (
<section className="space-y-3 rounded border p-4">
<h2 className="text-lg font-bold">{title}</h2>
{children}
</section>
);
}
function Field({ label, value }: { label: string; value: string }) {
return (
<div className="grid gap-2 border-b pb-2 sm:grid-cols-[220px_1fr]">
<strong>{label}</strong>
<span className="whitespace-pre-wrap">{value}</span>
</div>
);
}