PricingCode.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class PricingCode extends Model
  5. {
  6. const TYPE_TSN_NUMBER = 'tsn_number';
  7. const TYPE_PRICING_CODE = 'pricing_code';
  8. protected $fillable = [
  9. 'type',
  10. 'code',
  11. 'description',
  12. ];
  13. /**
  14. * Получить расшифровку для № по ТСН
  15. */
  16. public static function getTsnDescription(?string $code): ?string
  17. {
  18. if (!$code) {
  19. return null;
  20. }
  21. return self::where('type', self::TYPE_TSN_NUMBER)
  22. ->where('code', $code)
  23. ->value('description');
  24. }
  25. /**
  26. * Получить расшифровку для шифра расценки
  27. */
  28. public static function getPricingCodeDescription(?string $code): ?string
  29. {
  30. if (!$code) {
  31. return null;
  32. }
  33. return self::where('type', self::TYPE_PRICING_CODE)
  34. ->where('code', $code)
  35. ->value('description');
  36. }
  37. /**
  38. * Создать или обновить запись справочника
  39. */
  40. public static function createOrUpdate(string $type, string $code, string $description): void
  41. {
  42. self::updateOrCreate(
  43. ['type' => $type, 'code' => $code],
  44. ['description' => $description]
  45. );
  46. }
  47. }