| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace Database\Factories;
- use App\Models\Order;
- use App\Models\Reclamation;
- use App\Models\ReclamationType;
- use App\Models\User;
- use Illuminate\Database\Eloquent\Factories\Factory;
- /**
- * @extends Factory<Reclamation>
- */
- class ReclamationFactory extends Factory
- {
- protected $model = Reclamation::class;
- public function definition(): array
- {
- return [
- 'order_id' => Order::factory(),
- 'reclamation_type_id' => fn (): int => ReclamationType::idForCode(ReclamationType::CODE_DKR),
- 'user_id' => User::factory(),
- 'status_id' => Reclamation::STATUS_NEW,
- 'reason' => fake()->sentence(),
- 'guarantee' => fake()->boolean(),
- 'whats_done' => fake()->optional()->sentence(),
- 'create_date' => fake()->dateTimeBetween('-1 month', 'now')->format('Y-m-d'),
- 'finish_date' => fake()->dateTimeBetween('now', '+1 month')->format('Y-m-d'),
- 'start_work_date' => null,
- 'work_days' => fake()->numberBetween(1, 14),
- 'brigadier_id' => null,
- 'comment' => fake()->optional()->sentence(),
- 'factory_reclamation_number' => fake()->optional()->bothify('FR-#####'),
- ];
- }
- public function withStatus(int $status): static
- {
- return $this->state(fn (array $attributes) => [
- 'status_id' => $status,
- ]);
- }
- public function dkr(): static
- {
- return $this->state(fn (): array => [
- 'reclamation_type_id' => ReclamationType::idForCode(ReclamationType::CODE_DKR),
- ]);
- }
- public function other(): static
- {
- return $this->state(fn (): array => [
- 'reclamation_type_id' => ReclamationType::idForCode(ReclamationType::CODE_OTHER),
- ]);
- }
- public function inWork(): static
- {
- return $this->state(fn (array $attributes) => [
- 'status_id' => Reclamation::STATUS_IN_WORK,
- 'start_work_date' => now()->format('Y-m-d'),
- ]);
- }
- public function done(): static
- {
- return $this->state(fn (array $attributes) => [
- 'status_id' => Reclamation::STATUS_DONE,
- 'finish_date' => now()->format('Y-m-d'),
- ]);
- }
- public function forOrder(Order $order): static
- {
- return $this->state(fn (array $attributes) => [
- 'order_id' => $order->id,
- ]);
- }
- }
|