Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Offering.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Models\Common;
  3. use App\Casts\MoneyCast;
  4. use App\Concerns\Blamable;
  5. use App\Concerns\CompanyOwned;
  6. use App\Enums\Accounting\AdjustmentCategory;
  7. use App\Enums\Accounting\AdjustmentType;
  8. use App\Enums\Common\OfferingType;
  9. use App\Models\Accounting\Account;
  10. use App\Models\Accounting\Adjustment;
  11. use Illuminate\Database\Eloquent\Factories\HasFactory;
  12. use Illuminate\Database\Eloquent\Model;
  13. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  14. use Illuminate\Database\Eloquent\Relations\MorphToMany;
  15. class Offering extends Model
  16. {
  17. use Blamable;
  18. use CompanyOwned;
  19. use HasFactory;
  20. protected $fillable = [
  21. 'company_id',
  22. 'name',
  23. 'description',
  24. 'type',
  25. 'price',
  26. 'income_account_id',
  27. 'expense_account_id',
  28. 'created_by',
  29. 'updated_by',
  30. ];
  31. protected $casts = [
  32. 'type' => OfferingType::class,
  33. 'price' => MoneyCast::class,
  34. ];
  35. public function incomeAccount(): BelongsTo
  36. {
  37. return $this->belongsTo(Account::class, 'income_account_id');
  38. }
  39. public function expenseAccount(): BelongsTo
  40. {
  41. return $this->belongsTo(Account::class, 'expense_account_id');
  42. }
  43. public function adjustments(): MorphToMany
  44. {
  45. return $this->morphToMany(Adjustment::class, 'adjustmentable', 'adjustmentables');
  46. }
  47. public function salesTaxes(): MorphToMany
  48. {
  49. return $this->adjustments()->where('category', AdjustmentCategory::Tax)->where('type', AdjustmentType::Sales);
  50. }
  51. public function purchaseTaxes(): MorphToMany
  52. {
  53. return $this->adjustments()->where('category', AdjustmentCategory::Tax)->where('type', AdjustmentType::Purchase);
  54. }
  55. public function salesDiscounts(): MorphToMany
  56. {
  57. return $this->adjustments()->where('category', AdjustmentCategory::Discount)->where('type', AdjustmentType::Sales);
  58. }
  59. public function purchaseDiscounts(): MorphToMany
  60. {
  61. return $this->adjustments()->where('category', AdjustmentCategory::Discount)->where('type', AdjustmentType::Purchase);
  62. }
  63. }