<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('employee_advances', function (Blueprint $table) {
            $table->id();
            $table->foreignId('employee_id')->constrained('employees')->onDelete('cascade');
            $table->decimal('amount',        12, 2)->default(0);   // advance given
            $table->decimal('recovered',     12, 2)->default(0);   // recovered so far
            $table->decimal('monthly_deduction', 12, 2)->default(0);
            $table->date('given_date');
            $table->enum('status', ['active','recovered','cancelled'])->default('active');
            $table->text('notes')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('employee_advances');
    }
};