Support documented full annual noncivil PPC PEC estimates and dossier continuity
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
advanceCalendar,
|
||||
type AdvanceFiscalPeriod,
|
||||
} from './irpc-advance-calendar.ts';
|
||||
import {
|
||||
decimalFraction,
|
||||
addFractions,
|
||||
@@ -10,6 +14,8 @@ export const pecPlanSource =
|
||||
'RIRPC29(1):mesesJunho/Agosto/Outubro e opção de pagamento único. Montantes repartidos e mês único são hipótese explícita do utilizador,sem regra de igualdade,arredondamento,guia ou prazo legal presumidos. Conferência de prazo da opção única permanece separada.';
|
||||
export type PecPlan = {
|
||||
version: 1;
|
||||
periodFrom?: string;
|
||||
periodTo?: string;
|
||||
mode: '' | 'three' | 'single';
|
||||
reference: string;
|
||||
singleMonth: string;
|
||||
@@ -17,7 +23,10 @@ export type PecPlan = {
|
||||
august: string;
|
||||
october: string;
|
||||
};
|
||||
export const newPecPlan = (): PecPlan => ({
|
||||
export const newPecPlan = (period?: AdvanceFiscalPeriod): PecPlan => ({
|
||||
...(period?.from && period?.to
|
||||
? { periodFrom: period.from, periodTo: period.to }
|
||||
: {}),
|
||||
version: 1,
|
||||
mode: '',
|
||||
reference: '',
|
||||
@@ -27,6 +36,13 @@ export const newPecPlan = (): PecPlan => ({
|
||||
october: '',
|
||||
});
|
||||
export function validatePecPlan(p: PecPlan) {
|
||||
if (
|
||||
(p?.periodFrom !== undefined || p?.periodTo !== undefined) &&
|
||||
(typeof p.periodFrom !== 'string' || typeof p.periodTo !== 'string')
|
||||
)
|
||||
throw Error(
|
||||
'Contexto da hipótese PEC não recuperável;original preservado.',
|
||||
);
|
||||
if (
|
||||
!p ||
|
||||
p.version !== 1 ||
|
||||
@@ -46,9 +62,19 @@ export function calculatePecPlan(
|
||||
total: FiscalFraction | null,
|
||||
notApplicable: boolean,
|
||||
year: string,
|
||||
period?: AdvanceFiscalPeriod,
|
||||
) {
|
||||
validatePecPlan(p);
|
||||
const pending: string[] = [];
|
||||
const calendar = advanceCalendar(period, year);
|
||||
pending.push(...calendar.pending.map((p) => 'Projecção PEC: ' + p));
|
||||
const needsPeriodConfirmation =
|
||||
(calendar.mode === 'annual_non_civil' || p.periodFrom !== undefined) &&
|
||||
(p.periodFrom !== calendar.from || p.periodTo !== calendar.to);
|
||||
if (needsPeriodConfirmation)
|
||||
pending.push(
|
||||
'Projecção PEC: reconfira a distribuição no período actual;montantes e mês anterior conservados sem deslocação automática.',
|
||||
);
|
||||
let rows: Array<{ month: string; amount: FiscalFraction }> = [];
|
||||
if (!total)
|
||||
pending.push(
|
||||
@@ -92,11 +118,15 @@ export function calculatePecPlan(
|
||||
);
|
||||
else
|
||||
rows = amounts.map((amount, i) => ({
|
||||
month: ['2026-06', '2026-08', '2026-10'][i],
|
||||
month: calendar.pecMonths[i],
|
||||
amount,
|
||||
}));
|
||||
}
|
||||
} else if (!/^2026-(0[1-9]|1[0-2])$/.test(p.singleMonth))
|
||||
} else if (
|
||||
!/^20\d{2}-(0[1-9]|1[0-2])$/.test(p.singleMonth) ||
|
||||
p.singleMonth < calendar.from.slice(0, 7) ||
|
||||
p.singleMonth > calendar.to.slice(0, 7)
|
||||
)
|
||||
pending.push(
|
||||
'Projecção PEC:indique o mês previsto do pagamento único;isto não valida o prazo legal.',
|
||||
);
|
||||
@@ -104,7 +134,21 @@ export function calculatePecPlan(
|
||||
}
|
||||
return {
|
||||
version: pecPlanVersion,
|
||||
source: pecPlanSource,
|
||||
source:
|
||||
calendar.mode === 'annual_non_civil'
|
||||
? pecPlanSource.replace(
|
||||
'mesesJunho/Agosto/Outubro',
|
||||
'6.º/8.º/10.º mês do período anual não civil',
|
||||
) +
|
||||
' ' +
|
||||
calendar.source
|
||||
: pecPlanSource,
|
||||
months: calendar.pecMonths,
|
||||
needsPeriodConfirmation,
|
||||
contextFrom: calendar.from,
|
||||
contextTo: calendar.to,
|
||||
calendarPending: calendar.mode === 'unavailable',
|
||||
nonCivil: calendar.mode === 'annual_non_civil',
|
||||
mode: p.mode,
|
||||
pending,
|
||||
rows,
|
||||
@@ -120,8 +164,9 @@ export function pecPlanReport(
|
||||
total: FiscalFraction | null,
|
||||
notApplicable: boolean,
|
||||
year: string,
|
||||
period?: AdvanceFiscalPeriod,
|
||||
): Array<[string, string, string, string]> {
|
||||
const m = calculatePecPlan(p, total, notApplicable, year);
|
||||
const m = calculatePecPlan(p, total, notApplicable, year, period);
|
||||
return [
|
||||
[
|
||||
'IRPC — L8',
|
||||
|
||||
Reference in New Issue
Block a user