ajout app
This commit is contained in:
156
SNIPE-IT/database/factories/AccessoryFactory.php
Normal file
156
SNIPE-IT/database/factories/AccessoryFactory.php
Normal file
@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
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 Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class AccessoryFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Accessory::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => sprintf(
|
||||
'%s %s',
|
||||
$this->faker->randomElement(['Bluetooth', 'Wired']),
|
||||
$this->faker->randomElement(['Keyboard', 'Wired'])
|
||||
),
|
||||
'user_id' => User::factory()->superuser(),
|
||||
'category_id' => Category::factory()->forAccessories(),
|
||||
'model_number' => $this->faker->numberBetween(1000000, 50000000),
|
||||
'location_id' => Location::factory(),
|
||||
'qty' => 1,
|
||||
];
|
||||
}
|
||||
|
||||
public function appleBtKeyboard()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Bluetooth Keyboard',
|
||||
'image' => 'bluetooth.jpg',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Keyboards')->first() ?? Category::factory()->accessoryKeyboardCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
|
||||
},
|
||||
'qty' => 10,
|
||||
'min_amt' => 2,
|
||||
'supplier_id' => Supplier::factory(),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function appleUsbKeyboard()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'USB Keyboard',
|
||||
'image' => 'usb-keyboard.jpg',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Keyboards')->first() ?? Category::factory()->accessoryKeyboardCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
|
||||
},
|
||||
'qty' => 15,
|
||||
'min_amt' => 2,
|
||||
'supplier_id' => Supplier::factory(),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function appleMouse()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Magic Mouse',
|
||||
'image' => 'magic-mouse.jpg',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Mouse')->first() ?? Category::factory()->accessoryMouseCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
|
||||
},
|
||||
'qty' => 13,
|
||||
'min_amt' => 2,
|
||||
'supplier_id' => Supplier::factory(),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function microsoftMouse()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Sculpt Comfort Mouse',
|
||||
'image' => 'comfort-mouse.jpg',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Mouse')->first() ?? Category::factory()->accessoryMouseCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Microsoft')->first() ?? Manufacturer::factory()->microsoft();
|
||||
},
|
||||
'qty' => 13,
|
||||
'min_amt' => 2,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function withoutItemsRemaining()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'qty' => 1,
|
||||
];
|
||||
})->afterCreating(function ($accessory) {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$accessory->users()->attach($accessory->id, [
|
||||
'accessory_id' => $accessory->id,
|
||||
'created_at' => now(),
|
||||
'user_id' => $user->id,
|
||||
'assigned_to' => $user->id,
|
||||
'note' => '',
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
public function requiringAcceptance()
|
||||
{
|
||||
return $this->afterCreating(function ($accessory) {
|
||||
$accessory->category->update(['require_acceptance' => 1]);
|
||||
});
|
||||
}
|
||||
|
||||
public function checkedOutToUser(User $user = null)
|
||||
{
|
||||
return $this->afterCreating(function (Accessory $accessory) use ($user) {
|
||||
$accessory->users()->attach($accessory->id, [
|
||||
'accessory_id' => $accessory->id,
|
||||
'created_at' => Carbon::now(),
|
||||
'user_id' => 1,
|
||||
'assigned_to' => $user->id ?? User::factory()->create()->id,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
108
SNIPE-IT/database/factories/ActionlogFactory.php
Normal file
108
SNIPE-IT/database/factories/ActionlogFactory.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Actionlog;
|
||||
use App\Models\Asset;
|
||||
use App\Models\License;
|
||||
use App\Models\LicenseSeat;
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ActionlogFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Actionlog::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'item_id' => Asset::factory(),
|
||||
'item_type' => Asset::class,
|
||||
'user_id' => User::factory()->superuser(),
|
||||
'action_type' => 'uploaded',
|
||||
];
|
||||
}
|
||||
|
||||
public function assetCheckoutToUser()
|
||||
{
|
||||
return $this->state(function () {
|
||||
$target = User::inRandomOrder()->first();
|
||||
$asset = Asset::inRandomOrder()->RTD()->first();
|
||||
|
||||
$asset->update(
|
||||
[
|
||||
'assigned_to' => $target->id,
|
||||
'assigned_type' => User::class,
|
||||
'location_id' => $target->location_id,
|
||||
]
|
||||
);
|
||||
|
||||
return [
|
||||
'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
||||
'action_type' => 'checkout',
|
||||
'item_id' => $asset->id,
|
||||
'item_type' => Asset::class,
|
||||
'target_id' => $target->id,
|
||||
'target_type' => User::class,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function assetCheckoutToLocation()
|
||||
{
|
||||
return $this->state(function () {
|
||||
$target = Location::inRandomOrder()->first();
|
||||
$asset = Asset::inRandomOrder()->RTD()->first();
|
||||
|
||||
$asset->update(
|
||||
[
|
||||
'assigned_to' => $target->id,
|
||||
'assigned_type' => Location::class,
|
||||
'location_id' => $target->id,
|
||||
]
|
||||
);
|
||||
|
||||
return [
|
||||
'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
||||
'action_type' => 'checkout',
|
||||
'item_id' => $asset->id,
|
||||
'item_type' => Asset::class,
|
||||
'target_id' => $target->id,
|
||||
'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,
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
370
SNIPE-IT/database/factories/AssetFactory.php
Normal file
370
SNIPE-IT/database/factories/AssetFactory.php
Normal file
@ -0,0 +1,370 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Asset;
|
||||
use App\Models\AssetModel;
|
||||
use App\Models\Location;
|
||||
use App\Models\Statuslabel;
|
||||
use App\Models\Supplier;
|
||||
use App\Models\User;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class AssetFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Asset::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => null,
|
||||
'model_id' => AssetModel::factory(),
|
||||
'rtd_location_id' => Location::factory(),
|
||||
'serial' => $this->faker->uuid(),
|
||||
'status_id' => function () {
|
||||
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'),
|
||||
'notes' => 'Created by DB seeder',
|
||||
'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'),
|
||||
'purchase_cost' => $this->faker->randomFloat(2, '299.99', '2999.99'),
|
||||
'order_number' => (string) $this->faker->numberBetween(1000000, 50000000),
|
||||
'supplier_id' => Supplier::factory(),
|
||||
'requestable' => $this->faker->boolean(),
|
||||
'assigned_to' => null,
|
||||
'assigned_type' => null,
|
||||
'next_audit_date' => null,
|
||||
'last_checkout' => null,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function configure()
|
||||
{
|
||||
return $this->afterMaking(function (Asset $asset) {
|
||||
// calculates the EOL date most of the time, but sometimes sets a random date so we have some explicits
|
||||
// the explicit boolean gets set in the saving() method on the observer
|
||||
$asset->asset_eol_date = $this->faker->boolean(5)
|
||||
? CarbonImmutable::parse($asset->purchase_date)->addMonths(rand(0, 20))->format('Y-m-d')
|
||||
: CarbonImmutable::parse($asset->purchase_date)->addMonths($asset->model->eol)->format('Y-m-d');
|
||||
});
|
||||
}
|
||||
|
||||
public function laptopMbp()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'Macbook Pro 13"')->first() ?? AssetModel::factory()->mbp13Model();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function laptopMbpPending()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
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']);
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function laptopMbpArchived()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
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']);
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function laptopAir()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'Macbook Air')->first() ?? AssetModel::factory()->mbpAirModel();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function laptopSurface()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'Surface')->first() ?? AssetModel::factory()->surfaceModel();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function laptopXps()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'XPS 13')->first() ?? AssetModel::factory()->xps13Model();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function laptopSpectre()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'Spectre')->first() ?? AssetModel::factory()->spectreModel();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function laptopZenbook()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'ZenBook UX310')->first() ?? AssetModel::factory()->zenbookModel();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function laptopYoga()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'Yoga 910')->first() ?? AssetModel::factory()->yogaModel();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function desktopMacpro()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'iMac Pro')->first() ?? AssetModel::factory()->macproModel();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function desktopLenovoI5()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'Lenovo Intel Core i5')->first() ?? AssetModel::factory()->lenovoI5Model();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function desktopOptiplex()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'OptiPlex')->first() ?? AssetModel::factory()->optiplexModel();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function confPolycom()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'SoundStation 2')->first() ?? AssetModel::factory()->polycomModel();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function confPolycomcx()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'Polycom CX3000 IP Conference Phone')->first() ?? AssetModel::factory()->polycomcxModel();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function tabletIpad()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'iPad Pro')->first() ?? AssetModel::factory()->ipadModel();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function tabletTab3()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'Tab3')->first() ?? AssetModel::factory()->tab3Model();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function phoneIphone11()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'iPhone 11')->first() ?? AssetModel::factory()->iphone11Model();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function phoneIphone12()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'iPhone 12')->first() ?? AssetModel::factory()->iphone12Model();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function ultrafine()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'Ultrafine 4k')->first() ?? AssetModel::factory()->ultrafine();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function ultrasharp()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'Ultrasharp U2415')->first() ?? AssetModel::factory()->ultrasharp();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function assignedToUser(User $user = null)
|
||||
{
|
||||
return $this->state(function () use ($user) {
|
||||
return [
|
||||
'assigned_to' => $user->id ?? User::factory(),
|
||||
'assigned_type' => User::class,
|
||||
'last_checkout' => now()->subDay(),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function assignedToLocation()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'assigned_to' => Location::factory(),
|
||||
'assigned_type' => Location::class,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function assignedToAsset()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => 1,
|
||||
'assigned_to' => Asset::factory(),
|
||||
'assigned_type' => Asset::class,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function requiresAcceptance()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'Macbook Pro 13')->first() ?? AssetModel::factory()->mbp13Model();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function deleted()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => function () {
|
||||
return AssetModel::where('name', 'Macbook Pro 13')->first() ?? AssetModel::factory()->mbp13Model();
|
||||
},
|
||||
'deleted_at' => $this->faker->dateTime(),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function requestable()
|
||||
{
|
||||
return $this->state(['requestable' => true]);
|
||||
}
|
||||
|
||||
public function nonrequestable()
|
||||
{
|
||||
return $this->state(['requestable' => false]);
|
||||
}
|
||||
|
||||
/**
|
||||
* This allows bypassing model level validation if you want to purposefully
|
||||
* create an asset in an invalid state. Validation is turned back on
|
||||
* after the model is created via the factory.
|
||||
* @return AssetFactory
|
||||
*/
|
||||
public function canBeInvalidUponCreation()
|
||||
{
|
||||
return $this->afterMaking(function (Asset $asset) {
|
||||
$asset->setValidating(false);
|
||||
})->afterCreating(function (Asset $asset) {
|
||||
$asset->setValidating(true);
|
||||
});
|
||||
}
|
||||
}
|
36
SNIPE-IT/database/factories/AssetMaintenanceFactory.php
Normal file
36
SNIPE-IT/database/factories/AssetMaintenanceFactory.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Asset;
|
||||
use App\Models\AssetMaintenance;
|
||||
use App\Models\Supplier;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class AssetMaintenanceFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = AssetMaintenance::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'asset_id' => Asset::factory(),
|
||||
'supplier_id' => Supplier::factory(),
|
||||
'asset_maintenance_type' => $this->faker->randomElement(['maintenance', 'repair', 'upgrade']),
|
||||
'title' => $this->faker->sentence(),
|
||||
'start_date' => $this->faker->date(),
|
||||
'is_warranty' => $this->faker->boolean(),
|
||||
'notes' => $this->faker->paragraph(),
|
||||
];
|
||||
}
|
||||
}
|
432
SNIPE-IT/database/factories/AssetModelFactory.php
Normal file
432
SNIPE-IT/database/factories/AssetModelFactory.php
Normal file
@ -0,0 +1,432 @@
|
||||
<?php
|
||||
|
||||
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 App\Models\Category;
|
||||
|
||||
class AssetModelFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = AssetModel::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'user_id' => User::factory()->superuser(),
|
||||
'name' => $this->faker->catchPhrase(),
|
||||
'category_id' => Category::factory(),
|
||||
'model_number' => $this->faker->creditCardNumber(),
|
||||
'notes' => 'Created by demo seeder',
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public function mbp13Model()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Macbook Pro 13"',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory();
|
||||
},
|
||||
'eol' => '36',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
|
||||
},
|
||||
'image' => 'mbp.jpg',
|
||||
'fieldset_id' => function () {
|
||||
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function mbpAirModel()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Macbook Air',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
|
||||
},
|
||||
'eol' => '36',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
|
||||
},
|
||||
'image' => 'macbookair.jpg',
|
||||
'fieldset_id' => function () {
|
||||
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function surfaceModel()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Surface',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Microsoft')->first() ?? Manufacturer::factory()->microsoft();
|
||||
},
|
||||
'eol' => '36',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
|
||||
},
|
||||
'image' => 'surface.jpg',
|
||||
'fieldset_id' => function () {
|
||||
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function xps13Model()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'XPS 13',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Dell')->first() ?? Manufacturer::factory()->dell();
|
||||
},
|
||||
'eol' => '36',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
|
||||
},
|
||||
'image' => 'xps.jpg',
|
||||
'fieldset_id' => function () {
|
||||
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function zenbookModel()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'ZenBook UX310',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Asus')->first() ?? Manufacturer::factory()->asus();
|
||||
},
|
||||
'eol' => '36',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
|
||||
},
|
||||
'image' => 'zenbook.jpg',
|
||||
'fieldset_id' => function () {
|
||||
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function spectreModel()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Spectre',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'HP')->first() ?? Manufacturer::factory()->hp();
|
||||
},
|
||||
'eol' => '36',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
|
||||
},
|
||||
'image' => 'spectre.jpg',
|
||||
'fieldset_id' => function () {
|
||||
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function yogaModel()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Yoga 910',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Lenovo')->first() ?? Manufacturer::factory()->lenovo();
|
||||
},
|
||||
'eol' => '36',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
|
||||
},
|
||||
'image' => 'yoga.png',
|
||||
'fieldset_id' => function () {
|
||||
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function macproModel()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'iMac Pro',
|
||||
'category_id' => function (){
|
||||
return Category::where('name', 'Desktops')->first() ?? Category::factory()->assetDesktopCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
|
||||
},
|
||||
'eol' => '24',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
|
||||
},
|
||||
'image' => 'imacpro.jpg',
|
||||
'fieldset_id' => function () {
|
||||
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function lenovoI5Model()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Lenovo Intel Core i5',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Desktops')->first() ?? Category::factory()->assetDesktopCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Lenovo')->first() ?? Manufacturer::factory()->lenovo();
|
||||
},
|
||||
'eol' => '24',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
|
||||
},
|
||||
'image' => 'lenovoi5.png',
|
||||
'fieldset_id' => function () {
|
||||
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function optiplexModel()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'OptiPlex',
|
||||
'category_id' => function (){
|
||||
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)',
|
||||
'eol' => '24',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
|
||||
},
|
||||
'image' => 'optiplex.jpg',
|
||||
'fieldset_id' => function () {
|
||||
return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function polycomModel()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'SoundStation 2',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'VOIP Phones')->first() ?? Category::factory()->assetVoipCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Polycom')->first() ?? Manufacturer::factory()->polycom();
|
||||
},
|
||||
'eol' => '12',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
|
||||
},
|
||||
'image' => 'soundstation.jpg',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function polycomcxModel()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Polycom CX3000 IP Conference Phone',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'VOIP Phones')->first() ?? Category::factory()->assetVoipCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Polycom')->first() ?? Manufacturer::factory()->polycom();
|
||||
},
|
||||
'eol' => '12',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
|
||||
},
|
||||
'image' => 'cx3000.png',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function ipadModel()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'iPad Pro',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Tablets')->first() ?? Category::factory()->assetTabletCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
|
||||
},
|
||||
'eol' => '12',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
|
||||
},
|
||||
'image' => 'ipad.jpg',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function tab3Model()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Tab3',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Tablets')->first() ?? Category::factory()->assetTabletCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Lenovo')->first() ?? Manufacturer::factory()->lenovo();
|
||||
},
|
||||
'eol' => '12',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
|
||||
},
|
||||
'image' => 'tab3.png',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function iphone11Model()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'iPhone 11',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Mobile Phones')->first() ?? Category::factory()->assetMobileCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
|
||||
},
|
||||
'eol' => '12',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Mobile Phone Depreciation')->first() ?? Depreciation::factory()->mobilePhones();
|
||||
},
|
||||
'image' => 'iphone11.jpeg',
|
||||
'fieldset_id' => function () {
|
||||
return CustomFieldset::where('name', 'Mobile Devices')->first() ?? CustomFieldset::factory()->mobile();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function iphone12Model()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'iPhone 12',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Mobile Phones')->first() ?? Category::factory()->assetMobileCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
|
||||
},
|
||||
'eol' => '12',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer();
|
||||
},
|
||||
'image' => 'iphone12.jpeg',
|
||||
'fieldset_id' => function () {
|
||||
return CustomFieldset::where('name', 'Mobile Devices')->first() ?? CustomFieldset::factory()->mobile();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function ultrafine()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Ultrafine 4k',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Displays')->first() ?? Category::factory()->assetDisplayCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'LG')->first() ?? Manufacturer::factory()->lg();
|
||||
},
|
||||
'eol' => '12',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Display Depreciation')->first() ?? Depreciation::factory()->display();
|
||||
},
|
||||
'image' => 'ultrafine.jpg',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function ultrasharp()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Ultrasharp U2415',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Displays')->first() ?? Category::factory()->assetDisplayCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Dell')->first() ?? Manufacturer::factory()->dell();
|
||||
},
|
||||
'eol' => '12',
|
||||
'depreciation_id' => function () {
|
||||
return Depreciation::where('name', 'Display Depreciation')->first() ?? Depreciation::factory()->display();
|
||||
},
|
||||
'image' => 'ultrasharp.jpg',
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
181
SNIPE-IT/database/factories/CategoryFactory.php
Normal file
181
SNIPE-IT/database/factories/CategoryFactory.php
Normal file
@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use App\Models\Category;
|
||||
|
||||
class CategoryFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Category::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->catchPhrase(),
|
||||
'category_type' => 'asset',
|
||||
'checkin_email' => $this->faker->boolean(),
|
||||
'eula_text' => $this->faker->paragraph(),
|
||||
'require_acceptance' => false,
|
||||
'use_default_eula' => $this->faker->boolean(),
|
||||
'user_id' => User::factory()->superuser(),
|
||||
];
|
||||
}
|
||||
|
||||
// usage: Category::factory()->assetLaptopCategory();
|
||||
public function assetLaptopCategory()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => 'Laptops',
|
||||
'category_type' => 'asset',
|
||||
'require_acceptance' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
// usage: Category::factory()->assetDesktopCategory();
|
||||
public function assetDesktopCategory()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => 'Desktops',
|
||||
'category_type' => 'asset',
|
||||
'require_acceptance' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
// usage: Category::factory()->assetDisplayCategory();
|
||||
public function assetDisplayCategory()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => 'Displays',
|
||||
'category_type' => 'asset',
|
||||
]);
|
||||
}
|
||||
|
||||
// usage: Category::factory()->assetTabletCategory();
|
||||
public function assetTabletCategory()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => 'Tablets',
|
||||
'category_type' => 'asset',
|
||||
]);
|
||||
}
|
||||
|
||||
// usage: Category::factory()->assetMobileCategory();
|
||||
public function assetMobileCategory()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => 'Mobile Phones',
|
||||
'category_type' => 'asset',
|
||||
]);
|
||||
}
|
||||
|
||||
// usage: Category::factory()->assetConferenceCategory();
|
||||
public function assetConferenceCategory()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => 'Conference Phones',
|
||||
'category_type' => 'asset',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
// usage: Category::factory()->assetVoipCategory();
|
||||
public function assetVoipCategory()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => 'VOIP Phones',
|
||||
'category_type' => 'asset',
|
||||
]);
|
||||
}
|
||||
|
||||
// usage: Category::factory()->accessoryKeyboardCategory();
|
||||
public function accessoryKeyboardCategory()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => 'Keyboards',
|
||||
'category_type' => 'accessory',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
// usage: Category::factory()->accessoryMouseCategory();
|
||||
public function accessoryMouseCategory()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => 'Mouse',
|
||||
'category_type' => 'accessory',
|
||||
]);
|
||||
}
|
||||
|
||||
// usage: Category::factory()->componentHddCategory();
|
||||
public function componentHddCategory()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => 'HDD/SSD',
|
||||
'category_type' => 'component',
|
||||
]);
|
||||
}
|
||||
|
||||
// usage: Category::factory()->componentRamCategory();
|
||||
public function componentRamCategory()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => 'RAM',
|
||||
'category_type' => 'component',
|
||||
]);
|
||||
}
|
||||
|
||||
// usage: Category::factory()->consumablePaperCategory();
|
||||
public function consumablePaperCategory()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => 'Printer Paper',
|
||||
'category_type' => 'consumable',
|
||||
]);
|
||||
}
|
||||
|
||||
// usage: Category::factory()->consumableInkCategory();
|
||||
public function consumableInkCategory()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => 'Printer Ink',
|
||||
'category_type' => 'consumable',
|
||||
]);
|
||||
}
|
||||
|
||||
// usage: Category::factory()->licenseGraphicsCategory();
|
||||
public function licenseGraphicsCategory()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => 'Graphics Software',
|
||||
'category_type' => 'license',
|
||||
]);
|
||||
}
|
||||
|
||||
// usage: Category::factory()->licenseGraphicsCategory();
|
||||
public function licenseOfficeCategory()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => 'Office Software',
|
||||
'category_type' => 'license',
|
||||
]);
|
||||
}
|
||||
|
||||
public function forAccessories()
|
||||
{
|
||||
return $this->state([
|
||||
'category_type' => 'accessory',
|
||||
]);
|
||||
}
|
||||
}
|
41
SNIPE-IT/database/factories/CheckoutAcceptanceFactory.php
Normal file
41
SNIPE-IT/database/factories/CheckoutAcceptanceFactory.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Accessory;
|
||||
use App\Models\Asset;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class CheckoutAcceptanceFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'checkoutable_type' => Asset::class,
|
||||
'checkoutable_id' => Asset::factory(),
|
||||
'assigned_to_id' => User::factory(),
|
||||
];
|
||||
}
|
||||
|
||||
public function forAccessory()
|
||||
{
|
||||
return $this->state([
|
||||
'checkoutable_type' => Accessory::class,
|
||||
'checkoutable_id' => Accessory::factory(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function pending()
|
||||
{
|
||||
return $this->state([
|
||||
'accepted_at' => null,
|
||||
'declined_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
28
SNIPE-IT/database/factories/CompanyFactory.php
Normal file
28
SNIPE-IT/database/factories/CompanyFactory.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Company;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class CompanyFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Company::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->unique()->company(),
|
||||
];
|
||||
}
|
||||
}
|
101
SNIPE-IT/database/factories/ComponentFactory.php
Normal file
101
SNIPE-IT/database/factories/ComponentFactory.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
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 App\Models\Supplier;
|
||||
|
||||
class ComponentFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Component::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->text(20),
|
||||
'category_id' => Category::factory(),
|
||||
'location_id' => Location::factory(),
|
||||
'serial' => $this->faker->uuid(),
|
||||
'qty' => $this->faker->numberBetween(3, 10),
|
||||
'order_number' => $this->faker->numberBetween(1000000, 50000000),
|
||||
'purchase_date' => $this->faker->dateTime()->format('Y-m-d'),
|
||||
'purchase_cost' => $this->faker->randomFloat(2),
|
||||
'min_amt' => $this->faker->numberBetween($min = 1, $max = 2),
|
||||
'company_id' => Company::factory(),
|
||||
'supplier_id' => Supplier::factory(),
|
||||
];
|
||||
}
|
||||
|
||||
public function ramCrucial4()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Crucial 4GB DDR3L-1600 SODIMM',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'RAM')->first() ?? Category::factory()->componentRamCategory();
|
||||
},
|
||||
'qty' => 10,
|
||||
'min_amt' => 2,
|
||||
'location_id' => Location::factory(),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function ramCrucial8()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Crucial 8GB DDR3L-1600 SODIMM Memory for Mac',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'RAM')->first() ?? Category::factory()->componentRamCategory();
|
||||
},
|
||||
'qty' => 10,
|
||||
'min_amt' => 2,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function ssdCrucial120()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Crucial BX300 120GB SATA Internal SSD',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'HDD/SSD')->first() ?? Category::factory()->componentHddCategory();
|
||||
},
|
||||
'qty' => 10,
|
||||
'min_amt' => 2,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function ssdCrucial240()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Crucial BX300 240GB SATA Internal SSD',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'HDD/SSD')->first() ?? Category::factory()->componentHddCategory();
|
||||
},
|
||||
'qty' => 10,
|
||||
'min_amt' => 2,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
119
SNIPE-IT/database/factories/ConsumableFactory.php
Normal file
119
SNIPE-IT/database/factories/ConsumableFactory.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
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 App\Models\Supplier;
|
||||
|
||||
class ConsumableFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Consumable::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->words(3, true),
|
||||
'category_id' => Category::factory(),
|
||||
'user_id' => User::factory()->superuser(),
|
||||
'item_no' => $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_cost' => $this->faker->randomFloat(2, 1, 50),
|
||||
'qty' => $this->faker->numberBetween(5, 10),
|
||||
'min_amt' => $this->faker->numberBetween($min = 1, $max = 2),
|
||||
'company_id' => Company::factory(),
|
||||
'supplier_id' => Supplier::factory(),
|
||||
];
|
||||
}
|
||||
|
||||
public function cardstock()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Cardstock (White)',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Printer Paper')->first() ?? Category::factory()->consumablePaperCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Avery')->first() ?? Manufacturer::factory()->avery();
|
||||
},
|
||||
'qty' => 10,
|
||||
'min_amt' => 2,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function paper()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Laserjet Paper (Ream)',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Printer Paper')->first() ?? Category::factory()->consumablePaperCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Avery')->first() ?? Manufacturer::factory()->avery();
|
||||
},
|
||||
'qty' => 20,
|
||||
'min_amt' => 2,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function ink()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Laserjet Toner (black)',
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Printer Ink')->first() ?? Category::factory()->consumableInkCategory();
|
||||
},
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'HP')->first() ?? Manufacturer::factory()->hp();
|
||||
},
|
||||
'qty' => 20,
|
||||
'min_amt' => 2,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function withoutItemsRemaining()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'qty' => 1,
|
||||
];
|
||||
})->afterCreating(function (Consumable $consumable) {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$consumable->users()->attach($consumable->id, [
|
||||
'consumable_id' => $consumable->id,
|
||||
'user_id' => $user->id,
|
||||
'assigned_to' => $user->id,
|
||||
'note' => '',
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
public function requiringAcceptance()
|
||||
{
|
||||
return $this->afterCreating(function (Consumable $consumable) {
|
||||
$consumable->category->update(['require_acceptance' => 1]);
|
||||
});
|
||||
}
|
||||
}
|
120
SNIPE-IT/database/factories/CustomFieldFactory.php
Normal file
120
SNIPE-IT/database/factories/CustomFieldFactory.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\CustomField;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class CustomFieldFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = CustomField::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->unique()->catchPhrase(),
|
||||
'format' => '',
|
||||
'element' => 'text',
|
||||
'auto_add_to_fieldsets' => '0',
|
||||
'show_in_requestable_list' => '0',
|
||||
];
|
||||
}
|
||||
|
||||
public function imei()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'IMEI',
|
||||
'help_text' => 'The IMEI number for this device.',
|
||||
'format' => 'regex:/^[0-9]{15}$/',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function phone()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Phone Number',
|
||||
'help_text' => 'Enter the phone number for this device.',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function ram()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'RAM',
|
||||
'help_text' => 'The amount of RAM this device has.',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function cpu()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'CPU',
|
||||
'help_text' => 'The speed of the processor on this device.',
|
||||
'show_in_requestable_list' => '1',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function macAddress()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'MAC Address',
|
||||
'format' => 'regex:/^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$/',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function testEncrypted()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Test Encrypted',
|
||||
'field_encrypted' => '1',
|
||||
'help_text' => 'This is a sample encrypted field.',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function testCheckbox()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Test Checkbox',
|
||||
'help_text' => 'This is a sample checkbox.',
|
||||
'field_values' => "One\r\nTwo\r\nThree",
|
||||
'element' => 'checkbox',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function testRadio()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Test Radio',
|
||||
'help_text' => 'This is a sample radio.',
|
||||
'field_values' => "One\r\nTwo\r\nThree",
|
||||
'element' => 'radio',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
}
|
46
SNIPE-IT/database/factories/CustomFieldsetFactory.php
Normal file
46
SNIPE-IT/database/factories/CustomFieldsetFactory.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\CustomFieldset;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class CustomFieldsetFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = CustomFieldset::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->unique()->catchPhrase(),
|
||||
];
|
||||
}
|
||||
|
||||
public function mobile()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Mobile Devices',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function computer()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Laptops and Desktops',
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
95
SNIPE-IT/database/factories/DepartmentFactory.php
Normal file
95
SNIPE-IT/database/factories/DepartmentFactory.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class DepartmentFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Department::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->unique()->word() . ' Department',
|
||||
'user_id' => User::factory()->superuser(),
|
||||
'location_id' => Location::factory(),
|
||||
];
|
||||
}
|
||||
|
||||
public function hr()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Human Resources',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function engineering()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Engineering',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function marketing()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Marketing',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function client()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Client Services',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function design()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Graphic Design',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Product Management',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function silly()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Dept of Silly Walks',
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
61
SNIPE-IT/database/factories/DepreciationFactory.php
Normal file
61
SNIPE-IT/database/factories/DepreciationFactory.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Depreciation;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class DepreciationFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Depreciation::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->unique()->catchPhrase(),
|
||||
'user_id' => User::factory()->superuser(),
|
||||
'months' => 36,
|
||||
];
|
||||
}
|
||||
|
||||
public function computer()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Computer Depreciation',
|
||||
'months' => 36,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Display Depreciation',
|
||||
'months' => 12,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function mobilePhones()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Mobile Phone Depreciation',
|
||||
'months' => 24,
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
28
SNIPE-IT/database/factories/GroupFactory.php
Normal file
28
SNIPE-IT/database/factories/GroupFactory.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Group;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class GroupFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Group::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->name(),
|
||||
];
|
||||
}
|
||||
}
|
122
SNIPE-IT/database/factories/LicenseFactory.php
Normal file
122
SNIPE-IT/database/factories/LicenseFactory.php
Normal file
@ -0,0 +1,122 @@
|
||||
<?php
|
||||
namespace Database\Factories;
|
||||
|
||||
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;
|
||||
|
||||
class LicenseFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = License::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'user_id' => User::factory()->superuser(),
|
||||
'name' => $this->faker->name(),
|
||||
'license_email' => $this->faker->safeEmail(),
|
||||
'serial' => $this->faker->uuid(),
|
||||
'notes' => 'Created by DB seeder',
|
||||
'seats' => $this->faker->numberBetween(1, 10),
|
||||
'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'),
|
||||
'order_number' => $this->faker->numberBetween(1000000, 50000000),
|
||||
'expiration_date' => $this->faker->dateTimeBetween('now', '+3 years', date_default_timezone_get())->format('Y-m-d H:i:s'),
|
||||
'reassignable' => $this->faker->boolean(),
|
||||
'termination_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d H:i:s'),
|
||||
'supplier_id' => Supplier::factory(),
|
||||
'category_id' => Category::factory(),
|
||||
];
|
||||
}
|
||||
|
||||
public function photoshop()
|
||||
{
|
||||
return $this->state(function () {
|
||||
$data = [
|
||||
'name' => 'Photoshop',
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Adobe')->first() ?? Manufacturer::factory()->adobe();
|
||||
},
|
||||
'purchase_cost' => '299.99',
|
||||
'seats' => 10,
|
||||
'purchase_order' => '13503Q',
|
||||
'maintained' => true,
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Graphics Software')->first() ?? Category::factory()->licenseGraphicsCategory();
|
||||
},
|
||||
];
|
||||
|
||||
return $data;
|
||||
});
|
||||
}
|
||||
|
||||
public function acrobat()
|
||||
{
|
||||
return $this->state(function () {
|
||||
$data = [
|
||||
'name' => 'Acrobat',
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Adobe')->first() ?? Manufacturer::factory()->adobe();
|
||||
},
|
||||
'purchase_cost' => '29.99',
|
||||
'seats' => 10,
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Graphics Software')->first() ?? Category::factory()->licenseGraphicsCategory();
|
||||
},
|
||||
];
|
||||
|
||||
return $data;
|
||||
});
|
||||
}
|
||||
|
||||
public function indesign()
|
||||
{
|
||||
return $this->state(function () {
|
||||
$data = [
|
||||
'name' => 'InDesign',
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Adobe')->first() ?? Manufacturer::factory()->adobe();
|
||||
},
|
||||
'purchase_cost' => '199.99',
|
||||
'seats' => 10,
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Graphics Software')->first() ?? Category::factory()->licenseGraphicsCategory();
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
return $data;
|
||||
});
|
||||
}
|
||||
|
||||
public function office()
|
||||
{
|
||||
return $this->state(function () {
|
||||
$data = [
|
||||
'name' => 'Office',
|
||||
'manufacturer_id' => function () {
|
||||
return Manufacturer::where('name', 'Microsoft')->first() ?? Manufacturer::factory()->microsoft();
|
||||
},
|
||||
'purchase_cost' => '49.99',
|
||||
'seats' => 20,
|
||||
'category_id' => function () {
|
||||
return Category::where('name', 'Office Software')->first() ?? Category::factory()->licenseOfficeCategory();
|
||||
},
|
||||
];
|
||||
|
||||
return $data;
|
||||
});
|
||||
}
|
||||
}
|
26
SNIPE-IT/database/factories/LicenseSeatFactory.php
Normal file
26
SNIPE-IT/database/factories/LicenseSeatFactory.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\License;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class LicenseSeatFactory extends Factory
|
||||
{
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'license_id' => License::factory(),
|
||||
];
|
||||
}
|
||||
|
||||
public function assignedToUser(User $user = null)
|
||||
{
|
||||
return $this->state(function () use ($user) {
|
||||
return [
|
||||
'assigned_to' => $user->id ?? User::factory(),
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
28
SNIPE-IT/database/factories/LocationFactory.php
Normal file
28
SNIPE-IT/database/factories/LocationFactory.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class LocationFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->city(),
|
||||
'address' => $this->faker->streetAddress(),
|
||||
'address2' => $this->faker->secondaryAddress(),
|
||||
'city' => $this->faker->city(),
|
||||
'state' => $this->faker->stateAbbr(),
|
||||
'country' => $this->faker->countryCode(),
|
||||
'currency' => $this->faker->currencyCode(),
|
||||
'zip' => $this->faker->postcode(),
|
||||
'image' => rand(1, 9).'.jpg',
|
||||
];
|
||||
}
|
||||
}
|
168
SNIPE-IT/database/factories/ManufacturerFactory.php
Normal file
168
SNIPE-IT/database/factories/ManufacturerFactory.php
Normal file
@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Manufacturer;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ManufacturerFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Manufacturer::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->unique()->company(),
|
||||
'user_id' => User::factory()->superuser(),
|
||||
'support_phone' => $this->faker->phoneNumber(),
|
||||
'url' => $this->faker->url(),
|
||||
'support_email' => $this->faker->safeEmail(),
|
||||
];
|
||||
}
|
||||
|
||||
public function apple()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Apple',
|
||||
'url' => 'https://apple.com',
|
||||
'support_url' => 'https://support.apple.com',
|
||||
'warranty_lookup_url' => 'https://checkcoverage.apple.com',
|
||||
'image' => 'apple.jpg',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function microsoft()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Microsoft',
|
||||
'url' => 'https://microsoft.com',
|
||||
'support_url' => 'https://support.microsoft.com',
|
||||
'warranty_lookup_url' => 'https://account.microsoft.com/devices',
|
||||
'image' => 'microsoft.png',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function dell()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Dell',
|
||||
'url' => 'https://dell.com',
|
||||
'support_url' => 'https://support.dell.com',
|
||||
'warranty_lookup_url' => 'https://www.dell.com/support/home/en-us/Products/?app=warranty',
|
||||
'image' => 'dell.png',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function asus()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Asus',
|
||||
'url' => 'https://asus.com',
|
||||
'support_url' => 'https://support.asus.com',
|
||||
'image' => 'asus.png',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function hp()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'HP',
|
||||
'url' => 'https://hp.com',
|
||||
'support_url' => 'https://support.hp.com',
|
||||
'image' => 'hp.png',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function lenovo()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Lenovo',
|
||||
'url' => 'https://lenovo.com',
|
||||
'support_url' => 'https://support.lenovo.com',
|
||||
'image' => 'lenovo.jpg',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function lg()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'LG',
|
||||
'url' => 'https://lg.com',
|
||||
'support_url' => 'https://support.lg.com',
|
||||
'image' => 'lg.jpg',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function polycom()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Polycom',
|
||||
'url' => 'https://polycom.com',
|
||||
'support_url' => 'https://support.polycom.com',
|
||||
'image' => 'polycom.png',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function adobe()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Adobe',
|
||||
'url' => 'https://adobe.com',
|
||||
'support_url' => 'https://support.adobe.com',
|
||||
'image' => 'adobe.jpg',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function avery()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Avery',
|
||||
'url' => 'https://avery.com',
|
||||
'support_url' => 'https://support.avery.com',
|
||||
'image' => 'avery.png',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function crucial()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Crucial',
|
||||
'url' => 'https://crucial.com',
|
||||
'support_url' => 'https://support.crucial.com',
|
||||
'image' => 'crucial.jpg',
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
37
SNIPE-IT/database/factories/SettingFactory.php
Normal file
37
SNIPE-IT/database/factories/SettingFactory.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class SettingFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Setting::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'per_page' => 20,
|
||||
'site_name' => $this->faker->sentence(),
|
||||
'auto_increment_assets' => false,
|
||||
'alert_email' => $this->faker->safeEmail(),
|
||||
'alerts_enabled' => true,
|
||||
'brand' => 1,
|
||||
'default_currency' => $this->faker->currencyCode(),
|
||||
'locale' => 'en-US',
|
||||
'pwd_secure_min' => 10, // Match web setup
|
||||
'email_domain' => 'example.org',
|
||||
];
|
||||
}
|
||||
}
|
110
SNIPE-IT/database/factories/StatuslabelFactory.php
Normal file
110
SNIPE-IT/database/factories/StatuslabelFactory.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Statuslabel;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class StatuslabelFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Statuslabel::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->sentence(),
|
||||
'created_at' => $this->faker->dateTime(),
|
||||
'updated_at' => $this->faker->dateTime(),
|
||||
'user_id' => User::factory()->superuser(),
|
||||
'deleted_at' => null,
|
||||
'deployable' => 0,
|
||||
'pending' => 0,
|
||||
'archived' => 0,
|
||||
'notes' => '',
|
||||
];
|
||||
}
|
||||
|
||||
public function rtd()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'notes' => $this->faker->sentence(),
|
||||
'deployable' => 1,
|
||||
'default_label' => 1,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function pending()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'notes' => $this->faker->sentence(),
|
||||
'pending' => 1,
|
||||
'default_label' => 1,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function archived()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'notes' => 'These assets are permanently undeployable',
|
||||
'archived' => 1,
|
||||
'default_label' => 0,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function outForDiagnostics()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Out for Diagnostics',
|
||||
'default_label' => 0,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function outForRepair()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Out for Repair',
|
||||
'default_label' => 0,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function broken()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Broken - Not Fixable',
|
||||
'default_label' => 0,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function lost()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'name' => 'Lost/Stolen',
|
||||
'default_label' => 0,
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
40
SNIPE-IT/database/factories/SupplierFactory.php
Normal file
40
SNIPE-IT/database/factories/SupplierFactory.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Supplier;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class SupplierFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Supplier::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->company(),
|
||||
'address' => $this->faker->streetAddress(),
|
||||
'address2' => $this->faker->secondaryAddress(),
|
||||
'city' => $this->faker->city(),
|
||||
'state' => $this->faker->stateAbbr(),
|
||||
'zip' => $this->faker->postCode(),
|
||||
'country' => $this->faker->countryCode(),
|
||||
'contact' => $this->faker->name(),
|
||||
'phone' => $this->faker->phoneNumber(),
|
||||
'fax' => $this->faker->phoneNumber(),
|
||||
'email' => $this->faker->safeEmail(),
|
||||
'url' => $this->faker->url(),
|
||||
'notes' => $this->faker->text(191), // Supplier notes can be a max of 255 characters.
|
||||
];
|
||||
}
|
||||
}
|
302
SNIPE-IT/database/factories/UserFactory.php
Normal file
302
SNIPE-IT/database/factories/UserFactory.php
Normal file
@ -0,0 +1,302 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use \Auth;
|
||||
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'activated' => 1,
|
||||
'address' => $this->faker->address(),
|
||||
'city' => $this->faker->city(),
|
||||
'company_id' => Company::factory(),
|
||||
'country' => $this->faker->country(),
|
||||
'email' => $this->faker->safeEmail(),
|
||||
'employee_num' => $this->faker->numberBetween(3500, 35050),
|
||||
'first_name' => $this->faker->firstName(),
|
||||
'jobtitle' => $this->faker->jobTitle(),
|
||||
'last_name' => $this->faker->lastName(),
|
||||
'locale' => 'en-US',
|
||||
'notes' => 'Created by DB seeder',
|
||||
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
|
||||
'permissions' => '{}',
|
||||
'phone' => $this->faker->phoneNumber(),
|
||||
'state' => $this->faker->stateAbbr(),
|
||||
'username' => $this->faker->unique()->username(),
|
||||
'zip' => $this->faker->postcode(),
|
||||
];
|
||||
}
|
||||
|
||||
public function firstAdmin()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'first_name' => 'Admin',
|
||||
'last_name' => 'User',
|
||||
'username' => 'admin',
|
||||
'avatar' => '1.jpg',
|
||||
'permissions' => '{"superuser":"1"}',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function snipeAdmin()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'first_name' => 'Snipe E.',
|
||||
'last_name' => 'Head',
|
||||
'username' => 'snipe',
|
||||
'avatar' => '2.jpg',
|
||||
'email' => 'snipe@snipe.net',
|
||||
'permissions' => '{"superuser":"1"}',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function testAdmin()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'first_name' => 'Alison',
|
||||
'last_name' => 'Gianotto',
|
||||
'username' => 'agianotto@grokability.com',
|
||||
'avatar' => '2.jpg',
|
||||
'email' => 'agianotto@grokability.com',
|
||||
'permissions' => '{"superuser":"1"}',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function superuser()
|
||||
{
|
||||
return $this->appendPermission(['superuser' => '1']);
|
||||
}
|
||||
|
||||
public function admin()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'permissions' => '{"admin":"1"}',
|
||||
'manager_id' => function () {
|
||||
return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function viewAssets()
|
||||
{
|
||||
return $this->appendPermission(['assets.view' => '1']);
|
||||
}
|
||||
|
||||
public function createAssets()
|
||||
{
|
||||
return $this->appendPermission(['assets.create' => '1']);
|
||||
}
|
||||
|
||||
public function editAssets()
|
||||
{
|
||||
return $this->appendPermission(['assets.edit' => '1']);
|
||||
}
|
||||
|
||||
public function deleteAssets()
|
||||
{
|
||||
return $this->appendPermission(['assets.delete' => '1']);
|
||||
}
|
||||
|
||||
public function checkinAssets()
|
||||
{
|
||||
return $this->appendPermission(['assets.checkin' => '1']);
|
||||
}
|
||||
|
||||
public function checkoutAssets()
|
||||
{
|
||||
return $this->appendPermission(['assets.checkout' => '1']);
|
||||
}
|
||||
|
||||
public function viewRequestableAssets()
|
||||
{
|
||||
return $this->appendPermission(['assets.view.requestable' => '1']);
|
||||
}
|
||||
|
||||
public function viewAccessories()
|
||||
{
|
||||
return $this->appendPermission(['accessories.view' => '1']);
|
||||
}
|
||||
|
||||
public function createAccessories()
|
||||
{
|
||||
return $this->appendPermission(['accessories.create' => '1']);
|
||||
}
|
||||
|
||||
public function editAccessories()
|
||||
{
|
||||
return $this->appendPermission(['accessories.edit' => '1']);
|
||||
}
|
||||
|
||||
public function deleteAccessories()
|
||||
{
|
||||
return $this->appendPermission(['accessories.delete' => '1']);
|
||||
}
|
||||
|
||||
public function checkinAccessories()
|
||||
{
|
||||
return $this->appendPermission(['accessories.checkin' => '1']);
|
||||
}
|
||||
|
||||
public function checkoutAccessories()
|
||||
{
|
||||
return $this->appendPermission(['accessories.checkout' => '1']);
|
||||
}
|
||||
|
||||
public function viewConsumables()
|
||||
{
|
||||
return $this->appendPermission(['consumables.view' => '1']);
|
||||
}
|
||||
|
||||
public function createConsumables()
|
||||
{
|
||||
return $this->appendPermission(['consumables.create' => '1']);
|
||||
}
|
||||
|
||||
public function editConsumables()
|
||||
{
|
||||
return $this->appendPermission(['consumables.edit' => '1']);
|
||||
}
|
||||
|
||||
public function deleteConsumables()
|
||||
{
|
||||
return $this->appendPermission(['consumables.delete' => '1']);
|
||||
}
|
||||
|
||||
public function checkinConsumables()
|
||||
{
|
||||
return $this->appendPermission(['consumables.checkin' => '1']);
|
||||
}
|
||||
|
||||
public function checkoutConsumables()
|
||||
{
|
||||
return $this->appendPermission(['consumables.checkout' => '1']);
|
||||
}
|
||||
|
||||
public function viewDepartments()
|
||||
{
|
||||
return $this->appendPermission(['departments.view' => '1']);
|
||||
}
|
||||
|
||||
public function viewLicenses()
|
||||
{
|
||||
return $this->appendPermission(['licenses.view' => '1']);
|
||||
}
|
||||
|
||||
public function createLicenses()
|
||||
{
|
||||
return $this->appendPermission(['licenses.create' => '1']);
|
||||
}
|
||||
|
||||
public function editLicenses()
|
||||
{
|
||||
return $this->appendPermission(['licenses.edit' => '1']);
|
||||
}
|
||||
|
||||
public function deleteLicenses()
|
||||
{
|
||||
return $this->appendPermission(['licenses.delete' => '1']);
|
||||
}
|
||||
|
||||
public function checkoutLicenses()
|
||||
{
|
||||
return $this->appendPermission(['licenses.checkout' => '1']);
|
||||
}
|
||||
|
||||
public function viewKeysLicenses()
|
||||
{
|
||||
return $this->appendPermission(['licenses.keys' => '1']);
|
||||
}
|
||||
|
||||
public function viewComponents()
|
||||
{
|
||||
return $this->appendPermission(['components.view' => '1']);
|
||||
}
|
||||
|
||||
public function createComponents()
|
||||
{
|
||||
return $this->appendPermission(['components.create' => '1']);
|
||||
}
|
||||
|
||||
public function editComponents()
|
||||
{
|
||||
return $this->appendPermission(['components.edit' => '1']);
|
||||
}
|
||||
|
||||
public function deleteComponents()
|
||||
{
|
||||
return $this->appendPermission(['components.delete' => '1']);
|
||||
}
|
||||
|
||||
public function checkinComponents()
|
||||
{
|
||||
return $this->appendPermission(['components.checkin' => '1']);
|
||||
}
|
||||
|
||||
public function checkoutComponents()
|
||||
{
|
||||
return $this->appendPermission(['components.checkout' => '1']);
|
||||
}
|
||||
|
||||
public function viewUsers()
|
||||
{
|
||||
return $this->appendPermission(['users.view' => '1']);
|
||||
}
|
||||
|
||||
public function createUsers()
|
||||
{
|
||||
return $this->appendPermission(['users.create' => '1']);
|
||||
}
|
||||
|
||||
public function editUsers()
|
||||
{
|
||||
return $this->appendPermission(['users.edit' => '1']);
|
||||
}
|
||||
|
||||
public function deleteUsers()
|
||||
{
|
||||
return $this->appendPermission(['users.delete' => '1']);
|
||||
}
|
||||
|
||||
public function canEditOwnLocation()
|
||||
{
|
||||
return $this->appendPermission(['self.edit_location' => '1']);
|
||||
}
|
||||
|
||||
public function canViewReports()
|
||||
{
|
||||
return $this->appendPermission(['reports.view' => '1']);
|
||||
}
|
||||
|
||||
private function appendPermission(array $permission)
|
||||
{
|
||||
return $this->state(function ($currentState) use ($permission) {
|
||||
return [
|
||||
'permissions' => json_encode(
|
||||
array_merge(
|
||||
json_decode($currentState['permissions'], true),
|
||||
$permission
|
||||
)
|
||||
),
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user