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.

Tax.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Models\Setting;
  3. use App\Models\Company;
  4. use App\Models\Document\DocumentItem;
  5. use App\Models\Item;
  6. use App\Models\User;
  7. use Database\Factories\TaxFactory;
  8. use Illuminate\Database\Eloquent\Factories\Factory;
  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. class Tax extends Model
  14. {
  15. use HasFactory;
  16. protected $table = 'taxes';
  17. protected $fillable = [
  18. 'company_id',
  19. 'name',
  20. 'description',
  21. 'rate',
  22. 'computation',
  23. 'type',
  24. 'scope',
  25. 'enabled',
  26. 'created_by',
  27. ];
  28. protected $casts = [
  29. 'enabled' => 'boolean',
  30. ];
  31. public function company(): BelongsTo
  32. {
  33. return $this->belongsTo(Company::class, 'company_id');
  34. }
  35. public function createdBy(): BelongsTo
  36. {
  37. return $this->belongsTo(User::class, 'created_by');
  38. }
  39. public function items(): HasMany
  40. {
  41. return $this->hasMany(Item::class);
  42. }
  43. public function document_items(): HasMany
  44. {
  45. return $this->hasMany(DocumentItem::class);
  46. }
  47. public function bill_items(): HasMany
  48. {
  49. return $this->document_items()->where('type', 'bill');
  50. }
  51. public function invoice_items(): HasMany
  52. {
  53. return $this->document_items()->where('type', 'invoice');
  54. }
  55. protected static function newFactory(): Factory
  56. {
  57. return TaxFactory::new();
  58. }
  59. }