From ee9b26558227ed0bc345af0ed194f67053b4a79e Mon Sep 17 00:00:00 2001 From: Juan Felipe Zapata Moreno Date: Sat, 17 Jan 2026 11:18:47 -0600 Subject: [PATCH] =?UTF-8?q?fix:=20razon=20de=20cancelaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Repuve/PackageController.php | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/Repuve/PackageController.php b/app/Http/Controllers/Repuve/PackageController.php index f431eed..9476303 100644 --- a/app/Http/Controllers/Repuve/PackageController.php +++ b/app/Http/Controllers/Repuve/PackageController.php @@ -31,7 +31,6 @@ public function index(Request $request) 'tags.status:id,code,name', 'tags.vehicle:id,placa,niv', 'tags.module:id,name', - 'tags.cancellationLogs.cancellationReason', 'user:id,name,email' ]); } else { @@ -108,11 +107,6 @@ public function index(Request $request) 'id' => $tag->module->id, 'name' => $tag->module->name, ] : null, - 'cancellation_reason' => in_array($tag->status?->code, ['cancelled', 'damaged']) && $tag->cancellationLogs->first() ? [ - 'reason' => $tag->cancellationLogs->first()->cancellationReason?->name, - 'observations' => $tag->cancellationLogs->first()->cancellation_observations, - 'cancelled_at' => $tag->cancellationLogs->first()->cancellation_at, - ] : null, ]; }), ]; @@ -411,7 +405,7 @@ public function getBoxTags(Request $request) } // Obtener tags con paginación - $tags = Tag::with(['status:id,code,name', 'vehicle:id,placa,niv', 'module:id,name']) + $tags = Tag::with(['status:id,code,name', 'vehicle:id,placa,niv', 'module:id,name', 'cancellationLogs.cancellationReason']) ->where('package_id', $package->id) ->orderBy('folio', 'ASC'); @@ -428,20 +422,6 @@ public function getBoxTags(Request $request) $paginatedTags = $tags->paginate($request->input('per_page', 25)); - // Estadísticas generales - $estadisticas = [ - 'total' => Tag::where('package_id', $package->id)->count(), - 'available' => Tag::where('package_id', $package->id) - ->whereHas('status', fn($q) => $q->where('code', 'available')) - ->count(), - 'assigned' => Tag::where('package_id', $package->id) - ->whereHas('status', fn($q) => $q->where('code', 'assigned')) - ->count(), - 'cancelled' => Tag::where('package_id', $package->id) - ->whereHas('status', fn($q) => $q->where('code', 'cancelled')) - ->count(), - ]; - // Transformar tags $paginatedTags->getCollection()->transform(function ($tag) { return [ @@ -462,6 +442,11 @@ public function getBoxTags(Request $request) 'id' => $tag->module->id, 'name' => $tag->module->name, ] : null, + 'cancellation_reason' => in_array($tag->status?->code, ['cancelled', 'damaged']) && $tag->cancellationLogs->first() ? [ + 'reason' => $tag->cancellationLogs->first()->cancellationReason?->name, + 'observations' => $tag->cancellationLogs->first()->cancellation_observations, + 'cancelled_at' => $tag->cancellationLogs->first()->cancellation_at, + ] : null, ]; }); @@ -478,7 +463,6 @@ public function getBoxTags(Request $request) 'email' => $package->user->email, ] : null, ], - 'estadisticas' => $estadisticas, 'tags' => $paginatedTags, ]); } catch (\Exception $e) {