# Generated migration for expenses app

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('users', '0012_branch'),
        ('loans', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Expense',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('title', models.CharField(help_text='Brief description of the expense', max_length=200)),
                ('description', models.TextField(blank=True, help_text='Detailed description', null=True)),
                ('category', models.CharField(choices=[('operational', 'Operational'), ('staff', 'Staff'), ('marketing', 'Marketing'), ('loan_related', 'Loan-Related'), ('utilities', 'Utilities'), ('office', 'Office'), ('transport', 'Transport'), ('maintenance', 'Maintenance'), ('other', 'Other')], default='operational', max_length=20)),
                ('amount', models.DecimalField(decimal_places=2, help_text='Expense amount in KES', max_digits=12, validators=[django.core.validators.MinValueValidator(Decimal('0.01'))])),
                ('payment_method', models.CharField(choices=[('cash', 'Cash'), ('mpesa', 'M-Pesa'), ('bank', 'Bank Transfer'), ('cheque', 'Cheque')], default='cash', max_length=20)),
                ('paid_to', models.CharField(help_text='Recipient/Vendor name', max_length=200)),
                ('receipt_path', models.FileField(blank=True, help_text='Upload receipt or supporting document', null=True, upload_to='expenses/receipts/%Y/%m/')),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('approved', 'Approved'), ('rejected', 'Rejected')], default='pending', max_length=20)),
                ('approved_at', models.DateTimeField(blank=True, null=True)),
                ('rejection_reason', models.TextField(blank=True, null=True)),
                ('expense_date', models.DateField(help_text='Date when expense was incurred')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('reference_number', models.CharField(blank=True, help_text='Transaction/Reference number', max_length=50, null=True)),
                ('notes', models.TextField(blank=True, help_text='Additional notes', null=True)),
                ('approved_by', models.ForeignKey(blank=True, help_text='Manager/Admin who approved this expense', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='expenses_approved', to=settings.AUTH_USER_MODEL)),
                ('branch', models.ForeignKey(help_text='Branch where expense was incurred', on_delete=django.db.models.deletion.CASCADE, related_name='expenses', to='users.Branch')),
                ('loan', models.ForeignKey(blank=True, help_text='Related loan (if applicable)', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='related_expenses', to='loans.Loan')),
                ('staff', models.ForeignKey(help_text='Staff member who created this expense', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='expenses_created', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Expense',
                'verbose_name_plural': 'Expenses',
                'db_table': 'expenses',
                'ordering': ['-expense_date', '-created_at'],
                'indexes': [
                    models.Index(fields=['branch', 'expense_date'], name='expenses_branch_expense_idx'),
                    models.Index(fields=['status', 'expense_date'], name='expenses_status_expense_idx'),
                    models.Index(fields=['category', 'expense_date'], name='expenses_category_expense_idx'),
                    models.Index(fields=['staff', 'expense_date'], name='expenses_staff_expense_idx'),
                ],
            },
        ),
    ]
