# DrCr: Web-based double-entry bookkeeping framework # Copyright (C) 2022–2023 Lee Yingtong Li (RunasSudo) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . from ..config import TAX_MAPPING from ..models import Amount, Posting, Transaction, TrialBalancer from datetime import datetime def taxable_income(): balancer = TrialBalancer() balancer.apply_transactions(Transaction.query.all()) result = Amount(0, '$') for account in TAX_MAPPING['Salary and wages']: result.quantity += int(balancer.accounts[account].quantity / 100) * 100 for account in TAX_MAPPING['Government allowances']: result.quantity += int(balancer.accounts[account].quantity / 100) * 100 for account in TAX_MAPPING['Work-related self-education expenses']: result.quantity += int(balancer.accounts[account].quantity / 100) * 100 for account in TAX_MAPPING['Other work-related expenses']: result.quantity += int(balancer.accounts[account].quantity / 100) * 100 return result def base_income_tax(taxable_income): income = -taxable_income.as_cost().quantity if income <= 1820000: return Amount(0, '$') if income <= 4500000: return Amount(int((income - 1820000) * 0.19), '$') if income <= 12000000: return Amount(int(509200 + (income - 4500000) * 0.325), '$') if income <= 18000000: return Amount(int(2946700 + (income - 12000000) * 0.37), '$') return Amount(int(5166700 + (income - 18000000) * 0.45), '$') def calculate_tax(taxable_income): income = -taxable_income.as_cost().quantity medicare_levy = int(income * 0.02) return Amount(base_income_tax(taxable_income).quantity + medicare_levy, '$') def tax_transaction(taxable_income): tax = calculate_tax(taxable_income) # Get EOFY date dt = datetime.now().replace(month=6, day=30) if dt < datetime.now(): dt = dt.replace(year=dt.year + 1) return Transaction( dt=dt, description='Estimated tax payable', postings=[ Posting(account='Income Tax', quantity=tax.quantity, commodity='$'), Posting(account='Income Tax Control', quantity=-tax.quantity, commodity='$') ] )