fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -34,7 +34,10 @@ export function restoreCashflowDraftSnapshot(
|
||||
if (
|
||||
!parsed ||
|
||||
![1, 2].includes(parsed.version) ||
|
||||
(parsed.version === 2 && parsed.currency !== null && (typeof parsed.currency !== 'string' || !/^[A-Z]{3}$/.test(parsed.currency))) ||
|
||||
(parsed.version === 2 &&
|
||||
parsed.currency !== null &&
|
||||
(typeof parsed.currency !== 'string' ||
|
||||
!/^[A-Z]{3}$/.test(parsed.currency))) ||
|
||||
!['fixed', 'schedule'].includes(parsed.taxMode) ||
|
||||
!parsed.inputs ||
|
||||
typeof parsed.inputs !== 'object' ||
|
||||
@@ -58,7 +61,12 @@ export function restoreCashflowDraftSnapshot(
|
||||
} else if (typeof value !== 'string' || value.length > 160)
|
||||
return null;
|
||||
}
|
||||
return { version: parsed.version, ...(parsed.version === 2 ? {currency: parsed.currency} : {}), taxMode: parsed.taxMode, inputs: parsed.inputs };
|
||||
return {
|
||||
version: parsed.version,
|
||||
...(parsed.version === 2 ? { currency: parsed.currency } : {}),
|
||||
taxMode: parsed.taxMode,
|
||||
inputs: parsed.inputs,
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
@@ -69,14 +77,31 @@ export function serializeCashflowDraftSnapshot(
|
||||
inputs: CashflowDraftSnapshot['inputs'],
|
||||
currency?: string | null,
|
||||
): string {
|
||||
return JSON.stringify({ version: currency === undefined ? 1 : 2, ...(currency !== undefined ? {currency} : {}), taxMode, inputs });
|
||||
return JSON.stringify({
|
||||
version: currency === undefined ? 1 : 2,
|
||||
...(currency !== undefined ? { currency } : {}),
|
||||
taxMode,
|
||||
inputs,
|
||||
});
|
||||
}
|
||||
|
||||
export function cashflowCurrency(saved: CashflowDraftSnapshot, projectCurrency: string): {currency: string; matchesProject: boolean; notice: string} {
|
||||
export function cashflowCurrency(
|
||||
saved: CashflowDraftSnapshot,
|
||||
projectCurrency: string,
|
||||
): { currency: string; matchesProject: boolean; notice: string } {
|
||||
const currency = saved.version === 2 ? saved.currency : null;
|
||||
if (!currency) throw new Error('A moeda de origem da tesouraria guardada está por confirmar. Os montantes foram preservados; confirme a moeda na ferramenta de tesouraria antes de calcular ou reutilizar as vendas.');
|
||||
if (!currency)
|
||||
throw new Error(
|
||||
'A moeda de origem da tesouraria guardada está por confirmar. Os montantes foram preservados; confirme a moeda na ferramenta de tesouraria antes de calcular ou reutilizar as vendas.',
|
||||
);
|
||||
const matchesProject = currency === projectCurrency;
|
||||
return {currency, matchesProject, notice: matchesProject ? '' : `A tesouraria foi guardada em ${currency}, mas o projecto está em ${projectCurrency || 'moeda por indicar'}. Os montantes continuam em ${currency}; não foram convertidos nem reinterpretados. Para os reutilizar no projecto, restaure explicitamente a moeda de origem. Uma projecção noutra moeda exige pressupostos próprios.`};
|
||||
return {
|
||||
currency,
|
||||
matchesProject,
|
||||
notice: matchesProject
|
||||
? ''
|
||||
: `A tesouraria foi guardada em ${currency}, mas o projecto está em ${projectCurrency || 'moeda por indicar'}. Os montantes continuam em ${currency}; não foram convertidos nem reinterpretados. Para os reutilizar no projecto, restaure explicitamente a moeda de origem. Uma projecção noutra moeda exige pressupostos próprios.`,
|
||||
};
|
||||
}
|
||||
|
||||
export type MonthlyCashflowInput = {
|
||||
|
||||
Reference in New Issue
Block a user