bordro 0.1.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Arda Zeybek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,181 @@
1
+ # bordro
2
+
3
+ [![CI](https://github.com/ardazeybek-dev/bordro/actions/workflows/ci.yml/badge.svg)](https://github.com/ardazeybek-dev/bordro/actions/workflows/ci.yml)
4
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
5
+
6
+ Turkish payroll calculator. Gross to net, net to gross, employer cost — and the
7
+ thing almost every online calculator gets wrong: **cumulative income tax across 12 months.**
8
+
9
+ **[Try it in your browser →](https://ardazeybek-dev.github.io/bordro/)**
10
+
11
+ Run it without installing anything:
12
+
13
+ ```bash
14
+ npx github:ardazeybek-dev/bordro 75000
15
+ ```
16
+
17
+ Add it to your project:
18
+
19
+ ```bash
20
+ npm install github:ardazeybek-dev/bordro
21
+ ```
22
+
23
+ > **Note on language:** the documentation, the code comments and the test names are in English.
24
+ > The API names, the CLI output and the web page stay in Turkish on purpose — the domain is
25
+ > Turkish tax law, its vocabulary has no clean English equivalent, and the people who need a
26
+ > `bordro` are reading their payslip in Turkish. Renaming the API would also break every
27
+ > installed copy for no benefit.
28
+
29
+ ## Why another salary calculator?
30
+
31
+ In Turkey, income tax is calculated **cumulatively** from the start of the year. Even
32
+ if your gross salary never changes, your take-home pay drops in the month your
33
+ cumulative tax base crosses into a higher bracket:
34
+
35
+ ```
36
+ Gross 75,000 TRY — 2026, no raise at any point
37
+
38
+ January 58,080.28 TRY 15%
39
+ March 58,017.78 TRY 20% ← moved up a bracket
40
+ April 54,892.77 TRY 20%
41
+ July 51,981.70 TRY 27% ← moved up again
42
+ December 51,834.05 TRY 27%
43
+
44
+ January → December difference: −6,246.23 TRY
45
+ ```
46
+
47
+ Calculators that compute a single month never show this drop. `bordro` computes all
48
+ twelve months and marks exactly when the bracket changes.
49
+
50
+ ## Usage
51
+
52
+ ### Library
53
+
54
+ ```js
55
+ import { hesapla, yillikHesapla, nettenBrute, isvereneMaliyet } from "bordro";
56
+ // install: npm install github:ardazeybek-dev/bordro
57
+
58
+ // One month (defaults to January)
59
+ hesapla(75000).net; // 58080.28
60
+ hesapla(75000, 7).net; // 51981.70 — July, higher bracket
61
+
62
+ // Full year
63
+ const year = yillikHesapla(75000);
64
+ year.toplam.net; // 650008.62 — annual net
65
+ year.dilimGecisAylari; // [3, 7] — months where the bracket changed
66
+ year.netDegisimi; // -6246.23 — December net minus January net
67
+
68
+ // Net to gross
69
+ nettenBrute(50000); // 63697.48
70
+
71
+ // Employer cost
72
+ isvereneMaliyet(75000).toplamMaliyet; // 92062.50
73
+ isvereneMaliyet(75000, { besPuanIndirimi: true }).toplamMaliyet; // 88312.50
74
+ ```
75
+
76
+ ### Command line
77
+
78
+ No installation needed — `npx` runs it straight from GitHub:
79
+
80
+ ```bash
81
+ npx github:ardazeybek-dev/bordro 75000 # gross to net, 12-month table
82
+ npx github:ardazeybek-dev/bordro --net 50000 # net to gross
83
+ npx github:ardazeybek-dev/bordro 75000 --isveren # employer cost
84
+ npx github:ardazeybek-dev/bordro 120000 --ay 7 # a single month (July)
85
+ npx github:ardazeybek-dev/bordro 75000 --json # JSON output
86
+ ```
87
+
88
+ Once installed, the command is simply `bordro`:
89
+
90
+ ```bash
91
+ bordro 75000 --isveren
92
+ ```
93
+
94
+ ```
95
+ Brüt 75.000,00 ₺ · 2026 · aylık bordro
96
+
97
+ Ay SGK+İşsizlik Gelir vergisi Damga NET Dilim
98
+ ─────────────────────────────────────────────────────────────────────
99
+ Ocak 11.250,00 5.351,17 318,55 58.080,28 %15
100
+ Şubat 11.250,00 5.351,17 318,55 58.080,28 %15
101
+ Mart 11.250,00 5.413,67 318,55 58.017,78 %20 ← dilim atladı
102
+ ...
103
+ ```
104
+
105
+ ## API
106
+
107
+ | Function | Returns |
108
+ |---|---|
109
+ | `hesapla(gross, month?, options?)` | Full payroll breakdown for that month (`AylikBordro`) |
110
+ | `yillikHesapla(gross, options?)` | All 12 months plus annual totals (`YillikSonuc`) |
111
+ | `brutenNete(gross, month?, options?)` | Net amount only |
112
+ | `nettenBrute(net, month?, options?)` | Gross salary that yields the given net |
113
+ | `isvereneMaliyet(gross, options?)` | Employer contributions and total cost |
114
+ | `yilParametreleri(year?)` | Statutory parameters for that year |
115
+
116
+ **Options:** `{ yil, asgariUcretIstisnasi, besPuanIndirimi }` — year, minimum-wage tax
117
+ exemption (on by default), and the 5-point employer contribution discount (off by default).
118
+
119
+ TypeScript definitions are included and there are no runtime dependencies.
120
+
121
+ ## 2026 parameters
122
+
123
+ | Item | Value |
124
+ |---|---|
125
+ | Gross minimum wage | 33,030.00 TRY |
126
+ | Net minimum wage | 28,075.50 TRY |
127
+ | Social security, employee share | 14% |
128
+ | Unemployment insurance, employee share | 1% |
129
+ | Social security, employer share | 20.75% *(with 5-point discount: 15.75%)* |
130
+ | Unemployment insurance, employer share | 2% |
131
+ | Social security ceiling | 297,270.00 TRY |
132
+ | Stamp tax | 0.759% |
133
+ | Income tax brackets | 190,000 → 15% · 400,000 → 20% · 1,500,000 → 27% · 5,300,000 → 35% · above → 40% |
134
+
135
+ All parameters live in `src/veri/2026.ts` together with their sources. Supporting a new
136
+ year means copying that file and registering it in the `YILLAR` map.
137
+
138
+ ## Correctness
139
+
140
+ The biggest risk in a payroll calculator is producing a wrong number silently. To guard
141
+ against that, **the tests are pinned to officially published figures**: if the net minimum
142
+ wage does not come out to exactly `28,075.50 TRY`, CI fails. Any mistyped parameter is
143
+ caught there.
144
+
145
+ ```bash
146
+ npm run verify # type-check + tests
147
+ ```
148
+
149
+ There are currently 40 tests covering bracket transitions, social security floor and
150
+ ceiling, net-to-gross round-tripping, exemption logic and invalid input.
151
+
152
+ ### A subtle detail
153
+
154
+ The minimum-wage exemption is computed from the **minimum-wage earner's own cumulative
155
+ tax base**. Since that base also exceeds the first bracket over a year
156
+ (12 × 28,075.50 = 336,906 TRY), the exemption itself grows mid-year — which means a
157
+ higher earner's net pay can tick **slightly upward** in that month. This is not a bug but
158
+ a consequence of the legislation, and it is tested explicitly in `test/kumulatif.test.ts`.
159
+
160
+ ## Out of scope
161
+
162
+ Disability tax relief, private pension deductions, private insurance premiums, bonuses
163
+ and fringe benefits, employees working under retirement social security status (SGDP),
164
+ and the minimum living allowance (abolished in 2022).
165
+
166
+ ## Sources
167
+
168
+ - [Vergi Merkezi — 2026 quick reference](https://vergimerkezi.com.tr/2026-pratik-bilgiler-mali-rehber/)
169
+ - [Kolay İK — 2026 income tax brackets](https://kolayik.com/blog/2026-gelir-vergisi-dilimleri-guncel-tablo)
170
+ - [Kolay İK — 2026 payroll parameters](https://kolayik.com/blog/2026-bordro-parametreleri)
171
+ - [CottGroup — statutory payroll deductions for 2026](https://www.cottgroup.com/tr/mevzuat/item/2026-yili-icin-bordrodaki-yasal-kesintiler)
172
+
173
+ ## Disclaimer
174
+
175
+ This package is provided for informational purposes and is not a substitute for an
176
+ official payroll statement. The calculations are open source and covered by tests, but
177
+ please consult your accountant for binding figures.
178
+
179
+ ## License
180
+
181
+ [MIT](LICENSE)
@@ -0,0 +1,253 @@
1
+ // src/bicim.ts
2
+ var TL_BICIMI = new Intl.NumberFormat("tr-TR", {
3
+ minimumFractionDigits: 2,
4
+ maximumFractionDigits: 2
5
+ });
6
+ var AY_ADLARI = [
7
+ "Ocak",
8
+ "\u015Eubat",
9
+ "Mart",
10
+ "Nisan",
11
+ "May\u0131s",
12
+ "Haziran",
13
+ "Temmuz",
14
+ "A\u011Fustos",
15
+ "Eyl\xFCl",
16
+ "Ekim",
17
+ "Kas\u0131m",
18
+ "Aral\u0131k"
19
+ ];
20
+ function tl(tutar) {
21
+ return TL_BICIMI.format(tutar);
22
+ }
23
+ function tlSimgeli(tutar) {
24
+ return `${tl(tutar)} \u20BA`;
25
+ }
26
+ function yuzde(oran) {
27
+ return `%${(oran * 100).toLocaleString("tr-TR", { maximumFractionDigits: 2 })}`;
28
+ }
29
+ function sayiyaCevir(girdi) {
30
+ const temiz = girdi.trim().replace(/[\s₺]/g, "").replace(/\./g, "").replace(",", ".");
31
+ const sayi = Number(temiz);
32
+ if (!Number.isFinite(sayi)) throw new Error(`Say\u0131ya \xE7evrilemedi: "${girdi}"`);
33
+ return sayi;
34
+ }
35
+
36
+ // src/veri/2026.ts
37
+ var YIL_2026 = {
38
+ yil: 2026,
39
+ // Gross minimum wage: 33,030.00 TRY/month (28,075.50 TRY net)
40
+ asgariUcretBrut: 33030,
41
+ // Social security earnings: the floor is the minimum wage, the ceiling is 9x that
42
+ sgkTaban: 33030,
43
+ sgkTavan: 297270,
44
+ // Premiums withheld from the employee
45
+ sgkIsciOrani: 0.14,
46
+ issizlikIsciOrani: 0.01,
47
+ // Premiums paid by the employer (20.75% = 11% disability/old age/death + 7.5% health + 2.25% short-term)
48
+ sgkIsverenOrani: 0.2075,
49
+ sgkIsverenIndirimliOrani: 0.1575,
50
+ // law 5510 art. 81-i: the 5-point discount
51
+ issizlikIsverenOrani: 0.02,
52
+ // Stamp duty on wages: 0.759 per cent
53
+ damgaVergisiOrani: 759e-5,
54
+ // The progressive schedule applied to wage income
55
+ gelirVergisiDilimleri: [
56
+ { ustSinir: 19e4, oran: 0.15 },
57
+ { ustSinir: 4e5, oran: 0.2 },
58
+ { ustSinir: 15e5, oran: 0.27 },
59
+ { ustSinir: 53e5, oran: 0.35 },
60
+ { ustSinir: Infinity, oran: 0.4 }
61
+ ],
62
+ kaynaklar: [
63
+ "Vergi Merkezi \u2014 2026 Pratik Bilgiler: https://vergimerkezi.com.tr/2026-pratik-bilgiler-mali-rehber/",
64
+ "Kolay \u0130K \u2014 2026 gelir vergisi dilimleri: https://kolayik.com/blog/2026-gelir-vergisi-dilimleri-guncel-tablo",
65
+ "Kolay \u0130K \u2014 2026 bordro parametreleri: https://kolayik.com/blog/2026-bordro-parametreleri",
66
+ "CottGroup \u2014 2026 y\u0131l\u0131 bordrodaki yasal kesintiler: https://www.cottgroup.com/tr/mevzuat/item/2026-yili-icin-bordrodaki-yasal-kesintiler"
67
+ ]
68
+ };
69
+
70
+ // src/hesap.ts
71
+ var YILLAR = {
72
+ 2026: YIL_2026
73
+ };
74
+ var VARSAYILAN_YIL = Math.max(...Object.keys(YILLAR).map(Number));
75
+ function kurusaYuvarla(tutar) {
76
+ return Math.round((tutar + Number.EPSILON) * 100) / 100;
77
+ }
78
+ function yilParametreleri(yil = VARSAYILAN_YIL) {
79
+ const p = YILLAR[yil];
80
+ if (!p) {
81
+ const destekli = Object.keys(YILLAR).join(", ");
82
+ throw new Error(`${yil} y\u0131l\u0131 i\xE7in parametre yok. Desteklenen y\u0131llar: ${destekli}`);
83
+ }
84
+ return p;
85
+ }
86
+ function tarifeyeGoreVergi(kumulatifMatrah, dilimler) {
87
+ let vergi = 0;
88
+ let altSinir = 0;
89
+ for (const dilim of dilimler) {
90
+ if (kumulatifMatrah <= altSinir) break;
91
+ const dilimdekiTutar = Math.min(kumulatifMatrah, dilim.ustSinir) - altSinir;
92
+ vergi += dilimdekiTutar * dilim.oran;
93
+ altSinir = dilim.ustSinir;
94
+ }
95
+ return vergi;
96
+ }
97
+ function dilimOrani(kumulatifMatrah, dilimler) {
98
+ for (const dilim of dilimler) {
99
+ if (kumulatifMatrah <= dilim.ustSinir) return dilim.oran;
100
+ }
101
+ return dilimler[dilimler.length - 1]?.oran ?? 0;
102
+ }
103
+ function primeEsasKazanc(brut, p) {
104
+ return Math.min(Math.max(brut, p.sgkTaban), p.sgkTavan);
105
+ }
106
+ function yillikHesapla(brut, secenekler = {}) {
107
+ if (!Number.isFinite(brut) || brut <= 0) {
108
+ throw new Error("Br\xFCt maa\u015F s\u0131f\u0131rdan b\xFCy\xFCk bir say\u0131 olmal\u0131.");
109
+ }
110
+ const p = yilParametreleri(secenekler.yil);
111
+ const istisnaUygula = secenekler.asgariUcretIstisnasi ?? true;
112
+ const asgariMatrah = kurusaYuvarla(
113
+ p.asgariUcretBrut * (1 - p.sgkIsciOrani - p.issizlikIsciOrani)
114
+ );
115
+ const asgariDamga = kurusaYuvarla(p.asgariUcretBrut * p.damgaVergisiOrani);
116
+ const sgkMatrahi = kurusaYuvarla(primeEsasKazanc(brut, p));
117
+ const sgkIsci = kurusaYuvarla(sgkMatrahi * p.sgkIsciOrani);
118
+ const issizlikIsci = kurusaYuvarla(sgkMatrahi * p.issizlikIsciOrani);
119
+ const gelirVergisiMatrahi = kurusaYuvarla(brut - sgkIsci - issizlikIsci);
120
+ const hesaplananDamgaVergisi = kurusaYuvarla(brut * p.damgaVergisiOrani);
121
+ const aylar = [];
122
+ const dilimGecisAylari = [];
123
+ let kumulatif = 0;
124
+ let asgariKumulatif = 0;
125
+ let oncekiDilim = 0;
126
+ for (let ay = 1; ay <= 12; ay++) {
127
+ const oncekiKumulatif = kumulatif;
128
+ kumulatif = kurusaYuvarla(kumulatif + gelirVergisiMatrahi);
129
+ const hesaplananGelirVergisi = kurusaYuvarla(
130
+ tarifeyeGoreVergi(kumulatif, p.gelirVergisiDilimleri) - tarifeyeGoreVergi(oncekiKumulatif, p.gelirVergisiDilimleri)
131
+ );
132
+ const asgariOncekiKumulatif = asgariKumulatif;
133
+ asgariKumulatif = kurusaYuvarla(asgariKumulatif + asgariMatrah);
134
+ const asgariAylikVergi = kurusaYuvarla(
135
+ tarifeyeGoreVergi(asgariKumulatif, p.gelirVergisiDilimleri) - tarifeyeGoreVergi(asgariOncekiKumulatif, p.gelirVergisiDilimleri)
136
+ );
137
+ const gelirVergisiIstisnasi = istisnaUygula ? Math.min(hesaplananGelirVergisi, asgariAylikVergi) : 0;
138
+ const damgaVergisiIstisnasi = istisnaUygula ? Math.min(hesaplananDamgaVergisi, asgariDamga) : 0;
139
+ const gelirVergisi = kurusaYuvarla(hesaplananGelirVergisi - gelirVergisiIstisnasi);
140
+ const damgaVergisi = kurusaYuvarla(hesaplananDamgaVergisi - damgaVergisiIstisnasi);
141
+ const kesintiler = kurusaYuvarla(sgkIsci + issizlikIsci + gelirVergisi + damgaVergisi);
142
+ const net = kurusaYuvarla(brut - kesintiler);
143
+ const buAyinDilimi = dilimOrani(kumulatif, p.gelirVergisiDilimleri);
144
+ const dilimAtladi = ay > 1 && buAyinDilimi > oncekiDilim;
145
+ if (dilimAtladi) dilimGecisAylari.push(ay);
146
+ oncekiDilim = buAyinDilimi;
147
+ aylar.push({
148
+ ay,
149
+ brut,
150
+ sgkMatrahi,
151
+ sgkIsci,
152
+ issizlikIsci,
153
+ gelirVergisiMatrahi,
154
+ kumulatifMatrah: kumulatif,
155
+ hesaplananGelirVergisi,
156
+ gelirVergisiIstisnasi,
157
+ gelirVergisi,
158
+ hesaplananDamgaVergisi,
159
+ damgaVergisiIstisnasi,
160
+ damgaVergisi,
161
+ kesintiler,
162
+ net,
163
+ vergiDilimiOrani: buAyinDilimi,
164
+ dilimAtladi
165
+ });
166
+ }
167
+ const topla = (secici) => kurusaYuvarla(aylar.reduce((t, a) => t + secici(a), 0));
168
+ const ilkAy = aylar[0];
169
+ const sonAy = aylar[aylar.length - 1];
170
+ return {
171
+ yil: p.yil,
172
+ brut,
173
+ aylar,
174
+ toplam: {
175
+ brut: topla((a) => a.brut),
176
+ sgkIsci: topla((a) => a.sgkIsci),
177
+ issizlikIsci: topla((a) => a.issizlikIsci),
178
+ gelirVergisi: topla((a) => a.gelirVergisi),
179
+ damgaVergisi: topla((a) => a.damgaVergisi),
180
+ kesintiler: topla((a) => a.kesintiler),
181
+ net: topla((a) => a.net)
182
+ },
183
+ dilimGecisAylari,
184
+ netDegisimi: kurusaYuvarla(sonAy.net - ilkAy.net)
185
+ };
186
+ }
187
+ function hesapla(brut, ay = 1, secenekler = {}) {
188
+ if (!Number.isInteger(ay) || ay < 1 || ay > 12) {
189
+ throw new Error("Ay 1 ile 12 aras\u0131nda bir tam say\u0131 olmal\u0131.");
190
+ }
191
+ return yillikHesapla(brut, secenekler).aylar[ay - 1];
192
+ }
193
+ function brutenNete(brut, ay = 1, secenekler = {}) {
194
+ return hesapla(brut, ay, secenekler).net;
195
+ }
196
+ function nettenBrute(net, ay = 1, secenekler = {}) {
197
+ if (!Number.isFinite(net) || net <= 0) {
198
+ throw new Error("Net maa\u015F s\u0131f\u0131rdan b\xFCy\xFCk bir say\u0131 olmal\u0131.");
199
+ }
200
+ let alt = 0;
201
+ let ust = Math.max(net * 3, 1e3);
202
+ while (brutenNete(ust, ay, secenekler) < net) {
203
+ ust *= 2;
204
+ if (ust > 1e12) throw new Error("Net maa\u015F \xE7ok y\xFCksek, br\xFCt kar\u015F\u0131l\u0131\u011F\u0131 bulunamad\u0131.");
205
+ }
206
+ for (let i = 0; i < 60; i++) {
207
+ const orta = (alt + ust) / 2;
208
+ if (brutenNete(orta, ay, secenekler) < net) alt = orta;
209
+ else ust = orta;
210
+ }
211
+ const brut = kurusaYuvarla(ust);
212
+ return brutenNete(brut, ay, secenekler) < net ? kurusaYuvarla(brut + 0.01) : brut;
213
+ }
214
+ function isvereneMaliyet(brut, secenekler = {}) {
215
+ if (!Number.isFinite(brut) || brut <= 0) {
216
+ throw new Error("Br\xFCt maa\u015F s\u0131f\u0131rdan b\xFCy\xFCk bir say\u0131 olmal\u0131.");
217
+ }
218
+ const p = yilParametreleri(secenekler.yil);
219
+ const indirimUygulandi = secenekler.besPuanIndirimi ?? false;
220
+ const sgkMatrahi = kurusaYuvarla(primeEsasKazanc(brut, p));
221
+ const isverenOrani = indirimUygulandi ? p.sgkIsverenIndirimliOrani : p.sgkIsverenOrani;
222
+ const sgkIsveren = kurusaYuvarla(sgkMatrahi * isverenOrani);
223
+ const issizlikIsveren = kurusaYuvarla(sgkMatrahi * p.issizlikIsverenOrani);
224
+ return {
225
+ brut,
226
+ sgkMatrahi,
227
+ sgkIsveren,
228
+ issizlikIsveren,
229
+ toplamMaliyet: kurusaYuvarla(brut + sgkIsveren + issizlikIsveren),
230
+ indirimUygulandi
231
+ };
232
+ }
233
+
234
+ export {
235
+ AY_ADLARI,
236
+ tl,
237
+ tlSimgeli,
238
+ yuzde,
239
+ sayiyaCevir,
240
+ YIL_2026,
241
+ YILLAR,
242
+ VARSAYILAN_YIL,
243
+ kurusaYuvarla,
244
+ yilParametreleri,
245
+ tarifeyeGoreVergi,
246
+ dilimOrani,
247
+ primeEsasKazanc,
248
+ yillikHesapla,
249
+ hesapla,
250
+ brutenNete,
251
+ nettenBrute,
252
+ isvereneMaliyet
253
+ };