|
|
@@ -2641,6 +2641,7 @@ class PreventiveMaintenanceController extends Controller
|
|
|
'id_user' => 'required|string',
|
|
|
'linea' => 'required|integer',
|
|
|
'id_visit' => 'required|string',
|
|
|
+ 'comments' => 'nullable|string|min:15',
|
|
|
'status' => 'required|string|in:VA,EP,CP,CE,P,C,R,A,F'
|
|
|
]);
|
|
|
|
|
|
@@ -2795,7 +2796,26 @@ class PreventiveMaintenanceController extends Controller
|
|
|
} elseif ($newStatus == 'C') {
|
|
|
$updateArr['RVTN_USCA'] = $idUser;
|
|
|
$updateArr['RVTN_FECA'] = $nowStr;
|
|
|
- } elseif ($newStatus == 'R' || $newStatus == 'A') {
|
|
|
+ } elseif ($newStatus == 'R') {
|
|
|
+ $updateArr['RVTN_UARE'] = $idUser;
|
|
|
+ $updateArr['RVTN_FARE'] = $nowStr;
|
|
|
+
|
|
|
+ // Registrar comentario de rechazo
|
|
|
+ if (!empty($form['comments'])) {
|
|
|
+ $commentsArr = json_decode($visit->RVTN_COME, true);
|
|
|
+ if (!is_array($commentsArr)) {
|
|
|
+ $commentsArr = [];
|
|
|
+ }
|
|
|
+
|
|
|
+ $commentsArr['COMENTARIO_RECHAZO'] = [
|
|
|
+ 'ID' => $idUser,
|
|
|
+ 'COMENTARIO' => $form['comments'],
|
|
|
+ 'FECHA' => $nowStr
|
|
|
+ ];
|
|
|
+
|
|
|
+ $updateArr['RVTN_COME'] = json_encode($commentsArr);
|
|
|
+ }
|
|
|
+ } elseif ($newStatus == 'A') {
|
|
|
$updateArr['RVTN_UARE'] = $idUser;
|
|
|
$updateArr['RVTN_FARE'] = $nowStr;
|
|
|
} elseif ($newStatus == 'F') {
|
|
|
@@ -3026,11 +3046,19 @@ class PreventiveMaintenanceController extends Controller
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // Obtener comentarios existentes para validación
|
|
|
+ $existingCommentsArr = json_decode($visit->RVTN_COME, true);
|
|
|
+ if (!is_array($existingCommentsArr)) {
|
|
|
+ $existingCommentsArr = [];
|
|
|
+ }
|
|
|
+
|
|
|
// Validar que el operario no haya registrado comentario ya
|
|
|
- foreach ($cpStatus['COMENTARIOS_OPERARIOS'] as $existingComment) {
|
|
|
- if (isset($existingComment['ID']) && $existingComment['ID'] === $idUser) {
|
|
|
- DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, 'Ya ha registrado su comentario de finalización para esta visita.', [], 400);
|
|
|
+ if (isset($existingCommentsArr['COMENTARIOS_OPERADORES']) && is_array($existingCommentsArr['COMENTARIOS_OPERADORES'])) {
|
|
|
+ foreach ($existingCommentsArr['COMENTARIOS_OPERADORES'] as $existingComment) {
|
|
|
+ if (isset($existingComment['ID']) && $existingComment['ID'] === $idUser) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'Ya ha registrado su comentario de finalización para esta visita.', [], 400);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -3051,7 +3079,8 @@ class PreventiveMaintenanceController extends Controller
|
|
|
$statusHistoryStr = json_encode($statusHistoryArr);
|
|
|
|
|
|
// Contar comentarios registrados vs total de operarios
|
|
|
- $commentsRegistered = count($cpStatus['COMENTARIOS_OPERARIOS']);
|
|
|
+ $updatedCommentsArr = json_decode($visit->RVTN_COME, true);
|
|
|
+ $commentsRegistered = isset($updatedCommentsArr['COMENTARIOS_OPERADORES']) ? count($updatedCommentsArr['COMENTARIOS_OPERADORES']) : 0;
|
|
|
$totalOperators = count($acceptedOperators);
|
|
|
$isComplete = $commentsRegistered >= $totalOperators;
|
|
|
|
|
|
@@ -3069,15 +3098,24 @@ class PreventiveMaintenanceController extends Controller
|
|
|
$updateArr['RVTN_FARE'] = $nowStr;
|
|
|
}
|
|
|
|
|
|
- // Actualizar comentarios si es necesario
|
|
|
+ // Actualizar comentarios de operadores
|
|
|
$commentsArr = json_decode($visit->RVTN_COME, true);
|
|
|
if (!is_array($commentsArr)) {
|
|
|
$commentsArr = [];
|
|
|
}
|
|
|
- // Solo agregar comentario de cambio de estado si es el primer comentario (cambio EP -> CP)
|
|
|
- if ($isFirstComment) {
|
|
|
- $commentsArr['CCP'] = 'Inicio de registro de comentarios de finalización por operarios.';
|
|
|
+
|
|
|
+ // Inicializar array de comentarios de operadores si no existe
|
|
|
+ if (!isset($commentsArr['COMENTARIOS_OPERADORES']) || !is_array($commentsArr['COMENTARIOS_OPERADORES'])) {
|
|
|
+ $commentsArr['COMENTARIOS_OPERADORES'] = [];
|
|
|
}
|
|
|
+
|
|
|
+ // Agregar comentario del operario
|
|
|
+ $commentsArr['COMENTARIOS_OPERADORES'][] = [
|
|
|
+ 'ID' => $idUser,
|
|
|
+ 'COMENTARIO' => $form['comment'],
|
|
|
+ 'FECHA' => $nowStr
|
|
|
+ ];
|
|
|
+
|
|
|
$commentsStr = json_encode($commentsArr);
|
|
|
$updateArr['RVTN_COME'] = $commentsStr;
|
|
|
|