<?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('budget_entries', function (Blueprint $table) {

            $table->bigIncrements('Budg_Id');

            $table->unsignedBigInteger('Fin_Year')->nullable();
            $table->unsignedBigInteger('Dpt_Id')->nullable();
            $table->unsignedBigInteger('Lg_Id')->nullable();

            $table->decimal('Amount', 15, 2);

            $table->longText('Beg_Doc')->nullable();   // Multiple document attachments

            $table->decimal('Sug_Amount', 15, 2)->nullable(); // Suggested amount

            $table->string('Status', 20)->nullable();
            // D=Draft, R=Revised, P=Approve, F=Freeze, A=Active, I=Inactive, RR=Re-Revised, RJ=Reject, J=Justification

            $table->integer('Ref_Id')->default(0);

            $table->tinyInteger('Is_Latest')->default(1);

            $table->timestamps();
            $table->softDeletes();

            // Optional Foreign Keys (agar chaho to enable kar sakte ho)
            $table->foreign('Fin_Year')->references('FY_Id')->on('fyear_master');
            $table->foreign('Dpt_Id')->references('Dpt_Id')->on('dept_master');
            $table->foreign('Lg_Id')->references('Lg_Id')->on('ledger_master');
        });
    }

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

