2021-06-10 13:17:44 -07:00
|
|
|
<?php
|
2021-06-10 13:19:27 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
namespace Database\Factories;
|
|
|
|
|
2024-07-26 05:16:31 -07:00
|
|
|
use App\Models\Accessory;
|
|
|
|
use App\Models\Asset;
|
2023-03-14 12:50:02 -07:00
|
|
|
use App\Models\Category;
|
|
|
|
use App\Models\Company;
|
2023-03-20 11:39:27 -07:00
|
|
|
use App\Models\Component;
|
2024-10-23 11:05:34 -07:00
|
|
|
use App\Models\Manufacturer;
|
2024-07-26 05:16:31 -07:00
|
|
|
use App\Models\Consumable;
|
2023-03-13 17:27:06 -07:00
|
|
|
use App\Models\Location;
|
2024-07-26 05:16:31 -07:00
|
|
|
use App\Models\User;
|
|
|
|
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;
|
2021-06-10 13:17:44 -07:00
|
|
|
|
|
|
|
class ComponentFactory extends Factory
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name of the factory's corresponding model.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-03-20 11:39:27 -07:00
|
|
|
protected $model = Component::class;
|
2021-06-10 13:17:44 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Define the model's default state.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function definition()
|
|
|
|
{
|
2024-10-23 17:27:50 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
return [
|
2021-06-11 19:41:20 -07:00
|
|
|
'name' => $this->faker->text(20),
|
2023-03-14 12:50:02 -07:00
|
|
|
'category_id' => Category::factory(),
|
2023-03-15 18:31:08 -07:00
|
|
|
'location_id' => Location::factory(),
|
2023-03-16 17:07:46 -07:00
|
|
|
'serial' => $this->faker->uuid(),
|
2021-06-11 19:41:20 -07:00
|
|
|
'qty' => $this->faker->numberBetween(3, 10),
|
2021-06-10 13:17:44 -07:00
|
|
|
'order_number' => $this->faker->numberBetween(1000000, 50000000),
|
2023-03-14 17:02:45 -07:00
|
|
|
'purchase_date' => $this->faker->dateTime()->format('Y-m-d'),
|
2021-06-11 19:41:20 -07:00
|
|
|
'purchase_cost' => $this->faker->randomFloat(2),
|
2021-06-10 13:17:44 -07:00
|
|
|
'min_amt' => $this->faker->numberBetween($min = 1, $max = 2),
|
2023-03-14 12:50:02 -07:00
|
|
|
'company_id' => Company::factory(),
|
2023-04-13 11:07:22 -07:00
|
|
|
'supplier_id' => Supplier::factory(),
|
2024-10-23 11:05:34 -07:00
|
|
|
'model_number' => $this->faker->numberBetween(1000000, 50000000),
|
2021-06-10 13:17:44 -07:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ramCrucial4()
|
|
|
|
{
|
2024-10-23 17:27:50 -07:00
|
|
|
$manufacturer = Manufacturer::where('name', 'Crucial')->first() ?? Manufacturer::factory()->create(['name' => 'Crucial']);
|
|
|
|
return $this->state(function () use ($manufacturer) {
|
2021-06-10 13:17:44 -07:00
|
|
|
return [
|
|
|
|
'name' => 'Crucial 4GB DDR3L-1600 SODIMM',
|
2023-03-14 12:50:02 -07:00
|
|
|
'category_id' => function () {
|
|
|
|
return Category::where('name', 'RAM')->first() ?? Category::factory()->componentRamCategory();
|
|
|
|
},
|
2021-06-10 13:17:44 -07:00
|
|
|
'qty' => 10,
|
|
|
|
'min_amt' => 2,
|
2024-10-23 17:27:50 -07:00
|
|
|
'manufacturer_id' => $manufacturer->id,
|
2023-03-15 18:31:08 -07:00
|
|
|
'location_id' => Location::factory(),
|
2021-06-10 13:17:44 -07:00
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ramCrucial8()
|
|
|
|
{
|
2024-10-23 17:27:50 -07:00
|
|
|
$manufacturer = Manufacturer::where('name', 'Crucial')->first() ?? Manufacturer::factory()->create(['name' => 'Crucial']);
|
|
|
|
return $this->state(function () use ($manufacturer) {
|
2021-06-10 13:17:44 -07:00
|
|
|
return [
|
|
|
|
'name' => 'Crucial 8GB DDR3L-1600 SODIMM Memory for Mac',
|
2023-03-14 12:50:02 -07:00
|
|
|
'category_id' => function () {
|
|
|
|
return Category::where('name', 'RAM')->first() ?? Category::factory()->componentRamCategory();
|
|
|
|
},
|
2021-06-10 13:17:44 -07:00
|
|
|
'qty' => 10,
|
|
|
|
'min_amt' => 2,
|
2024-10-23 17:27:50 -07:00
|
|
|
'manufacturer_id' => $manufacturer->id,
|
2021-06-10 13:17:44 -07:00
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ssdCrucial120()
|
|
|
|
{
|
2024-10-23 17:27:50 -07:00
|
|
|
$manufacturer = Manufacturer::where('name', 'Crucial')->first() ?? Manufacturer::factory()->create(['name' => 'Crucial']);
|
|
|
|
return $this->state(function () use ($manufacturer) {
|
2021-06-10 13:17:44 -07:00
|
|
|
return [
|
|
|
|
'name' => 'Crucial BX300 120GB SATA Internal SSD',
|
2023-03-14 12:50:02 -07:00
|
|
|
'category_id' => function () {
|
|
|
|
return Category::where('name', 'HDD/SSD')->first() ?? Category::factory()->componentHddCategory();
|
|
|
|
},
|
2021-06-10 13:17:44 -07:00
|
|
|
'qty' => 10,
|
|
|
|
'min_amt' => 2,
|
2024-10-23 17:27:50 -07:00
|
|
|
'manufacturer_id' => $manufacturer->id,
|
2021-06-10 13:17:44 -07:00
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ssdCrucial240()
|
|
|
|
{
|
2024-10-23 17:27:50 -07:00
|
|
|
$manufacturer = Manufacturer::where('name', 'Crucial')->first() ?? Manufacturer::factory()->create(['name' => 'Crucial']);
|
|
|
|
return $this->state(function () use ($manufacturer) {
|
2021-06-10 13:17:44 -07:00
|
|
|
return [
|
|
|
|
'name' => 'Crucial BX300 240GB SATA Internal SSD',
|
2023-03-14 12:50:02 -07:00
|
|
|
'category_id' => function () {
|
|
|
|
return Category::where('name', 'HDD/SSD')->first() ?? Category::factory()->componentHddCategory();
|
|
|
|
},
|
2021-06-10 13:17:44 -07:00
|
|
|
'qty' => 10,
|
|
|
|
'min_amt' => 2,
|
2024-10-23 17:27:50 -07:00
|
|
|
'manufacturer_id' => $manufacturer->id,
|
2021-06-10 13:17:44 -07:00
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-07-26 05:16:31 -07:00
|
|
|
public function checkedOutToAsset(Asset $asset = null)
|
|
|
|
{
|
|
|
|
return $this->afterCreating(function (Component $component) use ($asset) {
|
|
|
|
$component->assets()->attach($component->id, [
|
|
|
|
'component_id' => $component->id,
|
|
|
|
'created_at' => Carbon::now(),
|
2024-09-17 14:16:41 -07:00
|
|
|
'created_by' => 1,
|
2024-07-26 05:16:31 -07:00
|
|
|
'asset_id' => $asset->id ?? Asset::factory()->create()->id,
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
}
|
2021-06-11 19:41:20 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
}
|