# Generated by Django 5.2.19 on 2026-11-29 09:32

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', '0006_accountingpolicy_default_valuation_method_and_more'),
        ('projects', '0001_initial'),
        ('tenancy', '0002_company_multi_currency_enabled'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Designation',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('code', models.CharField(max_length=24)),
                ('title', models.CharField(max_length=120)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='designations', to='tenancy.company')),
            ],
            options={
                'db_table': 'designations',
                'ordering': ['title'],
                'unique_together': {('company', 'code')},
            },
        ),
        migrations.CreateModel(
            name='LeaveRequest',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('leave_type', models.CharField(default='ANNUAL', max_length=24)),
                ('start_date', models.DateField()),
                ('end_date', models.DateField()),
                ('days', models.DecimalField(decimal_places=1, default=Decimal('1.0'), max_digits=5)),
                ('reason', models.CharField(blank=True, max_length=255)),
                ('status', models.CharField(default='PENDING', max_length=16)),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='leave_requests', to='tenancy.company')),
                ('employee', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='accounting.employeeprofile')),
            ],
            options={
                'db_table': 'leave_requests',
            },
        ),
        migrations.CreateModel(
            name='PayrollRun',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('run_no', models.CharField(max_length=40)),
                ('period_label', models.CharField(max_length=48)),
                ('period_start', models.DateField()),
                ('period_end', models.DateField()),
                ('pay_date', models.DateField()),
                ('bs_pay_date', models.CharField(blank=True, max_length=16)),
                ('total_gross', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('total_deductions', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('total_net_pay', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('status', models.CharField(choices=[('DRAFT', 'Draft'), ('CALCULATED', 'Calculated'), ('APPROVED', 'Finance Approved'), ('POSTED', 'Posted to General Ledger'), ('PAID', 'Paid via Bank')], db_index=True, default='DRAFT', max_length=16)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('accrual_voucher', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='accounting.voucher')),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payroll_runs', to='tenancy.company')),
                ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('payment_voucher', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='accounting.voucher')),
                ('project', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.project')),
            ],
            options={
                'db_table': 'payroll_runs',
                'ordering': ['-pay_date'],
            },
        ),
        migrations.CreateModel(
            name='PayrollLine',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('basic_pay', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('allowances', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('overtime_pay', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('gross_pay', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('pf_ssf_deduction', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('tds_tax', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('advance_recovery', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('loan_deduction', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('net_pay', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('advance_record', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='accounting.advancerecord')),
                ('cost_code', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.costcode')),
                ('employee', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='accounting.employeeprofile')),
                ('project', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.project')),
                ('staff_loan', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='accounting.staffloan')),
                ('payroll_run', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lines', to='hr.payrollrun')),
            ],
            options={
                'db_table': 'payroll_lines',
                'unique_together': {('payroll_run', 'employee')},
            },
        ),
        migrations.CreateModel(
            name='PayrollStatutoryRuleSet',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('rule_name', models.CharField(max_length=120)),
                ('effective_from', models.DateField()),
                ('effective_to', models.DateField(blank=True, null=True)),
                ('employee_pf_pct', models.DecimalField(decimal_places=2, default=Decimal('10.00'), max_digits=5)),
                ('employer_pf_pct', models.DecimalField(decimal_places=2, default=Decimal('10.00'), max_digits=5)),
                ('employee_ssf_pct', models.DecimalField(decimal_places=2, default=Decimal('11.00'), max_digits=5)),
                ('employer_ssf_pct', models.DecimalField(decimal_places=2, default=Decimal('20.00'), max_digits=5)),
                ('tax_slabs_single', models.JSONField(default=list, encoder=django.core.serializers.json.DjangoJSONEncoder)),
                ('tax_slabs_couple', models.JSONField(default=list, encoder=django.core.serializers.json.DjangoJSONEncoder)),
                ('is_active', models.BooleanField(default=True)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payroll_rule_sets', to='tenancy.company')),
            ],
            options={
                'db_table': 'payroll_statutory_rules',
                'ordering': ['-effective_from'],
            },
        ),
        migrations.AddField(
            model_name='payrollrun',
            name='statutory_rule_set',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='hr.payrollstatutoryruleset'),
        ),
        migrations.CreateModel(
            name='SalaryStructure',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('effective_from', models.DateField()),
                ('basic_salary', models.DecimalField(decimal_places=2, max_digits=14)),
                ('dearness_allowance', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('site_allowance', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('conveyance_allowance', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('is_current', models.BooleanField(default=True)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tenancy.company')),
                ('employee', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='salary_structures', to='accounting.employeeprofile')),
            ],
            options={
                'db_table': 'employee_salary_structures',
                'ordering': ['-effective_from'],
            },
        ),
        migrations.CreateModel(
            name='Timesheet',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('timesheet_no', models.CharField(max_length=40)),
                ('period_start', models.DateField()),
                ('period_end', models.DateField()),
                ('total_regular_hours', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=8)),
                ('total_overtime_hours', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=8)),
                ('total_labor_cost', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('status', models.CharField(choices=[('DRAFT', 'Draft'), ('SUBMITTED', 'Submitted'), ('APPROVED', 'Supervisor Approved'), ('POSTED_TO_PAYROLL', 'Included in Payroll'), ('REJECTED', 'Rejected')], db_index=True, default='DRAFT', max_length=24)),
                ('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='+', to=settings.AUTH_USER_MODEL)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='timesheets', to='tenancy.company')),
                ('employee', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='timesheets', to='accounting.employeeprofile')),
                ('project', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='projects.project')),
                ('site', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.site')),
                ('submitted_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'timesheets',
                'ordering': ['-period_end'],
                'unique_together': {('company', 'timesheet_no')},
            },
        ),
        migrations.CreateModel(
            name='TimesheetLine',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('work_date', models.DateField()),
                ('work_activity', models.CharField(max_length=120)),
                ('regular_hours', models.DecimalField(decimal_places=2, default=Decimal('8.00'), max_digits=6)),
                ('overtime_hours', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=6)),
                ('hourly_rate', models.DecimalField(decimal_places=2, max_digits=10)),
                ('overtime_rate', models.DecimalField(decimal_places=2, max_digits=10)),
                ('labor_cost', models.DecimalField(decimal_places=2, max_digits=14)),
                ('boq_item', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='accounting.boqitem')),
                ('cost_code', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.costcode')),
                ('timesheet', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lines', to='hr.timesheet')),
            ],
            options={
                'db_table': 'timesheet_lines',
            },
        ),
        migrations.CreateModel(
            name='WorkShift',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=80)),
                ('start_time', models.TimeField()),
                ('end_time', models.TimeField()),
                ('standard_hours', models.DecimalField(decimal_places=2, default=Decimal('8.00'), max_digits=4)),
                ('overtime_multiplier', models.DecimalField(decimal_places=2, default=Decimal('1.50'), max_digits=4)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='shifts', to='tenancy.company')),
            ],
            options={
                'db_table': 'shifts',
            },
        ),
        migrations.CreateModel(
            name='EmployeeDetail',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('employment_type', models.CharField(choices=[('PERMANENT', 'Permanent Staff'), ('TEMPORARY', 'Temporary Staff'), ('PROJECT_BASED', 'Project-Based Engineer/Staff'), ('SKILLED_LABOR', 'Skilled Construction Labor'), ('UNSKILLED_LABOR', 'Unskilled Labor'), ('DAILY_WAGE', 'Daily Wage Worker'), ('CONTRACT', 'Contractual Employee'), ('CONSULTANT', 'Consultant')], default='PERMANENT', max_length=20)),
                ('joining_date', models.DateField(blank=True, null=True)),
                ('exit_date', models.DateField(blank=True, null=True)),
                ('bank_name', models.CharField(blank=True, max_length=120)),
                ('bank_account_no', models.CharField(blank=True, max_length=48)),
                ('pan_no', models.CharField(blank=True, max_length=20)),
                ('ssf_no', models.CharField(blank=True, max_length=40)),
                ('pf_enrolled', models.BooleanField(default=True)),
                ('ssf_enrolled', models.BooleanField(default=False)),
                ('is_married_tax', models.BooleanField(default=False)),
                ('hourly_rate', models.DecimalField(decimal_places=2, default=Decimal('250.00'), max_digits=12)),
                ('status', models.CharField(choices=[('ACTIVE', 'Active'), ('SUSPENDED', 'Suspended'), ('RESIGNED', 'Resigned'), ('TERMINATED', 'Terminated')], default='ACTIVE', max_length=16)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='hr_employees', to='tenancy.company')),
                ('designation_obj', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='hr.designation')),
                ('employee_profile', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='hr_detail', to='accounting.employeeprofile')),
                ('shift', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='hr.workshift')),
            ],
            options={
                'db_table': 'employees',
            },
        ),
        migrations.AlterUniqueTogether(
            name='payrollrun',
            unique_together={('company', 'run_no')},
        ),
        migrations.CreateModel(
            name='Payslip',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('payslip_no', models.CharField(max_length=48)),
                ('generated_at', models.DateTimeField(auto_now_add=True)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tenancy.company')),
                ('payroll_line', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='payslip', to='hr.payrollline')),
            ],
            options={
                'db_table': 'payslips',
                'unique_together': {('company', 'payslip_no')},
            },
        ),
        migrations.CreateModel(
            name='AttendanceRecord',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('attendance_date', models.DateField(db_index=True)),
                ('check_in', models.TimeField(blank=True, null=True)),
                ('check_out', models.TimeField(blank=True, null=True)),
                ('overtime_hours', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=5)),
                ('status', models.CharField(choices=[('PRESENT', 'Present'), ('ABSENT', 'Absent'), ('HALF_DAY', 'Half Day'), ('LEAVE', 'Approved Leave'), ('HOLIDAY', 'Holiday')], default='PRESENT', max_length=16)),
                ('source', models.CharField(default='MANUAL', max_length=16)),
                ('original_snapshot', models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attendance_records', to='tenancy.company')),
                ('employee', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='attendance', to='accounting.employeeprofile')),
                ('project', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.project')),
                ('site', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.site')),
                ('shift', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='hr.workshift')),
            ],
            options={
                'db_table': 'attendance_records',
                'ordering': ['-attendance_date'],
                'unique_together': {('company', 'employee', 'attendance_date')},
            },
        ),
    ]
