- Add trial balance and general ledger pages to client resource with interactive tables - Implement sales and expenses relation managers for client-specific transactions - Enhance transaction handling with proper tax and withholding calculations - Add date casting to Transaction model and define client relationships - Configure super admin role bypass in AppServiceProvider - Update Filament components and fix JavaScript formatting issues
70 lines
1.6 KiB
PHP
70 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Observers\AccountObserver;
|
|
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
#[ObservedBy([AccountObserver::class])]
|
|
class Account extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $guarded = [];
|
|
|
|
public function getTypeAttribute(): string
|
|
{
|
|
return $this->accountType->type;
|
|
}
|
|
|
|
public function accountType(): BelongsTo
|
|
{
|
|
return $this->belongsTo(AccountType::class);
|
|
}
|
|
|
|
public function client(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Client::class);
|
|
}
|
|
|
|
public function getStartingBalanceAttribute()
|
|
{
|
|
if ($this->balances()->exists()) {
|
|
return $this->balances()
|
|
->where('is_starting', true)
|
|
->orderBy('id', 'desc')->first()->balance;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function balances(): HasMany
|
|
{
|
|
return $this->hasMany(Balance::class);
|
|
}
|
|
|
|
public function latestBalance(): \Illuminate\Database\Eloquent\Relations\HasOne
|
|
{
|
|
return $this->hasOne(Balance::class)->latestOfMany();
|
|
}
|
|
|
|
public function ledgers(): HasMany
|
|
{
|
|
return $this->hasMany(Ledger::class);
|
|
}
|
|
|
|
public function getCurrentBalanceAttribute()
|
|
{
|
|
if ($this->balances()->exists()) {
|
|
return $this->balances()
|
|
->orderBy('id', 'desc')->first()->balance;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|