您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Tax.php 2.7KB

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