Changes to UI and other stuff

This commit is contained in:
Simon Pocrnjič
2025-11-20 18:11:43 +01:00
parent b7fa2d261b
commit 3b284fa4bd
87 changed files with 7872 additions and 2330 deletions
+65
View File
@@ -2,6 +2,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Scope;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -57,6 +59,69 @@ protected static function booted()
});
}
/**
* Scope activities to those linked to contracts within a specific segment.
*/
#[Scope]
public function scopeForSegment(Builder $query, int $segmentId, array $contractIds): Builder
{
return $query->where(function ($q) use ($contractIds) {
$q->whereNull('contract_id');
if (! empty($contractIds)) {
$q->orWhereIn('contract_id', $contractIds);
}
});
}
/**
* Scope activities with decoded base64 filters.
*/
#[Scope]
public function scopeWithFilters(Builder $query, ?string $encodedFilters, \App\Models\ClientCase $clientCase): Builder
{
if (empty($encodedFilters)) {
return $query;
}
try {
$decompressed = base64_decode($encodedFilters);
$filters = json_decode($decompressed, true);
if (! is_array($filters)) {
return $query;
}
if (! empty($filters['action_id'])) {
$query->where('action_id', $filters['action_id']);
}
if (! empty($filters['contract_uuid'])) {
$contract = $clientCase->contracts()->where('uuid', $filters['contract_uuid'])->first(['id']);
if ($contract) {
$query->where('contract_id', $contract->id);
}
}
if (! empty($filters['user_id'])) {
$query->where('user_id', $filters['user_id']);
}
if (! empty($filters['date_from'])) {
$query->whereDate('created_at', '>=', $filters['date_from']);
}
if (! empty($filters['date_to'])) {
$query->whereDate('created_at', '<=', $filters['date_to']);
}
} catch (\Throwable $e) {
\Log::error('Invalid activity filter format', [
'error' => $e->getMessage(),
]);
}
return $query;
}
public function action(): BelongsTo
{
return $this->belongsTo(\App\Models\Action::class);