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

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