@thecodecodex/tools 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,124 @@
1
+ import { cltYear, grossForAnnualTotal, irrf, type CltOptions } from "./finance/clt"
2
+ import { cooperativeInss } from "./finance/pj"
3
+
4
+ // --- 1. ENCARGOS CLT ---
5
+ // INSS, IRRF 2026 (tabela + redução da Lei 15.270/2025) e o pacote anual CLT vêm de src/finance/clt.ts
6
+
7
+ // --- 3. HIRING MODELS ---
8
+
9
+ export interface ComparisonResult {
10
+ model: string
11
+ monthlyGrossOrRevenue: number
12
+ monthlyLiquidity: number
13
+ annualLiquidity: number
14
+ monthlyAverageReal: number
15
+ monthlyTaxesAndFees: number
16
+ }
17
+
18
+ function calculateFullClt(targetAnnualLiquidity: number, modelName: string = "CLT", options: CltOptions = {}): ComparisonResult {
19
+ const cltFullGross = grossForAnnualTotal(targetAnnualLiquidity, options)
20
+ const year = cltYear(cltFullGross, options)
21
+
22
+ return {
23
+ model: modelName,
24
+ monthlyGrossOrRevenue: cltFullGross,
25
+ monthlyLiquidity: year.month.net,
26
+ annualLiquidity: targetAnnualLiquidity,
27
+ monthlyAverageReal: targetAnnualLiquidity / 12,
28
+ monthlyTaxesAndFees: year.month.inss + year.month.irrf.tax,
29
+ }
30
+ }
31
+
32
+ function calculateSimplePj(targetAnnualLiquidity: number, pjTaxRate: number = 0.06, modelName: string = "PJ (Simples Nacional)"): ComparisonResult {
33
+ const pjTargetNetMonthly = targetAnnualLiquidity / 12
34
+ const pjRevenue = pjTargetNetMonthly / (1 - pjTaxRate)
35
+ const pjMonthlyTax = pjRevenue * pjTaxRate
36
+ const monthlyLiquidity = pjRevenue - pjMonthlyTax
37
+
38
+ return {
39
+ model: modelName,
40
+ monthlyGrossOrRevenue: pjRevenue,
41
+ monthlyLiquidity: monthlyLiquidity, // No PJ sem provisão, a liquidez mensal é igual à média
42
+ annualLiquidity: targetAnnualLiquidity,
43
+ monthlyAverageReal: targetAnnualLiquidity / 12,
44
+ monthlyTaxesAndFees: pjMonthlyTax
45
+ }
46
+ }
47
+
48
+ function calculateCooperative(
49
+ targetAnnualLiquidity: number,
50
+ coopAdminFeeRate: number = 0.03,
51
+ businessVacationDays: number = 10,
52
+ proLaboreValue: number = 2500.00,
53
+ modelName: string = "Cooperado"
54
+ ): ComparisonResult {
55
+ const coopMonthsFactorWithVacation = 12 + (businessVacationDays / 22)
56
+ const coopTargetNetMonthly = targetAnnualLiquidity / coopMonthsFactorWithVacation
57
+
58
+ // cooperado é contribuinte individual: 20% de INSS retidos pela cooperativa (não a tabela do empregado)
59
+ const proLaboreInss = cooperativeInss(proLaboreValue)
60
+ const proLaboreIrrf = irrf({ taxableIncome: proLaboreValue, socialSecurity: proLaboreInss }).tax
61
+ const totalTaxesProLabore = proLaboreInss + proLaboreIrrf
62
+
63
+ const cooperativeRevenue = (coopTargetNetMonthly + totalTaxesProLabore) / (1 - coopAdminFeeRate)
64
+ const coopMonthlyAdminFee = cooperativeRevenue * coopAdminFeeRate
65
+ const monthlyLiquidity = cooperativeRevenue - coopMonthlyAdminFee - totalTaxesProLabore
66
+
67
+ return {
68
+ model: modelName,
69
+ monthlyGrossOrRevenue: cooperativeRevenue,
70
+ monthlyLiquidity: monthlyLiquidity,
71
+ annualLiquidity: targetAnnualLiquidity,
72
+ monthlyAverageReal: targetAnnualLiquidity / 12,
73
+ monthlyTaxesAndFees: coopMonthlyAdminFee + totalTaxesProLabore
74
+ }
75
+ }
76
+
77
+
78
+ // --- 4. EXECUTION ---
79
+
80
+ export interface ComparatorOptions {
81
+ targetLiquidity: number
82
+ pjTaxRate?: number
83
+ coopAdminFeeRate?: number
84
+ businessVacationDays?: number
85
+ proLaboreValue?: number
86
+ // benefícios e bônus do lado CLT entram no pacote anual (reduzem o bruto necessário)
87
+ cltBenefitsMonthly?: number
88
+ cltAnnualBonus?: number
89
+ includeFgts?: boolean
90
+ modelNames?: {
91
+ clt: string
92
+ pj: string
93
+ coop: string
94
+ }
95
+ }
96
+
97
+ export function generateComparison(options: ComparatorOptions): ComparisonResult[] {
98
+ const modelNames = options.modelNames || { clt: "CLT", pj: "PJ (Simples Nacional)", coop: "Cooperado" }
99
+ return [
100
+ calculateFullClt(options.targetLiquidity, modelNames.clt, { monthlyBenefits: options.cltBenefitsMonthly ?? 0, annualBonus: options.cltAnnualBonus ?? 0, includeFgts: options.includeFgts ?? true }),
101
+ calculateSimplePj(options.targetLiquidity, options.pjTaxRate, modelNames.pj),
102
+ calculateCooperative(options.targetLiquidity, options.coopAdminFeeRate, options.businessVacationDays, options.proLaboreValue, modelNames.coop)
103
+ ]
104
+ }
105
+ export const DEFAULT_OPTIONS: Required<Omit<ComparatorOptions, "modelNames" | "includeFgts">> = {
106
+ targetLiquidity: 100_000,
107
+ pjTaxRate: 0.06,
108
+ coopAdminFeeRate: 0.03,
109
+ businessVacationDays: 10,
110
+ proLaboreValue: 1_000,
111
+ cltBenefitsMonthly: 0,
112
+ cltAnnualBonus: 0,
113
+ }
114
+
115
+ // Modo "tenho uma proposta CLT": o pacote anual dessa proposta vira a meta que PJ e Cooperado precisam igualar
116
+ export function annualTargetFromCltOffer(gross: number, options: Pick<ComparatorOptions, "cltBenefitsMonthly" | "cltAnnualBonus" | "includeFgts"> = {}): number {
117
+ return cltYear(gross, { monthlyBenefits: options.cltBenefitsMonthly ?? 0, annualBonus: options.cltAnnualBonus ?? 0, includeFgts: options.includeFgts ?? true }).annualTotal
118
+ }
119
+
120
+ // Faturamento em moeda estrangeira: quanto cobrar para receber `brl` em reais, descontado o spread da conversão
121
+ export function foreignAmount(brl: number, exchangeRate: number, spread: number): number {
122
+ const effectiveRate = exchangeRate * (1 - spread)
123
+ return effectiveRate > 0 ? brl / effectiveRate : 0
124
+ }