Przeglądaj źródła

modificacion a registerWorkOrder para registrar ICON_ID en los parametros de su notificacion.

EmilianoOrtiz 4 dni temu
rodzic
commit
df192867f9

+ 90 - 65
sistema-mantenimiento-back/app/Http/Controllers/CorrectiveMaintenanceController.php

@@ -331,7 +331,7 @@ class CorrectiveMaintenanceController extends Controller
             'OTCO_USRE' => $idUser,
             'OTCO_FERE' => $nowStr
         ]);
-            
+
         $paramsStr = file_get_contents('C:\inetpub\wwwroot\sam\storage\app\files\system-params.json');
         $paramsArr = json_decode($paramsStr, true);
         $orderPriorities = $paramsArr['order_priorities'];
@@ -341,28 +341,50 @@ class CorrectiveMaintenanceController extends Controller
         }, ARRAY_FILTER_USE_BOTH);
 
         $notificationColor = "rgb(35, 95, 172)";
-        if(count($priorityFilt) > 0){
+        if (count($priorityFilt) > 0) {
             $priority = end($priorityFilt);
             $notificationColor = $priority['color'];
         }
 
+        // Extract station code from equipment code
+        $stationCode = null;
+        $iconId = null;
+        $equipmentParts = explode('.', $equipmentCode);
+        if (count($equipmentParts) > 1) {
+            $stationCode = $equipmentParts[1];
+            $station = DB::table('S002V01TMEST')->where([
+                ['MEST_CODE', '=', $stationCode],
+                ['MEST_NULI', '=', $form['linea']]
+            ])->first();
+            
+            if (!is_null($station) && !is_null($station->MEST_FNCO)) {
+                $iconId = $this->encryptionController->encrypt($station->MEST_FNCO);
+            }
+        }
+
+        $actions = [[
+            'BOTON' => 'Ver detalles',
+            'FUNCION' => 'openCorrectiveWorkOrderDetails',
+            'PARAMETROS' => json_encode([$this->encryptionController->encrypt($orderID)])
+        ], [
+            'BOTON' => 'Asignar orden',
+            'FUNCION' => 'validateCorrectiveWorkOrder',
+            'PARAMETROS' => json_encode([$this->encryptionController->encrypt($orderID)])
+        ], [
+            'BOTON' => 'Ir al módulo',
+            'FUNCION' => 'openModule',
+            'PARAMETROS' => json_encode([$this->encryptionController->encrypt('GMCO/ORTR/GEOP')])
+        ]];
+        
+        if (!is_null($iconId)) {
+            $actions[] = ['ICON_ID' => $iconId];
+        }
+
         $this->notificationsController->emitNotification(
             'S002V01M09GMCO',
             "Orden de mantenimiento correctivo #$orderID",
             "Su usuario ha sido asignado como responsable de atender la orden de mantenimiento #$orderID.",
-            [[
-                'BOTON' => 'Ver detalles',
-                'FUNCION' => 'openCorrectiveWorkOrderDetails',
-                'PARAMETROS' => json_encode([$this->encryptionController->encrypt($orderID)])
-            ], [
-                'BOTON' => 'Asignar orden',
-                'FUNCION' => 'validateCorrectiveWorkOrder',
-                'PARAMETROS' => json_encode([$this->encryptionController->encrypt($orderID)])
-            ], [
-                'BOTON' => 'Ir al módulo',
-                'FUNCION' => 'openModule',
-                'PARAMETROS' => json_encode([$this->encryptionController->encrypt('GMCO/ORTR/GEOP')])
-            ]],
+            $actions,
             [$idUserResponsible],
             $idUser,
             $form['linea'],
@@ -798,7 +820,7 @@ class CorrectiveMaintenanceController extends Controller
         // Verificar si ya existe análisis previo
         $tieneAnalisisPrevio = !is_null($order->OTCO_ANCO) && $order->OTCO_ANCO !== '';
         $analisisPrevio = null;
-        
+
         if ($tieneAnalisisPrevio) {
             $analisisPrevio = json_decode($order->OTCO_ANCO, true);
         }
@@ -814,9 +836,10 @@ class CorrectiveMaintenanceController extends Controller
         ]);
     }
 
