'integer', 'period_start' => 'date', 'period_end' => 'date', 'approved_at' => 'datetime', ]; // Relationships public function createdBy(): BelongsTo { return $this->belongsTo(User::class, 'created_by_user_id'); } public function approvedBy(): BelongsTo { return $this->belongsTo(User::class, 'approved_by_user_id'); } public function budgetItems(): HasMany { return $this->hasMany(BudgetItem::class); } public function financialReports(): HasMany { return $this->hasMany(FinancialReport::class); } // Helper methods public function isDraft(): bool { return $this->status === self::STATUS_DRAFT; } public function isApproved(): bool { return $this->status === self::STATUS_APPROVED; } public function isActive(): bool { return $this->status === self::STATUS_ACTIVE; } public function isClosed(): bool { return $this->status === self::STATUS_CLOSED; } public function canBeEdited(): bool { return in_array($this->status, [self::STATUS_DRAFT, self::STATUS_SUBMITTED]); } public function canBeApproved(): bool { return $this->status === self::STATUS_SUBMITTED; } public function getTotalBudgetedIncomeAttribute(): float { return $this->budgetItems() ->whereHas('chartOfAccount', fn($q) => $q->where('account_type', 'income')) ->sum('budgeted_amount'); } public function getTotalBudgetedExpenseAttribute(): float { return $this->budgetItems() ->whereHas('chartOfAccount', fn($q) => $q->where('account_type', 'expense')) ->sum('budgeted_amount'); } public function getTotalActualIncomeAttribute(): float { return $this->budgetItems() ->whereHas('chartOfAccount', fn($q) => $q->where('account_type', 'income')) ->sum('actual_amount'); } public function getTotalActualExpenseAttribute(): float { return $this->budgetItems() ->whereHas('chartOfAccount', fn($q) => $q->where('account_type', 'expense')) ->sum('actual_amount'); } }