Exemplo n.º 1
0
def taxFromEarnings(rates, earn):
	tax = 0

	for (rate, level) in orderedRates(rates):
		left = earn - level
		if left > 0:
			earn = left
			tax += level * rate
		else:	# they're in this band
			tax += earn * rate
			break

	return tax
Exemplo n.º 2
0
def earningsFromTax(rates, tax):
	if tax == 0:
		return "Up to %s" % rates[0]

	earn = 0

	for (rate, level) in orderedRates(rates):
		max_tax = level * rate	# at this band

#		print rate, level, max_tax, tax

		if tax > max_tax:
			tax -= max_tax
			earn += level
		else:	# they're in this band
			earn += tax / rate
			break

	return earn