<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('purchase_histories', function (Blueprint $table) {
            $table->id();
            $table->foreignId('store_id')->constrained('stores')->cascadeOnDelete();
            $table->foreignId('item_id')->constrained('items')->cascadeOnDelete();
            
            // Kuantitas barang masuk (contoh: 5000 gram)
            $table->decimal('qty', 10, 2);
            
            // Total uang riil yang dibayarkan ke supplier (contoh: Rp 100.000)
            $table->decimal('total_cost', 15, 2);
            
            // HPP riil per UOM pada saat pembelian (contoh: Rp 20 / gram)
            $table->decimal('unit_cost', 15, 2);
            
            // Opsional: Nama supplier tempat membeli barang
            $table->string('supplier_name')->nullable();
            
            // Tanggal transaksi riil
            $table->date('purchased_at');
            
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('purchase_histories');
    }
};
