<?php
// Nowills SQC ERP — B10: budget virements (transfer between lines, with approval)
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('budget_virements', function (Blueprint $table) {
            $table->id();
            $table->string('virement_no', 30)->unique();
            $table->foreignId('from_budget_line_id')->constrained('budget_lines');
            $table->foreignId('to_budget_line_id')->constrained('budget_lines');
            $table->decimal('amount', 15, 2);
            $table->text('reason');
            $table->string('status', 20)->default('pending')->index();
            $table->foreignId('requested_by')->nullable()->constrained('users')->nullOnDelete();
            $table->foreignId('approved_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();
        });
    }
    public function down(): void {
        Schema::dropIfExists('budget_virements');
    }
};
