*/ 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, ]); } }