Created
August 8, 2024 14:29
-
-
Save CodeCouturiers/955b7f7f9bc602b0daa8fcfd940c344f to your computer and use it in GitHub Desktop.
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
import datetime | |
from decimal import Decimal | |
class Transaction: | |
def __init__(self, date, amount, description, transaction_type): | |
self.date = date | |
self.amount = Decimal(amount) | |
self.description = description | |
self.transaction_type = transaction_type # 'income' or 'expense' | |
class AccountingSystem: | |
def __init__(self): | |
self.transactions = [] | |
self.tax_system = '3group_5percent' # Default tax system | |
def add_transaction(self, date, amount, description, transaction_type): | |
transaction = Transaction(date, amount, description, transaction_type) | |
self.transactions.append(transaction) | |
def get_balance(self, start_date, end_date): | |
balance = Decimal('0') | |
for transaction in self.transactions: | |
if start_date <= transaction.date <= end_date: | |
if transaction.transaction_type == 'income': | |
balance += transaction.amount | |
else: | |
balance -= transaction.amount | |
return balance | |
def generate_report(self, start_date, end_date): | |
income = Decimal('0') | |
expenses = Decimal('0') | |
for transaction in self.transactions: | |
if start_date <= transaction.date <= end_date: | |
if transaction.transaction_type == 'income': | |
income += transaction.amount | |
else: | |
expenses += transaction.amount | |
balance = income - expenses | |
tax = self.calculate_tax(income) | |
report = f""" | |
Звіт за період з {start_date} по {end_date} | |
Загальний дохід: {income} | |
Загальні витрати: {expenses} | |
Баланс: {balance} | |
Податок до сплати: {tax} | |
""" | |
return report | |
def calculate_tax(self, income): | |
if self.tax_system == '3group_5percent': | |
return income * Decimal('0.05') | |
elif self.tax_system == '3group_3percent': | |
return income * Decimal('0.03') | |
else: | |
raise ValueError("Невідома система оподаткування") | |
def change_tax_system(self, new_system): | |
if new_system in ['3group_5percent', '3group_3percent']: | |
self.tax_system = new_system | |
else: | |
raise ValueError("Невідома система оподаткування") | |
class PrimaryDocuments: | |
def __init__(self): | |
self.documents = [] | |
def add_document(self, date, document_type, number, amount, description): | |
document = { | |
'date': date, | |
'type': document_type, | |
'number': number, | |
'amount': Decimal(amount), | |
'description': description | |
} | |
self.documents.append(document) | |
def get_documents(self, start_date, end_date): | |
return [doc for doc in self.documents if start_date <= doc['date'] <= end_date] | |
class BankIntegration: | |
def __init__(self, accounting_system): | |
self.accounting_system = accounting_system | |
def import_bank_statement(self, statement): | |
for transaction in statement: | |
self.accounting_system.add_transaction( | |
transaction['date'], | |
transaction['amount'], | |
transaction['description'], | |
'income' if transaction['amount'] > 0 else 'expense' | |
) | |
# Ініціалізація системи | |
accounting = AccountingSystem() | |
documents = PrimaryDocuments() | |
bank_integration = BankIntegration(accounting) | |
# Функція для зручного додавання транзакцій | |
def add_transaction(date, amount, description, type): | |
accounting.add_transaction(date, amount, description, type) | |
documents.add_document(date, "Рахунок", f"INV-{date.strftime('%Y%m%d')}", amount, description) | |
# Встановлення початкової дати | |
start_date = datetime.date(2023, 1, 1) | |
# Дохід від клієнтів (щомісячні платежі) | |
clients = ["Client A", "Client B", "Client C", "Client D", "Client E", | |
"Client F", "Client G", "Client H", "Client I", "Client J"] | |
for month in range(1, 13): # Для кожного місяця року | |
for client in clients: | |
payment_date = datetime.date(2023, month, 15) # Припустимо, що клієнти платять 15-го числа | |
add_transaction(payment_date, 1000, f"Щомісячна оплата за послуги SIP-телефонії - {client}", "income") | |
# Витрати на інфраструктуру | |
for month in range(1, 13): | |
payment_date = datetime.date(2023, month, 5) | |
add_transaction(payment_date, 2000, "Оплата хостингу та серверів", "expense") | |
add_transaction(payment_date, 500, "Ліцензії на програмне забезпечення", "expense") | |
# Заробітна плата співробітникам (припустимо, у вас 3 співробітники) | |
for month in range(1, 13): | |
payment_date = datetime.date(2023, month, 1) | |
add_transaction(payment_date, 5000, "Заробітна плата - Розробник 1", "expense") | |
add_transaction(payment_date, 4500, "Заробітна плата - Розробник 2", "expense") | |
add_transaction(payment_date, 4000, "Заробітна плата - Підтримка клієнтів", "expense") | |
# Маркетингові витрати | |
for quarter in range(4): | |
payment_date = datetime.date(2023, quarter * 3 + 1, 10) | |
add_transaction(payment_date, 3000, "Рекламна кампанія в Google Ads", "expense") | |
add_transaction(payment_date, 2000, "Участь у галузевій конференції", "expense") | |
# Разові доходи (нові клієнти, додаткові послуги) | |
add_transaction(datetime.date(2023, 3, 20), 45000, "Налаштування системи для нового клієнта", "income") | |
add_transaction(datetime.date(2023, 6, 15), 13000, "Додаткові послуги інтеграції для Client C", "income") | |
add_transaction(datetime.date(2023, 9, 5), 14500, "Консультаційні послуги для Client F", "income") | |
# Разові витрати | |
add_transaction(datetime.date(2023, 2, 10), 3000, "Оновлення офісного обладнання", "expense") | |
add_transaction(datetime.date(2023, 5, 22), 1500, "Юридичні послуги", "expense") | |
add_transaction(datetime.date(2023, 11, 30), 2000, "Навчання персоналу", "expense") | |
# Імітація банківської виписки | |
bank_statement = [ | |
{'date': datetime.date(2023, 1, 15), 'amount': 10000, 'description': "Оплата від клієнтів"}, | |
{'date': datetime.date(2023, 1, 5), 'amount': -2500, 'description': "Оплата хостингу та ліцензій"}, | |
{'date': datetime.date(2023, 1, 1), 'amount': -13500, 'description': "Заробітна плата"}, | |
{'date': datetime.date(2023, 2, 10), 'amount': -3000, 'description': "Оновлення обладнання"}, | |
# ... (додайте більше транзакцій відповідно до введених вище) | |
] | |
bank_integration.import_bank_statement(bank_statement) | |
# Зміна системи оподаткування (наприклад, якщо ви стали платником ПДВ) | |
accounting.change_tax_system('3group_3percent') | |
# Генерація річного звіту | |
annual_report = accounting.generate_report(start_date, datetime.date(2023, 12, 31)) | |
print(annual_report) | |
# Отримання балансу за рік | |
annual_balance = accounting.get_balance(start_date, datetime.date(2023, 12, 31)) | |
print(f"Річний баланс: {annual_balance}") | |
# Отримання всіх первинних документів за рік | |
all_documents = documents.get_documents(start_date, datetime.date(2023, 12, 31)) | |
print(f"Загальна кількість первинних документів: {len(all_documents)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment