- 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
77 lines
1.7 KiB
PHP
77 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Observers\ClientObserver;
|
|
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\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
|
|
|
#[ObservedBy([ClientObserver::class])]
|
|
class Client extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $guarded = [];
|
|
|
|
protected $appends = ['vatable'];
|
|
|
|
public function getFullNameAttribute()
|
|
{
|
|
return $this->lname.', '.$this->fname.' '.$this->mname;
|
|
}
|
|
|
|
public function getVatableAttribute(): bool
|
|
{
|
|
return $this->type->type == 'Vatable';
|
|
}
|
|
|
|
/**
|
|
* Get all the branches for the Client
|
|
*/
|
|
public function branches(): HasMany
|
|
{
|
|
return $this->hasMany(Branch::class);
|
|
}
|
|
|
|
/**
|
|
* Get the type associated with the Client
|
|
*/
|
|
public function type(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ClientType::class);
|
|
}
|
|
|
|
public function accounts(): HasMany
|
|
{
|
|
return $this->hasMany(Account::class);
|
|
}
|
|
|
|
/**
|
|
* The users that belong to the Client
|
|
*/
|
|
public function users(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(User::class);
|
|
}
|
|
|
|
public function transmittals(): HasMany
|
|
{
|
|
return $this->hasMany(Transmittal::class);
|
|
}
|
|
|
|
public function sales(): HasManyThrough
|
|
{
|
|
return $this->hasManyThrough(Sale::class, Branch::class);
|
|
}
|
|
|
|
public function expenses(): HasManyThrough
|
|
{
|
|
return $this->hasManyThrough(Expense::class, Branch::class);
|
|
}
|
|
}
|