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:
2026-03-11 23:33:10 +00:00
commit 35545c2a8f
1517 changed files with 246774 additions and 0 deletions

120
app/Models/Client.php Normal file
View 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();
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
class ClientContact extends Model
{
/** @use HasFactory<\Database\Factories\ClientContactFactory> */
use HasFactory, LogsActivity;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'client_id',
'full_name',
'job_title',
'email',
'phone',
'is_principal',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'is_principal' => 'boolean',
];
}
/**
* Get the client that owns the contact.
*
* @return BelongsTo<Client, $this>
*/
public function client(): BelongsTo
{
return $this->belongsTo(Client::class);
}
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logFillable()
->logOnlyDirty()
->dontSubmitEmptyLogs();
}
}

149
app/Models/Folder.php Normal file
View File

@@ -0,0 +1,149 @@
<?php
namespace App\Models;
use App\Enums\FolderPriority;
use App\Enums\FolderStatus;
use App\Enums\FolderType;
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\SoftDeletes;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
class Folder extends Model implements HasMedia
{
/** @use HasFactory<\Database\Factories\FolderFactory> */
use HasFactory, InteractsWithMedia, LogsActivity, SoftDeletes;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'workspace_id',
'client_id',
'created_by',
'title',
'type',
'period_year',
'period_month',
'period_quarter',
'due_date',
'status',
'priority',
'assigned_to',
'validated_at',
'closed_at',
'confirmation_requested_at',
'confirmation_media_id',
'confirmed_by_type',
'confirmed_by_id',
'confirmation_signature',
'refused_at',
'refusal_reason',
'notes_internal',
'notes_client',
'created_at',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'type' => FolderType::class,
'status' => FolderStatus::class,
'priority' => FolderPriority::class,
'validated_at' => 'datetime',
'closed_at' => 'datetime',
'confirmation_requested_at' => 'datetime',
'refused_at' => 'datetime',
'due_date' => 'date',
];
}
/**
* Register media collections.
*/
public function registerMediaCollections(): void
{
$this->addMediaCollection('documents')->useDisk('local');
}
/**
* Get the workspace that owns the folder.
*
* @return BelongsTo<Workspace, $this>
*/
public function workspace(): BelongsTo
{
return $this->belongsTo(Workspace::class);
}
/**
* Get the client that owns the folder.
*
* @return BelongsTo<Client, $this>
*/
public function client(): BelongsTo
{
return $this->belongsTo(Client::class);
}
/**
* Get the user who created the folder.
*
* @return BelongsTo<User, $this>
*/
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
/**
* Get the user assigned to the folder.
*
* @return BelongsTo<User, $this>
*/
public function assignee(): BelongsTo
{
return $this->belongsTo(User::class, 'assigned_to');
}
/**
* Get the messages for the folder.
*
* @return HasMany<Message>
*/
public function messages(): HasMany
{
return $this->hasMany(Message::class);
}
/**
* Get the invitations for the folder.
*
* @return HasMany<FolderInvitation>
*/
public function invitations(): HasMany
{
return $this->hasMany(FolderInvitation::class);
}
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logFillable()
->logOnlyDirty()
->dontSubmitEmptyLogs();
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str;
class FolderInvitation extends Model
{
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'folder_id',
'token',
'email',
'expires_at',
'used_at',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'expires_at' => 'datetime',
'used_at' => 'datetime',
];
}
/**
* Boot the model.
*/
protected static function boot(): void
{
parent::boot();
static::creating(function (FolderInvitation $invitation) {
if (empty($invitation->token)) {
$invitation->token = Str::uuid()->toString();
}
});
}
/**
* Get the folder that owns the invitation.
*
* @return BelongsTo<Folder, $this>
*/
public function folder(): BelongsTo
{
return $this->belongsTo(Folder::class);
}
/**
* Check if the invitation is valid (not expired, not used).
*/
public function isValid(): bool
{
if ($this->used_at !== null) {
return false;
}
return $this->expires_at->isFuture();
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class MediaDownload extends Model
{
public const CREATED_AT = 'created_at';
public const UPDATED_AT = null;
protected $fillable = [
'media_id',
'user_id',
'downloaded_at',
];
protected function casts(): array
{
return [
'downloaded_at' => 'datetime',
];
}
public function media(): BelongsTo
{
return $this->belongsTo(\Spatie\MediaLibrary\MediaCollections\Models\Media::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}

85
app/Models/Message.php Normal file
View File

@@ -0,0 +1,85 @@
<?php
namespace App\Models;
use App\Enums\ActorType;
use App\Enums\MessageType;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Message extends Model
{
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'folder_id',
'type',
'body',
'sent_by_type',
'sent_by_id',
'metadata',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'type' => MessageType::class,
'sent_by_type' => ActorType::class,
'metadata' => 'array',
];
}
/**
* Get the folder that owns the message.
*
* @return BelongsTo<Folder, $this>
*/
public function folder(): BelongsTo
{
return $this->belongsTo(Folder::class);
}
/**
* Get the user who sent the message (when sent_by_type is user).
*
* @return BelongsTo<User, $this>
*/
public function senderUser(): BelongsTo
{
return $this->belongsTo(User::class, 'sent_by_id');
}
/**
* Get the client who sent the message (when sent_by_type is client).
*
* @return BelongsTo<Client, $this>
*/
public function senderClient(): BelongsTo
{
return $this->belongsTo(Client::class, 'sent_by_id');
}
/**
* Get the sender display name.
*/
public function getSenderNameAttribute(): string
{
if ($this->sent_by_type?->is(ActorType::User)) {
return $this->senderUser?->name ?? '—';
}
if ($this->sent_by_type?->is(ActorType::Client)) {
return $this->senderClient?->company_name ?? 'Client';
}
return '—';
}
}

80
app/Models/User.php Normal file
View File

@@ -0,0 +1,80 @@
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Enums\UserGroup;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable, SoftDeletes, TwoFactorAuthenticatable, LogsActivity;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'name',
'email',
'password',
'group',
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
protected $hidden = [
'password',
'two_factor_secret',
'two_factor_recovery_codes',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'group' => UserGroup::class,
'two_factor_confirmed_at' => 'datetime',
];
}
/**
* The workspaces that the user belongs to.
*
* @return BelongsToMany<Workspace>
*/
public function workspaces(): BelongsToMany
{
return $this->belongsToMany(Workspace::class, 'workspace_user')
->using(\App\Models\WorkspaceUser::class)
->withPivot('role')
->withTimestamps();
}
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logFillable()
->logOnlyDirty()
->dontSubmitEmptyLogs();
}
}

