⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Repeated rows in list



Carloco

Carloco
  • profile picture
  • Member

Posted 10 September 2013 - 12:54 PM

Hi everybody

 

I have a strange problem wit GC, I have a controller "admin_bienes" and a table called "tbl_bienes", that table have one primary key: "bie_id" that is an integer.

 

The only problem is that the list show a row many times, the second row many times too...etc.

 

I don't know why, this is the first time I have this bug with GC

 

Here is the code of controller

 

<?php
if(!defined('BASEPATH'))
    exit('No se puede ejecutar el script directamente');
    
class admin_bienes extends CI_Controller {
    
    function admin_bienes() {
        parent::__construct();
        $this->load->model('mod_DBConexion','DB');
        $this->load->library('ajax_grocery_CRUD');
    }
    
    function _remap($me) {
        if(!$this->session->userdata('ses_user') || $this->session->userdata('Fecha y hora de logout')) { 
            redirect('login','refresh');
        }
        switch($me) {
            case 'show_admin_bienes': $this->show_admin_bienes(); break; 
            //case 'add': $this->Lib_utils->mensaje('Hola'); break;
        }
    }
    
    function show_admin_bienes() {
        try {
             /* Creamos el objeto */
            $crud = new ajax_grocery_CRUD();
    
            /* Seleccionamos el tema */
            $crud->set_theme('flexigrid');
        
            /* Seleccionmos el nombre de la tabla de nuestra base de datos*/
            $crud->set_table('tbl_bienes');
        
            /* Le asignamos un nombre */
            $crud->set_subject('Bienes');
        
            /* Asignamos el idioma español */
            $crud->set_language('spanish');
        
            /* Aqui le decimos a grocery que estos campos son obligatorios */
            $crud->required_fields(
              //'gru_id',
              //'tig_id',
              //'grb_id',
              'tib_id',
              'cmg_id',
              'clb_id',
              //'idb_id',
              //'bie_codigo',
              //'bie_nombre',
              'bie_localizacion',
              'bie_custodio',
              'bie_marca',
              //'bie_fecha_adq',
              //'bie_estado',
              //'bie_valor',
              'bie_descripcion'
            );
            
            /* Aqui le indicamos que campos deseamos mostrar en la lista */
            $crud->columns(
              'bie_codigo',  
              //'bie_nombre',
              'bie_localizacion',
              'bie_custodio',
              'bie_marca',
              'bie_descripcion',
              'bie_fecha_adq',
              'bie_estado',
              'bie_valor',
              'bie_usu_insert',
              'bie_usu_update',
              'bie_fecha_insert',
              'bie_fecha_update'
            );
            
            // Aqui indicamos los campos que queremos mostrar al agregar un nuevo bien
            $crud->fields(
              'gru_id',
              'tig_id',
              'grb_id',
              'tib_id',
              'cmg_id',
              'clb_id',
              'idb_id',
              'bie_codigo',
              //'bie_nombre',
              'bie_localizacion',
              'bie_custodio',
              'bie_marca',
              'bie_descripcion',
              'bie_fecha_adq',
              'bie_estado',
              'bie_valor'
            );
            
            // Aqui ponemos alias a los campos        
            //$crud->display_as('bie_id','ID');
            $crud->display_as('gru_id','Grupo');
            $crud->display_as('tig_id','Tipo de Grupo');
            $crud->display_as('grb_id','Grupo de Bienes');
            $crud->display_as('tib_id','Elija el tipo de Bien');
            $crud->display_as('cmg_id','Elija cuenta de Mayor General');
            $crud->display_as('clb_id','Elija la cuenta auxiliar');
            $crud->display_as('idb_id','Identificacion de los Bienes');
            $crud->display_as('bie_codigo','Codigo');
            //$crud->display_as('bie_nombre','Nombre');
            $crud->display_as('bie_localizacion','Departamento');
            $crud->display_as('bie_custodio','Custodio');
            $crud->display_as('bie_marca','Marca');
            $crud->display_as('bie_fecha_adq','Fecha de adquisicion');
            $crud->display_as('bie_estado','Estado');
            $crud->display_as('bie_valor','Valor');
            $crud->display_as('bie_descripcion','Descripcion');
            $crud->display_as('bie_usu_insert','Usuario que registro');
            $crud->display_as('bie_usu_update','Usuario que hizo ultima modificacion');
            $crud->display_as('bie_fecha_insert','Fecha de registro');
            $crud->display_as('bie_fecha_update','Fecha de ultima modificacion');
            
            //$crud->set_relation('gru_id','tbl_grupos','gru_concepto');
            //$crud->set_relation('tig_id','tbl_tipo_grupos','tig_concepto');
            //$crud->set_relation('grb_id','tbl_grupo_bienes','grb_concepto');
            $crud->set_relation('tib_id','tbl_tipos_bienes','tib_concepto'); // 4to nivel
            $crud->set_relation('cmg_id','tbl_cuentas_maygen','cmg_concepto'); // 5to nivel  
            $crud->set_relation('clb_id','tbl_clasificacion_bienes','clb_concepto',null,'clb_concepto asc');
            
            $crud->set_relation_dependency('cmg_id','tib_id','tib_id');
            $crud->set_relation_dependency('clb_id','cmg_id','cmg_id');
            //
            //$crud->field_type('bie_nombre','string');
            $crud->field_type('bie_fecha_adq','date');
            //$crud->field_type('gru_id','dropdown',$this->DB->loadGrupo());
//            $crud->field_type('tig_id','dropdown',$this->DB->loadTipoGrupo());
//            $crud->field_type('grb_id','dropdown',$this->DB->loadGrupoBienes());
            //$crud->field_type('tib_id','dropdown',$this->DB->loadTiposBienes());
            //$crud->field_type('cmg_id','dropdown',$this->DB->loadCMG());
            $crud->field_type('idb_id','hidden');
            
           
            //$crud->callback_add_field('idb_id',array($this,'setIDB'));
            //$crud->callback_edit_field('bie_usu_insert',array($this,'_blockUserInsert'));
            
            $crud->add_fields('gru_id','tig_id','grb_id','tib_id','cmg_id','clb_id','idb_id',
                               'bie_codigo','bie_localizacion','bie_custodio',
                               'bie_fecha_adq','bie_marca','bie_estado','bie_valor','bie_descripcion'
                               );
            $crud->edit_fields('gru_id','tig_id','grb_id','tib_id','cmg_id','clb_id','idb_id',
                               'bie_codigo','bie_localizacion','bie_custodio',
                               'bie_fecha_adq','bie_marca','bie_estado','bie_valor','bie_descripcion'
                               );
                               
             /** campos ocultos 
            $crud->field_type('gru_value','hidden','');
            $crud->field_type('tig_value','hidden','');
            $crud->field_type('grb_value','hidden',''); */
            
            /** CALLBACKS PARA LOS 3 PRIMEROS COMBOS */
            $crud->callback_add_field('gru_id',array($this,'addGroup'));
            $crud->callback_add_field('tig_id',array($this,'addTypeGroup')); // 
            $crud->callback_add_field('grb_id',array($this,'addGroupBienes'));
            $crud->callback_add_field('bie_usu_insert',array($this,'_UserInsert'));
            $crud->callback_add_field('bie_codigo',array($this,'_setCode'));
            //$crud->callback_add_field('tib_id',array($this,'addTypeBienes'));
//            $crud->callback_add_field('cmg_id',array($this,'addCMG'));
            
            
            $crud->callback_edit_field('gru_id',array($this,'addGroup'));
            $crud->callback_edit_field('tig_id',array($this,'addTypeGroup'));
            $crud->callback_edit_field('grb_id',array($this,'addGroupBienes'));
            $crud->callback_edit_field('bie_codigo',array($this,'blockBIE'));
//            $crud->callback_edit_field('grb_id',array($this,'blockGRB'));
//            $crud->callback_edit_field('tib_id',array($this,'blockTIB'));
            //$crud->callback_edit_field('idb_id',array($this,'blockIDB'));
            
            
//            $crud->field_type('gru_value','hidden','1');
            //$crud->field_type('var_tig_id','hidden',3);
            //$crud->field_type('var_grb_id','hidden',5);
//            $crud->field_type('tib_id','hidden');
//            $crud->field_type('idb_id','hidden');
//            
            //$crud->callback_before_insert(array($this,'enableCmb'));
            /** callback para el insert completo */
            $crud->callback_insert(array($this,'insertBien'));
            /** callback para el update completo */
            $crud->callback_update(array($this,'updateBien'));
                        
            /** Generamos la tabla */
            $output = $crud->render();
        
            // cargamos la vista
            $this->load->view('view_admin_bienes', $output);
        }
        catch(Exception $e) {
            show_error('ERROR: '.$e->getMessage().' --- '.$e->getTraceAsString());
        }
    }
    
