HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/ipsremont-demo/database/seeds/PartsStorageSeeder.php
<?php

use App\Models\PartsStorage;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class PartsStorageSeeder extends Seeder
{

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        PartsStorage::truncate();

        $central = \App\Services\Branch\BranchService::getCentral();

        if (!$central) {
            $central = \App\Models\Branch::query()->inRandomOrder()->first();
            $central->central = 1;
            $central->save();

        }

        \App\Models\Branch::query()->update(
            ['external_id' => DB::raw('CONCAT(id, "-ext")')]
        );

        $parts = \App\Models\Part::query()->orderBy('name', 'asc')->get('id')->pluck('id')->toArray();
        $central = \App\Services\Branch\BranchService::getCentral();

        if (!$central) {
            die("Выберите центральное подразделение");
        }

        $warehouses = \App\Models\Branch::displayed()
            ->where('id', '<>', $central->id)
            ->limit(10)
            ->get();

        $services = \App\Models\Service\Service::displayed()
            ->where('external_warehouse_id', '<>', '')
            ->limit(10)
            ->get('external_warehouse_id')->pluck('external_warehouse_id')->toArray();

        foreach ($parts as $partId) {
            if (in_array($partId, [1, 6, 11]) || $partId >= 15) {
                PartsStorage::create([
                    'part_id' => $partId,
                    'warehouse_id' => $central->id,
                    'external_warehouse_id' => $central->external_id,
                    'amount' => rand(1, 50),
                    'type' => PartsStorage::branch,
                ]);
            }

            if ($partId >= 5) {
                foreach ($warehouses as $warehouse) {
                    PartsStorage::create([
                        'part_id' => $partId,
                        'warehouse_id' => $warehouse->id,
                        'external_warehouse_id' => $warehouse->external_id,
                        'amount' => rand(1, 50),
                        'type' => PartsStorage::branch,
                    ]);
                }
            }

            if ($partId >= 10) {
                foreach ($services as $service) {
                    PartsStorage::create([
                        'part_id' => $partId,
                        'warehouse_id' => '',
                        'external_warehouse_id' => $service,
                        'amount' => rand(1, 50),
                        'type' => PartsStorage::service,
                    ]);
                }
            }
        }
    }
}