Merge remote-tracking branch 'origin/develop'

This commit is contained in:
snipe 2023-03-21 21:14:06 -07:00
commit 8aec28fad6
48 changed files with 1206 additions and 787 deletions

View file

@ -1147,4 +1147,39 @@ class Helper
return $age; return $age;
} }
/*
* This is a shorter way to see if the app is in demo mode.
*
* This makes it cleanly available in blades and in controllers, e.g.
*
* Blade:
* {{ Helper::isDemoMode() ? ' disabled' : ''}} for form blades where we need to disable a form
*
* Controller:
* if (Helper::isDemoMode()) {
* // don't allow the thing
* }
* @todo - use this everywhere else in the app where we have very long if/else config('app.lock_passwords') stuff
*/
public function isDemoMode() {
if (config('app.lock_passwords') === true) {
return true;
\Log::debug('app locked!');
}
return false;
}
/*
* I know it's gauche to return a shitty HTML string, but this is just a helper and since it will be the same every single time,
* it seemed pretty safe to do here. Don't you judge me.
*/
public function showDemoModeFieldWarning() {
if (Helper::isDemoMode()) {
return "<p class=\"text-warning\"><i class=\"fas fa-lock\"></i>" . trans('general.feature_disabled') . "</p>";
}
}
} }

View file

@ -5,13 +5,14 @@ namespace App\Http\Livewire;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Livewire\Component; use Livewire\Component;
use App\Models\Setting; use App\Models\Setting;
use App\Helpers\Helper;
class SlackSettingsForm extends Component class SlackSettingsForm extends Component
{ {
public $webhook_endpoint; public $webhook_endpoint;
public $webhook_channel; public $webhook_channel;
public $webhook_botname; public $webhook_botname;
public $isDisabled ='disabled' ; public $isDisabled ='' ;
public $webhook_name; public $webhook_name;
public $webhook_link; public $webhook_link;
public $webhook_placeholder; public $webhook_placeholder;
@ -27,8 +28,7 @@ class SlackSettingsForm extends Component
'webhook_botname' => 'string|nullable', 'webhook_botname' => 'string|nullable',
]; ];
public function mount() {
public function mount(){
$this->webhook_text= [ $this->webhook_text= [
"slack" => array( "slack" => array(
"name" => trans('admin/settings/general.slack') , "name" => trans('admin/settings/general.slack') ,
@ -45,6 +45,7 @@ class SlackSettingsForm extends Component
]; ];
$this->setting = Setting::getSettings(); $this->setting = Setting::getSettings();
$this->save_button = trans('general.save');
$this->webhook_selected = $this->setting->webhook_selected; $this->webhook_selected = $this->setting->webhook_selected;
$this->webhook_placeholder = $this->webhook_text[$this->setting->webhook_selected]["placeholder"]; $this->webhook_placeholder = $this->webhook_text[$this->setting->webhook_selected]["placeholder"];
$this->webhook_name = $this->webhook_text[$this->setting->webhook_selected]["name"]; $this->webhook_name = $this->webhook_text[$this->setting->webhook_selected]["name"];
@ -54,29 +55,49 @@ class SlackSettingsForm extends Component
$this->webhook_botname = $this->setting->webhook_botname; $this->webhook_botname = $this->setting->webhook_botname;
$this->webhook_options = $this->setting->webhook_selected; $this->webhook_options = $this->setting->webhook_selected;
if($this->setting->webhook_selected == 'general'){
$this->isDisabled='';
}
if($this->setting->webhook_endpoint != null && $this->setting->webhook_channel != null){
$this->isDisabled= '';
}
} }
public function updated($field){ public function updated($field) {
if($this->webhook_selected != 'general') { if($this->webhook_selected != 'general') {
$this->validateOnly($field, $this->rules); $this->validateOnly($field, $this->rules);
} }
} }
public function updatedWebhookSelected(){
public function updatedWebhookSelected() {
$this->webhook_name = $this->webhook_text[$this->webhook_selected]['name']; $this->webhook_name = $this->webhook_text[$this->webhook_selected]['name'];
$this->webhook_icon = $this->webhook_text[$this->webhook_selected]["icon"]; ; $this->webhook_icon = $this->webhook_text[$this->webhook_selected]["icon"]; ;
$this->webhook_placeholder = $this->webhook_text[$this->webhook_selected]["placeholder"]; $this->webhook_placeholder = $this->webhook_text[$this->webhook_selected]["placeholder"];
$this->webhook_link = $this->webhook_text[$this->webhook_selected]["link"]; $this->webhook_link = $this->webhook_text[$this->webhook_selected]["link"];
if($this->webhook_selected != 'slack'){
$this->isDisabled= '';
$this->save_button = trans('general.save');
}
}
private function isButtonDisabled() {
if($this->webhook_selected == 'slack') {
if (empty($this->webhook_endpoint)) {
$this->isDisabled = 'disabled';
$this->save_button = trans('admin/settings/general.webhook_presave');
}
if (empty($this->webhook_channel)) {
$this->isDisabled = 'disabled';
$this->save_button = trans('admin/settings/general.webhook_presave');
}
}
} }
public function render() public function render()
{ {
if(empty($this->webhook_channel || $this->webhook_endpoint)){ $this->isButtonDisabled();
$this->isDisabled= 'disabled';
}
if(empty($this->webhook_endpoint && $this->webhook_channel)){
$this->isDisabled= '';
}
return view('livewire.slack-settings-form'); return view('livewire.slack-settings-form');
} }
@ -98,37 +119,59 @@ class SlackSettingsForm extends Component
]); ]);
try { try {
$webhook->post($this->webhook_endpoint, ['body' => $payload]); $webhook->post($this->webhook_endpoint, ['body' => $payload]);
$this->isDisabled=''; $this->isDisabled='';
$this->save_button = trans('general.save');
return session()->flash('success' , 'Your '.$this->webhook_name.' Integration works!'); return session()->flash('success' , 'Your '.$this->webhook_name.' Integration works!');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->isDisabled= 'disabled'; $this->isDisabled= 'disabled';
return session()->flash('error' , trans('admin/settings/message.webhook.error', ['error_message' => $e->getMessage(), 'app' => $this->webhook_name])); return session()->flash('error' , trans('admin/settings/message.webhook.error', ['error_message' => $e->getMessage(), 'app' => $this->webhook_name]));
} }
//} return session()->flash('error' , trans('admin/settings/message.webhook.error_misc'));
return session()->flash('message' , trans('admin/settings/message.webhook.error_misc'));
} }
public function clearSettings(){
if (Helper::isDemoMode()) {
session()->flash('error',trans('general.feature_disabled'));
} else {
$this->webhook_endpoint = '';
$this->webhook_channel = '';
$this->webhook_botname = '';
$this->setting->webhook_endpoint = '';
$this->setting->webhook_channel = '';
$this->setting->webhook_botname = '';
$this->setting->save();
session()->flash('success', trans('admin/settings/message.update.success'));
}
}
public function submit() public function submit()
{ {
if($this->webhook_selected != 'general') { if (Helper::isDemoMode()) {
$this->validate($this->rules); session()->flash('error',trans('general.feature_disabled'));
} else {
if ($this->webhook_selected != 'general') {
$this->validate($this->rules);
}
$this->setting->webhook_selected = $this->webhook_selected;
$this->setting->webhook_endpoint = $this->webhook_endpoint;
$this->setting->webhook_channel = $this->webhook_channel;
$this->setting->webhook_botname = $this->webhook_botname;
$this->setting->save();
session()->flash('success',trans('admin/settings/message.update.success'));
} }
$this->setting->webhook_selected = $this->webhook_selected;
$this->setting->webhook_endpoint = $this->webhook_endpoint;
$this->setting->webhook_channel = $this->webhook_channel;
$this->setting->webhook_botname = $this->webhook_botname;
$this->setting->save();
session()->flash('save',trans('admin/settings/message.update.success'));
} }
} }

View file