    function insertBien($bien) {
        $bien['idb_id'] = $this->getIDB($bien);
        //$bien['bie_codigo'] = $this->setBieCodigo($bien);
        $useri = $this->session->userdata('ses_user'); // usuario que realiza la insercion
        $sp = "CALL sp_insert_bien(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        return $this->db->query($sp,array(
                                          'gru_id' => '1',//$bien['gru_id'],
                                          'tig_id' => '4',//$bien['tig_id'],
                                          'grb_id' => '1',//$bien['grb_id'],
                                          'tib_id' => $bien['tib_id'],
                                          'cmg_id' => $bien['cmg_id'],
                                          'clb_id' => $bien['clb_id'],
                                          'idb_id' => $bien['idb_id'],
                                          'bie_codigo' => $bien['bie_codigo'],
                                          //'bie_nombre' => $bien['bie_nombre'],
                                          'bie_localizacion' => $bien['bie_localizacion'],
                                          'bie_custodio' => $bien['bie_custodio'],
                                          'bie_fecha_adq' => date('Y-m-d', strtotime(str_replace('/', '-',$bien['bie_fecha_adq']))),
                                          'bie_marca' => $bien['bie_marca'],
                                          'bie_estado' => $bien['bie_estado'],
                                          'bie_valor' => $bien['bie_valor'],
                                          'bie_descripcion' => $bien['bie_descripcion'],
                                          'bie_usu_insert' => $useri
                                          ));
    }
    
    function updateBien($bien,$pk) {
        $useru = $this->session->userdata('ses_user'); // usuario que realiza la modificacion
        //$bien['bie_codigo'] = $this->setBieCodigo($bien);
        $sp = "CALL sp_update_bien(?,?,?,?,?,?,?,?,?,?,?,?)";
        return $this->db->query($sp,array(
                                          'cmg_id' => $bien['cmg_id'],
                                          'clb_id' => $bien['clb_id'],
                                          'bie_id' => $pk,
                                          'bie_codigo' => $bien['bie_codigo'],
                                          //'bie_nombre' => $bien['bie_nombre'],
                                          'bie_localizacion' => $bien['bie_localizacion'],
                                          'bie_custodio' => $bien['bie_custodio'],
                                          'bie_fecha_adq' => date('Y-m-d', strtotime(str_replace('/', '-',$bien['bie_fecha_adq']))),
                                          'bie_marca' => $bien['bie_marca'],
                                          'bie_estado' => $bien['bie_estado'],
                                          'bie_valor' => $bien['bie_valor'],
                                          'bie_descripcion' => $bien['bie_descripcion'],
                                          'bie_usu_update' => $useru
        ));
    }
    
    function _UserInsert() {
        return '<input type="text" maxlength="50" value="" disabled="true" name="bie_usu_insert" style="width:462px">(Este campo es de solo lectura, no se puede ingresar datos en el)';                
    }
    
    function _blockUserInsert($value,$pk) {
        return '<input type="text" maxlength="50" value="'.$value.'" disabled="true" name="bie_usu_insert" style="width:462px">';
    }
    
    function _setUserInsert($post) {
        $user = $this->session->userdata('ses_user');
        $post['bie_usu_insert'] = $user;
        return $post;                        
    }
    
    function _setCode($post) {
        return "<input type='text' name='bie_codigo' id='bie_codigo' readonly='true' /> (El codigo se crea automaticamente)";
    }
    
    function addGroup() {
        $group = $this->DB->loadGrupo();
        return form_dropdown("gru_id",$group,null,"disabled id='gru_id'");
    }
    
    function addTypeGroup() {
        $tipo = $this->DB->loadTipoGrupo();
        return form_dropdown('tig_id',$tipo,null,'disabled id="tig_id"');
    }
    
    function addGroupBienes() {
        $gbienes = $this->DB->loadGrupoBienes();
        return form_dropdown('grb_id',$gbienes,null,'disabled id="grb_id"');
    }
    
