feat(qa): separate startup resources and trace original example rows
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { csvCell } from './csv.js';
|
||||
import { calculateStartupAssetRequirements } from './startup-asset-requirements.ts';
|
||||
|
||||
type ProductLine = {
|
||||
label: string;
|
||||
@@ -120,6 +121,12 @@ export type BusinessFinancialPlanInput = {
|
||||
/** Explicit opt-in; saved forecasts without this choice retain their values. */
|
||||
applyAnnualGrowth?: boolean;
|
||||
creditTermDays?: string;
|
||||
startupAssetRequirements?: {
|
||||
cashRequired: string;
|
||||
otherCurrentAssetsRequired: string;
|
||||
longTermAssetsRequired: string;
|
||||
priorAssetInvestment?: string;
|
||||
};
|
||||
dividendsByPeriod?: string[];
|
||||
operatingExpenseLines?: {
|
||||
label: string;
|
||||
@@ -195,19 +202,22 @@ export function serializeBusinessPlanSnapshot(
|
||||
plan: BusinessFinancialPlanInput,
|
||||
): string {
|
||||
const snapshot = JSON.stringify({
|
||||
version: [
|
||||
'applyAnnualGrowth',
|
||||
'creditTermDays',
|
||||
'dividendsByPeriod',
|
||||
'operatingExpenseLines',
|
||||
'fundingBreakdown',
|
||||
'reportSource',
|
||||
].some(
|
||||
(key) =>
|
||||
plan[key as keyof BusinessFinancialPlanInput] !== undefined,
|
||||
)
|
||||
? 18
|
||||
: 17,
|
||||
version: plan.startupAssetRequirements
|
||||
? 19
|
||||
: [
|
||||
'applyAnnualGrowth',
|
||||
'creditTermDays',
|
||||
'dividendsByPeriod',
|
||||
'operatingExpenseLines',
|
||||
'fundingBreakdown',
|
||||
'reportSource',
|
||||
].some(
|
||||
(key) =>
|
||||
plan[key as keyof BusinessFinancialPlanInput] !==
|
||||
undefined,
|
||||
)
|
||||
? 18
|
||||
: 17,
|
||||
plan: {
|
||||
...plan,
|
||||
...(plan.useSupplierPaymentTerms === true
|
||||
@@ -290,7 +300,8 @@ export function restoreBusinessPlanSnapshot(
|
||||
decoded.version !== 15 &&
|
||||
decoded.version !== 16 &&
|
||||
decoded.version !== 17 &&
|
||||
decoded.version !== 18) ||
|
||||
decoded.version !== 18 &&
|
||||
decoded.version !== 19) ||
|
||||
!decoded.plan ||
|
||||
typeof decoded.plan !== 'object'
|
||||
)
|
||||
@@ -310,6 +321,21 @@ export function restoreBusinessPlanSnapshot(
|
||||
return null;
|
||||
const shortText = (v: unknown) =>
|
||||
typeof v === 'string' && v.length <= 160;
|
||||
if (plan.startupAssetRequirements !== undefined) {
|
||||
const r = plan.startupAssetRequirements as Record<string, unknown>;
|
||||
if (
|
||||
decoded.version < 19 ||
|
||||
!r ||
|
||||
![
|
||||
'cashRequired',
|
||||
'otherCurrentAssetsRequired',
|
||||
'longTermAssetsRequired',
|
||||
].every((k) => shortText(r[k])) ||
|
||||
(r.priorAssetInvestment !== undefined &&
|
||||
!shortText(r.priorAssetInvestment))
|
||||
)
|
||||
return null;
|
||||
}
|
||||
if (
|
||||
plan.creditTermDays !== undefined &&
|
||||
!shortText(plan.creditTermDays)
|
||||
@@ -1414,6 +1440,16 @@ export function compareBusinessScenarios(input: BusinessFinancialPlanInput) {
|
||||
|
||||
/** Forecast separates invoiced sales, collections, accounting expenses and cash payments. */
|
||||
export function forecastBusinessPlan(input: BusinessFinancialPlanInput) {
|
||||
if (input.startupAssetRequirements) {
|
||||
const needs = calculateStartupAssetRequirements(input);
|
||||
if (
|
||||
cents(input.assetInvestment, 'Investimento em activos') !==
|
||||
needs.assetInvestment
|
||||
)
|
||||
throw Error(
|
||||
'As aquisições do cenário não correspondem às necessidades de activos. Confira os valores e adopte as aquisições calculadas.',
|
||||
);
|
||||
}
|
||||
if (
|
||||
input.creditTermDays?.trim() &&
|
||||
(!/^\d+$/.test(input.creditTermDays) ||
|
||||
|
||||
Reference in New Issue
Block a user