fix: razon de cancelación
This commit is contained in:
parent
50e0cff497
commit
ee9b265582
@ -31,7 +31,6 @@ public function index(Request $request)
|
|||||||
'tags.status:id,code,name',
|
'tags.status:id,code,name',
|
||||||
'tags.vehicle:id,placa,niv',
|
'tags.vehicle:id,placa,niv',
|
||||||
'tags.module:id,name',
|
'tags.module:id,name',
|
||||||
'tags.cancellationLogs.cancellationReason',
|
|
||||||
'user:id,name,email'
|
'user:id,name,email'
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
@ -108,11 +107,6 @@ public function index(Request $request)
|
|||||||
'id' => $tag->module->id,
|
'id' => $tag->module->id,
|
||||||
'name' => $tag->module->name,
|
'name' => $tag->module->name,
|
||||||
] : null,
|
] : 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
|
// 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)
|
->where('package_id', $package->id)
|
||||||
->orderBy('folio', 'ASC');
|
->orderBy('folio', 'ASC');
|
||||||
|
|
||||||
@ -428,20 +422,6 @@ public function getBoxTags(Request $request)
|
|||||||
|
|
||||||
$paginatedTags = $tags->paginate($request->input('per_page', 25));
|
$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
|
// Transformar tags
|
||||||
$paginatedTags->getCollection()->transform(function ($tag) {
|
$paginatedTags->getCollection()->transform(function ($tag) {
|
||||||
return [
|
return [
|
||||||
@ -462,6 +442,11 @@ public function getBoxTags(Request $request)
|
|||||||
'id' => $tag->module->id,
|
'id' => $tag->module->id,
|
||||||
'name' => $tag->module->name,
|
'name' => $tag->module->name,
|
||||||
] : null,
|
] : 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,
|
'email' => $package->user->email,
|
||||||
] : null,
|
] : null,
|
||||||
],
|
],
|
||||||
'estadisticas' => $estadisticas,
|
|
||||||
'tags' => $paginatedTags,
|
'tags' => $paginatedTags,
|
||||||
]);
|
]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user