viernes, 22 de febrero de 2013

Postgresql y Jqgrid Navegar celdas con tecla enter excel



Buenos Días hoy voy a demostrar como desplazarse dentro del jqgrid con la tecla enter y editar la celda automáticamente.



<?php if (!isset($_SESSION["mapa"])){?>
<link rel="stylesheet" type="text/css" href="css/estilo.css">
    <br/>
    <table width="400" border="0" align="center" cellpadding="5" cellspacing="0">
  <tr>
    <td align="center" background="images/blue.png"><strong class="Titulos">Debe Entrar con un usuario valido</strong></td>
  </tr>
  <tr>
    <td align="center"><a href="index.php" class="menu">Entrar</a></td>
  </tr>
</table>
<?php } else{ ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<link rel="stylesheet" type="text/css" href="scripts/calendar/calendar-blue.css"/>
<link rel="stylesheet" type="text/css" href="css/estilo.css">
<link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-1.8.16.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript" src="scripts/Nomina.js"></script>
<script language="javascript" src="scripts/sisminalve.js" type="text/javascript"></script>
<script type="text/javascript" src="scripts/calendar/calendar.js"></script>
<script type="text/javascript" src="scripts/calendar/lang/calendar-es.js"></script>
<script type="text/javascript" src="scripts/calendar/calendar-setup.js"></script>
<?php
extract($_POST);
extract($_GET);
        include('funciones/Conectar.php');//Conexion a la Base de datos
        include('funciones/FuncionesListBox.php');
        include('funciones/globales.php');
        include('funciones/librerias.php');
       
?>
<script type="text/javascript">
$(function(){
 var identificador_rubro=$('#Renglon_Oculto').val();
 var Identifica_accion =<?php echo $_GET['rp'];?>;
 // Debes declarar estas variables para capturar el id de la fila y columna
var selICol; //iCol of selected cell
var selIRow; //iRow of selected cell



 if(Identifica_accion!=0)
 {


 $.getJSON('Busca_Data.php',{Num_Reque:Identifica_accion},function(solicitud){   
       
           
            //$('select[id="Tipo_solicitud_Id"] option:selected').val(solicitud.Tipo_solicitud_Id);
           
            $('#Tipo_solicitud_Id').val(solicitud.Tipo_solicitud_Id);
            $('#Status_decision_Id').val(solicitud.Status_Decision_Id);
            $('#Solicitante_Perfil_Id').val(solicitud.Solicitante_Id);
            $('#Unidad_requerente_Id').val(solicitud.Unidad_requerente_Id);
            //$('#Unidad_requerente_Id_a option:selected').val(solicitud.Unidad_requerente_Id_a);
            $('#fechaR').val(solicitud.Solicitud_maestro_fecha);
            $('#fecha_Cambio').val(solicitud.Solicitud_maestro_status_fecha);
            $('#Num_Reque').val(solicitud.Solicitud_Numero);
           
        });
       
   


 }// cierra el if identifica_accion

$("#enlace").click(function() {
     location.href = this.href; // ir al link
});


$("#Num_Reque").blur(function(){
  if($(this).val() == '') {
    $(this).after('<div class="error">Numero de Requisicion Requerido.</div>');
    hasError = true;
  }else{
      $.post("Valida_Reque.php",{Num_r:$(this).val()},function(result){if (result!=0){alert(result);$("#enlace").click();}});
  }
 
 
});







       // $.jgrid.formatter.integer.thousandsSeparator = ',';
        $.jgrid.formatter.number.thousandsSeparator = '.';
         $.jgrid.formatter.number.decimalSeparator = ',';
         $.jgrid.formatter.number.decimalPlaces = 2;
      //  $.jgrid.formatter.currency.thousandsSeparator = ',';
   
   
        var drenglon = (function () {
            var list = null;
           
            $.ajax({
                async: false,
                global: false,
                url: 'Renglon.php',
                dataType: 'json',
                success: function (data) {
                    list = data;
                }
            });

            return list;
        })();

   
   
    var drubro = (function () {
            var list = null;
           
            $.ajax({
                async: false,
                global: false,
                url: 'Rubro.php',
                dataType: 'json',
                success: function (data) {
                    list = data;
                }
            });

            return list;
        })();
   
   
    var dsistema = (function () {
            var list = null;

            $.ajax({
                async: false,
                global: false,
                url: 'Sistema.php',
                dataType: 'json',
                success: function (data) {
                    list = data;
                }
            });

            return list;
        })();
       
        var dmedida = (function () {
            var list = null;

            $.ajax({
                async: false,
                global: false,
                url: 'Medida.php',
                dataType: 'json',
                success: function (data) {
                    list = data;
                }
            });

            return list;
        })();   
       
   
           

    var dtamano = (function () {
            var list = null;

            $.ajax({
                async: false,
                global: false,
                url: 'Tamano.php',
                dataType: 'json',
                success: function (data) {
                    list = data;
                }
            });

            return list;
        })();   

    var dmaduracion = (function () {
            var list = null;

            $.ajax({
                async: false,
                global: false,
                url: 'Maduracion.php',
                dataType: 'json',
                success: function (data) {
                    list = data;
                }
            });

            return list;
        })();   
           
    var dcalidad = (function () {
            var list = null;

            $.ajax({
                async: false,
                global: false,
                url: 'Calidad.php',
                dataType: 'json',
                success: function (data) {
                    list = data;
                }
            });

            return list;
        })();   

    var dpresentacion = (function () {
            var list = null;

            $.ajax({
                async: false,
                global: false,
                url: 'Presentacion.php',
                dataType: 'json',
                success: function (data) {
                    list = data;
                }
            });

            return list;
        })();

    var dempaque = (function () {
            var list = null;

            $.ajax({
                async: false,
                global: false,
                url: 'Empaque.php',
                dataType: 'json',
                success: function (data) {
                    list = data;
                }
            });

            return list;
        })();

               
$("#grps").jqGrid({
url:'Carga_Datos.php?filtro='+<?php echo $_GET['rp'];?>,
datatype: 'json',
mtype: 'GET',
  colNames: ['Renglon','Rubro','Sistema','Medida','Cantidad', 'Tamano', 'Maduracion','Calidad','Presentacion','Empaque'],
          colModel: [
          { name: 'Renglon', index: 'Renglon', width: 80, align: 'left',editable: true,editrules:{required:true},formatter:'select',edittype:"select",editoptions:{value: drenglon,dataEvents: [{type: 'change',
                 fn: function(e)
                {
                        
                       
                       
                          $("#grps").setColProp("Rubro", {editoptions: { value: drubro}});
                           var v = parseInt($(e.target).val(), 10);
                              $.ajax({
                             url: "Rubro_Filtro.php?Id="+v,
                             dataType: "html",
                             success: function(data)
                             {
                           
                           
                             if ($(e.target).is(".FormElement"))
                                {
                                
                                   var form = $(e.target).closest("form.FormGrid");                                                      
                                   $("select#Rubro.FormElement", form[0]).html(data);
                                  
                                }else{
                                 // inline editing
                                  var row = $(e.target).closest("tr.jqgrow");
                                  var rowId = row.attr("id");
                                   $("select#" + rowId + "_Rubro", row[0]).html(data);
                               
                               
                              }// cierra el if
                             
                           }// cierra funcion de comprobacion de exito
                          
                          
                        }); // cierra el ajax
                       
                }//cierra funcion e
   
           }]//cierra evento change
   
   
     }// cierra editoptions
     }, // cierra la linea de sistema
    { name: 'Rubro', index: 'Rubro', width: 80, align: 'left',editable: true,editrules:{required:true},formatter:'select',edittype:"select",editoptions:{value: drubro},sortable: true},
     { name: 'Sistema', index: 'Sistema', width: 80, align: 'left',editable: true,editrules:{required:true},formatter:'select',edittype:"select",editoptions:{value: dsistema,dataEvents: [{type: 'change',
                 fn: function(e)
                {
                        
                       
                       
                          $("#grps").setColProp("Medida", {editoptions: { value: dmedida}});
                           var v = parseInt($(e.target).val(), 10);
                              $.ajax({
                             url: "Medida_Filtro.php?Id="+v,
                             dataType: "html",
                             success: function(data)
                             {
                           
                           
                             if ($(e.target).is(".FormElement"))
                                {
                                
                                   var form = $(e.target).closest("form.FormGrid");                                                      
                                   $("select#Medida.FormElement", form[0]).html(data);
                                  
                                }else{
                                 // inline editing
                                  var row = $(e.target).closest("tr.jqgrow");
                                  var rowId = row.attr("id");
                                   $("select#" + rowId + "_Medida", row[0]).html(data);
                               
                               
                              }// cierra el if
                             
                           }// cierra funcion de comprobacion de exito
                          
                          
                        }); // cierra el ajax
                       
                }//cierra funcion e
   
           }]//cierra evento change
   
   
     }// cierra editoptions
     }, // cierra la linea de sistema
   
     { name: 'Medida', index: 'Medida', width: 80, align: 'left',editable: true,editrules:{required:true},formatter:'select',edittype:"select",editoptions:{value: dmedida},sortable: true},
     { name: 'Cantidad', index: 'Cantidad', width: 80, align: 'left',editable: true,editrules:{required:true,number:true},formatter: 'number',edittype:'text',editoptions:{dataEvents: [
  
    {
   // Este codigo permite pasar a la celda    siguiente y editarla automaticamente, ademas controla que no se escriban caracteres que no sean numeros.
 type: 'keypress',
        fn: function(e) {
            var key = e.charCode || e.keyCode; // to support all browsers
             if (key == 13){setTimeout("jQuery('#grps').editCell(" + selIRow + " + 1, " + selICol + ", true);", 100);}
             if((key < 48 || key > 57) &&   key !== 46 && key !== 44 && key !== 8 &&  key !== 37 && key !== 39){ return false;}
        }// cierra la funcion e
    }// cierra el control del keypress

   
]   
     }// cierra editoptions
     }, // cierra la linea de sistema
   
   
   
   
   
   
   
      { name: 'Tamano', index: 'Tamano', width: 80, align: 'left',editable: true,editrules:{required:true},formatter:'select',edittype:"select",editoptions:{value: dtamano},sortable: true},
      { name: 'Maduracion', index: 'Maduracion', width: 80, align: 'left',editable: true,editrules:{required:true},formatter:'select',edittype:"select",editoptions:{value: dmaduracion},sortable: true},
      { name: 'Calidad', index: 'Calidad', width: 80, align: 'left',editable: true,editrules:{required:true},formatter:'select',edittype:"select",editoptions:{value: dcalidad},sortable: true},
     { name: 'Presentacion', index: 'Presentacion', width: 80, align: 'left',editable: true,editrules:{required:true},formatter:'select',edittype:"select",editoptions:{value: dpresentacion},sortable: true},
      { name: 'Empaque', index: 'Empaque', width: 80, align: 'left',editable: true,editrules:{required:true},formatter:'select',edittype:"select",editoptions:{value: dempaque},sortable: true},
      ],
   
    rownumbers:true,
    pager: '#pgrps',
    rowNum:15,
    rowList:[10,25,50,100],
    autowidth: true,
    viewrecords: true,
    width: "98%",
    height: "100%",
    editurl: "someurl.php",
    caption: 'Carga Asientos Contables',
    footerrow: true,
    cellEdit: true,
    cellurl:"otro.php",//Esta es una pagina vacia php
   




   

//importante agregar este codigo para capturar el id de la celda y columna.
beforeEditCell : function(rowid, cellname, value, iRow, iCol)
{
    selICol = iCol;
    selIRow = iRow;
},


afterSaveCell: function (rowid, cellname, value,iRow, iCol) {
                    if (cellname === 'Cantidad') {
                        var sum = jQuery("#grps").jqGrid('getCol', 'Cantidad', false, 'sum');
                        jQuery("#grps").jqGrid('footerData','set', {Rubro: 'Total:', Cantidad: sum});
                    }
                },
       

afterInsertRow:function() {
             var sum = jQuery("#grps").jqGrid('getCol', 'Cantidad', false, 'sum');
             jQuery("#grps").jqGrid('footerData','set', {Rubro: 'Total:', Cantidad: sum});
        },
 
gridComplete: function(){
             var sum = jQuery("#grps").jqGrid('getCol', 'Cantidad', false, 'sum');
             jQuery("#grps").jqGrid('footerData','set', {Rubro: 'Total:', Cantidad: sum});
        },

  });


jQuery("#grps").jqGrid('navGrid','#pgrps',{pdf:true}, //options
{reloadAfterSubmit:false,closeAfterEdit:true,recreateForm:true},// edit
{height:400,width:600,reloadAfterSubmit:false,closeAfterAdd:false,recreateForm:true}, // add options
{reloadAfterSubmit:false}, // del options
{multipleSearch:true,closeAfterSearch: true, closeOnEscape: true}

);






$("#bedata").click(function()
        {
       
       
        //jQuery("#grps").jqGrid('excelExport',{tag:"pdf","url":"querygrid.php"});
             
                if(!confirm(" Esta seguro  de Grabar los asientos?"))  {return false;}
                else {
                   
                     var busca_error =0;
                     var mensaje ="";
                     var status = $('#Status_decision_Id option:selected').val();
                     var Fecha = $('#fechaR').val();
                     var Num_r =$('#Num_Reque').val();
                     var Solicitante =$('#Solicitante_Perfil_Id').val();
                     var Unidad =$('#Unidad_requerente_Id option:selected').val();
                     var Fecha_Solicitud = $('#fecha_Cambio').val();
                    // var Destino = $('#Unidad_requerente_Id_a').val();
                     //var Destino ="";
                     var Fecha_Desde = $('#Fecha_Desde').val();
                     var Fecha_Hasta = $('#Fecha_Hasta').val();
                     var Tipo_Requisicion = $('#Tipo_solicitud_Id option:selected').val();
                     cantidad = $("#grps tbody").find("tr").length;


                     if (cantidad==1){busca_error=2;mensaje="No Puede Grabar Registros en blanco";}
                     if ($("#Status_decision_Id option:selected").text()=="Seleccione"){busca_error=1;mensaje="Status";}
                     if (Fecha==""){busca_error=1;mensaje="Fecha";}
                     if (Num_r==""){busca_error=1;mensaje="Numero Requisicion";}
                     if ($("#Solicitante_Perfil_Id option:selected").text()=="Seleccione"){busca_error=1;mensaje="Solicitante_Perfil";}
                     if ($("#Unidad_requerente_Id option:selected").text()=="Seleccione"){busca_error=1;mensaje="Unidad_requerente_Id";}
                     if (Fecha_Solicitud==""){busca_error=1;mensaje="Fecha_Solicitud";}
                    // if ($("#Unidad_requerente_Id_a option:selected").text()=="Seleccione"){busca_error=1;mensaje="Destino";}
                     if (Fecha_Desde==""){busca_error=1;mensaje="Fecha_Desde";}
                     if (Fecha_Hasta==""){busca_error=1;mensaje="Fecha_Hasta";}
                     if ($("#Tipo_solicitud_Id option:selected").text()=="Seleccione"){busca_error=1;mensaje="Tipo_solicitud";}

if(busca_error==0)
{                   
                        var z=0;
                     var texto ="";
                     var columns = new Array ();
                     var lista = jQuery("#grps").getDataIDs();
                     for(i=0;i<lista.length;i++)
                        {
                            rowData=jQuery("#grps").getRowData(lista[i]);
                            columns[z]=rowData.Renglon+';'+rowData.Rubro+';'+rowData.Sistema+';'+rowData.Medida+';'+parseInt(rowData.Cantidad)+';'+rowData.Tamano+';'+rowData.Maduracion+';'+rowData.Calidad+';'+rowData.Presentacion+';'+rowData.Empaque;
                            z++;
                       }// cierra el for

   
    var jObject={};
    for(i in columns)
    {
        jObject[i] = columns[i];
    }
   
        // window.open('pruebaz.php?Numero='+Num_r,'PDF','width=200,height=400');
        //window.open('pruebaz.php','PDF','width=200,height=400');
        //$.get("pruebaz.php", { 'z': jObject} );
        //$.get("pruebaz.php", {jObject});

       
           
                      $.post("Graba.php",{jObject:  jObject,status:status,Fecha:Fecha,Num_r:Num_r,Solicitante:Solicitante,Unidad:Unidad,Fecha_Solicitud:Fecha_Solicitud,Fecha_Desde:Fecha_Desde,Fecha_Hasta:Fecha_Hasta,Tipo_Requisicion:Tipo_Requisicion,Identifica_accion:Identifica_accion},function(result)
                         {
                         alert(result);
                         $("#enlace").click();
                         });
                         // return false;
                       

}else{

if (busca_error==1){alert('Ingrese un Valor para el Campo '+mensaje);}
if (busca_error==2){alert(mensaje);}
}




                     }   // cierra el confirm   
                   
                   
                        
        });  // cierra la funcion clic
       
       



       
});
</script>
</head>





       


<body>

<table width="900" border="0" align="center" cellpadding="5" cellspacing="0">
  <tr>
    <td><a href="index.php?m=1&amp;p=0" id='enlace' name='enlace'>Volver al listado</a></td>
  </tr>
</table>
<br />
<form id="Forma_Solicitud" name="Forma_Solicitud" method="post" action="Solicitud.php">






<div id="Tabla"align="center">
  <p>&nbsp;</p>
  <table width="900" border="1" align="center" cellpadding="3" cellspacing="0" class="srcTabla">
  <tr>
    <td colspan="9" align="center" valign="middle" nowrap="nowrap" bgcolor="#ECECEC"><div align="center"><strong>SOLICITUD DE REQUISICION </strong></div></td>
  </tr>
  <tr>
    <td colspan="5">&nbsp;</td>
    <td><strong>Status</strong></td>
    <td><div id="Combo_Status" style=" float:left">
      <?php LlenarCombo('"Status_decision_Id","Status_decision_Des"', 'Status_decision', 'Seleccione','Status_decision_Id') ?></div></td>
    <td width="29"><strong>Fecha:</strong></td>
    <td width="124"><input name="fechaR" type="text" id="fechaR" size="12" maxlength="10" value="<?php echo date("d/m/Y"); ?>" onkeyup = "this.value=formateafecha(this.value);"/>
      <img src="images/calendar.png" alt="Elija una fecha" name="cal_x_fecha_reg1" width="16" height="16" align="bottom" id="cal_x_fecha_reg1" style="cursor:pointer;cursor:hand;" onMouseOver="crearcalendar_d();" /></td>
  </tr>
  <tr>
    <td width="97"><strong>Numero Requisicion:</strong></td>
    <td width="98"><input type="text" name="Num_Reque" id="Num_Reque" />
    <div id="Combo_Solicitante" style=" float:left"></div>    </td>
    <td width="80"><strong>Solicitante:</strong></td>
    <td width="91"><span style=" float:left">
      <?php LlenarCombo('"Solicitante_Perfil_Id","Solicitante_Perfil_Des"', 'Solicitante_Perfil', 'Seleccione','Solicitante_Perfil_Id') ?>
    </span><span style=" float:left">
     <div id="Combo_Unidad" style=" float:left"></div>
    </span></td>
    <td width="128"><strong>Unidad </strong></td>
    <td width="76"><span style=" float:left">
      <?php LlenarCombo('"Unidad_requerente_Id","Unidad_requerente_Des"', 'Unidad_requerente', 'Seleccione','Unidad_requerente_Id') ?>
    </span></td>
    <td width="103"><strong>Fecha de Solicitud:</strong></td>
    <td colspan="2"><input name="fecha_Cambio" type="text" id="fecha_Cambio" size="12" maxlength="10" value="<?php echo date("d/m/Y"); ?>" onkeyup = "this.value=formateafecha(this.value);"/>
      <img src="images/calendar.png" alt="Elija una fecha" name="cal_x_fecha_reg" width="16" height="16" align="bottom" id="cal_x_fecha_reg" style="cursor:pointer;cursor:hand;" onmouseover="crearcalendar();" />
      <div id="Combo_Destino" style=" float:left"></div></td>
  </tr>
  <tr>
    <td><strong></strong></td>
    <td><span style=" float:left">
      <?php //LlenarCombo('"Unidad_requerente_Id","Unidad_requerente_Des"', 'Unidad_requerente', 'Seleccione','Unidad_requerente_Id_a') ?>
    </span></td>
    <td><strong>Fecha Desde:</strong></td>
    <td><input name="Fecha_Desde" type="text" id="Fecha_Desde" size="12" maxlength="10" value="<?php echo date("d/m/Y"); ?>" onkeyup = "this.value=formateafecha(this.value);"/>
      <img src="images/calendar.png" alt="Elija una fecha" name="cal_x_fecha_reg_23" width="16" height="16" align="bottom" id="cal_x_fecha_reg_23" style="cursor:pointer;cursor:hand;" onmouseover="crearcalendar_Fdesde();" /></td>
    <td><strong>Fecha Hasta</strong>: </td>
    <td><input name="Fecha_Hasta" type="text" id="Fecha_Hasta" size="12" maxlength="10" value="<?php echo date("d/m/Y"); ?>" onkeyup = "this.value=formateafecha(this.value);"/>
      <img src="images/calendar.png" alt="Elija una fecha" name="cal_x_fecha_reg_24" width="16" height="16" align="bottom" id="cal_x_fecha_reg_24" style="cursor:pointer;cursor:hand;" onmouseover="crearcalendar_Fhasta();" />
      <div id="Combo_Tipo_Requision" style=" float:left"></div></td>
    <td><strong>Tipo Requision: </strong></td>
    <td colspan="2"><span style=" float:left">
      <?php LlenarCombo('"Tipo_solicitud_Id","Tipo_solicitud_Des"', 'Tipo_solicitud', 'Seleccione','Tipo_solicitud_Id') ?>
      </span>
      <div id="Combo_Renglon" style=" float:left"></div></td></tr>
</table>
  <p>
    <input type="hidden" name="Renglon_Oculto" Id="Renglon_Oculto" value="<?php echo($_POST['Renglon_Oculto']); ?>" />
    <input type="hidden" name="Id_Renglon_Oculto" Id="Id_Renglon_Oculto"  value="<?php echo($_POST['Id_Renglon_Oculto']); ?>" />
  </p>
</div>


  <table id="grps"></table>
  <p>&nbsp;</p>
  <div id="pgrps"></div>
 
<div id="boton" align="center">
<input type="BUTTON" id="bedata" value="Grabar Requisicion y Generar Informe" />
</div>
</form>
</body>

</html>
<?php }//Cierra Nivel de Seguridad ?>

2 comentarios:

  1. buenas amigo seria mucho pedir si me proporciona un ejemplo para la descarga la verdad no entiendo mucho de esto

    ResponderEliminar
    Respuestas
    1. Hola José ya coloque los ejemplos listos para la descarga. Saludos.

      Eliminar