# Generated by Django 4.2.30 on 2026-11-20 09:18

from decimal import Decimal
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ('NexusApp', '0003_checkout_edit_requests_row_order'),
    ]

    operations = [
        migrations.CreateModel(
            name='ChitGroup',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=150)),
                ('chit_value', models.DecimalField(decimal_places=2, max_digits=14)),
                ('total_members', models.PositiveIntegerField()),
                ('total_months', models.PositiveIntegerField()),
                ('monthly_amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('start_month', models.DateField(help_text='First month of the chit (day is ignored)')),
                ('due_day', models.PositiveIntegerField(default=5)),
                ('commission_percent', models.DecimalField(decimal_places=2, default=Decimal('5'), max_digits=5)),
                ('auction_type', models.CharField(choices=[('auction', 'Auction'), ('lottery', 'Lottery / Draw'), ('fixed', 'Fixed order')], default='auction', max_length=10)),
                ('status', models.CharField(choices=[('active', 'Active'), ('closed', 'Closed')], db_index=True, default='active', max_length=10)),
                ('notes', models.TextField(blank=True, default='')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('place', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='chits', to='NexusApp.place')),
            ],
            options={
                'db_table': 'chit_groups',
                'ordering': ['-id'],
            },
        ),
        migrations.CreateModel(
            name='ChitMember',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('ticket_no', models.PositiveIntegerField()),
                ('name', models.CharField(max_length=150)),
                ('phone', models.CharField(max_length=15)),
                ('address', models.CharField(blank=True, default='', max_length=255)),
                ('aadhaar_number', models.CharField(blank=True, default='', max_length=12)),
                ('nominee', models.CharField(blank=True, default='', max_length=150)),
                ('joined_date', models.DateField(blank=True, null=True)),
                ('notes', models.CharField(blank=True, default='', max_length=255)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('chit', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='members', to='NexusApp.chitgroup')),
            ],
            options={
                'db_table': 'chit_members',
                'ordering': ['ticket_no'],
            },
        ),
        migrations.CreateModel(
            name='ChitTerm',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('term_no', models.PositiveIntegerField()),
                ('month', models.DateField()),
                ('due_date', models.DateField()),
                ('due_amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('prize_amount', models.DecimalField(decimal_places=2, max_digits=14)),
                ('bid_discount', models.DecimalField(decimal_places=2, default=Decimal('0'), max_digits=14)),
                ('commission_amount', models.DecimalField(decimal_places=2, default=Decimal('0'), max_digits=14)),
                ('dividend_per_member', models.DecimalField(decimal_places=2, default=Decimal('0'), max_digits=12)),
                ('claimed', models.BooleanField(default=False)),
                ('claimed_date', models.DateField(blank=True, null=True)),
                ('notes', models.CharField(blank=True, default='', max_length=255)),
                ('chit', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='terms', to='NexusApp.chitgroup')),
                ('winner', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='won_terms', to='NexusApp.chitmember')),
            ],
            options={
                'db_table': 'chit_terms',
                'ordering': ['chit', 'term_no'],
            },
        ),
        migrations.CreateModel(
            name='ChitPayment',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('paid_date', models.DateField()),
                ('method', models.CharField(choices=[('cash', 'Cash'), ('upi', 'UPI')], default='cash', max_length=10)),
                ('notes', models.CharField(blank=True, default='', max_length=255)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('collected_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='chit_collections', to='NexusApp.staff')),
                ('member', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payments', to='NexusApp.chitmember')),
                ('term', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payments', to='NexusApp.chitterm')),
            ],
            options={
                'db_table': 'chit_payments',
                'ordering': ['-paid_date', '-id'],
            },
        ),
        migrations.AddConstraint(
            model_name='chitterm',
            constraint=models.UniqueConstraint(fields=('chit', 'term_no'), name='unique_chit_term'),
        ),
        migrations.AddIndex(
            model_name='chitpayment',
            index=models.Index(fields=['term', 'member'], name='chit_paymen_term_id_381911_idx'),
        ),
        migrations.AddConstraint(
            model_name='chitmember',
            constraint=models.UniqueConstraint(fields=('chit', 'ticket_no'), name='unique_chit_ticket'),
        ),
    ]
