Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DocumentLineItem.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Models\Accounting;
  3. use App\Casts\MoneyCast;
  4. use App\Concerns\Blamable;
  5. use App\Concerns\CompanyOwned;
  6. use App\Enums\Accounting\AdjustmentCategory;
  7. use App\Models\Common\Offering;
  8. use Illuminate\Database\Eloquent\Factories\HasFactory;
  9. use Illuminate\Database\Eloquent\Model;
  10. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  11. use Illuminate\Database\Eloquent\Relations\MorphToMany;
  12. class DocumentLineItem extends Model
  13. {
  14. use Blamable;
  15. use CompanyOwned;
  16. use HasFactory;
  17. protected $table = 'document_line_items';
  18. protected $fillable = [
  19. 'company_id',
  20. 'document_id',
  21. 'offering_id',
  22. 'description',
  23. 'quantity',
  24. 'unit_price',
  25. 'total',
  26. 'tax_total',
  27. 'discount_total',
  28. 'created_by',
  29. 'updated_by',
  30. ];
  31. protected $casts = [
  32. 'unit_price' => MoneyCast::class,
  33. 'total' => MoneyCast::class,
  34. 'tax_total' => MoneyCast::class,
  35. 'discount_total' => MoneyCast::class,
  36. ];
  37. public function document(): BelongsTo
  38. {
  39. return $this->belongsTo(Document::class);
  40. }
  41. public function offering(): BelongsTo
  42. {
  43. return $this->belongsTo(Offering::class);
  44. }
  45. public function adjustments(): MorphToMany
  46. {
  47. return $this->morphToMany(Adjustment::class, 'adjustmentable', 'adjustmentables');
  48. }
  49. public function taxes(): MorphToMany
  50. {
  51. return $this->adjustments()->where('category', AdjustmentCategory::Tax);
  52. }
  53. public function discounts(): MorphToMany
  54. {
  55. return $this->adjustments()->where('category', AdjustmentCategory::Discount);
  56. }
  57. }