You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 line
766B

  1. <?php
  2. namespace App\Models;
  3. use Framework\Database\Model;
  4. class Stock extends Model
  5. {
  6. protected string $table = 'stock';
  7. public function item(): mixed
  8. {
  9. return $this->belongsTo(Item::class, 'item_id');
  10. }
  11. public function location(): mixed
  12. {
  13. return $this->belongsTo(Location::class, 'location_id');
  14. }
  15. public static function forItemAtLocation(int $itemId, int $locationId): static
  16. {
  17. $stock = static::where('item_id', $itemId)->where('location_id', $locationId)->first();
  18. if ($stock) {
  19. return $stock;
  20. }
  21. $stock = new static();
  22. $stock->item_id = $itemId;
  23. $stock->location_id = $locationId;
  24. $stock->quantity = 0;
  25. return $stock;
  26. }
  27. }

Powered by TurnKey Linux.