Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

DocumentLineItem.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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\Enums\Accounting\AdjustmentType;
  8. use App\Models\Common\Offering;
  9. use App\Observers\DocumentLineItemObserver;
  10. use Illuminate\Database\Eloquent\Attributes\ObservedBy;
  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. #[ObservedBy(DocumentLineItemObserver::class)]
  16. class DocumentLineItem extends Model
  17. {
  18. use Blamable;
  19. use CompanyOwned;
  20. use HasFactory;
  21. protected $table = 'document_line_items';
  22. protected $fillable = [
  23. 'company_id',
  24. 'document_id',
  25. 'offering_id',
  26. 'description',
  27. 'quantity',
  28. 'unit_price',
  29. 'tax_total',
  30. 'discount_total',
  31. 'created_by',
  32. 'updated_by',
  33. ];
  34. protected $casts = [
  35. 'unit_price' => MoneyCast::class,
  36. 'subtotal' => MoneyCast::class,
  37. 'tax_total' => MoneyCast::class,
  38. 'discount_total' => MoneyCast::class,
  39. 'total' => MoneyCast::class,
  40. ];
  41. public function document(): BelongsTo
  42. {
  43. return $this->belongsTo(Document::class);
  44. }
  45. public function offering(): BelongsTo
  46. {
  47. return $this->belongsTo(Offering::class);
  48. }
  49. public function adjustments(): MorphToMany
  50. {
  51. return $this->morphToMany(Adjustment::class, 'adjustmentable', 'adjustmentables');
  52. }
  53. public function salesTaxes(): MorphToMany
  54. {
  55. return $this->adjustments()->where('category', AdjustmentCategory::Tax)->where('type', AdjustmentType::Sales);
  56. }
  57. public function salesDiscounts(): MorphToMany
  58. {
  59. return $this->adjustments()->where('category', AdjustmentCategory::Discount)->where('type', AdjustmentType::Sales);
  60. }
  61. public function taxes(): MorphToMany
  62. {
  63. return $this->adjustments()->where('category', AdjustmentCategory::Tax);
  64. }
  65. public function discounts(): MorphToMany
  66. {
  67. return $this->adjustments()->where('category', AdjustmentCategory::Discount);
  68. }
  69. }