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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Models\Setting;
  3. use App\Concerns\Blamable;
  4. use App\Concerns\CompanyOwned;
  5. use App\Enums\Setting\DiscountType;
  6. use App\Enums\Setting\TaxType;
  7. use App\Models\Banking\BankAccount;
  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. class CompanyDefault extends Model
  14. {
  15. use Blamable;
  16. use CompanyOwned;
  17. use HasFactory;
  18. protected $table = 'company_defaults';
  19. protected $fillable = [
  20. 'company_id',
  21. 'bank_account_id',
  22. 'currency_code',
  23. 'sales_tax_id',
  24. 'purchase_tax_id',
  25. 'sales_discount_id',
  26. 'purchase_discount_id',
  27. 'created_by',
  28. 'updated_by',
  29. ];
  30. public function bankAccount(): BelongsTo
  31. {
  32. return $this->belongsTo(BankAccount::class, 'bank_account_id');
  33. }
  34. public function currency(): BelongsTo
  35. {
  36. return $this->belongsTo(Currency::class, 'currency_code', 'code');
  37. }
  38. public function salesTax(): BelongsTo
  39. {
  40. return $this->belongsTo(Tax::class, 'sales_tax_id', 'id')
  41. ->where('type', TaxType::Sales);
  42. }
  43. public function purchaseTax(): BelongsTo
  44. {
  45. return $this->belongsTo(Tax::class, 'purchase_tax_id', 'id')
  46. ->where('type', TaxType::Purchase);
  47. }
  48. public function salesDiscount(): BelongsTo
  49. {
  50. return $this->belongsTo(Discount::class, 'sales_discount_id', 'id')
  51. ->where('type', DiscountType::Sales);
  52. }
  53. public function purchaseDiscount(): BelongsTo
  54. {
  55. return $this->belongsTo(Discount::class, 'purchase_discount_id', 'id')
  56. ->where('type', DiscountType::Purchase);
  57. }
  58. protected static function newFactory(): Factory
  59. {
  60. return CompanyDefaultFactory::new();
  61. }
  62. }