//    function addTypeBienes() {
//        $tbienes = $this->DB->loadTiposBienes();
//        return form_dropdown("tib_id",$tbienes,null,"onchange=getCode();");
//    }
//    
//    function addCMG() {
//        $code = "<script> document.write(code) </script>";
//        echo $code;
//        $cmg = $this->DB->loadCMG($code);
//        return form_dropdown("cmg_id",$cmg,null,"");
//    }
    
    /** funcion que genera el secuencial del item */
    function getIDB($post) {
        $idb = $this->DB->loadIDB(); // carga el ultimo secuencial desde la tabla
        $res = "";
        if($idb == NULL or empty($idb) or $idb == "") {
            $res = "001";
        }
        else {
            $dig = array('c' =>(int) substr($idb,0,1), //1
                         'd' =>(int) substr($idb,1,1), //9
                         'u' =>(int) substr($idb,2,1));//9
            
            if($dig['u'] == 9) {
                $dig['d']++; // incremento la decena 10
                $dig['u'] = 0; // reseteo la unidad   0
            } 
            else { $dig['u']++; } // solo incremento la unidad 
 
            if($dig['d'] > 9) {
                $dig['c']++; // incremento la centena 2
                $dig['d'] = 0; // reseteo la decena 0
                $dig['u'] = 0; // reseteo la unidad // 0
            }
            //if($dig['c'] == 9) {
//            }
            $res = $dig['c'].$dig['d'].$dig['u'];
        }
        return $res;
    }
    
    /** ESTE CAMPO ES EL DE IDENTIFICACION DE LOS BIENES */
    function setIDB($post) {
        $idb = $this->getIDB($post);
        return "<input type='text' name='idb_id' value='".$idb."' disabled='true' /> (El codigo se crea automaticamente)";
    }
    
    function blockGRU($value,$pk) {
        $val = $this->DB->getConcepto('gru_id','tbl_grupos','gru_id',$value);
        return "<input type='text' disabled='true' name='gru_id' value='".$val."' /> ";
    }
    
    function blockTIG($value,$pk) {
        $val = $this->DB->getConcepto('tig_id','tbl_tipo_grupos','tig_id',$value);
        return "<input type='text' disabled='true' name='tig_id' value='".$val."'  /> ";
    }
    
    function blockGRB($value,$pk) {
        $val = $this->DB->getConcepto('grb_id','tbl_grupo_bienes','grb_id',$value);
        return "<input type='text' name='grb_id' value='".$val."' disabled='true' /> ";
    }
    
    function blockTIB($value,$pk) {
        $val = $this->DB->getConcepto('tib_id','tbl_tipos_bienes','tib_id',$value);
        return "<input type='text' name='tib_id' value='".$val."' disabled='true' /> ";
    }
    
    function blockIDB($value,$pk) {
        return "<input type='text' name='idb_id' value='".$value."' disabled='true' /> ";
    }
    
    function blockBIE($value,$pk) {
        return "<input type='text' id='bie_codigo' name='bie_codigo' value='".$value."' readonly /> (El codigo se modifica automaticamente)";
    }
    
    function setBieCodigo($post) {
        if(empty($post['bie_codigo'])) {
            $post['bie_codigo'] = $post['gru_id'].$post['tig_id'].$post['grb_id'].'.'.$post['tib_id'].'.'.$post['cmg_id'].'.'.$post['clb_id'].'.'.$post['idb_id'];    
        }
        else {
            $post['bie_codigo'] = $post['gru_id'].$post['tig_id'].$post['grb_id'].'.'.$post['tib_id'].'.'.$post['cmg_id'].'.'.$post['clb_id'].'.'.$post['idb_id'];
        } 
        
        return $post['bie_codigo'];       
    }
}
 
