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,3 +1,4 @@
|
||||
import { DecimalInput } from '@/components/decimal-input';
|
||||
import type { BusinessFinancialPlanInput } from '@/lib/business-financial-plan';
|
||||
import {
|
||||
buildComplementaryTables,
|
||||
@@ -34,13 +35,20 @@ export function MarketAnalysisPlan({
|
||||
) => (
|
||||
<label className="grid min-w-0 gap-1 text-sm">
|
||||
{label}
|
||||
<input
|
||||
className="min-w-0 rounded border p-2"
|
||||
type={type}
|
||||
step={type === 'number' ? 'any' : undefined}
|
||||
value={value}
|
||||
onChange={(e) => change(e.target.value)}
|
||||
/>
|
||||
{type === 'number' ? (
|
||||
<DecimalInput
|
||||
className="min-w-0 rounded border p-2"
|
||||
value={value}
|
||||
onValueChange={change}
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
className="min-w-0 rounded border p-2"
|
||||
type={type}
|
||||
value={value}
|
||||
onChange={(e) => change(e.target.value)}
|
||||
/>
|
||||
)}
|
||||
</label>
|
||||
);
|
||||
return (
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DecimalInput } from '@/components/decimal-input';
|
||||
import {
|
||||
forecastBusinessPlan,
|
||||
type BusinessFinancialPlanInput,
|
||||
@@ -42,12 +43,20 @@ export function PeriodInvestmentsEditor({
|
||||
) => (
|
||||
<label key={label} className="grid min-w-0 gap-1">
|
||||
{label}
|
||||
<input
|
||||
className="w-full min-w-0 rounded border p-2"
|
||||
type={type}
|
||||
value={value}
|
||||
onChange={(e) => change(e.target.value)}
|
||||
/>
|
||||
{type === 'number' ? (
|
||||
<DecimalInput
|
||||
className="w-full min-w-0 rounded border p-2"
|
||||
value={value}
|
||||
onValueChange={change}
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
className="w-full min-w-0 rounded border p-2"
|
||||
type={type}
|
||||
value={value}
|
||||
onChange={(e) => change(e.target.value)}
|
||||
/>
|
||||
)}
|
||||
</label>
|
||||
);
|
||||
let ledger: ReturnType<
|
||||
|
||||
@@ -5,7 +5,10 @@ import {
|
||||
type TeamNeed,
|
||||
} from '@/lib/project-dossier';
|
||||
import { restoreBusinessPlanSnapshot } from '@/lib/business-financial-plan';
|
||||
import { buildComplementaryTables } from '@/lib/complementary-report';
|
||||
import {
|
||||
buildComplementaryTables,
|
||||
teamPayrollSchedule,
|
||||
} from '@/lib/complementary-report';
|
||||
import { InvestmentReportTables } from './investment-report-tables';
|
||||
|
||||
const teamKeys = [
|
||||
@@ -64,20 +67,20 @@ function SupplementaryFields({
|
||||
{fields.map(([key, label, type]) => (
|
||||
<label className="grid min-w-0 gap-1 text-sm" key={key}>
|
||||
{label}
|
||||
<input
|
||||
className="min-w-0 rounded border p-2"
|
||||
type={type}
|
||||
min={type === 'number' ? 0 : undefined}
|
||||
step={
|
||||
type === 'number'
|
||||
? key === 'monthly_salary'
|
||||
? '0.01'
|
||||
: '1'
|
||||
: undefined
|
||||
}
|
||||
value={row[key] ?? ''}
|
||||
onChange={(e) => change(key, e.target.value)}
|
||||
/>
|
||||
{type === 'number' ? (
|
||||
<DecimalInput
|
||||
className="min-w-0 rounded border p-2"
|
||||
value={row[key] ?? ''}
|
||||
onValueChange={(value) => change(key, value)}
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
className="min-w-0 rounded border p-2"
|
||||
type={type}
|
||||
value={row[key] ?? ''}
|
||||
onChange={(e) => change(key, e.target.value)}
|
||||
/>
|
||||
)}
|
||||
</label>
|
||||
))}
|
||||
</>
|
||||
@@ -89,13 +92,34 @@ export function ProjectTeamPlanner({
|
||||
onChange,
|
||||
financialPlanSnapshot = '',
|
||||
projectCurrency = '',
|
||||
onAdoptPayroll,
|
||||
}: {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
financialPlanSnapshot?: string;
|
||||
projectCurrency?: string;
|
||||
/** Writes the map's monthly payroll into the financial plan, on the investor's request. */
|
||||
onAdoptPayroll?: (schedule: string[], payments: boolean) => void;
|
||||
}) {
|
||||
const rows = readRows<TeamNeed>(value, teamKeys);
|
||||
const plan = restoreBusinessPlanSnapshot(financialPlanSnapshot);
|
||||
const sameCurrency =
|
||||
!projectCurrency ||
|
||||
!plan?.currency ||
|
||||
plan.currency === projectCurrency;
|
||||
const payroll =
|
||||
plan && sameCurrency
|
||||
? teamPayrollSchedule(value, plan.periods ?? 12)
|
||||
: null;
|
||||
const adopted =
|
||||
payroll !== null &&
|
||||
payroll.every((amount, month) => {
|
||||
const current =
|
||||
plan?.monthlyPayrollExpenseByPeriod?.[month] ??
|
||||
plan?.monthlyPayrollExpense ??
|
||||
'';
|
||||
return Number(current || 0) === Number(amount);
|
||||
});
|
||||
const persist = (next: TeamNeed[]) => onChange(JSON.stringify(next));
|
||||
if (
|
||||
unreadable(value, rows, [
|
||||
@@ -303,10 +327,41 @@ export function ProjectTeamPlanner({
|
||||
project_team_snapshot: value,
|
||||
currency: projectCurrency,
|
||||
},
|
||||
restoreBusinessPlanSnapshot(financialPlanSnapshot),
|
||||
plan,
|
||||
)[2],
|
||||
]}
|
||||
/>
|
||||
{onAdoptPayroll && payroll && !adopted && (
|
||||
<div className="space-y-2 rounded border border-amber-300 bg-amber-50 p-3 text-sm">
|
||||
<p>
|
||||
O mapa de pessoal é a fonte da folha salarial. Para que
|
||||
o plano financeiro use os mesmos valores, escolha uma
|
||||
das opções. Só muda o que escolher.
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button
|
||||
type="button"
|
||||
className="rounded border px-3 py-2"
|
||||
onClick={() => onAdoptPayroll(payroll, false)}
|
||||
>
|
||||
Usar como custo mensal de pessoal
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="rounded border px-3 py-2"
|
||||
onClick={() => onAdoptPayroll(payroll, true)}
|
||||
>
|
||||
Usar como custo e pagamento (pago no próprio mês)
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{onAdoptPayroll && payroll && adopted && (
|
||||
<p className="text-sm text-emerald-800">
|
||||
O custo de pessoal do plano financeiro coincide com este
|
||||
mapa de pessoal.
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { DecimalInput } from '@/components/decimal-input';
|
||||
import { focusCorrectionId } from '@/lib/field-corrections';
|
||||
import { adoptTeamPayroll } from '@/lib/complementary-report';
|
||||
import FiscalOperationPicker from './fiscal-operation-picker';
|
||||
import { SimulationIrpcAnnual } from '@/components/simulation-irpc-annual';
|
||||
import DemographicContext from '@/components/demographic-context';
|
||||
@@ -3523,6 +3524,15 @@ export function SimulationForm() {
|
||||
onChange={(value) =>
|
||||
change('project_team_snapshot', value)
|
||||
}
|
||||
onAdoptPayroll={(schedule, payments) => {
|
||||
const next = adoptTeamPayroll(
|
||||
String(draft.business_plan_snapshot ?? ''),
|
||||
schedule,
|
||||
payments,
|
||||
);
|
||||
if (next)
|
||||
change('business_plan_snapshot', next);
|
||||
}}
|
||||
/>
|
||||
{draft.skills_needed && (
|
||||
<details className="rounded border p-3">
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DecimalInput } from '@/components/decimal-input';
|
||||
import { inputText } from '../lib/input-text.ts';
|
||||
import { useState } from 'react';
|
||||
import EvidenceDetails from '@/components/evidence-details';
|
||||
@@ -86,13 +87,22 @@ export function SimulationRemissionImports({
|
||||
) => (
|
||||
<label className="block" key={field}>
|
||||
{label}
|
||||
<input
|
||||
type={type}
|
||||
value={row[field]}
|
||||
onChange={(e) =>
|
||||
change(row.id, { [field]: e.target.value })
|
||||
}
|
||||
/>
|
||||
{type === 'number' ? (
|
||||
<DecimalInput
|
||||
value={row[field]}
|
||||
onValueChange={(value) =>
|
||||
change(row.id, { [field]: value })
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
type={type}
|
||||
value={row[field]}
|
||||
onChange={(e) =>
|
||||
change(row.id, { [field]: e.target.value })
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</label>
|
||||
);
|
||||
const select = (
|
||||
|
||||
@@ -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