Files
Investidor-V2/resources/js/components/fiscal-l3-preparation.tsx
T

90 lines
3.8 KiB
TypeScript

import {
l3FormPreparations,
l3FormPreparationHtml,
l3FormalitiesDependencies,
l3PreparationStatus,
} from '@/lib/l3-form-preparation';
export function FiscalL3Preparation({
draft,
}: {
draft: Record<string, unknown>;
}) {
try {
const forms = l3FormPreparations(draft);
if (!forms.length) return null;
return (
<details className="rounded border p-3">
<summary>Preparação dos quadros L3 e formalidades</summary>
<p>
Reutiliza entradas e resultados congelados. Os campos com
correspondência identificada ficam preparados para
conferência e exportação. As formalidades específicas por
identificar conservam o seu âmbito.
</p>
{forms.map((p) => (
<article key={p.id} className="border-t py-2">
<h4>
{p.branch} — {p.period} — {p.entity}
</h4>
<p>
{p.current
? 'Resultado correspondente às entradas'
: 'Resultado histórico;rever entradas/origem'}
;{l3PreparationStatus(p.status)}
</p>
<table>
<thead>
<tr>
<th>Campo</th>
<th>Finalidade</th>
<th>MZN</th>
</tr>
</thead>
<tbody>
{p.fields.map((f, i) => (
<tr key={i}>
<td>{f.field}</td>
<td>{f.label}</td>
<td>{f.value}</td>
</tr>
))}
</tbody>
</table>
<p>{p.reference}</p>
<button
type="button"
onClick={() => {
const url = URL.createObjectURL(
new Blob([l3FormPreparationHtml(p)], {
type: 'text/html;charset=utf-8',
}),
),
link = document.createElement('a');
link.href = url;
link.download = `preparacao-L3-${p.branch.replace('/', '-')}-${p.period || 'periodo'}.html`;
link.click();
setTimeout(
() => URL.revokeObjectURL(url),
1000,
);
}}
>
Exportar preparação {p.branch} para conferência
</button>
</article>
))}
{l3FormalitiesDependencies
.filter((dep) => forms.some((p) => p.branch === dep.branch))
.map((dep) => (
<p key={dep.branch}>
<strong>{dep.branch}:</strong> {dep.missing} Retomar
com: {dep.trigger}
</p>
))}
</details>
);
} catch (error) {
return <p role="alert">{String(error)}</p>;
}
}