InventoryMovementFactory.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\InventoryMovement;
  4. use App\Models\SparePart;
  5. use App\Models\SparePartOrder;
  6. use App\Models\User;
  7. use Illuminate\Database\Eloquent\Factories\Factory;
  8. /**
  9. * @extends Factory<InventoryMovement>
  10. */
  11. class InventoryMovementFactory extends Factory
  12. {
  13. protected $model = InventoryMovement::class;
  14. public function definition(): array
  15. {
  16. return [
  17. 'spare_part_order_id' => SparePartOrder::factory(),
  18. 'spare_part_id' => SparePart::factory(),
  19. 'qty' => fake()->numberBetween(1, 20),
  20. 'movement_type' => InventoryMovement::TYPE_RECEIPT,
  21. 'source_type' => InventoryMovement::SOURCE_MANUAL,
  22. 'source_id' => null,
  23. 'with_documents' => fake()->boolean(),
  24. 'user_id' => User::factory(),
  25. 'note' => fake()->optional()->sentence(),
  26. ];
  27. }
  28. public function receipt(): static
  29. {
  30. return $this->state(fn (array $attributes) => [
  31. 'movement_type' => InventoryMovement::TYPE_RECEIPT,
  32. ]);
  33. }
  34. public function reserve(): static
  35. {
  36. return $this->state(fn (array $attributes) => [
  37. 'movement_type' => InventoryMovement::TYPE_RESERVE,
  38. ]);
  39. }
  40. public function issue(): static
  41. {
  42. return $this->state(fn (array $attributes) => [
  43. 'movement_type' => InventoryMovement::TYPE_ISSUE,
  44. ]);
  45. }
  46. public function reserveCancel(): static
  47. {
  48. return $this->state(fn (array $attributes) => [
  49. 'movement_type' => InventoryMovement::TYPE_RESERVE_CANCEL,
  50. ]);
  51. }
  52. public function forReclamation(int $reclamationId): static
  53. {
  54. return $this->state(fn (array $attributes) => [
  55. 'source_type' => InventoryMovement::SOURCE_RECLAMATION,
  56. 'source_id' => $reclamationId,
  57. ]);
  58. }
  59. public function fromOrder(SparePartOrder $order): static
  60. {
  61. return $this->state(fn (array $attributes) => [
  62. 'spare_part_order_id' => $order->id,
  63. 'spare_part_id' => $order->spare_part_id,
  64. 'with_documents' => $order->with_documents,
  65. ]);
  66. }
  67. }