<?php

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

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

            $table->unsignedInteger('shopping_user_id');
            $table->unsignedInteger('auth_user_id');

            $table->unsignedInteger('country_id');

            $table->unsignedInteger('member_id')->nullable();

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

            $table->decimal('total', 13, 2)->nullable();
            $table->decimal('subtotal_full', 13, 2)->nullable();
            $table->decimal('discount', 13, 2)->nullable();
            $table->decimal('subtotal', 13, 2)->nullable();


            $table->decimal('shipping', 8, 2)->nullable();
            $table->decimal('shipping_net', 8, 2)->nullable();

            $table->decimal('subtotal_shipping', 13, 2)->nullable();
            $table->decimal('tax', 8, 2)->nullable();

            $table->decimal('total_without_credit', 13, 2)->nullable();
            $table->decimal('payment_credit', 13, 2)->nullable();
            $table->decimal('total_shipping', 13, 2)->nullable();

            $table->unsignedInteger('points')->nullable();

            $table->unsignedInteger('weight')->nullable();

            $table->boolean('paid')->default(false);
            $table->string('wp_invoice_path', 255)->nullable();
            $table->text('wp_notice')->nullable();

            $table->string('txaction', 20)->nullable()->index();
            $table->unsignedTinyInteger('shipped')->default(0);
            $table->string('tracking', 255)->nullable();

            $table->char('mode', 4)->nullable();

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

            $table->foreign('shopping_user_id')
                ->references('id')
                ->on('shopping_users');


            $table->foreign('country_id')
                ->references('id')
                ->on('shipping_countries');


            $table->foreign('member_id')
                ->references('id')
                ->on('users');
        });
    }

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