<?php

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

/**
 * The GRN form has always collected a per-line selling price, but there was no
 * column to store it — GrnService::create() silently dropped the value and
 * confirm() copied `unit_cost` into the product's sale_price, so the selling
 * price was being set to the purchase cost.
 *
 * This adds the missing column. `unit_cost` remains the purchase cost and now
 * feeds products.purchase_price; `sale_price` feeds products.sale_price.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('grn_items', function (Blueprint $table) {
            $table->decimal('sale_price', 12, 2)->nullable()->after('unit_cost');
        });
    }

    public function down(): void
    {
        Schema::table('grn_items', function (Blueprint $table) {
            $table->dropColumn('sale_price');
        });
    }
};
