| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace Database\Factories;
- use App\Models\Reclamation;
- use App\Models\Reservation;
- use App\Models\SparePart;
- use App\Models\SparePartOrder;
- use Illuminate\Database\Eloquent\Factories\Factory;
- /**
- * @extends Factory<Reservation>
- */
- class ReservationFactory extends Factory
- {
- protected $model = Reservation::class;
- public function definition(): array
- {
- return [
- 'spare_part_id' => SparePart::factory(),
- 'spare_part_order_id' => SparePartOrder::factory(),
- 'reclamation_id' => Reclamation::factory(),
- 'reserved_qty' => fake()->numberBetween(1, 10),
- 'with_documents' => fake()->boolean(),
- 'status' => Reservation::STATUS_ACTIVE,
- 'movement_id' => null,
- ];
- }
- public function active(): static
- {
- return $this->state(fn (array $attributes) => [
- 'status' => Reservation::STATUS_ACTIVE,
- ]);
- }
- public function issued(): static
- {
- return $this->state(fn (array $attributes) => [
- 'status' => Reservation::STATUS_ISSUED,
- ]);
- }
- public function cancelled(): static
- {
- return $this->state(fn (array $attributes) => [
- 'status' => Reservation::STATUS_CANCELLED,
- ]);
- }
- 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) => [
- 'reserved_qty' => $quantity,
- ]);
- }
- public function forReclamation(Reclamation $reclamation): static
- {
- return $this->state(fn (array $attributes) => [
- 'reclamation_id' => $reclamation->id,
- ]);
- }
- public function forSparePart(SparePart $sparePart): static
- {
- return $this->state(fn (array $attributes) => [
- 'spare_part_id' => $sparePart->id,
- ]);
- }
- public function fromOrder(SparePartOrder $order): static
- {
- return $this->state(fn (array $attributes) => [
- 'spare_part_order_id' => $order->id,
- 'spare_part_id' => $order->spare_part_id,
- 'with_documents' => $order->with_documents,
- ]);
- }
- }
|