<?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('work_order_masters', function (Blueprint $table) {
            $table->id();
            $table->string('work_order_no');
            $table->date('date');
            $table->unsignedBigInteger('quotation_id')->nullable();
            $table->unsignedBigInteger('client_id')->nullable();
            $table->unsignedBigInteger('user_id');
            $table->decimal('total', 15, 2)->default(0);
            $table->decimal('discount_first', 15, 2)->nullable()->default(0);
            $table->decimal('discount_second', 15, 2)->nullable()->default(0);
            $table->decimal('total_discount', 15, 2)->nullable()->default(0);
            $table->decimal('grand_total', 15, 2)->default(0);
            $table->string('status')->default('pending'); // pending, in_progress, completed, cancelled
            $table->text('note')->nullable();
            $table->unsignedBigInteger('created_by')->nullable();
            $table->unsignedBigInteger('updated_by')->nullable();
            $table->unsignedBigInteger('transition_location_id')->nullable();
            $table->unsignedBigInteger('transition_create_by')->nullable();
            $table->unsignedBigInteger('transition_update_by')->nullable();
            $table->timestamps();

            $table->foreign('quotation_id')->references('id')->on('product_quotation_masters')->onDelete('set null');
            $table->foreign('client_id')->references('id')->on('clients')->onDelete('set null');
        });
    }

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

