Forráskód Böngészése

correciones de KIOR

EmilianoOrtiz 2 hónapja
szülő
commit
d6d16cd366

+ 86 - 59
sistema-mantenimiento-back/app/Http/Controllers/TemplatesManagementController.php

@@ -161,7 +161,7 @@ public function validateAndProcessExcelTemplate(Request $request) {
         }
         
         // **LOG FINAL: Verificar qué códigos se van a insertar**
-        error_log("📊 [Final Insert] Resumen de códigos a insertar:");
+        error_log("[Final Insert] Resumen de códigos a insertar:");
         foreach($processedData as $index => $data) {
             error_log("   [{$index}] PCEQ_CPGE: '" . $data['PCEQ_CPGE'] . "'");
             if($index >= 4) { // Mostrar solo los primeros 5
@@ -320,7 +320,7 @@ private function extractAcronymMappings($spreadsheet) {
                     'PCEQ_FVAR' => $fechaVencimiento
                 ];
                 
-                error_log("📋 [EQUIPAMIENTO] {$acronimoEquipo}/{$acronimoModelo}: CARA='{$caracter}', COBA='{$codigoBarras}'");
+                error_log("[EQUIPAMIENTO] {$acronimoEquipo}/{$acronimoModelo}: CARA='{$caracter}', COBA='{$codigoBarras}'");
             }
             
             if (!empty($acronimoModelo) && !empty($modeloCompleto)) {
@@ -371,7 +371,7 @@ private function extractAcronymMappings($spreadsheet) {
                     'PCEQ_FVAR' => $fechaVencimiento
                 ];
                 
-                error_log("📋 [LRU] {$acronimoEquipo}/{$acronimoModelo}: CARA='{$caracter}', COBA='{$codigoBarras}'");
+                error_log("[LRU] {$acronimoEquipo}/{$acronimoModelo}: CARA='{$caracter}', COBA='{$codigoBarras}'");
             }
             
             if (!empty($acronimoModelo) && !empty($modeloCompleto)) {
@@ -791,9 +791,9 @@ private function extractRowData($worksheet, $row, $fieldMapping, $sheetName) {
         $rowData['PCEQ_CPGE'] = trim($frontendCode);
         
         // Log para debug
-        error_log("📋 [Frontend Code] {$sheetName} Fila {$row}: Usando código del frontend: '{$frontendCode}'");
+        error_log("[Frontend Code] {$sheetName} Fila {$row}: Usando código del frontend: '{$frontendCode}'");
     } else {
-        error_log("⚠️ [Frontend Code] {$sheetName} Fila {$row}: No se encontró código generado por frontend");
+        error_log("[Frontend Code] {$sheetName} Fila {$row}: No se encontró código generado por frontend");
         
         // Como fallback, generar código básico pero con advertencia
         $rowData['PCEQ_CPGE'] = $this->generateFallbackCode($rowData, $sheetName, $row);
@@ -1021,7 +1021,7 @@ private function prepareEquipmentData($rowData, $linea, $idUser, $sheetName) {
         $codigoEquivalente = $rowData['PCEQ_OTCO_HIJO'] ?? '';
         $fechaVencimiento = $this->noDate($rowData['PCEQ_FVAR_HIJO'] ?? null);
         
-        error_log("👶 [Equipment Data] HIJO - Usando: CARA='{$caracter}', COBA='{$codigoBarras}'");
+        error_log("[Equipment Data] HIJO - Usando: CARA='{$caracter}', COBA='{$codigoBarras}'");
     } else {
         // Para PADRE: usar los campos normales
         $caracter = $this->normalizeCaracter($rowData['PCEQ_CARA'] ?? null);
@@ -1030,7 +1030,7 @@ private function prepareEquipmentData($rowData, $linea, $idUser, $sheetName) {
         $codigoEquivalente = $rowData['PCEQ_OTCO'] ?? '';
         $fechaVencimiento = $this->noDate($rowData['PCEQ_FVAR'] ?? null);
         
-        error_log("👨 [Equipment Data] PADRE - Usando: CARA='{$caracter}', COBA='{$codigoBarras}'");
+        error_log("[Equipment Data] PADRE - Usando: CARA='{$caracter}', COBA='{$codigoBarras}'");
     }
     
     // Procesar otras fechas
@@ -1104,9 +1104,9 @@ private function prepareEquipmentData($rowData, $linea, $idUser, $sheetName) {
 
     // Validación final del código
     if (empty($equipmentData['PCEQ_CPGE'])) {
-        error_log("⚠️ [Equipment Data] ADVERTENCIA: PCEQ_CPGE está vacío para fila de {$sheetName}");
+        error_log("[Equipment Data] ADVERTENCIA: PCEQ_CPGE está vacío para fila de {$sheetName}");
         $equipmentData['PCEQ_CPGE'] = $this->generateFallbackCode($rowData, $sheetName, 0);
-        error_log("  [Equipment Data] Usando código de respaldo: " . $equipmentData['PCEQ_CPGE']);
+        error_log("[Equipment Data] Usando código de respaldo: " . $equipmentData['PCEQ_CPGE']);
     }
 
     // Lógica de nombres según jerarquía
@@ -1351,7 +1351,7 @@ private function processWorksheet($worksheet, $sheetConfig, $sheetName, $linea,
         
         // **VALIDACIÓN CRÍTICA: Verificar que el código del frontend esté presente**
         if (empty($rowData['PCEQ_CPGE']) || strlen(trim($rowData['PCEQ_CPGE'])) < 3) {
-            error_log("⚠️ [Process Worksheet] {$sheetName} Fila {$row}: Código PCEQ_CPGE inválido: '" . ($rowData['PCEQ_CPGE'] ?? 'NULL') . "'");
+            error_log("[Process Worksheet] {$sheetName} Fila {$row}: Código PCEQ_CPGE inválido: '" . ($rowData['PCEQ_CPGE'] ?? 'NULL') . "'");
             // Continuar procesamiento pero con advertencia
         } else {
             error_log("  [Process Worksheet] {$sheetName} Fila {$row}: Código PCEQ_CPGE válido: '" . $rowData['PCEQ_CPGE'] . "'");
@@ -1371,7 +1371,7 @@ private function processWorksheet($worksheet, $sheetConfig, $sheetName, $linea,
         $equipmentData = $this->prepareEquipmentData($rowData, $linea, $idUser, $sheetName);
         
         // **LOG FINAL: Confirmar qué código se va a insertar**
-        error_log("📝 [Final Data] {$sheetName} Fila {$row}: PCEQ_CPGE final = '" . $equipmentData['PCEQ_CPGE'] . "'");
+        error_log("[Final Data] {$sheetName} Fila {$row}: PCEQ_CPGE final = '" . $equipmentData['PCEQ_CPGE'] . "'");
         
         $processedData[] = $equipmentData;
         $count++;
@@ -1561,7 +1561,7 @@ private function resolveEquipmentNames(&$rowData, $sheetName, $cargaMap, $lruMap
             $rowData['PCEQ_OTCO'] = $equipmentDetails['PCEQ_OTCO'] ?? '';
             
         } else {
-            error_log("⚠️ [Equipment Details] No se encontraron detalles para Padre - {$acronimoTipo}/{$acronimoModelo}");
+            error_log("[Equipment Details] No se encontraron detalles para Padre - {$acronimoTipo}/{$acronimoModelo}");
         }
     }
 
@@ -1590,7 +1590,7 @@ private function resolveEquipmentNames(&$rowData, $sheetName, $cargaMap, $lruMap
             
             error_log("  [Equipment Details] Hijo - {$acronimoTipoHijo}/{$acronimoModeloHijo}: CARA='{$equipmentDetailsHijo['PCEQ_CARA']}', COBA='{$equipmentDetailsHijo['PCEQ_COBA']}'");
         } else {
-            error_log("⚠️ [Equipment Details] No se encontraron detalles para Hijo - {$acronimoTipoHijo}/{$acronimoModeloHijo}");
+            error_log("[Equipment Details] No se encontraron detalles para Hijo - {$acronimoTipoHijo}/{$acronimoModeloHijo}");
         }
     }
 }
@@ -1803,7 +1803,8 @@ public function transferEquipmentsToFinal($linea, $idUser) {
                     'EQUI_MODE' => $tempEquip->PCEQ_MOEQ,
                     'EQUI_IDEQ' => $newEquiId,
                     'EQUI_ESEQ' => $tempEquip->PCEQ_ESEQ,
-                    'EQUI_COEQ' => $tempEquip->PCEQ_CPGE, // Código generado
+                    'EQUI_COEQ' => $tempEquip->PCEQ_CPGE, // Era el problema principal del CASO 3
+                    
                     'EQUI_JERA' => $tempEquip->PCEQ_JERA,
                     'EQUI_EQPA' => $tempEquip->PCEQ_EQPA,
                     'EQUI_TICO' => $tempEquip->PCEQ_TICO,
@@ -1814,54 +1815,58 @@ public function transferEquipmentsToFinal($linea, $idUser) {
                     'EQUI_OCOR' => $tempEquip->PCEQ_OCOR,
                     'EQUI_ELOR' => $tempEquip->PCEQ_ELOR,
                     'EQUI_COOR' => $tempEquip->PCEQ_COOR,
-                    'EQUI_PCOR' => $tempEquip->PCEQ_PCOR,
+                    'EQUI_PCOR' => $tempEquip->PCEQ_PCOR ?? null,
                     
-                    // Campos de almacén (CASO 7)
-                    'EQUI_ALMA' => $tempEquip->PCEQ_ALMA,
-                    'EQUI_AREA' => $tempEquip->PCEQ_AREA,
-                    'EQUI_NIVE' => $tempEquip->PCEQ_NIVE,
-                    'EQUI_ZONA' => $tempEquip->PCEQ_ZONA,
+                    // Campos de almacén (CASO 7) - verificar si existen
+                    'EQUI_ALMA' => $tempEquip->PCEQ_ALMA ?? null,
+                    'EQUI_AREA' => $tempEquip->PCEQ_AREA ?? null,
+                    'EQUI_NIVE' => $tempEquip->PCEQ_NIVE ?? null,
+                    'EQUI_ZONA' => $tempEquip->PCEQ_ZONA ?? null,
                     
-                    // Campos PCC
-                    'EQUI_IPCC' => $tempEquip->PCEQ_IPCC,
-                    'EQUI_PPCC' => $tempEquip->PCEQ_PPCC,
+                    // Campos PCC - verificar si existen
+                    'EQUI_IPCC' => $tempEquip->PCEQ_IPCC ?? null,
+                    'EQUI_PPCC' => $tempEquip->PCEQ_PPCC ?? null,
                     
-                    // Campos adicionales origen
-                    'EQUI_KIOR' => is_numeric($tempEquip->PCEQ_KIOR) ? (float)$tempEquip->PCEQ_KIOR : null,
-                    'EQUI_SEOR' => $tempEquip->PCEQ_SEOR,
-                    'EQUI_ARTR' => $tempEquip->PCEQ_ARTR,
-                    'EQUI_TCOR' => $tempEquip->PCEQ_TCOR,
-                    'EQUI_CEOR' => $tempEquip->PCEQ_CEOR,
+                    'EQUI_KIOR' => $this->parseVarcharValue($tempEquip->PCEQ_KIOR),
+                    'EQUI_SEOR' => $tempEquip->PCEQ_SEOR ?? null,
+                    'EQUI_ARTR' => $tempEquip->PCEQ_ARTR ?? null,
+                    'EQUI_TCOR' => $tempEquip->PCEQ_TCOR ?? null,
+                    'EQUI_CEOR' => $tempEquip->PCEQ_CEOR ?? null,
                     
                     // Campos de ubicación destino
-                    'EQUI_UBDE' => $tempEquip->PCEQ_UBDE,
-                    'EQUI_NIDE' => $tempEquip->PCEQ_NIDE,
-                    'EQUI_OCDE' => $tempEquip->PCEQ_OCDE,
-                    'EQUI_ELDE' => $tempEquip->PCEQ_ELDE,
-                    'EQUI_CODE' => $tempEquip->PCEQ_CODE,
-                    'EQUI_PCDE' => $tempEquip->PCEQ_PCDE,
-                    'EQUI_KIDE' => is_numeric($tempEquip->PCEQ_KIDE) ? (float)$tempEquip->PCEQ_KIDE : null,
-                    'EQUI_SEDE' => $tempEquip->PCEQ_SEDE,
-                    'EQUI_TCDE' => $tempEquip->PCEQ_TCDE,
-                    'EQUI_CEDE' => $tempEquip->PCEQ_CEDE,
+                    'EQUI_UBDE' => $tempEquip->PCEQ_UBDE ?? null,
+                    'EQUI_NIDE' => $tempEquip->PCEQ_NIDE ?? null,
+                    'EQUI_OCDE' => $tempEquip->PCEQ_OCDE ?? null,
+                    'EQUI_ELDE' => $tempEquip->PCEQ_ELDE ?? null,
+                    'EQUI_CODE' => $tempEquip->PCEQ_CODE ?? null,
+                    'EQUI_PCDE' => $tempEquip->PCEQ_PCDE ?? null,
+                    
+                    'EQUI_KIDE' => $this->parseVarcharValue($tempEquip->PCEQ_KIDE),
+                    'EQUI_SEDE' => $tempEquip->PCEQ_SEDE ?? null,
+                    'EQUI_TCDE' => $tempEquip->PCEQ_TCDE ?? null,
+                    'EQUI_CEDE' => $tempEquip->PCEQ_CEDE ?? null,
                     
                     // Campos de fechas y proveedor
-                    'EQUI_CRSE' => $tempEquip->PCEQ_CRSE,
+                    'EQUI_CRSE' => $tempEquip->PCEQ_CRSE ?? null,
                     'EQUI_FEAD' => $tempEquip->PCEQ_FEAD,
                     'EQUI_FIGA' => $tempEquip->PCEQ_FIGA,
                     'EQUI_FTGA' => $tempEquip->PCEQ_FTGA,
-                    'EQUI_PREQ' => $tempEquip->PCEQ_PREQ,
-                    'EQUI_NUSE' => $tempEquip->PCEQ_NUSE,
+                    'EQUI_PREQ' => $tempEquip->PCEQ_PREQ ?? null,
+                    'EQUI_NUSE' => $tempEquip->PCEQ_NUSE ?? null,
+                    
+                    // 'EQUI_COBA' => $tempEquip->PCEQ_COBA ?? null, // Código de barras
+                    // 'EQUI_CARA' => $tempEquip->PCEQ_CARA ?? null, // Carácter
+                    // 'EQUI_FVAR' => $tempEquip->PCEQ_FVAR ?? null, // Fecha vencimiento
                     
                     // Campos de software
-                    'EQUI_DESO' => $tempEquip->PCEQ_DESO,
-                    'EQUI_VESO' => $tempEquip->PCEQ_VESO,
+                    'EQUI_DESO' => $tempEquip->PCEQ_DESO ?? null,
+                    'EQUI_VESO' => $tempEquip->PCEQ_VESO ?? null,
                     
                     // Campos JSON
                     'EQUI_HICO' => json_encode([]), // Historial de códigos (nuevo campo)
-                    'EQUI_GAIM' => $tempEquip->PCEQ_GAIM,
-                    'EQUI_DORE' => $tempEquip->PCEQ_DORE,
-                    'EQUI_OTCO' => $tempEquip->PCEQ_OTCO,
+                    'EQUI_GAIM' => $tempEquip->PCEQ_GAIM ?? json_encode([]),
+                    'EQUI_DORE' => $tempEquip->PCEQ_DORE ?? json_encode([]),
+                    'EQUI_OTCO' => $tempEquip->PCEQ_OTCO ?? json_encode([]),
                     
                     // Estados y usuarios
                     'EQUI_ESFU' => 'EF', // Estado funcionamiento por defecto
@@ -1871,6 +1876,12 @@ public function transferEquipmentsToFinal($linea, $idUser) {
                     'EQUI_FEMO' => null
                 ];
                 
+                // Debug para verificar campos críticos
+                error_log(" [Transfer Debug] PCEQ_IDPR: {$tempEquip->PCEQ_IDPR}");
+                error_log("   - PCEQ_CPGE: '{$tempEquip->PCEQ_CPGE}' -> EQUI_COEQ");
+                error_log("   - PCEQ_KIOR: '{$tempEquip->PCEQ_KIOR}' -> EQUI_KIOR: " . ($finalEquipmentData['EQUI_KIOR'] ?? 'NULL'));
+                error_log("   - PCEQ_KIDE: '{$tempEquip->PCEQ_KIDE}' -> EQUI_KIDE: " . ($finalEquipmentData['EQUI_KIDE'] ?? 'NULL'));
+                
                 // Insertar en tabla final
                 DB::table('S002V01TEQUI')->insert($finalEquipmentData);
                 
@@ -1880,14 +1891,13 @@ public function transferEquipmentsToFinal($linea, $idUser) {
                     ->where('PCEQ_NULI', $linea)
                     ->update([
                         'PCEQ_ESRE' => 'Aprobado',
-                        'PCEQ_COAC' => 'Transferido automáticamente a tabla final',
                         'PCEQ_USMO' => $idUser,
                         'PCEQ_FEMO' => now()->format('Y-m-d H:i:s')
                     ]);
                 
                 $transferredCount++;
                 
-                error_log("  [Transfer] Equipo transferido: PCEQ_IDPR={$tempEquip->PCEQ_IDPR} -> EQUI_IDEQ={$newEquiId}");
+                error_log("[Transfer] Equipo transferido: PCEQ_IDPR={$tempEquip->PCEQ_IDPR} -> EQUI_IDEQ={$newEquiId}");
                 
             } catch (Exception $e) {
                 $errors[] = "Error transfiriendo equipo PCEQ_IDPR {$tempEquip->PCEQ_IDPR}: " . $e->getMessage();
@@ -1918,6 +1928,33 @@ public function transferEquipmentsToFinal($linea, $idUser) {
     }
 }
 
+private function parseVarcharValue($value) {
+    if ($value === null || $value === '') {
+        return null;
+    }
+    
+    return trim((string)$value);
+}
+
+
+private function parseNumericValue($value) {
+    if ($value === null || $value === '') {
+        return null;
+    }
+    
+    // Si es string que representa un número
+    if (is_string($value) && is_numeric($value)) {
+        return (float)$value;
+    }
+    
+    // Si ya es numérico
+    if (is_numeric($value)) {
+        return (float)$value;
+    }
+    
+    return null;
+}
+
 
 private function generateNewEquiId($linea) {
     $maxId = DB::table('S002V01TEQUI')
@@ -1997,16 +2034,6 @@ public function transferEquipmentsToFinalTable(Request $request) {
 
 
 
-
-
-
-
-
-
-
-//Configuración de mapeo del EXCEL ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
-
    
 }