SparePartOrdersView.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. ];
  19. /**
  20. * Статус на русском языке
  21. */
  22. public function getStatusNameAttribute(): string
  23. {
  24. return self::STATUS_NAMES[$this->status] ?? $this->status;
  25. }
  26. /**
  27. * С документами - да/нет
  28. */
  29. public function getWithDocumentsTextAttribute(): string
  30. {
  31. return $this->with_documents ? 'Да' : 'Нет';
  32. }
  33. /**
  34. * @deprecated Используйте available_qty
  35. */
  36. public function getRemainingQuantityAttribute(): int
  37. {
  38. return $this->available_qty ?? 0;
  39. }
  40. }