# Generated by Django 6.0.4 on 2026-06-27 00:56

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('companies', '0002_initial'),
        ('projects', '0012_projectfinance_budget_category'),
    ]

    operations = [
        migrations.CreateModel(
            name='Account',
            fields=[
                ('id', models.UUIDField(default=apps.accounting.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('code', models.CharField(help_text='e.g. 1000, 4000.', max_length=20, unique=True)),
                ('name', models.CharField(max_length=200)),
                ('type', models.CharField(choices=[('Asset', 'Asset'), ('Liability', 'Liability'), ('Equity', 'Equity'), ('Income', 'Income'), ('Expense', 'Expense')], db_index=True, max_length=20)),
                ('normal_balance', models.CharField(choices=[('Debit', 'Debit'), ('Credit', 'Credit')], max_length=10)),
                ('notes', models.TextField(blank=True)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'verbose_name': 'account',
                'verbose_name_plural': 'chart of accounts',
                'db_table': 'accounting_accounts',
                'ordering': ['code'],
            },
        ),
        migrations.CreateModel(
            name='Fund',
            fields=[
                ('id', models.UUIDField(default=apps.accounting.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('fund_id', models.CharField(help_text='Business key, e.g. FND-001.', max_length=30, unique=True)),
                ('donor_name', models.CharField(blank=True, help_text='Free-text donor when not a Company.', max_length=200)),
                ('name', models.CharField(help_text='Grant / fund name.', max_length=255)),
                ('fund_type', models.CharField(choices=[('Restricted', 'Restricted'), ('Unrestricted', 'Unrestricted'), ('Designated', 'Designated')], default='Restricted', max_length=20)),
                ('project_code', models.CharField(blank=True, help_text='Free-text project tag, e.g. PRJ-HEALTH.', max_length=50)),
                ('start_date', models.DateField(blank=True, null=True)),
                ('end_date', models.DateField(blank=True, null=True)),
                ('award_amount', models.DecimalField(decimal_places=2, default=0, help_text='Total awarded (IDR).', max_digits=18)),
                ('received_amount', models.DecimalField(decimal_places=2, default=0, help_text='Received to date (IDR).', max_digits=18)),
                ('currency', models.CharField(default='IDR', max_length=10)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('donor', models.ForeignKey(blank=True, help_text='Donor company (optional).', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='accounting_funds', to='companies.company')),
                ('project', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='accounting_funds', to='projects.project')),
            ],
            options={
                'db_table': 'accounting_funds',
                'ordering': ['fund_id'],
            },
        ),
        migrations.CreateModel(
            name='JournalEntry',
            fields=[
                ('id', models.UUIDField(default=apps.accounting.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('journal_no', models.CharField(help_text='e.g. JV-001.', max_length=30, unique=True)),
                ('date', models.DateField()),
                ('reference', models.CharField(blank=True, help_text='Source ref, e.g. TRX-001.', max_length=50)),
                ('description', models.CharField(blank=True, max_length=255)),
                ('donor_name', models.CharField(blank=True, max_length=200)),
                ('project_code', models.CharField(blank=True, max_length=50)),
                ('activity', models.CharField(blank=True, max_length=200)),
                ('budget_line', models.CharField(blank=True, max_length=100)),
                ('status', models.CharField(choices=[('Draft', 'Draft'), ('Posted', 'Posted'), ('Rejected', 'Rejected')], db_index=True, default='Draft', max_length=20)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('fund', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='journal_entries', to='accounting.fund')),
            ],
            options={
                'verbose_name_plural': 'journal entries',
                'db_table': 'accounting_journal_entries',
                'ordering': ['journal_no'],
            },
        ),
        migrations.CreateModel(
            name='JournalLine',
            fields=[
                ('id', models.UUIDField(default=apps.accounting.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('description', models.CharField(blank=True, max_length=255)),
                ('debit_idr', models.DecimalField(decimal_places=2, default=0, max_digits=18)),
                ('credit_idr', models.DecimalField(decimal_places=2, default=0, max_digits=18)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('account', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='journal_lines', to='accounting.account')),
                ('journal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lines', to='accounting.journalentry')),
            ],
            options={
                'db_table': 'accounting_journal_lines',
                'ordering': ['created_at'],
            },
        ),
        migrations.CreateModel(
            name='Transaction',
            fields=[
                ('id', models.UUIDField(default=apps.accounting.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('transaction_id', models.CharField(help_text='Business key, e.g. TRX-001.', max_length=30, unique=True)),
                ('date', models.DateField()),
                ('description', models.CharField(blank=True, max_length=255)),
                ('transaction_type', models.CharField(choices=[('Grant Receipt', 'Grant Receipt'), ('Expense', 'Expense'), ('Advance', 'Advance'), ('Advance Settlement', 'Advance Settlement'), ('Allocation', 'Allocation')], db_index=True, max_length=30)),
                ('donor_name', models.CharField(blank=True, max_length=200)),
                ('project_code', models.CharField(blank=True, max_length=50)),
                ('activity', models.CharField(blank=True, max_length=200)),
                ('budget_line', models.CharField(blank=True, max_length=100)),
                ('counterparty', models.CharField(blank=True, max_length=200)),
                ('currency', models.CharField(default='IDR', max_length=10)),
                ('original_amount', models.DecimalField(decimal_places=2, default=0, max_digits=18)),
                ('exchange_rate', models.DecimalField(decimal_places=4, default=1, max_digits=14)),
                ('debit_idr', models.DecimalField(decimal_places=2, default=0, max_digits=18)),
                ('credit_idr', models.DecimalField(decimal_places=2, default=0, max_digits=18)),
                ('net_expense_idr', models.DecimalField(decimal_places=2, default=0, help_text='Computed.', max_digits=18)),
                ('status', models.CharField(choices=[('Draft', 'Draft'), ('Pending Approval', 'Pending Approval'), ('Posted', 'Posted'), ('Rejected', 'Rejected')], db_index=True, default='Draft', max_length=20)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('account', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='transactions', to='accounting.account')),
                ('fund', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='transactions', to='accounting.fund')),
            ],
            options={
                'db_table': 'accounting_transactions',
                'ordering': ['-date', '-created_at'],
            },
        ),
        migrations.AddIndex(
            model_name='journalentry',
            index=models.Index(fields=['status'], name='accounting__status_037e0d_idx'),
        ),
        migrations.AddIndex(
            model_name='journalentry',
            index=models.Index(fields=['date'], name='accounting__date_0a42cd_idx'),
        ),
        migrations.AddIndex(
            model_name='journalline',
            index=models.Index(fields=['journal'], name='accounting__journal_11d6f1_idx'),
        ),
        migrations.AddIndex(
            model_name='journalline',
            index=models.Index(fields=['account'], name='accounting__account_1110ac_idx'),
        ),
        migrations.AddIndex(
            model_name='transaction',
            index=models.Index(fields=['transaction_type'], name='accounting__transac_92ea39_idx'),
        ),
        migrations.AddIndex(
            model_name='transaction',
            index=models.Index(fields=['status'], name='accounting__status_2e6e52_idx'),
        ),
        migrations.AddIndex(
            model_name='transaction',
            index=models.Index(fields=['fund'], name='accounting__fund_id_e8925e_idx'),
        ),
    ]
