You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. use Wallo\FilamentCompanies\FilamentCompanies;
  14. class Tax extends Model
  15. {
  16. use HasFactory;
  17. protected $table = 'taxes';
  18. protected $fillable = [
  19. 'company_id',
  20. 'name',
  21. 'description',
  22. 'rate',
  23. 'computation',
  24. 'type',
  25. 'scope',
  26. 'enabled',
  27. 'created_by',
  28. 'updated_by',
  29. ];
  30. protected $casts = [
  31. 'enabled' => 'boolean',
  32. ];
  33. public function company(): BelongsTo
  34. {
  35. return $this->belongsTo(Company::class, 'company_id');
  36. }
  37. public function createdBy(): BelongsTo
  38. {
  39. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  40. }
  41. public function updatedBy(): BelongsTo
  42. {
  43. return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by');
  44. }
  45. public function items(): HasMany
  46. {
  47. return $this->hasMany(Item::class);
  48. }
  49. public function document_items(): HasMany
  50. {
  51. return $this->hasMany(DocumentItem::class);
  52. }
  53. public function bill_items(): HasMany
  54. {
  55. return $this->document_items()->where('type', 'bill');
  56. }
  57. public function invoice_items(): HasMany
  58. {
  59. return $this->document_items()->where('type', 'invoice');
  60. }
  61. public static function getComputationTypes(): array
  62. {
  63. return [
  64. 'fixed' => 'Fixed',
  65. 'percentage' => 'Percentage',
  66. 'compound' => 'Compound',
  67. ];
  68. }
  69. public static function getTaxTypes(): array
  70. {
  71. return [
  72. 'sales' => 'Sales',
  73. 'purchase' => 'Purchase',
  74. 'none' => 'None',
  75. ];
  76. }
  77. public static function getTaxScopes(): array
  78. {
  79. return [
  80. 'product' => 'Product',
  81. 'service' => 'Service',
  82. ];
  83. }
  84. protected static function newFactory(): Factory
  85. {
  86. return TaxFactory::new();
  87. }
  88. }