From 6108028942aa62c3f0089513564262ad83003f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Pocrnji=C4=8D?= Date: Thu, 9 Oct 2025 00:41:39 +0200 Subject: [PATCH] Arhived fixed --- app/Http/Controllers/ClientCaseContoller.php | 4 ++-- app/Services/Archiving/ArchiveExecutor.php | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ClientCaseContoller.php b/app/Http/Controllers/ClientCaseContoller.php index 233c853..d3cd2c7 100644 --- a/app/Http/Controllers/ClientCaseContoller.php +++ b/app/Http/Controllers/ClientCaseContoller.php @@ -1174,7 +1174,7 @@ public function show(ClientCase $clientCase) } return Inertia::render('Cases/Show', [ - 'client' => $case->client()->with('person', fn ($q) => $q->with(['addresses', 'phones', 'emails','bankAccounts']))->firstOrFail(), + 'client' => $case->client()->with('person', fn ($q) => $q->with(['addresses', 'phones', 'emails', 'bankAccounts']))->firstOrFail(), 'client_case' => $case, 'contracts' => $contracts, 'archive_meta' => [ @@ -1343,7 +1343,7 @@ public function archiveContract(ClientCase $clientCase, string $uuid, Request $r $overall = []; $hadAnyEffect = false; foreach ($settings as $setting) { - dd($setting); + $res = $executor->executeSetting($setting, $context, optional($request->user())->id); foreach ($res as $table => $count) { $overall[$table] = ($overall[$table] ?? 0) + $count; diff --git a/app/Services/Archiving/ArchiveExecutor.php b/app/Services/Archiving/ArchiveExecutor.php index 0f55f01..63de252 100644 --- a/app/Services/Archiving/ArchiveExecutor.php +++ b/app/Services/Archiving/ArchiveExecutor.php @@ -208,7 +208,16 @@ protected function applyContextFilters(Builder $query, ?array $context, string $ if ($value === null) { continue; } - if (Schema::hasColumn($query->from, $key)) { + // Special precedence: for contracts table, if contract_id provided, always scope to that single id + if ($table === 'contracts' && $key === 'contract_id') { + $query->where('id', $value); + $applied = true; + + // Do NOT allow broader filters (e.g., client_case_id) to widen the scope afterward + continue; + } + if (Schema::hasColumn($query->from, $key) && ! ($table === 'contracts' && $key === 'client_case_id' && isset($context['contract_id']))) { + // For contracts table: if contract_id present, skip client_case_id to avoid capturing all contracts of the case $query->where($key, $value); $applied = true; }