Reconciliar fontes instaladas 423bd512d8c5 com main

This commit is contained in:
2026-10-20 14:45:19 +02:00
parent 507387502c
commit 9ab721c97f
108 changed files with 2766 additions and 494 deletions
+18
View File
@@ -6,6 +6,21 @@ function csrfToken(): string {
?.slice('XSRF-TOKEN='.length) ?? '',
);
}
export type ContextDocument = {
resource_id: number;
document_id: string;
metadata_version: number;
document_version: number;
edition: string | null;
sha256: string;
source_reference: string;
title: string;
support_id: string;
support_version: number;
section: string | null;
opportunity_id: number;
download_url: string;
};
export type ContextReference = {
key: string;
kind: string;
@@ -15,6 +30,9 @@ export type ContextReference = {
version: number | string | null;
sha256: string;
fields: Record<string, string>;
documents?: ContextDocument[];
visibility?: 'private' | 'public';
state?: string | null;
};
export type DossierContext = {
revision: number;
@@ -0,0 +1,5 @@
export function participationIdentity(): {name:string;email:string} {
try { const value = JSON.parse(sessionStorage.getItem('investemoz-participation-identity') ?? 'null');
return {name: typeof value?.name === 'string' ? value.name : '', email: typeof value?.email === 'string' ? value.email : ''};
} catch { return {name:'',email:''}; }
}
+4
View File
@@ -113,6 +113,10 @@ export async function portalRequest<T>(
): Promise<T> {
const headers = new Headers(options.headers);
headers.set('Accept', 'application/json');
if (options.method && !['GET', 'HEAD'].includes(options.method.toUpperCase())) {
const token = document.cookie.split('; ').find(value => value.startsWith('XSRF-TOKEN='))?.slice(11);
if (token) headers.set('X-XSRF-TOKEN', decodeURIComponent(token));
}
const response = await fetch(url, {
...options,
credentials: 'same-origin',
+1 -1
View File
@@ -440,11 +440,11 @@ export function currentNavigationItem(
export function portalNavigation(access: PortalNavAccess): PortalNavItem[] {
const previous = legacyPortalNavigation(access);
return uniqueNavigationDestinations([
link('home', 'Início', '/'),
{
id: 'discovery',
label: 'Descoberta',
children: [
link('home', 'Início', '/'),
link(
'why',
'Porquê investir em Moçambique',
+14 -13
View File
@@ -367,7 +367,7 @@ export async function generateProjectDossierDocx(
annexesIncluded: boolean,
): Promise<Blob> {
const children: (Paragraph | Table)[] = [
new Paragraph({ text: 'InvestMoz', heading: HeadingLevel.HEADING_2 }),
new Paragraph({ text: 'InvesteMoz', heading: HeadingLevel.HEADING_2 }),
new Paragraph({
text: 'Relatório consolidado do projecto',
heading: HeadingLevel.TITLE,
@@ -447,7 +447,8 @@ export async function generateProjectDossierDocx(
alignment: AlignmentType.RIGHT,
children: [
new TextRun({
text: 'InvestMoz · relatório privado · página ',
text: 'InvesteMoz · '+model.title.slice(0, 60)+' · privado · página ',
size: 18,
}),
new SimpleField('PAGE'),
],
@@ -455,14 +456,14 @@ export async function generateProjectDossierDocx(
],
});
const doc = new Document({
creator: 'InvestMoz',
creator: 'InvesteMoz',
title: `Relatório do projecto — ${model.title}`,
description:
'Dossier consolidado exportado localmente a partir do formulário InvestMoz.',
'Dossier consolidado exportado localmente a partir do formulário InvesteMoz.',
styles: {
default: {
document: {
run: { font: 'Aptos', size: 20, color: '17211F' },
run: { font: 'Arial', size: 20, color: '17211F' },
paragraph: { spacing: { after: 120, line: 276 } },
},
},
@@ -472,7 +473,7 @@ export async function generateProjectDossierDocx(
name: 'Title',
basedOn: 'Normal',
run: {
font: 'Aptos Display',
font: 'Arial',
size: 34,
bold: true,
color: '123B35',
@@ -485,7 +486,7 @@ export async function generateProjectDossierDocx(
basedOn: 'Normal',
next: 'Normal',
run: {
font: 'Aptos Display',
font: 'Arial',
size: 26,
bold: true,
color: '123B35',
@@ -501,7 +502,7 @@ export async function generateProjectDossierDocx(
basedOn: 'Normal',
next: 'Normal',
run: {
font: 'Aptos',
font: 'Arial',
size: 24,
bold: true,
color: '27675C',
@@ -517,7 +518,7 @@ export async function generateProjectDossierDocx(
basedOn: 'Normal',
next: 'Normal',
run: {
font: 'Aptos',
font: 'Arial',
size: 22,
bold: true,
color: '27675C',
@@ -533,7 +534,7 @@ export async function generateProjectDossierDocx(
{
properties: {
page: {
size: { width: 12240, height: 15840 },
size: { width: 11906, height: 16838 },
margin: {
top: 900,
right: 960,
@@ -569,7 +570,7 @@ async function fileDataUrl(file: File): Promise<string> {
}
function htmlTable(headers: string[], rows: string[][]): string {
return `<table><thead><tr>${headers.map((value) => `<th>${escapeHtml(value)}</th>`).join('')}</tr></thead><tbody>${rows.map((row) => `<tr>${headers.map((_, index) => `<td>${escapeHtml(row[index] ?? '')}</td>`).join('')}</tr>`).join('')}</tbody></table>`;
return `<table class="${headers[0] === 'Campo' && headers[2] === 'Classificação / origem' ? 'report-table' : 'annex-table'}"><thead><tr>${headers.map((value) => `<th>${escapeHtml(value)}</th>`).join('')}</tr></thead><tbody>${rows.map((row) => `<tr>${headers.map((_, index) => `<td>${escapeHtml(row[index] ?? '')}</td>`).join('')}</tr>`).join('')}</tbody></table>`;
}
export async function createProjectDossierPrintHtml(
@@ -640,8 +641,8 @@ export async function createProjectDossierPrintHtml(
content.push('</section>');
}
return `<!doctype html><html lang="pt-MZ"><head><meta charset="utf-8"><title>Relatório — ${escapeHtml(model.title)}</title><style>
@page{size:A4;margin:18mm 17mm 20mm}*{box-sizing:border-box}body{font:10.5pt/1.45 Arial,sans-serif;color:#17211f;margin:0}h1{font-size:24pt;color:#123b35;margin:0 0 7mm}h2{font-size:16pt;color:#123b35;border-bottom:1px solid #b8c9c3;padding-bottom:2mm;margin:8mm 0 3mm;break-after:avoid}h3{font-size:12pt;color:#27675c;break-after:avoid}p{white-space:pre-wrap}table{width:100%;border-collapse:collapse;table-layout:fixed;margin:3mm 0 5mm;break-inside:auto}th,td{border:1px solid #cbd5d1;padding:5px 6px;text-align:left;vertical-align:top;overflow-wrap:anywhere}th{background:#123b35;color:white}tr{break-inside:avoid}th:first-child,td:first-child{width:22%}th:last-child,td:last-child{width:32%;font-size:9pt;color:#40524d}.private{padding:3mm;background:#fff4df;border-left:3px solid #b66a0c;font-weight:bold}section{break-inside:auto}figure{margin:5mm auto;text-align:center;break-inside:avoid}img{max-width:100%;max-height:210mm;object-fit:contain}figcaption{font-style:italic;color:#52615d}pre{white-space:pre-wrap;overflow-wrap:anywhere;font:9.5pt/1.4 Arial,sans-serif}@media print{a{color:inherit;text-decoration:none}.no-print{display:none}}
</style></head><body><h1>InvestMoz<br>Relatório consolidado do projecto</h1><p><strong>${escapeHtml(model.title)}</strong><br>Gerado em ${escapeHtml(new Date(model.generatedAt).toLocaleString('pt-MZ'))}<br>Versão/revisão: ${escapeHtml(model.version)}</p><p class="private">Documento privado. O portal não publica nem partilha este conteúdo.</p>${content.join('')}<footer><small>InvestMoz · Relatório privado · ${escapeHtml(model.version)}</small></footer><script>window.addEventListener('load',()=>setTimeout(()=>window.print(),350));</script></body></html>`;
@page{size:A4;margin:18mm 17mm 20mm}*{box-sizing:border-box}body{font:10.5pt/1.45 Arial,sans-serif;color:#17211f;margin:0}h1{font-size:24pt;color:#123b35;margin:0 0 7mm}h2{font-size:16pt;color:#123b35;border-bottom:1px solid #b8c9c3;padding-bottom:2mm;margin:8mm 0 3mm;break-after:avoid}h3{font-size:12pt;color:#27675c;break-after:avoid}p{white-space:pre-wrap}table{width:100%;border-collapse:collapse;table-layout:fixed;margin:3mm 0 5mm;break-inside:auto}th,td{border:1px solid #cbd5d1;padding:5px 6px;text-align:left;vertical-align:top;overflow-wrap:anywhere}th{background:#123b35;color:white}tr{break-inside:avoid}.report-table th:first-child,.report-table td:first-child{width:22%}.report-table th:last-child,.report-table td:last-child{width:32%}.report-table td:last-child{font-size:9pt;color:#40524d}.annex-table{table-layout:fixed;font-size:9pt}thead{display:table-header-group}.private{padding:3mm;background:#fff4df;border-left:3px solid #b66a0c;font-weight:bold}section{break-inside:auto}figure{margin:5mm auto;text-align:center;break-inside:avoid}img{max-width:100%;max-height:210mm;object-fit:contain}figcaption{font-style:italic;color:#52615d}pre{white-space:pre-wrap;overflow-wrap:anywhere;font:9.5pt/1.4 Arial,sans-serif}@media screen{body{max-width:1040px;margin:24px auto;padding:24px}table{font-size:11pt}}@media screen{body{max-width:1040px;margin:24px auto;padding:24px}table{font-size:11pt}}@media print{a{color:inherit;text-decoration:none}.no-print{display:none}th{color:#17211f;background:#edf4f1}footer{position:fixed;bottom:-14mm;left:0;right:0;font-size:9pt;color:#40524d}}
</style></head><body><h1>InvesteMoz<br>Relatório consolidado do projecto</h1><p><strong>${escapeHtml(model.title)}</strong><br>Gerado em ${escapeHtml(new Date(model.generatedAt).toLocaleString('pt-MZ'))}<br>Versão/revisão: ${escapeHtml(model.version)}</p><p class="private">Documento privado. O portal não publica nem partilha este conteúdo.</p>${content.join('')}<footer><small>InvesteMoz · Relatório privado · ${escapeHtml(model.version)}</small></footer><script>window.addEventListener('load',()=>setTimeout(()=>window.print(),350));</script></body></html>`;
}
export async function generateProjectDossierPackage(
+34 -7
View File
@@ -111,6 +111,30 @@ function classification(origin: string): string {
return 'Referência/estado indicado';
}
export function formatDossierReportValue(field: string, value: string, currency = ''): string {
if (field === 'Estado do plano detalhado') {
return value.replace('Snapshot versionado disponível; usar também a exportação do plano financeiro', 'Plano guardado disponível; consulte também a exportação financeira');
}
if (field === 'Reconciliação do financiamento') {
const states: Record<string, string> = { shortfall: 'Financiamento insuficiente', surplus: 'Fontes superiores aos usos previstos', balanced: 'Fontes e usos equilibrados', unknown: 'Informação insuficiente', incomplete: 'Informação insuficiente' };
return states[value] ?? value;
}
if (/^Necessidade \d+$/.test(field)) {
value = value.replace('; gap;', '; Competência em falta;').replace('; unknown;', '; Por confirmar;').replace('; available;', '; Disponível (declarado);');
}
if (/^Marco \d+$/.test(field)) {
value = value.replace('; planned;', '; Planeado;').replace('; in_progress;', '; Em curso;').replace('; completed;', '; Concluído (declarado);');
}
if (/^(Necessidade|Marco) \d+$/.test(field)) {
value = value.replace(/(custo|planeado|realizado): ([^;]*)(?=;|$)/g, (_, label: string, amount: string) => {
const raw = amount.trim();
return `${label}: ${raw ? (/^\d+(?:\.\d{1,2})?$/.test(raw) ? `${raw} ${currency || '(moeda não informada)'}` : raw) : 'Não informado'}`;
}).replace(/prazo: (?=;|$)/g, 'prazo: Não informado');
}
// Presentation only: group the decimal string without converting the amount
// to a JavaScript float or changing the saved financial snapshot.
return value.replace(/^(-?)(\d+)\.(\d{2}) ([A-Z]{3})$/, (_, sign: string, whole: string, cents: string, currency: string) => `${sign}${whole.replace(/\B(?=(\d{3})+(?!\d))/g, ' ')},${cents} ${currency}`);
}
const rowSection: Record<string, DossierReportSectionId> = {
Projecto: 'project',
Mercado: 'market',
@@ -180,28 +204,31 @@ function makeSections(
{
field: 'Data de geração',
value: new Date(generatedAt).toLocaleString('pt-MZ'),
origin: 'Relógio do dispositivo no momento da exportação',
classification: 'Metadado do relatório',
origin: 'Emissão no momento da exportação',
classification: 'Data de emissão',
},
{
field: 'Versão/revisão do dossier',
value: version,
origin: 'Revisão de rascunho guardada ou impressão digital local',
classification: 'Metadado técnico',
origin: 'Revisão do dossier exportado',
classification: 'Referência da revisão',
},
);
}
for (const [sectionName, field, value, origin] of rows.slice(1)) {
// Questionnaire schema identifiers remain stored; they do not help the
// reader assess the project and are not a business report field.
if (field === 'Versão do questionário') continue;
const id = rowSection[sectionName];
if (!id) continue;
const section = sections.get(id);
if (!section) continue;
section.rows.push({
field,
value: absent(value),
value: absent(formatDossierReportValue(field, value, text(draft, 'currency'))),
origin,
classification: classification(origin),
classification: value.trim() === '' ? 'Informação em falta' : classification(origin),
});
}
@@ -321,7 +348,7 @@ function makeSections(
field: 'Versão do motor/cenário',
value: `${typeof context?.engine_version === 'string' ? context.engine_version : 'não identificada'} / ${typeof context?.scenario_version === 'number' ? context.scenario_version : currentCalculation.version}`,
origin: 'Contexto guardado na execução',
classification: 'Metadado técnico',
classification: 'Referência da revisão',
},
{
field: 'Fórmula e valores usados',