<?php

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

class CreateHistoryContractsUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('history_contracts_users', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->nullable();
            $table->unsignedBigInteger('contract_id')->nullable();
            $table->unsignedBigInteger('company_id')->nullable();
            $table->string('job_position',100)->nullable();
            $table->enum('salary_type', ['1', '2', '3'])->nullable();
            $table->decimal('base_salary',10 ,2)->nullable();
            $table->decimal('performance_factor',10 ,2)->nullable(); //Factor prestacional 30%
            $table->decimal('salary',10 ,2)->nullable();
            $table->enum('payment_method', ['1', '2', '3', '4'])->nullable();
            $table->longText('content_contract')->nullable();
            $table->date('start_date');
            $table->date('end_date')->nullable();
            $table->date('start_date_work');
            $table->date('end_date_work')->nullable();
            $table->string('place_hired')->nullable();
            $table->string('place_work')->nullable();
            $table->enum('work_day', ['1', '2', '3'])->nullable();
            $table->decimal('energy_cost', 10, 2)->nullable();
            $table->decimal('maintenance_technology_resources_cost', 10, 2)->nullable();
            $table->decimal('phone_cost', 10, 2)->nullable();
            $table->decimal('others_cost', 10, 2)->nullable();
            $table->longText('no_salary_cost')->nullable();
            $table->string('status',1)->nullable();
            $table->string('signature_employee')->nullable();
            $table->string('signature_company')->nullable();
            $table->string('signature_full_name')->nullable();
            $table->string('signature_position')->nullable();
            $table->string('signature_document_type',1)->nullable();
            $table->string('signature_document_number')->nullable();
            $table->date('signature_date')->nullable();
            $table->boolean('active_signature_employee')->default(false);
            $table->string('signature_employee_code')->nullable();
            $table->unsignedBigInteger('created_by')->nullable();
            $table->string('ref_reason_termination')->nullable();
            $table->longText('reason_termination')->nullable();
            $table->date('date_termination')->nullable();
            $table->unsignedBigInteger('user_termination')->nullable();
            $table->foreign('user_id')->references('id')->on('users')
                ->onDelete('cascade')
                ->onUpdate('cascade');
            $table->foreign('contract_id')->references('id')->on('contracts')
                ->onDelete('set null')
                ->onUpdate('set null');
            $table->foreign('company_id')->references('id')->on('companies')
                ->onDelete('cascade')
                ->onUpdate('cascade');
            $table->foreign('created_by')->references('id')->on('users')
                ->onDelete('set null')
                ->onUpdate('set null');
            $table->foreign('user_termination')->references('id')->on('users')
                ->onDelete('set null')
                ->onUpdate('set null');
            $table->timestamps();
        });
    }

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