Contractor.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Casts\Attribute;
  4. use Illuminate\Database\Eloquent\Factories\HasFactory;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Database\Eloquent\Relations\HasMany;
  7. class Contractor extends Model
  8. {
  9. use HasFactory;
  10. public const ORGANIZATION_FORM_IP = 'ip';
  11. public const ORGANIZATION_FORM_OOO = 'ooo';
  12. public const ORGANIZATION_FORM_SELF_EMPLOYED = 'self_employed';
  13. public const TAX_WITHOUT_VAT = 'without_vat';
  14. public const TAX_5 = '5';
  15. public const TAX_7 = '7';
  16. public const TAX_15 = '15';
  17. public const TAX_22 = '22';
  18. public const ORGANIZATION_FORMS = [
  19. self::ORGANIZATION_FORM_IP => 'ИП',
  20. self::ORGANIZATION_FORM_OOO => 'ООО',
  21. self::ORGANIZATION_FORM_SELF_EMPLOYED => 'Самозанятый',
  22. ];
  23. public const TAX_RATES = [
  24. self::TAX_WITHOUT_VAT => 'Без НДС',
  25. self::TAX_5 => '5%',
  26. self::TAX_7 => '7%',
  27. self::TAX_15 => '15%',
  28. self::TAX_22 => '22%',
  29. ];
  30. public const SIGNER_TITLES = [
  31. self::ORGANIZATION_FORM_IP => 'Индивидуальный предприниматель',
  32. self::ORGANIZATION_FORM_OOO => 'Генеральный директор',
  33. self::ORGANIZATION_FORM_SELF_EMPLOYED => 'Самозанятый',
  34. ];
  35. protected $fillable = [
  36. 'name',
  37. 'legal_name',
  38. 'contract_number',
  39. 'contract_date',
  40. 'director_name',
  41. 'organization_form',
  42. 'tax_rate',
  43. 'contract_header',
  44. 'hidden',
  45. ];
  46. protected $casts = [
  47. 'contract_date' => 'date',
  48. 'hidden' => 'boolean',
  49. ];
  50. protected $appends = [
  51. 'organization_form_name',
  52. 'tax_rate_name',
  53. 'hidden_txt',
  54. 'signer_title',
  55. ];
  56. public function prices(): HasMany
  57. {
  58. return $this->hasMany(ContractorInstallationPrice::class);
  59. }
  60. protected function organizationFormName(): Attribute
  61. {
  62. return Attribute::make(
  63. get: fn() => self::ORGANIZATION_FORMS[$this->organization_form] ?? $this->organization_form,
  64. );
  65. }
  66. protected function taxRateName(): Attribute
  67. {
  68. return Attribute::make(
  69. get: fn() => self::TAX_RATES[$this->tax_rate] ?? $this->tax_rate,
  70. );
  71. }
  72. protected function hiddenTxt(): Attribute
  73. {
  74. return Attribute::make(
  75. get: fn() => $this->hidden ? 'Да' : 'Нет',
  76. );
  77. }
  78. protected function signerTitle(): Attribute
  79. {
  80. return Attribute::make(
  81. get: fn() => self::SIGNER_TITLES[$this->organization_form] ?? '',
  82. );
  83. }
  84. }