2017-10-07 02:27:02 -07:00
|
|
|
<?php
|
2021-06-10 13:19:27 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
namespace Database\Factories;
|
|
|
|
|
2023-03-20 11:39:27 -07:00
|
|
|
use App\Models\Accessory;
|
2023-03-14 12:50:02 -07:00
|
|
|
use App\Models\Category;
|
2023-03-15 18:31:08 -07:00
|
|
|
use App\Models\Location;
|
2023-03-14 12:01:23 -07:00
|
|
|
use App\Models\Manufacturer;
|
2023-03-16 12:41:34 -07:00
|
|
|
use App\Models\Supplier;
|
2023-03-14 11:34:58 -07:00
|
|
|
use App\Models\User;
|
2024-02-12 12:54:48 -08:00
|
|
|
use Carbon\Carbon;
|
2021-06-10 13:19:27 -07:00
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
2017-10-07 02:27:02 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
class AccessoryFactory extends Factory
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name of the factory's corresponding model.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-03-20 11:39:27 -07:00
|
|
|
protected $model = Accessory::class;
|
2021-06-10 13:17:44 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Define the model's default state.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function definition()
|
|
|
|
{
|
|
|
|
return [
|
2023-03-16 17:08:18 -07:00
|
|
|
'name' => sprintf(
|
|
|
|
'%s %s',
|
|
|
|
$this->faker->randomElement(['Bluetooth', 'Wired']),
|
|
|
|
$this->faker->randomElement(['Keyboard', 'Wired'])
|
|
|
|
),
|
2024-09-17 14:16:41 -07:00
|
|
|
'created_by' => User::factory()->superuser(),
|
2024-01-29 14:21:30 -08:00
|
|
|
'category_id' => Category::factory()->forAccessories(),
|
2021-06-10 13:17:44 -07:00
|
|
|
'model_number' => $this->faker->numberBetween(1000000, 50000000),
|
2023-03-15 18:31:08 -07:00
|
|
|
'location_id' => Location::factory(),
|
2023-03-16 17:08:18 -07:00
|
|
|
'qty' => 1,
|
2021-06-10 13:17:44 -07:00
|
|
|
];
|
|
|
|
}
|
2017-10-07 02:27:02 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
public function appleBtKeyboard()
|
|
|
|
{
|
|
|
|
return $this->state(function () {
|
|
|
|
return [
|
|
|
|
'name' => 'Bluetooth Keyboard',
|
|
|
|
'image' => 'bluetooth.jpg',
|
2023-03-14 12:50:02 -07:00
|
|
|
'category_id' => function () {
|
2023-03-20 12:01:39 -07:00
|
|
|
return Category::where('name', 'Keyboards')->first() ?? Category::factory()->accessoryKeyboardCategory();
|
2023-03-14 12:50:02 -07:00
|
|
|
},
|
2023-03-14 12:01:23 -07:00
|
|
|
'manufacturer_id' => function () {
|
|
|
|
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
|
|
|
|
},
|
2021-06-10 13:17:44 -07:00
|
|
|
'qty' => 10,
|
|
|
|
'min_amt' => 2,
|
2023-03-16 12:41:34 -07:00
|
|
|
'supplier_id' => Supplier::factory(),
|
2021-06-10 13:17:44 -07:00
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
2017-10-07 02:27:02 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
public function appleUsbKeyboard()
|
|
|
|
{
|
|
|
|
return $this->state(function () {
|
|
|
|
return [
|
|
|
|
'name' => 'USB Keyboard',
|
|
|
|
'image' => 'usb-keyboard.jpg',
|
2023-03-14 12:50:02 -07:00
|
|
|
'category_id' => function () {
|
2023-03-20 12:01:39 -07:00
|
|
|
return Category::where('name', 'Keyboards')->first() ?? Category::factory()->accessoryKeyboardCategory();
|
2023-03-14 12:50:02 -07:00
|
|
|
},
|
2023-03-14 12:01:23 -07:00
|
|
|
'manufacturer_id' => function () {
|
|
|
|
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
|
|
|
|
},
|
2021-06-10 13:17:44 -07:00
|
|
|
'qty' => 15,
|
|
|
|
'min_amt' => 2,
|
2023-03-16 12:41:34 -07:00
|
|
|
'supplier_id' => Supplier::factory(),
|
2021-06-10 13:17:44 -07:00
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
2017-10-07 02:27:02 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
public function appleMouse()
|
|
|
|
{
|
|
|
|
return $this->state(function () {
|
|
|
|
return [
|
|
|
|
'name' => 'Magic Mouse',
|
|
|
|
'image' => 'magic-mouse.jpg',
|
2023-03-14 12:50:02 -07:00
|
|
|
'category_id' => function () {
|
|
|
|
return Category::where('name', 'Mouse')->first() ?? Category::factory()->accessoryMouseCategory();
|
|
|
|
},
|
2023-03-14 12:01:23 -07:00
|
|
|
'manufacturer_id' => function () {
|
|
|
|
return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple();
|
|
|
|
},
|
2021-06-10 13:17:44 -07:00
|
|
|
'qty' => 13,
|
|
|
|
'min_amt' => 2,
|
2023-03-16 12:41:34 -07:00
|
|
|
'supplier_id' => Supplier::factory(),
|
2021-06-10 13:17:44 -07:00
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
2017-10-07 02:27:02 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
public function microsoftMouse()
|
|
|
|
{
|
|
|
|
return $this->state(function () {
|
|
|
|
return [
|
|
|
|
'name' => 'Sculpt Comfort Mouse',
|
|
|
|
'image' => 'comfort-mouse.jpg',
|
2023-03-14 12:50:02 -07:00
|
|
|
'category_id' => function () {
|
|
|
|
return Category::where('name', 'Mouse')->first() ?? Category::factory()->accessoryMouseCategory();
|
|
|
|
},
|
2023-03-14 12:01:23 -07:00
|
|
|
'manufacturer_id' => function () {
|
|
|
|
return Manufacturer::where('name', 'Microsoft')->first() ?? Manufacturer::factory()->microsoft();
|
|
|
|
},
|
2021-06-10 13:17:44 -07:00
|
|
|
'qty' => 13,
|
|
|
|
'min_amt' => 2,
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
2024-01-29 14:21:30 -08:00
|
|
|
|
|
|
|
public function withoutItemsRemaining()
|
|
|
|
{
|
|
|
|
return $this->state(function () {
|
|
|
|
return [
|
|
|
|
'qty' => 1,
|
|
|
|
];
|
|
|
|
})->afterCreating(function ($accessory) {
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
2024-07-29 01:54:53 -07:00
|
|
|
$accessory->checkouts()->create([
|
2024-01-29 14:21:30 -08:00
|
|
|
'accessory_id' => $accessory->id,
|
2024-07-29 01:54:53 -07:00
|
|
|
'created_at' => Carbon::now(),
|
2024-09-17 14:16:41 -07:00
|
|
|
'created_by' => $user->id,
|
2024-01-29 14:21:30 -08:00
|
|
|
'assigned_to' => $user->id,
|
2024-07-29 01:54:53 -07:00
|
|
|
'assigned_type' => User::class,
|
2024-01-29 14:21:30 -08:00
|
|
|
'note' => '',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
}
|
2024-01-29 15:56:18 -08:00
|
|
|
|
|
|
|
public function requiringAcceptance()
|
|
|
|
{
|
|
|
|
return $this->afterCreating(function ($accessory) {
|
|
|
|
$accessory->category->update(['require_acceptance' => 1]);
|
|
|
|
});
|
|
|
|
}
|
2024-02-12 12:54:48 -08:00
|
|
|
|
2024-02-12 16:31:32 -08:00
|
|
|
public function checkedOutToUser(User $user = null)
|
2024-02-12 12:54:48 -08:00
|
|
|
{
|
2024-02-12 16:22:59 -08:00
|
|
|
return $this->afterCreating(function (Accessory $accessory) use ($user) {
|
2024-07-29 01:54:53 -07:00
|
|
|
$accessory->checkouts()->create([
|
2024-02-12 12:54:48 -08:00
|
|
|
'accessory_id' => $accessory->id,
|
|
|
|
'created_at' => Carbon::now(),
|
2024-09-17 14:16:41 -07:00
|
|
|
'created_by' => 1,
|
2024-02-12 16:22:59 -08:00
|
|
|
'assigned_to' => $user->id ?? User::factory()->create()->id,
|
2024-07-29 01:54:53 -07:00
|
|
|
'assigned_type' => User::class,
|
2024-02-12 12:54:48 -08:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
}
|
2024-09-19 11:24:01 -07:00
|
|
|
|
|
|
|
public function checkedOutToUsers(array $users)
|
|
|
|
{
|
|
|
|
return $this->afterCreating(function (Accessory $accessory) use ($users) {
|
|
|
|
foreach ($users as $user) {
|
|
|
|
$accessory->checkouts()->create([
|
|
|
|
'accessory_id' => $accessory->id,
|
|
|
|
'created_at' => Carbon::now(),
|
|
|
|
'user_id' => 1,
|
|
|
|
'assigned_to' => $user->id,
|
|
|
|
'assigned_type' => User::class,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-06-10 13:17:44 -07:00
|
|
|
}
|