ReservationFactory.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\Reclamation;
  4. use App\Models\Reservation;
  5. use App\Models\SparePart;
  6. use App\Models\SparePartOrder;
  7. use Illuminate\Database\Eloquent\Factories\Factory;
  8. /**
  9. * @extends Factory<Reservation>
  10. */
  11. class ReservationFactory extends Factory
  12. {
  13. protected $model = Reservation::class;
  14. public function definition(): array
  15. {
  16. return [
  17. 'spare_part_id' => SparePart::factory(),
  18. 'spare_part_order_id' => SparePartOrder::factory(),
  19. 'reclamation_id' => Reclamation::factory(),
  20. 'reserved_qty' => fake()->numberBetween(1, 10),
  21. 'with_documents' => fake()->boolean(),
  22. 'status' => Reservation::STATUS_ACTIVE,
  23. 'movement_id' => null,
  24. ];
  25. }
  26. public function active(): static
  27. {
  28. return $this->state(fn (array $attributes) => [
  29. 'status' => Reservation::STATUS_ACTIVE,
  30. ]);
  31. }
  32. public function issued(): static
  33. {
  34. return $this->state(fn (array $attributes) => [
  35. 'status' => Reservation::STATUS_ISSUED,
  36. ]);
  37. }
  38. public function cancelled(): static
  39. {
  40. return $this->state(fn (array $attributes) => [
  41. 'status' => Reservation::STATUS_CANCELLED,
  42. ]);
  43. }
  44. public function withDocuments(bool $withDocs = true): static
  45. {
  46. return $this->state(fn (array $attributes) => [
  47. 'with_documents' => $withDocs,
  48. ]);
  49. }
  50. public function withQuantity(int $quantity): static
  51. {
  52. return $this->state(fn (array $attributes) => [
  53. 'reserved_qty' => $quantity,
  54. ]);
  55. }
  56. public function forReclamation(Reclamation $reclamation): static
  57. {
  58. return $this->state(fn (array $attributes) => [
  59. 'reclamation_id' => $reclamation->id,
  60. ]);
  61. }
  62. public function forSparePart(SparePart $sparePart): static
  63. {
  64. return $this->state(fn (array $attributes) => [
  65. 'spare_part_id' => $sparePart->id,
  66. ]);
  67. }
  68. public function fromOrder(SparePartOrder $order): static
  69. {
  70. return $this->state(fn (array $attributes) => [
  71. 'spare_part_order_id' => $order->id,
  72. 'spare_part_id' => $order->spare_part_id,
  73. 'with_documents' => $order->with_documents,
  74. ]);
  75. }
  76. }