<?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('easy_in_purchases', function (Blueprint $table) {
            $table->id();
            $table->string('reference_number', 30)->unique();
            $table->date('purchase_date');
            $table->string('item_description');
            $table->string('unit', 50);
            $table->decimal('quantity', 10, 2);
            $table->decimal('unit_price', 12, 2)->default(0);
            $table->decimal('total_amount', 15, 2)->default(0);
            $table->string('supplier_name', 255)->nullable();
            $table->string('invoice_number', 100)->nullable();
            $table->string('lpo_number', 100)->nullable();
            $table->text('notes')->nullable();
            $table->foreignId('created_by')->constrained('users')->onDelete('restrict');
            $table->timestamps();
            $table->softDeletes();

            $table->index('purchase_date');
            $table->index('reference_number');
        });
    }

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