public function importarMatrizLegal() { $destinationPath = public_path() . '/imagenes/repositorio/temporal'; Excel::load($destinationPath . '/Plantilla Matriz Legal.xlsx', function ($reader) { $datos = $reader->getActiveSheet(); $matriz = array(); $errores = array(); $fila = 10; $posMatriz = 0; $posErr = 0; //***************************** // Fecha //***************************** // si la celda esta en blanco, reportamos error de obligatoriedad $fechaMatriz = $datos->getCellByColumnAndRow(0, 5)->getValue(); if ($fechaMatriz == '' or $fechaMatriz == null) { $fechaMatriz = date("Y-m-d"); } //***************************** // Nombre //***************************** // si la celda esta en blanco, reportamos error de obligatoriedad $nombreMatriz = $datos->getCellByColumnAndRow(1, 5)->getValue(); if ($nombreMatriz == '' or $nombreMatriz == null) { $errores[$posErr]["linea"] = 5; // $errores[$posErr]["nombre"] = $matriz[ $posMatriz]["nombreCompletoTercero"]; $errores[$posErr]["mensaje"] = 'Debe diligenciar el nombre de la matriz'; $posErr++; } //***************************** // Origen //***************************** // si la celda esta en blanco, reportamos error de obligatoriedad $origenMatriz = $datos->getCellByColumnAndRow(2, 5)->getValue(); if ($origenMatriz == '' or $origenMatriz == null) { $errores[$posErr]["linea"] = 5; // $errores[$posErr]["nombre"] = $matriz[ $posMatriz]["nombreCompletoTercero"]; $errores[$posErr]["mensaje"] = 'Debe diligenciar el origen de la matriz'; $posErr++; } //***************************** // Frecuencia Medicion //***************************** // si la celda esta en blanco, reportamos error de obligatoriedad $frecuenciaMedicion = $datos->getCellByColumnAndRow(3, 5)->getValue(); if ($frecuenciaMedicion == '' or $frecuenciaMedicion == null) { $errores[$posErr]["linea"] = 5; // $errores[$posErr]["nombre"] = $matriz[ $posMatriz]["nombreCompletoTercero"]; $errores[$posErr]["mensaje"] = 'Debe diligenciar la Frecuencia de Medición'; $posErr; } else { $consulta = \App\FrecuenciaMedicion::where('codigoFrecuenciaMedicion', '=', $frecuenciaMedicion)->lists('idFrecuenciaMedicion'); // si se encuentra el id lo guardamos en el array if (isset($consulta[0])) { $frecuenciaMedicion = $consulta[0]; } else { $errores[$posErr]["linea"] = 5; // $errores[$posErr]["nombre"] = $matriz[ $posMatriz]["nombreCompletoTercero"]; $errores[$posErr]["mensaje"] = 'Frecuencia ' . $frecuenciaMedicion . ' no existe'; $posErr; } } while ($datos->getCellByColumnAndRow(0, $fila)->getValue() != '' and $datos->getCellByColumnAndRow(0, $fila)->getValue() != NULL) { // para cada registro de matriz recorremos las columnas desde la 0 hasta la 11 $matriz[$posMatriz]["idMatrizLegalDetalle"] = 0; $matriz[$posMatriz]["Compania_idCompania"] = 0; for ($columna = 0; $columna <= 11; $columna++) { // en la fila 9 del archivo de excel (oculta) estan los nombres de los campos de la tabla $campo = $datos->getCellByColumnAndRow($columna, 9)->getValue(); // si es una celda calculada, la ejeutamos, sino tomamos su valor if ($datos->getCellByColumnAndRow($columna, $fila)->getDataType() == 'f') { $matriz[$posMatriz][$campo] = $datos->getCellByColumnAndRow($columna, $fila)->getCalculatedValue(); } else { $matriz[$posMatriz][$campo] = $datos->getCellByColumnAndRow($columna, $fila)->getValue() == null ? '' : $datos->getCellByColumnAndRow($columna, $fila)->getValue(); } } //***************************** // Tipo de norma //***************************** // si la celda esta en blanco, reportamos error de obligatoriedad if ($matriz[$posMatriz]["TipoNormaLegal_idTipoNormaLegal"] == '' or $matriz[$posMatriz]["TipoNormaLegal_idTipoNormaLegal"] == null) { $errores[$posErr]["linea"] = $fila; // $errores[$posErr]["nombre"] = $matriz[ $posMatriz]["nombreCompletoTercero"]; $errores[$posErr]["mensaje"] = 'Debe diligenciar el tipo de norma'; $posErr++; } else { $consulta = \App\TipoNormaLegal::where('codigoTipoNormaLegal', '=', $matriz[$posMatriz]["TipoNormaLegal_idTipoNormaLegal"])->lists('idTipoNormaLegal'); // si se encuentra el id lo guardamos en el array if (isset($consulta[0])) { $matriz[$posMatriz]["TipoNormaLegal_idTipoNormaLegal"] = $consulta[0]; } else { $errores[$posErr]["linea"] = $fila; // $errores[$posErr]["nombre"] = $matriz[ $posMatriz]["nombreCompletoTercero"]; $errores[$posErr]["mensaje"] = 'Tipo Norma Legal ' . $matriz[$posMatriz]["TipoNormaLegal_idTipoNormaLegal"] . ' no existe'; $posErr++; } } //***************************** // Expedida por //***************************** // si la celda esta en blanco, reportamos error de obligatoriedad if ($matriz[$posMatriz]["ExpideNormaLegal_idExpideNormaLegal"] == '' or $matriz[$posMatriz]["ExpideNormaLegal_idExpideNormaLegal"] == null) { $errores[$posErr]["linea"] = $fila; // $errores[$posErr]["nombre"] = $matriz[ $posMatriz]["nombreCompletoTercero"]; $errores[$posErr]["mensaje"] = 'Debe diligenciar expedido por'; $posErr++; } else { $consulta = \App\ExpideNormaLegal::where('codigoExpideNormaLegal', '=', $matriz[$posMatriz]["ExpideNormaLegal_idExpideNormaLegal"])->lists('idExpideNormaLegal'); // si se encuentra el id lo guardamos en el array if (isset($consulta[0])) { $matriz[$posMatriz]["ExpideNormaLegal_idExpideNormaLegal"] = $consulta[0]; } else { $errores[$posErr]["linea"] = $fila; // $errores[$posErr]["nombre"] = $matriz[ $posMatriz]["nombreCompletoTercero"]; $errores[$posErr]["mensaje"] = 'Expide Norma Legal ' . $matriz[$posMatriz]["ExpideNormaLegal_idExpideNormaLegal"] . ' no existe'; $posErr++; } } $posMatriz++; $fila++; } $totalErrores = count($errores); if ($totalErrores > 0) { $mensaje = '<table cellspacing="0" cellpadding="1" style="width:100%;">' . '<tr>' . '<td colspan="3">' . '<h3>Informe de inconsistencias en Importacion de matriz</h3>' . '</td>' . '</tr>' . '<tr>' . '<td >No. Línea</td>' . '<td >Mensaje</td>' . '</tr>'; for ($regErr = 0; $regErr < $totalErrores; $regErr++) { $mensaje .= '<tr>' . '<td >' . $errores[$regErr]["linea"] . '</td>' . '<td >' . $errores[$regErr]["mensaje"] . '</td>' . '</tr>'; } $mensaje .= '</table>'; echo json_encode(array(false, $mensaje)); } else { $indice = array('idMatrizLegal' => 0); $data = array('fechaElaboracionMatrizLegal' => $fechaMatriz, 'nombreMatrizLegal' => $nombreMatriz, 'origenMatrizLegal' => $origenMatriz, 'Users_id' => \Session::get("idUsuario"), 'FrecuenciaMedicion_idFrecuenciaMedicion' => $frecuenciaMedicion, 'Compania_idCompania' => \Session::get("idCompania")); $matrizlegal = \App\MatrizLegal::updateOrCreate($indice, $data); // Consultamos el ultimo id insertado en la matriz legal $ultmatrizLegal = \App\MatrizLegal::All()->last(); $matrizlegal = $ultmatrizLegal->idMatrizLegal; // recorremos el array recibido para insertar o actualizar cada registro for ($reg = 0; $reg < count($matriz); $reg++) { $indice = array('idMatrizLegalDetalle' => $matriz[$reg]["idMatrizLegalDetalle"]); $data = array('MatrizLegal_idMatrizLegal' => $matrizlegal, 'TipoNormaLegal_idTipoNormaLegal' => $matriz[$reg]['TipoNormaLegal_idTipoNormaLegal'], 'articuloAplicableMatrizLegalDetalle' => $matriz[$reg]['articuloAplicableMatrizLegalDetalle'], 'ExpideNormaLegal_idExpideNormaLegal' => $matriz[$reg]['ExpideNormaLegal_idExpideNormaLegal'], 'exigenciaMatrizLegalDetalle' => $matriz[$reg]['exigenciaMatrizLegalDetalle'], 'fuenteMatrizLegalDetalle' => $matriz[$reg]['fuenteMatrizLegalDetalle'], 'medioMatrizLegalDetalle' => $matriz[$reg]['medioMatrizLegalDetalle'], 'personaMatrizLegalDetalle' => $matriz[$reg]['personaMatrizLegalDetalle'], 'herramientaSeguimientoMatrizLegalDetalle' => $matriz[$reg]['herramientaSeguimientoMatrizLegalDetalle'], 'cumpleMatrizLegalDetalle' => $matriz[$reg]['cumpleMatrizLegalDetalle'], 'fechaVerificacionMatrizLegalDetalle' => $matriz[$reg]['fechaVerificacionMatrizLegalDetalle'], 'accionEvidenciaMatrizLegalDetalle' => $matriz[$reg]['accionEvidenciaMatrizLegalDetalle'], 'controlAImplementarMatrizLegalDetalle' => $matriz[$reg]['controlAImplementarMatrizLegalDetalle'], 'Compania_idCompania' => \Session::get("idCompania")); $matrizlegaldetalle = \App\MatrizLegalDetalle::updateOrCreate($indice, $data); } echo json_encode(array(true, 'Importacion Exitosa, por favor verifique')); } }); unlink($destinationPath . '/Plantilla Matriz Legal.xlsx'); }
<?php $modificar = $_GET['modificar']; $eliminar = $_GET['eliminar']; $visibleM = ''; $visibleE = ''; if ($modificar == 1) { $visibleM = 'inline-block;'; } else { $visibleM = 'none;'; } if ($eliminar == 1) { $visibleE = 'inline-block;'; } else { $visibleE = 'none;'; } $tiponormalegal = \App\TipoNormaLegal::All(); $row = array(); foreach ($tiponormalegal as $key => $value) { $row[$key][] = '<a href="tiponormalegal/' . $value['idTipoNormaLegal'] . '/edit">' . '<span class="glyphicon glyphicon-pencil" style = "display:' . $visibleM . '"></span>' . '</a> ' . '<a href="tiponormalegal/' . $value['idTipoNormaLegal'] . '/edit?accion=eliminar">' . '<span class="glyphicon glyphicon-trash" style = "display:' . $visibleE . '"></span>' . '</a>'; $row[$key][] = $value['idTipoNormaLegal']; $row[$key][] = $value['codigoTipoNormaLegal']; $row[$key][] = $value['nombreTipoNormaLegal']; } $output['aaData'] = $row; echo json_encode($output);
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { \App\TipoNormaLegal::destroy($id); return redirect('/tiponormalegal'); }