Init
This commit is contained in:
commit
2186d54475
67
main.py
Normal file
67
main.py
Normal file
@ -0,0 +1,67 @@
|
||||
class ProfitTaxCalculator:
|
||||
def __init__(self, income_tax_rate=0.1):
|
||||
self.transactions = []
|
||||
self.income_tax_rate = income_tax_rate
|
||||
|
||||
def add_transaction(self, amount, is_income=True, vat_rate=0.0, includes_vat=True):
|
||||
"""
|
||||
Add a transaction.
|
||||
:param amount: The amount billed (positive number).
|
||||
:param is_income: True if it is revenue, False if it is an expense.
|
||||
:param vat_rate: VAT rate applied (e.g., 0.2 for 20% VAT).
|
||||
:param includes_vat: True if the amount provided includes VAT, False if it's net.
|
||||
"""
|
||||
if vat_rate > 0:
|
||||
if includes_vat:
|
||||
vat_amount = amount * vat_rate / (1 + vat_rate)
|
||||
net_amount = amount / (1 + vat_rate)
|
||||
else:
|
||||
vat_amount = amount * vat_rate
|
||||
net_amount = amount
|
||||
else:
|
||||
vat_amount = 0
|
||||
net_amount = amount
|
||||
|
||||
self.transactions.append((net_amount, vat_amount, is_income))
|
||||
|
||||
def calculate_results(self):
|
||||
total_income = sum(t[0] for t in self.transactions if t[2])
|
||||
total_expenses = sum(t[0] for t in self.transactions if not t[2])
|
||||
total_vat_collected = sum(t[1] for t in self.transactions if t[2])
|
||||
total_vat_paid = sum(t[1] for t in self.transactions if not t[2])
|
||||
net_profit = total_income - total_expenses
|
||||
income_tax_due = net_profit * self.income_tax_rate if net_profit > 0 else 0
|
||||
final_profit = net_profit - income_tax_due
|
||||
|
||||
return {
|
||||
"Total Revenue": total_income,
|
||||
"Total Expenses": total_expenses,
|
||||
"VAT Collected": total_vat_collected,
|
||||
"VAT Paid": total_vat_paid,
|
||||
"Net Profit (Taxable)": net_profit,
|
||||
"Income Tax Due": income_tax_due,
|
||||
"Final Profit (After Tax)": final_profit
|
||||
}
|
||||
|
||||
def display_summary(self):
|
||||
results = self.calculate_results()
|
||||
print("\n--- Financial Summary ---")
|
||||
for key, value in results.items():
|
||||
print(f"{key}: {value:.2f} BGN")
|
||||
print("--------------------------\n")
|
||||
|
||||
if __name__ == "__main__":
|
||||
calc = ProfitTaxCalculator()
|
||||
while True:
|
||||
try:
|
||||
amount = float(input("Enter transaction amount (or 0 to finish): "))
|
||||
if amount == 0:
|
||||
break
|
||||
type_choice = input("Is this income? (y/n): ").strip().lower() == 'y'
|
||||
vat_rate = float(input("Enter VAT rate (e.g., 0.2 for 20% or 0 for none): "))
|
||||
includes_vat = input("Does the amount include VAT? (y/n): ").strip().lower() == 'y'
|
||||
calc.add_transaction(amount, type_choice, vat_rate, includes_vat)
|
||||
except ValueError:
|
||||
print("Invalid input. Please enter numbers correctly.")
|
||||
|
||||
calc.display_summary()
|
||||
Loading…
Reference in New Issue
Block a user