feat: AfterSales CRM - SOP compliant real-estate customer care system

- Departments + cross-department transfer workflow
- Role-based closing (staff→resolved, manager→closed) with proof_of_resolution
- Private file storage with collection system + temporary signed URLs
- Dashboard: resolved tickets table, stats, handler performance bar chart
- Spatie RBAC (admin/manager/staff)
- Notifications: TicketTransferred, TicketClosed (database + mail)
- Pest tests: 8 tests, 21 assertions
- Docker production-ready (Dockerfile + compose + entrypoint)
This commit is contained in:
2026-04-27 05:29:48 +00:00
parent 8ad7826f56
commit 887765bbd7
134 changed files with 17416 additions and 45 deletions

24
app/Models/Customer.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
#[Fillable(['name', 'email', 'phone', 'address', 'status'])]
class Customer extends Model
{
public function products(): BelongsToMany
{
return $this->belongsToMany(Product::class, 'customer_product')
->withPivot('purchase_date')
->withTimestamps();
}
public function feedbacks(): HasMany
{
return $this->hasMany(Feedback::class);
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class CustomerProduct extends Model
{
protected $table = 'customer_product';
protected $fillable = [
'customer_id',
'product_id',
'purchase_date',
];
protected function casts(): array
{
return [
'purchase_date' => 'date',
];
}
public function customer(): BelongsTo
{
return $this->belongsTo(Customer::class);
}
public function product(): BelongsTo
{
return $this->belongsTo(Product::class);
}
public function feedbacks(): HasMany
{
return $this->hasMany(Feedback::class);
}
}

32
app/Models/Department.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
#[Fillable(['name', 'manager_id'])]
class Department extends Model
{
public function manager(): BelongsTo
{
return $this->belongsTo(User::class, 'manager_id');
}
public function feedbacks(): HasMany
{
return $this->hasMany(Feedback::class, 'current_department_id');
}
public function transferLogsFrom(): HasMany
{
return $this->hasMany(TicketTransferLog::class, 'from_department_id');
}
public function transferLogsTo(): HasMany
{
return $this->hasMany(TicketTransferLog::class, 'to_department_id');
}
}

58
app/Models/Feedback.php Normal file
View File

@@ -0,0 +1,58 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
#[Fillable(['customer_id', 'customer_product_id', 'feedback_channel_id', 'assigned_to', 'title', 'content', 'status', 'current_department_id', 'is_escalated'])]
class Feedback extends Model
{
public function customer(): BelongsTo
{
return $this->belongsTo(Customer::class);
}
public function customerProduct(): BelongsTo
{
return $this->belongsTo(CustomerProduct::class, 'customer_product_id');
}
public function feedbackChannel(): BelongsTo
{
return $this->belongsTo(FeedbackChannel::class);
}
public function assignedTo(): BelongsTo
{
return $this->belongsTo(User::class, 'assigned_to');
}
public function currentDepartment(): BelongsTo
{
return $this->belongsTo(Department::class, 'current_department_id');
}
public function transferLogs(): HasMany
{
return $this->hasMany(TicketTransferLog::class);
}
public function interactions(): HasMany
{
return $this->hasMany(FeedbackInteraction::class)->latest();
}
public function attachments(): HasMany
{
return $this->hasMany(FeedbackAttachment::class);
}
public function tags(): BelongsToMany
{
return $this->belongsToMany(FeedbackTag::class, 'feedback_feedback_tag');
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
#[Fillable(['uuid', 'feedback_id', 'feedback_interaction_id', 'user_id', 'name', 'path', 'disk', 'collection', 'mime_type', 'size'])]
class FeedbackAttachment extends Model
{
public function feedback(): BelongsTo
{
return $this->belongsTo(Feedback::class);
}
public function interaction(): BelongsTo
{
return $this->belongsTo(FeedbackInteraction::class, 'feedback_interaction_id');
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function scopeByCollection($query, string $collection)
{
return $query->where('collection', $collection);
}
public function scopeByDisk($query, string $disk)
{
return $query->where('disk', $disk);
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
#[Fillable(['name', 'slug', 'icon', 'is_active'])]
class FeedbackChannel extends Model
{
protected function casts(): array
{
return [
'is_active' => 'boolean',
];
}
public function feedbacks(): HasMany
{
return $this->hasMany(Feedback::class);
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
#[Fillable(['feedback_id', 'user_id', 'type', 'content', 'changes'])]
class FeedbackInteraction extends Model
{
protected function casts(): array
{
return [
'changes' => 'array',
];
}
public function feedback(): BelongsTo
{
return $this->belongsTo(Feedback::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function attachments(): HasMany
{
return $this->hasMany(FeedbackAttachment::class, 'feedback_interaction_id');
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
#[Fillable(['name', 'slug', 'color'])]
class FeedbackTag extends Model
{
public function feedbacks(): BelongsToMany
{
return $this->belongsToMany(Feedback::class, 'feedback_feedback_tag');
}
}

18
app/Models/Product.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
#[Fillable(['name', 'description', 'status'])]
class Product extends Model
{
public function customers(): BelongsToMany
{
return $this->belongsToMany(Customer::class, 'customer_product')
->withPivot('purchase_date')
->withTimestamps();
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
#[Fillable(['feedback_id', 'from_department_id', 'to_department_id', 'sender_id', 'reason'])]
class TicketTransferLog extends Model
{
public function feedback(): BelongsTo
{
return $this->belongsTo(Feedback::class);
}
public function fromDepartment(): BelongsTo
{
return $this->belongsTo(Department::class, 'from_department_id');
}
public function toDepartment(): BelongsTo
{
return $this->belongsTo(Department::class, 'to_department_id');
}
public function sender(): BelongsTo
{
return $this->belongsTo(User::class, 'sender_id');
}
}

View File

@@ -2,26 +2,25 @@
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;
use Illuminate\Contracts\Auth\Access\Authorizable;
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
#[Fillable(['name', 'email', 'password'])]
#[Fillable(['name', 'email', 'password', 'role'])]
#[Hidden(['password', 'remember_token'])]
class User extends Authenticatable
class User extends Authenticatable implements FilamentUser
{
/** @use HasFactory<UserFactory> */
use HasFactory, Notifiable;
use HasFactory, Notifiable, HasRoles;
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
@@ -29,4 +28,24 @@ class User extends Authenticatable
'password' => 'hashed',
];
}
public function canAccessPanel(Panel $panel): bool
{
return true;
}
public function assignedFeedbacks(): HasMany
{
return $this->hasMany(Feedback::class, 'assigned_to');
}
public function isAdmin(): bool
{
return $this->hasRole('admin');
}
public function isManager(): bool
{
return $this->hasRole('manager');
}
}