-    public function saveCostAnalysis(Request $request) {
+    public function saveCostAnalysis(Request $request)
+    {
         DB::enableQueryLog();
-        
+
         $validator = Validator::make($request->all(), [
             'id_user' => 'required|string',
             'linea' => 'required|integer',
@@ -909,7 +932,7 @@ class CorrectiveMaintenanceController extends Controller
         $nowStr = $now->toDateTimeString();
         $actions = DB::getQueryLog();
         $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-        
+
         $idac = $this->functionsController->registerActivity(
             $form['linea'],
             'S002V01M09GMCO',
@@ -923,7 +946,7 @@ class CorrectiveMaintenanceController extends Controller
         );
 
         $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
-        
+
         return $this->responseController->makeResponse(false, 'Análisis de costos guardado exitosamente.', []);
     }
 
@@ -1412,7 +1435,7 @@ class CorrectiveMaintenanceController extends Controller
                 $audience[] = $employee->PERS_IDUS;
             }
         }
-            
+
         $paramsStr = file_get_contents('C:\inetpub\wwwroot\sam\storage\app\files\system-params.json');
         $paramsArr = json_decode($paramsStr, true);
         $orderPriorities = $paramsArr['order_priorities'];
@@ -1422,7 +1445,7 @@ class CorrectiveMaintenanceController extends Controller
         }, ARRAY_FILTER_USE_BOTH);
 
         $notificationColor = "rgb(35, 95, 172)";
-        if(count($priorityFilt) > 0){
+        if (count($priorityFilt) > 0) {
             $priority = end($priorityFilt);
             $notificationColor = $priority['color'];
         }
@@ -1599,7 +1622,7 @@ class CorrectiveMaintenanceController extends Controller
         $statusApproved['PERSONAL'] = $staff;
         $statusHistoryArr[$approvedKey] = $statusApproved;
         $statusHistoryStr = json_encode($statusHistoryArr);
-            
+
         $paramsStr = file_get_contents('C:\inetpub\wwwroot\sam\storage\app\files\system-params.json');
         $paramsArr = json_decode($paramsStr, true);
         $orderPriorities = $paramsArr['order_priorities'];
@@ -1609,7 +1632,7 @@ class CorrectiveMaintenanceController extends Controller
         }, ARRAY_FILTER_USE_BOTH);
 
         $notificationColor = "rgb(35, 95, 172)";
-        if(count($priorityFilt) > 0){
+        if (count($priorityFilt) > 0) {
             $priority = end($priorityFilt);
             $notificationColor = $priority['color'];
         }
@@ -1749,10 +1772,10 @@ class CorrectiveMaintenanceController extends Controller
         $validatedStatus = end($validatedStatusFilt);
         $audience = [];
 
-        foreach($validatedStatus['ATENCION'] as $item){
-            if($item['RESPUESTA'] == 'A') $audience[] = $item['ID'];
+        foreach ($validatedStatus['ATENCION'] as $item) {
+            if ($item['RESPUESTA'] == 'A') $audience[] = $item['ID'];
         }
-            
+
         $paramsStr = file_get_contents('C:\inetpub\wwwroot\sam\storage\app\files\system-params.json');
         $paramsArr = json_decode($paramsStr, true);
         $orderPriorities = $paramsArr['order_priorities'];
@@ -1762,7 +1785,7 @@ class CorrectiveMaintenanceController extends Controller
         }, ARRAY_FILTER_USE_BOTH);
 
         $notificationColor = "rgb(35, 95, 172)";
