| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 | 
							- <?php
 - 
 - namespace App\Models\Setting;
 - 
 - use App\Models\Banking\Account;
 - use App\Scopes\CurrentCompanyScope;
 - use App\Traits\Blamable;
 - use App\Traits\CompanyOwned;
 - use Illuminate\Database\Eloquent\Factories\HasFactory;
 - use Illuminate\Database\Eloquent\Model;
 - use Illuminate\Database\Eloquent\Relations\BelongsTo;
 - use Wallo\FilamentCompanies\FilamentCompanies;
 - 
 - class DefaultSetting extends Model
 - {
 -     use Blamable, CompanyOwned, HasFactory;
 - 
 -     protected $table = 'default_settings';
 - 
 -     protected $fillable = [
 -         'company_id',
 -         'account_id',
 -         'currency_code',
 -         'sales_tax_id',
 -         'purchase_tax_id',
 -         'sales_discount_id',
 -         'purchase_discount_id',
 -         'income_category_id',
 -         'expense_category_id',
 -         'created_by',
 -         'updated_by',
 -     ];
 - 
 -     protected static function booted(): void
 -     {
 -         static::addGlobalScope(new CurrentCompanyScope);
 -     }
 - 
 -     public function company(): BelongsTo
 -     {
 -         return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
 -     }
 - 
 -     public function account(): BelongsTo
 -     {
 -         return $this->belongsTo(Account::class, 'account_id');
 -     }
 - 
 -     public function currency(): BelongsTo
 -     {
 -         return $this->belongsTo(Currency::class, 'currency_code', 'code');
 -     }
 - 
 -     public function salesTax(): BelongsTo
 -     {
 -         return $this->belongsTo(Tax::class,'sales_tax_id', 'id')
 -             ->where('type', 'sales');
 -     }
 - 
 -     public function purchaseTax(): BelongsTo
 -     {
 -         return $this->belongsTo(Tax::class,'purchase_tax_id', 'id')
 -             ->where('type', 'purchase');
 -     }
 - 
 -     public function salesDiscount(): BelongsTo
 -     {
 -         return $this->belongsTo(Discount::class,'sales_discount_id', 'id')
 -             ->where('type', 'sales');
 -     }
 - 
 -     public function purchaseDiscount(): BelongsTo
 -     {
 -         return $this->belongsTo(Discount::class,'purchase_discount_id', 'id')
 -             ->where('type', 'purchase');
 -     }
 - 
 -     public function incomeCategory(): BelongsTo
 -     {
 -         return $this->belongsTo(Category::class,'income_category_id', 'id')
 -             ->where('type', 'income');
 -     }
 - 
 -     public function expenseCategory(): BelongsTo
 -     {
 -         return $this->belongsTo(Category::class,'expense_category_id', 'id')
 -             ->where('type', 'expense');
 -     }
 - 
 -     public function createdBy(): BelongsTo
 -     {
 -         return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
 -     }
 - 
 -     public function updatedBy(): BelongsTo
 -     {
 -         return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by');
 -     }
 - 
 -     public static function getAccounts(): array
 -     {
 -         return Account::pluck('name', 'id')->toArray();
 -     }
 - 
 -     public static function getCurrencies(): array
 -     {
 -         return Currency::pluck('name', 'code')->toArray();
 -     }
 - 
 -     public static function getSalesTaxes(): array
 -     {
 -         return Tax::where('type', 'sales')
 -             ->pluck('name', 'id')
 -             ->toArray();
 -     }
 - 
 -     public static function getPurchaseTaxes(): array
 -     {
 -         return Tax::where('type', 'purchase')
 -             ->pluck('name', 'id')
 -             ->toArray();
 -     }
 - 
 -     public static function getSalesDiscounts(): array
 -     {
 -         return Discount::where('type', 'sales')
 -             ->pluck('name', 'id')
 -             ->toArray();
 -     }
 - 
 -     public static function getPurchaseDiscounts(): array
 -     {
 -         return Discount::where('type', 'purchase')
 -             ->pluck('name', 'id')
 -             ->toArray();
 -     }
 - 
 -     public static function getIncomeCategories(): array
 -     {
 -         return Category::where('type', 'income')
 -             ->pluck('name', 'id')
 -             ->toArray();
 -     }
 - 
 -     public static function getExpenseCategories(): array
 -     {
 -         return Category::where('type', 'expense')
 -             ->pluck('name', 'id')
 -             ->toArray();
 -     }
 - 
 -     public static function getDefaultAccount()
 -     {
 -         $defaultAccount = Account::where('enabled', true)->first();
 - 
 -         return $defaultAccount->id ?? null;
 -     }
 - 
 -     public static function getDefaultCurrency()
 -     {
 -         $defaultCurrency = Currency::where('enabled', true)->first();
 - 
 -         return $defaultCurrency->code ?? null;
 -     }
 - 
 -     public static function getDefaultSalesTax()
 -     {
 -         $defaultSalesTax = Tax::where('enabled', true)
 -             ->where('type', 'sales')
 -             ->first();
 - 
 -         return $defaultSalesTax->id ?? null;
 -     }
 - 
 -     public static function getDefaultPurchaseTax()
 -     {
 -         $defaultPurchaseTax = Tax::where('enabled', true)
 -             ->where('type', 'purchase')
 -             ->first();
 - 
 -         return $defaultPurchaseTax->id ?? null;
 -     }
 - 
 -     public static function getDefaultSalesDiscount()
 -     {
 -         $defaultSalesDiscount = Discount::where('enabled', true)
 -             ->where('type', 'sales')
 -             ->first();
 - 
 -         return $defaultSalesDiscount->id ?? null;
 -     }
 - 
 -     public static function getDefaultPurchaseDiscount()
 -     {
 -         $defaultPurchaseDiscount = Discount::where('enabled', true)
 -             ->where('type', 'purchase')
 -             ->first();
 - 
 -         return $defaultPurchaseDiscount->id ?? null;
 -     }
 - 
 -     public static function getDefaultIncomeCategory()
 -     {
 -         $defaultIncomeCategory = Category::where('enabled', true)
 -             ->where('type', 'income')
 -             ->first();
 - 
 -         return $defaultIncomeCategory->id ?? null;
 -     }
 - 
 -     public static function getDefaultExpenseCategory()
 -     {
 -         $defaultExpenseCategory = Category::where('enabled', true)
 -             ->where('type', 'expense')
 -             ->first();
 - 
 -         return $defaultExpenseCategory->id ?? null;
 -     }
 - }
 
 
  |