| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Casts\Attribute;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- class Contractor extends Model
- {
- use HasFactory;
- public const ORGANIZATION_FORM_IP = 'ip';
- public const ORGANIZATION_FORM_OOO = 'ooo';
- public const ORGANIZATION_FORM_SELF_EMPLOYED = 'self_employed';
- public const TAX_WITHOUT_VAT = 'without_vat';
- public const TAX_5 = '5';
- public const TAX_7 = '7';
- public const TAX_15 = '15';
- public const TAX_22 = '22';
- public const ORGANIZATION_FORMS = [
- self::ORGANIZATION_FORM_IP => 'ИП',
- self::ORGANIZATION_FORM_OOO => 'ООО',
- self::ORGANIZATION_FORM_SELF_EMPLOYED => 'Самозанятый',
- ];
- public const TAX_RATES = [
- self::TAX_WITHOUT_VAT => 'Без НДС',
- self::TAX_5 => '5%',
- self::TAX_7 => '7%',
- self::TAX_15 => '15%',
- self::TAX_22 => '22%',
- ];
- public const SIGNER_TITLES = [
- self::ORGANIZATION_FORM_IP => 'Индивидуальный предприниматель',
- self::ORGANIZATION_FORM_OOO => 'Генеральный директор',
- self::ORGANIZATION_FORM_SELF_EMPLOYED => 'Самозанятый',
- ];
- protected $fillable = [
- 'name',
- 'legal_name',
- 'contract_number',
- 'contract_date',
- 'director_name',
- 'organization_form',
- 'tax_rate',
- 'contract_header',
- 'hidden',
- ];
- protected $casts = [
- 'contract_date' => 'date',
- 'hidden' => 'boolean',
- ];
- protected $appends = [
- 'organization_form_name',
- 'tax_rate_name',
- 'hidden_txt',
- 'signer_title',
- ];
- public function prices(): HasMany
- {
- return $this->hasMany(ContractorInstallationPrice::class);
- }
- protected function organizationFormName(): Attribute
- {
- return Attribute::make(
- get: fn() => self::ORGANIZATION_FORMS[$this->organization_form] ?? $this->organization_form,
- );
- }
- protected function taxRateName(): Attribute
- {
- return Attribute::make(
- get: fn() => self::TAX_RATES[$this->tax_rate] ?? $this->tax_rate,
- );
- }
- protected function hiddenTxt(): Attribute
- {
- return Attribute::make(
- get: fn() => $this->hidden ? 'Да' : 'Нет',
- );
- }
- protected function signerTitle(): Attribute
- {
- return Attribute::make(
- get: fn() => self::SIGNER_TITLES[$this->organization_form] ?? '',
- );
- }
- }
|