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.

CompanyDefault.php 2.9KB

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