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

CompanyDefault.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Models\Setting;
  3. use App\Enums\CategoryType;
  4. use App\Enums\DiscountType;
  5. use App\Enums\TaxType;
  6. use App\Models\Banking\Account;
  7. use App\Traits\Blamable;
  8. use App\Traits\CompanyOwned;
  9. use Database\Factories\Setting\CompanyDefaultFactory;
  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 Wallo\FilamentCompanies\FilamentCompanies;
  15. class CompanyDefault extends Model
  16. {
  17. use Blamable;
  18. use CompanyOwned;
  19. use HasFactory;
  20. protected $table = 'company_defaults';
  21. protected $fillable = [
  22. 'company_id',
  23. 'account_id',
  24. 'currency_code',
  25. 'sales_tax_id',
  26. 'purchase_tax_id',
  27. 'sales_discount_id',
  28. 'purchase_discount_id',
  29. 'income_category_id',
  30. 'expense_category_id',
  31. 'created_by',
  32. 'updated_by',
  33. ];
  34. public function company(): BelongsTo
  35. {
  36. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  37. }
  38. public function account(): BelongsTo
  39. {
  40. return $this->belongsTo(Account::class, 'account_id');
  41. }
  42. public function currency(): BelongsTo
  43. {
  44. return $this->belongsTo(Currency::class, 'currency_code', 'code');
  45. }
  46. public function salesTax(): BelongsTo
  47. {
  48. return $this->belongsTo(Tax::class, 'sales_tax_id', 'id')
  49. ->where('type', TaxType::Sales);
  50. }
  51. public function purchaseTax(): BelongsTo
  52. {
  53. return $this->belongsTo(Tax::class, 'purchase_tax_id', 'id')
  54. ->where('type', TaxType::Purchase);
  55. }
  56. public function salesDiscount(): BelongsTo
  57. {
  58. return $this->belongsTo(Discount::class, 'sales_discount_id', 'id')
  59. ->where('type', DiscountType::Sales);
  60. }
  61. public function purchaseDiscount(): BelongsTo
  62. {
  63. return $this->belongsTo(Discount::class, 'purchase_discount_id', 'id')
  64. ->where('type', DiscountType::Purchase);
  65. }
  66. public function incomeCategory(): BelongsTo
  67. {
  68. return $this->belongsTo(Category::class, 'income_category_id', 'id')
  69. ->where('type', CategoryType::Income);
  70. }
  71. public function expenseCategory(): BelongsTo
  72. {
  73. return $this->belongsTo(Category::class, 'expense_category_id', 'id')
  74. ->where('type', CategoryType::Expense);
  75. }
  76. public function createdBy(): BelongsTo
  77. {
  78. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  79. }
  80. public function updatedBy(): BelongsTo
  81. {
  82. return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by');
  83. }
  84. protected static function newFactory(): Factory
  85. {
  86. return CompanyDefaultFactory::new();
  87. }
  88. }