<?php

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

class CreateShoppingOrderItemsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('shopping_order_items', function (Blueprint $table) {
            $table->increments('id');

            $table->unsignedInteger('shopping_order_id');
            $table->string('row_id', 40)->nullable();
            $table->unsignedInteger('product_id');

            $table->unsignedTinyInteger('comp')->nullable();


            $table->unsignedInteger('qty');
            $table->decimal('price', 8, 2)->nullable();
            $table->decimal('price_net', 8, 3)->nullable();

            $table->decimal('tax_rate', 5, 2)->nullable();
            $table->string('slug')->nullable();

            $table->timestamps();
            $table->softDeletes();
            $table->timestamp('user_deleted_at')->nullable();


            $table->foreign('shopping_order_id')
                ->references('id')
                ->on('shopping_orders');

            $table->foreign('product_id')
                ->references('id')
                ->on('products');
        });
    }

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