<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('deductions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('company_id')->constrained();
            $table->foreignId('branch_id')->nullable();
            $table->foreignId('user_id')->constrained();
            $table->year('year');
            $table->integer('month');
            $table->decimal('amount')->default(0);
            $table->decimal('consider_amount')->nullable()->default(0);
            $table->tinyInteger('is_appealed')->nullable()->default(0);
            $table->dateTime('appealed_at')->nullable();
            $table->text('appeal_details')->nullable();
            $table->foreignId('appeal_attachment_id')->nullable()->constrained('uploads');
            $table->foreignId('appeal_status')->nullable()->constrained('statuses')->comment('2 => Pending, 5 => Approve, 6 => Reject');
            $table->foreignId('appeal_approved_by')->nullable()->constrained('users');
            $table->dateTime('appeal_approved_at')->nullable();
            $table->foreignId('created_by')->constrained('users');
            $table->foreignId('updated_by')->nullable()->constrained('users');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('duductions');
    }
};
