2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2021-06-10 13:18:00 -07:00
|
|
|
namespace Database\Seeders;
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
use App\Models\Asset;
|
2023-03-15 18:31:08 -07:00
|
|
|
use App\Models\Location;
|
2023-03-16 12:41:34 -07:00
|
|
|
use App\Models\Supplier;
|
2023-03-16 18:29:51 -07:00
|
|
|
use App\Models\User;
|
2023-03-16 14:23:40 -07:00
|
|
|
use Illuminate\Database\Eloquent\Factories\Sequence;
|
2021-06-10 13:15:52 -07:00
|
|
|
use Illuminate\Database\Seeder;
|
2021-06-10 13:19:27 -07:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2018-09-29 21:33:52 -07:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
class AssetSeeder extends Seeder
|
|
|
|
{
|
2023-03-16 18:29:51 -07:00
|
|
|
private $admin;
|
|
|
|
private $locationIds;
|
|
|
|
private $supplierIds;
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
Asset::truncate();
|
2023-03-15 18:31:08 -07:00
|
|
|
|
2023-03-16 18:29:51 -07:00
|
|
|
$this->ensureLocationsSeeded();
|
|
|
|
$this->ensureSuppliersSeeded();
|
|
|
|
|
2024-09-20 11:11:52 -07:00
|
|
|
$this->adminuser = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
2023-03-16 18:29:51 -07:00
|
|
|
$this->locationIds = Location::all()->pluck('id');
|
|
|
|
$this->supplierIds = Supplier::all()->pluck('id');
|
|
|
|
|
2023-04-15 18:27:53 -07:00
|
|
|
Asset::factory()->count(2000)->laptopMbp()->state(new Sequence($this->getState()))->create();
|
2023-03-16 18:29:51 -07:00
|
|
|
Asset::factory()->count(50)->laptopMbpPending()->state(new Sequence($this->getState()))->create();
|
|
|
|
Asset::factory()->count(50)->laptopMbpArchived()->state(new Sequence($this->getState()))->create();
|
|
|
|
Asset::factory()->count(50)->laptopAir()->state(new Sequence($this->getState()))->create();
|
2023-04-15 18:27:53 -07:00
|
|
|
Asset::factory()->count(50)->laptopSurface()->state(new Sequence($this->getState()))->create();
|
2023-03-16 18:29:51 -07:00
|
|
|
Asset::factory()->count(5)->laptopXps()->state(new Sequence($this->getState()))->create();
|
|
|
|
Asset::factory()->count(5)->laptopSpectre()->state(new Sequence($this->getState()))->create();
|
2023-04-15 18:27:53 -07:00
|
|
|
Asset::factory()->count(50)->laptopZenbook()->state(new Sequence($this->getState()))->create();
|
|
|
|
Asset::factory()->count(30)->laptopYoga()->state(new Sequence($this->getState()))->create();
|
2023-03-16 18:29:51 -07:00
|
|
|
Asset::factory()->count(30)->desktopMacpro()->state(new Sequence($this->getState()))->create();
|
|
|
|
Asset::factory()->count(30)->desktopLenovoI5()->state(new Sequence($this->getState()))->create();
|
|
|
|
Asset::factory()->count(30)->desktopOptiplex()->state(new Sequence($this->getState()))->create();
|
2023-04-15 18:27:53 -07:00
|
|
|
Asset::factory()->count(50)->confPolycom()->state(new Sequence($this->getState()))->create();
|
|
|
|
Asset::factory()->count(20)->confPolycomcx()->state(new Sequence($this->getState()))->create();
|
|
|
|
Asset::factory()->count(30)->tabletIpad()->state(new Sequence($this->getState()))->create();
|
|
|
|
Asset::factory()->count(10)->tabletTab3()->state(new Sequence($this->getState()))->create();
|
2023-03-16 18:29:51 -07:00
|
|
|
Asset::factory()->count(27)->phoneIphone11()->state(new Sequence($this->getState()))->create();
|
|
|
|
Asset::factory()->count(40)->phoneIphone12()->state(new Sequence($this->getState()))->create();
|
2023-04-15 18:27:53 -07:00
|
|
|
Asset::factory()->count(20)->ultrafine()->state(new Sequence($this->getState()))->create();
|
|
|
|
Asset::factory()->count(20)->ultrasharp()->state(new Sequence($this->getState()))->create();
|
2021-06-10 13:15:52 -07:00
|
|
|
|
|
|
|
$del_files = Storage::files('assets');
|
|
|
|
foreach ($del_files as $del_file) { // iterate files
|
2023-03-16 14:23:40 -07:00
|
|
|
Log::debug('Deleting: ' . $del_files);
|
2021-06-10 13:15:52 -07:00
|
|
|
try {
|
2023-03-16 14:23:40 -07:00
|
|
|
Storage::disk('public')->delete('assets' . '/' . $del_files);
|
2021-06-10 13:15:52 -07:00
|
|
|
} catch (\Exception $e) {
|
2021-06-10 13:19:27 -07:00
|
|
|
Log::debug($e);
|
2021-06-10 13:15:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DB::table('checkout_requests')->truncate();
|
|
|
|
}
|
2023-03-16 18:29:51 -07:00
|
|
|
|
|
|
|
private function ensureLocationsSeeded()
|
|
|
|
{
|
|
|
|
if (! Location::count()) {
|
|
|
|
$this->call(LocationSeeder::class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function ensureSuppliersSeeded()
|
|
|
|
{
|
|
|
|
if (! Supplier::count()) {
|
|
|
|
$this->call(SupplierSeeder::class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getState()
|
|
|
|
{
|
|
|
|
return fn($sequence) => [
|
|
|
|
'rtd_location_id' => $this->locationIds->random(),
|
|
|
|
'supplier_id' => $this->supplierIds->random(),
|
2024-09-20 11:45:10 -07:00
|
|
|
'created_by' => $this->adminuser->id,
|
2023-03-16 18:29:51 -07:00
|
|
|
];
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|