# Generated by Django 6.0.4 on 2026-06-06 02:55

import apps.projects.models
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('companies', '0002_initial'),
        ('events', '0001_initial'),
        ('finance', '0001_initial'),
        ('hr', '0001_initial'),
        ('publications', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='ProjectSettings',
            fields=[
                ('id', models.UUIDField(default=apps.projects.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('access_level', models.CharField(choices=[('everyone', 'Everyone in the organization'), ('members', 'Project team members only'), ('admins', 'Administrators only')], default='members', max_length=20)),
                ('donor_pic_can_access', models.BooleanField(default=False)),
                ('proposal_template', models.TextField(blank=True)),
                ('report_template', models.TextField(blank=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'db_table': 'project_settings',
            },
        ),
        migrations.CreateModel(
            name='Project',
            fields=[
                ('id', models.UUIDField(default=apps.projects.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=255)),
                ('description', models.TextField(blank=True)),
                ('status', models.CharField(choices=[('planning', 'Planning'), ('active', 'Active'), ('on_hold', 'On Hold'), ('completed', 'Completed'), ('archived', 'Archived')], default='planning', max_length=20)),
                ('start_date', models.DateField(blank=True, null=True)),
                ('end_date', models.DateField(blank=True, null=True)),
                ('tags', models.JSONField(default=list)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('lead', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='led_projects', to='hr.employee')),
            ],
            options={
                'db_table': 'projects',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='ProjectDissemination',
            fields=[
                ('id', models.UUIDField(default=apps.projects.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('title', models.CharField(max_length=255)),
                ('description', models.TextField(blank=True)),
                ('date', models.DateField(blank=True, null=True)),
                ('location', models.CharField(blank=True, max_length=255)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('event', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='project_disseminations', to='events.event')),
                ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='disseminations', to='projects.project')),
                ('publication', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='project_disseminations', to='publications.publication')),
            ],
            options={
                'db_table': 'project_disseminations',
                'ordering': ['-date', '-created_at'],
            },
        ),
        migrations.CreateModel(
            name='ProjectDocument',
            fields=[
                ('id', models.UUIDField(default=apps.projects.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=255)),
                ('file', models.FileField(upload_to='project_documents/%Y/%m/')),
                ('access_level', models.CharField(choices=[('public', 'Public'), ('restricted', 'Restricted')], default='public', max_length=20)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('allowed_users', models.ManyToManyField(blank=True, related_name='accessible_project_documents', to=settings.AUTH_USER_MODEL)),
                ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='documents', to='projects.project')),
                ('uploaded_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'project_documents',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='ProjectFinance',
            fields=[
                ('id', models.UUIDField(default=apps.projects.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('description', models.CharField(max_length=255)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=14)),
                ('currency', models.CharField(default='IDR', max_length=10)),
                ('type', models.CharField(choices=[('income', 'Income'), ('expense', 'Expense')], default='expense', max_length=10)),
                ('ledger', models.CharField(choices=[('general', 'General Ledger'), ('project', 'Project Ledger'), ('event', 'Event Budget Ledger'), ('expense', 'Expense Ledger'), ('apar', 'AP/AR Ledger'), ('procurement', 'Procurement Ledger'), ('grant', 'Grant Ledger'), ('asset', 'Asset Ledger'), ('cashbank', 'Cash/Bank Ledger'), ('audit', 'Audit Ledger')], default='general', max_length=20)),
                ('category', models.CharField(blank=True, max_length=100)),
                ('date', models.DateField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('budget_item', models.ForeignKey(blank=True, help_text='Budget item (catalog code) this entry maps to.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='finance_entries', to='finance.budgetitem')),
                ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='finance_entries', to='projects.project')),
            ],
            options={
                'db_table': 'project_finance',
                'ordering': ['-date', '-created_at'],
            },
        ),
        migrations.CreateModel(
            name='ProjectFund',
            fields=[
                ('id', models.UUIDField(default=apps.projects.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('source', models.CharField(help_text='Donor / grantor / funding body name', max_length=255)),
                ('fund_type', models.CharField(choices=[('grant', 'Grant'), ('sponsorship', 'Sponsorship'), ('donation', 'Donation'), ('cofunding', 'Co-funding'), ('other', 'Other')], db_index=True, default='grant', help_text="Funding mechanism. 'grant' is the most common subset.", max_length=20)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=14)),
                ('currency', models.CharField(default='IDR', max_length=10)),
                ('exchange_rate', models.DecimalField(blank=True, decimal_places=6, help_text='IDR per 1 unit of currency, on received_date. 1 for IDR.', max_digits=18, null=True)),
                ('amount_idr', models.DecimalField(blank=True, decimal_places=2, help_text='amount converted to IDR at exchange_rate.', max_digits=20, null=True)),
                ('status', models.CharField(choices=[('proposed', 'Proposed'), ('pledged', 'Pledged'), ('received', 'Received'), ('allocated', 'Allocated'), ('closed', 'Closed'), ('rejected', 'Rejected')], default='pledged', max_length=20)),
                ('agreement_date', models.DateField(blank=True, null=True)),
                ('received_date', models.DateField(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(blank=True, help_text='Canonical donor record. Auto-linked by name when missing.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='funds_provided', to='companies.company')),
                ('project', models.ForeignKey(blank=True, help_text='Owning project. Null while the fund is still a prospect/proposal (fund-first flow).', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='funds', to='projects.project')),
            ],
            options={
                'db_table': 'project_funds',
                'ordering': ['-agreement_date', '-created_at'],
            },
        ),
        migrations.CreateModel(
            name='ProjectFundAllocation',
            fields=[
                ('id', models.UUIDField(default=apps.projects.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('amount', models.DecimalField(decimal_places=2, default=0, max_digits=14)),
                ('note', models.CharField(blank=True, max_length=255)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('budget_item', models.ForeignKey(help_text='Budget item this slice maps to.', on_delete=django.db.models.deletion.PROTECT, related_name='allocations', to='finance.budgetitem')),
                ('fund', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='allocations', to='projects.projectfund')),
            ],
            options={
                'db_table': 'project_fund_allocations',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='ProjectSchedule',
            fields=[
                ('id', models.UUIDField(default=apps.projects.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('title', models.CharField(max_length=255)),
                ('description', models.TextField(blank=True)),
                ('start_date', models.DateField(blank=True, null=True)),
                ('end_date', models.DateField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='schedule_items', to='projects.project')),
            ],
            options={
                'db_table': 'project_schedule',
                'ordering': ['start_date', '-created_at'],
            },
        ),
        migrations.CreateModel(
            name='ProjectTeamMember',
            fields=[
                ('id', models.UUIDField(default=apps.projects.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('role', models.CharField(choices=[('owner', 'Owner'), ('manager', 'Manager'), ('member', 'Member'), ('viewer', 'Viewer')], default='member', max_length=20)),
                ('joined_at', models.DateTimeField(auto_now_add=True)),
                ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='team_members', to='projects.project')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='project_memberships', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'project_team_members',
                'ordering': ['role', 'joined_at'],
            },
        ),
        migrations.AddIndex(
            model_name='project',
            index=models.Index(fields=['status'], name='projects_status_6303d7_idx'),
        ),
        migrations.AddIndex(
            model_name='project',
            index=models.Index(fields=['start_date'], name='projects_start_d_7e0135_idx'),
        ),
        migrations.AddIndex(
            model_name='project',
            index=models.Index(fields=['end_date'], name='projects_end_dat_a34feb_idx'),
        ),
        migrations.AddIndex(
            model_name='projectfinance',
            index=models.Index(fields=['type'], name='project_fin_type_fd6653_idx'),
        ),
        migrations.AddIndex(
            model_name='projectfinance',
            index=models.Index(fields=['ledger'], name='project_fin_ledger_a6579d_idx'),
        ),
        migrations.AddIndex(
            model_name='projectfinance',
            index=models.Index(fields=['date'], name='project_fin_date_5b873e_idx'),
        ),
        migrations.AddIndex(
            model_name='projectfinance',
            index=models.Index(fields=['project', 'type'], name='project_fin_project_97e9bb_idx'),
        ),
        migrations.AddIndex(
            model_name='projectfinance',
            index=models.Index(fields=['project', 'date'], name='project_fin_project_647eea_idx'),
        ),
        migrations.AddIndex(
            model_name='projectfundallocation',
            index=models.Index(fields=['fund'], name='project_fun_fund_id_fc22b8_idx'),
        ),
        migrations.AddConstraint(
            model_name='projectfundallocation',
            constraint=models.UniqueConstraint(fields=('fund', 'budget_item'), name='uniq_fund_budget_item'),
        ),
        migrations.AlterUniqueTogether(
            name='projectteammember',
            unique_together={('project', 'user')},
        ),
    ]
