Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/medad.corals.io/Corals/modules/Medad/database/migrations/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/medad.corals.io/Corals/modules/Medad/database/migrations/MedadTables.php
<?php

namespace Corals\Modules\Medad\database\migrations;

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

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

            $table->string('name');
            $table->string('code')->unique();
            $table->string('type');
            $table->string('status');
            $table->unsignedInteger('parent_id')->nullable();
            $table->string('tin')->unique()->nullable();
            $table->string('email')->nullable();
            $table->string('phone_number')->nullable();
            $table->string('website')->nullable();

            $table->unsignedInteger('location_id')->index()->nullable();

            $this->commonColumns($table);

            $table->foreign('parent_id')
                ->references('id')
                ->on('medad_companies')
                ->onUpdate('cascade');

            $table->foreign('location_id')->references('id')
                ->on('utility_locations');
        });

        Schema::create('medad_company_relation', function (Blueprint $table) {
            $table->increments('id');

            $table->unsignedInteger('company_id')->nullable();
            $table->unsignedInteger('second_company_id')->index()->nullable();
            $table->string('relation_type')->nullable();

            $this->commonColumns($table);

            $table->foreign('company_id')
                ->references('id')
                ->on('medad_companies')
                ->onUpdate('cascade');

            $table->foreign('second_company_id')
                ->references('id')
                ->on('medad_companies')
                ->onUpdate('cascade');
        });

        Schema::create('company_relation_branches', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('branch_id');
            $table->unsignedInteger('company_relation_id');

            $this->commonColumns($table);

            $table->foreign('branch_id')
                ->references('id')
                ->on('medad_companies')
                ->onUpdate('cascade');

            $table->foreign('company_relation_id')
                ->references('id')
                ->on('medad_company_relation')
                ->onUpdate('cascade');
        });

        Schema::create('medad_company_user', function (Blueprint $table) {
            $table->increments('id');

            $table->unsignedInteger('company_id');

            $table->unsignedInteger('user_id');

            $table->boolean('is_admin')->default(false);

            $this->commonColumns($table);

            $table->foreign('company_id')
                ->references('id')
                ->on('medad_companies')
                ->onUpdate('cascade');

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

        Schema::create('medad_invitations', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('company_id');
            $table->string('token')->unique();
            $this->commonColumns($table);

            $table->foreign('company_id')
                ->references('id')
                ->on('medad_companies')
                ->onUpdate('cascade');
        });

        Schema::create('medad_vehicles', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('company_id');
            $table->string('licence_plate')->unique();
            $table->string('model_code');
            $table->string('model_year')->nullable();
            $table->string('make_code')->nullable();
            $table->string('color')->nullable();
            $table->integer('current_odometer')->nullable();
            $table->string('current_fuel_level')->nullable();//Full 7/8 3/4 5/8 1/2 3/8 1/4 1/8 Empty
            $table->string('engine_fuel')->nullable();//Diesel, Gas, Electricity
            $table->date('registration_expiration')->nullable();

            $this->commonColumns($table);

            $table->foreign('company_id')
                ->references('id')
                ->on('medad_companies')
                ->onUpdate('cascade');

            $table->foreign('model_code')
                ->references('code')
                ->on('utility_list_of_values')
                ->onUpdate('cascade');
        });
        Schema::create('medad_vehicle_services', function (Blueprint $table) {
            $table->increments('id');
            $table->string('code')->unique();
            $table->unsignedInteger('vehicle_id');
            $table->unsignedInteger('user_id');
            $table->string('service_type_code');
            $table->integer('odometer_reading')->nullable();
            $table->decimal('cost')->nullable();
            $table->string('fuel_level')->nullable();//Full 7/8 3/4 5/8 1/2 3/8 1/4 1/8 Empty
            $table->text('work_performed')->nullable();
            $table->date('service_date')->nullable();
            $table->unsignedInteger('driver_id')->nullable();

            $this->commonColumns($table);

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


            $table->foreign('vehicle_id')
                ->references('id')
                ->on('medad_vehicles')
                ->onUpdate('cascade');


            $table->foreign('driver_id')
                ->references('id')
                ->on('users')
                ->onUpdate('cascade');
        });
        Schema::create('medad_vehicle_drivers', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('vehicle_id');
            $table->date('start_date')->nullable();
            $table->date('end_date')->nullable();
            $table->unsignedInteger('driver_id')->nullable();

            $this->commonColumns($table);

            $table->foreign('driver_id')
                ->references('id')
                ->on('users')
                ->onUpdate('cascade');

            $table->foreign('vehicle_id')
                ->references('id')
                ->on('medad_vehicles')
                ->onUpdate('cascade');
        });

        Schema::create('medad_projects', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->text('description')->nullable();

            $table->unsignedInteger('manager_id')->nullable();
            $table->unsignedInteger('branch_id');
            $table->string('address')->nullable();
            $table->string('lat')->nullable();
            $table->string('long')->nullable();

            $this->commonColumns($table);

            $table->foreign('manager_id')
                ->references('id')
                ->on('users')
                ->onUpdate('cascade');

            $table->foreign('branch_id')
                ->references('id')
                ->on('medad_companies')
                ->onUpdate('cascade');
        });

        Schema::create('medad_model_users', function (Blueprint $table) {
            $table->increments('id');

            $table->morphs('model');

            $table->unsignedInteger('user_id');

            $table->string('role');

            $this->commonColumns($table);

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

        Schema::create('medad_company_project', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('project_id');
            $table->unsignedInteger('company_id');

            $table->string('relation_type')->nullable();

            $this->commonColumns($table);

            $table->foreign('project_id')
                ->references('id')
                ->on('medad_projects')
                ->onUpdate('cascade');

            $table->foreign('company_id')
                ->references('id')
                ->on('medad_companies')
                ->onUpdate('cascade');
        });

        Schema::create('medad_quotation_requests', function (Blueprint $table) {
            $table->increments('id');
            $this->projectItemCommon($table, false);
        });

        Schema::create('medad_quotation_request_suppliers', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('quotation_request_id');
            $table->unsignedInteger('company_id');
            $table->unsignedInteger('branch_id')->nullable();

            $this->commonColumns($table);

            $table->foreign('quotation_request_id')
                ->references('id')
                ->on('medad_quotation_requests')
                ->onUpdate('cascade');

            $table->foreign('company_id')
                ->references('id')
                ->on('medad_companies')
                ->onUpdate('cascade');

            $table->foreign('branch_id')
                ->references('id')
                ->on('medad_companies')
                ->onUpdate('cascade');
        });

        Schema::create('medad_quotations', function (Blueprint $table) {
            $table->increments('id');
            $this->projectItemCommon($table);

            $table->decimal('amount', 14)->nullable();
            $table->date('expiration_date')->nullable();

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

            $table->foreign('quotation_request_id')
                ->references('id')
                ->on('medad_quotation_requests')
                ->onUpdate('cascade');
        });

        Schema::create('medad_purchase_orders', function (Blueprint $table) {
            $table->increments('id');
            $this->projectItemCommon($table);

            $table->decimal('amount', 14)->nullable();
            $table->string('address')->nullable();
            $table->string('lat')->nullable();
            $table->string('long')->nullable();

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

            $table->foreign('quotation_id')
                ->references('id')
                ->on('medad_quotations')
                ->onUpdate('cascade');
        });

        Schema::create('medad_delivery_notes', function (Blueprint $table) {
            $table->increments('id');
            $this->projectItemCommon($table);

            $table->unsignedInteger('driver_id')->nullable();
            $table->string('recipient_name')->nullable();
            $table->string('recipient_phone')->nullable();
            $table->string('recipient_id_number')->nullable();
            $table->string('items_source')->nullable();

            $table->timestamp('started_at')->nullable();
            $table->timestamp('schedule_date')->nullable();
            $table->timestamp('completed_at')->nullable();
            $table->timestamp('assignment_date')->nullable();

            $table->unsignedInteger('purchase_order_id');

            $table->foreign('purchase_order_id')
                ->references('id')
                ->on('medad_purchase_orders')
                ->onUpdate('cascade');

            $table->foreign('driver_id')
                ->references('id')
                ->on('users')
                ->onUpdate('cascade');
        });


        Schema::create('delivery_note_tracking', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('delivery_note_id');
            $table->string('lat')->nullable();
            $table->string('long')->nullable();

            $this->commonColumns($table);

            $table->foreign('delivery_note_id')
                ->references('id')
                ->on('medad_delivery_notes')
                ->onUpdate('cascade');
        });

        Schema::create('medad_invoices', function (Blueprint $table) {
            $table->increments('id');
            $this->projectItemCommon($table);
            $table->decimal('amount', 14)->nullable();

            $table->unsignedInteger('purchase_order_id');

            $table->foreign('purchase_order_id')
                ->references('id')
                ->on('medad_purchase_orders');
        });

        Schema::create('medad_transactions', function (Blueprint $table) {
            $table->increments('id');
            $this->projectItemCommon($table);
            $table->decimal('amount', 14)->nullable();

            $table->unsignedInteger('invoice_id');

            $table->foreign('invoice_id')
                ->references('id')
                ->on('medad_invoices');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        DB::statement('set foreign_key_checks= 0;');
        Schema::dropIfExists('medad_company_relation');
        Schema::dropIfExists('company_relation_branches');
        Schema::dropIfExists('medad_vehicles');
        Schema::dropIfExists('medad_transactions');
        Schema::dropIfExists('medad_invoices');
        Schema::dropIfExists('medad_delivery_notes');
        Schema::dropIfExists('medad_purchase_orders');
        Schema::dropIfExists('medad_quotations');
        Schema::dropIfExists('medad_quotation_request_suppliers');
        Schema::dropIfExists('medad_quotation_requests');
        Schema::dropIfExists('medad_company_project');
        Schema::dropIfExists('medad_model_users');
        Schema::dropIfExists('medad_projects');
        Schema::dropIfExists('medad_invitations');
        Schema::dropIfExists('medad_company_user');
        Schema::dropIfExists('medad_companies');
        Schema::dropIfExists('medad_vehicle_services');
        Schema::dropIfExists('medad_vehicle_drivers');
        Schema::dropIfExists('delivery_note_tracking');
        DB::statement('set foreign_key_checks= 1;');
    }

    protected function projectItemCommon(Blueprint $table, $includeSupplierCompany = true)
    {
        $table->string('code')->unique();
        $table->text('notes')->nullable();
        $table->text('types_count')->nullable();
        $table->decimal('total_quantity')->nullable();
        $table->string('status');

        $table->unsignedInteger('owner_id');
        $table->unsignedInteger('owner_company_id');

        $table->foreign('owner_id')
            ->references('id')
            ->on('users')
            ->onUpdate('cascade');

        $table->unsignedInteger('customer_company_id');
        $table->unsignedInteger('customer_branch_id')->nullable();

        $table->foreign('owner_company_id')
            ->references('id')
            ->on('medad_companies')
            ->onUpdate('cascade');

        $table->foreign('customer_company_id')
            ->references('id')
            ->on('medad_companies')
            ->onUpdate('cascade');

        $table->foreign('customer_branch_id')
            ->references('id')
            ->on('medad_companies')
            ->onUpdate('cascade');

        if ($includeSupplierCompany) {
            $table->unsignedInteger('supplier_company_id');
            $table->unsignedInteger('supplier_branch_id')->nullable();

            $table->foreign('supplier_company_id')
                ->references('id')
                ->on('medad_companies')
                ->onUpdate('cascade');

            $table->foreign('supplier_branch_id')
                ->references('id')
                ->on('medad_companies')
                ->onUpdate('cascade');
        }

        $table->unsignedInteger('project_id')->nullable();
        $table->foreign('project_id')
            ->references('id')
            ->on('medad_projects')
            ->onUpdate('cascade');

        $this->commonColumns($table);
    }

    protected function commonColumns(Blueprint $table)
    {
        $table->text('properties')->nullable();
        $table->auditable();
        $table->softDeletes();
        $table->timestamps();
    }
}

Spamworldpro Mini