|
| 1 | +import { format } from "../utils/currency"; |
| 2 | + |
| 3 | +interface CalcProps { |
| 4 | + grossSalary: number; |
| 5 | + maritalStatus: string; |
| 6 | + dependents: string; |
| 7 | +} |
| 8 | + |
| 9 | +interface IPTKPRate { |
| 10 | + [key: string]: number; |
| 11 | +} |
| 12 | + |
| 13 | +const NUMBER_OF_MONTHS_IN_A_YEAR = 12; |
| 14 | +const POSITION_COST_PERCENTAGE = 0.05; |
| 15 | + |
| 16 | +const PERCENTAGE_OF_BPJS_HEALTH_COVERED_BY_EMPLOYEES = 0.01; |
| 17 | +const PERCENTAGE_OF_BPJS_HEALTH_COVERED_BY_COMPANY = 0.04; |
| 18 | + |
| 19 | +const PERCENTAGE_OF_BPJS_EMPLOYEMENT_COVERED_BY_EMPLOYEES = 0.02; |
| 20 | +const PERCENTAGE_OF_BPJS_EMPLOYEMENT_COVERED_BY_COMPANY = 0.037; |
| 21 | + |
| 22 | +const PTKP_RATE = { |
| 23 | + "TK/0": 54_000_000, |
| 24 | + "TK/1": 58_500_000, |
| 25 | + "TK/2": 63_000_000, |
| 26 | + "TK/3": 67_500_000, |
| 27 | + "K/0": 58_500_000, |
| 28 | + "K/1": 63_000_000, |
| 29 | + "K/2": 67_500_000, |
| 30 | + "K/3": 7_200_0000, |
| 31 | +} as IPTKPRate; |
| 32 | + |
| 33 | +function calcBPJSHealth(salary: number, percentage: number): number { |
| 34 | + if (salary < 12_000_000) { |
| 35 | + return salary * percentage; |
| 36 | + } |
| 37 | + return 12_000_000 * percentage; |
| 38 | +} |
| 39 | + |
| 40 | +function getTax21Percentage(pkp: number): number { |
| 41 | + if (pkp <= 60_000_000) { |
| 42 | + return 0.05; |
| 43 | + } else if (pkp <= 250_000_000) { |
| 44 | + return 0.15; |
| 45 | + } else if (pkp <= 500_000_000) { |
| 46 | + return 0.25; |
| 47 | + } else if (pkp <= 5_000_000_000) { |
| 48 | + return 0.3; |
| 49 | + } else { |
| 50 | + return 0.35; |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +function calcPositionCost( |
| 55 | + annualizedSalary: number, |
| 56 | + positionCostPercentage: number |
| 57 | +): number { |
| 58 | + let positionCost = annualizedSalary * positionCostPercentage; |
| 59 | + console.log("calcPositionCost positionCost", positionCost); |
| 60 | + if (positionCost > 6_000_000) { |
| 61 | + positionCost = 6_000_000; |
| 62 | + } else if (positionCost > 500_000) { |
| 63 | + positionCost = 500_000; |
| 64 | + } |
| 65 | + return positionCost; |
| 66 | +} |
| 67 | + |
| 68 | +function Calc({ grossSalary, maritalStatus, dependents }: CalcProps) { |
| 69 | + const annualizedSalary = grossSalary * NUMBER_OF_MONTHS_IN_A_YEAR; |
| 70 | + const ptkp = PTKP_RATE[`${maritalStatus}/${dependents}`]; |
| 71 | + const pkp = annualizedSalary - PTKP_RATE[`${maritalStatus}/${dependents}`]; |
| 72 | + const positionCost = calcPositionCost( |
| 73 | + annualizedSalary, |
| 74 | + POSITION_COST_PERCENTAGE |
| 75 | + ); |
| 76 | + const tax21 = getTax21Percentage(pkp) * pkp - positionCost; |
| 77 | + const monthlyIncomeTax = tax21 / 12; |
| 78 | + |
| 79 | + const bpjsHealthCoveredByEmployees = calcBPJSHealth( |
| 80 | + grossSalary, |
| 81 | + PERCENTAGE_OF_BPJS_HEALTH_COVERED_BY_EMPLOYEES |
| 82 | + ); |
| 83 | + const bpjsHealthCoveredByCompany = calcBPJSHealth( |
| 84 | + grossSalary, |
| 85 | + PERCENTAGE_OF_BPJS_HEALTH_COVERED_BY_COMPANY |
| 86 | + ); |
| 87 | + |
| 88 | + const bpjsEmployementCoveredByEmployees = |
| 89 | + grossSalary * PERCENTAGE_OF_BPJS_EMPLOYEMENT_COVERED_BY_EMPLOYEES; |
| 90 | + const bpjsEmployementCoveredByCompany = |
| 91 | + grossSalary * PERCENTAGE_OF_BPJS_EMPLOYEMENT_COVERED_BY_COMPANY; |
| 92 | + |
| 93 | + const bpjsEmploymentCost = |
| 94 | + bpjsEmployementCoveredByEmployees + bpjsEmployementCoveredByCompany; |
| 95 | + const bpjsHealthCost = |
| 96 | + bpjsHealthCoveredByEmployees + bpjsHealthCoveredByCompany; |
| 97 | + const nettoSalary = |
| 98 | + grossSalary - (monthlyIncomeTax + bpjsEmploymentCost + bpjsHealthCost); |
| 99 | + |
| 100 | + return ( |
| 101 | + <section className="w-full min-h-[300px] items-end flex flex-col gap-4"> |
| 102 | + <div className="bg-[#f4f6fb] rounded-md p-4 flex flex-col w-full"> |
| 103 | + <div className="flex flex-row justify-between mb-1"> |
| 104 | + <h1 className="text-slate-900 text-base">Gaji Disetahunkan</h1> |
| 105 | + <h1 className="text-slate-900 text-base font-bold text-right w-[250px] md:w-fit"> |
| 106 | + Rp {format(annualizedSalary)} |
| 107 | + </h1> |
| 108 | + </div> |
| 109 | + |
| 110 | + <div className="flex flex-row justify-between mb-1"> |
| 111 | + <p className="text-slate-500 font-thin text-xs"> |
| 112 | + Penghasilan Tidak Kena Pajak (PTKP) |
| 113 | + </p> |
| 114 | + <p className="text-slate-500 font-thin text-xs text-right w-[250px] md:w-fit"> |
| 115 | + Rp {format(ptkp)} |
| 116 | + </p> |
| 117 | + </div> |
| 118 | + |
| 119 | + <div className="flex flex-row justify-between mb-4"> |
| 120 | + <p className="text-slate-500 font-thin text-xs"> |
| 121 | + Penghasilan Kena Pajak (PKP) |
| 122 | + </p> |
| 123 | + <p className="text-slate-500 font-thin text-xs text-right w-[250px] md:w-fit"> |
| 124 | + Rp {format(pkp)} |
| 125 | + </p> |
| 126 | + </div> |
| 127 | + |
| 128 | + <div className="h-[0.5px] bg-gray-500 w-full mb-4" /> |
| 129 | + |
| 130 | + <div className="flex flex-row justify-between mb-1"> |
| 131 | + <h1 className="text-slate-900 text-base"> |
| 132 | + Pajak Penghasilan Tahunan (PPh 21) |
| 133 | + </h1> |
| 134 | + <h1 className="text-slate-900 text-base font-bold text-right w-[250px] md:w-fit"> |
| 135 | + Rp {format(tax21)} |
| 136 | + </h1> |
| 137 | + </div> |
| 138 | + |
| 139 | + <div className="flex flex-row justify-between mb-2"> |
| 140 | + <p className="text-slate-500 font-thin text-xs"> |
| 141 | + Pajak Penghasilan Bulanan |
| 142 | + </p> |
| 143 | + <p className="text-slate-500 font-thin text-xs text-right w-[250px] md:w-fit"> |
| 144 | + Rp {format(monthlyIncomeTax)} |
| 145 | + </p> |
| 146 | + </div> |
| 147 | + |
| 148 | + <div className="flex flex-row justify-between mb-1"> |
| 149 | + <h1 className="text-slate-900 text-base">BPJS Kesehatan</h1> |
| 150 | + <h1 className="text-slate-900 text-base font-bold text-right w-[250px] md:w-fit"> |
| 151 | + Rp {format(bpjsHealthCost)} |
| 152 | + </h1> |
| 153 | + </div> |
| 154 | + |
| 155 | + <div className="flex flex-row justify-between mb-2"> |
| 156 | + <p className="text-slate-500 font-thin text-xs"> |
| 157 | + Iuran ditanggung Karyawan |
| 158 | + </p> |
| 159 | + <p className="text-slate-500 font-thin text-xs text-right w-[250px] md:w-fit"> |
| 160 | + Rp {format(bpjsHealthCoveredByEmployees)} |
| 161 | + </p> |
| 162 | + </div> |
| 163 | + |
| 164 | + <div className="flex flex-row justify-between mb-2"> |
| 165 | + <p className="text-slate-500 font-thin text-xs"> |
| 166 | + Iuran ditanggung Perusahaan |
| 167 | + </p> |
| 168 | + <p className="text-slate-500 font-thin text-xs text-right w-[250px] md:w-fit"> |
| 169 | + Rp {format(bpjsHealthCoveredByCompany)} |
| 170 | + </p> |
| 171 | + </div> |
| 172 | + |
| 173 | + <div className="flex flex-row justify-between mb-1"> |
| 174 | + <h1 className="text-slate-900 text-base">BPJS Ketenagakerjaan</h1> |
| 175 | + <h1 className="text-slate-900 text-base font-bold text-right w-[250px] md:w-fit"> |
| 176 | + Rp {format(bpjsEmploymentCost)} |
| 177 | + </h1> |
| 178 | + </div> |
| 179 | + |
| 180 | + <div className="flex flex-row justify-between mb-2"> |
| 181 | + <p className="text-slate-500 font-thin text-xs"> |
| 182 | + Iuran ditanggung Karyawan |
| 183 | + </p> |
| 184 | + <p className="text-slate-500 font-thin text-xs text-right w-[250px] md:w-fit"> |
| 185 | + Rp {format(bpjsEmployementCoveredByEmployees)} |
| 186 | + </p> |
| 187 | + </div> |
| 188 | + |
| 189 | + <div className="flex flex-row justify-between mb-2"> |
| 190 | + <p className="text-slate-500 font-thin text-xs"> |
| 191 | + Iuran ditanggung Perusahaan |
| 192 | + </p> |
| 193 | + <p className="text-slate-500 font-thin text-xs text-right w-[250px] md:w-fit"> |
| 194 | + Rp {format(bpjsEmployementCoveredByCompany)} |
| 195 | + </p> |
| 196 | + </div> |
| 197 | + </div> |
| 198 | + |
| 199 | + <div className="bg-lime-100 rounded-md p-6 flex flex-col w-full"> |
| 200 | + <div className="flex flex-col"> |
| 201 | + <h1 className="text-slate-900 text-sm mb-2"> |
| 202 | + Gaji bersih bulanan (Take Home Pay) |
| 203 | + </h1> |
| 204 | + <h1 className="text-slate-950 font-bold text-3xl"> |
| 205 | + Rp {format(nettoSalary)} |
| 206 | + </h1> |
| 207 | + </div> |
| 208 | + </div> |
| 209 | + </section> |
| 210 | + ); |
| 211 | +} |
| 212 | + |
| 213 | +export default Calc; |
0 commit comments