Skip to content

Instantly share code, notes, and snippets.

@ericzakariasson
Last active August 14, 2019 11:09
Show Gist options
  • Save ericzakariasson/768a142e6ac6360081e0ebbe861e8c02 to your computer and use it in GitHub Desktop.
Save ericzakariasson/768a142e6ac6360081e0ebbe861e8c02 to your computer and use it in GitHub Desktop.
Skatteverket Representation
const getSumOfTaxPerPerson = ({ rate, peopleCount, primary, secondary}) => ((primary / (primary + secondary)) * 300 * peopleCount * rate)
const getDeductableNotFika = ({
peopleCount,
tax12,
tax25,
}) => {
const tax12_exVat = tax12 / 1.12;
const tax25_exVat = tax25 / 1.25;
const isSumMoreThan300PerPerson = ((tax12_exVat + tax25_exVat) / peopleCount) > 300;
const isTax46OrMorePerPerson = (((tax12_exVat * 0.12) + (tax25_exVat * 0.25)) / peopleCount) >= 46
const isNotZeroTax = tax12_exVat > 0 && tax25_exVat > 0
const taxSumPerPerson =
getSumOfTaxPerPerson({ rate: 1.12, peopleCount, primary: tax12_exVat, secondary: tax25_exVat }) +
getSumOfTaxPerPerson({ rate: 1.25, peopleCount, secondary: tax12_exVat, primary: tax25_exVat })
const taxSum = (tax12_exVat * 0.12) + (tax25_exVat * 0.25);
const totalPersonCost = isSumMoreThan300PerPerson
? taxSumPerPerson
: taxSum
const something = totalPersonCost <= (46 * peopleCount);
if (isSumMoreThan300PerPerson && isTax46OrMorePerPerson && isNotZeroTax && something) {
return 46 * peopleCount;
}
if (isSumMoreThan300PerPerson) {
return taxSumPerPerson;
}
return taxSum;
}
const getRepresentation = ({
tax12 = 0,
tax25 = 0,
peopleCount = 1,
tip = 0
}) => {
const deductable = getDeductableNotFika({ peopleCount, tax12, tax25 })
const total = tax12 + tax25 + tip;
return {
deductable,
nonDeductable: total - deductable,
total
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment