feat(qa): consolidate eleven financial report tables pending private visual acceptance
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { InvestmentReportTables } from './investment-report-tables';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { DossierReportPreview } from './dossier-report-preview';
|
||||
import {
|
||||
createInvestorDossierReport,
|
||||
createInvestorStageReport,
|
||||
investorDossierReportIndex,
|
||||
investorFinancialReportChoices,
|
||||
type InvestorDossierReportInput,
|
||||
} from '@/lib/investor-dossier-report';
|
||||
import {
|
||||
@@ -32,6 +33,7 @@ function InvestorDossierReportsContent({
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [stage, setStage] = useState('');
|
||||
const [financialResultId, setFinancialResultId] = useState('');
|
||||
const [download, setDownload] = useState<{
|
||||
url: string;
|
||||
name: string;
|
||||
@@ -45,13 +47,44 @@ function InvestorDossierReportsContent({
|
||||
const requiresChoice =
|
||||
dossier.opportunity_options.length > 1 && !dossier.context_opportunity;
|
||||
const entries = requiresChoice ? [] : investorDossierReportIndex(dossier);
|
||||
const financialChoices = requiresChoice
|
||||
? []
|
||||
: investorFinancialReportChoices(dossier);
|
||||
const financialChoiceRequired =
|
||||
(!stage || stage === 'S03') &&
|
||||
financialChoices.length > 1 &&
|
||||
!financialResultId;
|
||||
const report = useMemo(
|
||||
() =>
|
||||
requiresChoice || financialChoiceRequired
|
||||
? null
|
||||
: stage
|
||||
? createInvestorStageReport(
|
||||
dossier,
|
||||
stage,
|
||||
undefined,
|
||||
financialResultId || undefined,
|
||||
)
|
||||
: createInvestorDossierReport(dossier, undefined, {
|
||||
financialResultId: financialResultId || undefined,
|
||||
}),
|
||||
[
|
||||
dossier,
|
||||
stage,
|
||||
financialResultId,
|
||||
requiresChoice,
|
||||
financialChoiceRequired,
|
||||
],
|
||||
);
|
||||
async function exportReport(format: 'word' | 'html') {
|
||||
setBusy(true);
|
||||
setError('');
|
||||
try {
|
||||
const model = stage
|
||||
? createInvestorStageReport(dossier, stage)
|
||||
: createInvestorDossierReport(dossier);
|
||||
if (!report)
|
||||
throw Error(
|
||||
'Escolha o contexto e a versão financeira antes de exportar.',
|
||||
);
|
||||
const model = report;
|
||||
const blob =
|
||||
format === 'word'
|
||||
? await generateProjectDossierDocx(model, [], true)
|
||||
@@ -116,13 +149,69 @@ function InvestorDossierReportsContent({
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
{stage && (
|
||||
<StageReportPreview dossier={dossier} stage={stage} />
|
||||
{(!stage || stage === 'S03') &&
|
||||
financialChoices.length > 0 && (
|
||||
<label className="grid min-w-0 gap-1">
|
||||
Plano financeiro a incluir
|
||||
<select
|
||||
className="w-full min-w-0 rounded border p-2"
|
||||
value={financialResultId}
|
||||
disabled={busy}
|
||||
onChange={(e) => {
|
||||
setFinancialResultId(e.target.value);
|
||||
setDownload(null);
|
||||
}}
|
||||
>
|
||||
<option value="">
|
||||
{financialChoices.length === 1
|
||||
? 'Única versão preservada neste contexto'
|
||||
: 'Escolha uma versão — os valores não serão misturados'}
|
||||
</option>
|
||||
{financialChoices.map((r) => (
|
||||
<option key={r.id} value={r.id}>
|
||||
Rascunho v{r.draft_version} ·{' '}
|
||||
{r.recorded_at} · contexto v
|
||||
{r.context_revision ??
|
||||
'por identificar'}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
{financialChoiceRequired && (
|
||||
<p role="status">
|
||||
Escolha a versão financeira a incluir. As restantes
|
||||
versões permanecem no histórico.
|
||||
</p>
|
||||
)}
|
||||
{!financialChoices.length &&
|
||||
dossier.results.some(
|
||||
(r) =>
|
||||
(r.context_opportunity ?? null) ===
|
||||
dossier.context_opportunity,
|
||||
) && (
|
||||
<p className="text-sm">
|
||||
As versões antigas não contêm todos os dados do
|
||||
relatório integral. Os originais permanecem
|
||||
disponíveis; use uma versão completa guardada
|
||||
para reunir as onze tabelas.
|
||||
</p>
|
||||
)}
|
||||
{report && (
|
||||
<details
|
||||
className="rounded border p-3"
|
||||
open={Boolean(stage)}
|
||||
>
|
||||
<summary>
|
||||
Conferir o relatório antes de exportar
|
||||
</summary>
|
||||
<DossierReportPreview report={report} />
|
||||
</details>
|
||||
)}
|
||||
<div className="flex flex-wrap gap-3">
|
||||
<button
|
||||
className="rounded border px-3 py-2"
|
||||
disabled={busy}
|
||||
disabled={busy || financialChoiceRequired}
|
||||
onClick={() => exportReport('word')}
|
||||
>
|
||||
Preparar{' '}
|
||||
@@ -133,7 +222,7 @@ function InvestorDossierReportsContent({
|
||||
</button>
|
||||
<button
|
||||
className="rounded border px-3 py-2"
|
||||
disabled={busy}
|
||||
disabled={busy || financialChoiceRequired}
|
||||
onClick={() => exportReport('html')}
|
||||
>
|
||||
Preparar versão para impressão/PDF
|
||||
@@ -227,49 +316,3 @@ function InvestorDossierReportsContent({
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function StageReportPreview({
|
||||
dossier,
|
||||
stage,
|
||||
}: {
|
||||
dossier: InvestorDossierReportInput;
|
||||
stage: string;
|
||||
}) {
|
||||
const report = createInvestorStageReport(dossier, stage);
|
||||
return (
|
||||
<article
|
||||
className="space-y-3 rounded border p-3"
|
||||
aria-label={`Relatório da etapa ${stage}`}
|
||||
>
|
||||
<h3 className="font-semibold">{report.title}</h3>
|
||||
<p className="text-sm">{report.version}</p>
|
||||
{report.sections.map((section) => (
|
||||
<section key={section.id} className="space-y-2">
|
||||
<h4 className="font-medium">{section.title}</h4>
|
||||
{section.paragraphs.map((text) => (
|
||||
<p key={text}>{text}</p>
|
||||
))}
|
||||
<dl className="space-y-2">
|
||||
{section.rows.map((row, index) => (
|
||||
<div key={index} className="break-words">
|
||||
<dt className="font-medium">{row.field}</dt>
|
||||
<dd>{row.value}</dd>
|
||||
<dd className="text-sm">
|
||||
{row.classification} · {row.origin}
|
||||
</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
{section.tables && (
|
||||
<InvestmentReportTables tables={section.tables} />
|
||||
)}
|
||||
</section>
|
||||
))}
|
||||
{report.limitations.map((text) => (
|
||||
<p className="text-sm" key={text}>
|
||||
{text}
|
||||
</p>
|
||||
))}
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user