?>
 
And the structure of table "tbl_bienes"
 
/*
SQLyog Ultimate v8.82 
MySQL - 5.6.12-log : Database - inventario
*********************************************************************
*/
 
 
/*!40101 SET NAMES utf8 */;
 
/*!40101 SET SQL_MODE=''*/;
 
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`inventario` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */;
 
USE `inventario`;
 
/*Table structure for table `tbl_bienes` */
 
DROP TABLE IF EXISTS `tbl_bienes`;
 
CREATE TABLE `tbl_bienes` (
  `gru_id` varchar(2) COLLATE latin1_spanish_ci NOT NULL,
  `tig_id` varchar(2) COLLATE latin1_spanish_ci NOT NULL,
  `grb_id` varchar(2) COLLATE latin1_spanish_ci NOT NULL,
  `tib_id` varchar(2) COLLATE latin1_spanish_ci NOT NULL,
  `cmg_id` varchar(2) COLLATE latin1_spanish_ci NOT NULL,
  `bie_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Id del registro',
  `clb_id` varchar(2) COLLATE latin1_spanish_ci NOT NULL,
  `idb_id` varchar(3) COLLATE latin1_spanish_ci NOT NULL,
  `bie_codigo` varchar(20) COLLATE latin1_spanish_ci NOT NULL COMMENT 'Codigo asociado al bien',
  `bie_nombre` varchar(50) COLLATE latin1_spanish_ci NOT NULL COMMENT 'Nombre del bien',
  `bie_localizacion` varchar(30) COLLATE latin1_spanish_ci NOT NULL COMMENT 'Localizacion fisica del bien',
  `bie_custodio` varchar(30) COLLATE latin1_spanish_ci NOT NULL COMMENT 'Custodio del bien',
  `bie_marca` varchar(20) COLLATE latin1_spanish_ci DEFAULT NULL COMMENT 'Marca del bien',
  `bie_descripcion` varchar(80) COLLATE latin1_spanish_ci DEFAULT NULL COMMENT 'Descripcion de las caracteristicas del bien',
  `bie_fecha_adq` date NOT NULL COMMENT 'Fecha de adquisicion del bien',
  `bie_estado` varchar(20) COLLATE latin1_spanish_ci NOT NULL COMMENT 'Estado del bien(bueno,defectuoso)',
  `bie_valor` decimal(7,2) NOT NULL COMMENT 'Valor del bien',
  `bie_usu_insert` varchar(15) COLLATE latin1_spanish_ci NOT NULL COMMENT 'Usuario que registro el bien',
  `bie_usu_update` varchar(15) COLLATE latin1_spanish_ci NOT NULL COMMENT 'Usuario que modifico datos del bien',
  `bie_fecha_insert` datetime NOT NULL COMMENT 'Fecha y hora de la creacion del registro',
  `bie_fecha_update` datetime NOT NULL COMMENT 'Fecha y hora de la ultima actualizacion del registro',
  PRIMARY KEY (`bie_id`),
  UNIQUE KEY `bie_id` (`bie_id`),
  KEY `FK_tbl_clasificacion_bienes` (`clb_id`),
  KEY `FK_tbl_grupos_bienes` (`gru_id`),
  KEY `FK_tbl_tipos_grupos_bienes` (`tig_id`),
  KEY `FK_tbl_grupos_bienes_bienes` (`grb_id`),
  KEY `FK_tbl_tipos_bienes_bienes` (`tib_id`),
  KEY `FK_tbl_cuentas_maygen_bienes` (`cmg_id`),
  KEY `FK_tbl_identificacion_bienes` (`idb_id`),
  CONSTRAINT `FK_tbl_grupos_bienes` FOREIGN KEY (`gru_id`) REFERENCES `tbl_grupos` (`gru_id`),
  CONSTRAINT `FK_tbl_grupos_bienes_bienes` FOREIGN KEY (`grb_id`) REFERENCES `tbl_grupo_bienes` (`grb_id`),
  CONSTRAINT `FK_tbl_tipos_bienes_bienes` FOREIGN KEY (`tib_id`) REFERENCES `tbl_tipos_bienes` (`tib_id`),
  CONSTRAINT `FK_tbl_tipos_grupos_bienes` FOREIGN KEY (`tig_id`) REFERENCES `tbl_tipo_grupos` (`tig_id`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci;
 
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
 

 

I have two records in tbl_bienes, but GC show its repeatedly, here I attached an image

 

Please I hope somebody can help, thanks

 

 


davidoster

davidoster
  • profile picture
  • Member

Posted 10 September 2013 - 14:55 PM

Just in case I have missed it from your code at  function show_admin_bienes(), do you set your primary key the GC way?


Carloco

Carloco
  • profile picture
  • Member

Posted 10 September 2013 - 21:21 PM

Thanks, I have tried but the problem is still there

 

Please I need help because this is a important project in my job


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 11 September 2013 - 06:22 AM

Well i will recommend you do a debug of the query that is getting executed. If for some reason, if the relations are not setting in right, this might be the issue.

 

Again .. if not mistakened - you have custom created this function - set_relation_dependency

Just add @the bottom of your function - $this->output->enable_profiler(TRUE);

below the output you should get in all the queries that gets executed and a lot other information. But what we need to debug is query.

If on execution of the same in your, if you getting the same - double result, you need to then debug as why and where is the query part that is troubling (especially i doubt strongly it has to do something with the relation). Once you get in your hands on it.. the same tweek / change you need to look out inside your code 2 overcome the trouble.


davidoster

davidoster
  • profile picture
  • Member

Posted 11 September 2013 - 06:23 AM

Well it shouldn't. First of all I assume that you have checked that the records exist only once within the table right? Silly question but I have to ask anyway!

Secondly, review how the model you load, mod_DBConexion might be affecting the application.

Thirdly, review the ajax_grocery_CRUD extension/library. There might be something suspicious there.

Try to debug using these guidelines to see which part of the application doesn't work well.

Does the GC library gets the data ok but some strange display error get the data displayed twice or more?

Does the GC library returns the same row more than once?

 

Just follow the guidelines in order to see where the problem lies and then try to figure out how to solve it.