SparePartOrdersView.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. protected $fillable = [
  9. 'id',
  10. 'order_number',
  11. 'article',
  12. 'source_text',
  13. 'status',
  14. 'status_name',
  15. 'ordered_quantity',
  16. 'available_qty',
  17. 'with_documents',
  18. 'with_documents_text',
  19. 'note',
  20. 'user_name',
  21. 'created_at',
  22. 'spare_part_id',
  23. ];
  24. const DEFAULT_SORT_BY = 'created_at';
  25. const STATUS_NAMES = [
  26. 'ordered' => 'Заказано',
  27. 'in_stock' => 'На складе',
  28. 'shipped' => 'Отгружено',
  29. ];
  30. protected $casts = [
  31. 'with_documents' => 'boolean',
  32. 'ordered_quantity' => 'integer',
  33. 'available_qty' => 'integer',
  34. ];
  35. /**
  36. * Статус на русском языке
  37. */
  38. public function getStatusNameAttribute(): string
  39. {
  40. return self::STATUS_NAMES[$this->status] ?? $this->status;
  41. }
  42. /**
  43. * С документами - да/нет
  44. */
  45. public function getWithDocumentsTextAttribute(): string
  46. {
  47. return $this->with_documents ? 'Да' : 'Нет';
  48. }
  49. /**
  50. * @deprecated Используйте available_qty
  51. */
  52. public function getRemainingQuantityAttribute(): int
  53. {
  54. return $this->available_qty ?? 0;
  55. }
  56. }