Prechádzať zdrojové kódy

Implementación de pedidos en orden de mantenimiento preventivo

JeanBenitez 1 rok pred
rodič
commit
8ef079d1fa

+ 4 - 4
sistema-mantenimiento-back/app/Http/Controllers/EquipmentManagementController.php

@@ -132,7 +132,7 @@ class EquipmentManagementController extends Controller{
             'custom_icon' => 'required|string|in:S,N',
             'icon_file' => 'required_if:custom_icon,=,S|string'
         ]);
- 
+
         if($validator->fails()){
             return $this->responseController->makeResponse(
                 true,
@@ -826,7 +826,7 @@ class EquipmentManagementController extends Controller{
             'custom_icon' => 'required|string|in:S,N',
             'icon_file' => 'required_if:custom_icon,=,S|string'
         ]);
- 
+
         if($validator->fails()){
             return $this->responseController->makeResponse(
                 true,
@@ -4987,7 +4987,7 @@ class EquipmentManagementController extends Controller{
             'equipment_code' => 'required|string',
             'equipment_arborescence' => 'required|string',
         ]);
- 
+
         if($validator->fails()){
             return $this->responseController->makeResponse(
                 true,
@@ -5361,7 +5361,7 @@ class EquipmentManagementController extends Controller{
             'file_type' => 'required|string|in:PDF,XLS',
             'file_data' => 'required|string',
         ]);
- 
+
         if($validator->fails()){
             return $this->responseController->makeResponse(
                 true,

+ 8 - 39
sistema-mantenimiento-back/app/Http/Controllers/OrderController.php

@@ -113,7 +113,6 @@ class OrderController extends Controller {
         }
         DB::beginTransaction();
         $requestData = $request->all();
-        $arrInfoRegistro = array();
         $arrToWorkflow = array();
 
         
@@ -145,10 +144,6 @@ class OrderController extends Controller {
             return $this->responseController->makeResponse(true, "ERR_ORDER_REG003: No se pudo registrar la orden de compra.", [], 401);
         }
 
-        $arrInfoRegistro['S002V01TORCO'][] = [
-            'ORCO_NUOR' => $idOrder,
-        ];
-
         $idMantPrev = null;
         $idMantCorr = null;
         if ($requestData['PROPOSITO'] === 'MANT-PREV' && !is_null($requestData['ID_MANT_PREV'])) {
@@ -180,15 +175,14 @@ class OrderController extends Controller {
 
 
         try {
-            $idHistoryOrder = DB::table('S002V01THIOR')
-                ->insertGetId([
-                    'HIOR_NULI' => $requestData['NUMERO_LINEA'],
-                    'HIOR_NUOR' => $idOrder,
-                    'HIOR_POEN' => 10,
-                    'HIOR_USRE' => $user,
-                    'HIOR_FERE' => $currentDate,
-                    'HIOR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
-                ]);
+            $idHistoryOrder = DB::table('S002V01THIOR')->insertGetId([
+                'HIOR_NULI' => $requestData['NUMERO_LINEA'],
+                'HIOR_NUOR' => $idOrder,
+                'HIOR_POEN' => 10,
+                'HIOR_USRE' => $user,
+                'HIOR_FERE' => $currentDate,
+                'HIOR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+            ]);
         } catch (\Throwable $th) {
             DB::rollBack();
             return $this->responseController->makeResponse(true, "ERR_ORDER_REG006: Ocurrió un error al insertar el registro en el historial.", $th->getMessage(), 500);
@@ -198,31 +192,6 @@ class OrderController extends Controller {
             return $this->responseController->makeResponse(true, "ERR_ORDER_REG007: No se pudo insertar el registro en el HISTORIAL.", [], 401);
         }
 
-        $arrInfoRegistro['S002V01THIOR'][] = [ 'HIOR_IDHO' => $idHistoryOrder, ];
-
-
-        /* $arrToWorkflow['NUMERO_SOLICITUD'] = $requestData['NUMERO_SOLICITUD'];
-        $arrToWorkflow['DESPACHO'] = $requestData['DESPACHO'];
-        $arrToWorkflow['PROPOSITO'] = $requestData['PROPOSITO'];
-        if (!is_null($requestData['ID_MANT_PREV'])) {
-            $arrToWorkflow['MANTENIMIENTO_PREVENTIVO'] = $requestData['ID_MANT_PREV'];
-        }
-        if (!is_null($requestData['ID_MANT_CORR'])) {
-            $arrToWorkflow['MANTENIMIENTO_CORRECTIVO'] = $requestData['ID_MANT_CORR'];
-        } */
-        // $strToWorkflow = json_encode($arrToWorkflow);
-        // $encToWorkflow = $this->encController->encrypt($strToWorkflow);
-
-
-        // $strInfoRegistro = json_encode($arrInfoRegistro);
-        // $encInfoRegistro = $this->encController->encrypt($strInfoRegistro);
-
-        /* $arrResponseRequestWorkflow = $this->processManagementController->registerRequestWorkflow(2, $encToWorkflow, $encInfoRegistro, $user, $requestData['NUMERO_LINEA']);
-        if ($arrResponseRequestWorkflow['error']) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, $arrResponseRequestWorkflow['msg'], $arrResponseRequestWorkflow['response'], 500);
-        } */
-
         DB::commit();
         return $this->responseController->makeResponse(false, "ÉXITO: Generación de Órdenes Exitosas");
 

+ 14 - 9
sistema-mantenimiento-back/app/Http/Controllers/PreventiveMaintenanceController.php

@@ -82,15 +82,7 @@ class PreventiveMaintenanceController extends Controller{
             return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
         }
 
-        //Pendiente revisar con stock
-        $resources = json_decode($form['resources'], true);
-        if(empty($resources)){
-            return $this->responseController->makeResponse(true, 'El JSON de recursos tiene un formato inválido.', [], 400);
-        }
-        $responseCheckItems = $this->requestLineController->checkItemsWorkOrder($resources, $form['linea']);
-        if ($responseCheckItems['error']) {
-            return $this->responseController->makeResponse(true, $responseCheckItems['msg'], $responseCheckItems['response'], 400);
-        }
+        
 
         $idActivator = $this->encryptionController->decrypt($form['activator']);
         if(!$idActivator){
@@ -287,6 +279,7 @@ class PreventiveMaintenanceController extends Controller{
         }
         $done = json_encode($attachedArrFn);
 
+        $orderCreated = null;
         if($form['exists'] == 'S'){
             $idOrder = $this->encryptionController->decrypt($form['id_order']);
             if(!$idOrder){
@@ -322,6 +315,7 @@ class PreventiveMaintenanceController extends Controller{
                 'OTPR_USMO' => $idUser,
                 'OTPR_FEMO' => $nowStr,
             ]);
+            $orderCreated = $idOrder;
         }else{
             $idOrder = DB::table('S002V01TOTPR')->insertGetId([
                 'OTPR_NULI' => $form['linea'],
@@ -341,6 +335,17 @@ class PreventiveMaintenanceController extends Controller{
                 'OTPR_USRE' => $idUser,
                 'OTPR_FERE' => $nowStr,
             ]);
+            $orderCreated = $idOrder;
+        }
+
+        //Pendiente revisar con stock
+        $resources = json_decode($form['resources'], true);
+        if(empty($resources)){
+            return $this->responseController->makeResponse(true, 'El JSON de recursos tiene un formato inválido.', [], 400);
+        }
+        $responseCheckItems = $this->requestLineController->checkItemsWorkOrder($resources, $orderCreated, $idUser, $form['linea']);
+        if ($responseCheckItems['error']) {
+            return $this->responseController->makeResponse(true, $responseCheckItems['msg'], $responseCheckItems['response'], 400);
         }
 
         $actions = DB::getQueryLog();

+ 137 - 18
sistema-mantenimiento-back/app/Http/Controllers/RequestLineController.php

@@ -952,35 +952,154 @@ class RequestLineController extends Controller
         return $this->responseController->makeResponse(false, "ÉXITO", $arrArtitleSelected);
     }
 
-    public function checkItemsWorkOrder ($resources, $line) {
+    public function checkItemsWorkOrder ($resources, $idOrder, $user, $line) {
         foreach ($resources as $resource) {
             
             if ($resource['REQ'] !== '-') {
-                $cant = intval($resource['REQ']);
-                $id = $resource['ID'];
+                goto next;
+            }
+
+            $id = $this->encController->decrypt($resource['REQ']);
+            if (is_null($id)) {
+                return $this->responseController->makeResponse(true, 'El ID de la herramienta o refacción no está encriptado correctamente.', [], 500);
+            }
+
+            try {
+                $amountStock = DB::table('S002V01TSTAR')
+                    ->where([
+                        ['STAR_IDIS', '=', $id],
+                        ['STAR_NULI', '=', $line],
+                        ['STAR_ESTA', '=', 'Activo'],
+                    ])
+                    ->count();
+            } catch (\Throwable $th) {
+                return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener la información del stock.', $th->getMessage(), 500);
+            }
 
+            $amountRequest = intval($resource['REQ']);
+            if ($amountRequest > $amountStock) {
+                goto next;
+            }
+
+            $adquisitionAmount = $amountRequest - $amountStock;
+
+            try {
+                $adquisition = (array) DB::table('S002V01TINST')
+                    ->where([
+                        ['INST_IDIS', '=', $id],
+                        ['INST_NULI', '=', $line],
+                        ['INST_ESTA', '=', 'Activo'],
+                    ])
+                    ->join('S002V01TINAR', 'INAR_CODI', '=', 'INST_COMO')
+                    ->join('S002V01TARTI', 'ARTI_IDAR', '=', 'INST_ARTI')
+                    ->join('S002V01TDEAR', 'DEAR_IDDE', '=', 'INAR_IDDE')
+                    ->first([
+                        'ARTI_IDAR',
+                        'DEAR_NUPR',
+                        'INAR_IDIN',
+                    ]);
+            } catch (\Throwable $th) {
+                return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener la información de la adquisición.', $th->getMessage(), 500);
+            }
+            if (is_null($adquisition) || empty($adquisition)) {
+                return $this->responseController->makeResponse(true, 'No se pudo obtener la información de la adquisición.', [], 500);
+            }
+
+            $now = $this->functionsController->now();
+            $currentDate = $now->toDateTimeString();
+
+            try {
+                $idLine = DB::table('S002V01TLINE')->insertGetId([
+                    'LINE_NUPR' => $adquisition['DEAR_NUPR'],
+                    'LINE_OTPR' => null,
+                    'LINE_OTCO' => $idOrder,
+                    'LINE_NULI' => $line,
+                    'LINE_ESTA' => 'En OC',
+                    'LINE_USRE' => $user,
+                    'LINE_FERE' => $currentDate,
+                    'LINE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
+                ]);
+            } catch (\Throwable $th) {
+                return $this->responseController->makeResponse(true, 'Ocurrió un error al registrar la línea de solicitud.', $th->getMessage(), 500);
+            }
+            if (is_null($idLine) || $idLine < 1) {
+                return $this->responseController->makeResponse(true, 'No se pudo registrar la línea de solicitud.', [], 500);
+            }
+
+            for ($i=1; $i <= $adquisitionAmount; $i++) {
                 try {
-                    $items = DB::table('S002V01TSTAR')
-                        ->where([
-                            ['STAR_NULI', '=', $line],
-                            ['STAR_IDIS', '=', $id],
-                        ])
-                        ->join('S002V01TUNID', 'UNID_IDUN', '=', 'STAR_IDUN')
-                        ->get([
-                            'UNID_NOMB AS UNIT',
-                            'STAR_CONS AS TYPE',
-                        ]);
-                    $items = json_decode(json_encode($items), true);
+                    $validateInsert = DB::table('S002V01TARSE')->insert([
+                        'ARSE_IDAS' => $i,
+                        'ARSE_NULI' => $line,
+                        'ARSE_IDLI' => $idLine,
+                        'ARSE_IDAR' => $adquisition['ARTI_IDAR'],
+                        'ARSE_NUPR' => $adquisition['DEAR_NUPR'],
+                        'ARSE_IDIN' => $adquisition['INAR_IDIN'],
+                        'ARSE_USRE' => $user,
+                        'ARSE_FERE' => $currentDate,
+                        'ARSE_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                    ]);
                 } catch (\Throwable $th) {
-                    return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los datos de las herramientas y refacciones.', $th->getMessage(), 500);
+                    return $this->responseController->makeResponse(true, 'Ocurrió un error al registrar los artículos en la línea de solicitud.', $th->getMessage(), 500);
                 }
 
-                if ($cant > count($items)) {
-                    
-                }
+                if (is_null($validateInsert) || !$validateInsert) {
+                    return $this->responseController->makeResponse(true, 'No se pudo registrar los artículos en la línea de solicitud.', [], 500);
+                }    
+            }
+
+            $typeOrder = rand(0, 1) === 0 ? 'ASC' : 'DESC';
+
+            try {
+                $dispatch = (array) DB::table('S002V01TDESP')
+                    ->where([
+                        ['DESP_NULI', '=', $line],
+                        ['DESP_ESTA', '=', 'Activo'],
+                    ])
+                    ->orderBy('DESP_IDDE', $typeOrder)
+                    ->first([
+                        'DESP_IDDE'
+                    ]);
+            } catch (\Throwable $th) {
+                return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener la información del despacho.', [], 500);
+            }
+            if (is_null($dispatch) || empty($dispatch)) {
+                return $this->responseController->makeResponse(true, 'No se pudo obtener la información del despacho.', [], 500);
+            }
 
+            try {
+                $idOrder = DB::table('S002V01TORCO')->insertGetId([
+                    'ORCO_NULI' => $line,
+                    'ORCO_IDLI' => $idLine,
+                    'ORCO_IDDE' => $dispatch['DESP_IDDE'],
+                    'ORCO_USRE' => $user,
+                    'ORCO_FERE' => $currentDate,
+                    'ORCO_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                ]);
+            } catch (\Throwable $th) {
+                return $this->responseController->makeResponse(true, 'Ocurrió un error al registrar la orden de compra.', $th->getMessage(), 500);
+            }
+            if (is_null($idOrder) || $idOrder < 1) {
+                return $this->responseController->makeResponse(true, 'No se pudo registrar la línea de solicitud.', [], 500);
             }
 
+            try {
+                $validateInsert = DB::table('S002V01THIOR')->insert([
+                    'HIOR_NULI' => $idLine,
+                    'HIOR_NUOR' => $idOrder,
+                    'HIOR_POEN' => 10,
+                    'HIOR_USRE' => $user,
+                    'HIOR_FERE' => $currentDate,
+                    'HIOR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                ]);
+            } catch (\Throwable $th) {
+                return $this->responseController->makeResponse(true, 'Ocurrió un error al registrar el historial de la orden de compra.', $th->getMessage(), 500);
+            }
+            if (is_null($validateInsert) || !$validateInsert) {
+                return $this->responseController->makeResponse(true, 'No se pudo registrar el historial de la orden de compra.', [], 500);
+            }
+            
+            next:
         }
     }
 }

+ 0 - 16
sistema-mantenimiento-back/app/Http/Controllers/StockController.php

@@ -6063,22 +6063,6 @@ class StockController extends Controller
         return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", [ 'HERRAMIENTAS' => $arrTools, 'REFACCIONES' => $arrSpares ]);
     }
 
-    public function getSpares ($user, $line) {
-        $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
-        if ($arrResponseCheckUser['error']) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
-        }
 
-        /* try {
-            $arrSpares = DB::table('S002V01TINST')
-                ->where([
-                    'STAR_NULI', '', $line,
-                ])
-        } catch (\Throwable $th) {
-            //throw $th;
-        } */
-
-    }
 
 }