|
|
@@ -2234,7 +2234,6 @@ class PreventiveMaintenanceController extends Controller
|
|
|
// Visitas técnicas no programadas (Preventivas)
|
|
|
public function newUnprogrammedOrder(Request $request)
|
|
|
{
|
|
|
- Log::info($request->all());
|
|
|
DB::enableQueryLog();
|
|
|
|
|
|
$validator = Validator::make($request->all(), [
|
|
|
@@ -2633,7 +2632,6 @@ class PreventiveMaintenanceController extends Controller
|
|
|
// Visitas técnicas no programadas (Preventivas)
|
|
|
public function updateVisitStatus(Request $request)
|
|
|
{
|
|
|
- Log::info($request->all());
|
|
|
DB::enableQueryLog();
|
|
|
|
|
|
// RVTN_ESTA enum: 'VA','EP','CP','CE','P','C','R','A','F'
|
|
|
@@ -2644,7 +2642,6 @@ class PreventiveMaintenanceController extends Controller
|
|
|
'id_user' => 'required|string',
|
|
|
'linea' => 'required|integer',
|
|
|
'id_visit' => 'required|string',
|
|
|
- 'comments' => 'required|string|min:35',
|
|
|
'status' => 'required|string|in:VA,EP,CP,CE,P,C,R,A,F'
|
|
|
]);
|
|
|
|
|
|
@@ -2762,14 +2759,6 @@ class PreventiveMaintenanceController extends Controller
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Actualizar comentarios
|
|
|
- $commentsArr = json_decode($visit->RVTN_COME, true);
|
|
|
- if (!is_array($commentsArr)) {
|
|
|
- $commentsArr = [];
|
|
|
- }
|
|
|
- $commentsArr["C$newStatus"] = $form['comments'];
|
|
|
- $commentsStr = json_encode($commentsArr);
|
|
|
-
|
|
|
// Obtener y actualizar historial de estados
|
|
|
$statusHistoryArr = json_decode($visit->RVTN_HIES, true);
|
|
|
if (!is_array($statusHistoryArr)) {
|
|
|
@@ -2790,7 +2779,6 @@ class PreventiveMaintenanceController extends Controller
|
|
|
// Preparar actualización
|
|
|
$updateArr = [
|
|
|
'RVTN_ESTA' => $newStatus,
|
|
|
- 'RVTN_COME' => $commentsStr,
|
|
|
'RVTN_HIES' => $statusHistoryStr,
|
|
|
'RVTN_USMO' => $idUser,
|
|
|
'RVTN_FEMO' => $nowStr,
|
|
|
@@ -2864,7 +2852,7 @@ class PreventiveMaintenanceController extends Controller
|
|
|
|
|
|
$statusAction = $statusMessages[$newStatus] ?? 'Cambio de estado';
|
|
|
$notificationTitle = "Visita Técnica No Programada #$idVisit";
|
|
|
- $notificationMessage = "La visita técnica no programada #$idVisit ha sido {$statusAction}.";
|
|
|
+ $notificationMessage = "La visita técnica no programada #$idVisit ha sido actulizada a estado:{$statusAction}.";
|
|
|
|
|
|
// Notificación general para todos los cambios de estado (A, R, C, EP, F, VA, CE, CP)
|
|
|
if (in_array($newStatus, ['A', 'R', 'C', 'EP', 'F', 'VA', 'CE', 'CP']) && !empty($audience)) {
|
|
|
@@ -2919,7 +2907,7 @@ class PreventiveMaintenanceController extends Controller
|
|
|
'id_user' => 'required|string',
|
|
|
'linea' => 'required|integer',
|
|
|
'id_visit' => 'required|string',
|
|
|
- 'comment' => 'required|string|min:35'
|
|
|
+ 'comment' => 'required|string|min:15'
|
|
|
]);
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
@@ -3235,7 +3223,25 @@ class PreventiveMaintenanceController extends Controller
|
|
|
// Revertir transacción en caso de error
|
|
|
DB::rollBack();
|
|
|
|
|
|
- Log::error('Error en registerOperatorClosingComment: ' . $e->getMessage());
|
|
|
+ $actions = DB::getQueryLog();
|
|
|
+ $now = $this->functionsController->now();
|
|
|
+ $nowStr = $now->toDateTimeString();
|
|
|
+ $name = $this->functionsController->joinName($usr->USUA_NOMB ?? '', $usr->USUA_APPA ?? '', $usr->USUA_APMA ?? '');
|
|
|
+
|
|
|
+ $idac = $this->functionsController->registerActivity(
|
|
|
+ $form['linea'],
|
|
|
+ 'S002V01M10GMPR',
|
|
|
+ 'S002V01F11RVTP',
|
|
|
+ 'S002V01P01REVI',
|
|
|
+ 'Error',
|
|
|
+ "Error al registrar comentario de finalización para la visita no programada #$idVisit: " . $e->getMessage(),
|
|
|
+ $idUser,
|
|
|
+ $nowStr,
|
|
|
+ 'S002V01S02AOTR'
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
|
|
|
+
|
|
|
return $this->responseController->makeResponse(
|
|
|
true,
|
|
|
'Ocurrió un error al registrar el comentario de finalización.',
|
|
|
@@ -3320,27 +3326,30 @@ class PreventiveMaintenanceController extends Controller
|
|
|
|
|
|
$statusHistoryArr = json_decode($visit->RVTN_HIES, true);
|
|
|
if (!is_array($statusHistoryArr)) {
|
|
|
- return $this->responseController->makeResponse(true, 'No se encontró un historial de estados válido para la visita.', [], 500);
|
|
|
+ $statusHistoryArr = [];
|
|
|
}
|
|
|
|
|
|
+ // Buscar objeto VA en el historial
|
|
|
+ // Si no existe pero RVTN_ESTA == 'VA', la visita está validada pero aún no tiene operarios asignados
|
|
|
$validatedHistoryFilt = array_filter($statusHistoryArr, function ($item) {
|
|
|
return array_key_exists('ESTADO', $item) && $item['ESTADO'] == 'VA';
|
|
|
});
|
|
|
|
|
|
- if (empty($validatedHistoryFilt)) {
|
|
|
- return $this->responseController->makeResponse(true, 'La visita no cuenta con un estado validado para iniciar.', [], 401);
|
|
|
- }
|
|
|
-
|
|
|
- $validatedStatus = end($validatedHistoryFilt);
|
|
|
$audience = [];
|
|
|
|
|
|
- if (array_key_exists('ATENCION', $validatedStatus) && is_array($validatedStatus['ATENCION'])) {
|
|
|
- foreach ($validatedStatus['ATENCION'] as $item) {
|
|
|
- if (($item['RESPUESTA'] ?? '') === 'A') {
|
|
|
- $audience[] = $item['ID'];
|
|
|
+ // Si existe el objeto VA en el historial, obtener los operarios aceptados
|
|
|
+ if (!empty($validatedHistoryFilt)) {
|
|
|
+ $validatedStatus = end($validatedHistoryFilt);
|
|
|
+ if (array_key_exists('ATENCION', $validatedStatus) && is_array($validatedStatus['ATENCION'])) {
|
|
|
+ foreach ($validatedStatus['ATENCION'] as $item) {
|
|
|
+ if (($item['RESPUESTA'] ?? '') === 'A') {
|
|
|
+ $audience[] = $item['ID'];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ // Si no existe el objeto VA en el historial pero RVTN_ESTA == 'VA',
|
|
|
+ // la audiencia quedará vacía (no hay operarios asignados aún)
|
|
|
|
|
|
$now = $this->functionsController->now();
|
|
|
$nowStr = $now->toDateTimeString();
|
|
|
@@ -5928,7 +5937,25 @@ class PreventiveMaintenanceController extends Controller
|
|
|
// Revertir transacción en caso de error
|
|
|
DB::rollBack();
|
|
|
|
|
|
- Log::error('Error en assignOperariosToPreventiveVisit: ' . $e->getMessage());
|
|
|
+ $actions = DB::getQueryLog();
|
|
|
+ $now = $this->functionsController->now();
|
|
|
+ $nowStr = $now->toDateTimeString();
|
|
|
+ $name = $this->functionsController->joinName($usr->USUA_NOMB ?? '', $usr->USUA_APPA ?? '', $usr->USUA_APMA ?? '');
|
|
|
+
|
|
|
+ $idac = $this->functionsController->registerActivity(
|
|
|
+ $form['linea'],
|
|
|
+ 'S002V01M10GMPR',
|
|
|
+ 'S002V01F11RVTP',
|
|
|
+ 'S002V01P01REVI',
|
|
|
+ 'Error',
|
|
|
+ "Error al asignar operarios a la visita preventiva #$idVisit: " . $e->getMessage(),
|
|
|
+ $idUser,
|
|
|
+ $nowStr,
|
|
|
+ 'S002V01S02AOTR'
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
|
|
|
+
|
|
|
return $this->responseController->makeResponse(
|
|
|
true,
|
|
|
'Ocurrió un error al asignar operarios a la visita preventiva.',
|
|
|
@@ -5971,13 +5998,42 @@ class PreventiveMaintenanceController extends Controller
|
|
|
return $this->responseController->makeResponse(true, 'La visita relacionada no está registrada.', [], 404);
|
|
|
}
|
|
|
|
|
|
+ // Validar que la visita esté en estado VA (validado)
|
|
|
+ // Puede estar en estado VA en RVTN_ESTA sin tener aún el objeto VA en RVTN_HIES
|
|
|
+ // (cuando se crea automáticamente pero aún no se han asignado operarios)
|
|
|
+ $visitStates = [
|
|
|
+ 'VA' => 'Validada',
|
|
|
+ 'EP' => 'En progreso',
|
|
|
+ 'CP' => 'Cerrada pendiente',
|
|
|
+ 'CE' => 'Cerrada',
|
|
|
+ 'PE' => 'Pendiente de validación',
|
|
|
+ 'P' => 'Pendiente',
|
|
|
+ 'C' => 'Cancelada',
|
|
|
+ 'R' => 'Rechazada',
|
|
|
+ 'A' => 'Aprobada',
|
|
|
+ 'F' => 'Finalizada',
|
|
|
+ ];
|
|
|
+
|
|
|
+ if ($visit->RVTN_ESTA !== 'VA') {
|
|
|
+ $statusKey = $visit->RVTN_ESTA;
|
|
|
+ $statusName = array_key_exists($statusKey, $visitStates) ? $visitStates[$statusKey] : $statusKey;
|
|
|
+ return $this->responseController->makeResponse(true, "La visita relacionada no está en el estado de validación (estado actual: $statusName)", [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
$statusHistory = json_decode($visit->RVTN_HIES, true);
|
|
|
+ if (!is_array($statusHistory)) {
|
|
|
+ $statusHistory = [];
|
|
|
+ }
|
|
|
+
|
|
|
$validatedHistoryFilt = array_filter($statusHistory, function ($v, $k) {
|
|
|
- return $v['ESTADO'] == 'VA';
|
|
|
+ return isset($v['ESTADO']) && $v['ESTADO'] == 'VA';
|
|
|
}, ARRAY_FILTER_USE_BOTH);
|
|
|
|
|
|
+ // Si no hay objeto VA en el historial pero el estado es VA, significa que aún no se han asignado operarios
|
|
|
if (empty($validatedHistoryFilt)) {
|
|
|
- return $this->responseController->makeResponse(true, 'La visita relacionada no está en el estado de validación', [], 404);
|
|
|
+ $statusKey = $visit->RVTN_ESTA;
|
|
|
+ $statusName = array_key_exists($statusKey, $visitStates) ? $visitStates[$statusKey] : $statusKey;
|
|
|
+ return $this->responseController->makeResponse(true, "La visita tiene estado $statusName pero aún no ha asignado operarios.", [], 404);
|
|
|
}
|
|
|
|
|
|
$validatedHistory = end($validatedHistoryFilt);
|
|
|
@@ -6507,7 +6563,25 @@ class PreventiveMaintenanceController extends Controller
|
|
|
// Revertir transacción en caso de error
|
|
|
DB::rollBack();
|
|
|
|
|
|
- Log::error('Error en attendPreventiveVisit: ' . $e->getMessage());
|
|
|
+ $actions = DB::getQueryLog();
|
|
|
+ $now = $this->functionsController->now();
|
|
|
+ $nowStr = $now->toDateTimeString();
|
|
|
+ $userName = $this->functionsController->joinName($usr->USUA_NOMB ?? '', $usr->USUA_APPA ?? '', $usr->USUA_APMA ?? '');
|
|
|
+
|
|
|
+ $idac = $this->functionsController->registerActivity(
|
|
|
+ $form['linea'],
|
|
|
+ 'S002V01M10GMPR',
|
|
|
+ 'S002V01F11RVTP',
|
|
|
+ 'S002V01P01REVI',
|
|
|
+ 'Error',
|
|
|
+ "Error al procesar la respuesta de la visita preventiva #$idVisit: " . $e->getMessage(),
|
|
|
+ $idUser,
|
|
|
+ $nowStr,
|
|
|
+ 'S002V01S02AOTR'
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
|
|
|
+
|
|
|
return $this->responseController->makeResponse(
|
|
|
true,
|
|
|
'Ocurrió un error al procesar la respuesta de la visita.',
|