2017-10-07 02:46:04 -07:00
|
|
|
<?php
|
2021-06-10 13:19:27 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
namespace Database\Factories;
|
|
|
|
|
2023-03-14 12:50:02 -07:00
|
|
|
use App\Models\Category;
|
2023-03-15 14:12:34 -07:00
|
|
|
use App\Models\Company;
|
2023-03-20 11:39:27 -07:00
|
|
|
use App\Models\Consumable;
|
2023-03-14 12:01:23 -07:00
|
|
|
use App\Models\Manufacturer;
|
2023-03-14 11:34:58 -07:00
|
|
|
use App\Models\User;
|
2024-07-03 12:18:53 -07:00
|
|
|
use Carbon\Carbon;
|
2021-06-10 13:19:27 -07:00
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
2023-04-13 11:07:22 -07:00
|
|
|
use App\Models\Supplier;
|
2017-10-07 02:46:04 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
class ConsumableFactory extends Factory
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name of the factory's corresponding model.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-03-20 11:39:27 -07:00
|
|
|
protected $model = Consumable::class;
|
2021-06-10 13:17:44 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Define the model's default state.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function definition()
|
|
|
|
{
|
|
|
|
return [
|
2023-06-05 12:57:09 -07:00
|
|
|
'name' => $this->faker->words(3, true),
|
2023-03-16 17:08:18 -07:00
|
|
|
'category_id' => Category::factory(),
|
2024-09-17 14:16:41 -07:00
|
|
|
'created_by' => User::factory()->superuser(),
|
2021-06-10 13:17:44 -07:00
|
|
|
'item_no' => $this->faker->numberBetween(1000000, 50000000),
|
|
|
|
'order_number' => $this->faker->numberBetween(1000000, 50000000),
|
2023-03-14 01:55:20 -07:00
|
|
|
'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'),
|
2021-06-10 13:17:44 -07:00
|
|
|
'purchase_cost' => $this->faker->randomFloat(2, 1, 50),
|
|
|
|
'qty' => $this->faker->numberBetween(5, 10),
|
|
|
|
'min_amt' => $this->faker->numberBetween($min = 1, $max = 2),
|
2023-03-15 14:12:34 -07:00
|
|
|
'company_id' => Company::factory(),
|
2023-04-13 11:07:22 -07:00
|
|
|
'supplier_id' => Supplier::factory(),
|
2021-06-10 13:17:44 -07:00
|
|
|
];
|
|
|
|
}
|
2017-10-07 02:46:04 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
public function cardstock()
|
|
|
|
{
|
|
|
|
return $this->state(function () {
|
|
|
|
return [
|
|
|
|
'name' => 'Cardstock (White)',
|
2023-03-14 12:50:02 -07:00
|
|
|
'category_id' => function () {
|
|
|
|
return Category::where('name', 'Printer Paper')->first() ?? Category::factory()->consumablePaperCategory();
|
|
|
|
},
|
2023-03-14 12:01:23 -07:00
|
|
|
'manufacturer_id' => function () {
|
|
|
|
return Manufacturer::where('name', 'Avery')->first() ?? Manufacturer::factory()->avery();
|
|
|
|
},
|
2021-06-10 13:17:44 -07:00
|
|
|
'qty' => 10,
|
|
|
|
'min_amt' => 2,
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
2017-10-07 02:46:04 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
public function paper()
|
|
|
|
{
|
|
|
|
return $this->state(function () {
|
|
|
|
return [
|
|
|
|
'name' => 'Laserjet Paper (Ream)',
|
2023-03-14 12:50:02 -07:00
|
|
|
'category_id' => function () {
|
|
|
|
return Category::where('name', 'Printer Paper')->first() ?? Category::factory()->consumablePaperCategory();
|
|
|
|
},
|
2023-03-14 12:01:23 -07:00
|
|
|
'manufacturer_id' => function () {
|
|
|
|
return Manufacturer::where('name', 'Avery')->first() ?? Manufacturer::factory()->avery();
|
|
|
|
},
|
2021-06-10 13:17:44 -07:00
|
|
|
'qty' => 20,
|
|
|
|
'min_amt' => 2,
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
2017-10-07 02:46:04 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
public function ink()
|
|
|
|
{
|
|
|
|
return $this->state(function () {
|
|
|
|
return [
|
|
|
|
'name' => 'Laserjet Toner (black)',
|
2023-03-14 12:50:02 -07:00
|
|
|
'category_id' => function () {
|
|
|
|
return Category::where('name', 'Printer Ink')->first() ?? Category::factory()->consumableInkCategory();
|
|
|
|
},
|
2023-03-14 12:01:23 -07:00
|
|
|
'manufacturer_id' => function () {
|
|
|
|
return Manufacturer::where('name', 'HP')->first() ?? Manufacturer::factory()->hp();
|
|
|
|
},
|
2021-06-10 13:17:44 -07:00
|
|
|
'qty' => 20,
|
|
|
|
'min_amt' => 2,
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
2024-01-30 12:43:20 -08:00
|
|
|
|
|
|
|
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,
|
2024-09-17 14:16:41 -07:00
|
|
|
'created_by' => $user->id,
|
2024-01-30 12:43:20 -08:00
|
|
|
'assigned_to' => $user->id,
|
|
|
|
'note' => '',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
}
|
2024-01-30 13:19:20 -08:00
|
|
|
|
|
|
|
public function requiringAcceptance()
|
|
|
|
{
|
|
|
|
return $this->afterCreating(function (Consumable $consumable) {
|
|
|
|
$consumable->category->update(['require_acceptance' => 1]);
|
|
|
|
});
|
|
|
|
}
|
2024-07-03 12:18:53 -07:00
|
|
|
|
|
|
|
public function checkedOutToUser(User $user = null)
|
|
|
|
{
|
|
|
|
return $this->afterCreating(function (Consumable $consumable) use ($user) {
|
|
|
|
$consumable->users()->attach($consumable->id, [
|
|
|
|
'consumable_id' => $consumable->id,
|
|
|
|
'created_at' => Carbon::now(),
|
2024-09-17 14:16:41 -07:00
|
|
|
'created_by' => User::factory()->create()->id,
|
2024-07-03 12:18:53 -07:00
|
|
|
'assigned_to' => $user->id ?? User::factory()->create()->id,
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
}
|
2021-06-10 13:17:44 -07:00
|
|
|
}
|