Initial commit

This commit is contained in:
2025-11-20 23:21:05 +08:00
commit 13bc6db529
378 changed files with 54527 additions and 0 deletions

76
app/Models/BudgetItem.php Normal file
View File

@@ -0,0 +1,76 @@
<?php
namespace App\Models;
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 HasFactory;
protected $fillable = [
'budget_id',
'chart_of_account_id',
'budgeted_amount',
'actual_amount',
'notes',
];
protected $casts = [
'budgeted_amount' => 'decimal:2',
'actual_amount' => 'decimal:2',
];
// Relationships
public function budget(): BelongsTo
{
return $this->belongsTo(Budget::class);
}
public function chartOfAccount(): BelongsTo
{
return $this->belongsTo(ChartOfAccount::class);
}
public function transactions(): HasMany
{
return $this->hasMany(Transaction::class);
}
// Helper methods
public function getVarianceAttribute(): float
{
return $this->actual_amount - $this->budgeted_amount;
}
public function getVariancePercentageAttribute(): float
{
if ($this->budgeted_amount == 0) {
return 0;
}
return ($this->variance / $this->budgeted_amount) * 100;
}
public function getRemainingBudgetAttribute(): float
{
return $this->budgeted_amount - $this->actual_amount;
}
public function isOverBudget(): bool
{
return $this->actual_amount > $this->budgeted_amount;
}
public function getUtilizationPercentageAttribute(): float
{
if ($this->budgeted_amount == 0) {
return 0;
}
return ($this->actual_amount / $this->budgeted_amount) * 100;
}
}