# Generated by Django 4.2.25 on 2025-11-07 00:27

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('core', '0006_product_buying_price_profitrecord'),
    ]

    operations = [
        migrations.AddField(
            model_name='transaction',
            name='mpesa_reference',
            field=models.CharField(blank=True, help_text='M-Pesa transaction code (e.g., QGH7X9Y2)', max_length=100, null=True),
        ),
        migrations.AddField(
            model_name='transaction',
            name='payment_phone',
            field=models.CharField(blank=True, help_text='Customer phone number for M-Pesa', max_length=20, null=True),
        ),
        migrations.AlterField(
            model_name='stockmovement',
            name='reason',
            field=models.CharField(choices=[('sale', 'Sale'), ('purchase', 'Purchase'), ('transfer', 'Transfer'), ('adjustment', 'Adjustment')], default='sale', max_length=100),
        ),
        migrations.AlterField(
            model_name='transaction',
            name='payment_method',
            field=models.CharField(choices=[('cash', 'Cash'), ('mpesa_paybill', 'M-Pesa Paybill'), ('mpesa_till', 'M-Pesa Till'), ('bank_transfer', 'Bank Transfer')], default='cash', max_length=50),
        ),
        migrations.CreateModel(
            name='Purchase',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('supplier_name', models.CharField(help_text='Who are we buying from?', max_length=255)),
                ('purchase_date', models.DateTimeField()),
                ('total_amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('payment_method', models.CharField(choices=[('cash', 'Cash'), ('mpesa_paybill', 'M-Pesa Paybill'), ('mpesa_till', 'M-Pesa Till'), ('bank_transfer', 'Bank Transfer')], default='cash', max_length=50)),
                ('payment_status', models.CharField(choices=[('paid', 'Paid in Full'), ('credit', 'On Credit (Pay Later)')], default='paid', max_length=20)),
                ('reference_number', models.CharField(blank=True, help_text='Supplier invoice/receipt number', max_length=100, null=True)),
                ('notes', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
                ('destination_location', models.ForeignKey(help_text='Where should stock be delivered? (Main Store or Truck)', on_delete=django.db.models.deletion.CASCADE, related_name='purchases_received', to='core.location')),
                ('paid_from_location', models.ForeignKey(blank=True, help_text="Which location's cash segment to deduct from (for accounting)", null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='purchases_paid', to='core.location')),
            ],
            options={
                'verbose_name': 'Purchase',
                'verbose_name_plural': 'Purchases',
                'ordering': ['-purchase_date'],
            },
        ),
        migrations.CreateModel(
            name='CashTransfer',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('from_payment_method', models.CharField(choices=[('cash', 'Cash'), ('mpesa_paybill', 'M-Pesa Paybill'), ('mpesa_till', 'M-Pesa Till'), ('bank_transfer', 'Bank Transfer')], help_text='Payment method losing money', max_length=50)),
                ('to_payment_method', models.CharField(choices=[('cash', 'Cash'), ('mpesa_paybill', 'M-Pesa Paybill'), ('mpesa_till', 'M-Pesa Till'), ('bank_transfer', 'Bank Transfer')], help_text='Payment method receiving money', max_length=50)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('transfer_type', models.CharField(choices=[('method_change', 'Payment Method Change'), ('location_transfer', 'Location Transfer'), ('consolidation', 'Consolidation/Banking'), ('float', 'Float Allocation'), ('other', 'Other')], max_length=50)),
                ('notes', models.TextField(blank=True)),
                ('reference_number', models.CharField(editable=False, max_length=100, unique=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
                ('from_location', models.ForeignKey(help_text='Location losing money', on_delete=django.db.models.deletion.CASCADE, related_name='transfers_out', to='core.location')),
                ('to_location', models.ForeignKey(help_text='Location receiving money', on_delete=django.db.models.deletion.CASCADE, related_name='transfers_in', to='core.location')),
            ],
            options={
                'verbose_name': 'Cash Transfer',
                'verbose_name_plural': 'Cash Transfers',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='CashTransaction',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('payment_method', models.CharField(choices=[('cash', 'Cash'), ('mpesa_paybill', 'M-Pesa Paybill'), ('mpesa_till', 'M-Pesa Till'), ('bank_transfer', 'Bank Transfer')], max_length=50)),
                ('transaction_type', models.CharField(choices=[('sale', 'Sale Income'), ('purchase', 'Stock Purchase'), ('withdrawal', 'Cash Withdrawal'), ('deposit', 'Cash Deposit'), ('transfer', 'Transfer Between Locations'), ('adjustment', 'Balance Adjustment'), ('transfer_out', 'Transfer Out'), ('transfer_in', 'Transfer In')], max_length=50)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('description', models.TextField(blank=True)),
                ('reference_number', models.CharField(blank=True, max_length=100, null=True)),
                ('balance_after', models.DecimalField(decimal_places=2, max_digits=15)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
                ('location', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cash_transactions', to='core.location')),
                ('sale_transaction', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='cash_entries', to='core.transaction')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='LocationCashBalance',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('payment_method', models.CharField(choices=[('cash', 'Cash'), ('mpesa_paybill', 'M-Pesa Paybill'), ('mpesa_till', 'M-Pesa Till'), ('bank_transfer', 'Bank Transfer')], max_length=50)),
                ('balance', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('total_sales', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('total_purchases', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('location', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cash_balances', to='core.location')),
            ],
            options={
                'ordering': ['location', 'payment_method'],
                'unique_together': {('location', 'payment_method')},
            },
        ),
    ]
