1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
-
- namespace App\Models\Accounting;
-
- use App\Concerns\Blamable;
- use App\Concerns\CompanyOwned;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasMany;
-
- class BudgetItem extends Model
- {
- use Blamable;
- use CompanyOwned;
- use HasFactory;
-
- protected $fillable = [
- 'company_id',
- 'budget_id',
- 'account_id',
- 'created_by',
- 'updated_by',
- ];
-
- protected $appends = ['allocations_by_period'];
-
- public function getAllocationsByPeriodAttribute(): array
- {
- return $this->allocations->pluck('amount', 'period')->toArray();
- }
-
- public function budget(): BelongsTo
- {
- return $this->belongsTo(Budget::class);
- }
-
- public function account(): BelongsTo
- {
- return $this->belongsTo(Account::class);
- }
-
- public function allocations(): HasMany
- {
- return $this->hasMany(BudgetAllocation::class);
- }
- }
|