Created
September 3, 2021 10:35
-
-
Save 25b3nk/19967645a06f8d514ec588c6abba8f4f to your computer and use it in GitHub Desktop.
Google sheets' App script to calculate income tax according to Indian new tax regime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Calculate Income tax based on new regime | |
function incomeAfterNewTaxDeductions(CTC) { | |
var initCostToCompany = CTC | |
var costToCompany = CTC | |
var totalTax = 0.0 | |
var new_tax_regime = { | |
1500000: 0.30, | |
1250000: 0.25, | |
1000000: 0.20, | |
750000: 0.15, | |
500000: 0.10, | |
250000: 0.05 | |
} | |
// Get the keys; Note that the keys are in string format | |
var slabs = Object.keys(new_tax_regime) | |
// Sort the keys | |
slabs.sort(sortDescendingOrder) | |
for (var i = 0; i < slabs.length; i++) { | |
var upperTaxSlab = parseFloat(slabs[i]) | |
if (costToCompany > upperTaxSlab) { | |
var currTax = parseFloat(new_tax_regime[upperTaxSlab]) * (costToCompany - upperTaxSlab) | |
totalTax = totalTax + currTax | |
costToCompany = upperTaxSlab | |
} | |
} | |
var healthEducationCess = 0.04 * totalTax | |
totalTax = totalTax + healthEducationCess | |
var incomeAfterTax = initCostToCompany - totalTax | |
// Logger.log("CTC: " + initCostToCompany + " Tax deducted income: " + incomeAfterTax) | |
return incomeAfterTax | |
} | |
function sortDescendingOrder(val1, val2) { | |
// Converting string to int | |
ele1 = parseInt(val1) | |
ele2 = parseInt(val2) | |
if (ele1 > ele2) { | |
return -1 | |
} | |
if (ele1 < ele2) { | |
return 1 | |
} | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to write custom functions and use them in google sheets: link