Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Vendor.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Models\Common;
  3. use App\Concerns\Blamable;
  4. use App\Concerns\CompanyOwned;
  5. use App\Enums\Common\ContractorType;
  6. use App\Enums\Common\VendorType;
  7. use App\Models\Accounting\Bill;
  8. use App\Models\Setting\Currency;
  9. use Illuminate\Database\Eloquent\Factories\HasFactory;
  10. use Illuminate\Database\Eloquent\Model;
  11. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  12. use Illuminate\Database\Eloquent\Relations\HasMany;
  13. use Illuminate\Database\Eloquent\Relations\MorphOne;
  14. class Vendor extends Model
  15. {
  16. use Blamable;
  17. use CompanyOwned;
  18. use HasFactory;
  19. protected $table = 'vendors';
  20. protected $fillable = [
  21. 'company_id',
  22. 'name',
  23. 'type',
  24. 'contractor_type',
  25. 'ssn',
  26. 'ein',
  27. 'currency_code',
  28. 'account_number',
  29. 'website',
  30. 'notes',
  31. 'created_by',
  32. 'updated_by',
  33. ];
  34. protected $casts = [
  35. 'type' => VendorType::class,
  36. 'contractor_type' => ContractorType::class,
  37. 'ssn' => 'encrypted',
  38. 'ein' => 'encrypted',
  39. ];
  40. public function bills(): HasMany
  41. {
  42. return $this->hasMany(Bill::class);
  43. }
  44. public function currency(): BelongsTo
  45. {
  46. return $this->belongsTo(Currency::class, 'currency_code', 'code');
  47. }
  48. public function address(): MorphOne
  49. {
  50. return $this->morphOne(Address::class, 'addressable');
  51. }
  52. public function contact(): MorphOne
  53. {
  54. return $this->morphOne(Contact::class, 'contactable');
  55. }
  56. }