<?php

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

class CreateFinishedcontractsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('finished_contracts', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id')->nullable();
            $table->unsignedBigInteger('supplier_id')->nullable();
            $table->unsignedBigInteger('category_id')->nullable();
            $table->string('address');
            $table->string('int_number');
            $table->text('references')->nullable();
            $table->geography('location', subtype: 'point');
            $table->timestamp('appointment')->nullable();
            $table->float('amount');
            $table->float('IVA');
            $table->float('ISR');
            $table->float('ichamba_fee');
            $table->float('revenue');
            $table->text('details')->nullable();
            $table->text('comments')->nullable();
            $table->boolean('en')->default(false);
            $table->string('transaction_id');
            $table->unsignedBigInteger('status_id')->nullable()->default('3');
            $table->unsignedBigInteger('parent_contract_id')->nullable();
            $table->Integer('score')->nullable();
            $table->timestamp('scored_at')->nullable();
            $table->unsignedBigInteger('technical_id')->nullable();
            $table->boolean('paid')->default(false);
            $table->timestamp('paid_at')->nullable();
            $table->timestamps();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('set null');
            $table->foreign('supplier_id')->references('id')->on('suppliers')->onDelete('set null');
            $table->foreign('category_id')->references('id')->on('categories')->onDelete('set null');
            $table->foreign('status_id')->references('id')->on('statuses')->onDelete('set null');
            $table->foreign('parent_contract_id')->references('id')->on('finished_contracts')->onDelete('set null');
        });
    }

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