|
|
@@ -6,11 +6,17 @@ use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
use Illuminate\Support\Carbon;
|
|
|
+use Exception;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
class TemplatesManagementController extends Controller {
|
|
|
|
|
|
private $responseController;
|
|
|
@@ -267,7 +273,7 @@ private function extractAcronymMappings($spreadsheet) {
|
|
|
$cell = $worksheet->getCell($column . $row);
|
|
|
return trim($cell->getFormattedValue());
|
|
|
} catch (\Exception $e) {
|
|
|
- \Log::error("Error leyendo celda $column$row: " . $e->getMessage());
|
|
|
+ // \Log::error("Error leyendo celda $column$row: " . $e->getMessage());
|
|
|
return '';
|
|
|
}
|
|
|
}
|
|
|
@@ -662,15 +668,34 @@ private function extractRowData($worksheet, $row, $fieldMapping, $sheetName) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // RESTAURAR: Manejar concatenaciones especiales para coordenadas
|
|
|
- if ($sheetName === 'CASO 1' || $sheetName === 'CASO 2') {
|
|
|
- // Concatenar coordenadas para CASO 1 y 2
|
|
|
+ // **CAMBIO CLAVE 5: Capturar el código completo generado por el frontend**
|
|
|
+ if (in_array($sheetName, ['CASO 1', 'CASO 2'])) {
|
|
|
+ // Para CASO 1 y 2, el código está en columna AH
|
|
|
+ $frontendCode = $worksheet->getCell('AH' . $row)->getCalculatedValue();
|
|
|
+ if (!empty($frontendCode)) {
|
|
|
+ $rowData['PCEQ_CPGE'] = trim($frontendCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Manejar concatenaciones especiales para coordenadas
|
|
|
$coordL = $this->getCellValue($worksheet, 'L', $row);
|
|
|
$coordM = $this->getCellValue($worksheet, 'M', $row);
|
|
|
$coordN = $this->getCellValue($worksheet, 'N', $row);
|
|
|
$rowData['PCEQ_COOR'] = $coordL . $coordM . $coordN;
|
|
|
}
|
|
|
+ elseif ($sheetName === 'CASO 3') {
|
|
|
+ // Para CASO 3, el código está en columna AP
|
|
|
+ $frontendCode = $worksheet->getCell('AP' . $row)->getCalculatedValue();
|
|
|
+ if (!empty($frontendCode)) {
|
|
|
+ $rowData['PCEQ_CPGE'] = trim($frontendCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
elseif ($sheetName === 'CASO 4') {
|
|
|
+ // Para CASO 4, el código está en columna AX
|
|
|
+ $frontendCode = $worksheet->getCell('AX' . $row)->getCalculatedValue();
|
|
|
+ if (!empty($frontendCode)) {
|
|
|
+ $rowData['PCEQ_CPGE'] = trim($frontendCode);
|
|
|
+ }
|
|
|
+
|
|
|
// Concatenar coordenadas para CASO 4 (origen y destino)
|
|
|
$coordN = $this->getCellValue($worksheet, 'N', $row);
|
|
|
$coordO = $this->getCellValue($worksheet, 'O', $row);
|
|
|
@@ -682,10 +707,44 @@ private function extractRowData($worksheet, $row, $fieldMapping, $sheetName) {
|
|
|
$coordAD = $this->getCellValue($worksheet, 'AD', $row);
|
|
|
$rowData['PCEQ_COOR_DESTINO'] = $coordAB . $coordAC . $coordAD;
|
|
|
}
|
|
|
+ elseif (in_array($sheetName, ['CASO 5', 'CASO 6'])) {
|
|
|
+ // Para CASO 5 y 6, el código está en columna AF
|
|
|
+ $frontendCode = $worksheet->getCell('AF' . $row)->getCalculatedValue();
|
|
|
+ if (!empty($frontendCode)) {
|
|
|
+ $rowData['PCEQ_CPGE'] = trim($frontendCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ $rowData['PCEQ_TIEQ_ACRONIMO'] = '';
|
|
|
+ $rowData['PCEQ_MOEQ_ACRONIMO'] = '';
|
|
|
+ $rowData['PCEQ_TIEQ_HIJO_ACRONIMO'] = '';
|
|
|
+ $rowData['PCEQ_MOEQ_HIJO_ACRONIMO'] = '';
|
|
|
+
|
|
|
return $rowData;
|
|
|
}
|
|
|
|
|
|
+private function logCodeComparison($frontendCode, $backendCode, $sheetName, $row) {
|
|
|
+ if ($frontendCode !== $backendCode) {
|
|
|
+ // \Log::info("Comparación de códigos en $sheetName fila $row:");
|
|
|
+ // \Log::info("Frontend: $frontendCode");
|
|
|
+ // \Log::info("Backend: $backendCode");
|
|
|
+
|
|
|
+ // Analizar diferencias
|
|
|
+ $frontParts = explode('.', $frontendCode);
|
|
|
+ $backParts = explode('.', $backendCode);
|
|
|
+
|
|
|
+ for ($i = 0; $i < max(count($frontParts), count($backParts)); $i++) {
|
|
|
+ $front = $frontParts[$i] ?? '[MISSING]';
|
|
|
+ $back = $backParts[$i] ?? '[MISSING]';
|
|
|
+ if ($front !== $back) {
|
|
|
+ // \Log::info("Diferencia en parte $i: Frontend='$front' vs Backend='$back'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private function isEmptyRow($rowData) {
|
|
|
$requiredFields = ['PCEQ_TIEQ', 'PCEQ_MOEQ']; // Campos mínimos
|
|
|
|
|
|
@@ -775,73 +834,75 @@ private function noDate($value)
|
|
|
}
|
|
|
|
|
|
|
|
|
- private function prepareEquipmentData($rowData, $linea, $idUser, $sheetName) {
|
|
|
- $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
|
|
|
-
|
|
|
- $caracter = $this->normalizeCaracter($rowData['PCEQ_CARA'] ?? null);
|
|
|
- $fechaInicioGarantia = $this->parseDate($rowData['PCEQ_FIGA'] ?? null);
|
|
|
- $fechaFinGarantia = $this->parseDate($rowData['PCEQ_FTGA'] ?? null);
|
|
|
- $fechaAdquisicion = $this->parseDate($rowData['PCEQ_FEAD'] ?? null);
|
|
|
- $fechaVencimiento = $this->noDate($rowData['PCEQ_FVAR'] ?? null);
|
|
|
-
|
|
|
- $equipmentData = [
|
|
|
- 'PCEQ_FIGA' => $fechaInicioGarantia ?? now()->format('Y-m-d'),
|
|
|
- 'PCEQ_FEAD' => $fechaAdquisicion ?? now()->format('Y-m-d'),
|
|
|
- 'PCEQ_FTGA' => $fechaFinGarantia ?? now()->format('Y-m-d'),
|
|
|
- 'PCEQ_OTCO' => '[]',
|
|
|
- 'PCEQ_NULI' => $linea,
|
|
|
- 'PCEQ_UBOR' => $rowData['PCEQ_UBOR'] ?? '',
|
|
|
- 'PCEQ_NIOR' => $rowData['PCEQ_NIOR'] ?? '',
|
|
|
- 'PCEQ_OCOR' => $rowData['PCEQ_OCOR'] ?? '',
|
|
|
- 'PCEQ_ELOR' => $rowData['PCEQ_ELOR'] ?? '',
|
|
|
- 'PCEQ_COOR' => $rowData['PCEQ_COOR'] ?? '',
|
|
|
- 'PCEQ_FAMI' => $rowData['PCEQ_FAMI'] ?? '',
|
|
|
- 'PCEQ_SUBF' => $rowData['PCEQ_SUBF'] ?? '',
|
|
|
- 'PCEQ_ESEQ' => $rowData['PCEQ_ESEQ'] ?? 'A',
|
|
|
- 'PCEQ_TIEQ' => $rowData['PCEQ_TIEQ'] ?? '',
|
|
|
- 'PCEQ_MOEQ' => $rowData['PCEQ_MOEQ'] ?? '',
|
|
|
- 'PCEQ_CPGE' => $rowData['PCEQ_CPGE'] ?? '',
|
|
|
- 'PCEQ_TICO' => $this->getCodeTypeFromSheet($sheetName),
|
|
|
- 'PCEQ_JERA' => 'Padre',
|
|
|
- 'PCEQ_EQPA' => null,
|
|
|
- 'PCEQ_NUSE' => $rowData['PCEQ_NUSE'] ?? '',
|
|
|
- 'PCEQ_COBA' => $rowData['PCEQ_COBA'] ?? '',
|
|
|
- 'PCEQ_CARA' => $caracter,
|
|
|
- 'PCEQ_PREQ' => $rowData['PCEQ_PREQ'] ?? 0,
|
|
|
- 'PCEQ_FVAR' => $fechaVencimiento ?? now()->format('Y-m-d'),
|
|
|
- 'PCEQ_GAIM' => json_encode([]),
|
|
|
- 'PCEQ_DORE' => json_encode([]),
|
|
|
- 'PCEQ_ESRE' => 'Revisión',
|
|
|
- 'PCEQ_USRE' => $idUser,
|
|
|
- 'PCEQ_FERE' => $nowStr,
|
|
|
- 'PCEQ_IDPR' => $this->generateNumericUniqueId($linea)
|
|
|
- ];
|
|
|
+private function prepareEquipmentData($rowData, $linea, $idUser, $sheetName) {
|
|
|
+ $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
|
|
|
+
|
|
|
+ $caracter = $this->normalizeCaracter($rowData['PCEQ_CARA'] ?? null);
|
|
|
+ $fechaInicioGarantia = $this->parseDate($rowData['PCEQ_FIGA'] ?? null);
|
|
|
+ $fechaFinGarantia = $this->parseDate($rowData['PCEQ_FTGA'] ?? null);
|
|
|
+ $fechaAdquisicion = $this->parseDate($rowData['PCEQ_FEAD'] ?? null);
|
|
|
+ $fechaVencimiento = $this->noDate($rowData['PCEQ_FVAR'] ?? null);
|
|
|
+
|
|
|
+ $equipmentData = [
|
|
|
+ 'PCEQ_FIGA' => $fechaInicioGarantia ?? now()->format('Y-m-d'),
|
|
|
+ 'PCEQ_FEAD' => $fechaAdquisicion ?? now()->format('Y-m-d'),
|
|
|
+ 'PCEQ_FTGA' => $fechaFinGarantia ?? now()->format('Y-m-d'),
|
|
|
+ 'PCEQ_OTCO' => '[]',
|
|
|
+ 'PCEQ_NULI' => $linea,
|
|
|
+ 'PCEQ_UBOR' => $rowData['PCEQ_UBOR'] ?? '',
|
|
|
+ 'PCEQ_NIOR' => $rowData['PCEQ_NIOR'] ?? '',
|
|
|
+ 'PCEQ_OCOR' => $rowData['PCEQ_OCOR'] ?? '',
|
|
|
+ 'PCEQ_ELOR' => $rowData['PCEQ_ELOR'] ?? '',
|
|
|
+ 'PCEQ_COOR' => $rowData['PCEQ_COOR'] ?? '',
|
|
|
+ 'PCEQ_FAMI' => $rowData['PCEQ_FAMI'] ?? '',
|
|
|
+ 'PCEQ_SUBF' => $rowData['PCEQ_SUBF'] ?? '',
|
|
|
+ 'PCEQ_ESEQ' => $rowData['PCEQ_ESEQ'] ?? 'A',
|
|
|
+ 'PCEQ_TICO' => $this->getCodeTypeFromSheet($sheetName),
|
|
|
+ 'PCEQ_JERA' => 'Padre',
|
|
|
+ 'PCEQ_EQPA' => null,
|
|
|
+ 'PCEQ_NUSE' => $rowData['PCEQ_NUSE'] ?? '',
|
|
|
+ 'PCEQ_COBA' => $rowData['PCEQ_COBA'] ?? '',
|
|
|
+ 'PCEQ_CARA' => $caracter,
|
|
|
+ 'PCEQ_PREQ' => $rowData['PCEQ_PREQ'] ?? 0,
|
|
|
+ 'PCEQ_FVAR' => $fechaVencimiento ?? now()->format('Y-m-d'),
|
|
|
+ 'PCEQ_GAIM' => json_encode([]),
|
|
|
+ 'PCEQ_DORE' => json_encode([]),
|
|
|
+ 'PCEQ_ESRE' => 'Revisión',
|
|
|
+ 'PCEQ_USRE' => $idUser,
|
|
|
+ 'PCEQ_FERE' => $nowStr,
|
|
|
+ 'PCEQ_IDPR' => $this->generateNumericUniqueId($linea)
|
|
|
+ ];
|
|
|
|
|
|
- // Lógica de jerarquía (Padre/Hijo) para casos 1-6
|
|
|
- if (in_array($sheetName, ['CASO 1', 'CASO 2', 'CASO 3', 'CASO 4', 'CASO 5', 'CASO 6'])) {
|
|
|
- $tieneSegundoConjunto =
|
|
|
- !empty(trim($rowData['PCEQ_TIEQ_HIJO'] ?? '')) &&
|
|
|
- !empty(trim($rowData['PCEQ_MOEQ_HIJO'] ?? ''));
|
|
|
-
|
|
|
- if ($tieneSegundoConjunto) {
|
|
|
- $equipmentData['PCEQ_TIEQ'] = $rowData['PCEQ_TIEQ_HIJO'];
|
|
|
- $equipmentData['PCEQ_MOEQ'] = $rowData['PCEQ_MOEQ_HIJO'];
|
|
|
- $equipmentData['PCEQ_JERA'] = 'Hijo';
|
|
|
- } else {
|
|
|
- $equipmentData['PCEQ_TIEQ'] = $rowData['PCEQ_TIEQ'] ?? '';
|
|
|
- $equipmentData['PCEQ_MOEQ'] = $rowData['PCEQ_MOEQ'] ?? '';
|
|
|
- $equipmentData['PCEQ_JERA'] = 'Padre';
|
|
|
- }
|
|
|
+ // ==================== CAMBIO PRINCIPAL ====================
|
|
|
+ // Lógica de jerarquía (Padre/Hijo) para casos 1-6
|
|
|
+ if (in_array($sheetName, ['CASO 1', 'CASO 2', 'CASO 3', 'CASO 4', 'CASO 5', 'CASO 6'])) {
|
|
|
+ $tieneSegundoConjunto =
|
|
|
+ !empty(trim($rowData['PCEQ_TIEQ_HIJO'] ?? '')) &&
|
|
|
+ !empty(trim($rowData['PCEQ_MOEQ_HIJO'] ?? ''));
|
|
|
+
|
|
|
+ if ($tieneSegundoConjunto) {
|
|
|
+ // Para HIJO: Guardar nombres COMPLETOS en BD
|
|
|
+ $equipmentData['PCEQ_TIEQ'] = $rowData['PCEQ_TIEQ_HIJO_COMPLETO'] ?? $rowData['PCEQ_TIEQ_HIJO'] ?? '';
|
|
|
+ $equipmentData['PCEQ_MOEQ'] = $rowData['PCEQ_MOEQ_HIJO_COMPLETO'] ?? $rowData['PCEQ_MOEQ_HIJO'] ?? '';
|
|
|
+ $equipmentData['PCEQ_JERA'] = 'Hijo';
|
|
|
} else {
|
|
|
- $equipmentData['PCEQ_TIEQ'] = $rowData['PCEQ_TIEQ'] ?? '';
|
|
|
- $equipmentData['PCEQ_MOEQ'] = $rowData['PCEQ_MOEQ'] ?? '';
|
|
|
+ // Para PADRE: Guardar nombres COMPLETOS en BD
|
|
|
+ $equipmentData['PCEQ_TIEQ'] = $rowData['PCEQ_TIEQ_COMPLETO'] ?? $rowData['PCEQ_TIEQ'] ?? '';
|
|
|
+ $equipmentData['PCEQ_MOEQ'] = $rowData['PCEQ_MOEQ_COMPLETO'] ?? $rowData['PCEQ_MOEQ'] ?? '';
|
|
|
+ $equipmentData['PCEQ_JERA'] = 'Padre';
|
|
|
}
|
|
|
-
|
|
|
- // Agregar campos específicos según el tipo de hoja
|
|
|
- $this->addSheetSpecificFields($equipmentData, $rowData, $sheetName);
|
|
|
-
|
|
|
- return $equipmentData;
|
|
|
+ } else {
|
|
|
+ // Para CARGA DE EQUIPOS y LRU: También usar nombres completos si están disponibles
|
|
|
+ $equipmentData['PCEQ_TIEQ'] = $rowData['PCEQ_TIEQ_COMPLETO'] ?? $rowData['PCEQ_TIEQ'] ?? '';
|
|
|
+ $equipmentData['PCEQ_MOEQ'] = $rowData['PCEQ_MOEQ_COMPLETO'] ?? $rowData['PCEQ_MOEQ'] ?? '';
|
|
|
}
|
|
|
+ // ==================== FIN CAMBIO PRINCIPAL ====================
|
|
|
+
|
|
|
+ // Agregar campos específicos según el tipo de hoja
|
|
|
+ $this->addSheetSpecificFields($equipmentData, $rowData, $sheetName);
|
|
|
+
|
|
|
+ return $equipmentData;
|
|
|
+}
|
|
|
|
|
|
private function parseDate($value) {
|
|
|
if (!$value) return null;
|
|
|
@@ -898,49 +959,67 @@ private function normalizeCaracter($value) {
|
|
|
}
|
|
|
|
|
|
// MÉTODO PARA GENERAR PCEQ_IDPR: Solo ID numérico único
|
|
|
-private function generateNumericUniqueId($linea) {
|
|
|
- static $lastId = []; // Almacena el último ID usado por línea
|
|
|
+private function generateNumericUniqueId($linea, $increment = true) {
|
|
|
+ static $lastId = [];
|
|
|
+ static $initialized = [];
|
|
|
|
|
|
- if (!isset($lastId[$linea])) {
|
|
|
+ // Solo inicializar una vez por línea
|
|
|
+ if (!isset($initialized[$linea])) {
|
|
|
// Obtener el máximo ID existente en la base de datos
|
|
|
$maxId = DB::table('S002V01TPCEQ')
|
|
|
->where('PCEQ_NULI', $linea)
|
|
|
->max('PCEQ_IDPR');
|
|
|
|
|
|
- $lastId[$linea] = $maxId ? $maxId : 0;
|
|
|
+ if ($maxId) {
|
|
|
+ // Si hay registros, convertir a entero (removiendo padding)
|
|
|
+ $lastId[$linea] = (int)ltrim($maxId, '0');
|
|
|
+ } else {
|
|
|
+ // Si NO hay registros, empezar desde 0
|
|
|
+ $lastId[$linea] = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ $initialized[$linea] = true;
|
|
|
+
|
|
|
+ // Log para debug
|
|
|
+ // \Log::info("Línea $linea - Max ID en BD: " . ($maxId ?? 'NULL') . ", Contador inicializado en: " . $lastId[$linea]);
|
|
|
}
|
|
|
|
|
|
- // Incrementar el contador para esta línea
|
|
|
- $lastId[$linea]++;
|
|
|
+ // Solo incrementar si se solicita (por defecto true)
|
|
|
+ if ($increment) {
|
|
|
+ $lastId[$linea]++;
|
|
|
+ }
|
|
|
|
|
|
- return $lastId[$linea];
|
|
|
+ // FORMATEAR A 6 DÍGITOS
|
|
|
+ return str_pad($lastId[$linea], 6, '0', STR_PAD_LEFT);
|
|
|
}
|
|
|
|
|
|
// MÉTODO PARA GENERAR PCEQ_CPGE: El código concatenado complejo (solo CASOS 1-6)
|
|
|
private function generateConcatenatedCode($equipmentData, $sheetName) {
|
|
|
- // Solo generar concatenación para CASOS 1-6
|
|
|
+ // Validar campos mínimos requeridos
|
|
|
+ $requiredFields = ['PCEQ_NULI', 'PCEQ_IDPR'];
|
|
|
+ foreach ($requiredFields as $field) {
|
|
|
+ if (empty($equipmentData[$field])) {
|
|
|
+ return 'CODIGO_INCOMPLETO_' . uniqid();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
switch($sheetName) {
|
|
|
case 'CASO 1':
|
|
|
case 'CASO 2':
|
|
|
return $this->generateCodeCaso1y2($equipmentData);
|
|
|
-
|
|
|
case 'CASO 3':
|
|
|
return $this->generateCodeCaso3($equipmentData);
|
|
|
-
|
|
|
case 'CASO 4':
|
|
|
return $this->generateCodeCaso4($equipmentData);
|
|
|
-
|
|
|
case 'CASO 5':
|
|
|
case 'CASO 6':
|
|
|
return $this->generateCodeCaso5y6($equipmentData);
|
|
|
-
|
|
|
default:
|
|
|
return 'DEFAULT_CODE_' . $equipmentData['PCEQ_IDPR'];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private function generateCodeCaso1y2($data) {
|
|
|
- // Patrón: LINEA.UBICACION.NIVEL.OCUPACION.ELEMENTO+COORDENADAS_FAMILIA.SUBFAMILIA.ESTADO.TIPO-MODELO-ID.TIPO-MODELO-ID-CODIGO_SAM
|
|
|
$parts = [
|
|
|
str_pad($data['PCEQ_NULI'], 2, '0', STR_PAD_LEFT),
|
|
|
$data['PCEQ_UBOR'] ?? '',
|
|
|
@@ -951,95 +1030,95 @@ private function generateCodeCaso1y2($data) {
|
|
|
$data['PCEQ_FAMI'] ?? '',
|
|
|
$data['PCEQ_SUBF'] ?? '',
|
|
|
$data['PCEQ_ESEQ'] ?? 'A',
|
|
|
- $data['PCEQ_TIEQ'] ?? '',
|
|
|
- $data['PCEQ_MOEQ'] ?? '',
|
|
|
- $data['PCEQ_IDPR'],
|
|
|
+ // USAR ACRÓNIMOS para la generación del código
|
|
|
+ $this->getAcronymForCode($data, 'TIEQ'),
|
|
|
+ $this->getAcronymForCode($data, 'MOEQ'),
|
|
|
+ $data['PCEQ_IDPR']
|
|
|
];
|
|
|
|
|
|
- $code = implode('.', array_filter($parts));
|
|
|
-
|
|
|
- // Eliminar separadores finales no deseados
|
|
|
- $code = rtrim($code, '.');
|
|
|
-
|
|
|
- return $code;
|
|
|
+ return implode('.', array_filter($parts));
|
|
|
}
|
|
|
|
|
|
private function generateCodeCaso3($data) {
|
|
|
- // Patrón para CASO 3: LINEA.UBICACION_ORIGEN.NIVEL_ORIGEN.OCUPACION_ORIGEN.ELEMENTO_ORIGEN:UBICACION_DESTINO.NIVEL_DESTINO.OCUPACION_DESTINO.ELEMENTO_DESTINO-FAMILIA-SUBFAMILIA.ESTADO-TIPO-MODELO-ID
|
|
|
$parts = [
|
|
|
str_pad($data['PCEQ_NULI'], 2, '0', STR_PAD_LEFT),
|
|
|
- $data['PCEQ_UBOR'] ?? '', // Ubicación origen
|
|
|
- $data['PCEQ_NIDE'] ?? '', // Nivel origen
|
|
|
- $data['PCEQ_OCDE'] ?? '', // Ocupación origen
|
|
|
- $data['PCEQ_ELDE'] ?? '', // Elemento origen
|
|
|
- $data['PCEQ_UBDE'] ?? '', // Ubicación destino
|
|
|
- $data['PCEQ_FAMI'] ?? '', // Familia
|
|
|
- $data['PCEQ_SUBF'] ?? '', // Subfamilia
|
|
|
- $data['PCEQ_ESEQ'] ?? 'A', // Estado
|
|
|
- $data['PCEQ_TIEQ'] ?? '', // Tipo
|
|
|
- $data['PCEQ_MOEQ'] ?? '', // Modelo
|
|
|
- $data['PCEQ_IDPR'], // ID numérico
|
|
|
+ $data['PCEQ_UBOR'] ?? '',
|
|
|
+ $data['PCEQ_NIDE'] ?? '',
|
|
|
+ $data['PCEQ_OCDE'] ?? '',
|
|
|
+ $data['PCEQ_ELDE'] ?? '',
|
|
|
+ $data['PCEQ_UBDE'] ?? '',
|
|
|
+ $data['PCEQ_FAMI'] ?? '',
|
|
|
+ $data['PCEQ_SUBF'] ?? '',
|
|
|
+ $data['PCEQ_ESEQ'] ?? 'A',
|
|
|
+ // USAR ACRÓNIMOS para la generación del código
|
|
|
+ $this->getAcronymForCode($data, 'TIEQ'),
|
|
|
+ $this->getAcronymForCode($data, 'MOEQ'),
|
|
|
+ $data['PCEQ_IDPR']
|
|
|
];
|
|
|
|
|
|
- $code = implode('.', array_filter($parts));
|
|
|
-
|
|
|
- // Eliminar separadores finales no deseados
|
|
|
- $code = rtrim($code, '.');
|
|
|
-
|
|
|
- return $code;
|
|
|
+ return implode('.', array_filter($parts));
|
|
|
}
|
|
|
|
|
|
private function generateCodeCaso4($data) {
|
|
|
- // Patrón para CASO 4: Similar a CASO 3 pero con secuenciales y coordenadas adicionales
|
|
|
$parts = [
|
|
|
str_pad($data['PCEQ_NULI'], 2, '0', STR_PAD_LEFT),
|
|
|
- $data['PCEQ_UBOR'] ?? '', // Ubicación origen
|
|
|
- $data['PCEQ_SEOR'] ?? '0', // Secuencial origen
|
|
|
- $data['PCEQ_COOR'] ?? '', // Coordenadas origen
|
|
|
- $data['PCEQ_UBDE'] ?? '', // Ubicación destino
|
|
|
- $data['PCEQ_SEDE'] ?? '0', // Secuencial destino
|
|
|
- $data['PCEQ_CODE'] ?? '', // Coordenadas destino
|
|
|
- $data['PCEQ_FAMI'] ?? '', // Familia
|
|
|
- $data['PCEQ_SUBF'] ?? '', // Subfamilia
|
|
|
- $data['PCEQ_ESEQ'] ?? 'A', // Estado
|
|
|
- $data['PCEQ_TIEQ'] ?? '', // Tipo
|
|
|
- $data['PCEQ_MOEQ'] ?? '', // Modelo
|
|
|
- $data['PCEQ_IDPR'], // ID numérico
|
|
|
+ $data['PCEQ_UBOR'] ?? '',
|
|
|
+ $data['PCEQ_SEOR'] ?? '0',
|
|
|
+ $data['PCEQ_COOR'] ?? '',
|
|
|
+ $data['PCEQ_UBDE'] ?? '',
|
|
|
+ $data['PCEQ_SEDE'] ?? '0',
|
|
|
+ $data['PCEQ_CODE'] ?? '',
|
|
|
+ $data['PCEQ_FAMI'] ?? '',
|
|
|
+ $data['PCEQ_SUBF'] ?? '',
|
|
|
+ $data['PCEQ_ESEQ'] ?? 'A',
|
|
|
+ // USAR ACRÓNIMOS para la generación del código
|
|
|
+ $this->getAcronymForCode($data, 'TIEQ'),
|
|
|
+ $this->getAcronymForCode($data, 'MOEQ'),
|
|
|
+ $data['PCEQ_IDPR']
|
|
|
];
|
|
|
|
|
|
- $code = implode('.', array_filter($parts));
|
|
|
-
|
|
|
- // Eliminar separadores finales no deseados
|
|
|
- $code = rtrim($code, '.');
|
|
|
-
|
|
|
- return $code;
|
|
|
-
|
|
|
+ return implode('.', array_filter($parts));
|
|
|
}
|
|
|
|
|
|
private function generateCodeCaso5y6($data) {
|
|
|
- // Patrón para CASO 5 y 6: LINEA.UBICACION.NIVEL.OCUPACION.AREA.ELEMENTO_FAMILIA.SUBFAMILIA.ESTADO.TIPO-MODELO-ID.TIPO-MODELO-ID-CODIGO
|
|
|
$parts = [
|
|
|
str_pad($data['PCEQ_NULI'], 2, '0', STR_PAD_LEFT),
|
|
|
- $data['PCEQ_UBOR'] ?? '', // Ubicación
|
|
|
- $data['PCEQ_NIOR'] ?? '', // Nivel
|
|
|
- $data['PCEQ_OCOR'] ?? '', // Ocupación
|
|
|
- $data['PCEQ_ARTR'] ?? '', // Área
|
|
|
- $data['PCEQ_ELOR'] ?? '', // Elemento
|
|
|
- $data['PCEQ_FAMI'] ?? '', // Familia
|
|
|
- $data['PCEQ_SUBF'] ?? '', // Subfamilia
|
|
|
- $data['PCEQ_ESEQ'] ?? 'A', // Estado
|
|
|
- $data['PCEQ_TIEQ'] ?? '', // Tipo
|
|
|
- $data['PCEQ_MOEQ'] ?? '', // Modelo
|
|
|
- $data['PCEQ_IDPR'], // ID numérico
|
|
|
+ $data['PCEQ_UBOR'] ?? '',
|
|
|
+ $data['PCEQ_NIOR'] ?? '',
|
|
|
+ $data['PCEQ_OCOR'] ?? '',
|
|
|
+ $data['PCEQ_ARTR'] ?? '',
|
|
|
+ $data['PCEQ_ELOR'] ?? '',
|
|
|
+ $data['PCEQ_FAMI'] ?? '',
|
|
|
+ $data['PCEQ_SUBF'] ?? '',
|
|
|
+ $data['PCEQ_ESEQ'] ?? 'A',
|
|
|
+ // USAR ACRÓNIMOS para la generación del código
|
|
|
+ $this->getAcronymForCode($data, 'TIEQ'),
|
|
|
+ $this->getAcronymForCode($data, 'MOEQ'),
|
|
|
+ $data['PCEQ_IDPR']
|
|
|
];
|
|
|
|
|
|
- $code = implode('.', array_filter($parts));
|
|
|
+ return implode('.', array_filter($parts));
|
|
|
+}
|
|
|
+
|
|
|
+private function getAcronymForCode($data, $type) {
|
|
|
+ // Determinar si usar padre o hijo según PCEQ_JERA
|
|
|
+ $isHijo = ($data['PCEQ_JERA'] ?? 'Padre') === 'Hijo';
|
|
|
|
|
|
- // Eliminar separadores finales no deseados
|
|
|
- $code = rtrim($code, '.');
|
|
|
+ if ($type === 'TIEQ') {
|
|
|
+ if ($isHijo) {
|
|
|
+ return $data['PCEQ_TIEQ_HIJO_ACRONIMO'] ?? $data['PCEQ_TIEQ_ACRONIMO'] ?? '';
|
|
|
+ } else {
|
|
|
+ return $data['PCEQ_TIEQ_ACRONIMO'] ?? '';
|
|
|
+ }
|
|
|
+ } elseif ($type === 'MOEQ') {
|
|
|
+ if ($isHijo) {
|
|
|
+ return $data['PCEQ_MOEQ_HIJO_ACRONIMO'] ?? $data['PCEQ_MOEQ_ACRONIMO'] ?? '';
|
|
|
+ } else {
|
|
|
+ return $data['PCEQ_MOEQ_ACRONIMO'] ?? '';
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- return $code;
|
|
|
-
|
|
|
+ return '';
|
|
|
}
|
|
|
|
|
|
// MÉTODO ALTERNATIVO: Usar timestamp + hash para garantizar unicidad (para CARGA DE EQUIPOS y LRU)
|
|
|
@@ -1128,82 +1207,62 @@ private function upsertEquipmentData($equipmentData) {
|
|
|
}
|
|
|
|
|
|
// MÉTODO MODIFICADO PARA PROCESAR WORKSHEET CON MANEJO DE DUPLICADOS
|
|
|
- private function processWorksheet($worksheet, $sheetConfig, $sheetName, $linea, $idUser, $cargaMap, $lruMap) {
|
|
|
- $processedData = [];
|
|
|
- $errors = [];
|
|
|
- $count = 0;
|
|
|
-
|
|
|
- $highestRow = $worksheet->getHighestRow();
|
|
|
- $startRow = $sheetConfig['date_start_row'];
|
|
|
- $fieldMapping = $sheetConfig['field_mapping'];
|
|
|
-
|
|
|
- // Obtener todos los equipos de CARGA y LRU para búsqueda
|
|
|
- $cargaEquipments = $this->getAllCargaEquipments($worksheet->getParent());
|
|
|
- $lruEquipments = $this->getAllLruEquipments($worksheet->getParent());
|
|
|
-
|
|
|
- $this->generateNumericUniqueId($linea);
|
|
|
+private function processWorksheet($worksheet, $sheetConfig, $sheetName, $linea, $idUser, $cargaMap, $lruMap) {
|
|
|
+ $processedData = [];
|
|
|
+ $errors = [];
|
|
|
+ $count = 0;
|
|
|
+
|
|
|
+ $highestRow = $worksheet->getHighestRow();
|
|
|
+ $startRow = $sheetConfig['date_start_row'];
|
|
|
+ $fieldMapping = $sheetConfig['field_mapping'];
|
|
|
+
|
|
|
+ // Obtener todos los equipos de CARGA y LRU para búsqueda
|
|
|
+ $cargaEquipments = $this->getAllCargaEquipments($worksheet->getParent());
|
|
|
+ $lruEquipments = $this->getAllLruEquipments($worksheet->getParent());
|
|
|
+
|
|
|
|
|
|
|
|
|
- for($row = $startRow; $row <= $highestRow; $row++) {
|
|
|
- $rowData = $this->extractRowData($worksheet, $row, $fieldMapping, $sheetName);
|
|
|
-
|
|
|
- $backendCode = $this->generateConcatenatedCode($equipmentData, $sheetName);
|
|
|
- $frontendCode = $rowData['PCEQ_CPGE'] ?? '';
|
|
|
-
|
|
|
- if ($backendCode !== $frontendCode) {
|
|
|
- $errors[] = "Código generado no coincide en $sheetName fila $row:
|
|
|
- Backend: $backendCode, Frontend: $frontendCode";
|
|
|
- }
|
|
|
+ for($row = $startRow; $row <= $highestRow; $row++) {
|
|
|
+ $rowData = $this->extractRowData($worksheet, $row, $fieldMapping, $sheetName);
|
|
|
+
|
|
|
+ if($this->isEmptyRow($rowData)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // PASO 1: Resolver nombres completos y acrónimos
|
|
|
+ $this->resolveEquipmentNames($rowData, $sheetName, $cargaMap, $lruMap);
|
|
|
|
|
|
- if($this->isEmptyRow($rowData)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- $this->replaceAcronyms($rowData, $sheetName, $cargaMap, $lruMap);
|
|
|
- $validation = $this->validateRowData($rowData, $sheetName, $row);
|
|
|
-
|
|
|
- if(!$validation['valid']) {
|
|
|
- $errors[] = "Hoja: $sheetName, Fila: $row - " . implode(', ', $validation['errors']);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // Determinar si es equipo padre o hijo
|
|
|
- $isHijo = !empty($rowData['PCEQ_TIEQ_HIJO']) || !empty($rowData['PCEQ_MOEQ_HIJO']);
|
|
|
-
|
|
|
- // Buscar equipo completo en CARGA o LRU
|
|
|
- $fullEquipment = null;
|
|
|
- if($isHijo) {
|
|
|
- // Buscar en LRU por tipo y modelo hijo
|
|
|
- $fullEquipment = $this->findEquipment(
|
|
|
- $lruEquipments,
|
|
|
- $rowData['PCEQ_TIEQ_HIJO'] ?? '',
|
|
|
- $rowData['PCEQ_MOEQ_HIJO'] ?? ''
|
|
|
- );
|
|
|
- } else {
|
|
|
- // Buscar en CARGA por tipo y modelo padre
|
|
|
- $fullEquipment = $this->findEquipment(
|
|
|
- $cargaEquipments,
|
|
|
- $rowData['PCEQ_TIEQ'] ?? '',
|
|
|
- $rowData['PCEQ_MOEQ'] ?? ''
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- // Combinar datos del caso con datos del equipo completo
|
|
|
- if($fullEquipment) {
|
|
|
- $rowData = array_merge($rowData, $fullEquipment);
|
|
|
- }
|
|
|
-
|
|
|
- $equipmentData = $this->prepareEquipmentData($rowData, $linea, $idUser, $sheetName);
|
|
|
- $processedData[] = $equipmentData;
|
|
|
- $count++;
|
|
|
+ $validation = $this->validateRowData($rowData, $sheetName, $row);
|
|
|
+
|
|
|
+ if(!$validation['valid']) {
|
|
|
+ $errors[] = "Hoja: $sheetName, Fila: $row - " . implode(', ', $validation['errors']);
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
- return [
|
|
|
- 'data' => $processedData,
|
|
|
- 'errors' => $errors,
|
|
|
- 'count' => $count
|
|
|
- ];
|
|
|
+ // PASO 2: Preparar datos del equipo (con nombres COMPLETOS para BD)
|
|
|
+ $equipmentData = $this->prepareEquipmentData($rowData, $linea, $idUser, $sheetName);
|
|
|
+
|
|
|
+ // PASO 3: Crear array especial para generación de código (con ACRÓNIMOS)
|
|
|
+ $codeData = array_merge($equipmentData, [
|
|
|
+ 'PCEQ_TIEQ_ACRONIMO' => $rowData['PCEQ_TIEQ_ACRONIMO'] ?? '',
|
|
|
+ 'PCEQ_MOEQ_ACRONIMO' => $rowData['PCEQ_MOEQ_ACRONIMO'] ?? '',
|
|
|
+ 'PCEQ_TIEQ_HIJO_ACRONIMO' => $rowData['PCEQ_TIEQ_HIJO_ACRONIMO'] ?? '',
|
|
|
+ 'PCEQ_MOEQ_HIJO_ACRONIMO' => $rowData['PCEQ_MOEQ_HIJO_ACRONIMO'] ?? ''
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // PASO 4: Generar código usando acrónimos
|
|
|
+ $equipmentData['PCEQ_CPGE'] = $this->generateConcatenatedCode($codeData, $sheetName);
|
|
|
+
|
|
|
+ $processedData[] = $equipmentData;
|
|
|
+ $count++;
|
|
|
}
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'data' => $processedData,
|
|
|
+ 'errors' => $errors,
|
|
|
+ 'count' => $count
|
|
|
+ ];
|
|
|
+}
|
|
|
|
|
|
// Obtener todos los equipos de CARGA DE EQUIPOS
|
|
|
private function getAllCargaEquipments($spreadsheet) {
|
|
|
@@ -1272,41 +1331,39 @@ private function findEquipment($equipments, $tipo, $modelo) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-private function replaceAcronyms(&$rowData, $sheetName, $cargaMap, $lruMap) {
|
|
|
+private function resolveEquipmentNames(&$rowData, $sheetName, $cargaMap, $lruMap) {
|
|
|
if (!in_array($sheetName, ['CASO 1','CASO 2','CASO 3','CASO 4','CASO 5','CASO 6'])) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // Para equipo principal (padre)
|
|
|
- $acronimoEquipo = trim($rowData['PCEQ_TIEQ'] ?? '');
|
|
|
- $acronimoModelo = trim($rowData['PCEQ_MOEQ'] ?? '');
|
|
|
+ // Resolver nombres completos para equipo principal
|
|
|
+ $acronimoTipo = $rowData['PCEQ_TIEQ'] ?? '';
|
|
|
+ $acronimoModelo = $rowData['PCEQ_MOEQ'] ?? '';
|
|
|
|
|
|
- if ($acronimoEquipo && $acronimoModelo) {
|
|
|
- // Buscar en CARGA usando combinación equipo+modelo
|
|
|
- if (isset($cargaMap['equipos'][$acronimoEquipo][$acronimoModelo])) {
|
|
|
- $rowData['PCEQ_TIEQ'] = $cargaMap['equipos'][$acronimoEquipo][$acronimoModelo];
|
|
|
- }
|
|
|
+ if ($acronimoTipo && $acronimoModelo) {
|
|
|
+ // Obtener nombre completo desde los mapas
|
|
|
+ $tipoCompleto = $cargaMap['equipos'][$acronimoTipo][$acronimoModelo] ?? $acronimoTipo;
|
|
|
+ $modeloCompleto = $cargaMap['modelos'][$acronimoModelo] ?? $acronimoModelo;
|
|
|
|
|
|
- // Reemplazar modelo si existe
|
|
|
- if (isset($cargaMap['modelos'][$acronimoModelo])) {
|
|
|
- $rowData['PCEQ_MOEQ'] = $cargaMap['modelos'][$acronimoModelo];
|
|
|
- }
|
|
|
+ // Preservar ambos valores
|
|
|
+ $rowData['PCEQ_TIEQ_COMPLETO'] = $tipoCompleto; // Nombre completo para BD
|
|
|
+ $rowData['PCEQ_MOEQ_COMPLETO'] = $modeloCompleto; // Nombre completo para BD
|
|
|
+ $rowData['PCEQ_TIEQ_ACRONIMO'] = $acronimoTipo; // Acrónimo para generación de código
|
|
|
+ $rowData['PCEQ_MOEQ_ACRONIMO'] = $acronimoModelo; // Acrónimo para generación de código
|
|
|
}
|
|
|
|
|
|
- // Para equipo hijo (si existe)
|
|
|
- $acronimoEquipoHijo = trim($rowData['PCEQ_TIEQ_HIJO'] ?? '');
|
|
|
- $acronimoModeloHijo = trim($rowData['PCEQ_MOEQ_HIJO'] ?? '');
|
|
|
+ // Resolver nombres completos para equipo hijo
|
|
|
+ $acronimoTipoHijo = $rowData['PCEQ_TIEQ_HIJO'] ?? '';
|
|
|
+ $acronimoModeloHijo = $rowData['PCEQ_MOEQ_HIJO'] ?? '';
|
|
|
|
|
|
- if ($acronimoEquipoHijo && $acronimoModeloHijo) {
|
|
|
- // Buscar en LRU usando combinación equipo+modelo
|
|
|
- if (isset($lruMap['equipos'][$acronimoEquipoHijo][$acronimoModeloHijo])) {
|
|
|
- $rowData['PCEQ_TIEQ_HIJO'] = $lruMap['equipos'][$acronimoEquipoHijo][$acronimoModeloHijo];
|
|
|
- }
|
|
|
+ if ($acronimoTipoHijo && $acronimoModeloHijo) {
|
|
|
+ $tipoHijoCompleto = $lruMap['equipos'][$acronimoTipoHijo][$acronimoModeloHijo] ?? $acronimoTipoHijo;
|
|
|
+ $modeloHijoCompleto = $lruMap['modelos'][$acronimoModeloHijo] ?? $acronimoModeloHijo;
|
|
|
|
|
|
- // Reemplazar modelo si existe
|
|
|
- if (isset($lruMap['modelos'][$acronimoModeloHijo])) {
|
|
|
- $rowData['PCEQ_MOEQ_HIJO'] = $lruMap['modelos'][$acronimoModeloHijo];
|
|
|
- }
|
|
|
+ $rowData['PCEQ_TIEQ_HIJO_COMPLETO'] = $tipoHijoCompleto;
|
|
|
+ $rowData['PCEQ_MOEQ_HIJO_COMPLETO'] = $modeloHijoCompleto;
|
|
|
+ $rowData['PCEQ_TIEQ_HIJO_ACRONIMO'] = $acronimoTipoHijo;
|
|
|
+ $rowData['PCEQ_MOEQ_HIJO_ACRONIMO'] = $acronimoModeloHijo;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1464,228 +1521,7 @@ private function replaceAcronyms(&$rowData, $sheetName, $cargaMap, $lruMap) {
|
|
|
/**
|
|
|
* Método para aprobar equipamientos desde la tabla temporal hacia la tabla final
|
|
|
*/
|
|
|
- public function approveEquipments(Request $request) {
|
|
|
- DB::enableQueryLog();
|
|
|
-
|
|
|
- $validator = Validator::make($request->all(), [
|
|
|
- 'id_user' => 'required|string',
|
|
|
- 'linea' => 'required|integer',
|
|
|
- 'equipment_ids' => 'required|array',
|
|
|
- 'equipment_ids.*' => '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 del usuario no fue desencriptado correctamente", [], 400);
|
|
|
- }
|
|
|
-
|
|
|
- $usr = DB::table('S002V01TUSUA')->where([
|
|
|
- ['USUA_IDUS', '=', $idUser],
|
|
|
- ['USUA_NULI', '=', $form['linea']]
|
|
|
- ])->first();
|
|
|
-
|
|
|
- if(is_null($usr)) {
|
|
|
- return $this->responseController->makeResponse(true, 'El usuario no está registrado', [], 404);
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- DB::beginTransaction();
|
|
|
-
|
|
|
- $approvedCount = 0;
|
|
|
- $errors = [];
|
|
|
-
|
|
|
- foreach($form['equipment_ids'] as $encryptedId) {
|
|
|
- $equipmentId = $this->encryptionController->decrypt($encryptedId);
|
|
|
-
|
|
|
- if(!$equipmentId) {
|
|
|
- $errors[] = "ID de equipamiento inválido: $encryptedId";
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // Obtener equipamiento temporal
|
|
|
- $tempEquipment = DB::table('S002V01TPCEQ')
|
|
|
- ->where('PCEQ_IDPR', $equipmentId)
|
|
|
- ->where('PCEQ_NULI', $form['linea'])
|
|
|
- ->where('PCEQ_ESRE', 'Revisión')
|
|
|
- ->first();
|
|
|
-
|
|
|
- if(!$tempEquipment) {
|
|
|
- $errors[] = "Equipamiento no encontrado o ya procesado: $equipmentId";
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // Mover a tabla final de equipamientos
|
|
|
- $finalEquipmentData = $this->prepareFinalEquipmentData($tempEquipment, $idUser);
|
|
|
-
|
|
|
- $finalEquipmentId = DB::table('S002V01TEQUI')->insertGetId($finalEquipmentData);
|
|
|
-
|
|
|
- // Actualizar estado en tabla temporal
|
|
|
- DB::table('S002V01TPCEQ')
|
|
|
- ->where('PCEQ_IDPR', $equipmentId)
|
|
|
- ->update([
|
|
|
- 'PCEQ_ESRE' => 'Aprobado',
|
|
|
- 'PCEQ_USAP' => $idUser,
|
|
|
- 'PCEQ_FEAP' => Carbon::now('America/Mexico_city')->toDateTimeString()
|
|
|
- ]);
|
|
|
-
|
|
|
- $approvedCount++;
|
|
|
- }
|
|
|
-
|
|
|
- if($approvedCount === 0) {
|
|
|
- DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "No se pudo aprobar ningún equipamiento: " . implode('; ', $errors), [], 400);
|
|
|
- }
|
|
|
-
|
|
|
- DB::commit();
|
|
|
-
|
|
|
- // Registrar actividad
|
|
|
- $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
|
|
|
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
|
|
|
-
|
|
|
- $actions = DB::getQueryLog();
|
|
|
- $idac = $this->functionsController->registerActivity(
|
|
|
- $form['linea'],
|
|
|
- 'S002V01M07GEEQ',
|
|
|
- 'S002V01F01ADEQ',
|
|
|
- 'S002V01P11REEQ',
|
|
|
- 'Aprobación',
|
|
|
- "El usuario $name (" . $usr->USUA_IDUS . ") aprobó $approvedCount equipamientos.",
|
|
|
- $idUser,
|
|
|
- $nowStr,
|
|
|
- );
|
|
|
-
|
|
|
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
|
|
|
-
|
|
|
- $responseData = [
|
|
|
- 'equipos_aprobados' => $approvedCount,
|
|
|
- 'total_procesados' => count($form['equipment_ids'])
|
|
|
- ];
|
|
|
-
|
|
|
- if(!empty($errors)) {
|
|
|
- $responseData['errores'] = $errors;
|
|
|
- }
|
|
|
-
|
|
|
- return $this->responseController->makeResponse(false, "Aprobación exitosa", $responseData);
|
|
|
-
|
|
|
- } catch(Exception $e) {
|
|
|
- DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "Error al aprobar equipamientos: " . $e->getMessage(), [], 500);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private function prepareFinalEquipmentData($tempEquipment, $approvingUserId) {
|
|
|
- $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
|
|
|
-
|
|
|
- return [
|
|
|
-
|
|
|
- 'EQUI_NULI' => $tempEquipment->PCEQ_NULI,
|
|
|
- 'EQUI_COEQ' => $tempEquipment->PCEQ_CPGE,
|
|
|
- 'EQUI_JERA' => $tempEquipment->PCEQ_JERA,
|
|
|
- 'EQUI_EQPA' => $tempEquipment->PCEQ_EQPA,
|
|
|
- 'EQUI_TICO' => $tempEquipment->PCEQ_TICO,
|
|
|
- 'EQUI_UBOR' => $tempEquipment->PCEQ_UBOR,
|
|
|
- 'EQUI_NIOR' => $tempEquipment->PCEQ_NIOR,
|
|
|
- 'EQUI_OCOR' => $tempEquipment->PCEQ_OCOR,
|
|
|
- 'EQUI_ELOR' => $tempEquipment->PCEQ_ELOR,
|
|
|
- 'EQUI_FAMI' => $tempEquipment->PCEQ_FAMI,
|
|
|
- 'EQUI_SUBF' => $tempEquipment->PCEQ_SUBF,
|
|
|
- 'EQUI_ESEQ' => $tempEquipment->PCEQ_ESEQ,
|
|
|
- 'EQUI_TIEQ' => $tempEquipment->PCEQ_TIEQ,
|
|
|
- 'EQUI_MOEQ' => $tempEquipment->PCEQ_MOEQ,
|
|
|
- 'EQUI_FEAD' => $tempEquipment->PCEQ_FEAD,
|
|
|
- 'EQUI_FIGA' => $tempEquipment->PCEQ_FIGA,
|
|
|
- 'EQUI_FTGA' => $tempEquipment->PCEQ_FTGA,
|
|
|
- 'EQUI_PREQ' => $tempEquipment->PCEQ_PREQ,
|
|
|
- 'EQUI_NUSE' => $tempEquipment->PCEQ_NUSE,
|
|
|
- 'EQUI_GAIM' => $tempEquipment->PCEQ_GAIM,
|
|
|
- 'EQUI_DORE' => $tempEquipment->PCEQ_DORE,
|
|
|
- 'EQUI_USRE' => $approvingUserId,
|
|
|
- 'EQUI_FERE' => $nowStr,
|
|
|
- // Campos adicionales según el tipo de equipamiento
|
|
|
- 'EQUI_UBDE' => $tempEquipment->PCEQ_UBDE ?? null,
|
|
|
- 'EQUI_NIDE' => $tempEquipment->PCEQ_NIDE ?? null,
|
|
|
- 'EQUI_OCDE' => $tempEquipment->PCEQ_OCDE ?? null,
|
|
|
- 'EQUI_ELDE' => $tempEquipment->PCEQ_ELDE ?? null,
|
|
|
- 'EQUI_COOR' => $tempEquipment->PCEQ_COOR ?? null,
|
|
|
- 'EQUI_SEOR' => $tempEquipment->PCEQ_SEOR ?? null,
|
|
|
- 'EQUI_SEDE' => $tempEquipment->PCEQ_SEDE ?? null,
|
|
|
- 'EQUI_ARTR' => $tempEquipment->PCEQ_ARTR ?? null,
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Método para rechazar equipamientos
|
|
|
- */
|
|
|
- public function rejectEquipments(Request $request) {
|
|
|
- $validator = Validator::make($request->all(), [
|
|
|
- 'id_user' => 'required|string',
|
|
|
- 'linea' => 'required|integer',
|
|
|
- 'equipment_ids' => 'required|array',
|
|
|
- 'equipment_ids.*' => 'required|string',
|
|
|
- 'rejection_reason' => '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 del usuario no fue desencriptado correctamente", [], 400);
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- DB::beginTransaction();
|
|
|
-
|
|
|
- $rejectedCount = 0;
|
|
|
-
|
|
|
- foreach($form['equipment_ids'] as $encryptedId) {
|
|
|
- $equipmentId = $this->encryptionController->decrypt($encryptedId);
|
|
|
-
|
|
|
- if($equipmentId) {
|
|
|
- DB::table('S002V01TPCEQ')
|
|
|
- ->where('PCEQ_IDPR', $equipmentId)
|
|
|
- ->where('PCEQ_NULI', $form['linea'])
|
|
|
- ->update([
|
|
|
- 'PCEQ_ESRE' => 'Rechazado',
|
|
|
- 'PCEQ_MORE' => $form['rejection_reason'],
|
|
|
- 'PCEQ_USRE' => $idUser,
|
|
|
- 'PCEQ_FERE' => Carbon::now('America/Mexico_city')->toDateTimeString()
|
|
|
- ]);
|
|
|
-
|
|
|
- $rejectedCount++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- DB::commit();
|
|
|
-
|
|
|
- return $this->responseController->makeResponse(false, "Equipamientos rechazados exitosamente", [
|
|
|
- 'equipos_rechazados' => $rejectedCount
|
|
|
- ]);
|
|
|
-
|
|
|
- } catch(Exception $e) {
|
|
|
- DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "Error al rechazar equipamientos: " . $e->getMessage(), [], 500);
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
class ExcelTemplateConfig {
|
|
|
@@ -1699,7 +1535,7 @@ class ExcelTemplateConfig {
|
|
|
'table_start' => 'B9',
|
|
|
'table_end' => 'P9',
|
|
|
'header_row' => 7,
|
|
|
- 'date_start_row' => 8,
|
|
|
+ 'date_start_row' => 9,
|
|
|
'field_mapping' => [
|
|
|
'A' => '',
|
|
|
'B' => 'PCEQ_OTCO', // Código Equivalente
|
|
|
@@ -2019,4 +1855,6 @@ class ExcelTemplateConfig {
|
|
|
}
|
|
|
|
|
|
|
|
|
-};
|
|
|
+};
|
|
|
+
|
|
|
+
|