# Generated by Django 6.0 on 2025-12-08 16:43

import django.core.validators
import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('orders', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Budget',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=200)),
                ('description', models.TextField(blank=True)),
                ('fiscal_year', models.IntegerField()),
                ('period_start', models.DateField()),
                ('period_end', models.DateField()),
                ('revenue_budget', models.DecimalField(decimal_places=2, max_digits=15)),
                ('expense_budget', models.DecimalField(decimal_places=2, max_digits=15)),
                ('profit_target', models.DecimalField(decimal_places=2, max_digits=15)),
                ('actual_revenue', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('actual_expenses', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('actual_profit', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'ordering': ['-fiscal_year'],
            },
        ),
        migrations.CreateModel(
            name='Invoice',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('invoice_number', models.CharField(max_length=50, unique=True)),
                ('client_name', models.CharField(max_length=200)),
                ('client_email', models.EmailField(max_length=254)),
                ('client_address', models.TextField(blank=True)),
                ('subtotal', models.DecimalField(decimal_places=2, max_digits=15)),
                ('tax_rate', models.DecimalField(decimal_places=2, default=0, max_digits=5)),
                ('tax_amount', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('total', models.DecimalField(decimal_places=2, max_digits=15)),
                ('status', models.CharField(choices=[('DRAFT', 'Draft'), ('SENT', 'Sent'), ('PAID', 'Paid'), ('OVERDUE', 'Overdue'), ('CANCELLED', 'Cancelled')], default='DRAFT', max_length=20)),
                ('invoice_date', models.DateField()),
                ('due_date', models.DateField()),
                ('paid_date', models.DateField(blank=True, null=True)),
                ('notes', models.TextField(blank=True)),
                ('terms', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'ordering': ['-invoice_date'],
            },
        ),
        migrations.CreateModel(
            name='TaxRecord',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('tax_type', models.CharField(choices=[('SALES_TAX', 'Sales Tax'), ('VAT', 'VAT'), ('INCOME_TAX', 'Income Tax'), ('PAYROLL_TAX', 'Payroll Tax')], max_length=20)),
                ('description', models.CharField(max_length=300)),
                ('tax_rate', models.DecimalField(decimal_places=2, max_digits=5)),
                ('taxable_amount', models.DecimalField(decimal_places=2, max_digits=15)),
                ('tax_amount', models.DecimalField(decimal_places=2, max_digits=15)),
                ('period_start', models.DateField()),
                ('period_end', models.DateField()),
                ('is_paid', models.BooleanField(default=False)),
                ('paid_date', models.DateField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'ordering': ['-period_end'],
            },
        ),
        migrations.CreateModel(
            name='Transaction',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('transaction_number', models.CharField(max_length=50, unique=True)),
                ('transaction_type', models.CharField(choices=[('SALE', 'Sale Revenue'), ('EXPENSE', 'Expense'), ('PAYMENT', 'Payment'), ('REFUND', 'Refund'), ('COMMISSION', 'Commission'), ('SUBSCRIPTION', 'Subscription'), ('PAYOUT', 'Vendor Payout'), ('TAX', 'Tax'), ('TRANSFER', 'Transfer')], max_length=20)),
                ('description', models.TextField()),
                ('amount', models.DecimalField(decimal_places=2, max_digits=15, validators=[django.core.validators.MinValueValidator(0)])),
                ('transaction_date', models.DateTimeField(default=django.utils.timezone.now)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'ordering': ['-transaction_date'],
            },
        ),
        migrations.CreateModel(
            name='Expense',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('expense_number', models.CharField(max_length=50, unique=True)),
                ('category', models.CharField(choices=[('COGS', 'Cost of Goods Sold'), ('SHIPPING', 'Shipping & Delivery'), ('MARKETING', 'Marketing & Advertising'), ('HOSTING', 'Server & Hosting'), ('SOFTWARE', 'Software & Tools'), ('PAYROLL', 'Salaries & Wages'), ('RENT', 'Rent & Utilities'), ('INSURANCE', 'Insurance'), ('TAXES', 'Taxes'), ('BANK_FEES', 'Bank & Payment Fees'), ('REFUND', 'Refunds'), ('OTHER', 'Other Expenses')], max_length=30)),
                ('description', models.TextField()),
                ('amount', models.DecimalField(decimal_places=2, max_digits=15, validators=[django.core.validators.MinValueValidator(0)])),
                ('tax_amount', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('vendor_name', models.CharField(blank=True, max_length=200)),
                ('invoice_number', models.CharField(blank=True, max_length=100)),
                ('receipt', models.FileField(blank=True, upload_to='expenses/receipts/')),
                ('payment_method', models.CharField(blank=True, max_length=50)),
                ('payment_status', models.CharField(choices=[('PENDING', 'Pending'), ('PAID', 'Paid'), ('OVERDUE', 'Overdue')], default='PENDING', max_length=20)),
                ('expense_date', models.DateField(db_index=True)),
                ('due_date', models.DateField(blank=True, null=True)),
                ('paid_date', models.DateField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-expense_date'],
            },
        ),
        migrations.CreateModel(
            name='FinancialAccount',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(max_length=20, unique=True)),
                ('name', models.CharField(max_length=200)),
                ('account_type', models.CharField(choices=[('ASSET', 'Asset'), ('LIABILITY', 'Liability'), ('EQUITY', 'Equity'), ('REVENUE', 'Revenue'), ('EXPENSE', 'Expense')], max_length=20)),
                ('description', models.TextField(blank=True)),
                ('current_balance', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('parent_account', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='sub_accounts', to='payments.financialaccount')),
            ],
            options={
                'ordering': ['code'],
            },
        ),
        migrations.CreateModel(
            name='FinancialReport',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('report_type', models.CharField(choices=[('INCOME_STATEMENT', 'Income Statement (P&L)'), ('BALANCE_SHEET', 'Balance Sheet'), ('CASH_FLOW', 'Cash Flow Statement'), ('TAX_REPORT', 'Tax Report'), ('VENDOR_PAYOUT', 'Vendor Payout Report')], max_length=30)),
                ('report_name', models.CharField(max_length=200)),
                ('period_start', models.DateField()),
                ('period_end', models.DateField()),
                ('total_revenue', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('total_expenses', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('net_profit', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('report_file', models.FileField(blank=True, upload_to='financial_reports/')),
                ('report_data', models.JSONField(blank=True, null=True)),
                ('generated_at', models.DateTimeField(auto_now_add=True)),
                ('generated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-generated_at'],
            },
        ),
        migrations.CreateModel(
            name='Revenue',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('revenue_type', models.CharField(choices=[('PRODUCT_SALE', 'Product Sales'), ('VENDOR_COMMISSION', 'Vendor Commission'), ('SUBSCRIPTION', 'Subscription Fees'), ('SHIPPING', 'Shipping Fees'), ('OTHER', 'Other Revenue')], max_length=30)),
                ('description', models.CharField(max_length=300)),
                ('gross_amount', models.DecimalField(decimal_places=2, max_digits=15)),
                ('discount', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('tax_amount', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('net_amount', models.DecimalField(decimal_places=2, max_digits=15)),
                ('revenue_date', models.DateField(db_index=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('order', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='orders.order')),
            ],
            options={
                'ordering': ['-revenue_date'],
            },
        ),
    ]
