feat: L'Ami Fiduciaire V1.0.0 — full codebase with Story 0.1 complete
Initial commit of the L'Ami Fiduciaire SaaS platform built on Laravel 12, Vue 3, Inertia.js 2, and Tailwind CSS 4. Story 0.1 (rename folders to declarations in database) is implemented and code-reviewed: migration, rollback, and 6 Pest tests all passing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
120
app/Models/Client.php
Normal file
120
app/Models/Client.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ClientStatus;
|
||||
use App\Enums\LegalForm;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\Activitylog\LogOptions;
|
||||
use Spatie\Activitylog\Traits\LogsActivity;
|
||||
|
||||
class Client extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\ClientFactory> */
|
||||
use HasFactory, SoftDeletes, LogsActivity;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'workspace_id',
|
||||
'company_name',
|
||||
'legal_form',
|
||||
'ice',
|
||||
'fiscal_id',
|
||||
'rc',
|
||||
'cnss',
|
||||
'patente',
|
||||
'contact_last_name',
|
||||
'contact_first_name',
|
||||
'contact_job_title',
|
||||
'contact_email',
|
||||
'contact_phone',
|
||||
'internal_responsible_id',
|
||||
'status',
|
||||
'internal_notes',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'legal_form' => LegalForm::class,
|
||||
'status' => ClientStatus::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the workspace that owns the client.
|
||||
*
|
||||
* @return BelongsTo<Workspace, $this>
|
||||
*/
|
||||
public function workspace(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Workspace::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the internal responsible user.
|
||||
*
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function internalResponsible(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'internal_responsible_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contacts for the client.
|
||||
*
|
||||
* @return HasMany<ClientContact>
|
||||
*/
|
||||
public function contacts(): HasMany
|
||||
{
|
||||
return $this->hasMany(ClientContact::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the primary contact for the client.
|
||||
*
|
||||
* @return HasOne<ClientContact>
|
||||
*/
|
||||
public function primaryContact(): HasOne
|
||||
{
|
||||
return $this->hasOne(ClientContact::class)->where('is_principal', true)->latest();
|
||||
}
|
||||
|
||||
public function getPrimaryContactEmailAttribute(): ?string
|
||||
{
|
||||
return $this->primaryContact?->email ?? $this->contact_email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the folders for the client.
|
||||
*
|
||||
* @return HasMany<Folder>
|
||||
*/
|
||||
public function folders(): HasMany
|
||||
{
|
||||
return $this->hasMany(Folder::class);
|
||||
}
|
||||
|
||||
public function getActivitylogOptions(): LogOptions
|
||||
{
|
||||
return LogOptions::defaults()
|
||||
->logFillable()
|
||||
->logOnlyDirty()
|
||||
->dontSubmitEmptyLogs();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user