89
app/Models/Workspace.php Normal file
View File

@@ -0,0 +1,89 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
class Workspace extends Model
{
/** @use HasFactory<\Database\Factories\WorkspaceFactory> */
use HasFactory, SoftDeletes, LogsActivity;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'name',
'slug',
];
/**
* Boot the model.
*/
protected static function boot(): void
{
parent::boot();
static::creating(function (Workspace $workspace) {
if (empty($workspace->slug)) {
$workspace->slug = Str::slug($workspace->name);
}
});
static::updating(function (Workspace $workspace) {
if (empty($workspace->slug)) {
$workspace->slug = Str::slug($workspace->name);
}
});
}
/**
* Get the clients for the workspace.
*
* @return HasMany<Client>
*/
public function clients(): HasMany
{
return $this->hasMany(Client::class);
}
/**
* Get the folders for the workspace.
*
* @return HasMany<Folder>
*/
public function folders(): HasMany
{
return $this->hasMany(Folder::class);
}
/**
* The users that belong to the workspace.
*
* @return BelongsToMany<User>
*/
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class, 'workspace_user')
->using(WorkspaceUser::class)
->withPivot('role')
->withTimestamps();
}
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logFillable()
->logOnlyDirty()
->dontSubmitEmptyLogs();
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Models;
use App\Enums\WorkspaceUserRole;
use Illuminate\Database\Eloquent\Relations\Pivot;
class WorkspaceUser extends Pivot
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'workspace_user';
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'role',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'role' => WorkspaceUserRole::class,
];
}
}