|
@@ -5104,14 +5104,22 @@ class PreventiveMaintenanceController extends Controller
|
|
|
$statusHistoryArr[$vaStatusIndex]['ATENCION'],
|
|
$statusHistoryArr[$vaStatusIndex]['ATENCION'],
|
|
|
$newInvitations
|
|
$newInvitations
|
|
|
);
|
|
);
|
|
|
|
|
+ // Agregar nuevos operarios a PERSONAL (sin duplicar)
|
|
|
|
|
+ $currentPersonal = $statusHistoryArr[$vaStatusIndex]['PERSONAL'] ?? [];
|
|
|
|
|
+ foreach ($audience as $operarioId) {
|
|
|
|
|
+ if (!in_array($operarioId, $currentPersonal)) {
|
|
|
|
|
+ $currentPersonal[] = $operarioId;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $statusHistoryArr[$vaStatusIndex]['PERSONAL'] = $currentPersonal;
|
|
|
} else {
|
|
} else {
|
|
|
- // Crear nuevo objeto VA
|
|
|
|
|
|
|
+ // Crear nuevo objeto VA con todos los invitados en PERSONAL
|
|
|
$statusHistoryArr[] = [
|
|
$statusHistoryArr[] = [
|
|
|
'USUARIO' => $idUser,
|
|
'USUARIO' => $idUser,
|
|
|
'ESTADO' => 'VA',
|
|
'ESTADO' => 'VA',
|
|
|
'FECHA' => $nowStr,
|
|
'FECHA' => $nowStr,
|
|
|
'ATENCION' => $newInvitations,
|
|
'ATENCION' => $newInvitations,
|
|
|
- 'PERSONAL' => []
|
|
|
|
|
|
|
+ 'PERSONAL' => $audience
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -5163,6 +5171,166 @@ class PreventiveMaintenanceController extends Controller
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function getVisitAttendance($idVisit, $idUser, $line)
|
|
|
|
|
+ {
|
|
|
|
|
+ DB::enableQueryLog();
|
|
|
|
|
+
|
|
|
|
|
+ $idUser = $this->encryptionController->decrypt($idUser);
|
|
|
|
|
+ if (!$idUser) {
|
|
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $usr = DB::table('S002V01TUSUA')->where([
|
|
|
|
|
+ ['USUA_NULI', '=', $line],
|
|
|
|
|
+ ['USUA_IDUS', '=', $idUser],
|
|
|
|
|
+ ])->first();
|
|
|
|
|
+
|
|
|
|
|
+ if (is_null($usr)) {
|
|
|
|
|
+ return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $idVisit = $this->encryptionController->decrypt($idVisit);
|
|
|
|
|
+ if (!$idVisit) {
|
|
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID de la visita relacionada no está encriptado correctamente', [], 400);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $visit = DB::table('S002V01TRVTN')->where([
|
|
|
|
|
+ ['RVTN_NULI', '=', $line],
|
|
|
|
|
+ ['RVTN_IDVI', '=', $idVisit]
|
|
|
|
|
+ ])->first();
|
|
|
|
|
+
|
|
|
|
|
+ if (is_null($visit)) {
|
|
|
|
|
+ return $this->responseController->makeResponse(true, 'La visita relacionada no está registrada.', [], 404);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $statusHistory = json_decode($visit->RVTN_HIES, true);
|
|
|
|
|
+ $validatedHistoryFilt = array_filter($statusHistory, function ($v, $k) {
|
|
|
|
|
+ return $v['ESTADO'] == 'VA';
|
|
|
|
|
+ }, ARRAY_FILTER_USE_BOTH);
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($validatedHistoryFilt)) {
|
|
|
|
|
+ return $this->responseController->makeResponse(true, 'La visita relacionada no está en el estado de validación', [], 404);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $validatedHistory = end($validatedHistoryFilt);
|
|
|
|
|
+ $attendance = array_key_exists('ATENCION', $validatedHistory) ? $validatedHistory['ATENCION'] : [];
|
|
|
|
|
+ $attendanceAux = [];
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($attendance as $item) {
|
|
|
|
|
+ if ($item['RESPUESTA'] == 'A') {
|
|
|
|
|
+ $attendanceAux[] = $item;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $this->responseController->makeResponse(false, 'EXITO', $attendanceAux);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function getVisitStaff($idVisit, $idUser, $line)
|
|
|
|
|
+ {
|
|
|
|
|
+ DB::enableQueryLog();
|
|
|
|
|
+
|
|
|
|
|
+ $idUser = $this->encryptionController->decrypt($idUser);
|
|
|
|
|
+ if (!$idUser) {
|
|
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $usr = DB::table('S002V01TUSUA')->where([
|
|
|
|
|
+ ['USUA_NULI', '=', $line],
|
|
|
|
|
+ ['USUA_IDUS', '=', $idUser],
|
|
|
|
|
+ ])->first();
|
|
|
|
|
+
|
|
|
|
|
+ if (is_null($usr)) {
|
|
|
|
|
+ return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $idVisit = $this->encryptionController->decrypt($idVisit);
|
|
|
|
|
+ if (!$idVisit) {
|
|
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID de la visita relacionada no está encriptado correctamente', [], 400);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $visit = DB::table('S002V01TRVTN')->where([
|
|
|
|
|
+ ['RVTN_NULI', '=', $line],
|
|
|
|
|
+ ['RVTN_IDVI', '=', $idVisit]
|
|
|
|
|
+ ])->first();
|
|
|
|
|
+
|
|
|
|
|
+ if (is_null($visit)) {
|
|
|
|
|
+ return $this->responseController->makeResponse(true, 'La visita relacionada no está registrada.', [], 404);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $staffArr = json_decode($visit->RVTN_PEIN, true);
|
|
|
|
|
+ $staffArrFn = [];
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($staffArr as $val) {
|
|
|
|
|
+ if (array_key_exists('TYPE', $val)) {
|
|
|
|
|
+ if ($val['TYPE'] == 'EQ') {
|
|
|
|
|
+ $workTeamStaff = DB::table('S002V01TPERS')->join('S002V01TUSUA', 'USUA_IDUS', '=', 'PERS_IDUS')->where([
|
|
|
|
|
+ ['PERS_NULI', '=', $line],
|
|
|
|
|
+ ['PERS_EQTR', '=', $val['ID']]
|
|
|
|
|
+ ])->get()->all();
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($workTeamStaff as $item) {
|
|
|
|
|
+ $itemID = $item->PERS_IDPE;
|
|
|
|
|
+ $itemFilt = array_filter($staffArrFn, function ($v, $k) use ($itemID) {
|
|
|
|
|
+ return $v['ID'] == $itemID;
|
|
|
|
|
+ }, ARRAY_FILTER_USE_BOTH);
|
|
|
|
|
+
|
|
|
|
|
+ if (count($itemFilt) <= 0) {
|
|
|
|
|
+ $staffArrFn[] = [
|
|
|
|
|
+ 'ID' => $itemID,
|
|
|
|
|
+ 'ID_USER' => $item->USUA_IDUS,
|
|
|
|
|
+ 'NAME' => $this->functionsController->joinName($item->USUA_NOMB, $item->USUA_APPA, $item->USUA_APMA),
|
|
|
|
|
+ 'TYPE' => $item->PERS_TICO,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ($val['TYPE'] == 'SU') {
|
|
|
|
|
+ $subcontratistStaff = DB::table('S002V01TPERS')->join('S002V01TUSUA', 'USUA_IDUS', '=', 'PERS_IDUS')->where([
|
|
|
|
|
+ ['PERS_NULI', '=', $line],
|
|
|
|
|
+ ['PERS_IDPS', '=', $val['ID']]
|
|
|
|
|
+ ])->get()->all();
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($subcontratistStaff as $item) {
|
|
|
|
|
+ $itemID = $item->PERS_IDPE;
|
|
|
|
|
+ $itemFilt = array_filter($staffArrFn, function ($v, $k) use ($itemID) {
|
|
|
|
|
+ return $v['ID'] == $itemID;
|
|
|
|
|
+ }, ARRAY_FILTER_USE_BOTH);
|
|
|
|
|
+
|
|
|
|
|
+ if (count($itemFilt) <= 0) {
|
|
|
|
|
+ $staffArrFn[] = [
|
|
|
|
|
+ 'ID' => $itemID,
|
|
|
|
|
+ 'ID_USER' => $item->USUA_IDUS,
|
|
|
|
|
+ 'NAME' => $this->functionsController->joinName($item->USUA_NOMB, $item->USUA_APPA, $item->USUA_APMA),
|
|
|
|
|
+ 'TYPE' => $item->PERS_TICO,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ($val['TYPE'] == 'EM') {
|
|
|
|
|
+ $employee = DB::table('S002V01TPERS')->join('S002V01TUSUA', 'USUA_IDUS', '=', 'PERS_IDUS')->where([
|
|
|
|
|
+ ['PERS_NULI', '=', $line],
|
|
|
|
|
+ ['PERS_IDPE', '=', $val['ID']]
|
|
|
|
|
+ ])->first();
|
|
|
|
|
+
|
|
|
|
|
+ if (!is_null($employee)) {
|
|
|
|
|
+ $itemID = $employee->PERS_IDPE;
|
|
|
|
|
+ $itemFilt = array_filter($staffArrFn, function ($v, $k) use ($itemID) {
|
|
|
|
|
+ return $v['ID'] == $itemID;
|
|
|
|
|
+ }, ARRAY_FILTER_USE_BOTH);
|
|
|
|
|
+
|
|
|
|
|
+ if (count($itemFilt) <= 0) {
|
|
|
|
|
+ $staffArrFn[] = [
|
|
|
|
|
+ 'ID' => $itemID,
|
|
|
|
|
+ 'ID_USER' => $employee->USUA_IDUS,
|
|
|
|
|
+ 'NAME' => $this->functionsController->joinName($employee->USUA_NOMB, $employee->USUA_APPA, $employee->USUA_APMA),
|
|
|
|
|
+ 'TYPE' => $employee->PERS_TICO,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $this->responseController->makeResponse(false, 'EXITO', $staffArr);
|
|
|
|
|
+ }
|
|
|
public function getVisitStatusHistory($idOrder, $idUser, $line)
|
|
public function getVisitStatusHistory($idOrder, $idUser, $line)
|
|
|
{
|
|
{
|
|
|
DB::enableQueryLog();
|
|
DB::enableQueryLog();
|
|
@@ -5430,15 +5598,6 @@ class PreventiveMaintenanceController extends Controller
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
$signature = $code;
|
|
$signature = $code;
|
|
|
-
|
|
|
|
|
- // Agregar al array PERSONAL
|
|
|
|
|
- if (!isset($statusHistoryArr[$vaStatusIndex]['PERSONAL'])) {
|
|
|
|
|
- $statusHistoryArr[$vaStatusIndex]['PERSONAL'] = [];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (!in_array($idUser, $statusHistoryArr[$vaStatusIndex]['PERSONAL'])) {
|
|
|
|
|
- $statusHistoryArr[$vaStatusIndex]['PERSONAL'][] = $idUser;
|
|
|
|
|
- }
|
|
|
|
|
} else if ($form['attendance'] == 'R') {
|
|
} else if ($form['attendance'] == 'R') {
|
|
|
$comments = $form['data'];
|
|
$comments = $form['data'];
|
|
|
}
|
|
}
|