-        if(count($priorityFilt) > 0){
+        if (count($priorityFilt) > 0) {
             $priority = end($priorityFilt);
             $notificationColor = $priority['color'];
         }
@@ -1821,7 +1844,8 @@ class CorrectiveMaintenanceController extends Controller
         return $this->responseController->makeResponse(false, 'EXITO.');
     }
 
-    public function updateWorkOrderStatus(Request $request)
+
+        public function updateWorkOrderStatus(Request $request)
     {
         DB::enableQueryLog();
         $validator = Validator::make($request->all(), [
@@ -2131,6 +2155,7 @@ class CorrectiveMaintenanceController extends Controller
         return $this->responseController->makeResponse(false, "EXITO");
     }
 
+
     public function closeWorkOrder(Request $request)
     {
         DB::enableQueryLog();
@@ -2201,7 +2226,7 @@ class CorrectiveMaintenanceController extends Controller
 
         $closeUserName = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
         $audience = [$order->OTCO_USRE];
-            
+
         $paramsStr = file_get_contents('C:\inetpub\wwwroot\sam\storage\app\files\system-params.json');
         $paramsArr = json_decode($paramsStr, true);
         $orderPriorities = $paramsArr['order_priorities'];
@@ -2211,7 +2236,7 @@ class CorrectiveMaintenanceController extends Controller
         }, ARRAY_FILTER_USE_BOTH);
 
         $notificationColor = "rgb(35, 95, 172)";
-        if(count($priorityFilt) > 0){
+        if (count($priorityFilt) > 0) {
             $priority = end($priorityFilt);
             $notificationColor = $priority['color'];
         }
@@ -2535,7 +2560,7 @@ class CorrectiveMaintenanceController extends Controller
             'OTCO_USMO' => $idUser,
             'OTCO_FEMO' => $nowStr
         ]);
-            
+
         $paramsStr = file_get_contents('C:\inetpub\wwwroot\sam\storage\app\files\system-params.json');
         $paramsArr = json_decode($paramsStr, true);
         $orderPriorities = $paramsArr['order_priorities'];
@@ -2545,7 +2570,7 @@ class CorrectiveMaintenanceController extends Controller
         }, ARRAY_FILTER_USE_BOTH);
 
         $notificationColor = "rgb(35, 95, 172)";
-        if(count($priorityFilt) > 0){
+        if (count($priorityFilt) > 0) {
             $priority = end($priorityFilt);
             $notificationColor = $priority['color'];
         }
@@ -4304,14 +4329,14 @@ class CorrectiveMaintenanceController extends Controller
         }
 
         $staffArr = json_decode($form['staff'], true);
