| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace Database\Factories;
- use App\Models\SparePart;
- use App\Models\SparePartOrder;
- use App\Models\User;
- use Illuminate\Database\Eloquent\Factories\Factory;
- /**
- * @extends Factory<SparePartOrder>
- */
- class SparePartOrderFactory extends Factory
- {
- protected $model = SparePartOrder::class;
- public function definition(): array
- {
- $quantity = fake()->numberBetween(5, 100);
- return [
- 'year' => (int) date('Y'),
- 'spare_part_id' => SparePart::factory(),
- 'source_text' => fake()->company(),
- 'status' => SparePartOrder::STATUS_IN_STOCK,
- 'ordered_quantity' => $quantity,
- 'available_qty' => $quantity,
- 'with_documents' => fake()->boolean(),
- 'note' => fake()->optional()->sentence(),
- 'user_id' => User::factory(),
- ];
- }
- public function ordered(): static
- {
- return $this->state(fn (array $attributes) => [
- 'status' => SparePartOrder::STATUS_ORDERED,
- ]);
- }
- public function inStock(): static
- {
- return $this->state(fn (array $attributes) => [
- 'status' => SparePartOrder::STATUS_IN_STOCK,
- ]);
- }
- public function shipped(): static
- {
- return $this->state(fn (array $attributes) => [
- 'status' => SparePartOrder::STATUS_SHIPPED,
- 'available_qty' => 0,
- ]);
- }
- public function withDocuments(bool $withDocs = true): static
- {
- return $this->state(fn (array $attributes) => [
- 'with_documents' => $withDocs,
- ]);
- }
- public function withQuantity(int $quantity): static
- {
- return $this->state(fn (array $attributes) => [
- 'ordered_quantity' => $quantity,
- 'available_qty' => $quantity,
- ]);
- }
- public function forSparePart(SparePart $sparePart): static
- {
- return $this->state(fn (array $attributes) => [
- 'spare_part_id' => $sparePart->id,
- ]);
- }
- }
|