# Generated by Django 5.2.19 on 2026-11-29 17:12

import django.core.serializers.json
import django.db.models.deletion
import uuid
from decimal import Decimal
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('accounting', '0007_accountingpolicy_auto_create_open_items_and_more'),
        ('banking', '0001_initial'),
        ('document_engine', '0001_initial'),
        ('inventory', '0002_initial'),
        ('procurement', '0001_initial'),
        ('projects', '0001_initial'),
        ('tenancy', '0002_company_multi_currency_enabled'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='CustomerProfile',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('customer_category', models.CharField(choices=[('GOVERNMENT', 'Government / Public Authority'), ('PRIVATE', 'Private Developer / Client'), ('CORPORATE', 'Corporate & Industrial'), ('INDIVIDUAL', 'Individual Client')], default='PRIVATE', max_length=20)),
                ('registration_no', models.CharField(blank=True, max_length=64)),
                ('tax_classification', models.CharField(choices=[('VAT_REGISTERED', 'VAT Registered (13%)'), ('PAN_ONLY', 'PAN Only (Non-VAT)'), ('TAX_EXEMPT', 'Tax Exempt / Diplomatic'), ('EXPORT', 'Zero-Rated / Export')], default='VAT_REGISTERED', max_length=20)),
                ('pan_vat_no', models.CharField(blank=True, db_index=True, max_length=20)),
                ('contract_number', models.CharField(blank=True, max_length=64)),
                ('agreement_date', models.DateField(blank=True, null=True)),
                ('contract_value', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('credit_days', models.PositiveSmallIntegerField(default=30)),
                ('credit_hold', models.BooleanField(default=False)),
                ('is_blacklisted', models.BooleanField(default=False)),
                ('blacklist_reason', models.CharField(blank=True, max_length=255)),
                ('bank_name', models.CharField(blank=True, max_length=120)),
                ('bank_account_no', models.CharField(blank=True, max_length=48)),
                ('approval_status', models.CharField(choices=[('PENDING', 'Pending Approval'), ('APPROVED', 'Approved'), ('SUSPENDED', 'Suspended'), ('BLACKLISTED', 'Blacklisted')], db_index=True, default='APPROVED', max_length=16)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='approved_customers', to=settings.AUTH_USER_MODEL)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='customer_profiles', to='tenancy.company')),
                ('party', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name='customer_profile', to='accounting.party')),
            ],
            options={
                'db_table': 'customer_profiles',
                'ordering': ['party__name'],
            },
        ),
        migrations.CreateModel(
            name='CustomerDocument',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('doc_type', models.CharField(max_length=64)),
                ('doc_number', models.CharField(blank=True, max_length=64)),
                ('file_ref', models.CharField(blank=True, max_length=255)),
                ('issue_date', models.DateField(blank=True, null=True)),
                ('expiry_date', models.DateField(blank=True, null=True)),
                ('customer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='documents', to='party_hub.customerprofile')),
            ],
            options={
                'db_table': 'customer_documents',
            },
        ),
        migrations.CreateModel(
            name='CustomerContact',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=120)),
                ('designation', models.CharField(blank=True, max_length=80)),
                ('phone', models.CharField(blank=True, max_length=40)),
                ('email', models.EmailField(blank=True, max_length=254)),
                ('is_primary', models.BooleanField(default=False)),
                ('customer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='contacts', to='party_hub.customerprofile')),
            ],
            options={
                'db_table': 'customer_contacts',
            },
        ),
        migrations.CreateModel(
            name='CustomerAddress',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('label', models.CharField(default='Head Office / Billing', max_length=80)),
                ('address_line', models.CharField(max_length=255)),
                ('city', models.CharField(blank=True, max_length=80)),
                ('is_billing', models.BooleanField(default=True)),
                ('is_site', models.BooleanField(default=False)),
                ('customer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='addresses', to='party_hub.customerprofile')),
            ],
            options={
                'db_table': 'customer_addresses',
            },
        ),
        migrations.CreateModel(
            name='OpenItem',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('hub_side', models.CharField(choices=[('RECEIVABLE', 'Receivable (Debtor)'), ('PAYABLE', 'Payable (Creditor)')], db_index=True, max_length=16)),
                ('doc_kind', models.CharField(choices=[('SALES_INVOICE', 'Sales / Tax Invoice'), ('PROFORMA_INVOICE', 'Proforma Invoice'), ('CLIENT_RA_BILL', 'Client RA / Progress Bill'), ('FINAL_BILL', 'Final Contract Bill'), ('VARIATION_CLAIM', 'Variation / Escalation Claim'), ('PURCHASE_INVOICE', 'Supplier Purchase Invoice'), ('SUBCONTRACTOR_BILL', 'Subcontractor RA Bill'), ('CREDIT_NOTE', 'Credit Note'), ('DEBIT_NOTE', 'Debit Note'), ('RECEIPT', 'Customer Receipt (Unallocated Cash)'), ('PAYMENT', 'Supplier Payment (Unallocated Cash)'), ('ADJUSTMENT', 'Authorized Control Adjustment')], db_index=True, max_length=24)),
                ('is_unallocated_credit', models.BooleanField(default=False, help_text='True for Receipts, Payments, and Notes carrying unallocated credit awaiting explicit bill allocation.')),
                ('is_certified', models.BooleanField(default=True)),
                ('document_no', models.CharField(db_index=True, max_length=64)),
                ('contract_ref', models.CharField(blank=True, max_length=64)),
                ('document_date', models.DateField(db_index=True)),
                ('bs_date', models.CharField(blank=True, max_length=16)),
                ('due_date', models.DateField(db_index=True)),
                ('currency', models.CharField(default='NPR', max_length=3)),
                ('exchange_rate', models.DecimalField(decimal_places=6, default=Decimal('1.000000'), max_digits=14)),
                ('gross_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('tax_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('tds_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('retention_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('advance_recovered', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('other_deductions', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('original_amount', models.DecimalField(decimal_places=2, max_digits=18)),
                ('allocated_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('written_off_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('status', models.CharField(choices=[('OPEN', 'Open'), ('PARTIAL', 'Partially Settled'), ('SETTLED', 'Fully Settled'), ('DISPUTED', 'Disputed / Held'), ('WRITTEN_OFF', 'Written Off'), ('REVERSED', 'Reversed')], db_index=True, default='OPEN', max_length=16)),
                ('expected_settlement_date', models.DateField(blank=True, null=True)),
                ('notes', models.CharField(blank=True, max_length=255)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('collection_owner', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='assigned_open_items', to=settings.AUTH_USER_MODEL)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='open_items', to='tenancy.company')),
                ('control_account', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='open_items', to='accounting.account')),
                ('grn', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='open_items', to='inventory.goodsreceiptnote')),
                ('party', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='open_items', to='accounting.party')),
                ('project', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='open_items', to='projects.project')),
                ('purchase_order', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='open_items', to='procurement.purchaseorder')),
                ('voucher', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='open_items', to='accounting.voucher')),
            ],
            options={
                'db_table': 'open_items',
                'ordering': ['due_date', 'document_date', 'document_no'],
                'unique_together': {('voucher', 'party', 'control_account', 'is_unallocated_credit')},
            },
        ),
        migrations.CreateModel(
            name='CollectionActivity',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('activity_type', models.CharField(choices=[('CALL', 'Phone Follow-up'), ('EMAIL', 'Email / Statement Sent'), ('SITE_VISIT', 'Client / Engineer Meeting'), ('DEMAND_NOTICE', 'Formal Overdue Notice'), ('ESCALATION', 'Management Escalation')], default='CALL', max_length=20)),
                ('contacted_at', models.DateField()),
                ('bs_contacted_at', models.CharField(blank=True, max_length=16)),
                ('promised_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('promised_date', models.DateField(blank=True, null=True)),
                ('next_followup_date', models.DateField(blank=True, null=True)),
                ('outcome', models.CharField(max_length=255)),
                ('notes', models.TextField(blank=True)),
                ('status', models.CharField(choices=[('OPEN', 'Follow-up Open'), ('PROMISED', 'Payment Promised'), ('COMPLETED', 'Collected / Closed'), ('ESCALATED', 'Escalated')], db_index=True, default='OPEN', max_length=16)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('assigned_to', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='assigned_collections', to=settings.AUTH_USER_MODEL)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='collection_activities', to='tenancy.company')),
                ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='logged_collections', to=settings.AUTH_USER_MODEL)),
                ('party', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='collection_activities', to='accounting.party')),
                ('open_item', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='collection_activities', to='party_hub.openitem')),
            ],
            options={
                'db_table': 'collection_activities',
                'ordering': ['-contacted_at', '-created_at'],
            },
        ),
        migrations.CreateModel(
            name='PartyGroup',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('hub_scope', models.CharField(choices=[('DEBTOR', 'Sundry Debtor / Customer Group'), ('CREDITOR', 'Sundry Creditor / Supplier Group')], db_index=True, max_length=16)),
                ('code', models.CharField(max_length=32)),
                ('name', models.CharField(max_length=160)),
                ('default_payment_terms_days', models.PositiveSmallIntegerField(default=30)),
                ('description', models.CharField(blank=True, max_length=255)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='party_groups', to='tenancy.company')),
                ('default_control_account', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='party_group_controls', to='accounting.account')),
            ],
            options={
                'db_table': 'party_groups',
                'ordering': ['hub_scope', 'code'],
                'unique_together': {('company', 'hub_scope', 'code')},
            },
        ),
        migrations.AddField(
            model_name='customerprofile',
            name='group',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='customers', to='party_hub.partygroup'),
        ),
        migrations.CreateModel(
            name='PartyReconciliationRun',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('run_no', models.CharField(max_length=40)),
                ('as_of_date', models.DateField()),
                ('is_reconciled', models.BooleanField(default=True)),
                ('summary_payload', models.JSONField(default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder)),
                ('exception_count', models.PositiveIntegerField(default=0)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='party_reconciliations', to='tenancy.company')),
                ('run_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'party_reconciliations',
                'ordering': ['-created_at'],
                'unique_together': {('company', 'run_no')},
            },
        ),
        migrations.CreateModel(
            name='PartyReconciliationException',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('control_role', models.CharField(max_length=32)),
                ('account_code', models.CharField(blank=True, max_length=32)),
                ('gl_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('subledger_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('variance_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('severity', models.CharField(choices=[('CRITICAL', 'GL vs Subledger Variance'), ('WARNING', 'Open-Item / Allocation Warning')], default='CRITICAL', max_length=16)),
                ('description', models.CharField(max_length=255)),
                ('is_resolved', models.BooleanField(default=False)),
                ('party', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='accounting.party')),
                ('reconciliation_run', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='exceptions', to='party_hub.partyreconciliationrun')),
            ],
            options={
                'db_table': 'party_reconciliation_exceptions',
            },
        ),
        migrations.CreateModel(
            name='PaymentProposal',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('proposal_no', models.CharField(max_length=40)),
                ('proposal_date', models.DateField()),
                ('bs_date', models.CharField(blank=True, max_length=16)),
                ('available_bank_balance', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('total_proposed', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('status', models.CharField(choices=[('DRAFT', 'Draft Schedule'), ('SUBMITTED', 'Submitted for Approval'), ('APPROVED', 'Approved by Finance Authority'), ('EXECUTED', 'Payment Voucher(s) Executed'), ('REJECTED', 'Rejected')], db_index=True, default='DRAFT', max_length=16)),
                ('notes', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='approved_payment_proposals', to=settings.AUTH_USER_MODEL)),
                ('bank_account', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='payment_proposals', to='banking.bankaccount')),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payment_proposals', to='tenancy.company')),
                ('executed_voucher', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='executed_proposals', to='accounting.voucher')),
                ('prepared_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='prepared_payment_proposals', to=settings.AUTH_USER_MODEL)),
                ('project', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='projects.project')),
            ],
            options={
                'db_table': 'payment_proposals',
                'ordering': ['-proposal_date', '-created_at'],
                'unique_together': {('company', 'proposal_no')},
            },
        ),
        migrations.CreateModel(
            name='PaymentProposalLine',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('priority', models.CharField(choices=[('URGENT', 'Urgent / Critical Site'), ('HIGH', 'High Priority'), ('NORMAL', 'Normal Due')], default='NORMAL', max_length=12)),
                ('proposed_amount', models.DecimalField(decimal_places=2, max_digits=18)),
                ('discount_captured', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('tds_applicable', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('remarks', models.CharField(blank=True, max_length=255)),
                ('open_item', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='proposal_lines', to='party_hub.openitem')),
                ('party', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='accounting.party')),
                ('proposal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lines', to='party_hub.paymentproposal')),
            ],
            options={
                'db_table': 'payment_proposal_lines',
            },
        ),
        migrations.CreateModel(
            name='RetentionSchedule',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('direction', models.CharField(choices=[('RECEIVABLE', 'Retention Receivable (From Client)'), ('PAYABLE', 'Retention Payable (To Subcontractor/Supplier)')], db_index=True, max_length=16)),
                ('contract_ref', models.CharField(blank=True, max_length=64)),
                ('certificate_no', models.CharField(blank=True, max_length=64)),
                ('retention_pct', models.DecimalField(decimal_places=2, default=Decimal('5.00'), max_digits=5)),
                ('retention_amount', models.DecimalField(decimal_places=2, max_digits=18)),
                ('released_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('hold_date', models.DateField()),
                ('bs_hold_date', models.CharField(blank=True, max_length=16)),
                ('release_milestone', models.CharField(default='Completion & Defect Liability Expiry', max_length=160)),
                ('defect_liability_end_date', models.DateField(blank=True, null=True)),
                ('release_due_date', models.DateField(blank=True, null=True)),
                ('is_disputed', models.BooleanField(default=False)),
                ('status', models.CharField(choices=[('HELD', 'Held / Pending Release'), ('PARTIAL', 'Partially Released'), ('RELEASED', 'Fully Released'), ('DISPUTED', 'Disputed / Defect Claim')], db_index=True, default='HELD', max_length=16)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='retention_schedules', to='tenancy.company')),
                ('party', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='retention_schedules', to='accounting.party')),
                ('project', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.project')),
                ('source_voucher', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='retention_schedules', to='accounting.voucher')),
            ],
            options={
                'db_table': 'retention_schedules',
                'ordering': ['release_due_date', 'hold_date'],
                'unique_together': {('source_voucher', 'party', 'direction')},
            },
        ),
        migrations.CreateModel(
            name='RetentionReleaseLog',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('released_amount', models.DecimalField(decimal_places=2, max_digits=18)),
                ('release_date', models.DateField()),
                ('remarks', models.CharField(blank=True, max_length=255)),
                ('released_at', models.DateTimeField(auto_now_add=True)),
                ('release_voucher', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='accounting.voucher')),
                ('released_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
                ('retention', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='releases', to='party_hub.retentionschedule')),
            ],
            options={
                'db_table': 'retention_release_logs',
            },
        ),
        migrations.CreateModel(
            name='PartyControlMap',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('hub_side', models.CharField(choices=[('RECEIVABLE', 'Sundry Debtors (AR) Control'), ('PAYABLE', 'Sundry Creditors (AP) Control')], db_index=True, max_length=16)),
                ('party_type', models.CharField(max_length=20)),
                ('is_default', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('advance_account', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='hub_advance_mappings', to='accounting.account')),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='party_control_maps', to='tenancy.company')),
                ('control_account', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='hub_control_mappings', to='accounting.account')),
                ('retention_account', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='hub_retention_mappings', to='accounting.account')),
                ('writeoff_account', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='hub_writeoff_mappings', to='accounting.account')),
                ('party_group', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='party_hub.partygroup')),
            ],
            options={
                'db_table': 'party_control_maps',
                'unique_together': {('company', 'hub_side', 'party_type', 'party_group')},
            },
        ),
        migrations.CreateModel(
            name='PartyStatement',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('statement_no', models.CharField(max_length=48)),
                ('statement_type', models.CharField(choices=[('CUSTOMER_STATEMENT', 'Customer Account Statement'), ('SUPPLIER_STATEMENT', 'Supplier Account Statement'), ('CONFIRMATION_REQUEST', 'Balance Confirmation Statement')], db_index=True, max_length=28)),
                ('from_date', models.DateField()),
                ('to_date', models.DateField()),
                ('opening_balance', models.DecimalField(decimal_places=2, max_digits=18)),
                ('closing_balance', models.DecimalField(decimal_places=2, max_digits=18)),
                ('overdue_balance', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('retention_balance', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('advance_balance', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('confirmation_status', models.CharField(choices=[('GENERATED', 'Generated'), ('SENT', 'Sent to Party'), ('CONFIRMED', 'Confirmed Agreed'), ('DISPUTED', 'Exception / Disputed')], db_index=True, default='GENERATED', max_length=16)),
                ('confirmed_by_name', models.CharField(blank=True, max_length=120)),
                ('confirmation_notes', models.TextField(blank=True)),
                ('confirmed_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='party_statements', to='tenancy.company')),
                ('document_record', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='document_engine.documentrecord')),
                ('generated_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
                ('party', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='statements', to='accounting.party')),
            ],
            options={
                'db_table': 'party_statements',
                'ordering': ['-created_at'],
                'unique_together': {('company', 'statement_no')},
            },
        ),
        migrations.CreateModel(
            name='PartyDispute',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('hub_side', models.CharField(choices=[('RECEIVABLE', 'Debtor / Client Dispute'), ('PAYABLE', 'Creditor / Vendor Dispute')], db_index=True, max_length=16)),
                ('dispute_no', models.CharField(max_length=40)),
                ('dispute_type', models.CharField(choices=[('QUALITY', 'Material / Work Quality'), ('QUANTITY_VARIATION', 'Measurement / BOQ Variance'), ('RATE_MISMATCH', 'Contract Rate Mismatch'), ('TAX_DEDUCTION', 'VAT / TDS Discrepancy'), ('DOCUMENTATION', 'Missing Certification / Challan'), ('RETENTION', 'Defect Liability / Retention')], default='DOCUMENTATION', max_length=24)),
                ('disputed_amount', models.DecimalField(decimal_places=2, max_digits=18)),
                ('claim_ref', models.CharField(blank=True, max_length=64)),
                ('description', models.TextField()),
                ('status', models.CharField(choices=[('OPEN', 'Open Dispute'), ('UNDER_REVIEW', 'Under Review'), ('RESOLVED', 'Resolved'), ('ESCALATED', 'Escalated')], db_index=True, default='OPEN', max_length=16)),
                ('resolved_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('resolution_notes', models.TextField(blank=True)),
                ('raised_at', models.DateTimeField(auto_now_add=True)),
                ('resolved_at', models.DateTimeField(blank=True, null=True)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='party_disputes', to='tenancy.company')),
                ('open_item', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='disputes', to='party_hub.openitem')),
                ('party', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='disputes', to='accounting.party')),
                ('raised_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='raised_disputes', to=settings.AUTH_USER_MODEL)),
                ('resolved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='resolved_disputes', to=settings.AUTH_USER_MODEL)),
                ('retention', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='disputes', to='party_hub.retentionschedule')),
            ],
            options={
                'db_table': 'party_disputes',
                'ordering': ['-raised_at'],
                'unique_together': {('company', 'dispute_no')},
            },
        ),
    ]
