Initial commit
This commit is contained in:
84
app/Models/ChartOfAccount.php
Normal file
84
app/Models/ChartOfAccount.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?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 ChartOfAccount extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'account_code',
|
||||
'account_name_zh',
|
||||
'account_name_en',
|
||||
'account_type',
|
||||
'category',
|
||||
'parent_account_id',
|
||||
'is_active',
|
||||
'display_order',
|
||||
'description',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'display_order' => 'integer',
|
||||
];
|
||||
|
||||
// Relationships
|
||||
|
||||
public function parentAccount(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ChartOfAccount::class, 'parent_account_id');
|
||||
}
|
||||
|
||||
public function childAccounts(): HasMany
|
||||
{
|
||||
return $this->hasMany(ChartOfAccount::class, 'parent_account_id')->orderBy('display_order');
|
||||
}
|
||||
|
||||
public function budgetItems(): HasMany
|
||||
{
|
||||
return $this->hasMany(BudgetItem::class);
|
||||
}
|
||||
|
||||
public function transactions(): HasMany
|
||||
{
|
||||
return $this->hasMany(Transaction::class);
|
||||
}
|
||||
|
||||
// Helper methods
|
||||
|
||||
public function getFullNameAttribute(): string
|
||||
{
|
||||
return "{$this->account_code} - {$this->account_name_zh}";
|
||||
}
|
||||
|
||||
public function isIncome(): bool
|
||||
{
|
||||
return $this->account_type === 'income';
|
||||
}
|
||||
|
||||
public function isExpense(): bool
|
||||
{
|
||||
return $this->account_type === 'expense';
|
||||
}
|
||||
|
||||
public function isAsset(): bool
|
||||
{
|
||||
return $this->account_type === 'asset';
|
||||
}
|
||||
|
||||
public function isLiability(): bool
|
||||
{
|
||||
return $this->account_type === 'liability';
|
||||
}
|
||||
|
||||
public function isNetAsset(): bool
|
||||
{
|
||||
return $this->account_type === 'net_asset';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user