@ -150,6 +150,7 @@ class SettingsServiceProvider extends ServiceProvider
// Set the monetary locale to the configured locale to make helper::parseFloat work. // Set the monetary locale to the configured locale to make helper::parseFloat work.
setlocale(LC_MONETARY, config('app.locale')); setlocale(LC_MONETARY, config('app.locale'));
setlocale(LC_NUMERIC, config('app.locale')); setlocale(LC_NUMERIC, config('app.locale'));
} }
/** /**

View file

@ -2,17 +2,14 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\Accessory;
use App\Models\Category;
use App\Models\Location;
use App\Models\Manufacturer;
use App\Models\Supplier;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/*
|--------------------------------------------------------------------------
| Asset Model Factories
|--------------------------------------------------------------------------
|
| Factories related exclusively to creating models ..
|
*/
class AccessoryFactory extends Factory class AccessoryFactory extends Factory
{ {
/** /**
@ -20,7 +17,7 @@ class AccessoryFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\Accessory::class; protected $model = Accessory::class;
/** /**
* Define the model's default state. * Define the model's default state.
@ -30,9 +27,16 @@ class AccessoryFactory extends Factory
public function definition() public function definition()
{ {
return [ return [
'user_id' => 1, 'name' => sprintf(
'%s %s',
$this->faker->randomElement(['Bluetooth', 'Wired']),
$this->faker->randomElement(['Keyboard', 'Wired'])
),
'user_id' => User::factory()->superuser(),
'category_id' => Category::factory(),
'model_number' => $this->faker->numberBetween(1000000, 50000000), 'model_number' => $this->faker->numberBetween(1000000, 50000000),
'location_id' => rand(1, 5), 'location_id' => Location::factory(),
'qty' => 1,
]; ];
} }
@ -42,11 +46,15 @@ class AccessoryFactory extends Factory
return [ return [
'name' => 'Bluetooth Keyboard', 'name' => 'Bluetooth Keyboard',
'image' => 'bluetooth.jpg', 'image' => 'bluetooth.jpg',
'category_id' => 8, 'category_id' => function () {
'manufacturer_id' => 1, return Category::where('name', 'Keyboards')->first() ?? Category::factory()->accessoryKeyboardCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
},
'qty' => 10, 'qty' => 10,
'min_amt' => 2, 'min_amt' => 2,
'supplier_id' => rand(1, 5), 'supplier_id' => Supplier::factory(),
]; ];
}); });
} }
@ -57,11 +65,15 @@ class AccessoryFactory extends Factory
return [ return [
'name' => 'USB Keyboard', 'name' => 'USB Keyboard',
'image' => 'usb-keyboard.jpg', 'image' => 'usb-keyboard.jpg',
'category_id' => 8, 'category_id' => function () {
'manufacturer_id' => 1, return Category::where('name', 'Keyboards')->first() ?? Category::factory()->accessoryKeyboardCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
},
'qty' => 15, 'qty' => 15,
'min_amt' => 2, 'min_amt' => 2,
'supplier_id' => rand(1, 5), 'supplier_id' => Supplier::factory(),
]; ];
}); });
} }
@ -72,11 +84,15 @@ class AccessoryFactory extends Factory
return [ return [
'name' => 'Magic Mouse', 'name' => 'Magic Mouse',
'image' => 'magic-mouse.jpg', 'image' => 'magic-mouse.jpg',
'category_id' => 9, 'category_id' => function () {
'manufacturer_id' => 1, return Category::where('name', 'Mouse')->first() ?? Category::factory()->accessoryMouseCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
},
'qty' => 13, 'qty' => 13,
'min_amt' => 2, 'min_amt' => 2,
'supplier_id' => rand(1, 5), 'supplier_id' => Supplier::factory(),
]; ];
}); });
} }
@ -87,8 +103,12 @@ class AccessoryFactory extends Factory
return [ return [
'name' => 'Sculpt Comfort Mouse', 'name' => 'Sculpt Comfort Mouse',
'image' => 'comfort-mouse.jpg', 'image' => 'comfort-mouse.jpg',
'category_id' => 9, 'category_id' => function () {
'manufacturer_id' => 2, return Category::where('name', 'Mouse')->first() ?? Category::factory()->accessoryMouseCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Microsoft')->first() ?? Manufacturer::factory()->microsoft();
},
'qty' => 13, 'qty' => 13,
'min_amt' => 2, 'min_amt' => 2,
]; ];

View file

@ -4,20 +4,12 @@ namespace Database\Factories;
use App\Models\Actionlog; use App\Models\Actionlog;
use App\Models\Asset; use App\Models\Asset;
use App\Models\Company; use App\Models\License;
use App\Models\LicenseSeat;
use App\Models\Location; use App\Models\Location;
use App\Models\User; use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/*
|--------------------------------------------------------------------------
| Action Log Factories
|--------------------------------------------------------------------------
|
| This simulates checkin/checkout/etc activities
|
*/
class ActionlogFactory extends Factory class ActionlogFactory extends Factory
{ {
/** /**
@ -25,7 +17,7 @@ class ActionlogFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\Actionlog::class; protected $model = Actionlog::class;
/** /**
* Define the model's default state. * Define the model's default state.
@ -34,71 +26,83 @@ class ActionlogFactory extends Factory
*/ */
public function definition() public function definition()
{ {
$asset = \App\Models\Asset::factory()->create();
return [ return [
'item_type' => get_class($asset), 'item_id' => Asset::factory(),
'item_id' => 1, 'item_type' => Asset::class,
'user_id' => 1, 'user_id' => User::factory()->superuser(),
'action_type' => 'uploaded', 'action_type' => 'uploaded',
]; ];
} }
public function assetCheckoutToUser() public function assetCheckoutToUser()
{ {
return $this->state(function () { return $this->state(function () {
$target = \App\Models\User::inRandomOrder()->first(); $target = User::inRandomOrder()->first();
$item = \App\Models\Asset::RTD()->inRandomOrder()->first(); $asset = Asset::RTD()->inRandomOrder()->first();
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
$asset = Asset::where('id', $item->id) $asset->update(
->update(
[ [
'assigned_to' => $target->id, 'assigned_to' => $target->id,
'assigned_type' => \App\Models\User::class, 'assigned_type' => User::class,
'location_id' => $target->location_id, 'location_id' => $target->location_id,
] ]
); );
return [ return [
'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()), 'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
'user_id' => $user_id,
'action_type' => 'checkout', 'action_type' => 'checkout',
'item_id' => $item->id, 'item_id' => $asset->id,
'item_type' => \App\Models\Asset::class, 'item_type' => Asset::class,
'target_id' => $target->id, 'target_id' => $target->id,
'target_type' => get_class($target), 'target_type' => User::class,
]; ];
}); });
} }
public function assetCheckoutToLocation() public function assetCheckoutToLocation()
{ {
return $this->state(function () { return $this->state(function () {
$target = \App\Models\Location::inRandomOrder()->first(); $target = Location::inRandomOrder()->first();
$item = \App\Models\Asset::inRandomOrder()->RTD()->first(); $asset = Asset::inRandomOrder()->RTD()->first();
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
$asset = \App\Models\Asset::where('id', $item->id) $asset->update(
->update(
[ [
'assigned_to' => $target->id, 'assigned_to' => $target->id,
'assigned_type' => \App\Models\Location::class, 'assigned_type' => Location::class,
'location_id' => $target->id, 'location_id' => $target->id,
] ]
); );
return [ return [
'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()), 'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
'user_id' => $user_id,
'action_type' => 'checkout', 'action_type' => 'checkout',
'item_id' => $item->id, 'item_id' => $asset->id,
'item_type' => \App\Models\Asset::class, 'item_type' => Asset::class,
'target_id' => $target->id, 'target_id' => $target->id,
'target_type' => get_class($target), 'target_type' => Location::class,
]; ];
}); });
} }
public function licenseCheckoutToUser()
{
return $this->state(function () {
$target = User::inRandomOrder()->first();
$licenseSeat = LicenseSeat::whereNull('assigned_to')->inRandomOrder()->first();
$licenseSeat->update([
'assigned_to' => $target->id,
'user_id' => 1, // not ideal but works
]);
return [
'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
'action_type' => 'checkout',
'item_id' => $licenseSeat->license->id,
'item_type' => License::class,
'target_id' => $target->id,
'target_type' => User::class,
];
});
}
} }

View file

@ -4,22 +4,12 @@ namespace Database\Factories;
use App\Models\Asset; use App\Models\Asset;
use App\Models\AssetModel; use App\Models\AssetModel;
use App\Models\Category;
use App\Models\Location; use App\Models\Location;
use App\Models\Statuslabel;
use App\Models\Supplier; use App\Models\Supplier;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Factories related exclusively to modelling assets.
|
*/
// These are just for unit tests, not to generate data
class AssetFactory extends Factory class AssetFactory extends Factory
{ {
/** /**
@ -38,10 +28,13 @@ class AssetFactory extends Factory
{ {
return [ return [
'name' => null, 'name' => null,
'model_id' => AssetModel::factory(),
'rtd_location_id' => Location::factory(), 'rtd_location_id' => Location::factory(),
'serial' => $this->faker->uuid(), 'serial' => $this->faker->uuid(),
'status_id' => 1, 'status_id' => function () {
'user_id' => 1, return Statuslabel::where('name', 'Ready to Deploy')->first() ?? Statuslabel::factory()->rtd()->create(['name' => 'Ready to Deploy']);
},
'user_id' => User::factory()->superuser(),
'asset_tag' => $this->faker->unixTime('now'), 'asset_tag' => $this->faker->unixTime('now'),
'notes' => 'Created by DB seeder', 'notes' => 'Created by DB seeder',
'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'), 'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'),
@ -60,7 +53,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 1, 'model_id' => function () {
return AssetModel::where('name', 'Macbook Pro 13"')->first() ?? AssetModel::factory()->mbp13Model();
},
]; ];
}); });
} }
@ -69,8 +64,12 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 1, 'model_id' => function () {
'status_id' => 2, return AssetModel::where('name', 'Macbook Pro 13"')->first() ?? AssetModel::factory()->mbp13Model();
},
'status_id' => function () {
return Statuslabel::where('name', 'Pending')->first() ?? Statuslabel::factory()->pending()->make(['name' => 'Pending']);
},
]; ];
}); });
} }
@ -79,8 +78,12 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 1, 'model_id' => function () {
'status_id' => 3, return AssetModel::where('name', 'Macbook Pro 13"')->first() ?? AssetModel::factory()->mbp13Model();
},
'status_id' => function () {
return Statuslabel::where('name', 'Archived')->first() ?? Statuslabel::factory()->archived()->make(['name' => 'Archived']);
},
]; ];
}); });
} }
@ -89,7 +92,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 2, 'model_id' => function () {
return AssetModel::where('name', 'Macbook Air')->first() ?? AssetModel::factory()->mbpAirModel();
},
]; ];
}); });
} }
@ -98,7 +103,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 3, 'model_id' => function () {
return AssetModel::where('name', 'Surface')->first() ?? AssetModel::factory()->surfaceModel();
},
]; ];
}); });
} }
@ -107,7 +114,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 4, 'model_id' => function () {
return AssetModel::where('name', 'XPS 13')->first() ?? AssetModel::factory()->xps13Model();
},
]; ];
}); });
} }
@ -116,7 +125,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 5, 'model_id' => function () {
return AssetModel::where('name', 'Spectre')->first() ?? AssetModel::factory()->spectreModel();
},
]; ];
}); });
} }
@ -125,7 +136,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 6, 'model_id' => function () {
return AssetModel::where('name', 'ZenBook UX310')->first() ?? AssetModel::factory()->zenbookModel();
},
]; ];
}); });
} }
@ -134,7 +147,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 7, 'model_id' => function () {
return AssetModel::where('name', 'Yoga 910')->first() ?? AssetModel::factory()->yogaModel();
},
]; ];
}); });
} }
@ -143,7 +158,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 8, 'model_id' => function () {
return AssetModel::where('name', 'iMac Pro')->first() ?? AssetModel::factory()->macproModel();
},
]; ];
}); });
} }
@ -152,7 +169,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 9, 'model_id' => function () {
return AssetModel::where('name', 'Lenovo Intel Core i5')->first() ?? AssetModel::factory()->lenovoI5Model();
},
]; ];
}); });
} }
@ -161,7 +180,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 10, 'model_id' => function () {
return AssetModel::where('name', 'OptiPlex')->first() ?? AssetModel::factory()->optiplexModel();
},
]; ];
}); });
} }
@ -170,7 +191,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 11, 'model_id' => function () {
return AssetModel::where('name', 'SoundStation 2')->first() ?? AssetModel::factory()->polycomModel();
},
]; ];
}); });
} }
@ -179,7 +202,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 12, 'model_id' => function () {
return AssetModel::where('name', 'Polycom CX3000 IP Conference Phone')->first() ?? AssetModel::factory()->polycomcxModel();
},
]; ];
}); });
} }
@ -188,7 +213,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 13, 'model_id' => function () {
return AssetModel::where('name', 'iPad Pro')->first() ?? AssetModel::factory()->ipadModel();
},
]; ];
}); });
} }
@ -197,7 +224,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 14, 'model_id' => function () {
return AssetModel::where('name', 'Tab3')->first() ?? AssetModel::factory()->tab3Model();
},
]; ];
}); });
} }
@ -206,7 +235,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 15, 'model_id' => function () {
return AssetModel::where('name', 'iPhone 11')->first() ?? AssetModel::factory()->iphone11Model();
},
]; ];
}); });
} }
@ -215,7 +246,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 16, 'model_id' => function () {
return AssetModel::where('name', 'iPhone 12')->first() ?? AssetModel::factory()->iphone12Model();
},
]; ];
}); });
} }
@ -224,7 +257,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 17, 'model_id' => function () {
return AssetModel::where('name', 'Ultrafine 4k')->first() ?? AssetModel::factory()->ultrafine();
},
]; ];
}); });
} }
@ -233,7 +268,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 18, 'model_id' => function () {
return AssetModel::where('name', 'Ultrasharp U2415')->first() ?? AssetModel::factory()->ultrasharp();
},
]; ];
}); });
} }
@ -242,9 +279,8 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 1, 'assigned_to' => User::factory(),
'assigned_to' => \App\Models\User::factory()->create()->id, 'assigned_type' => User::class,
'assigned_type' => \App\Models\User::class,
]; ];
}); });
} }
@ -253,9 +289,8 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 1, 'assigned_to' => Location::factory(),
'assigned_to' => \App\Models\Location::factory()->create()->id, 'assigned_type' => Location::class,
'assigned_type' => \App\Models\Location::class,
]; ];
}); });
} }
@ -265,8 +300,8 @@ class AssetFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 1, 'model_id' => 1,
'assigned_to' => \App\Models\Asset::factory()->create()->id, 'assigned_to' => Asset::factory(),
'assigned_type' => \App\Models\Asset::class, 'assigned_type' => Asset::class,
]; ];
}); });
} }
@ -275,7 +310,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 1, 'model_id' => function () {
return AssetModel::where('name', 'Macbook Pro 13')->first() ?? AssetModel::factory()->mbp13Model();
},
]; ];
}); });
} }
@ -284,7 +321,9 @@ class AssetFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'model_id' => 1, 'model_id' => function () {
return AssetModel::where('name', 'Macbook Pro 13')->first() ?? AssetModel::factory()->mbp13Model();
},
'deleted_at' => $this->faker->dateTime(), 'deleted_at' => $this->faker->dateTime(),
]; ];
}); });

View file

@ -3,19 +3,10 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\Asset; use App\Models\Asset;
use App\Models\AssetModel; use App\Models\AssetMaintenance;
use App\Models\Category; use App\Models\Supplier;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Factories related exclusively to modelling assets.
|
*/
class AssetMaintenanceFactory extends Factory class AssetMaintenanceFactory extends Factory
{ {
/** /**
@ -23,7 +14,7 @@ class AssetMaintenanceFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\AssetMaintenance::class; protected $model = AssetMaintenance::class;
/** /**
* Define the model's default state. * Define the model's default state.
@ -33,14 +24,10 @@ class AssetMaintenanceFactory extends Factory
public function definition() public function definition()
{ {
return [ return [
'asset_id' => function () { 'asset_id' => Asset::factory(),
return \App\Models\Asset::factory()->create()->id; 'supplier_id' => Supplier::factory(),
},
'supplier_id' => function () {
return \App\Models\Supplier::factory()->create()->id;
},
'asset_maintenance_type' => $this->faker->randomElement(['maintenance', 'repair', 'upgrade']), 'asset_maintenance_type' => $this->faker->randomElement(['maintenance', 'repair', 'upgrade']),
'title' => $this->faker->sentence, 'title' => $this->faker->sentence(),
'start_date' => $this->faker->date(), 'start_date' => $this->faker->date(),
'is_warranty' => $this->faker->boolean(), 'is_warranty' => $this->faker->boolean(),
'notes' => $this->faker->paragraph(), 'notes' => $this->faker->paragraph(),

View file

@ -2,68 +2,14 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\AssetModel;
use App\Models\CustomFieldset;
use App\Models\Depreciation;
use App\Models\Manufacturer;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\Category; use App\Models\Category;
/*
|--------------------------------------------------------------------------
| Asset Model Factories
|--------------------------------------------------------------------------
|
| Factories related exclusively to creating models ..
|
*/
/*
|--------------------------------------------------------------------------
| Laptops
|--------------------------------------------------------------------------
*/
// 1
// 2
// 3
// 4
// 5
// 6
// 7
/*
|--------------------------------------------------------------------------
| Desktops
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| Conference Phones
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| Tablets
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| Mobile Phones
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| Displays
|--------------------------------------------------------------------------
*/
class AssetModelFactory extends Factory class AssetModelFactory extends Factory
{ {
/** /**
@ -71,7 +17,7 @@ class AssetModelFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\AssetModel::class; protected $model = AssetModel::class;
/** /**
* Define the model's default state. * Define the model's default state.
@ -81,8 +27,9 @@ class AssetModelFactory extends Factory
public function definition() public function definition()
{ {
return [ return [
'user_id' => 1, 'user_id' => User::factory()->superuser(),
'name' => $this->faker->catchPhrase(), 'name' => $this->faker->catchPhrase(),
'category_id' => Category::factory(),
'model_number' => $this->faker->creditCardNumber(), 'model_number' => $this->faker->creditCardNumber(),
'notes' => 'Created by demo seeder', 'notes' => 'Created by demo seeder',
@ -94,11 +41,17 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Macbook Pro 13"', 'name' => 'Macbook Pro 13"',
'category_id' => 1, 'category_id' => function () {
return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory();
},
'eol' => '36', 'eol' => '36',
'depreciation_id' => 1, 'depreciation_id' => function () {
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
},
'image' => 'mbp.jpg', 'image' => 'mbp.jpg',
'fieldset_id' => 2, 'fieldset_id' => function () {
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
},
]; ];
}); });
} }
@ -108,12 +61,20 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Macbook Air', 'name' => 'Macbook Air',
'category_id' => 1, 'category_id' => function () {
'manufacturer_id' => 1, return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
},
'eol' => '36', 'eol' => '36',
'depreciation_id' => 1, 'depreciation_id' => function () {
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
},
'image' => 'macbookair.jpg', 'image' => 'macbookair.jpg',
'fieldset_id' => 2, 'fieldset_id' => function () {
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
},
]; ];
}); });
} }
@ -123,12 +84,20 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Surface', 'name' => 'Surface',
'category_id' => 1, 'category_id' => function () {
'manufacturer_id' => 2, return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Microsoft')->first() ?? Manufacturer::factory()->microsoft();
},
'eol' => '36', 'eol' => '36',
'depreciation_id' => 1, 'depreciation_id' => function () {
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
},
'image' => 'surface.jpg', 'image' => 'surface.jpg',
'fieldset_id' => 2, 'fieldset_id' => function () {
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
},
]; ];
}); });
} }
@ -138,12 +107,20 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'XPS 13', 'name' => 'XPS 13',
'category_id' => 1, 'category_id' => function () {
'manufacturer_id' => 3, return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Dell')->first() ?? Manufacturer::factory()->dell();
},
'eol' => '36', 'eol' => '36',
'depreciation_id' => 1, 'depreciation_id' => function () {
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
},
'image' => 'xps.jpg', 'image' => 'xps.jpg',
'fieldset_id' => 2, 'fieldset_id' => function () {
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
},
]; ];
}); });
} }
@ -153,12 +130,20 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'ZenBook UX310', 'name' => 'ZenBook UX310',
'category_id' => 1, 'category_id' => function () {
'manufacturer_id' => 4, return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Asus')->first() ?? Manufacturer::factory()->asus();
},
'eol' => '36', 'eol' => '36',
'depreciation_id' => 1, 'depreciation_id' => function () {
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
},
'image' => 'zenbook.jpg', 'image' => 'zenbook.jpg',
'fieldset_id' => 2, 'fieldset_id' => function () {
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
},
]; ];
}); });
} }
@ -168,12 +153,20 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Spectre', 'name' => 'Spectre',
'category_id' => 1, 'category_id' => function () {
'manufacturer_id' => 5, return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'HP')->first() ?? Manufacturer::factory()->hp();
},
'eol' => '36', 'eol' => '36',
'depreciation_id' => 1, 'depreciation_id' => function () {
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
},
'image' => 'spectre.jpg', 'image' => 'spectre.jpg',
'fieldset_id' => 2, 'fieldset_id' => function () {
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
},
]; ];
}); });
} }
@ -183,12 +176,20 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Yoga 910', 'name' => 'Yoga 910',
'category_id' => 1, 'category_id' => function () {
'manufacturer_id' => 6, return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Lenovo')->first() ?? Manufacturer::factory()->lenovo();
},
'eol' => '36', 'eol' => '36',
'depreciation_id' => 1, 'depreciation_id' => function () {
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
},
'image' => 'yoga.png', 'image' => 'yoga.png',
'fieldset_id' => 2, 'fieldset_id' => function () {
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
},
]; ];
}); });
} }
@ -198,12 +199,20 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'iMac Pro', 'name' => 'iMac Pro',
'category_id' => 2, 'category_id' => function (){
'manufacturer_id' => 1, return Category::where('name', 'Desktops')->first() ?? Category::factory()->assetDesktopCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
},
'eol' => '24', 'eol' => '24',
'depreciation_id' => 1, 'depreciation_id' => function () {
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
},
'image' => 'imacpro.jpg', 'image' => 'imacpro.jpg',
'fieldset_id' => 2, 'fieldset_id' => function () {
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
},
]; ];
}); });
} }
@ -213,12 +222,20 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Lenovo Intel Core i5', 'name' => 'Lenovo Intel Core i5',
'category_id' => 2, 'category_id' => function () {
'manufacturer_id' => 6, return Category::where('name', 'Desktops')->first() ?? Category::factory()->assetDesktopCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Lenovo')->first() ?? Manufacturer::factory()->lenovo();
},
'eol' => '24', 'eol' => '24',
'depreciation_id' => 1, 'depreciation_id' => function () {
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
},
'image' => 'lenovoi5.png', 'image' => 'lenovoi5.png',
'fieldset_id' => 2, 'fieldset_id' => function () {
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
},
]; ];
}); });
} }
@ -228,13 +245,21 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'OptiPlex', 'name' => 'OptiPlex',
'category_id' => 2, 'category_id' => function (){
'manufacturer_id' => 3, return Category::where('name', 'Desktops')->first() ?? Category::factory()->assetDesktopCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Dell')->first() ?? Manufacturer::factory()->dell();
},
'model_number' => '5040 (MRR81)', 'model_number' => '5040 (MRR81)',
'eol' => '24', 'eol' => '24',
'depreciation_id' => 1, 'depreciation_id' => function () {
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
},
'image' => 'optiplex.jpg', 'image' => 'optiplex.jpg',
'fieldset_id' => 2, 'fieldset_id' => function () {
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
},
]; ];
}); });
} }
@ -244,10 +269,16 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'SoundStation 2', 'name' => 'SoundStation 2',
'category_id' => 6, 'category_id' => function () {
'manufacturer_id' => 8, return Category::where('name', 'VOIP Phones')->first() ?? Category::factory()->assetVoipCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Polycom')->first() ?? Manufacturer::factory()->polycom();
},
'eol' => '12', 'eol' => '12',
'depreciation_id' => 1, 'depreciation_id' => function () {
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
},
'image' => 'soundstation.jpg', 'image' => 'soundstation.jpg',
]; ];
}); });
@ -258,10 +289,16 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Polycom CX3000 IP Conference Phone', 'name' => 'Polycom CX3000 IP Conference Phone',
'category_id' => 6, 'category_id' => function () {
'manufacturer_id' => 8, return Category::where('name', 'VOIP Phones')->first() ?? Category::factory()->assetVoipCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Polycom')->first() ?? Manufacturer::factory()->polycom();
},
'eol' => '12', 'eol' => '12',
'depreciation_id' => 1, 'depreciation_id' => function () {
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
},
'image' => 'cx3000.png', 'image' => 'cx3000.png',
]; ];
}); });
@ -272,10 +309,16 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'iPad Pro', 'name' => 'iPad Pro',
'category_id' => 3, 'category_id' => function () {
'manufacturer_id' => 1, return Category::where('name', 'Tablets')->first() ?? Category::factory()->assetTabletCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
},
'eol' => '12', 'eol' => '12',
'depreciation_id' => 1, 'depreciation_id' => function () {
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
},
'image' => 'ipad.jpg', 'image' => 'ipad.jpg',
]; ];
}); });
@ -286,10 +329,16 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Tab3', 'name' => 'Tab3',
'category_id' => 3, 'category_id' => function () {
'manufacturer_id' => 6, return Category::where('name', 'Tablets')->first() ?? Category::factory()->assetTabletCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Lenovo')->first() ?? Manufacturer::factory()->lenovo();
},
'eol' => '12', 'eol' => '12',
'depreciation_id' => 1, 'depreciation_id' => function () {
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
},
'image' => 'tab3.png', 'image' => 'tab3.png',
]; ];
}); });
@ -300,12 +349,20 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'iPhone 11', 'name' => 'iPhone 11',
'category_id' => 4, 'category_id' => function () {
'manufacturer_id' => 1, return Category::where('name', 'Mobile Phones')->first() ?? Category::factory()->assetMobileCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
},
'eol' => '12', 'eol' => '12',
'depreciation_id' => 3, 'depreciation_id' => function () {
return Depreciation::where('name', 'Mobile Phone Depreciation')->first() ?? Depreciation::factory()->mobilePhones();
},
'image' => 'iphone11.jpeg', 'image' => 'iphone11.jpeg',
'fieldset_id' => 1, 'fieldset_id' => function () {
return CustomFieldset::where('name', 'Mobile Devices')->first() ?? CustomFieldset::factory()->mobile();
},
]; ];
}); });
} }
@ -315,12 +372,20 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'iPhone 12', 'name' => 'iPhone 12',
'category_id' => 4, 'category_id' => function () {
'manufacturer_id' => 1, return Category::where('name', 'Mobile Phones')->first() ?? Category::factory()->assetMobileCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
},
'eol' => '12', 'eol' => '12',
'depreciation_id' => 1, 'depreciation_id' => function () {
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
},
'image' => 'iphone12.jpeg', 'image' => 'iphone12.jpeg',
'fieldset_id' => 1, 'fieldset_id' => function () {
return CustomFieldset::where('name', 'Mobile Devices')->first() ?? CustomFieldset::factory()->mobile();
},
]; ];
}); });
} }
@ -330,10 +395,16 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Ultrafine 4k', 'name' => 'Ultrafine 4k',
'category_id' => 5, 'category_id' => function () {
'manufacturer_id' => 7, return Category::where('name', 'Displays')->first() ?? Category::factory()->assetDisplayCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'LG')->first() ?? Manufacturer::factory()->lg();
},
'eol' => '12', 'eol' => '12',
'depreciation_id' => 2, 'depreciation_id' => function () {
return Depreciation::where('name', 'Display Depreciation')->first() ?? Depreciation::factory()->display();
},
'image' => 'ultrafine.jpg', 'image' => 'ultrafine.jpg',
]; ];
}); });
@ -344,10 +415,16 @@ class AssetModelFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Ultrasharp U2415', 'name' => 'Ultrasharp U2415',
'category_id' => 5, 'category_id' => function () {
'manufacturer_id' => 3, return Category::where('name', 'Displays')->first() ?? Category::factory()->assetDisplayCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Dell')->first() ?? Manufacturer::factory()->dell();
},
'eol' => '12', 'eol' => '12',
'depreciation_id' => 2, 'depreciation_id' => function () {
return Depreciation::where('name', 'Display Depreciation')->first() ?? Depreciation::factory()->display();
},
'image' => 'ultrasharp.jpg', 'image' => 'ultrasharp.jpg',
]; ];
}); });

View file

@ -2,18 +2,10 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\Category; use App\Models\Category;
/*
|--------------------------------------------------------------------------
| Category Factories
|--------------------------------------------------------------------------
|
| Factories related exclusively to creating categories and the various states..
|
*/
class CategoryFactory extends Factory class CategoryFactory extends Factory
{ {
/** /**
@ -21,7 +13,7 @@ class CategoryFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\Category::class; protected $model = Category::class;
/** /**
* Define the model's default state. * Define the model's default state.
@ -32,18 +24,19 @@ class CategoryFactory extends Factory
{ {
return [ return [
'name' => $this->faker->catchPhrase(), 'name' => $this->faker->catchPhrase(),
'category_type' => 'asset',
'checkin_email' => $this->faker->boolean(), 'checkin_email' => $this->faker->boolean(),
'eula_text' => $this->faker->paragraph(), 'eula_text' => $this->faker->paragraph(),
'require_acceptance' => false, 'require_acceptance' => false,
'use_default_eula' => $this->faker->boolean(), 'use_default_eula' => $this->faker->boolean(),
'user_id' => 1, 'user_id' => User::factory()->superuser(),
]; ];
} }
// usage: Category::factory()->assetLaptopCategory(); // usage: Category::factory()->assetLaptopCategory();
public function assetLaptopCategory() public function assetLaptopCategory()
{ {
return Category::factory()->create([ return $this->state([
'name' => 'Laptops', 'name' => 'Laptops',
'category_type' => 'asset', 'category_type' => 'asset',
'require_acceptance' => true, 'require_acceptance' => true,
@ -53,7 +46,7 @@ class CategoryFactory extends Factory
// usage: Category::factory()->assetDesktopCategory(); // usage: Category::factory()->assetDesktopCategory();
public function assetDesktopCategory() public function assetDesktopCategory()
{ {
return Category::factory()->create([ return $this->state([
'name' => 'Desktops', 'name' => 'Desktops',
'category_type' => 'asset', 'category_type' => 'asset',
'require_acceptance' => true, 'require_acceptance' => true,
@ -63,7 +56,7 @@ class CategoryFactory extends Factory
// usage: Category::factory()->assetDisplayCategory(); // usage: Category::factory()->assetDisplayCategory();
public function assetDisplayCategory() public function assetDisplayCategory()
{ {
return Category::factory()->create([ return $this->state([
'name' => 'Displays', 'name' => 'Displays',
'category_type' => 'asset', 'category_type' => 'asset',
]); ]);
@ -72,7 +65,7 @@ class CategoryFactory extends Factory
// usage: Category::factory()->assetTabletCategory(); // usage: Category::factory()->assetTabletCategory();
public function assetTabletCategory() public function assetTabletCategory()
{ {
return Category::factory()->create([ return $this->state([
'name' => 'Tablets', 'name' => 'Tablets',
'category_type' => 'asset', 'category_type' => 'asset',
]); ]);
@ -81,7 +74,7 @@ class CategoryFactory extends Factory
// usage: Category::factory()->assetMobileCategory(); // usage: Category::factory()->assetMobileCategory();
public function assetMobileCategory() public function assetMobileCategory()
{ {
return Category::factory()->create([ return $this->state([
'name' => 'Mobile Phones', 'name' => 'Mobile Phones',
'category_type' => 'asset', 'category_type' => 'asset',
]); ]);
@ -90,7 +83,7 @@ class CategoryFactory extends Factory
// usage: Category::factory()->assetConferenceCategory(); // usage: Category::factory()->assetConferenceCategory();
public function assetConferenceCategory() public function assetConferenceCategory()
{ {
return Category::factory()->create([ return $this->state([
'name' => 'Conference Phones', 'name' => 'Conference Phones',
'category_type' => 'asset', 'category_type' => 'asset',
]); ]);
@ -100,7 +93,7 @@ class CategoryFactory extends Factory
// usage: Category::factory()->assetVoipCategory(); // usage: Category::factory()->assetVoipCategory();
public function assetVoipCategory() public function assetVoipCategory()
{ {
return Category::factory()->create([ return $this->state([
'name' => 'VOIP Phones', 'name' => 'VOIP Phones',
'category_type' => 'asset', 'category_type' => 'asset',
]); ]);
@ -109,8 +102,8 @@ class CategoryFactory extends Factory
// usage: Category::factory()->accessoryKeyboardCategory(); // usage: Category::factory()->accessoryKeyboardCategory();
public function accessoryKeyboardCategory() public function accessoryKeyboardCategory()
{ {
return Category::factory()->create([ return $this->state([
'name' => 'Keyboardss', 'name' => 'Keyboards',
'category_type' => 'accessory', 'category_type' => 'accessory',
]); ]);
} }
@ -119,7 +112,7 @@ class CategoryFactory extends Factory
// usage: Category::factory()->accessoryMouseCategory(); // usage: Category::factory()->accessoryMouseCategory();
public function accessoryMouseCategory() public function accessoryMouseCategory()
{ {
return Category::factory()->create([ return $this->state([
'name' => 'Mouse', 'name' => 'Mouse',
'category_type' => 'accessory', 'category_type' => 'accessory',
]); ]);
@ -128,7 +121,7 @@ class CategoryFactory extends Factory
// usage: Category::factory()->componentHddCategory(); // usage: Category::factory()->componentHddCategory();
public function componentHddCategory() public function componentHddCategory()
{ {
return Category::factory()->create([ return $this->state([
'name' => 'HDD/SSD', 'name' => 'HDD/SSD',
'category_type' => 'component', 'category_type' => 'component',
]); ]);
@ -137,7 +130,7 @@ class CategoryFactory extends Factory
// usage: Category::factory()->componentRamCategory(); // usage: Category::factory()->componentRamCategory();
public function componentRamCategory() public function componentRamCategory()
{ {
return Category::factory()->create([ return $this->state([
'name' => 'RAM', 'name' => 'RAM',
'category_type' => 'component', 'category_type' => 'component',
]); ]);
@ -146,7 +139,7 @@ class CategoryFactory extends Factory
// usage: Category::factory()->consumablePaperCategory(); // usage: Category::factory()->consumablePaperCategory();
public function consumablePaperCategory() public function consumablePaperCategory()
{ {
return Category::factory()->create([ return $this->state([
'name' => 'Printer Paper', 'name' => 'Printer Paper',
'category_type' => 'consumable', 'category_type' => 'consumable',
]); ]);
@ -155,7 +148,7 @@ class CategoryFactory extends Factory
// usage: Category::factory()->consumableInkCategory(); // usage: Category::factory()->consumableInkCategory();
public function consumableInkCategory() public function consumableInkCategory()
{ {
return Category::factory()->create([ return $this->state([
'name' => 'Printer Ink', 'name' => 'Printer Ink',
'category_type' => 'consumable', 'category_type' => 'consumable',
]); ]);
@ -164,7 +157,7 @@ class CategoryFactory extends Factory
// usage: Category::factory()->licenseGraphicsCategory(); // usage: Category::factory()->licenseGraphicsCategory();
public function licenseGraphicsCategory() public function licenseGraphicsCategory()
{ {
return Category::factory()->create([ return $this->state([
'name' => 'Graphics Software', 'name' => 'Graphics Software',
'category_type' => 'license', 'category_type' => 'license',
]); ]);
@ -173,7 +166,7 @@ class CategoryFactory extends Factory
// usage: Category::factory()->licenseGraphicsCategory(); // usage: Category::factory()->licenseGraphicsCategory();
public function licenseOfficeCategory() public function licenseOfficeCategory()
{ {
return Category::factory()->create([ return $this->state([
'name' => 'Office Software', 'name' => 'Office Software',
'category_type' => 'license', 'category_type' => 'license',
]); ]);

View file

@ -1,25 +1,8 @@
<?php <?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
namespace Database\Factories; namespace Database\Factories;
use App\Models\AssetModel;
use App\Models\Category;
use App\Models\Company; use App\Models\Company;
use App\Models\Location;
use App\Models\Manufacturer;
use App\Models\Statuslabel;
use App\Models\Supplier;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
class CompanyFactory extends Factory class CompanyFactory extends Factory
@ -29,7 +12,7 @@ class CompanyFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\Company::class; protected $model = Company::class;
/** /**
* Define the model's default state. * Define the model's default state.
@ -39,7 +22,7 @@ class CompanyFactory extends Factory
public function definition() public function definition()
{ {
return [ return [
'name' => $this->faker->company, 'name' => $this->faker->company(),
]; ];
} }
} }

View file

@ -2,17 +2,12 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\Category;
use App\Models\Company;
use App\Models\Component;
use App\Models\Location;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/*
|--------------------------------------------------------------------------
| Components Factories
|--------------------------------------------------------------------------
|
| Factories related exclusively to creating components ..
|
*/
class ComponentFactory extends Factory class ComponentFactory extends Factory
{ {
/** /**
@ -20,7 +15,7 @@ class ComponentFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\Component::class; protected $model = Component::class;
/** /**
* Define the model's default state. * Define the model's default state.
@ -31,19 +26,15 @@ class ComponentFactory extends Factory
{ {
return [ return [
'name' => $this->faker->text(20), 'name' => $this->faker->text(20),
'category_id' => function () { 'category_id' => Category::factory(),
return \App\Models\Category::factory()->create()->id; 'location_id' => Location::factory(),
}, 'serial' => $this->faker->uuid(),
'location_id' => 1,
'serial' => $this->faker->uuid,
'qty' => $this->faker->numberBetween(3, 10), 'qty' => $this->faker->numberBetween(3, 10),
'order_number' => $this->faker->numberBetween(1000000, 50000000), 'order_number' => $this->faker->numberBetween(1000000, 50000000),
'purchase_date' => $this->faker->dateTime()->format('Y-m-d'), 'purchase_date' => $this->faker->dateTime()->format('Y-m-d'),
'purchase_cost' => $this->faker->randomFloat(2), 'purchase_cost' => $this->faker->randomFloat(2),
'min_amt' => $this->faker->numberBetween($min = 1, $max = 2), 'min_amt' => $this->faker->numberBetween($min = 1, $max = 2),
'company_id' => function () { 'company_id' => Company::factory(),
return \App\Models\Company::factory()->create()->id;
},
]; ];
} }
@ -52,11 +43,12 @@ class ComponentFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Crucial 4GB DDR3L-1600 SODIMM', 'name' => 'Crucial 4GB DDR3L-1600 SODIMM',
'category_id' => 13, 'category_id' => function () {
return Category::where('name', 'RAM')->first() ?? Category::factory()->componentRamCategory();
},
'qty' => 10, 'qty' => 10,
'min_amt' => 2, 'min_amt' => 2,
'location_id' => 3, 'location_id' => Location::factory(),
'company_id' => 2,
]; ];
}); });
} }
@ -66,7 +58,9 @@ class ComponentFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Crucial 8GB DDR3L-1600 SODIMM Memory for Mac', 'name' => 'Crucial 8GB DDR3L-1600 SODIMM Memory for Mac',
'category_id' => 13, 'category_id' => function () {
return Category::where('name', 'RAM')->first() ?? Category::factory()->componentRamCategory();
},
'qty' => 10, 'qty' => 10,
'min_amt' => 2, 'min_amt' => 2,
]; ];
@ -78,7 +72,9 @@ class ComponentFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Crucial BX300 120GB SATA Internal SSD', 'name' => 'Crucial BX300 120GB SATA Internal SSD',
'category_id' => 12, 'category_id' => function () {
return Category::where('name', 'HDD/SSD')->first() ?? Category::factory()->componentHddCategory();
},
'qty' => 10, 'qty' => 10,
'min_amt' => 2, 'min_amt' => 2,
]; ];
@ -90,7 +86,9 @@ class ComponentFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Crucial BX300 240GB SATA Internal SSD', 'name' => 'Crucial BX300 240GB SATA Internal SSD',
'category_id' => 12, 'category_id' => function () {
return Category::where('name', 'HDD/SSD')->first() ?? Category::factory()->componentHddCategory();
},
'qty' => 10, 'qty' => 10,
'min_amt' => 2, 'min_amt' => 2,
]; ];

View file

@ -2,17 +2,13 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\Category;
use App\Models\Company;
use App\Models\Consumable;
use App\Models\Manufacturer;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/*
|--------------------------------------------------------------------------
| Consumables Factories
|--------------------------------------------------------------------------
|
| Factories related exclusively to creating consumables ..
|
*/
class ConsumableFactory extends Factory class ConsumableFactory extends Factory
{ {
/** /**
@ -20,7 +16,7 @@ class ConsumableFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\Consumable::class; protected $model = Consumable::class;
/** /**
* Define the model's default state. * Define the model's default state.
@ -30,13 +26,16 @@ class ConsumableFactory extends Factory
public function definition() public function definition()
{ {
return [ return [
'user_id' => 1, 'name' => $this->faker->word(),
'category_id' => Category::factory(),
'user_id' => User::factory()->superuser(),
'item_no' => $this->faker->numberBetween(1000000, 50000000), 'item_no' => $this->faker->numberBetween(1000000, 50000000),
'order_number' => $this->faker->numberBetween(1000000, 50000000), 'order_number' => $this->faker->numberBetween(1000000, 50000000),
'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'), 'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'),
'purchase_cost' => $this->faker->randomFloat(2, 1, 50), 'purchase_cost' => $this->faker->randomFloat(2, 1, 50),
'qty' => $this->faker->numberBetween(5, 10), 'qty' => $this->faker->numberBetween(5, 10),
'min_amt' => $this->faker->numberBetween($min = 1, $max = 2), 'min_amt' => $this->faker->numberBetween($min = 1, $max = 2),
'company_id' => Company::factory(),
]; ];
} }
@ -45,11 +44,14 @@ class ConsumableFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Cardstock (White)', 'name' => 'Cardstock (White)',
'category_id' => 10, 'category_id' => function () {
'manufacturer_id' => 10, return Category::where('name', 'Printer Paper')->first() ?? Category::factory()->consumablePaperCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Avery')->first() ?? Manufacturer::factory()->avery();
},
'qty' => 10, 'qty' => 10,
'min_amt' => 2, 'min_amt' => 2,
'company_id' => 3,
]; ];
}); });
} }
@ -59,8 +61,12 @@ class ConsumableFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Laserjet Paper (Ream)', 'name' => 'Laserjet Paper (Ream)',
'category_id' => 10, 'category_id' => function () {
'manufacturer_id' => 10, return Category::where('name', 'Printer Paper')->first() ?? Category::factory()->consumablePaperCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'Avery')->first() ?? Manufacturer::factory()->avery();
},
'qty' => 20, 'qty' => 20,
'min_amt' => 2, 'min_amt' => 2,
]; ];
@ -72,8 +78,12 @@ class ConsumableFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'name' => 'Laserjet Toner (black)', 'name' => 'Laserjet Toner (black)',
'category_id' => 11, 'category_id' => function () {
'manufacturer_id' => 5, return Category::where('name', 'Printer Ink')->first() ?? Category::factory()->consumableInkCategory();
},
'manufacturer_id' => function () {
return Manufacturer::where('name', 'HP')->first() ?? Manufacturer::factory()->hp();
},
'qty' => 20, 'qty' => 20,
'min_amt' => 2, 'min_amt' => 2,
]; ];

View file

@ -2,6 +2,7 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\CustomField;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
class CustomFieldFactory extends Factory class CustomFieldFactory extends Factory
@ -11,7 +12,7 @@ class CustomFieldFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\CustomField::class; protected $model = CustomField::class;
/** /**
* Define the model's default state. * Define the model's default state.
@ -21,7 +22,7 @@ class CustomFieldFactory extends Factory
public function definition() public function definition()
{ {
return [ return [
'name' => $this->faker->catchPhrase, 'name' => $this->faker->catchPhrase(),
'format' => '', 'format' => '',
'element' => 'text', 'element' => 'text',
]; ];

View file

@ -2,6 +2,7 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\CustomFieldset;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
class CustomFieldsetFactory extends Factory class CustomFieldsetFactory extends Factory
@ -11,7 +12,7 @@ class CustomFieldsetFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\CustomFieldset::class; protected $model = CustomFieldset::class;
/** /**
* Define the model's default state. * Define the model's default state.
@ -21,7 +22,7 @@ class CustomFieldsetFactory extends Factory
public function definition() public function definition()
{ {
return [ return [
'name' => $this->faker->catchPhrase, 'name' => $this->faker->catchPhrase(),
]; ];
} }

View file

@ -2,17 +2,11 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\Department;
use App\Models\Location;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/*
|--------------------------------------------------------------------------
| Asset Model Factories
|--------------------------------------------------------------------------
|
| Factories related exclusively to creating models ..
|
*/
class DepartmentFactory extends Factory class DepartmentFactory extends Factory
{ {
/** /**
@ -20,7 +14,7 @@ class DepartmentFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\Department::class; protected $model = Department::class;
/** /**
* Define the model's default state. * Define the model's default state.
@ -30,8 +24,9 @@ class DepartmentFactory extends Factory
public function definition() public function definition()
{ {
return [ return [
'user_id' => 1, 'name' => $this->faker->word() . ' Department',
'location_id' => rand(1, 5), 'user_id' => User::factory()->superuser(),
'location_id' => Location::factory(),
]; ];
} }

View file

@ -2,17 +2,10 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\Depreciation;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/*
|--------------------------------------------------------------------------
| Asset Model Factories
|--------------------------------------------------------------------------
|
| Factories related exclusively to creating models ..
|
*/
class DepreciationFactory extends Factory class DepreciationFactory extends Factory
{ {
/** /**
@ -20,7 +13,7 @@ class DepreciationFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\Depreciation::class; protected $model = Depreciation::class;
/** /**
* Define the model's default state. * Define the model's default state.
@ -31,7 +24,7 @@ class DepreciationFactory extends Factory
{ {
return [ return [
'name' => $this->faker->catchPhrase(), 'name' => $this->faker->catchPhrase(),
'user_id' => 1, 'user_id' => User::factory()->superuser(),
'months' => 36, 'months' => 36,
]; ];
} }

View file

@ -1,25 +1,8 @@
<?php <?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
namespace Database\Factories; namespace Database\Factories;
use App\Models\AssetModel; use App\Models\Group;
use App\Models\Category;
use App\Models\Company;
use App\Models\Location;
use App\Models\Manufacturer;
use App\Models\Statuslabel;
use App\Models\Supplier;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
class GroupFactory extends Factory class GroupFactory extends Factory
@ -29,7 +12,7 @@ class GroupFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\Group::class; protected $model = Group::class;
/** /**
* Define the model's default state. * Define the model's default state.
@ -39,7 +22,7 @@ class GroupFactory extends Factory
public function definition() public function definition()
{ {
return [ return [
'name' => $this->faker->name, 'name' => $this->faker->name(),
]; ];
} }
} }

View file

@ -2,25 +2,12 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\Category; use App\Models\Category;
use App\Models\License;
use App\Models\Manufacturer;
use App\Models\Supplier;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/*
|--------------------------------------------------------------------------
| Asset Model Factories
|--------------------------------------------------------------------------
|
| Factories related exclusively to creating models ..
|
*/
// 1
// 2
// 3
// 4
class LicenseFactory extends Factory class LicenseFactory extends Factory
{ {
/** /**
@ -28,7 +15,7 @@ class LicenseFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\License::class; protected $model = License::class;
/** /**
* Define the model's default state. * Define the model's default state.
@ -37,13 +24,11 @@ class LicenseFactory extends Factory
*/ */
public function definition() public function definition()
{ {
return [ return [
'user_id' => 1, 'user_id' => User::factory()->superuser(),
'name' => $this->faker->name, 'name' => $this->faker->name(),
'license_email' => $this->faker->safeEmail, 'license_email' => $this->faker->safeEmail(),
'serial' => $this->faker->uuid, 'serial' => $this->faker->uuid(),
'notes' => 'Created by DB seeder', 'notes' => 'Created by DB seeder',
'seats' => $this->faker->numberBetween(1, 10), 'seats' => $this->faker->numberBetween(1, 10),
'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'), 'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'),
@ -51,8 +36,8 @@ class LicenseFactory extends Factory
'expiration_date' => $this->faker->dateTimeBetween('now', '+3 years', date_default_timezone_get())->format('Y-m-d H:i:s'), 'expiration_date' => $this->faker->dateTimeBetween('now', '+3 years', date_default_timezone_get())->format('Y-m-d H:i:s'),
'reassignable' => $this->faker->boolean(), 'reassignable' => $this->faker->boolean(),
'termination_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d H:i:s'), 'termination_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d H:i:s'),
'supplier_id' => $this->faker->numberBetween(1, 5), 'supplier_id' => Supplier::factory(),
'category_id' => Category::where('category_type', '=', 'license')->inRandomOrder()->first()->id 'category_id' => Category::factory(),
]; ];
} }
@ -61,12 +46,16 @@ class LicenseFactory extends Factory
return $this->state(function () { return $this->state(function () {
$data = [ $data = [
'name' => 'Photoshop', 'name' => 'Photoshop',
'manufacturer_id' => 9, 'manufacturer_id' => function () {
return Manufacturer::where('name', 'Adobe')->first() ?? Manufacturer::factory()->adobe();
},
'purchase_cost' => '299.99', 'purchase_cost' => '299.99',
'seats' => 10, 'seats' => 10,
'purchase_order' => '13503Q', 'purchase_order' => '13503Q',
'maintained' => true, 'maintained' => true,
'category_id' => 14, 'category_id' => function () {
return Category::where('name', 'Graphics Software')->first() ?? Category::factory()->licenseGraphicsCategory();
},
]; ];
return $data; return $data;
@ -78,10 +67,14 @@ class LicenseFactory extends Factory
return $this->state(function () { return $this->state(function () {
$data = [ $data = [
'name' => 'Acrobat', 'name' => 'Acrobat',
'manufacturer_id' => 9, 'manufacturer_id' => function () {
return Manufacturer::where('name', 'Adobe')->first() ?? Manufacturer::factory()->adobe();
},
'purchase_cost' => '29.99', 'purchase_cost' => '29.99',
'seats' => 10, 'seats' => 10,
'category_id' => 14, 'category_id' => function () {
return Category::where('name', 'Graphics Software')->first() ?? Category::factory()->licenseGraphicsCategory();
},
]; ];
return $data; return $data;
@ -93,10 +86,14 @@ class LicenseFactory extends Factory
return $this->state(function () { return $this->state(function () {
$data = [ $data = [
'name' => 'InDesign', 'name' => 'InDesign',
'manufacturer_id' => 9, 'manufacturer_id' => function () {
return Manufacturer::where('name', 'Adobe')->first() ?? Manufacturer::factory()->adobe();
},
'purchase_cost' => '199.99', 'purchase_cost' => '199.99',
'seats' => 10, 'seats' => 10,
'category_id' => 14, 'category_id' => function () {
return Category::where('name', 'Graphics Software')->first() ?? Category::factory()->licenseGraphicsCategory();
},
]; ];
@ -109,10 +106,14 @@ class LicenseFactory extends Factory
return $this->state(function () { return $this->state(function () {
$data = [ $data = [
'name' => 'Office', 'name' => 'Office',
'manufacturer_id' => 2, 'manufacturer_id' => function () {
return Manufacturer::where('name', 'Microsoft')->first() ?? Manufacturer::factory()->microsoft();
},
'purchase_cost' => '49.99', 'purchase_cost' => '49.99',
'seats' => 20, 'seats' => 20,
'category_id' => 15, 'category_id' => function () {
return Category::where('name', 'Office Software')->first() ?? Category::factory()->licenseOfficeCategory();
},
]; ];
return $data; return $data;

View file

@ -23,8 +23,6 @@ class LocationFactory extends Factory
'currency' => $this->faker->currencyCode(), 'currency' => $this->faker->currencyCode(),
'zip' => $this->faker->postcode(), 'zip' => $this->faker->postcode(),
'image' => rand(1, 9).'.jpg', 'image' => rand(1, 9).'.jpg',
]; ];
} }
} }

View file

@ -2,39 +2,10 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\Manufacturer;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/*
|--------------------------------------------------------------------------
| Asset Model Factories
|--------------------------------------------------------------------------
|
| Factories related exclusively to creating models ..
|
*/
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9
// 10
// 11
class ManufacturerFactory extends Factory class ManufacturerFactory extends Factory
{ {
/** /**
@ -42,7 +13,7 @@ class ManufacturerFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\Manufacturer::class; protected $model = Manufacturer::class;
/** /**
* Define the model's default state. * Define the model's default state.
@ -52,7 +23,8 @@ class ManufacturerFactory extends Factory
public function definition() public function definition()
{ {
return [ return [
'user_id' => 1, 'name' => $this->faker->company(),
'user_id' => User::factory()->superuser(),
'support_phone' => $this->faker->phoneNumber(), 'support_phone' => $this->faker->phoneNumber(),
'url' => $this->faker->url(), 'url' => $this->faker->url(),
'support_email' => $this->faker->safeEmail(), 'support_email' => $this->faker->safeEmail(),

View file

@ -1,25 +1,8 @@
<?php <?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
namespace Database\Factories; namespace Database\Factories;
use App\Models\AssetModel; use App\Models\Setting;
use App\Models\Category;
use App\Models\Company;
use App\Models\Location;
use App\Models\Manufacturer;
use App\Models\Statuslabel;
use App\Models\Supplier;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
class SettingFactory extends Factory class SettingFactory extends Factory
@ -29,7 +12,7 @@ class SettingFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\Setting::class; protected $model = Setting::class;
/** /**
* Define the model's default state. * Define the model's default state.
@ -39,14 +22,13 @@ class SettingFactory extends Factory
public function definition() public function definition()
{ {
return [ return [
'user_id' => 1,
'per_page' => 20, 'per_page' => 20,
'site_name' => $this->faker->sentence, 'site_name' => $this->faker->sentence(),
'auto_increment_assets' => false, 'auto_increment_assets' => false,
'alert_email' => $this->faker->safeEmail(), 'alert_email' => $this->faker->safeEmail(),
'alerts_enabled' => true, 'alerts_enabled' => true,
'brand' => 1, 'brand' => 1,
'default_currency' => $this->faker->currencyCode, 'default_currency' => $this->faker->currencyCode(),
'locale' => 'en', 'locale' => 'en',
'pwd_secure_min' => 10, // Match web setup 'pwd_secure_min' => 10, // Match web setup
'email_domain' => 'test.com', 'email_domain' => 'test.com',

View file

@ -3,6 +3,7 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\Statuslabel; use App\Models\Statuslabel;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
class StatuslabelFactory extends Factory class StatuslabelFactory extends Factory
@ -22,10 +23,10 @@ class StatuslabelFactory extends Factory
public function definition() public function definition()
{ {
return [ return [
'name' => $this->faker->sentence, 'name' => $this->faker->sentence(),
'created_at' => $this->faker->dateTime(), 'created_at' => $this->faker->dateTime(),
'updated_at' => $this->faker->dateTime(), 'updated_at' => $this->faker->dateTime(),
'user_id' => 1, 'user_id' => User::factory()->superuser(),
'deleted_at' => null, 'deleted_at' => null,
'deployable' => 0, 'deployable' => 0,
'pending' => 0, 'pending' => 0,
@ -38,7 +39,7 @@ class StatuslabelFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'notes' => $this->faker->sentence, 'notes' => $this->faker->sentence(),
'deployable' => 1, 'deployable' => 1,
'default_label' => 1, 'default_label' => 1,
]; ];
@ -49,7 +50,7 @@ class StatuslabelFactory extends Factory
{ {
return $this->state(function () { return $this->state(function () {
return [ return [
'notes' => $this->faker->sentence, 'notes' => $this->faker->sentence(),
'pending' => 1, 'pending' => 1,
'default_label' => 1, 'default_label' => 1,
]; ];

View file

@ -1,24 +1,7 @@
<?php <?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
namespace Database\Factories; namespace Database\Factories;
use App\Models\AssetModel;
use App\Models\Category;
use App\Models\Company;
use App\Models\Location;
use App\Models\Manufacturer;
use App\Models\Statuslabel;
use App\Models\Supplier; use App\Models\Supplier;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
@ -29,7 +12,7 @@ class SupplierFactory extends Factory
* *
* @var string * @var string
*/ */
protected $model = \App\Models\Supplier::class; protected $model = Supplier::class;
/** /**
* Define the model's default state. * Define the model's default state.

View file

@ -2,6 +2,8 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\Company;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
use \Auth; use \Auth;
@ -18,10 +20,9 @@ class UserFactory extends Factory
'activated' => 1, 'activated' => 1,
'address' => $this->faker->address(), 'address' => $this->faker->address(),
'city' => $this->faker->city(), 'city' => $this->faker->city(),
'company_id' => rand(1, 4), 'company_id' => Company::factory(),
'country' => $this->faker->country(), 'country' => $this->faker->country(),
'department_id' => rand(1, 6), 'email' => $this->faker->safeEmail(),
'email' => $this->faker->safeEmail,
'employee_num' => $this->faker->numberBetween(3500, 35050), 'employee_num' => $this->faker->numberBetween(3500, 35050),
'first_name' => $this->faker->firstName(), 'first_name' => $this->faker->firstName(),
'jobtitle' => $this->faker->jobTitle(), 'jobtitle' => $this->faker->jobTitle(),
@ -30,10 +31,10 @@ class UserFactory extends Factory
'notes' => 'Created by DB seeder', 'notes' => 'Created by DB seeder',
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'permissions' => '{"user":"0"}', 'permissions' => '{"user":"0"}',
'phone' => $this->faker->phoneNumber, 'phone' => $this->faker->phoneNumber(),
'state' => $this->faker->stateAbbr, 'state' => $this->faker->stateAbbr(),
'username' => $this->faker->username, 'username' => $this->faker->username(),
'zip' => $this->faker->postcode, 'zip' => $this->faker->postcode(),
]; ];
} }
@ -78,7 +79,9 @@ class UserFactory extends Factory
return $this->state(function () { return $this->state(function () {
return [ return [
'permissions' => '{"admin":"1"}', 'permissions' => '{"admin":"1"}',
'manager_id' => rand(1, 2), 'manager_id' => function () {
return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();
},
]; ];
}); });
} }

View file

@ -3,6 +3,9 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\Accessory; use App\Models\Accessory;
use App\Models\Location;
use App\Models\Supplier;
use App\Models\User;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
@ -14,10 +17,45 @@ class AccessorySeeder extends Seeder
{ {
Accessory::truncate(); Accessory::truncate();
DB::table('accessories_users')->truncate(); DB::table('accessories_users')->truncate();
Accessory::factory()->count(1)->appleUsbKeyboard()->create();
Accessory::factory()->count(1)->appleBtKeyboard()->create(); if (! Location::count()) {
Accessory::factory()->count(1)->appleMouse()->create(); $this->call(LocationSeeder::class);
Accessory::factory()->count(1)->microsoftMouse()->create(); }
$locationIds = Location::all()->pluck('id');
if (! Supplier::count()) {
$this->call(SupplierSeeder::class);
}
$supplierIds = Supplier::all()->pluck('id');
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
Accessory::factory()->appleUsbKeyboard()->create([
'location_id' => $locationIds->random(),
'supplier_id' => $supplierIds->random(),
'user_id' => $admin->id,
]);
Accessory::factory()->appleBtKeyboard()->create([
'location_id' => $locationIds->random(),
'supplier_id' => $supplierIds->random(),
'user_id' => $admin->id,
]);
Accessory::factory()->appleMouse()->create([
'location_id' => $locationIds->random(),
'supplier_id' => $supplierIds->random(),
'user_id' => $admin->id,
]);
Accessory::factory()->microsoftMouse()->create([
'location_id' => $locationIds->random(),
'supplier_id' => $supplierIds->random(),
'user_id' => $admin->id,
]);
$src = public_path('/img/demo/accessories/'); $src = public_path('/img/demo/accessories/');
$dst = 'accessories'.'/'; $dst = 'accessories'.'/';

View file

@ -3,6 +3,9 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\Actionlog; use App\Models\Actionlog;
use App\Models\Asset;
use App\Models\Location;
use App\Models\User;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
class ActionlogSeeder extends Seeder class ActionlogSeeder extends Seeder
@ -10,9 +13,30 @@ class ActionlogSeeder extends Seeder
public function run() public function run()
{ {
Actionlog::truncate(); Actionlog::truncate();
Actionlog::factory()->count(300)->assetCheckoutToUser()->create();
Actionlog::factory()->count(100)->assetCheckoutToLocation()->create();
if (! Asset::count()) {
$this->call(AssetSeeder::class);
}
if (! Location::count()) {
$this->call(LocationSeeder::class);
}
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
Actionlog::factory()
->count(300)
->assetCheckoutToUser()
->create(['user_id' => $admin->id]);
Actionlog::factory()
->count(100)
->assetCheckoutToLocation()
->create(['user_id' => $admin->id]);
Actionlog::factory()
->count(20)
->licenseCheckoutToUser()
->create(['user_id' => $admin->id]);
} }
} }

View file

@ -3,6 +3,7 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\AssetModel; use App\Models\AssetModel;
use App\Models\User;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
@ -13,35 +14,37 @@ class AssetModelSeeder extends Seeder
{ {
AssetModel::truncate(); AssetModel::truncate();
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
// Laptops // Laptops
AssetModel::factory()->count(1)->mbp13Model()->create(); // 1 AssetModel::factory()->count(1)->mbp13Model()->create(['user_id' => $admin->id]);
AssetModel::factory()->count(1)->mbpAirModel()->create(); // 2 AssetModel::factory()->count(1)->mbpAirModel()->create(['user_id' => $admin->id]);
AssetModel::factory()->count(1)->surfaceModel()->create(); // 3 AssetModel::factory()->count(1)->surfaceModel()->create(['user_id' => $admin->id]);
AssetModel::factory()->count(1)->xps13Model()->create(); // 4 AssetModel::factory()->count(1)->xps13Model()->create(['user_id' => $admin->id]);
AssetModel::factory()->count(1)->spectreModel()->create(); // 5 AssetModel::factory()->count(1)->spectreModel()->create(['user_id' => $admin->id]);
AssetModel::factory()->count(1)->zenbookModel()->create(); // 6 AssetModel::factory()->count(1)->zenbookModel()->create(['user_id' => $admin->id]);
AssetModel::factory()->count(1)->yogaModel()->create(); // 7 AssetModel::factory()->count(1)->yogaModel()->create(['user_id' => $admin->id]);
// Desktops // Desktops
AssetModel::factory()->count(1)->macproModel()->create(); // 8 AssetModel::factory()->count(1)->macproModel()->create(['user_id' => $admin->id]);
AssetModel::factory()->count(1)->lenovoI5Model()->create(); // 9 AssetModel::factory()->count(1)->lenovoI5Model()->create(['user_id' => $admin->id]);
AssetModel::factory()->count(1)->optiplexModel()->create(); // 10 AssetModel::factory()->count(1)->optiplexModel()->create(['user_id' => $admin->id]);
// Conference Phones // Conference Phones
AssetModel::factory()->count(1)->polycomModel()->create(); // 11 AssetModel::factory()->count(1)->polycomModel()->create(['user_id' => $admin->id]);
AssetModel::factory()->count(1)->polycomcxModel()->create(); // 12 AssetModel::factory()->count(1)->polycomcxModel()->create(['user_id' => $admin->id]);
// Tablets // Tablets
AssetModel::factory()->count(1)->ipadModel()->create(); // 13 AssetModel::factory()->count(1)->ipadModel()->create(['user_id' => $admin->id]);
AssetModel::factory()->count(1)->tab3Model()->create(); // 14 AssetModel::factory()->count(1)->tab3Model()->create(['user_id' => $admin->id]);
// Phones // Phones
AssetModel::factory()->count(1)->iphone11Model()->create(); // 15 AssetModel::factory()->count(1)->iphone11Model()->create(['user_id' => $admin->id]);
AssetModel::factory()->count(1)->iphone12Model()->create(); // 16 AssetModel::factory()->count(1)->iphone12Model()->create(['user_id' => $admin->id]);
// Displays // Displays
AssetModel::factory()->count(1)->ultrafine()->create(); // 17 AssetModel::factory()->count(1)->ultrafine()->create(['user_id' => $admin->id]);
AssetModel::factory()->count(1)->ultrasharp()->create(); // 18 AssetModel::factory()->count(1)->ultrasharp()->create(['user_id' => $admin->id]);
$src = public_path('/img/demo/models/'); $src = public_path('/img/demo/models/');
$dst = 'models'.'/'; $dst = 'models'.'/';

View file

@ -3,6 +3,10 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\Asset; use App\Models\Asset;
use App\Models\Location;
use App\Models\Supplier;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Sequence;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
@ -10,40 +14,47 @@ use Illuminate\Support\Facades\Storage;
class AssetSeeder extends Seeder class AssetSeeder extends Seeder
{ {
private $admin;
private $locationIds;
private $supplierIds;
public function run() public function run()
{ {
Asset::truncate(); Asset::truncate();
Asset::factory()->count(1000)->laptopMbp()->create();
Asset::factory()->count(50)->laptopMbpPending()->create();
Asset::factory()->count(50)->laptopMbpArchived()->create();
Asset::factory()->count(50)->laptopAir()->create();
Asset::factory()->count(5)->laptopSurface()->create();
Asset::factory()->count(5)->laptopXps()->create();
Asset::factory()->count(5)->laptopSpectre()->create();
Asset::factory()->count(5)->laptopZenbook()->create();
Asset::factory()->count(3)->laptopYoga()->create();
Asset::factory()->count(30)->desktopMacpro()->create(); $this->ensureLocationsSeeded();
Asset::factory()->count(30)->desktopLenovoI5()->create(); $this->ensureSuppliersSeeded();
Asset::factory()->count(30)->desktopOptiplex()->create();
Asset::factory()->count(5)->confPolycom()->create(); $this->admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
Asset::factory()->count(2)->confPolycomcx()->create(); $this->locationIds = Location::all()->pluck('id');
$this->supplierIds = Supplier::all()->pluck('id');
Asset::factory()->count(12)->tabletIpad()->create(); Asset::factory()->count(1000)->laptopMbp()->state(new Sequence($this->getState()))->create();
Asset::factory()->count(4)->tabletTab3()->create(); 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(27)->phoneIphone11()->create(); Asset::factory()->count(50)->laptopAir()->state(new Sequence($this->getState()))->create();
Asset::factory()->count(40)->phoneIphone12()->create(); Asset::factory()->count(5)->laptopSurface()->state(new Sequence($this->getState()))->create();
Asset::factory()->count(5)->laptopXps()->state(new Sequence($this->getState()))->create();
Asset::factory()->count(10)->ultrafine()->create(); Asset::factory()->count(5)->laptopSpectre()->state(new Sequence($this->getState()))->create();
Asset::factory()->count(10)->ultrasharp()->create(); Asset::factory()->count(5)->laptopZenbook()->state(new Sequence($this->getState()))->create();
Asset::factory()->count(3)->laptopYoga()->state(new Sequence($this->getState()))->create();
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();
Asset::factory()->count(5)->confPolycom()->state(new Sequence($this->getState()))->create();
Asset::factory()->count(2)->confPolycomcx()->state(new Sequence($this->getState()))->create();
Asset::factory()->count(12)->tabletIpad()->state(new Sequence($this->getState()))->create();
Asset::factory()->count(4)->tabletTab3()->state(new Sequence($this->getState()))->create();
Asset::factory()->count(27)->phoneIphone11()->state(new Sequence($this->getState()))->create();
Asset::factory()->count(40)->phoneIphone12()->state(new Sequence($this->getState()))->create();
Asset::factory()->count(10)->ultrafine()->state(new Sequence($this->getState()))->create();
Asset::factory()->count(10)->ultrasharp()->state(new Sequence($this->getState()))->create();
$del_files = Storage::files('assets'); $del_files = Storage::files('assets');
foreach ($del_files as $del_file) { // iterate files foreach ($del_files as $del_file) { // iterate files
Log::debug('Deleting: '.$del_files); Log::debug('Deleting: ' . $del_files);
try { try {
Storage::disk('public')->delete('assets'.'/'.$del_files); Storage::disk('public')->delete('assets' . '/' . $del_files);
} catch (\Exception $e) { } catch (\Exception $e) {
Log::debug($e); Log::debug($e);
} }
@ -51,4 +62,27 @@ class AssetSeeder extends Seeder
DB::table('checkout_requests')->truncate(); DB::table('checkout_requests')->truncate();
} }
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(),
'user_id' => $this->admin->id,
];
}
} }

View file

@ -3,6 +3,7 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\Category; use App\Models\Category;
use App\Models\User;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
class CategorySeeder extends Seeder class CategorySeeder extends Seeder
@ -11,20 +12,22 @@ class CategorySeeder extends Seeder
{ {
Category::truncate(); Category::truncate();
Category::factory()->count(1)->assetLaptopCategory()->create(); // 1 $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
Category::factory()->count(1)->assetDesktopCategory()->create(); // 2
Category::factory()->count(1)->assetTabletCategory()->create(); // 3 Category::factory()->count(1)->assetLaptopCategory()->create(['user_id' => $admin->id]);
Category::factory()->count(1)->assetMobileCategory()->create(); // 4 Category::factory()->count(1)->assetDesktopCategory()->create(['user_id' => $admin->id]);
Category::factory()->count(1)->assetDisplayCategory()->create(); // 5 Category::factory()->count(1)->assetTabletCategory()->create(['user_id' => $admin->id]);
Category::factory()->count(1)->assetVoipCategory()->create(); // 6 Category::factory()->count(1)->assetMobileCategory()->create(['user_id' => $admin->id]);
Category::factory()->count(1)->assetConferenceCategory()->create(); // 7 Category::factory()->count(1)->assetDisplayCategory()->create(['user_id' => $admin->id]);
Category::factory()->count(1)->accessoryKeyboardCategory()->create(); // 8 Category::factory()->count(1)->assetVoipCategory()->create(['user_id' => $admin->id]);
Category::factory()->count(1)->accessoryMouseCategory()->create(); // 9 Category::factory()->count(1)->assetConferenceCategory()->create(['user_id' => $admin->id]);
Category::factory()->count(1)->consumablePaperCategory()->create(); // 10 Category::factory()->count(1)->accessoryKeyboardCategory()->create(['user_id' => $admin->id]);
Category::factory()->count(1)->consumableInkCategory()->create(); // 11 Category::factory()->count(1)->accessoryMouseCategory()->create(['user_id' => $admin->id]);
Category::factory()->count(1)->componentHddCategory()->create(); // 12 Category::factory()->count(1)->consumablePaperCategory()->create(['user_id' => $admin->id]);
Category::factory()->count(1)->componentRamCategory()->create(); // 13 Category::factory()->count(1)->consumableInkCategory()->create(['user_id' => $admin->id]);
Category::factory()->count(1)->licenseGraphicsCategory()->create(); // 14 Category::factory()->count(1)->componentHddCategory()->create(['user_id' => $admin->id]);
Category::factory()->count(1)->licenseOfficeCategory()->create(); // 15 Category::factory()->count(1)->componentRamCategory()->create(['user_id' => $admin->id]);
Category::factory()->count(1)->licenseGraphicsCategory()->create(['user_id' => $admin->id]);
Category::factory()->count(1)->licenseOfficeCategory()->create(['user_id' => $admin->id]);
} }
} }

View file

@ -2,7 +2,9 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\Company;
use App\Models\Component; use App\Models\Component;
use App\Models\Location;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@ -12,9 +14,34 @@ class ComponentSeeder extends Seeder
{ {
Component::truncate(); Component::truncate();
DB::table('components_assets')->truncate(); DB::table('components_assets')->truncate();
Component::factory()->count(1)->ramCrucial4()->create(); // 1
Component::factory()->count(1)->ramCrucial8()->create(); // 1 if (! Company::count()) {
Component::factory()->count(1)->ssdCrucial120()->create(); // 1 $this->call(CompanySeeder::class);
Component::factory()->count(1)->ssdCrucial240()->create(); // 1 }
$companyIds = Company::all()->pluck('id');
if (! Location::count()) {
$this->call(LocationSeeder::class);
}
$locationIds = Location::all()->pluck('id');
Component::factory()->ramCrucial4()->create([
'company_id' => $companyIds->random(),
'location_id' => $locationIds->random(),
]);
Component::factory()->ramCrucial8()->create([
'company_id' => $companyIds->random(),
'location_id' => $locationIds->random(),
]);
Component::factory()->ssdCrucial120()->create([
'company_id' => $companyIds->random(),
'location_id' => $locationIds->random(),
]);
Component::factory()->ssdCrucial240()->create([
'company_id' => $companyIds->random(),
'location_id' => $locationIds->random(),
]);
} }
} }

View file

@ -3,6 +3,7 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\Consumable; use App\Models\Consumable;
use App\Models\User;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@ -12,8 +13,11 @@ class ConsumableSeeder extends Seeder
{ {
Consumable::truncate(); Consumable::truncate();
DB::table('consumables_users')->truncate(); DB::table('consumables_users')->truncate();
Consumable::factory()->count(1)->cardstock()->create(); // 1
Consumable::factory()->count(1)->paper()->create(); // 2 $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
Consumable::factory()->count(1)->ink()->create(); // 3
Consumable::factory()->count(1)->cardstock()->create(['user_id' => $admin->id]);
Consumable::factory()->count(1)->paper()->create(['user_id' => $admin->id]);
Consumable::factory()->count(1)->ink()->create(['user_id' => $admin->id]);
} }
} }

View file

@ -3,15 +3,6 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\Setting; use App\Models\Setting;
use Database\Seeders\AccessorySeeder;
use Database\Seeders\ActionlogSeeder;
use Database\Seeders\AssetModelSeeder;
use Database\Seeders\AssetSeeder;
use Database\Seeders\CategorySeeder;
use Database\Seeders\CompanySeeder;
use Database\Seeders\ComponentSeeder;
use Database\Seeders\ConsumableSeeder;
use Database\Seeders\CustomFieldSeeder;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
@ -38,9 +29,9 @@ class DatabaseSeeder extends Seeder
$this->call(CompanySeeder::class); $this->call(CompanySeeder::class);
$this->call(CategorySeeder::class); $this->call(CategorySeeder::class);
$this->call(LocationSeeder::class); $this->call(LocationSeeder::class);
$this->call(DepartmentSeeder::class);
$this->call(UserSeeder::class); $this->call(UserSeeder::class);
$this->call(DepreciationSeeder::class); $this->call(DepreciationSeeder::class);
$this->call(DepartmentSeeder::class);
$this->call(ManufacturerSeeder::class); $this->call(ManufacturerSeeder::class);
$this->call(SupplierSeeder::class); $this->call(SupplierSeeder::class);
$this->call(AssetModelSeeder::class); $this->call(AssetModelSeeder::class);

View file

@ -3,6 +3,8 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\Department; use App\Models\Department;
use App\Models\Location;
use App\Models\User;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
class DepartmentSeeder extends Seeder class DepartmentSeeder extends Seeder
@ -10,11 +12,43 @@ class DepartmentSeeder extends Seeder
public function run() public function run()
{ {
Department::truncate(); Department::truncate();
Department::factory()->count(1)->hr()->create(); // 1
Department::factory()->count(1)->engineering()->create(); // 2 if (! Location::count()) {
Department::factory()->count(1)->marketing()->create(); // 3 $this->call(LocationSeeder::class);
Department::factory()->count(1)->client()->create(); // 4 }
Department::factory()->count(1)->product()->create(); // 5
Department::factory()->count(1)->silly()->create(); // 6 $locationIds = Location::all()->pluck('id');
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
Department::factory()->count(1)->hr()->create([
'location_id' => $locationIds->random(),
'user_id' => $admin->id,
]);
Department::factory()->count(1)->engineering()->create([
'location_id' => $locationIds->random(),
'user_id' => $admin->id,
]);
Department::factory()->count(1)->marketing()->create([
'location_id' => $locationIds->random(),
'user_id' => $admin->id,
]);
Department::factory()->count(1)->client()->create([
'location_id' => $locationIds->random(),
'user_id' => $admin->id,
]);
Department::factory()->count(1)->product()->create([
'location_id' => $locationIds->random(),
'user_id' => $admin->id,
]);
Department::factory()->count(1)->silly()->create([
'location_id' => $locationIds->random(),
'user_id' => $admin->id,
]);
} }
} }

View file

@ -3,6 +3,7 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\Depreciation; use App\Models\Depreciation;
use App\Models\User;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
class DepreciationSeeder extends Seeder class DepreciationSeeder extends Seeder
@ -10,8 +11,11 @@ class DepreciationSeeder extends Seeder
public function run() public function run()
{ {
Depreciation::truncate(); Depreciation::truncate();
Depreciation::factory()->count(1)->computer()->create(); // 1
Depreciation::factory()->count(1)->display()->create(); // 2 $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
Depreciation::factory()->count(1)->mobilePhones()->create(); // 3
Depreciation::factory()->count(1)->computer()->create(['user_id' => $admin->id]);
Depreciation::factory()->count(1)->display()->create(['user_id' => $admin->id]);
Depreciation::factory()->count(1)->mobilePhones()->create(['user_id' => $admin->id]);
} }
} }

View file

@ -2,8 +2,11 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\Category;
use App\Models\License; use App\Models\License;
use App\Models\LicenseSeat; use App\Models\LicenseSeat;
use App\Models\Supplier;
use App\Models\User;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
class LicenseSeeder extends Seeder class LicenseSeeder extends Seeder
@ -12,9 +15,43 @@ class LicenseSeeder extends Seeder
{ {
License::truncate(); License::truncate();
LicenseSeat::truncate(); LicenseSeat::truncate();
License::factory()->count(1)->photoshop()->create();
License::factory()->count(1)->acrobat()->create(); if (! Category::count()) {
License::factory()->count(1)->indesign()->create(); $this->call(CategorySeeder::class);
License::factory()->count(1)->office()->create(); }
$categoryIds = Category::all()->pluck('id');
if (! Supplier::count()) {
$this->call(SupplierSeeder::class);
}
$supplierIds = Supplier::all()->pluck('id');
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
License::factory()->count(1)->photoshop()->create([
'category_id' => $categoryIds->random(),
'supplier_id' => $supplierIds->random(),
'user_id' => $admin->id,
]);
License::factory()->count(1)->acrobat()->create([
'category_id' => $categoryIds->random(),
'supplier_id' => $supplierIds->random(),
'user_id' => $admin->id,
]);
License::factory()->count(1)->indesign()->create([
'category_id' => $categoryIds->random(),
'supplier_id' => $supplierIds->random(),
'user_id' => $admin->id,
]);
License::factory()->count(1)->office()->create([
'category_id' => $categoryIds->random(),
'supplier_id' => $supplierIds->random(),
'user_id' => $admin->id,
]);
} }
} }

View file

@ -3,6 +3,7 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\Manufacturer; use App\Models\Manufacturer;
use App\Models\User;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
@ -12,17 +13,20 @@ class ManufacturerSeeder extends Seeder
public function run() public function run()
{ {
Manufacturer::truncate(); Manufacturer::truncate();
Manufacturer::factory()->count(1)->apple()->create(); // 1
Manufacturer::factory()->count(1)->microsoft()->create(); // 2 $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
Manufacturer::factory()->count(1)->dell()->create(); // 3
Manufacturer::factory()->count(1)->asus()->create(); // 4 Manufacturer::factory()->count(1)->apple()->create(['user_id' => $admin->id]);
Manufacturer::factory()->count(1)->hp()->create(); // 5 Manufacturer::factory()->count(1)->microsoft()->create(['user_id' => $admin->id]);
Manufacturer::factory()->count(1)->lenovo()->create(); // 6 Manufacturer::factory()->count(1)->dell()->create(['user_id' => $admin->id]);
Manufacturer::factory()->count(1)->lg()->create(); // 7 Manufacturer::factory()->count(1)->asus()->create(['user_id' => $admin->id]);
Manufacturer::factory()->count(1)->polycom()->create(); // 8 Manufacturer::factory()->count(1)->hp()->create(['user_id' => $admin->id]);
Manufacturer::factory()->count(1)->adobe()->create(); // 9 Manufacturer::factory()->count(1)->lenovo()->create(['user_id' => $admin->id]);
Manufacturer::factory()->count(1)->avery()->create(); // 10 Manufacturer::factory()->count(1)->lg()->create(['user_id' => $admin->id]);
Manufacturer::factory()->count(1)->crucial()->create(); // 10 Manufacturer::factory()->count(1)->polycom()->create(['user_id' => $admin->id]);
Manufacturer::factory()->count(1)->adobe()->create(['user_id' => $admin->id]);
Manufacturer::factory()->count(1)->avery()->create(['user_id' => $admin->id]);
Manufacturer::factory()->count(1)->crucial()->create(['user_id' => $admin->id]);
$src = public_path('/img/demo/manufacturers/'); $src = public_path('/img/demo/manufacturers/');
$dst = 'manufacturers'.'/'; $dst = 'manufacturers'.'/';

View file

@ -3,6 +3,7 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\Statuslabel; use App\Models\Statuslabel;
use App\Models\User;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
class StatuslabelSeeder extends Seeder class StatuslabelSeeder extends Seeder
@ -10,12 +11,27 @@ class StatuslabelSeeder extends Seeder
public function run() public function run()
{ {
Statuslabel::truncate(); Statuslabel::truncate();
Statuslabel::factory()->rtd()->create(['name' => 'Ready to Deploy']);
Statuslabel::factory()->pending()->create(['name' => 'Pending']); $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
Statuslabel::factory()->archived()->create(['name' => 'Archived']);
Statuslabel::factory()->outForDiagnostics()->create(); Statuslabel::factory()->rtd()->create([
Statuslabel::factory()->outForRepair()->create(); 'name' => 'Ready to Deploy',
Statuslabel::factory()->broken()->create(); 'user_id' => $admin->id,
Statuslabel::factory()->lost()->create(); ]);
Statuslabel::factory()->pending()->create([
'name' => 'Pending',
'user_id' => $admin->id,
]);
Statuslabel::factory()->archived()->create([
'name' => 'Archived',
'user_id' => $admin->id,
]);
Statuslabel::factory()->outForDiagnostics()->create(['user_id' => $admin->id]);
Statuslabel::factory()->outForRepair()->create(['user_id' => $admin->id]);
Statuslabel::factory()->broken()->create(['user_id' => $admin->id]);
Statuslabel::factory()->lost()->create(['user_id' => $admin->id]);
} }
} }

View file

@ -2,7 +2,10 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\Company;
use App\Models\Department;
use App\Models\User; use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Sequence;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
@ -17,11 +20,53 @@ class UserSeeder extends Seeder
public function run() public function run()
{ {
User::truncate(); User::truncate();
User::factory()->count(1)->firstAdmin()->create();
User::factory()->count(1)->snipeAdmin()->create(); if (! Company::count()) {
User::factory()->count(3)->superuser()->create(); $this->call(CompanySeeder::class);
User::factory()->count(3)->admin()->create(); }
User::factory()->count(50)->viewAssets()->create();
$companyIds = Company::all()->pluck('id');
if (! Department::count()) {
$this->call(DepartmentSeeder::class);
}
$departmentIds = Department::all()->pluck('id');
User::factory()->count(1)->firstAdmin()
->state(new Sequence(fn($sequence) => [
'company_id' => $companyIds->random(),
'department_id' => $departmentIds->random(),
]))
->create();
User::factory()->count(1)->snipeAdmin()
->state(new Sequence(fn($sequence) => [
'company_id' => $companyIds->random(),
'department_id' => $departmentIds->random(),
]))
->create();
User::factory()->count(3)->superuser()
->state(new Sequence(fn($sequence) => [
'company_id' => $companyIds->random(),
'department_id' => $departmentIds->random(),
]))
->create();
User::factory()->count(3)->admin()
->state(new Sequence(fn($sequence) => [
'company_id' => $companyIds->random(),
'department_id' => $departmentIds->random(),
]))
->create();
User::factory()->count(50)->viewAssets()
->state(new Sequence(fn($sequence) => [
'company_id' => $companyIds->random(),
'department_id' => $departmentIds->random(),
]))
->create();
$src = public_path('/img/demo/avatars/'); $src = public_path('/img/demo/avatars/');
$dst = 'avatars'.'/'; $dst = 'avatars'.'/';

View file

@ -202,6 +202,7 @@ return [
'slack' => 'Slack', 'slack' => 'Slack',
'general_webhook' => 'General Webhook', 'general_webhook' => 'General Webhook',
'webhook' => ':app', 'webhook' => ':app',
'webhook_presave' => 'Test to Save',
'webhook_title' => 'Update Webhook Settings', 'webhook_title' => 'Update Webhook Settings',
'webhook_help' => 'Integration settings', 'webhook_help' => 'Integration settings',
'webhook_botname' => ':app Botname', 'webhook_botname' => ':app Botname',

View file

@ -417,6 +417,6 @@ return [
'merged' => 'merged', 'merged' => 'merged',
'merged_log_this_user_into' => 'Merged this user (ID :to_id - :to_username) into user ID :from_id (:from_username) ', 'merged_log_this_user_into' => 'Merged this user (ID :to_id - :to_username) into user ID :from_id (:from_username) ',
'merged_log_this_user_from' => 'Merged user ID :from_id (:from_username) into this user (ID :to_id - :to_username)', 'merged_log_this_user_from' => 'Merged user ID :from_id (:from_username) into this user (ID :to_id - :to_username)',
'clear_and_save' => 'Clear & Save',
]; ];

View file

@ -12,34 +12,33 @@
{{-- Page content --}} {{-- Page content --}}
@section('content') @section('content')
<div> <div><!-- livewire div - do not remove -->
<form class="form-horizontal" role="form" wire:submit.prevent="submit"> <form class="form-horizontal" role="form" wire:submit.prevent="submit">
{{csrf_field()}} {{csrf_field()}}
<div class="row"> <div class="row">
<div class="col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2">
<div class="panel box box-default">
<div class="box-header with-border">
<h2 class="box-title">
<i class="{{$webhook_icon}}"></i> {{ trans('admin/settings/general.webhook', ['app' => $webhook_name] ) }}
</h2>
</div>
<div class="box-body">
<div class="col-md-12">
@if($webhook_selected != 'general')
<p>
{!! trans('admin/settings/general.webhook_integration_help',array('webhook_link' => $webhook_link, 'app' => $webhook_name)) !!}
</p>
@endif
<br>
</div>
<div class="col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2">
<div class="panel box box-default">
<div class="box-header with-border">
<h2 class="box-title">
<i class="{{$webhook_icon}}"></i> {{ trans('admin/settings/general.webhook', ['app' => $webhook_name] ) }}
</h2>
</div>
<div class="box-body">
@if($webhook_selected != 'general')
<div class="col-md-12"> <div class="col-md-12">
@if (session()->has('save')) <p>
<div class="alert alert-success fade in"> {!! trans('admin/settings/general.webhook_integration_help',array('webhook_link' => $webhook_link, 'app' => $webhook_name)) !!}
{{session('save')}} </p>
</div> <br>
@endif </div>
@endif
<div class="col-md-12" style="border-top: 0px;">
@if(session()->has('success')) @if(session()->has('success'))
<div class="alert alert-success fade in"> <div class="alert alert-success fade in">
@ -51,123 +50,135 @@
{{session('error')}} {{session('error')}}
</div> </div>
@endif @endif
@if(session()->has('message'))
<div class="alert alert-danger fade in"> <div class="form-group">
{{session('message')}} <div class="col-md-2">
<label for="webhook_selected">
{{ trans('general.integration_option') }}
</label>
</div> </div>
<div class="col-md-9 required" wire:ignore>
{{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'style'=>'width:90%')) }}
</div>
</div>
@if (Helper::isDemoMode())
@include('partials.forms.demo-mode')
@endif
<!--Webhook endpoint-->
<div class="form-group{{ $errors->has('webhook_endpoint') ? ' error' : '' }}">
<div class="col-md-2">
{{ Form::label('webhook_endpoint', trans('admin/settings/general.webhook_endpoint',['app' => $webhook_name ])) }}
</div>
<div class="col-md-9 required">
<input type="text" wire:model="webhook_endpoint" class="form-control" placeholder="{{$webhook_placeholder}}" value="{{old('webhook_endpoint', $webhook_endpoint)}}"{{ Helper::isDemoMode() ? ' disabled' : ''}}>
{!! $errors->first('webhook_endpoint', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div>
</div>
@if (Helper::isDemoMode())
@include('partials.forms.demo-mode')
@endif @endif
<div class="form-group col-md-12 required">
<div class="col-md-3">
<label for="webhook_selected">
{{ trans('general.integration_option') }}
</label>
</div>
<div class="col-md-9">
<select wire:model="webhook_selected" aria-label="webhook_selected" class="form-control">
<option value="slack">{{ trans('admin/settings/general.slack') }}</option>
<option value="general">{{ trans('admin/settings/general.general_webhook') }}</option>
</select>
</div>
</div>
<!--Webhook endpoint-->
<div class="form-group col-md-12 required{{ $errors->has('webhook_endpoint') ? ' error' : '' }}">
<div class="col-md-3">
{{ Form::label('webhook_endpoint', trans('admin/settings/general.webhook_endpoint',['app' => ucwords($webhook_selected) ])) }}
</div>
<div class="col-md-9">
@if (config('app.lock_passwords')===true)
<p class="text-warning">
<i class="fas fa-lock" aria-hidden="true"></i>
{{ trans('general.feature_disabled') }}
</p>
<input type="text" wire:model="webhook_endpoint" class="form-control" placeholder="{{ $webhook_placeholder }}" value="{{ old('webhook_endpoint', $webhook_endpoint) }}">
@else
<input type="text" wire:model="webhook_endpoint" class="form-control" placeholder="{{ $webhook_placeholder }}" value="{{ old('webhook_endpoint', $webhook_endpoint) }}">
@endif
{!! $errors->first('webhook_endpoint', '<span class="alert-msg">:message</span>') !!}
</div>
</div>
<!-- Webhook channel --> <!-- Webhook channel -->
<div class="col-md-12 form-group required{{ $errors->has('webhook_channel') ? ' error' : '' }}"> <div class="form-group{{ $errors->has('webhook_channel') ? ' error' : '' }}">
<div class="col-md-3"> <div class="col-md-2">
{{ Form::label('webhook_channel', trans('admin/settings/general.webhook_channel',['app' => ucwords($webhook_selected) ])) }} {{ Form::label('webhook_channel', trans('admin/settings/general.webhook_channel',['app' => $webhook_name ])) }}
</div> </div>
<div class="col-md-9"> <div class="col-md-9 required">
<input type="text" wire:model="webhook_channel" class="form-control" placeholder="#IT-Ops" value="{{ old('webhook_channel', $webhook_channel) }}"{{ Helper::isDemoMode() ? ' disabled' : ''}}>
@if (config('app.lock_passwords')===true) {!! $errors->first('webhook_channel', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
<input type="text" wire:model="webhook_channel" class="form-control" placeholder="#IT-Ops" value="{{ old('webhook_channel', $webhook_channel) }}">
<p class="text-warning">
<i class="fas fa-lock" aria-hidden="true"></i> {{ trans('general.feature_disabled') }}</p>
@else
<input type="text" wire:model="webhook_channel" class="form-control" placeholder="#IT-Ops" value="{{ old('webhook_channel', $webhook_channel) }}">
@endif
{!! $errors->first('webhook_channel', '<span class="alert-msg">:message</span>') !!}
</div> </div>
</div> </div>
<!-- Webhook botname --> @if (Helper::isDemoMode())
<div class="col-md-12 form-group required{{ $errors->has('webhook_botname') ? ' error' : '' }}"> @include('partials.forms.demo-mode')
<div class="col-md-3"> @endif
{{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => ucwords($webhook_selected) ])) }}
</div> <!-- Webhook botname -->
<div class="col-md-9"> <div class="form-group{{ $errors->has('webhook_botname') ? ' error' : '' }}">
@if (config('app.lock_passwords')===true) <div class="col-md-2">
<input type="text" wire:model="webhook_botname" class='form-control' {{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => $webhook_name ])) }}
placeholder="Snipe-Bot" {{old('webhook_botname', $webhook_botname)}}>
<p class="text-warning"><i class="fas fa-lock"></i>
{{ trans('general.feature_disabled') }}
</p>
@else
<input type="text" wire:model="webhook_botname" class="form-control" placeholder="Snipe-Bot" {{old('webhook_botname', $webhook_botname)}}>
@endif
{!! $errors->first('webhook_botname', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div><!--col-md-10-->
</div> </div>
<div class="col-md-9">
<input type="text" wire:model="webhook_botname" class='form-control' placeholder="Snipe-Bot" {{ old('webhook_botname', $webhook_botname)}}{{ Helper::isDemoMode() ? ' disabled' : ''}}>
{!! $errors->first('webhook_botname', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div><!--col-md-10-->
</div>
<!--Webhook Integration Test--> @if (!Helper::isDemoMode())
@if($webhook_selected == 'slack') @include('partials.forms.demo-mode')
@if($webhook_endpoint != null && $webhook_channel != null) @endif
<div class="form-group col-md-12">
<div class="col-md-offset-3 col-md-9">
<a href="#" wire:click.prevent="testWebhook"
class="btn btn-default btn-sm pull-left">
<i class="{{$webhook_icon}}" aria-hidden="true"></i>
{!! trans('admin/settings/general.webhook_test',['app' => ucwords($webhook_selected) ]) !!}
</a>
<div wire:loading>
<span style="padding-left: 5px; font-size: 20px">
<i class="fas fa-spinner fa-spin" aria-hidden="true"></i>
</span>
</div>
<!--Webhook Integration Test-->
@if($webhook_selected == 'slack')
@if($webhook_endpoint != null && $webhook_channel != null)
<div class="form-group">
<div class="col-md-offset-2 col-md-9">
<a href="#" wire:click.prevent="testWebhook"
class="btn btn-default btn-sm pull-left">
<i class="{{$webhook_icon}}" aria-hidden="true"></i>
{!! trans('admin/settings/general.webhook_test',['app' => ucwords($webhook_selected) ]) !!}
</a>
<div wire:loading>
<span style="padding-left: 5px; font-size: 20px">
<i class="fas fa-spinner fa-spin" aria-hidden="true"></i>
</span>
</div> </div>
</div> </div>
@endif
@endif
<div class="box-footer" style="margin-top: 45px;">
<div class="text-right col-md-12">
<a class="btn btn-link text-left"
href="{{ route('settings.index') }}">{{ trans('button.cancel') }}</a>
<button type="submit" {{$isDisabled}} class="btn btn-primary"><i
class="fas fa-check icon-white"
aria-hidden="true"></i> {{ trans('general.save') }}</button>
</div> </div>
</div><!--box-footer--> @endif
</div> <!-- /box --> @endif
</div> <!-- /.col-md-8--> </div><!-- /.col-md-12 -->
</div> </div><!-- /.box-body -->
</div>
</form> <div class="box-footer">
</div> <div class="text-right col-md-12">
<button type="reset" wire:click.prevent="clearSettings" class="col-md-2 text-left btn btn-danger pull-left"{{ Helper::isDemoMode() ? ' disabled' : ''}}>{{ trans('general.clear_and_save') }}</button>
<a class="btn btn-link pull-left" href="{{ route('settings.index') }}">{{ trans('button.cancel') }}</a>
<button type="submit" {{$isDisabled}} class="btn btn-primary"{{ Helper::isDemoMode() ? ' disabled' : ''}}>
<i class="fas fa-check icon-white" aria-hidden="true"></i> {{ $save_button }}</button>
</div> <!-- /.col-md-12 -->
</div><!--box-footer-->
</div> <!-- /.box -->
</div> <!-- /.col-md-8-->
</div> <!-- /.row -->
</form>
</div> <!-- /livewire div -->
@section('moar_scripts')
<script>
$(document).ready(function () {
$('#select2').select2();
$('#select2').on('change', function (e) {
var data = $('#select2').select2("val");
@this.set('webhook_selected', data);
});
// Re-render select2
window.livewire.hook('message.processed', function (el, component) {
$('.select2').select2();
});
});
</script>
@endsection

View file

@ -0,0 +1,5 @@
<div class="row">
<div class="col-md-10 col-md-offset-2">
{!! Helper::showDemoModeFieldWarning() !!}
</div>
</div>

View file

@ -0,0 +1,35 @@
<?php
namespace Tests\Feature\Api\Assets;
use App\Models\Asset;
use App\Models\Setting;
use App\Models\User;
use Illuminate\Testing\Fluent\AssertableJson;
use Laravel\Passport\Passport;
use Tests\TestCase;
class AssetIndexTest extends TestCase
{
public function testAssetIndexReturnsExpectedAssets()
{
Setting::factory()->create();
Asset::factory()->count(3)->create();
Passport::actingAs(User::factory()->superuser()->create());
$this->getJson(
route('api.assets.index', [
'sort' => 'name',
'order' => 'asc',
'offset' => '0',
'limit' => '20',
]))
->assertOk()
->assertJsonStructure([
'total',
'rows',
])
->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc());
}
}

View file

@ -15,9 +15,9 @@ class UsersForSelectListTest extends TestCase
{ {
Setting::factory()->create(); Setting::factory()->create();
User::factory()->count(3)->create(); $users = User::factory()->superuser()->count(3)->create();
Passport::actingAs(User::factory()->firstAdmin()->create()); Passport::actingAs($users->first());
$this->getJson(route('api.users.selectlist')) $this->getJson(route('api.users.selectlist'))
->assertOk() ->assertOk()
->assertJsonStructure([ ->assertJsonStructure([
@ -27,7 +27,7 @@ class UsersForSelectListTest extends TestCase
'page', 'page',
'page_count', 'page_count',
]) ])
->assertJson(fn(AssertableJson $json) => $json->has('results', 4)->etc()); ->assertJson(fn(AssertableJson $json) => $json->has('results', 3)->etc());
} }
public function testUsersScopedToCompanyWhenMultipleFullCompanySupportEnabled() public function testUsersScopedToCompanyWhenMultipleFullCompanySupportEnabled()

View file

@ -36,7 +36,7 @@ class AssetTest extends TestCase
'model_id' => AssetModel::factory() 'model_id' => AssetModel::factory()
->create( ->create(
[ [
'category_id' => Category::factory()->assetLaptopCategory()->id 'category_id' => Category::factory()->assetLaptopCategory()->create()->id
] ]
)->id, )->id,
'warranty_months' => 24, 'warranty_months' => 24,

View file

@ -26,7 +26,7 @@ class CategoryTest extends TestCase
public function testACategoryCanHaveAssets() public function testACategoryCanHaveAssets()
{ {
$category = Category::factory()->assetDesktopCategory(); $category = Category::factory()->assetDesktopCategory()->create();
// Generate 5 models via factory // Generate 5 models via factory
$models = AssetModel::factory() $models = AssetModel::factory()

View file

@ -18,7 +18,7 @@ class DepreciationTest extends TestCase
->count(5) ->count(5)
->create( ->create(
[ [
'category_id' => Category::factory()->assetLaptopCategory(), 'category_id' => Category::factory()->assetLaptopCategory()->create(),
'depreciation_id' => $depreciation->id 'depreciation_id' => $depreciation->id
]); ]);
@ -35,7 +35,7 @@ class DepreciationTest extends TestCase
->photoshop() ->photoshop()
->create( ->create(
[ [
'category_id' => Category::factory()->licenseGraphicsCategory(), 'category_id' => Category::factory()->licenseGraphicsCategory()->create(),
'depreciation_id' => $depreciation->id 'depreciation_id' => $depreciation->id
]); ]);

View file

@ -22,7 +22,7 @@ class NotificationTest extends TestCase
'model_id' => AssetModel::factory() 'model_id' => AssetModel::factory()
->create( ->create(
[ [
'category_id' => Category::factory()->assetLaptopCategory()->id 'category_id' => Category::factory()->assetLaptopCategory()->create()->id
] ]
)->id, )->id,
'warranty_months' => 24, 'warranty_months' => 24,