ReclamationFactory.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\Order;
  4. use App\Models\Reclamation;
  5. use App\Models\ReclamationType;
  6. use App\Models\User;
  7. use Illuminate\Database\Eloquent\Factories\Factory;
  8. /**
  9. * @extends Factory<Reclamation>
  10. */
  11. class ReclamationFactory extends Factory
  12. {
  13. protected $model = Reclamation::class;
  14. public function definition(): array
  15. {
  16. return [
  17. 'order_id' => Order::factory(),
  18. 'reclamation_type_id' => fn (): int => ReclamationType::idForCode(ReclamationType::CODE_DKR),
  19. 'user_id' => User::factory(),
  20. 'status_id' => Reclamation::STATUS_NEW,
  21. 'reason' => fake()->sentence(),
  22. 'guarantee' => fake()->boolean(),
  23. 'whats_done' => fake()->optional()->sentence(),
  24. 'create_date' => fake()->dateTimeBetween('-1 month', 'now')->format('Y-m-d'),
  25. 'finish_date' => fake()->dateTimeBetween('now', '+1 month')->format('Y-m-d'),
  26. 'start_work_date' => null,
  27. 'work_days' => fake()->numberBetween(1, 14),
  28. 'brigadier_id' => null,
  29. 'comment' => fake()->optional()->sentence(),
  30. 'factory_reclamation_number' => fake()->optional()->bothify('FR-#####'),
  31. ];
  32. }
  33. public function withStatus(int $status): static
  34. {
  35. return $this->state(fn (array $attributes) => [
  36. 'status_id' => $status,
  37. ]);
  38. }
  39. public function dkr(): static
  40. {
  41. return $this->state(fn (): array => [
  42. 'reclamation_type_id' => ReclamationType::idForCode(ReclamationType::CODE_DKR),
  43. ]);
  44. }
  45. public function other(): static
  46. {
  47. return $this->state(fn (): array => [
  48. 'reclamation_type_id' => ReclamationType::idForCode(ReclamationType::CODE_OTHER),
  49. ]);
  50. }
  51. public function inWork(): static
  52. {
  53. return $this->state(fn (array $attributes) => [
  54. 'status_id' => Reclamation::STATUS_IN_WORK,
  55. 'start_work_date' => now()->format('Y-m-d'),
  56. ]);
  57. }
  58. public function done(): static
  59. {
  60. return $this->state(fn (array $attributes) => [
  61. 'status_id' => Reclamation::STATUS_DONE,
  62. 'finish_date' => now()->format('Y-m-d'),
  63. ]);
  64. }
  65. public function forOrder(Order $order): static
  66. {
  67. return $this->state(fn (array $attributes) => [
  68. 'order_id' => $order->id,
  69. ]);
  70. }
  71. }