Plano de pessoal: a folha salarial do mapa de pessoal passa a ser a fonte do custo de pessoal
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
O mapa de pessoal (passo Equipa) e o «Custo mensal de pessoal» do plano financeiro eram duas fontes independentes; o portal só avisava que divergiam. O mapa passa a calcular a folha salarial mês a mês e, enquanto o plano tiver outro valor, oferece duas acções expressas: usar como custo mensal de pessoal, ou como custo e pagamento no próprio mês. Depois da escolha a diferença desaparece e o passo confirma que coincidem. Um mapa incompleto ou noutra moeda nunca é adoptado; os pagamentos só mudam quando o investidor o pede. Os campos numéricos do mapa de pessoal, da análise de mercado, dos investimentos por período e das importações em regime de remissão passam a usar o mesmo campo decimal do simulador. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import {
|
||||
forecastBusinessPlan,
|
||||
businessPlanNumberError,
|
||||
restoreBusinessPlanSnapshot,
|
||||
serializeBusinessPlanSnapshot,
|
||||
type BusinessFinancialPlanInput,
|
||||
} from './business-financial-plan.ts';
|
||||
import {
|
||||
@@ -102,6 +104,75 @@ const table = (
|
||||
],
|
||||
});
|
||||
|
||||
/**
|
||||
* Monthly payroll of the personnel map, in the plan's decimal format: the one
|
||||
* source the investor can adopt for «Custo mensal de pessoal». Null while any
|
||||
* function is incomplete, so a partial map never becomes the plan's payroll.
|
||||
*/
|
||||
export function teamPayrollSchedule(
|
||||
teamSnapshot: string,
|
||||
periods: number,
|
||||
): string[] | null {
|
||||
const data = structuredRows<TeamNeed>(
|
||||
teamSnapshot,
|
||||
['competency', 'state', 'action', 'estimated_cost', 'due_date'],
|
||||
[
|
||||
'department',
|
||||
'quantity',
|
||||
'monthly_salary',
|
||||
'start_month',
|
||||
'end_month',
|
||||
],
|
||||
);
|
||||
if (!data.valid || !data.rows.length) return null;
|
||||
const totals = Array(periods).fill(0n) as bigint[];
|
||||
try {
|
||||
for (const r of data.rows) {
|
||||
requireField(r.competency, 'Competência ou função');
|
||||
requireField(r.department, 'Departamento (mapa de pessoal)');
|
||||
const count = integer(r.quantity, 0, 1000000);
|
||||
const salary = amount(r.monthly_salary);
|
||||
const start = integer(r.start_month, 1, periods);
|
||||
const end = integer(r.end_month, 1, periods);
|
||||
if (start > end) return null;
|
||||
for (let month = start; month <= end; month++)
|
||||
totals[month - 1] += salary * BigInt(count);
|
||||
}
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
return totals.map(
|
||||
(v) => `${v / 100n}.${String(v % 100n).padStart(2, '0')}`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The financial plan with the personnel map's payroll as its personnel cost
|
||||
* (and, when asked, as its payment in the same month). Every other value of
|
||||
* the plan is kept. Null when the saved plan cannot be read.
|
||||
*/
|
||||
export function adoptTeamPayroll(
|
||||
planSnapshot: string,
|
||||
schedule: string[],
|
||||
payments: boolean,
|
||||
): string | null {
|
||||
const plan = restoreBusinessPlanSnapshot(planSnapshot);
|
||||
if (!plan) return null;
|
||||
const constant = schedule.every((amount) => amount === schedule[0]);
|
||||
const byPeriod = constant ? undefined : [...schedule];
|
||||
return serializeBusinessPlanSnapshot({
|
||||
...plan,
|
||||
monthlyPayrollExpense: schedule[0] ?? '',
|
||||
monthlyPayrollExpenseByPeriod: byPeriod,
|
||||
...(payments
|
||||
? {
|
||||
monthlyPayrollPayments: schedule[0] ?? '',
|
||||
monthlyPayrollPaymentsByPeriod: byPeriod,
|
||||
}
|
||||
: {}),
|
||||
});
|
||||
}
|
||||
|
||||
export function isMarketAnalysis(
|
||||
value: unknown,
|
||||
): value is NonNullable<BusinessFinancialPlanInput['marketAnalysis']> {
|
||||
|
||||
Reference in New Issue
Block a user