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.

Offering.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Models;
  3. use App\Concerns\CompanyOwned;
  4. use App\Models\Accounting\Account;
  5. use App\Models\Setting\Discount;
  6. use App\Models\Setting\Tax;
  7. use Illuminate\Database\Eloquent\Factories\HasFactory;
  8. use Illuminate\Database\Eloquent\Model;
  9. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  10. use Illuminate\Database\Eloquent\Relations\MorphToMany;
  11. class Offering extends Model
  12. {
  13. use CompanyOwned;
  14. use HasFactory;
  15. protected $fillable = [
  16. 'company_id',
  17. 'name',
  18. 'description',
  19. 'type',
  20. 'price',
  21. 'income_account_id',
  22. 'expense_account_id',
  23. ];
  24. public function incomeAccount(): BelongsTo
  25. {
  26. return $this->belongsTo(Account::class, 'income_account_id');
  27. }
  28. public function expenseAccount(): BelongsTo
  29. {
  30. return $this->belongsTo(Account::class, 'expense_account_id');
  31. }
  32. public function taxes(): MorphToMany
  33. {
  34. return $this->morphToMany(Tax::class, 'adjustmentable', 'adjustmentables')
  35. ->wherePivot('adjustment_type', Tax::class);
  36. }
  37. public function discounts(): MorphToMany
  38. {
  39. return $this->morphToMany(Discount::class, 'adjustmentable', 'adjustmentables')
  40. ->wherePivot('adjustment_type', Discount::class);
  41. }
  42. }