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

            $table->bigIncrements('TA_Id');

            $table->unsignedBigInteger('WA_Id')->nullable();
            $table->unsignedBigInteger('SL_Id')->nullable();

            $table->date('TA_Date')->nullable();
            $table->string('Fix_Per', 1)->nullable();

            $table->decimal('WO_Amount', 18, 2);
            $table->decimal('Percentage', 18, 2);
            $table->decimal('Adj_Amount', 18, 2);

            $table->string('Add_Deduct', 1)->nullable();
            $table->string('Bill_No', 25)->nullable();

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

            // Index
            $table->index('WO_Amount');

            // Foreign Keys
            $table->foreign('SL_Id', 'fk_tdr_adj_sl')
                ->references('SL_Id')
                ->on('subledg_master')
                ->onDelete('restrict')
                ->onUpdate('cascade');

            $table->foreign('WA_Id', 'fk_tdr_adj_wa')
                ->references('WA_Id')
                ->on('work_allocation_book')
                ->onDelete('restrict')
                ->onUpdate('cascade');
        });
    }

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