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.

BudgetItem.php 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Models\Accounting;
  3. use App\Concerns\Blamable;
  4. use App\Concerns\CompanyOwned;
  5. use Illuminate\Database\Eloquent\Factories\HasFactory;
  6. use Illuminate\Database\Eloquent\Model;
  7. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  8. use Illuminate\Database\Eloquent\Relations\HasMany;
  9. class BudgetItem extends Model
  10. {
  11. use Blamable;
  12. use CompanyOwned;
  13. use HasFactory;
  14. protected $fillable = [
  15. 'company_id',
  16. 'budget_id',
  17. 'account_id',
  18. 'created_by',
  19. 'updated_by',
  20. ];
  21. protected $appends = ['allocations_by_period'];
  22. public function getAllocationsByPeriodAttribute(): array
  23. {
  24. return $this->allocations->pluck('amount', 'period')->toArray();
  25. }
  26. public function budget(): BelongsTo
  27. {
  28. return $this->belongsTo(Budget::class);
  29. }
  30. public function account(): BelongsTo
  31. {
  32. return $this->belongsTo(Account::class);
  33. }
  34. public function allocations(): HasMany
  35. {
  36. return $this->hasMany(BudgetAllocation::class);
  37. }
  38. }