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

            $table->id('CV_Id');

            $table->unsignedBigInteger('CV_Ty')->nullable();
            $table->date('Chln_Date');

            $table->string('CV_No', 50)->nullable()->comment('Payment Voucher Number - Auto-generated');

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

            $table->integer('CV_Sr')->nullable();

            $table->unsignedBigInteger('SL_Id')->nullable()->comment('Sub Ledger');
            $table->string('SL_Nm', 25)->nullable();

            $table->string('Py_Mode', 25)->nullable();

            $table->decimal('Amount', 15, 2)->nullable();
            $table->string('FileNo', 25)->nullable();

            $table->text('Remarks')->nullable()->comment('Remarks/Notes');

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


            $table->foreign('CV_Ty')
                ->references('Cht_Id')
                ->on('challan_type')
                ->onDelete('set null');

            $table->foreign('Dpt_Id')
                ->references('Dpt_id')
                ->on('dept_master')
                ->onDelete('set null');

            $table->foreign('Bh_Id')
                ->references('Bh_Id')
                ->on('budget_head')
                ->onDelete('set null');

            $table->foreign('Lg_Id')
                ->references('Lg_Id')
                ->on('ledger_master')
                ->onDelete('set null');

            $table->foreign('SL_Id')
                ->references('SL_Id')
                ->on('subledg_master')
                ->onDelete('set null');
        });
    }

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

};
