<?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_spareparts', function (Blueprint $table) {
            $table->id();
            $table->string('purchase_sparepart_number')->unique();
            $table->date('document_date');
            $table->unsignedBigInteger('supplier_id');
            $table->string("tax")->nullable();
            $table->decimal("tax_tariff", 20,2)->nullable();
            $table->decimal("subtotal", 20,2);
            $table->decimal("add_tax", 20,2)->nullable();
            $table->decimal("total", 20,2);
            $table->unsignedBigInteger('department_id');
            $table->unsignedBigInteger('created_by')->nullable();
            $table->unsignedBigInteger('updated_by')->nullable();
            $table->timestamps();

            $table->foreign('supplier_id')->references('id')->on('suppliers')->onDelete('restrict');
            $table->foreign('department_id')->references('id')->on('department')->onDelete('restrict');
            $table->foreign('created_by')->references('id')->on('users')->onDelete('restrict');
            $table->foreign('updated_by')->references('id')->on('users')->onDelete('restrict');
        });
    }

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