|
|
@@ -287,7 +287,7 @@ class CorrectiveMaintenanceController extends Controller{
|
|
|
}
|
|
|
|
|
|
$finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GMCO', 'OR', $tempFile, $idUser);
|
|
|
- if(!$finalFile){
|
|
|
+ if(!$finalFile[0]){
|
|
|
return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
|
|
|
}else{
|
|
|
$attachedArrFn[] = $finalFile[1];
|
|
|
@@ -637,8 +637,12 @@ class CorrectiveMaintenanceController extends Controller{
|
|
|
['USUA_NULI', '=', $line]
|
|
|
])->first();
|
|
|
|
|
|
- $nameReg = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
|
|
|
- $order->USUREG = $nameReg . " (" . $order->USUREG . ")";
|
|
|
+ if(is_null($usrReg)){
|
|
|
+ $order->USUREG = "AUTOMÁTICO (0)";
|
|
|
+ }else{
|
|
|
+ $nameReg = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
|
|
|
+ $order->USUREG = $nameReg . " (" . $order->USUREG . ")";
|
|
|
+ }
|
|
|
|
|
|
if(!is_null($order->USUMOD)){
|
|
|
$usrMod = DB::table('S002V01TUSUA')->where([
|
|
|
@@ -3292,4 +3296,1313 @@ class CorrectiveMaintenanceController extends Controller{
|
|
|
$this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
|
|
|
return $this->responseController->makeResponse(false, 'EXITO.', $reports);
|
|
|
}
|
|
|
+
|
|
|
+ public function registerMaintnencePlan(Request $request) {
|
|
|
+ DB::enableQueryLog();
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'id_user' => 'required|string',
|
|
|
+ 'linea' => 'required|integer',
|
|
|
+ 'equipment' => 'required|string',
|
|
|
+ 'equipment_status' => 'required|string|in:DE,DP,EF',
|
|
|
+ 'lru' => 'string',
|
|
|
+ 'lru_status' => 'string|in:DE,DP,EF',
|
|
|
+ 'description' => 'required|string|min:15',
|
|
|
+ 'inm_time' => 'required|numeric',
|
|
|
+ 'priority' => 'required|string',
|
|
|
+ 'total_duration' => 'required|numeric',
|
|
|
+ 'classification' => 'required|string|max:100',
|
|
|
+ 'specialties' => 'required|json',
|
|
|
+ 'specialties_conf' => 'required|json',
|
|
|
+ 'resources' => 'required|json',
|
|
|
+ 'attached' => 'required|json',
|
|
|
+ 'symptom' => 'required|string',
|
|
|
+ 'scada' => 'required|string',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if($validator->fails()){
|
|
|
+ return $this->responseController->makeResponse(
|
|
|
+ true,
|
|
|
+ "Se encontraron uno o más errores.",
|
|
|
+ $this->responseController->makeErrors(
|
|
|
+ $validator->errors()->messages()
|
|
|
+ ),
|
|
|
+ 401
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ $form = $request->all();
|
|
|
+ $idUser = $this->encryptionController->decrypt($form['id_user']);
|
|
|
+ if(!$idUser){
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $usr = DB::table('S002V01TUSUA')->where([
|
|
|
+ ['USUA_NULI', '=', $form['linea']],
|
|
|
+ ['USUA_IDUS', '=', $idUser]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($usr)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $equipmentCode = $this->encryptionController->decrypt($form['equipment']);
|
|
|
+ if(!$equipmentCode){
|
|
|
+ return $this->responseController->makeResponse(true, 'El código del equipamiento no fue encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $equipment = DB::table('S002V01TEQUI')->where([
|
|
|
+ ['EQUI_COEQ', '=', $equipmentCode],
|
|
|
+ ['EQUI_NULI', '=', $form['linea']]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($equipment)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El equipamiento relacionado no existe.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $lrui = null;
|
|
|
+ $eflr = null;
|
|
|
+ if(isset($form['lru'])){
|
|
|
+ $lruCode = $this->encryptionController->decrypt($form['lru']);
|
|
|
+ if(!$lruCode){
|
|
|
+ return $this->responseController->makeResponse(true, 'El código del LRU no fue encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $lru = DB::table('S002V01TEQUI')->where([
|
|
|
+ ['EQUI_COEQ', '=', $lruCode],
|
|
|
+ ['EQUI_NULI', '=', $form['linea']]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($lru)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El LRU relacionado no existe.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!isset($form['lru_status'])){
|
|
|
+ return $this->responseController->makeResponse(true, 'El estado del lru es obligatorio cuando se envía el campo lru.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $lrui = $lruCode;
|
|
|
+ $eflr = $form['lru_status'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $priorityDec = $this->encryptionController->decrypt($form['priority']);
|
|
|
+ $systemParamsExists = file_exists('C:\inetpub\wwwroot\sam\storage\app\files\system-params.json');
|
|
|
+ if(!$systemParamsExists){
|
|
|
+ return $this->responseController->makeResponse(true, 'El archivo de parámetros del sistema no fue encontrado.', [], 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ $paramsStr = file_get_contents('C:\inetpub\wwwroot\sam\storage\app\files\system-params.json');
|
|
|
+ $paramsArr = json_decode($paramsStr, true);
|
|
|
+ $orderPriorities = $paramsArr['order_priorities'];
|
|
|
+
|
|
|
+ $priorityFilt = array_filter($orderPriorities, function($v, $k) use($priorityDec) {
|
|
|
+ return $v['value'] == $priorityDec;
|
|
|
+ }, ARRAY_FILTER_USE_BOTH);
|
|
|
+
|
|
|
+ if(count($priorityFilt) < 1){
|
|
|
+ return $this->responseController->makeResponse(true, 'La prioridad seleccionada es inválida.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ //PENDINTE REVISAR RECURSOS CON STOCK
|
|
|
+ $attachedArr = json_decode($form['attached'], true);
|
|
|
+ $attachedArrFn = [];
|
|
|
+ foreach($attachedArr as $key=>$attached){
|
|
|
+ $idDec = $this->encryptionController->decrypt($attached['id']);
|
|
|
+ if(!$idDec){
|
|
|
+ return $this->responseController->makeResponse(true, "El ID del documento en la posición $key no fue encriptado correctamente.", [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $tempFile = DB::table('S002V01TARTE')->where([
|
|
|
+ ['ARTE_IDAR', '=', $idDec],
|
|
|
+ ['ARTE_NULI', '=', $form['linea']]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($tempFile)){
|
|
|
+ return $this->responseController->makeResponse(true, "El documento en la posición $key no existe.", [], 404);
|
|
|
+ }else if($tempFile->ARTE_ESTA == 'Eliminado'){
|
|
|
+ return $this->responseController->makeResponse(true, "El documento en la posición $key está eliminado.", [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GMCO', 'OR', $tempFile, $idUser);
|
|
|
+ if(!$finalFile[0]){
|
|
|
+ return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
|
|
|
+ }else{
|
|
|
+ $attachedArrFn[] = [
|
|
|
+ 'ID' => $finalFile[1],
|
|
|
+ 'TYPE' => $attached['type']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $idSymptom = $this->encryptionController->decrypt($form['symptom']);
|
|
|
+ if(!$idSymptom){
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID del síntoma no fue encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $symptom = DB::table('S002V01TLISI')->where([
|
|
|
+ ['LISI_NULI', '=', $form['linea']],
|
|
|
+ ['LISI_IDSI', '=', $idSymptom],
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($symptom)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El síntoma relacionado no existe.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $idSCADA = $this->encryptionController->decrypt($form['scada']);
|
|
|
+ if(!$idSCADA){
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID del SCADA no fue encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $scada = DB::table('S002V01TLISC')->where([
|
|
|
+ ['LISC_NULI', '=', $form['linea']],
|
|
|
+ ['LISC_IDSC', '=', $idSCADA]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($scada)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El SCADA relacionado no existe.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ //Una vez que se aprueban los datos se registra el contador relacionado
|
|
|
+ $now = $this->functionsController->now();
|
|
|
+ $nowStr = $now->toDateTimeString();
|
|
|
+ $idCounter = DB::table('S002V01TCONA')->insertGetId([
|
|
|
+ 'CONA_NULI' => $form['linea'],
|
|
|
+ 'CONA_INLE' => 5,
|
|
|
+ 'CONA_UTIL' => 'min',
|
|
|
+ 'CONA_TOIN' => 1,
|
|
|
+ 'CONA_UTTI' => 'min',
|
|
|
+ 'CONA_IDSC' => $idSCADA,
|
|
|
+ 'CONA_COEQ' => is_null($lrui) ? $equipmentCode : $lrui,
|
|
|
+ 'CONA_COVI' => '[]',
|
|
|
+ 'CONA_USRE' => $idUser,
|
|
|
+ 'CONA_FERE' => $nowStr
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $repeatStartDate = new Carbon($now->toDateString());
|
|
|
+ $repeatStart = str_replace(' ', 'T', $repeatStartDate->toDateTimeString());
|
|
|
+
|
|
|
+ $repeatHourDate = new Carbon($nowStr);
|
|
|
+ $hour = $repeatHourDate->hour;
|
|
|
+ $hourStr = "";
|
|
|
+ $minute = $repeatHourDate->minute;
|
|
|
+ $minuteStr = "";
|
|
|
+
|
|
|
+ if($minute > 0 && $minute <= 15){
|
|
|
+ $minuteStr = "15";
|
|
|
+ $hourStr = $hour < 10 ? "0$hour" : "$hour";
|
|
|
+ }else if($minute > 15 && $minute <= 30){
|
|
|
+ $minuteStr = "30";
|
|
|
+ $hourStr = $hour < 10 ? "0$hour" : "$hour";
|
|
|
+ }else if($minute > 30 && $minute <= 45){
|
|
|
+ $minuteStr = "45";
|
|
|
+ $hourStr = $hour < 10 ? "0$hour" : "$hour";
|
|
|
+ }else{
|
|
|
+ $minuteStr = "00";
|
|
|
+ $hourAux = $hour + 1;
|
|
|
+ $hourStr = $hourAux < 10 ? "0$hourAux" : "$hourAux";
|
|
|
+ }
|
|
|
+
|
|
|
+ $repeatHourStr = "$hourStr:$minuteStr:00";
|
|
|
+ $symptomRepeat = [
|
|
|
+ 'sign' => $idSymptom,
|
|
|
+ 'color' => 'rgb(79, 195, 255)',
|
|
|
+ 'repeat' => 'TD',
|
|
|
+ 'startDate' => "$repeatStart.000Z",
|
|
|
+ 'startHour' => $repeatHourStr,
|
|
|
+ 'customRepeat' => '',
|
|
|
+ ];
|
|
|
+
|
|
|
+ //Se procede a crear un activador relacionado al contador nuevo
|
|
|
+ $symptomRepeatStr = json_encode($symptomRepeat);
|
|
|
+ $idActivator = DB::table('S002V01TACTI')->insertGetId([
|
|
|
+ 'ACTI_NULI' => $form['linea'],
|
|
|
+ 'ACTI_PRIO' => $priorityDec,
|
|
|
+ 'ACTI_TIAC' => 'Sintoma',
|
|
|
+ 'ACTI_COAC' => $symptomRepeatStr,
|
|
|
+ 'ACTI_CORE' => $idCounter,
|
|
|
+ 'ACTI_USRE' => $idUser,
|
|
|
+ 'ACTI_FERE' => $nowStr,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $specialtiesArr = json_decode($form['specialties'], true);
|
|
|
+ $specialtiesDec = [];
|
|
|
+ foreach($specialtiesArr as $specialty){
|
|
|
+ $specialtiesDec[] = $this->encryptionController->decrypt($specialty);
|
|
|
+ }
|
|
|
+
|
|
|
+ $specialtiesStr = json_encode($specialtiesDec);
|
|
|
+
|
|
|
+ //Una vez obtenido el ID del nuevo contador relacionado se ingresa el plan de mantenimiento
|
|
|
+ $come = isset($form['comments']) ? $form['comments'] : null;
|
|
|
+ $dead = isset($form['extra_details']) ? $form['extra_details'] : null;
|
|
|
+ $dore = json_encode($attachedArrFn);
|
|
|
+
|
|
|
+ $idPlan = DB::table('S002V01TPMCO')->insertGetId([
|
|
|
+ 'PMCO_NULI' => $form['linea'],
|
|
|
+ 'PMCO_EQIN' => $equipmentCode,
|
|
|
+ 'PMCO_LRUI' => $lrui,
|
|
|
+ 'PMCO_EFEQ' => $form['equipment_status'],
|
|
|
+ 'PMCO_EFLR' => $eflr,
|
|
|
+ 'PMCO_DESC' => $form['description'],
|
|
|
+ 'PMCO_TIES' => $form['inm_time'],
|
|
|
+ 'PMCO_DTIN' => $form['total_duration'],
|
|
|
+ 'PMCO_CLAS' => $form['classification'],
|
|
|
+ 'PMCO_ESRE' => $specialtiesStr,
|
|
|
+ 'PMCO_COES' => $form['specialties_conf'],
|
|
|
+ 'PMCO_COME' => $come,
|
|
|
+ 'PMCO_RECU' => $form['resources'],
|
|
|
+ 'PMCO_DEAD' => $dead,
|
|
|
+ 'PMCO_DORE' => $dore,
|
|
|
+ 'PMCO_CORE' => $idCounter,
|
|
|
+ 'PMCO_USRE' => $idUser,
|
|
|
+ 'PMCO_FERE' => $nowStr,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $actions = DB::getQueryLog();
|
|
|
+ $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
|
|
|
+
|
|
|
+ $idac = $this->functionsController->registerActivity(
|
|
|
+ $form['linea'],
|
|
|
+ 'S002V01M09GMCO',
|
|
|
+ 'S002V01F02PLAN',
|
|
|
+ 'S002V01P01ASPL',
|
|
|
+ 'Registro',
|
|
|
+ "El usuario $name (" . $usr->USUA_IDUS . ") registró el plan de mantenimiento correctivo #$idPlan.",
|
|
|
+ $idUser,
|
|
|
+ $nowStr,
|
|
|
+ 'S002V01S02GEME'
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
|
|
|
+ return $this->responseController->makeResponse(false, 'EXITO.', [
|
|
|
+ 'PLAN' => $this->encryptionController->encrypt($idPlan),
|
|
|
+ 'ACTIVADOR' => $this->encryptionController->encrypt($idActivator),
|
|
|
+ 'CONTADOR' => $this->encryptionController->encrypt($idCounter),
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getMaintenancePlans($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);
|
|
|
+ }
|
|
|
+
|
|
|
+ $plansList = DB::table('S002V01TPMCO')->select([
|
|
|
+ 'PMCO_IDPM AS ID_PLAN',
|
|
|
+ 'PMCO_EQIN AS EQUIPAMIENTO',
|
|
|
+ 'PMCO_LRUI AS LRU',
|
|
|
+ 'PMCO_TIES AS TIEMPO_INMOVILIZACION_ESTIMADO',
|
|
|
+ 'PMCO_DTIN AS DURACION_TOTAL',
|
|
|
+ 'PMCO_CLAS AS CLASIFICACION',
|
|
|
+ 'PMCO_CORE AS CONTADOR',
|
|
|
+ 'ACTI_IDAC AS ACTIVADOR',
|
|
|
+ 'ACTI_PRIO AS PRIORIDAD',
|
|
|
+ 'PMCO_ESTA AS ESTADO',
|
|
|
+ 'PMCO_USRE AS USRREG',
|
|
|
+ 'PMCO_FERE AS FECREG',
|
|
|
+ 'PMCO_USMO AS USRMOD',
|
|
|
+ 'PMCO_FEMO AS FECMOD',
|
|
|
+ ])->join('S002V01TACTI', 'ACTI_CORE', '=', 'PMCO_CORE')->get()->all();
|
|
|
+
|
|
|
+ foreach($plansList as $key=>$plan){
|
|
|
+ $plan->ID_PLAN = $this->encryptionController->encrypt($plan->ID_PLAN);
|
|
|
+
|
|
|
+ $equipment = DB::table('S002V01TEQUI')->where([
|
|
|
+ ['EQUI_NULI', '=', $line],
|
|
|
+ ['EQUI_COEQ', '=', $plan->EQUIPAMIENTO]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ $equipmentLabel = $plan->EQUIPAMIENTO . " - " . $equipment->EQUI_TIPO . " - " . $equipment->EQUI_MODE . " (" . $equipment->EQUI_IDEQ . ")";
|
|
|
+ $plan->EQUIPAMIENTO = $this->encryptionController->encrypt($equipmentLabel);
|
|
|
+
|
|
|
+ if(!is_null($plan->LRU)){
|
|
|
+ $lru = DB::table('S002V01TEQUI')->where([
|
|
|
+ ['EQUI_NULI', '=', $line],
|
|
|
+ ['EQUI_COEQ', '=', $plan->LRU]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ $lruLabel = $plan->LRU . " - " . $lru->EQUI_TIPO . " - " . $lru->EQUI_MODE . " (" . $lru->EQUI_IDEQ . ")";
|
|
|
+ $plan->LRU = $this->encryptionController->encrypt($lruLabel);
|
|
|
+ }
|
|
|
+
|
|
|
+ $plan->CONTADOR = $this->encryptionController->encrypt($plan->CONTADOR);
|
|
|
+ $plan->ACTIVADOR = $this->encryptionController->encrypt($plan->ACTIVADOR);
|
|
|
+ $plan->PRIORIDAD = $this->encryptionController->encrypt($plan->PRIORIDAD);
|
|
|
+
|
|
|
+ $usrReg = DB::table('S002V01TUSUA')->where([
|
|
|
+ ['USUA_IDUS', '=', $plan->USRREG],
|
|
|
+ ['USUA_NULI', '=', '1'],
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
|
|
|
+ $plan->USRREG = $usrRegName . " (" . $plan->USRREG . ")";
|
|
|
+
|
|
|
+ if(!is_null($plan->USRMOD)){
|
|
|
+ $usrMod = DB::table('S002V01TUSUA')->where([
|
|
|
+ ['USUA_IDUS', '=', $plan->USRMOD],
|
|
|
+ ['USUA_NULI', '=', '1'],
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
|
|
|
+ $plan->USRMOD = $usrModName . " (" . $plan->USRMOD . ")";
|
|
|
+ }
|
|
|
+
|
|
|
+ $plansList[$key] = $plan;
|
|
|
+ }
|
|
|
+
|
|
|
+ $now = $this->functionsController->now();
|
|
|
+ $nowStr = $now->toDateTimeString();
|
|
|
+ $actions = DB::getQueryLog();
|
|
|
+ $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
|
|
|
+
|
|
|
+ $idac = $this->functionsController->registerActivity(
|
|
|
+ $line,
|
|
|
+ 'S002V01M09GMCO',
|
|
|
+ 'S002V01F02PLAN',
|
|
|
+ 'S002V01P01ASPL',
|
|
|
+ 'Consulta',
|
|
|
+ "El usuario $name (" . $usr->USUA_IDUS . ") consultó los planes de mantenimiento registrados.",
|
|
|
+ $idUser,
|
|
|
+ $nowStr,
|
|
|
+ 'S002V01S02GEME'
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
|
|
|
+ return $this->responseController->makeResponse(false, 'EXITO.', $plansList);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getMaintenancePlan($idPlan, $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);
|
|
|
+ }
|
|
|
+
|
|
|
+ $idPlan = $this->encryptionController->decrypt($idPlan);
|
|
|
+ if(!$idPlan){
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID del plan de mantenimiento no está encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $plan = DB::table('S002V01TPMCO')->select([
|
|
|
+ 'PMCO_IDPM AS ID_PLAN',
|
|
|
+ 'PMCO_EQIN AS EQUIPAMIENTO',
|
|
|
+ 'PMCO_LRUI AS LRU',
|
|
|
+ 'PMCO_EFEQ AS ESTADO_FUNCIONAMIENTO_EQUIPAMIENTO',
|
|
|
+ 'PMCO_EFLR AS ESTADO_FUNCIONAMIENTO_LRU',
|
|
|
+ 'PMCO_DESC AS DESCRIPCION',
|
|
|
+ 'PMCO_TIES AS TIEMPO_INMOVILIZACION_ESTIMADO',
|
|
|
+ 'PMCO_DTIN AS DURACION_TOTAL',
|
|
|
+ 'PMCO_CLAS AS CLASIFICACION',
|
|
|
+ 'PMCO_ESRE AS ESPECIALIDADES_REQUERIDAS',
|
|
|
+ 'PMCO_COES AS CONFIGURACION_OPERARIOS',
|
|
|
+ 'PMCO_COME AS COMENTARIOS',
|
|
|
+ 'PMCO_RECU AS RECURSOS',
|
|
|
+ 'PMCO_DEAD AS DETALLES_ADICIONALES',
|
|
|
+ 'PMCO_DORE AS DOCUMENTOS_RELACIONADOS',
|
|
|
+ 'PMCO_CORE AS CONTADOR',
|
|
|
+ 'CONA_IDSC AS SCADA',
|
|
|
+ 'ACTI_IDAC AS ACTIVADOR',
|
|
|
+ 'ACTI_PRIO AS PRIORIDAD',
|
|
|
+ 'ACTI_COAC AS SINTOMA',
|
|
|
+ 'PMCO_ESTA AS ESTADO',
|
|
|
+ 'PMCO_USRE AS USRREG',
|
|
|
+ 'PMCO_FERE AS FECREG',
|
|
|
+ 'PMCO_USMO AS USRMOD',
|
|
|
+ 'PMCO_FEMO AS FECMOD',
|
|
|
+ ])->where([
|
|
|
+ ['PMCO_NULI', '=', $line],
|
|
|
+ ['PMCO_IDPM', '=', $idPlan]
|
|
|
+ ])->join('S002V01TACTI', 'ACTI_CORE', '=', 'PMCO_CORE')
|
|
|
+ ->join('S002V01TCONA', 'CONA_IDCO', '=', 'PMCO_CORE')->first();
|
|
|
+
|
|
|
+ if(is_null($plan)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El plan solicitado no existe.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $plan->ID_PLAN = $this->encryptionController->encrypt($plan->ID_PLAN);
|
|
|
+ $equipment = DB::table('S002V01TEQUI')->where([
|
|
|
+ ['EQUI_NULI', '=', $line],
|
|
|
+ ['EQUI_COEQ', '=', $plan->EQUIPAMIENTO]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ $equipmentLabel = $plan->EQUIPAMIENTO . " - " . $equipment->EQUI_TIPO . " - " . $equipment->EQUI_MODE . " (" . $equipment->EQUI_IDEQ . ")";
|
|
|
+ $plan->EQUIPAMIENTO = $this->encryptionController->encrypt($equipmentLabel);
|
|
|
+
|
|
|
+ if(!is_null($plan->LRU)){
|
|
|
+ $lru = DB::table('S002V01TEQUI')->where([
|
|
|
+ ['EQUI_NULI', '=', $line],
|
|
|
+ ['EQUI_COEQ', '=', $plan->LRU]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ $lruLabel = $plan->LRU . " - " . $lru->EQUI_TIPO . " - " . $lru->EQUI_MODE . " (" . $lru->EQUI_IDEQ . ")";
|
|
|
+ $plan->LRU = $this->encryptionController->encrypt($lruLabel);
|
|
|
+ }
|
|
|
+
|
|
|
+ $documentsArr = json_decode($plan->DOCUMENTOS_RELACIONADOS, true);
|
|
|
+ $documentsFn = [];
|
|
|
+ foreach($documentsArr as $document){
|
|
|
+ $documentCodeArr0 = explode('=', $document['ID']);
|
|
|
+ $documentCodeArr1 = explode('-', $documentCodeArr0[0]);
|
|
|
+
|
|
|
+ $documentObj = DB::table('S002V01TAFAL')->where([
|
|
|
+ ['AFAL_NULI', '=', $line],
|
|
|
+ ['AFAL_COMO', '=', $documentCodeArr1[1]],
|
|
|
+ ['AFAL_CLDO', '=', $documentCodeArr1[2]],
|
|
|
+ ['AFAL_FECR', '=', $documentCodeArr1[3]],
|
|
|
+ ['AFAL_NUSE', '=', $documentCodeArr1[4]],
|
|
|
+ ['AFAL_NUVE', '=', $documentCodeArr0[1]],
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ $documentsFn[] = [
|
|
|
+ 'id' => $this->encryptionController->encrypt($document['ID']),
|
|
|
+ 'name' => $document['ID'],
|
|
|
+ 'size' => $documentObj->AFAL_TAMA,
|
|
|
+ 'type' => $document['TYPE']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $plan->DOCUMENTOS_RELACIONADOS = json_encode($documentsFn);
|
|
|
+ $plan->CONTADOR = $this->encryptionController->encrypt($plan->CONTADOR);
|
|
|
+ $plan->SCADA = $this->encryptionController->encrypt($plan->SCADA);
|
|
|
+ $plan->ACTIVADOR = $this->encryptionController->encrypt($plan->ACTIVADOR);
|
|
|
+ $plan->PRIORIDAD = $this->encryptionController->encrypt($plan->PRIORIDAD);
|
|
|
+
|
|
|
+ $activationConfig = json_decode($plan->SINTOMA, true);
|
|
|
+ $plan->SINTOMA = $this->encryptionController->encrypt($activationConfig['sign']);
|
|
|
+
|
|
|
+ $usrReg = DB::table('S002V01TUSUA')->where([
|
|
|
+ ['USUA_NULI', '=', $line],
|
|
|
+ ['USUA_IDUS', '=', $plan->USRREG]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
|
|
|
+ $plan->USRREG = $usrRegName . " (" . $plan->USRREG . ")";
|
|
|
+
|
|
|
+ if(!is_null($plan->USRMOD)){
|
|
|
+ $usrMod = DB::table('S002V01TUSUA')->where([
|
|
|
+ ['USUA_NULI', '=', $line],
|
|
|
+ ['USUA_IDUS', '=', $plan->USRMOD]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
|
|
|
+ $plan->USRMOD = $usrModName . " (" . $plan->USRMOD . ")";
|
|
|
+ }
|
|
|
+
|
|
|
+ $now = $this->functionsController->now();
|
|
|
+ $nowStr = $now->toDateTimeString();
|
|
|
+ $actions = DB::getQueryLog();
|
|
|
+ $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
|
|
|
+
|
|
|
+ $idac = $this->functionsController->registerActivity(
|
|
|
+ $line,
|
|
|
+ 'S002V01M09GMCO',
|
|
|
+ 'S002V01F02PLAN',
|
|
|
+ 'S002V01P01ASPL',
|
|
|
+ 'Consulta',
|
|
|
+ "El usuario $name (" . $usr->USUA_IDUS . ") consultó el plan de mantenimiento #$idPlan.",
|
|
|
+ $idUser,
|
|
|
+ $nowStr,
|
|
|
+ 'S002V01S02GEME'
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
|
|
|
+ return $this->responseController->makeResponse(false, 'EXITO.', $plan);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function updateMaintenancePlan(Request $request) {
|
|
|
+ DB::enableQueryLog();
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'id_user' => 'required|string',
|
|
|
+ 'linea' => 'required|integer',
|
|
|
+ 'id_plan' => 'required|string',
|
|
|
+ 'equipment' => 'required|string',
|
|
|
+ 'equipment_status' => 'required|string|in:DE,DP,EF',
|
|
|
+ 'lru' => 'string',
|
|
|
+ 'lru_status' => 'string|in:DE,DP,EF',
|
|
|
+ 'description' => 'required|string|min:15',
|
|
|
+ 'inm_time' => 'required|numeric',
|
|
|
+ 'total_duration' => 'required|numeric',
|
|
|
+ 'classification' => 'required|string|max:100',
|
|
|
+ 'specialties' => 'required|json',
|
|
|
+ 'specialties_conf' => 'required|json',
|
|
|
+ 'resources' => 'required|json',
|
|
|
+ 'attached' => 'required|json',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if($validator->fails()){
|
|
|
+ return $this->responseController->makeResponse(
|
|
|
+ true,
|
|
|
+ "Se encontraron uno o más errores.",
|
|
|
+ $this->responseController->makeErrors(
|
|
|
+ $validator->errors()->messages()
|
|
|
+ ),
|
|
|
+ 401
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ $form = $request->all();
|
|
|
+ $idUser = $this->encryptionController->decrypt($form['id_user']);
|
|
|
+ if(!$idUser){
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $usr = DB::table('S002V01TUSUA')->where([
|
|
|
+ ['USUA_NULI', '=', $form['linea']],
|
|
|
+ ['USUA_IDUS', '=', $idUser]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($usr)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $idPlan = $this->encryptionController->decrypt($form['id_plan']);
|
|
|
+ if(!$idPlan){
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID del plan de mantenimiento no fue encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $plan = DB::table('S002V01TPMCO')->where([
|
|
|
+ ['PMCO_NULI', '=', $form['linea']],
|
|
|
+ ['PMCO_IDPM', '=', $idPlan]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($plan)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El plan que desea modificar no existe.', [], 404);
|
|
|
+ }else if($plan->PMCO_ESTA == 'Eliminado'){
|
|
|
+ return $this->responseController->makeResponse(true, 'El plan que desea modificar está eliminado.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $equipmentCode = $this->encryptionController->decrypt($form['equipment']);
|
|
|
+ if(!$equipmentCode){
|
|
|
+ return $this->responseController->makeResponse(true, 'El código del equipamiento no fue encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $equipment = DB::table('S002V01TEQUI')->where([
|
|
|
+ ['EQUI_COEQ', '=', $equipmentCode],
|
|
|
+ ['EQUI_NULI', '=', $form['linea']]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($equipment)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El equipamiento relacionado no existe.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $lrui = null;
|
|
|
+ $eflr = null;
|
|
|
+ if(isset($form['lru'])){
|
|
|
+ $lruCode = $this->encryptionController->decrypt($form['lru']);
|
|
|
+ if(!$lruCode){
|
|
|
+ return $this->responseController->makeResponse(true, 'El código del LRU no fue encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $lru = DB::table('S002V01TEQUI')->where([
|
|
|
+ ['EQUI_COEQ', '=', $lruCode],
|
|
|
+ ['EQUI_NULI', '=', $form['linea']]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($lru)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El LRU relacionado no existe.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!isset($form['lru_status'])){
|
|
|
+ return $this->responseController->makeResponse(true, 'El estado del lru es obligatorio cuando se envía el campo lru.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $lrui = $lruCode;
|
|
|
+ $eflr = $form['lru_status'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $planCounter = DB::table('S002V01TCONA')->where([
|
|
|
+ ['CONA_NULI', '=', $form['linea']],
|
|
|
+ ['CONA_IDCO', '=', $plan->PMCO_CORE]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ $now = $this->functionsController->now();
|
|
|
+ $nowStr = $now->toDateTimeString();
|
|
|
+ $counterEquipment = $planCounter->CONA_COEQ;
|
|
|
+
|
|
|
+ if(is_null($lrui) && $counterEquipment != $equipmentCode){
|
|
|
+ DB::table('S002V01TCONA')->where([
|
|
|
+ ['CONA_NULI', '=', $form['linea']],
|
|
|
+ ['CONA_IDCO', '=', $plan->PMCO_CORE]
|
|
|
+ ])->update([
|
|
|
+ 'CONA_COEQ' => $equipmentCode,
|
|
|
+ 'CONA_USMO' => $idUser,
|
|
|
+ 'CONA_FEMO' => $nowStr
|
|
|
+ ]);
|
|
|
+ }else if($lrui != $counterEquipment){
|
|
|
+ DB::table('S002V01TCONA')->where([
|
|
|
+ ['CONA_NULI', '=', $form['linea']],
|
|
|
+ ['CONA_IDCO', '=', $plan->PMCO_CORE]
|
|
|
+ ])->update([
|
|
|
+ 'CONA_COEQ' => $lrui,
|
|
|
+ 'CONA_USMO' => $idUser,
|
|
|
+ 'CONA_FEMO' => $nowStr
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $specialtiesArr = json_decode($form['specialties'], true);
|
|
|
+ if(count($specialtiesArr) == 0){
|
|
|
+ return $this->responseController->makeResponse(true, 'El arreglo de especialidades está vacío.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $specialtiesDec = [];
|
|
|
+ foreach($specialtiesArr as $specialty){
|
|
|
+ $specialtiesDec[] = $this->encryptionController->decrypt($specialty);
|
|
|
+ }
|
|
|
+
|
|
|
+ $specialtiesStr = json_encode($specialtiesDec);
|
|
|
+ $attachedArr = json_decode($form['attached'], true);
|
|
|
+ if(count($attachedArr) == 0){
|
|
|
+ return $this->responseController->makeResponse(true, 'El arreglo de documentos está vacío.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $attachedArrFn = [];
|
|
|
+ foreach($attachedArr as $key=>$attached){
|
|
|
+ $idDec = $this->encryptionController->decrypt($attached['id']);
|
|
|
+ if(!$idDec){
|
|
|
+ return $this->responseController->makeResponse(true, "El ID del documento en la posición $key no fue encriptado correctamente.", [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($attached['isFinalFile']){
|
|
|
+ $documentCodeArr0 = explode('=', $idDec);
|
|
|
+ $documentCodeArr1 = explode('-', $documentCodeArr0[0]);
|
|
|
+
|
|
|
+ $file = DB::table('S002V01TAFAL')->where([
|
|
|
+ ['AFAL_NULI', '=', $form['linea']],
|
|
|
+ ['AFAL_COMO', '=', $documentCodeArr1[1]],
|
|
|
+ ['AFAL_CLDO', '=', $documentCodeArr1[2]],
|
|
|
+ ['AFAL_FECR', '=', $documentCodeArr1[3]],
|
|
|
+ ['AFAL_NUSE', '=', $documentCodeArr1[4]],
|
|
|
+ ['AFAL_NUVE', '=', $documentCodeArr0[1]],
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($file)){
|
|
|
+ return $this->responseController->makeResponse(true, "El documento en la posición $key no existe.", [], 404);
|
|
|
+ }else if($file->AFAL_ESTA == 'Eliminado'){
|
|
|
+ return $this->responseController->makeResponse(true, "El documento en la posición $key está eliminado.", [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $attachedArrFn[] = [
|
|
|
+ 'ID' => $idDec,
|
|
|
+ 'TYPE' => $attached['type']
|
|
|
+ ];
|
|
|
+ }else{
|
|
|
+ $tempFile = DB::table('S002V01TARTE')->where([
|
|
|
+ ['ARTE_IDAR', '=', $idDec],
|
|
|
+ ['ARTE_NULI', '=', $form['linea']]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($tempFile)){
|
|
|
+ return $this->responseController->makeResponse(true, "El documento en la posición $key no existe.", [], 404);
|
|
|
+ }else if($tempFile->ARTE_ESTA == 'Eliminado'){
|
|
|
+ return $this->responseController->makeResponse(true, "El documento en la posición $key está eliminado.", [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GMCO', 'OR', $tempFile, $idUser);
|
|
|
+ if(!$finalFile[0]){
|
|
|
+ return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
|
|
|
+ }else{
|
|
|
+ $attachedArrFn[] = [
|
|
|
+ 'ID' => $finalFile[1],
|
|
|
+ 'TYPE' => $attached['type']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $come = isset($form['comments']) ? $form['comments'] : null;
|
|
|
+ $dead = isset($form['extra_details']) ? $form['extra_details'] : null;
|
|
|
+ $dore = json_encode($attachedArrFn);
|
|
|
+
|
|
|
+ DB::table('S002V01TPMCO')->where([
|
|
|
+ ['PMCO_NULI', '=', $form['linea']],
|
|
|
+ ['PMCO_IDPM', '=', $idPlan]
|
|
|
+ ])->update([
|
|
|
+ 'PMCO_EQIN' => $equipmentCode,
|
|
|
+ 'PMCO_LRUI' => $lrui,
|
|
|
+ 'PMCO_EFEQ' => $form['equipment_status'],
|
|
|
+ 'PMCO_EFLR' => $eflr,
|
|
|
+ 'PMCO_DESC' => $form['description'],
|
|
|
+ 'PMCO_TIES' => $form['inm_time'],
|
|
|
+ 'PMCO_DTIN' => $form['total_duration'],
|
|
|
+ 'PMCO_CLAS' => $form['classification'],
|
|
|
+ 'PMCO_ESRE' => $specialtiesStr,
|
|
|
+ 'PMCO_COES' => $form['specialties_conf'],
|
|
|
+ 'PMCO_COME' => $come,
|
|
|
+ 'PMCO_RECU' => $form['resources'],
|
|
|
+ 'PMCO_DEAD' => $dead,
|
|
|
+ 'PMCO_DORE' => $dore,
|
|
|
+ 'PMCO_USMO' => $idUser,
|
|
|
+ 'PMCO_FEMO' => $nowStr,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $actions = DB::getQueryLog();
|
|
|
+ $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
|
|
|
+
|
|
|
+ $idac = $this->functionsController->registerActivity(
|
|
|
+ $form['linea'],
|
|
|
+ 'S002V01M09GMCO',
|
|
|
+ 'S002V01F02PLAN',
|
|
|
+ 'S002V01P01ASPL',
|
|
|
+ 'Actualización',
|
|
|
+ "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el plan de mantenimiento correctivo #$idPlan.",
|
|
|
+ $idUser,
|
|
|
+ $nowStr,
|
|
|
+ 'S002V01S02GEME'
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
|
|
|
+ return $this->responseController->makeResponse(false, 'EXITO.');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deleteMaintenancePlan(Request $request) {
|
|
|
+ DB::enableQueryLog();
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'id_user' => 'required|string',
|
|
|
+ 'linea' => 'required|integer',
|
|
|
+ 'id_plan' => 'required|string',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if($validator->fails()){
|
|
|
+ return $this->responseController->makeResponse(
|
|
|
+ true,
|
|
|
+ "Se encontraron uno o más errores.",
|
|
|
+ $this->responseController->makeErrors(
|
|
|
+ $validator->errors()->messages()
|
|
|
+ ),
|
|
|
+ 401
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ $form = $request->all();
|
|
|
+ $idUser = $this->encryptionController->decrypt($form['id_user']);
|
|
|
+ if(!$idUser){
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $usr = DB::table('S002V01TUSUA')->where([
|
|
|
+ ['USUA_NULI', '=', $form['linea']],
|
|
|
+ ['USUA_IDUS', '=', $idUser]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($usr)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $idPlan = $this->encryptionController->decrypt($form['id_plan']);
|
|
|
+ if(!$idPlan){
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID del plan de mantenimiento no fue encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $plan = DB::table('S002V01TPMCO')->where([
|
|
|
+ ['PMCO_NULI', '=', $form['linea']],
|
|
|
+ ['PMCO_IDPM', '=', $idPlan]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($plan)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El plan que desea modificar no existe.', [], 404);
|
|
|
+ }else if($plan->PMCO_ESTA == 'Eliminado'){
|
|
|
+ return $this->responseController->makeResponse(true, 'El plan que desea modificar está eliminado.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $now = $this->functionsController->now();
|
|
|
+ $nowStr = $now->toDateTimeString();
|
|
|
+ DB::table('S002V01TPMCO')->where([
|
|
|
+ ['PMCO_NULI', '=', $form['linea']],
|
|
|
+ ['PMCO_IDPM', '=', $idPlan]
|
|
|
+ ])->update([
|
|
|
+ 'PMCO_ESTA' => 'Eliminado',
|
|
|
+ 'PMCO_USMO' => $idUser,
|
|
|
+ 'PMCO_FEMO' => $nowStr,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $actions = DB::getQueryLog();
|
|
|
+ $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
|
|
|
+
|
|
|
+ $idac = $this->functionsController->registerActivity(
|
|
|
+ $form['linea'],
|
|
|
+ 'S002V01M09GMCO',
|
|
|
+ 'S002V01F02PLAN',
|
|
|
+ 'S002V01P01ASPL',
|
|
|
+ 'Eliminación',
|
|
|
+ "El usuario $name (" . $usr->USUA_IDUS . ") eliminó el plan de mantenimiento correctivo #$idPlan.",
|
|
|
+ $idUser,
|
|
|
+ $nowStr,
|
|
|
+ 'S002V01S02GEME'
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
|
|
|
+ return $this->responseController->makeResponse(false, 'EXITO.');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function registerWorkGroup(Request $request) {
|
|
|
+ DB::enableQueryLog();
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'id_user' => 'required|string',
|
|
|
+ 'linea' => 'required|integer',
|
|
|
+ 'work_group_name' => 'required|string|max:100|min:8',
|
|
|
+ 'related_teams' => 'required|json',
|
|
|
+ 'specialty' => 'required|string|max:100|min:8',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if($validator->fails()){
|
|
|
+ return $this->responseController->makeResponse(
|
|
|
+ true,
|
|
|
+ "Se encontraron uno o más errores.",
|
|
|
+ $this->responseController->makeErrors(
|
|
|
+ $validator->errors()->messages()
|
|
|
+ ),
|
|
|
+ 401
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ $form = $request->all();
|
|
|
+ $idUser = $this->encryptionController->decrypt($form['id_user']);
|
|
|
+ if(!$idUser){
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $usr = DB::table('S002V01TUSUA')->where([
|
|
|
+ ['USUA_NULI', '=', $form['linea']],
|
|
|
+ ['USUA_IDUS', '=', $idUser]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($usr)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $relatedTeamsArr = json_decode($form['related_teams'], true);
|
|
|
+ if(count($relatedTeamsArr) < 2){
|
|
|
+ return $this->responseController->makeResponse(true, 'El arreglo de equipos relacionados debe contener al menos 2 elementos.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $relatedTeamsArrDec = [];
|
|
|
+ foreach($relatedTeamsArr as $key=>$team){
|
|
|
+ $itemDec = $this->encryptionController->decrypt($team);
|
|
|
+ if(!$itemDec){
|
|
|
+ return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados no fue encriptado correctamente.", [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $workTeam = DB::table('S002V01TEQMA')->where([
|
|
|
+ ['EQMA_NULI', '=', $form['linea']],
|
|
|
+ ['EQMA_IDEQ', '=', $itemDec]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($workTeam)){
|
|
|
+ return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados no existe.", [], 404);
|
|
|
+ }else if($workTeam->EQMA_ESTA == 'Eliminado'){
|
|
|
+ return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados está eliminado.", [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $relatedTeamsArrDec[] = $itemDec;
|
|
|
+ }
|
|
|
+
|
|
|
+ $now = $this->functionsController->now();
|
|
|
+ $nowStr = $now->toDateTimeString();
|
|
|
+ $relatedTeamsStr = json_encode($relatedTeamsArrDec);
|
|
|
+ $idWorkGroup = DB::table('S002V01TGMCO')->insertGetId([
|
|
|
+ 'GMCO_NULI' => $form['linea'],
|
|
|
+ 'GMCO_NGMC' => $form['work_group_name'],
|
|
|
+ 'GMCO_EQRE' => $relatedTeamsStr,
|
|
|
+ 'GMCO_ESPE' => $form['specialty'],
|
|
|
+ 'GMCO_USRE' => $idUser,
|
|
|
+ 'GMCO_FERE' => $nowStr
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $actions = DB::getQueryLog();
|
|
|
+ $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
|
|
|
+
|
|
|
+ $idac = $this->functionsController->registerActivity(
|
|
|
+ $form['linea'],
|
|
|
+ 'S002V01M09GMCO',
|
|
|
+ 'S002V01F02AEMA',
|
|
|
+ 'S002V01P01AEOP',
|
|
|
+ 'Registro',
|
|
|
+ "El usuario $name (" . $usr->USUA_IDUS . ") registró el grupo de trabajo $form[work_group_name] ($idWorkGroup).",
|
|
|
+ $idUser,
|
|
|
+ $nowStr,
|
|
|
+ 'S002V01S04FUFL'
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
|
|
|
+ return $this->responseController->makeResponse(false, 'EXITO.');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getWorkGroups($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);
|
|
|
+ }
|
|
|
+
|
|
|
+ $workGroups = DB::table('S002V01TGMCO')->select([
|
|
|
+ 'GMCO_IDGM AS ID_GRUPO',
|
|
|
+ 'GMCO_NGMC AS NOMBRE_GRUPO',
|
|
|
+ 'GMCO_ESPE AS ESPECIALIDAD',
|
|
|
+ 'GMCO_ESTA AS ESTADO',
|
|
|
+ 'GMCO_USRE AS USUREG',
|
|
|
+ 'GMCO_FERE AS FECREG',
|
|
|
+ 'GMCO_USMO AS USUMOD',
|
|
|
+ 'GMCO_FEMO AS FECMOD'
|
|
|
+ ])->where('GMCO_NULI', '=', $line)->get()->all();
|
|
|
+
|
|
|
+ foreach($workGroups as $key=>$group){
|
|
|
+ $group->ID_GRUPO = $this->encryptionController->encrypt($group->ID_GRUPO);
|
|
|
+
|
|
|
+ $usrReg = DB::table('S002V01TUSUA')->where([
|
|
|
+ ['USUA_IDUS', '=', $group->USUREG],
|
|
|
+ ['USUA_NULI', '=', $line]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
|
|
|
+ $group->USUREG = $usrRegName . " (" . $group->USUREG . ')';
|
|
|
+
|
|
|
+ if(!is_null($group->USUMOD)){
|
|
|
+ $usrMod = DB::table('S002V01TUSUA')->where([
|
|
|
+ ['USUA_IDUS', '=', $group->USUMOD],
|
|
|
+ ['USUA_NULI', '=', $line]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
|
|
|
+ $group->USUMOD = $usrModName . " (" . $group->USUMOD . ')';
|
|
|
+ }
|
|
|
+
|
|
|
+ $workGroups[$key] = $group;
|
|
|
+ }
|
|
|
+
|
|
|
+ $now = $this->functionsController->now();
|
|
|
+ $nowStr = $now->toDateTimeString();
|
|
|
+ $actions = DB::getQueryLog();
|
|
|
+ $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
|
|
|
+
|
|
|
+ $idac = $this->functionsController->registerActivity(
|
|
|
+ $line,
|
|
|
+ 'S002V01M09GMCO',
|
|
|
+ 'S002V01F02AEMA',
|
|
|
+ 'S002V01P01AEOP',
|
|
|
+ 'Consulta',
|
|
|
+ "El usuario $name (" . $usr->USUA_IDUS . ") consultó los grupos de trabajo registrados.",
|
|
|
+ $idUser,
|
|
|
+ $nowStr,
|
|
|
+ 'S002V01S04FUFL'
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
|
|
|
+ return $this->responseController->makeResponse(false, 'EXITO.', $workGroups);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getWorkGroup($idGroup, $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);
|
|
|
+ }
|
|
|
+
|
|
|
+ $idGroup = $this->encryptionController->decrypt($idGroup);
|
|
|
+ if(!$idGroup){
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID del grupo de trabajo no está encriptado correctamente', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $workGroup = DB::table('S002V01TGMCO')->select([
|
|
|
+ 'GMCO_IDGM AS ID_GRUPO',
|
|
|
+ 'GMCO_NGMC AS NOMBRE_GRUPO',
|
|
|
+ 'GMCO_EQRE AS EQUIPOS_RELACIONADOS',
|
|
|
+ 'GMCO_ESPE AS ESPECIALIDAD',
|
|
|
+ 'GMCO_ESTA AS ESTADO',
|
|
|
+ 'GMCO_USRE AS USUREG',
|
|
|
+ 'GMCO_FERE AS FECREG',
|
|
|
+ 'GMCO_USMO AS USUMOD',
|
|
|
+ 'GMCO_FEMO AS FECMOD'
|
|
|
+ ])->where([
|
|
|
+ ['GMCO_IDGM', '=', $idGroup],
|
|
|
+ ['GMCO_NULI', '=', $line]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($workGroup)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El grupo de trabajo consultado no está registrado.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $workGroup->ID_GRUPO = $this->encryptionController->encrypt($workGroup->ID_GRUPO);
|
|
|
+ $relatedTeamsArr = json_decode($workGroup->EQUIPOS_RELACIONADOS, true);
|
|
|
+
|
|
|
+ $relatedTeams = [];
|
|
|
+ foreach($relatedTeamsArr as $team){
|
|
|
+ $teamInfo = DB::table('S002V01TEQMA')->where([
|
|
|
+ ['EQMA_NULI', '=', $line],
|
|
|
+ ['EQMA_IDEQ', '=', $team]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ $relatedTeams[] = [
|
|
|
+ 'ID_EQUIPO' => $this->encryptionController->encrypt($teamInfo->EQMA_IDEQ),
|
|
|
+ 'NOMBRE_EQUIPO' => $teamInfo->EQMA_NOMB,
|
|
|
+ 'ESPECIALIDAD' => $teamInfo->EQMA_ESPE
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $workGroup->EQUIPOS_RELACIONADOS = json_encode($relatedTeams);
|
|
|
+ $usrReg = DB::table('S002V01TUSUA')->where([
|
|
|
+ ['USUA_IDUS', '=', $workGroup->USUREG],
|
|
|
+ ['USUA_NULI', '=', $line]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
|
|
|
+ $workGroup->USUREG = $usrRegName . " (" . $workGroup->USUREG . ')';
|
|
|
+
|
|
|
+ if(!is_null($workGroup->USUMOD)){
|
|
|
+ $usrMod = DB::table('S002V01TUSUA')->where([
|
|
|
+ ['USUA_IDUS', '=', $workGroup->USUMOD],
|
|
|
+ ['USUA_NULI', '=', $line]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
|
|
|
+ $workGroup->USUMOD = $usrModName . " (" . $workGroup->USUMOD . ')';
|
|
|
+ }
|
|
|
+
|
|
|
+ $now = $this->functionsController->now();
|
|
|
+ $nowStr = $now->toDateTimeString();
|
|
|
+ $actions = DB::getQueryLog();
|
|
|
+ $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
|
|
|
+
|
|
|
+ $idac = $this->functionsController->registerActivity(
|
|
|
+ $line,
|
|
|
+ 'S002V01M09GMCO',
|
|
|
+ 'S002V01F02AEMA',
|
|
|
+ 'S002V01P01AEOP',
|
|
|
+ 'Consulta',
|
|
|
+ "El usuario $name (" . $usr->USUA_IDUS . ") consultó el grupo de trabajo " . $workGroup->NOMBRE_GRUPO . " ($idGroup).",
|
|
|
+ $idUser,
|
|
|
+ $nowStr,
|
|
|
+ 'S002V01S04FUFL'
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
|
|
|
+ return $this->responseController->makeResponse(false, 'EXITO.', $workGroup);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function updateWorkGroup(Request $request) {
|
|
|
+ DB::enableQueryLog();
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'id_user' => 'required|string',
|
|
|
+ 'linea' => 'required|integer',
|
|
|
+ 'id_work_group' => 'required|string',
|
|
|
+ 'work_group_name' => 'required|string|max:100|min:8',
|
|
|
+ 'related_teams' => 'required|json',
|
|
|
+ 'specialty' => 'required|string|max:100|min:8',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if($validator->fails()){
|
|
|
+ return $this->responseController->makeResponse(
|
|
|
+ true,
|
|
|
+ "Se encontraron uno o más errores.",
|
|
|
+ $this->responseController->makeErrors(
|
|
|
+ $validator->errors()->messages()
|
|
|
+ ),
|
|
|
+ 401
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ $form = $request->all();
|
|
|
+ $idUser = $this->encryptionController->decrypt($form['id_user']);
|
|
|
+ if(!$idUser){
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $usr = DB::table('S002V01TUSUA')->where([
|
|
|
+ ['USUA_NULI', '=', $form['linea']],
|
|
|
+ ['USUA_IDUS', '=', $idUser]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($usr)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $idWorkGroup = $this->encryptionController->decrypt($form['id_work_group']);
|
|
|
+ if(!$idWorkGroup){
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID del grupo de trabajo no fue encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $workGroup = DB::table('S002V01TGMCO')->where([
|
|
|
+ ['GMCO_NULI', '=', $form['linea']],
|
|
|
+ ['GMCO_IDGM', '=', $idWorkGroup]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($workGroup)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El grupo de trabajo solicitado no existe.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $relatedTeamsArr = json_decode($form['related_teams'], true);
|
|
|
+ if(count($relatedTeamsArr) < 2){
|
|
|
+ return $this->responseController->makeResponse(true, 'El arreglo de equipos relacionados debe contener al menos 2 elementos.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $relatedTeamsArrDec = [];
|
|
|
+ foreach($relatedTeamsArr as $key=>$team){
|
|
|
+ $itemDec = $this->encryptionController->decrypt($team);
|
|
|
+ if(!$itemDec){
|
|
|
+ return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados no fue encriptado correctamente.", [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $workTeam = DB::table('S002V01TEQMA')->where([
|
|
|
+ ['EQMA_NULI', '=', $form['linea']],
|
|
|
+ ['EQMA_IDEQ', '=', $itemDec]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($workTeam)){
|
|
|
+ return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados no existe.", [], 404);
|
|
|
+ }else if($workTeam->EQMA_ESTA == 'Eliminado'){
|
|
|
+ return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados está eliminado.", [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $relatedTeamsArrDec[] = $itemDec;
|
|
|
+ }
|
|
|
+
|
|
|
+ $now = $this->functionsController->now();
|
|
|
+ $nowStr = $now->toDateTimeString();
|
|
|
+ $relatedTeamsStr = json_encode($relatedTeamsArrDec);
|
|
|
+ DB::table('S002V01TGMCO')->where([
|
|
|
+ ['GMCO_NULI', '=', $form['linea']],
|
|
|
+ ['GMCO_IDGM', '=', $idWorkGroup]
|
|
|
+ ])->update([
|
|
|
+ 'GMCO_NGMC' => $form['work_group_name'],
|
|
|
+ 'GMCO_EQRE' => $relatedTeamsStr,
|
|
|
+ 'GMCO_ESPE' => $form['specialty'],
|
|
|
+ 'GMCO_USMO' => $idUser,
|
|
|
+ 'GMCO_FEMO' => $nowStr
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $actions = DB::getQueryLog();
|
|
|
+ $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
|
|
|
+
|
|
|
+ $idac = $this->functionsController->registerActivity(
|
|
|
+ $form['linea'],
|
|
|
+ 'S002V01M09GMCO',
|
|
|
+ 'S002V01F02AEMA',
|
|
|
+ 'S002V01P01AEOP',
|
|
|
+ 'Actualización',
|
|
|
+ "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el grupo de trabajo $form[work_group_name] ($idWorkGroup).",
|
|
|
+ $idUser,
|
|
|
+ $nowStr,
|
|
|
+ 'S002V01S04FUFL'
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
|
|
|
+ return $this->responseController->makeResponse(false, 'EXITO.');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deleteWorkGroup(Request $request) {
|
|
|
+ DB::enableQueryLog();
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'id_user' => 'required|string',
|
|
|
+ 'linea' => 'required|integer',
|
|
|
+ 'id_work_group' => 'required|string',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if($validator->fails()){
|
|
|
+ return $this->responseController->makeResponse(
|
|
|
+ true,
|
|
|
+ "Se encontraron uno o más errores.",
|
|
|
+ $this->responseController->makeErrors(
|
|
|
+ $validator->errors()->messages()
|
|
|
+ ),
|
|
|
+ 401
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ $form = $request->all();
|
|
|
+ $idUser = $this->encryptionController->decrypt($form['id_user']);
|
|
|
+ if(!$idUser){
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $usr = DB::table('S002V01TUSUA')->where([
|
|
|
+ ['USUA_NULI', '=', $form['linea']],
|
|
|
+ ['USUA_IDUS', '=', $idUser]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($usr)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $idWorkGroup = $this->encryptionController->decrypt($form['id_work_group']);
|
|
|
+ if(!$idWorkGroup){
|
|
|
+ return $this->responseController->makeResponse(true, 'El ID del grupo de trabajo no fue encriptado correctamente.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $workGroup = DB::table('S002V01TGMCO')->where([
|
|
|
+ ['GMCO_NULI', '=', $form['linea']],
|
|
|
+ ['GMCO_IDGM', '=', $idWorkGroup]
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(is_null($workGroup)){
|
|
|
+ return $this->responseController->makeResponse(true, 'El grupo de trabajo solicitado no existe.', [], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $now = $this->functionsController->now();
|
|
|
+ $nowStr = $now->toDateTimeString();
|
|
|
+ DB::table('S002V01TGMCO')->where([
|
|
|
+ ['GMCO_NULI', '=', $form['linea']],
|
|
|
+ ['GMCO_IDGM', '=', $idWorkGroup]
|
|
|
+ ])->update([
|
|
|
+ 'GMCO_ESTA' => 'Eliminado',
|
|
|
+ 'GMCO_USMO' => $idUser,
|
|
|
+ 'GMCO_FEMO' => $nowStr
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $actions = DB::getQueryLog();
|
|
|
+ $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
|
|
|
+
|
|
|
+ $idac = $this->functionsController->registerActivity(
|
|
|
+ $form['linea'],
|
|
|
+ 'S002V01M09GMCO',
|
|
|
+ 'S002V01F02AEMA',
|
|
|
+ 'S002V01P01AEOP',
|
|
|
+ 'Eliminación',
|
|
|
+ "El usuario $name (" . $usr->USUA_IDUS . ") eliminó el grupo de trabajo #$idWorkGroup.",
|
|
|
+ $idUser,
|
|
|
+ $nowStr,
|
|
|
+ 'S002V01S04FUFL'
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
|
|
|
+ return $this->responseController->makeResponse(false, 'EXITO.');
|
|
|
+ }
|
|
|
}
|