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.7KB

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