| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsToMany;
- class PricingCode extends Model
- {
- const TYPE_TSN_NUMBER = 'tsn_number';
- const TYPE_PRICING_CODE = 'pricing_code';
- protected $fillable = [
- 'type',
- 'code',
- 'description',
- ];
- public function spareParts(): BelongsToMany
- {
- return $this->belongsToMany(SparePart::class, 'spare_part_pricing_code')
- ->withTimestamps();
- }
- /**
- * Получить расшифровку для № по ТСН
- */
- 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]
- );
- }
- }
|