SparePartOrdersView.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class SparePartOrdersView extends Model
  5. {
  6. protected $table = 'spare_part_orders_view';
  7. public $timestamps = false;
  8. const DEFAULT_SORT_BY = 'created_at';
  9. const STATUS_NAMES = [
  10. 'ordered' => 'Заказано',
  11. 'in_stock' => 'На складе',
  12. 'shipped' => 'Отгружено',
  13. ];
  14. protected $casts = [
  15. 'with_documents' => 'boolean',
  16. 'ordered_quantity' => 'integer',
  17. 'available_qty' => 'integer',
  18. 'year' => 'integer',
  19. ];
  20. /**
  21. * Статус на русском языке
  22. */
  23. public function getStatusNameAttribute(): string
  24. {
  25. return self::STATUS_NAMES[$this->status] ?? $this->status;
  26. }
  27. /**
  28. * С документами - да/нет
  29. */
  30. public function getWithDocumentsTextAttribute(): string
  31. {
  32. return $this->with_documents ? 'Да' : 'Нет';
  33. }
  34. /**
  35. * @deprecated Используйте available_qty
  36. */
  37. public function getRemainingQuantityAttribute(): int
  38. {
  39. return $this->available_qty ?? 0;
  40. }
  41. }