Advertisement
Guest User

controlador phpexcel

a guest
Feb 21st, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 41.76 KB | None | 0 0
  1.  function guardar() {
  2.        
  3.        
  4.         // validar que el nombre de la localidad no sea repetido
  5.         $this->form_validation->set_error_delimiters('<h3 style="color:red">', '</h3>');        
  6.        
  7.         $name     = $_FILES['file']['name'];
  8.         //$typ    = $_FILES["file"]["type"];
  9.         //$siz    = $_FILES["file"]["size"];
  10.         $tname    = $_FILES['file']['tmp_name'];    
  11.  
  12.  
  13.      // ver que datos se estan intentando cargar
  14.     echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  15.     echo "Type: " . $_FILES["file"]["type"] . "<br />";
  16.     echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  17.     echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";  
  18.        
  19.  
  20.         if ($name <> ""){    
  21.             $this->importar_excel_datos_trabajadores($name, $tname); //$tname);
  22.         }else{
  23.            
  24.             $accion = $this->input->post("accion");
  25.             $detalle = $this->input->post("irdetalle");
  26.             if ($accion == "Agregar")
  27.                 $this->form_validation->set_rules("cedula", "Cedula", "required|numeric|callback__verificarTrabajadorRegistrado");
  28.             $this->form_validation->set_rules("nombre", "Nombre", "required|alfhanumeric");
  29.             $this->form_validation->set_rules("apellido", "Apelido", "required|alfhanumeric");
  30.            
  31.             $this->form_validation->set_rules('fecha_nacimiento', "Fecha Nacimiento");
  32.             $this->form_validation->set_rules("lugar", "Lugar de Nacimiento");
  33.             $this->form_validation->set_rules("nacionalidad", "Nacionalidad");
  34.             $this->form_validation->set_rules("estado_civil", "Estado Civil");
  35.             $this->form_validation->set_rules("nivel_educativo", "Nivel Educativo");
  36.             $this->form_validation->set_rules("direccion", "Direccion");
  37.             $this->form_validation->set_rules("telefono", "Telefonos");
  38.             $this->form_validation->set_rules("num_hijo", "Nro. de Hijos");
  39.             $this->form_validation->set_rules("correo", "Correo", "valid_email");
  40.             $this->form_validation->set_rules("grupo_sangre", "Grupo Sanguineo");
  41.             //$this->form_validation->set_rules("edad", "Edad", "required");
  42.             $this->form_validation->set_rules("sexo", "Sexo");
  43.             $this->form_validation->set_rules("profesion", "Profesion");
  44.             $this->form_validation->set_rules("dominio_mano", "Dominio de la Mano");
  45.             $this->form_validation->set_rules("c_activo", "Activo");
  46.             //$this->form_validation->set_message("required","El campo %s es obligatorio");
  47.  
  48.             //validando accidente ya registrado
  49.             $this->form_validation->set_message('_verificarTrabajadorRegistrado', "El Trabajador ya se encuentra registrado.");
  50.  
  51.  
  52.             //TOMANDO EL VALOR DE LA VALIDACION DE LOS DATOS
  53.             $validacion = $this->form_validation->run();
  54.  
  55.             if ($validacion == false){  //si hay error en los datos
  56.  
  57.                 $this->agregar();
  58.  
  59.             }else{ // si todos los datos estan correctos
  60.  
  61.                 $cedula = $this->input->post("cedula");
  62.                 //creando registro nuevo registro de accidentes
  63.                 if ($accion == "Agregar"){
  64.                     $trabajador = new TTrabajador();
  65.                     $trabajador->cpk_cedula=$cedula;                        
  66.                     $sqlanterior = NULL;
  67.                 }
  68.                     //Buscado Registro de Accidente a Modificar
  69.                 //if (($accion == "Modificar") or ($accion == "Ver"))
  70.                 if ($accion == "Modificar"){
  71.                     $trabajador = $this->buscartrabajador($cedula);
  72.                     $sqlanterior = $trabajador->exportTo('yml');
  73.                 }
  74.  
  75.                 /* registrar datos basicos */
  76.                 $trabajador->c_nombre=$this->input->post("nombre");
  77.                 $trabajador->c_apellido=$this->input->post("apellido");
  78.                 if ($this->input->post("fecha_nacimiento") != ""){
  79.                     $trabajador->c_fecha_nacimiento=date('Y-m-d', strtotime($this->input->post("fecha_nacimiento")));
  80.                     $trabajador->c_edad=$this->calcular_edad($this->input->post("fecha_nacimiento"));
  81.                 }else{
  82.                     $trabajador->c_fecha_nacimiento=NULL;
  83.                     $trabajador->c_edad=0;
  84.                 }
  85.                 $trabajador->c_lugar_nacimiento=$this->input->post("lugar");
  86.                 $trabajador->c_nacionalidad = $this->input->post("nacionalidad");
  87.                 $trabajador->c_estado_civil = $this->input->post("estado_civil");
  88.                 $trabajador->cfkn_nivel_educativo = $this->input->post("nivel_educativo");
  89.                 $trabajador->c_direccion =$this->input->post("direccion");
  90.                 $trabajador->c_telefonos=$this->input->post("telefono");
  91.                 $trabajador->c_num_hijos=$this->input->post("num_hijo");
  92.                 $trabajador->c_correo=$this->input->post("correo");
  93.                 $trabajador->c_grupo_sanguineo=$this->input->post("grupo_sangre");
  94.                 $trabajador->c_sexo=$this->input->post("sexo");
  95.                 $trabajador->c_diestro = $this->input->post("dominio_mano");
  96.                 $trabajador->c_profesion=$this->input->post("profesion");
  97.                 $trabajador->c_estado=$this->input->post("estado");
  98.  
  99.                
  100.                 try {
  101.                
  102.                     $trabajador->save();
  103.                     $sqlactual = $trabajador->exportTo('yml');
  104.                     $auditoria = $this->auditoria->crearauditoria($this->control, 1, $this->aplicacion, $this->usuario->cpk_usuario, "REGISTRAR/MODIFICAR", " t_trabajador", $trabajador->cpk_cedula, "cpk_cedula", $sqlanterior, $sqlactual);                            
  105.                     if ($auditoria != ""){
  106.                         $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  107.                         $mensaje['mensaje_error'] = "La Auditoria REGISTRAR/MODIFICAR en t_trabajador Id_Nro = $trabajador->cpk_cedula, no se registro."."<br>".$auditoria;
  108.                         $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  109.                         $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  110.                         return;
  111.                     }        
  112.                    
  113.                 } catch (Doctrine_Exception $e) {
  114.                     $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  115.                     $mensaje['mensaje_error'] = "No se registro el trabajador."."<br>".$e->getMessage();
  116.                     //$this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  117.                     $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  118.                     return;
  119.                 }                
  120.  
  121.                
  122.                 $mensaje = array(
  123.                     "nombre_mensaje"=>$this->lang->line('mensaje_exito'),
  124.                     "mensaje_exito"=>"El registro del trabajador se ha realizado satisfactoriamente.",
  125.                     "ir_a"=>$detalle."/".$trabajador->cpk_cedula,
  126.                     "mensaje_enlace"=>"Ir -> Agregar Antecedente"
  127.                 );
  128.  
  129.                 $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_exitos",$mensaje,true);
  130.  
  131.  
  132.                 $menu = $this->plantilla->crearmenu(1);            
  133.                 $this->plantilla->crearplantilla($this->control, $this->contenido,$menu);        
  134.             }
  135.         }
  136.     }
  137.        
  138.  
  139.  function importar_excel_datos_trabajadores($name,$tname){
  140.  
  141.  
  142.         // Buscamos nuestra clase para leer el Excel
  143.         $this->load->library("spreadsheet_excel_reader");
  144.        
  145.         // Instanciamos nuestra clase
  146.         $dato = new Spreadsheet_Excel_Reader($name);
  147.         //$dato->setOutputEncoding('CP1251');
  148.         //$dato->read($name);
  149.  
  150.          //print "<pre>";
  151.          //print_r ($dato);
  152.        
  153.  
  154.         //Aqui vamos a leer el Excel, empezando desde la fila 2
  155.         for ($i = 2; $i <= $dato->rowcount($sheet_index=0); $i++) {
  156.  
  157.             //Verificamos que cada celda la fila no se encuentra vacia
  158.             if($dato->val($i,1) != ''){
  159.                
  160.                 $this->new_localidad = null;
  161.                 $this->new_gerencia = null;
  162.                 $this->new_departamento = null;
  163.                 $this->new_cargo = null;
  164.                 $this->new_trabajador = null;
  165.                 // leemos columna por columna
  166.                 for ($j = 1; $j <= $dato->colcount($sheet_index=0); $j++) {
  167.  
  168.                     $ced_trab = $value   = $dato->val($i,6);  
  169.                     $trabajador = new TTrabajador();
  170.                     $existe_trab = $trabajador->existe_trabajador($ced_trab);
  171.                     $estatus = $dato->val($i,18);
  172.                  
  173.                     if (($existe_trab)||(!$existe_trab && ($estatus != 3)  )){
  174.                        
  175.                         $value   = $dato->val($i,$j);
  176.                        
  177.                         // si la columna del excel es la nro 1 (nombres de localidades proyectos)    
  178.                         if ($j==1){
  179.                             $localidad = new TLocalidad();
  180.                             $existe_loc = $localidad->existe_localidad($value);
  181.  
  182.                             if (!$existe_loc){
  183.                                 $localidad->c_numero_contrato = $value;
  184.                                 $localidad->c_nombre = $value;
  185.                                 $localidad->c_descripcion = $value;
  186.                                 $localidad->c_fecha_inicio =  date("Y-m-d");
  187.  
  188.                                 try {
  189.                                     $localidad->save();
  190.                                     $this->new_localidad = $localidad->cpk_localidad;
  191.                                 } catch (Doctrine_Connection_Mysql_Exception $e) {
  192.                                     $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  193.                                     $mensaje['mensaje_error'] = "La localidad: ".$this->new_localidad->c_nombre." bajo el nro de contrato: ".$value." no se registro.<br>".$e->getMessage();
  194.                                     $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  195.                                     $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  196.                                     return;
  197.                                 }                              
  198.                             }else{
  199.                                 $this->new_localidad = $localidad->obtener_localidad_x_nro_contrato($value)->cpk_localidad;
  200.                                 $estatus_localidad = $localidad->obtener_localidad_x_nro_contrato($value)->c_activo;
  201.                                 // si el proyecto esta inactivo lo activo
  202.                                 if ($estatus_localidad == 0){
  203.                                     $localidad = $localidad->obtener_localidad_x_nro_contrato($value);
  204.                                     $localidad->c_activo = 1;
  205.                                     $localidad->save();
  206.                                 }
  207.                                
  208.                             }
  209.  
  210.                         }                                                  
  211.                        
  212.                         // si la columna del excel es la nro 2 (nombres de gerencias)    
  213.                         if ($j==2){
  214.  
  215.                             $gerencia = new TGerencium();
  216.                             $gerloc = new TLocalidadGerencium();                        
  217.                             $existe_ger = $gerencia->existe_gerencia($value);                                            
  218.  
  219.                             if ($existe_ger){
  220.  
  221.                                 $this->new_gerencia = $gerencia->obtener_gerencia_x_nombre($value)->cpk_gerencia;
  222.  
  223.                                 $existe_rel_lg = $gerloc->existe_relacion_loc_ger($this->new_localidad, $this->new_gerencia);
  224.  
  225.                                 if (!$existe_rel_lg){
  226.  
  227.                                     $gerloc->cfkn_localidad = $this->new_localidad;
  228.                                     $gerloc->cfkn_gerencia = $this->new_gerencia;
  229.  
  230.                                     try {
  231.                                         $gerloc->save();
  232.                                     } catch (Doctrine_Connection_Mysql_Exception $e) {
  233.                                         $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  234.                                         $mensaje['mensaje_error'] = "La localidad $this->new_localidad no se pudo relacionar a la gerencia $this->new_gerencia"."<br>".$e->getMessage();
  235.                                         $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  236.                                         $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  237.                                         return;
  238.                                     }                                  
  239.  
  240.                                 }
  241. /*                              
  242. echo "existe".$value."-Localidad:".$this->new_localidad."-Gerencia:".$this->new_gerencia."-Departamento:".$this->new_departamento."-Cargo:".$this->new_cargo;
  243. echo "<br>".$i."-".$j;
  244. //break;
  245. */
  246.                             }else{
  247.  
  248.                                 $gerencia->c_nombre = $value;
  249.                                 $gerencia->c_descripcion = $value;
  250.  
  251.                                 try {
  252.                                     $gerencia->save();
  253.                                     $this->new_gerencia = $gerencia->cpk_gerencia ;
  254.                                 } catch (Doctrine_Connection_Mysql_Exception $e) {
  255.                                     $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  256.                                     $mensaje['mensaje_error'] = "La gerencia $value no se registro"."<br>".$e->getMessage();
  257.                                     $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  258.                                     $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  259.                                     return;
  260.                                 }
  261.  
  262.                                 $gerloc->cfkn_localidad = $this->new_localidad;
  263.                                 $gerloc->cfkn_gerencia = $this->new_gerencia;
  264.  
  265.                                 try {
  266.                                         $gerloc->save();
  267.                                 } catch (Doctrine_Connection_Mysql_Exception $e) {
  268.                                         $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  269.                                         $mensaje['mensaje_error'] = "La localidad $this->new_localidad no se pudo relacionar a la gerencia $this->new_gerencia"."<br>".$e->getMessage();
  270.                                         $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  271.                                         $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  272.                                         return;
  273.                                 }                              
  274. /*
  275. echo "no existe".$value."-".$this->new_localidad."-Gerencia:".$this->new_gerencia."-Departamento:".$this->new_departamento."-Cargo:".$this->new_cargo;
  276. echo "<br>".$i."-".$j;
  277. //break;                              
  278. */
  279.  
  280.                             }
  281.                         }
  282.  
  283.                         // si la columna del excel es la nro 3 (nombres de departamentos)    
  284.                         if ($j==3){
  285.  
  286.                             $departamento = new TDepartamento();
  287.                             $gerdepto = new TGerenciumDepartamento();                        
  288.                             $existe_dep = $departamento->existe_departamento($value);                                            
  289.  
  290.                             if ($existe_dep){
  291.  
  292.                                 $this->new_departamento = $departamento->obtener_departamento_x_nombre($value)->cpk_departamento;
  293.  
  294.                                 $existe_rel_gd = $gerdepto->existe_relacion_ger_depto($this->new_gerencia, $this->new_departamento);
  295.  
  296.                                 if (!$existe_rel_gd){
  297.  
  298.                                     $gerdepto->cfkn_gerencia = $this->new_gerencia;
  299.                                     $gerdepto->cfkn_departamento = $this->new_departamento;
  300.  
  301.                                     try {
  302.                                         $gerdepto->save();
  303.                                     } catch (Doctrine_Connection_Mysql_Exception $e) {
  304.                                         $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  305.                                         $mensaje['mensaje_error'] = "El departamento $this->new_departamento no se pudo relacionar a la gerencia $this->new_gerencia"."<br>".$e->getMessage();
  306.                                         $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  307.                                         $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  308.                                         return;
  309.                                     }                                  
  310.  
  311.                                 }
  312.  
  313.                             }else{
  314.  
  315.                                 $departamento->c_nombre = $value;
  316.                                 $departamento->c_descripcion = $value;
  317.  
  318.                                 try {
  319.                                     $departamento->save();
  320.                                     $this->new_departamento = $departamento->cpk_departamento;
  321.                                 } catch (Doctrine_Connection_Mysql_Exception $e) {
  322.                                     $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  323.                                     $mensaje['mensaje_error'] = "El departamento $value no se registro"."<br>".$e->getMessage();
  324.                                     $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  325.                                     $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  326.                                     return;
  327.                                 }
  328.  
  329.                                 $gerdepto->cfkn_gerencia= $this->new_gerencia;
  330.                                 $gerdepto->cfkn_departamento = $this->new_departamento;
  331.  
  332.                                 try {
  333.                                         $gerdepto->save();
  334.                                 } catch (Doctrine_Connection_Mysql_Exception $e) {
  335.                                         $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  336.                                         $mensaje['mensaje_error'] = "El departamento: ".$this->new_departamento.", no se pudo relacionar a la gerencia: ".$this->new_gerencia.".<br>".$e->getMessage();
  337.                                         $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  338.                                         $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  339.                                         return;
  340.                                 }    
  341.  
  342.                             }
  343.  
  344.                         }                    
  345.  
  346.                         // si la columna del excel es la nro 5 (nombres de cargos)    
  347.                         if ($j==5){
  348.  
  349.                             $cargo = new TCargo();
  350.                             $cargodepto = new TCargoDepartamento();
  351.                             $existe_cargo = $cargo->existe_cargo_nombre($value);
  352.  
  353.                             if ($existe_cargo){    
  354.  
  355.                                 $this->new_cargo = $cargo->obtener_cargo_x_nombre($value)->cpk_cargo;
  356.  
  357.                                 $existe_rel_cd = $cargodepto->existe_relacion_cargo_depto($this->new_departamento,$this->new_cargo);
  358.  
  359.                                 if (!$existe_rel_cd){
  360.  
  361.                                     $cargodepto->cfkn_departamento = $this->new_departamento;
  362.                                     $cargodepto->cfkn_cargo = $this->new_cargo;
  363.  
  364.                                     try {
  365.                                         $cargodepto->save();
  366.                                     } catch (Doctrine_Connection_Mysql_Exception $e) {
  367.                                         $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  368.                                         $mensaje['mensaje_error'] = "El cargo: ".$this->new_cargo." no se pudo relacionar al departamento: ".$this->new_departamento.".<br>".$e->getMessage();
  369.                                         $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  370.                                         $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  371.                                         return;
  372.                                     }                                  
  373.  
  374.                                 }
  375.  
  376.                             }else{
  377.  
  378.                                 $cargo->c_nombre = $value;
  379.                                 $cargo->c_descripcion = $value;
  380.  
  381.                                 try {
  382.                                     $cargo->save();
  383.                                     $this->new_cargo = $cargo->cpk_cargo;
  384.                                 } catch (Doctrine_Connection_Mysql_Exception $e) {
  385.                                     $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  386.                                     $mensaje['mensaje_error'] = "El cargo $value no se registro"."<br>".$e->getMessage();
  387.                                     $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  388.                                     $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  389.                                     return;
  390.                                 }
  391.  
  392.                                 $cargodepto->cfkn_cargo= $this->new_cargo;
  393.                                 $cargodepto->cfkn_departamento = $this->new_departamento;
  394.  
  395.                                 try {
  396.                                         $cargodepto->save();
  397.                                 } catch (Doctrine_Connection_Mysql_Exception $e) {
  398.                                         $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  399.                                         $mensaje['mensaje_error'] = "El cargo: ".$this->new_cargo." no se pudo relacionar al departamento: ".$this->new_departamento.".<br>".$e->getMessage();
  400.                                         $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  401.                                         $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  402.                                         return;
  403.                                 }  
  404.  
  405.                             }
  406.  
  407.                         }                    
  408.  
  409.                         if ($j==6){
  410.  
  411.  
  412.                             $antecedente = new TAntecedenteLaborale();
  413.                            
  414.                             if ($existe_trab){
  415.  
  416.                                 /* registrar datos basicos */
  417.                                 $trabajador = $this->buscartrabajador($value);
  418.                                 $estatus_ant = $trabajador->c_estado;
  419.                                 $trabajador->c_nombre= $dato->val($i,7);
  420.                                 $trabajador->c_apellido=$dato->val($i,8);;
  421.                                 $trabajador->c_fecha_nacimiento=date('Y-m-d', strtotime($dato->val($i,9)));
  422.                                 $trabajador->c_lugar_nacimiento=$dato->val($i,10);
  423.  
  424.                                 $estado_civil = $dato->val($i,11);
  425.                                 if ($estado_civil == 1) $ec = "C";
  426.                                 if ($estado_civil == 2) $ec = "D";
  427.                                 if ($estado_civil == 3) $ec = "CC";
  428.                                 if ($estado_civil == 4) $ec = "S";
  429.                                 if ($estado_civil == 5) $ec = "V";
  430.                                 $trabajador->c_estado_civil = $ec;
  431.  
  432.  
  433.                                 $trabajador->c_direccion = $dato->val($i,12);
  434.                                 $trabajador->c_telefonos= $dato->val($i,13);
  435.                                 $trabajador->c_sexo=$dato->val($i,14);
  436.  
  437.                                 if ($estatus == 1) $e = "A";
  438.                                 if ($estatus == 2) $e = "V";                            
  439.                                 if ($estatus == 3) $e = "R";                            
  440.                                 $trabajador->c_estado= $e;
  441.  
  442.  
  443.                                 try {
  444.                                     $trabajador->save();
  445.                                     //echo "cedula ".$trabajador->cpk_cedula;
  446.                                 } catch (Doctrine_Connection_Mysql_Exception $e) {
  447.                                     $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  448.                                     $mensaje['mensaje_error'] = "El trabajador $value no se registro"."<br>".$e->getMessage();
  449.                                     $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  450.                                     $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  451.                                     return;
  452.                                 }                            
  453.  
  454. //echo "cedula libro ".$value."<br>";
  455.                                 $antecedente_actual = $antecedente->obtener_antecedente_actual($value);
  456.                                 if ($estatus_ant == "R") $antecedente_actual = $antecedente->obtener_ultimo_antecedente($value);
  457.                                
  458. //echo "existe trabajador:".$trabajador->cpk_cedula." - Antecedente actual:".$antecedente_actual->cpk_antecedentes." - ".$value."-Localidad:".$this->new_localidad."-Gerencia:".$this->new_gerencia."-Departamento:".$this->new_departamento."-Cargo:".$this->new_cargo;
  459. //echo "<br>";
  460. //echo $this->new_cargo." != ".$antecedente_actual->cfkn_cargo_confurca." || ".$this->new_departamento." != ".$antecedente_actual->cfkn_departamento." || ".$this->new_gerencia." != ".$antecedente_actual->cfkn_gerencia." || ".$this->new_localidad." != ".$antecedente_actual->cfkn_localidad."<br>";
  461. //echo "<br>".$i."-".$j;
  462. //break;   
  463.                                 if (($estatus_ant == "R")&&(($this->new_cargo != $antecedente_actual->cfkn_cargo_confurca)||($this->new_departamento != $antecedente_actual->cfkn_departamento)||($this->new_gerencia != $antecedente_actual->cfkn_gerencia)||($this->new_localidad != $antecedente_actual->cfkn_localidad))){
  464.  
  465.                                     /* registrar datos de antecedentes */
  466.                                     $antecedente->cfkn_cedula = $value;
  467.                                     $antecedente->cfkn_localidad = $this->new_localidad;
  468.                                     $antecedente->cfkn_gerencia=$this->new_gerencia;  
  469.                                     $antecedente->cfkn_departamento=$this->new_departamento;  
  470.                                     $antecedente->cfkn_cargo_confurca=$this->new_cargo;  
  471.                                     $antecedente->c_fecha_ingreso =date('Y-m-d', strtotime($dato->val($i,15)));
  472.                                    
  473.                                     $fecha_retiro = $dato->val($i,16);
  474.                                     if (($fecha_retiro != "  -   -") && ($fecha_retiro != "")){
  475.                                         $antecedente->c_fecha_egreso=date('Y-m-d', strtotime($fecha_retiro));
  476.                                     }
  477.                                    
  478.                                     if ($estatus == 1) $e = "A";
  479.                                     if ($estatus == 2) $e = "V";                            
  480.                                     if ($estatus == 3) $e = "R";                            
  481.                                     $antecedente->c_estado= $e;
  482.  
  483.                                     $nomina = $dato->val($i,17);
  484.                                     if ($nomina == 1) $nom = "D";
  485.                                     if ($nomina == 2) $nom = "M";                            
  486.                                     if ($nomina == 3) $nom = "G";                            
  487.                                     $antecedente->c_nomina= $nom;                            
  488.  
  489.                                     $antecedente->c_confurca=1;
  490.                                     $antecedente->c_trabajo_actual=1;
  491.  
  492.                                     $antecedente_actual->c_trabajo_actual=0;
  493.                                     $antecedente_actual->c_estado= "R";                                    
  494.  
  495.                                     $conn =  Doctrine_Manager::connection();
  496.                                     $conn->beginTransaction();  
  497.  
  498.  
  499.                                     try {
  500.                                         $antecedente->save();
  501.                                         //echo "antecedente nuevo ".$antecedente->cfkn_cedula;
  502.                                     } catch (Doctrine_Connection_Mysql_Exception $e) {
  503.                                         $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  504.                                         $mensaje['mensaje_error'] = "El Antecedente anterior del trabajador $value no se actualizo"."<br>".$e->getMessage();
  505.                                         $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  506.                                         $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  507.                                         return;
  508.                                     }    
  509.  
  510. //echo "existe trabajador y cargo dif:".$trabajador->cpk_cedula."-Antecedente actual".$antecedente_actual->cpk_antecedentes."-".$value."-Localidad:".$this->new_localidad."-Gerencia:".$this->new_gerencia."-Departamento:".$this->new_departamento."-Cargo:".$this->new_cargo."<br>";
  511. //echo $this->new_cargo." != ".$antecedente_actual->cfkn_cargo_confurca." || ".$this->new_departamento." != ".$antecedente_actual->cfkn_departamento." || ".$this->new_gerencia." != ".$antecedente_actual->cfkn_gerencia." || ".$this->new_localidad." != ".$antecedente_actual->cfkn_localidad."<br>";
  512. //echo $antecedente->cfkn_cargo_confurca." != ".$antecedente_actual->cfkn_cargo_confurca." || ".$antecedente->cfkn_departamento." != ".$antecedente_actual->cfkn_departamento." || ".$antecedente->cfkn_gerencia." != ".$antecedente_actual->cfkn_gerencia." || ".$antecedente->cfkn_localidad." != ".$antecedente_actual->cfkn_localidad."<br>";
  513. //echo "<br>".$i."-".$j;
  514. //break;   
  515.  
  516.                                     try {
  517.                                         $antecedente_actual->save();
  518.                                         //echo "antecedente actual ".$antecedente_actual->cfkn_cedula;
  519.                                     } catch (Doctrine_Connection_Mysql_Exception $e) {
  520.                                         $conn->rollback();
  521.                                         $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  522.                                         $mensaje['mensaje_error'] = "El Antecdente nuevo del trabajador $value no se registro"."<br>".$e->getMessage();
  523.                                         $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  524.                                         $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  525.                                         return;
  526.                                     }                                  
  527.  
  528.                                     $conn->commit();
  529.  
  530.                                 }else{
  531.                                     // si existe pero el cargo/depto/ger/loc no es distinto - solo actualiza los demas datos
  532.  
  533.                                     $fecha_retiro = $dato->val($i,16);
  534.                                     if (($fecha_retiro != "  -   -") && ($fecha_retiro != "")){
  535.                                         $antecedente_actual->c_fecha_egreso=date('Y-m-d', strtotime($fecha_retiro));
  536.                                     }
  537.                                    
  538.                                     if ($estatus == 1) $e = "A";
  539.                                     if ($estatus == 2) $e = "V";                            
  540.                                     if ($estatus == 3) $e = "R";                            
  541.                                     $antecedente_actual->c_estado= $e;                                    
  542.                                    
  543.  
  544.                                     $nomina = $dato->val($i,17);
  545.                                     if ($nomina == 1) $nom = "D";
  546.                                     if ($nomina == 2) $nom = "M";                            
  547.                                     if ($nomina == 3) $nom = "G";                            
  548.                                     $antecedente_actual->c_nomina= $nom;                            
  549.  
  550.                                     $antecedente_actual->c_confurca=1;
  551.                                     $antecedente_actual->c_trabajo_actual=1;
  552.                                    
  553.                                    
  554. echo "existe trabajador y cargo igual:".$trabajador->cpk_cedula."-Antecedente actual:".$antecedente_actual->cpk_antecedentes."-".$value."-Localidad:".$this->new_localidad."-Gerencia:".$this->new_gerencia."-Departamento:".$this->new_departamento."-Cargo:".$this->new_cargo."<br>";
  555. echo $this->new_cargo." != ".$antecedente_actual->cfkn_cargo_confurca." || ".$this->new_departamento." != ".$antecedente_actual->cfkn_departamento." || ".$this->new_gerencia." != ".$antecedente_actual->cfkn_gerencia." || ".$this->new_localidad." != ".$antecedente_actual->cfkn_localidad."<br>";
  556. echo "<br>".$i."-".$j."<br>";
  557. //break;
  558.  
  559.                                     try {
  560.                                         $antecedente_actual->save();
  561.                                     } catch (Doctrine_Connection_Mysql_Exception $e) {
  562.                                         $conn->rollback();
  563.                                         $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  564.                                         $mensaje['mensaje_error'] = "El Antecdente nuevo del trabajador $value no se registro"."<br>".$e->getMessage();
  565.                                         $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  566.                                         $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  567.                                         return;
  568.                                     }                                  
  569.  
  570.                                    
  571.                                    
  572.                                 }
  573.                              
  574.  
  575.  
  576.                             }else{
  577.  
  578.                                     /* registrar datos basicos */
  579.                                     $trabajador->cpk_cedula=$value;
  580.                                     $trabajador->c_nombre= $dato->val($i,7);
  581.                                     $trabajador->c_apellido=$dato->val($i,8);;
  582.                                     $trabajador->c_fecha_nacimiento=date('Y-m-d', strtotime($dato->val($i,9)));
  583.                                     $trabajador->c_lugar_nacimiento=$dato->val($i,10);
  584.  
  585.                                     $estado_civil = $dato->val($i,11);
  586.                                     if ($estado_civil == 1) $ec = "C";
  587.                                     if ($estado_civil == 2) $ec = "D";
  588.                                     if ($estado_civil == 3) $ec = "CC";
  589.                                     if ($estado_civil == 4) $ec = "S";
  590.                                     if ($estado_civil == 5) $ec = "V";
  591.                                     $trabajador->c_estado_civil = $ec;
  592.  
  593.  
  594.                                     $trabajador->c_direccion = $dato->val($i,12);
  595.                                     $trabajador->c_telefonos= $dato->val($i,13);
  596.                                     $trabajador->c_sexo=$dato->val($i,14);
  597.  
  598.                                     if ($estatus == 1) $e = "A";
  599.                                     if ($estatus == 2) $e = "V";                            
  600.                                     if ($estatus == 3) $e = "R";                            
  601.                                     $trabajador->c_estado= $e;                                    
  602.  
  603.                                     try {
  604.                                         $trabajador->save();
  605.                                         $this->new_trabajador = $trabajador;
  606.                                     } catch (Doctrine_Connection_Mysql_Exception $e) {
  607.                                         $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  608.                                         $mensaje['mensaje_error'] = "El trabajador $value no se registro"."<br>".$e->getMessage();
  609.                                         $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  610.                                         $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  611.                                         return;
  612.                                     }                            
  613.  
  614.                                     /* registrar datos de antecedentes */
  615.                                     $antecedente->cfkn_cedula = $value;
  616.                                     $antecedente->cfkn_localidad = $this->new_localidad;
  617.                                     $antecedente->cfkn_gerencia=$this->new_gerencia;  
  618.                                     $antecedente->cfkn_departamento=$this->new_departamento;  
  619.                                     $antecedente->cfkn_cargo_confurca=$this->new_cargo;  
  620.  
  621.                                     $antecedente->c_fecha_ingreso =date('Y-m-d', strtotime($dato->val($i,15)));
  622.                                     if (($fecha_retiro != "  -   -") && ($fecha_retiro != "")){
  623.                                         $antecedente->c_fecha_egreso=date('Y-m-d', strtotime($fecha_retiro));
  624.                                     }
  625.                                    
  626.                                     if ($estatus == 1) $e = "A";
  627.                                     if ($estatus == 2) $e = "V";                            
  628.                                     if ($estatus == 3) $e = "R";                            
  629.                                     $antecedente->c_estado= $e;                                                                        
  630.  
  631.                                     $nomina = $dato->val($i,17);
  632.                                     if ($nomina == 1) $nom = "D";
  633.                                     if ($nomina == 2) $nom = "M";                            
  634.                                     if ($nomina == 3) $nom = "G";                            
  635.                                     $antecedente->c_nomina= $nom;                            
  636.  
  637.                                     $antecedente->c_confurca=1;
  638.                                     $antecedente->c_trabajo_actual=1;
  639.  
  640.                                     try {
  641.                                         $antecedente->save();                                
  642.                                     } catch (Doctrine_Connection_Mysql_Exception $e) {
  643.                                         $mensaje['nombre_mensaje'] = $this->lang->line('mensaje_error');
  644.                                         $mensaje['mensaje_error'] = "El trabajador $value no se registro"."<br>".$e->getMessage();
  645.                                         $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_errores", $mensaje,true);
  646.                                         $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  647.                                         return;
  648.                                     }                            
  649. //echo "TRABAJADOR NO EXISTE ".$ced_trab." Y ESTATUS = ".$estatus." SE REGISTRO NUEVO<BR>";
  650. //echo $i."-".$j."<br>";
  651.                             }
  652.                        
  653.                         }
  654.                        
  655.                     }
  656.                     /*else{
  657.                         echo "TRABAJADOR NO EXISTE ".$ced_trab." Y ESTATUS = ".$estatus."<BR>";
  658.                         echo $i."-".$j."<br>";
  659.                     }*/
  660.                 }
  661.                 //break;    
  662.             }
  663.            
  664.         }
  665.        
  666.                         $mensaje = array(
  667.                                 "nombre_mensaje"=>$this->lang->line('mensaje_exito'),
  668.                                 "mensaje_exito"=>"La actualizacion de los trabajadores se ha realizado satisfactoriamente.",
  669.                                 "ir_a"=>"trabajador/index",
  670.                                 "mensaje_enlace"=>$this->lang->line('aceptar')
  671.                         );
  672.  
  673.                         $this->contenido =  $this->contenido . $this->load->view("mensajes/mensaje_exitos",$mensaje,true);
  674.                         $this->plantilla->crearplantilla($this->control, $this->contenido, $this->plantilla->crearmenu(1), true);
  675.        
  676.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement