20 lines
3.7 KiB
TypeScript
20 lines
3.7 KiB
TypeScript
import {fraction,type FiscalFraction} from './fiscal-rational.ts';
|
||
|
||
export const normalAssessmentVersion='IRPC-normal-adjustments/4';
|
||
export type NormalAssessmentInput={version:1;treatment:''|'general_61_1'|'other';reference:string};
|
||
export const newNormalAssessmentInput=():NormalAssessmentInput=>({version:1,treatment:'',reference:''});
|
||
export function validateNormalAssessment(i:NormalAssessmentInput){if(!i||i.version!==1||!['','general_61_1','other'].includes(i.treatment)||typeof i.reference!=='string')throw Error('Enquadramento da colecta não recuperável;original conservado.');}
|
||
export type NormalAssessmentModel={input:NormalAssessmentInput;period:{year:string;from:string;to:string};classification:string;rate:FiscalFraction|null;taxableBase:FiscalFraction|null;colecta:FiscalFraction|null;centExact:boolean|null;pending:string[];rule:string;source:string;finalBalance:{scope:'L8';status:'not_calculated';payable:null;recoverable:null;reason:string}};
|
||
export function calculateNormalAssessment(input:NormalAssessmentInput,base:FiscalFraction|null,context:{year:string;scope:string;currency:string}):NormalAssessmentModel{
|
||
validateNormalAssessment(input);const pending:string[]=[],period={year:context.year,from:/^20\d{2}$/.test(context.year)?context.year+'-01-01':'',to:/^20\d{2}$/.test(context.year)?context.year+'-12-31':''};
|
||
if(context.year!=='2026')pending.push('Taxa geral correspondida neste incremento apenas ao exercício2026;sem taxa transportada para outro período.');
|
||
if(context.scope!=='resident_general'||context.currency!=='MZN')pending.push('Colecta delimitada ao sujeito residente no regime geral emMZN;outros âmbitos por corresponder.');
|
||
if(input.treatment!=='general_61_1')pending.push(input.treatment==='other'?'Benefício,taxa reduzida,tributação autónoma ou outro caso especial:tratamento próprio;sem taxa geral aplicada por aproximação.':'Enquadramento da taxa geral por identificar;sem escolha presumida.');
|
||
if(!input.reference.trim())pending.push('Identifique suporte ou pressuposto da aplicação da taxa geral ao caso;uma actividade semelhante não prova o regime.');
|
||
if(base===null)pending.push('Matéria colectável actual indeterminada;lucro tributável não é substituto da base.');
|
||
else if(!/^-?\d{1,80}$/.test(base.numerator)||!/^\d{1,80}$/.test(base.denominator)||BigInt(base.denominator)===0n||BigInt(base.numerator)<0n)pending.push('Matéria colectável deve ser um valor conhecido não negativo e reconciliado.');
|
||
const rate=input.treatment==='general_61_1'&&context.year==='2026'?fraction(32n):null;
|
||
const colecta=pending.length===0&&base!==null&&rate?fraction(BigInt(base.numerator)*32n,BigInt(base.denominator)*100n):null;
|
||
return{input:structuredClone(input),period,classification:input.treatment==='general_61_1'?'Regime normal — taxa geral do artigo61(1)':input.treatment==='other'?'Caso especial fora deste recorte':'Enquadramento por identificar',rate,taxableBase:base,colecta,centExact:colecta?(BigInt(colecta.numerator)*100n)%BigInt(colecta.denominator)===0n:null,pending,rule:'CIRPC61(1)-general-2026/1',source:'CIRPC Lei34/2007 art61(1),PDF17/p768(71):taxa geral32%. Lei4/2012 altera61(2);Lei20/2022 PDF1/p2731 mantém61(1),altera61(2) com termo31/12/2025;Lei12/2025 PDF18/20 não altera61(1),adita61-A para mais-valias,fora deste recorte. Exercício anual2026/MZN/residente geral,matéria colectável actual×32/100 em aritmética racional exacta. Sem arredondamento fiscal ou transcriçãoM20/M22 presumidos.',finalBalance:{scope:'L8',status:'not_calculated',payable:null,recoverable:null,reason:'Saldo final a pagar ou recuperar por determinar emL8:retenções,pagamentos e créditos do fecho anual não apurados nem abatidos à colecta neste incremento. Colecta não equivale ao saldo final.'}};
|
||
}
|