| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class PricingCode extends Model
- {
- const TYPE_TSN_NUMBER = 'tsn_number';
- const TYPE_PRICING_CODE = 'pricing_code';
- protected $fillable = [
- 'type',
- 'code',
- 'description',
- ];
- /**
- * Получить расшифровку для № по ТСН
- */
- public static function getTsnDescription(?string $code): ?string
- {
- if (!$code) {
- return null;
- }
- return self::where('type', self::TYPE_TSN_NUMBER)
- ->where('code', $code)
- ->value('description');
- }
- /**
- * Получить расшифровку для шифра расценки
- */
- public static function getPricingCodeDescription(?string $code): ?string
- {
- if (!$code) {
- return null;
- }
- return self::where('type', self::TYPE_PRICING_CODE)
- ->where('code', $code)
- ->value('description');
- }
- /**
- * Создать или обновить запись справочника
- */
- public static function createOrUpdate(string $type, string $code, string $description): void
- {
- self::updateOrCreate(
- ['type' => $type, 'code' => $code],
- ['description' => $description]
- );
- }
- }
|