# Generated by Django 6.0.4 on 2026-06-23 02:43

import apps.finance.models
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('companies', '0002_initial'),
        ('events', '0006_eventregistration_is_vip'),
        ('finance', '0003_currency'),
        ('projects', '0012_projectfinance_budget_category'),
    ]

    operations = [
        migrations.CreateModel(
            name='Invoice',
            fields=[
                ('id', models.UUIDField(default=apps.finance.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('invoice_number', models.CharField(blank=True, max_length=50, unique=True)),
                ('currency', models.CharField(default='IDR', max_length=10)),
                ('subtotal', models.DecimalField(decimal_places=2, default=0, help_text='Sum of line amounts. Computed.', max_digits=14)),
                ('tax', models.DecimalField(decimal_places=2, default=0, max_digits=12)),
                ('total', models.DecimalField(decimal_places=2, default=0, help_text='subtotal + tax. Computed.', max_digits=14)),
                ('issue_date', models.DateField(blank=True, null=True)),
                ('due_date', models.DateField(blank=True, null=True)),
                ('status', models.CharField(choices=[('draft', 'Draft'), ('issued', 'Issued'), ('sent', 'Sent'), ('paid', 'Paid'), ('overdue', 'Overdue'), ('cancelled', 'Cancelled')], default='draft', max_length=20)),
                ('paid_at', models.DateTimeField(blank=True, null=True)),
                ('notes', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('donor', models.ForeignKey(help_text='The billed party (donor / sponsor).', on_delete=django.db.models.deletion.PROTECT, related_name='receivable_invoices', to='companies.company')),
                ('event', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='receivable_invoices', to='events.event')),
                ('project', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='receivable_invoices', to='projects.project')),
            ],
            options={
                'db_table': 'finance_invoices',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='InvoiceLine',
            fields=[
                ('id', models.UUIDField(default=apps.finance.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('description', models.CharField(max_length=255)),
                ('quantity', models.DecimalField(decimal_places=2, default=1, max_digits=12)),
                ('unit_price', models.DecimalField(decimal_places=2, default=0, max_digits=14)),
                ('amount', models.DecimalField(decimal_places=2, default=0, help_text='quantity × unit_price. Computed.', max_digits=14)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('invoice', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lines', to='finance.invoice')),
            ],
            options={
                'db_table': 'finance_invoice_lines',
                'ordering': ['created_at'],
            },
        ),
        migrations.AddIndex(
            model_name='invoice',
            index=models.Index(fields=['status'], name='finance_inv_status_7c9653_idx'),
        ),
        migrations.AddIndex(
            model_name='invoice',
            index=models.Index(fields=['donor'], name='finance_inv_donor_i_8bf342_idx'),
        ),
        migrations.AddIndex(
            model_name='invoice',
            index=models.Index(fields=['project'], name='finance_inv_project_7d687d_idx'),
        ),
    ]
