| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace Database\Factories;
- use App\Models\InventoryMovement;
- use App\Models\SparePart;
- use App\Models\SparePartOrder;
- use App\Models\User;
- use Illuminate\Database\Eloquent\Factories\Factory;
- /**
- * @extends Factory<InventoryMovement>
- */
- class InventoryMovementFactory extends Factory
- {
- protected $model = InventoryMovement::class;
- public function definition(): array
- {
- return [
- 'spare_part_order_id' => SparePartOrder::factory(),
- 'spare_part_id' => SparePart::factory(),
- 'qty' => fake()->numberBetween(1, 20),
- 'movement_type' => InventoryMovement::TYPE_RECEIPT,
- 'source_type' => InventoryMovement::SOURCE_MANUAL,
- 'source_id' => null,
- 'with_documents' => fake()->boolean(),
- 'user_id' => User::factory(),
- 'note' => fake()->optional()->sentence(),
- ];
- }
- public function receipt(): static
- {
- return $this->state(fn (array $attributes) => [
- 'movement_type' => InventoryMovement::TYPE_RECEIPT,
- ]);
- }
- public function reserve(): static
- {
- return $this->state(fn (array $attributes) => [
- 'movement_type' => InventoryMovement::TYPE_RESERVE,
- ]);
- }
- public function issue(): static
- {
- return $this->state(fn (array $attributes) => [
- 'movement_type' => InventoryMovement::TYPE_ISSUE,
- ]);
- }
- public function reserveCancel(): static
- {
- return $this->state(fn (array $attributes) => [
- 'movement_type' => InventoryMovement::TYPE_RESERVE_CANCEL,
- ]);
- }
- public function forReclamation(int $reclamationId): static
- {
- return $this->state(fn (array $attributes) => [
- 'source_type' => InventoryMovement::SOURCE_RECLAMATION,
- 'source_id' => $reclamationId,
- ]);
- }
- 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,
- ]);
- }
- }
|