-        if(count($staffArr) == 0){
+        if (count($staffArr) == 0) {
             return $this->responseController->makeResponse(true, 'El arreglo del personal está vacío.', [], 400);
         }
 
         $staff = [];
-        foreach($staffArr as $key=>$specialty){
+        foreach ($staffArr as $key => $specialty) {
             $specialtyDec = $this->encryptionController->decrypt($specialty['SPECIALTY']);
-            if(!$specialtyDec){
+            if (!$specialtyDec) {
                 return $this->responseController->makeResponse(true, "El código en la posición $key del arreglo de especialidades no fue encriptado correctamente.", [], 400);
             }
 
@@ -4320,7 +4345,7 @@ class CorrectiveMaintenanceController extends Controller
                 ['GEES_COES', '=', $specialtyDec]
             ])->first();
 
-            if(is_null($specialtyObj)){
+            if (is_null($specialtyObj)) {
                 return $this->responseController->makeResponse(true, "El item en la posición $key del arreglo de especialidades no existe.", [], 404);
             }
 
@@ -4332,23 +4357,23 @@ class CorrectiveMaintenanceController extends Controller
 
         $staffStrFn = json_encode($staff);
         $resources = json_decode($form['resources'], true);
-        if(empty($resources)){
+        if (empty($resources)) {
             return $this->responseController->makeResponse(true, 'El JSON de recursos tiene un formato inválido.', [], 400);
         }
 
-        foreach($resources as $key=>$item){
-            if(!array_key_exists('ID', $item)){
+        foreach ($resources as $key => $item) {
+            if (!array_key_exists('ID', $item)) {
                 return $this->responseController->makeResponse(true, "No se pudo encontrar el ID del elemento en la posición $key del arreglo de recursos.", [], 400);
             }
 
-            if($item['ID'] != 'SH'){
+            if ($item['ID'] != 'SH') {
                 $idItemDec = $this->encryptionController->decrypt($item['ID']);
                 $resource = DB::table('S002V01TINST')->where([
                     ['INST_NULI', '=', $form['linea']],
                     ['INST_IDIS', '=', $idItemDec],
                 ])->first();
 
-                if(is_null($resource)){
+                if (is_null($resource)) {
                     return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de recursos no existe.", [], 404);
                 }
 
@@ -4418,7 +4443,7 @@ class CorrectiveMaintenanceController extends Controller
         }
 
         $idCounter = $this->encryptionController->decrypt($form['id_counter']);
-        if(!$idCounter){
+        if (!$idCounter) {
             return $this->responseController->makeResponse(true, 'El ID del contador relacionado no fue encriptado correctamente.', [], 400);
         }
 
@@ -4426,13 +4451,13 @@ class CorrectiveMaintenanceController extends Controller
             ['CONA_IDCO', '=', $idCounter],
             ['CONA_NULI', '=', $form['linea']]
         ])->first();
-        
-        if(is_null($counter)){
+
+        if (is_null($counter)) {
             return $this->responseController->makeResponse(true, 'El contador relacionado no existe.', [], 404);
         }
-        
+
         $idManagement = $this->encryptionController->decrypt($form['security_management']);
-        if(!$idManagement){
+        if (!$idManagement) {
             return $this->responseController->makeResponse(true, 'El ID de la gerencia de seguridad no está encriptado correctamente', [], 400);
         }
 
@@ -4441,12 +4466,12 @@ class CorrectiveMaintenanceController extends Controller
             ['GESE_IDGS', '=', $idManagement]
         ])->first();
 
-        if(is_null($management)){
+        if (is_null($management)) {
             return $this->responseController->makeResponse(true, 'La gerencia de seguridad seleccionada no está registrada.', [], 404);
         }
-        
+
         $idUserResponsible = $this->encryptionController->decrypt($form['id_responsible']);
-        if(!$idUserResponsible){
+        if (!$idUserResponsible) {
             return $this->responseController->makeResponse(true, 'El ID del usuario responsable no fue encriptado correctamente.', [], 400);
         }
 
@@ -4454,8 +4479,8 @@ class CorrectiveMaintenanceController extends Controller
             ['USUA_NULI', '=', $form['linea']],
             ['USUA_IDUS', '=', $idUserResponsible]
         ])->first();
-        
-        if(is_null($usrResponsible)){
+
+        if (is_null($usrResponsible)) {
             return $this->responseController->makeResponse(true, 'El usuario responsable de atender la solicitud no existe.', [], 404);
         }
 
@@ -4752,12 +4777,12 @@ class CorrectiveMaintenanceController extends Controller
             ['PMCO_NULI', '=', $line],
             ['PMCO_IDPM', '=', $idPlan]
         ])->join('S002V01TACTI', 'ACTI_CORE', '=', 'PMCO_CORE')
-        ->join('S002V01TCONA', 'CONA_IDCO', '=', 'PMCO_CORE')
-        ->join('S002V01TUSUA AS USRES', 'USRES.USUA_IDUS', '=', 'PMCO_IDUR')
-        ->join('S002V01TEQUI AS EQUI', 'EQUI.EQUI_COEQ', '=', 'PMCO_EQIN')
-        ->leftJoin('S002V01TEQUI AS LRUI', 'LRUI.EQUI_COEQ', '=', 'PMCO_LRUI')
-        ->join('S002V01TUSUA AS USREG', 'USREG.USUA_IDUS', '=', 'PMCO_USRE')
-        ->leftJoin('S002V01TUSUA AS USMOD', 'USMOD.USUA_IDUS', '=', 'PMCO_USMO')->first();
+            ->join('S002V01TCONA', 'CONA_IDCO', '=', 'PMCO_CORE')
+            ->join('S002V01TUSUA AS USRES', 'USRES.USUA_IDUS', '=', 'PMCO_IDUR')
+            ->join('S002V01TEQUI AS EQUI', 'EQUI.EQUI_COEQ', '=', 'PMCO_EQIN')
+            ->leftJoin('S002V01TEQUI AS LRUI', 'LRUI.EQUI_COEQ', '=', 'PMCO_LRUI')
+            ->join('S002V01TUSUA AS USREG', 'USREG.USUA_IDUS', '=', 'PMCO_USRE')
+            ->leftJoin('S002V01TUSUA AS USMOD', 'USMOD.USUA_IDUS', '=', 'PMCO_USMO')->first();
 
         if (is_null($plan)) {
             return $this->responseController->makeResponse(true, 'El plan solicitado no existe.', [], 404);
@@ -4768,7 +4793,7 @@ class CorrectiveMaintenanceController extends Controller
         $plan->CODIGO_EQUIPAMIENTO = $this->encryptionController->encrypt($plan->CODIGO_EQUIPAMIENTO);
         $plan->ID_EQUIPAMIENTO = $this->encryptionController->encrypt($plan->ID_EQUIPAMIENTO);
 
-        if(!is_null($plan->CODIGO_LRU)){
+        if (!is_null($plan->CODIGO_LRU)) {
             $plan->CODIGO_LRU = $this->encryptionController->encrypt($plan->CODIGO_LRU);
             $plan->ID_LRU = $this->encryptionController->encrypt($plan->ID_LRU);
         }
@@ -4804,15 +4829,15 @@ class CorrectiveMaintenanceController extends Controller
         $plan->GERENCIA_SEGURIDAD = $this->encryptionController->encrypt($plan->GERENCIA_SEGURIDAD);
 
         $resources = json_decode($plan->RECURSOS, true);
-        foreach($resources as $key=>$resource){
-            if($resource['ID'] != 'SH'){
+        foreach ($resources as $key => $resource) {
+            if ($resource['ID'] != 'SH') {
                 $resourceObj = DB::table('S002V01TINST')->where([
                     ['INST_NULI', '=', $line],
                     ['INST_IDIS', '=', $resource['ID']],
                 ])->join('S002V01TSTAR', 'STAR_IDIS', '=', 'INST_IDIS')
-                ->join('S002V01TUNID', 'UNID_IDUN', '=', 'STAR_IDUN')->first();
+                    ->join('S002V01TUNID', 'UNID_IDUN', '=', 'STAR_IDUN')->first();
 
-                if(!is_null($resourceObj)){
+                if (!is_null($resourceObj)) {
                     $resource['NAME'] = $resourceObj->INST_MODE;
                     $resource['UNIT'] = $resourceObj->UNID_NOMB;
                 }
@@ -7083,7 +7108,7 @@ class CorrectiveMaintenanceController extends Controller
                 "OTCO_FEMO" => $nowStr,
             ]);
         }
-            
+
         $paramsStr = file_get_contents('C:\inetpub\wwwroot\sam\storage\app\files\system-params.json');
         $paramsArr = json_decode($paramsStr, true);
         $orderPriorities = $paramsArr['order_priorities'];
@@ -7093,7 +7118,7 @@ class CorrectiveMaintenanceController extends Controller
         }, ARRAY_FILTER_USE_BOTH);
 
         $notificationColor = "rgb(35, 95, 172)";
-        if(count($priorityFilt) > 0){
+        if (count($priorityFilt) > 0) {
             $priority = end($priorityFilt);
             $notificationColor = $priority['color'];
         }