<?php

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

class CreateShoppingOrderMarginsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('shopping_order_margins', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('shopping_order_id');
            $table->unsignedInteger('user_id');

            $table->decimal('net_price', 13, 2)->nullable();
            $table->decimal('net_discount', 13, 2)->nullable();
            $table->decimal('net_amount', 13, 2)->nullable();
            $table->decimal('from_payment_credit', 13, 2)->nullable();

            $table->unsignedInteger('m_sponsor_id')->nullable();
            $table->decimal('net_partner_commission', 13, 2)->nullable();

            $table->date('from')->nullable();

            $table->boolean('paid')->default(false);
            $table->boolean('cancellation')->default(false);
            $table->unsignedTinyInteger('status')->index()->default(0);


            $table->text('content')->nullable();

            $table->timestamps();


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

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

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

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