<?php

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

class CreateProductionOrderTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('production_order', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('pos_id')->nullable()->unsigned();
            $table->foreign('pos_id')->references('id')->on('production_order_stages');
            $table->bigInteger('bom_id')->nullable()->unsigned();
            $table->foreign('bom_id')->references('id')->on('bill_of_materials');
            $table->bigInteger('product_id')->nullable()->unsigned();
            $table->foreign('product_id')->references('id')->on('products');
            $table->integer('qty')->default(0);
            $table->string('reference_no')->nullable();
            $table->bigInteger('fg_store_id')->nullable()->unsigned();
            $table->foreign('fg_store_id')->references('id')->on('stores');
            $table->bigInteger('rm_store_id')->nullable()->unsigned();
            $table->foreign('rm_store_id')->references('id')->on('stores');
            $table->bigInteger('scrap_store_id')->nullable()->unsigned();
            $table->foreign('scrap_store_id')->references('id')->on('stores');
            $table->string('attachment_file')->nullable();
            $table->bigInteger('reviewed_by_user_id')->nullable()->unsigned();
            $table->foreign('reviewed_by_user_id')->references('id')->on('users');
            $table->timestamps();
            $table->softDeletes();
        });
    }

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