<?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('warehouse_in', function (Blueprint $table) {
            $table->id();
            $table->dateTime('tanggal');
            $table->foreignId('item_id')->constrained('warehouse_items')->cascadeOnDelete();
            $table->decimal('qty', 15, 2)->default(0);
            $table->decimal('harga_beli', 15, 2)->default(0);
            $table->string('note')->nullable();
            $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();

            $table->index(['tanggal', 'item_id']);
        });
    }

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