from faker import Faker
import random
import csv
from datetime import datetime, timedelta, date

# Create a Faker instance
fake = Faker()

# Define the number of transactions for each month
transactions_per_month = [
    65, 60, 45, 30, 55, 85, 58, 40, 80, 65, 40, 75,  # Year 1
    65, 50, 75, 60, 45, 60, 50, 57, 60, 60, 65, 80   # Year 2
]

# Create a list to store transactions
transactions = []

# Define possible transaction types
transaction_types = [
    "Sales Transaction",
    "Purchase Transaction",
    "Expense Transaction",
    "Asset Transaction",
    "Liability Transaction",
    "Equity Transaction",
    "Adjusting Journal Entry",
    "Revenue Recognition",
    "Depreciation and Amortization",
    "Cash Transaction",
    "Non-Cash Transaction",
    "Reversing Entry",
]

# Generate transactions
for year in range(2021, 2023):
    for month, num_transactions in enumerate(transactions_per_month, start=1):
        for _ in range(num_transactions):
            transaction_type = random.choice(transaction_types)
            if transaction_type == "Sales Transaction":
                amount = round(random.uniform(1000, 10000), 2)
            elif transaction_type == "Purchase Transaction":
                amount = round(random.uniform(500, 5000), 2)
            elif transaction_type == "Expense Transaction":
                amount = round(random.uniform(100, 2000), 2)
            elif transaction_type == "Asset Transaction":
                amount = round(random.uniform(1000, 10000), 2)
            elif transaction_type == "Liability Transaction":
                amount = round(random.uniform(500, 5000), 2)
            elif transaction_type == "Equity Transaction":
                amount = round(random.uniform(1000, 5000), 2)
            elif transaction_type == "Adjusting Journal Entry":
                amount = round(random.uniform(50, 500), 2)
            elif transaction_type == "Revenue Recognition":
                amount = round(random.uniform(1000, 10000), 2)
            elif transaction_type == "Depreciation and Amortization":
                amount = round(random.uniform(100, 2000), 2)
            elif transaction_type == "Cash Transaction":
                amount = round(random.uniform(100, 5000), 2)
            elif transaction_type == "Non-Cash Transaction":
                amount = round(random.uniform(1000, 10000), 2)
            else:
                amount = round(random.uniform(50, 500), 2)
  

            transaction = {
                "Year": year,
                "Month": month,                
                "Date": fake.date_between(start_date=datetime.date(f'{year}-{month}-1'), end_date=datetime.date(f'{year}-{month}-28')),
                "Type": transaction_type,
                "Description": fake.catch_phrase(),
                "Amount": amount,
                "Account": fake.bs(),
                "Recipient/Payer": fake.company(),
            }
            transactions.append(transaction)

# Write the transactions to a CSV file
with open("accounting_transactions.csv", "w", newline="") as csvfile:
    fieldnames = ["Year", "Month", "Date", "Type", "Description", "Amount", "Account", "Recipient/Payer"]
    writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
    writer.writeheader()
    writer.writerows(transactions)

print("Accounting transactions data generated and saved to 'accounting_transactions.csv'")
