<table id="jqGrid"></table>
<div id="jqGridPager"></div>

<script>
    findControl = function ()
    {
        strFormSerialize = $( 'form' ).serialize();
        relaodGrid( strFormSerialize );
    }
    
    relaodGrid = function( s_url_param )
    {
        jQuery( '#jqGrid' ).jqGrid( 'clearGridData' );
        jQuery( '#jqGrid' ).jqGrid( 'setGridParam', { url: '<?=buildUrl('ptovta/grid','block=001')?>?' + s_url_param } );
        jQuery( '#jqGrid' ).trigger( 'reloadGrid' );
    }
    
    showView = function( i_Id )
    {
        $( '#myIframe' ).attr( 'src', '<?=buildUrl( 'ptovta/viewdel', 'block=001&s_TipoProc=shw&i_Id=' )?>' + i_Id );
        $( '#dialog' ).dialog( 'open' );
    }
    
    deleteRow = function( i_Id )
    {
        $( '#myIframe' ).attr( 'src', '<?=buildUrl( 'ptovta/viewdel', 'block=001&s_TipoProc=dlt&i_Id=' )?>' + i_Id );
        $( '#dialog' ).dialog( 'open' );
    }
    
    closeWindow = function( s_NameWin )
    {
        $( '#' + s_NameWin ).dialog( 'close' );
    }
</script>

<script>
    var s_Estado_Valores = { value: "A:Activo;I:Inactivo" };
    var s_Tipo_Valores = { value: "L:Litros;M:Masa;U:Unidad" };

    var jqGridContent = $( "#jqGrid" );
    jqGridContent.jqGrid
    (
        {
            // "IdSucursalDocumento", "CompaniaDesc", "SucursalDesc", "TipoDocumentoDesc", "DocumentoTicketFlag", "SerieFormato", "RangoDesdeFormato", 'RangoHastaFormato', "NumeroActual", "Estado"
            url         : '<?=buildUrl('ptovta/grid','block=001')?>',
            mtype       : "POST",
            datatype    : "json",
            editurl     : 'edicionData.php',                        
            colNames    : [ 'IdSucursalDocumento', 'Compania', 'Sucursal', 'TipoDocumento', 'EsTicket', 'Serie', 'Rango Inicial', 'Rango Final', 'Numero Actual', 'Estado',  '', '', '' ],
            colModel    : 
                          [
                            { name: 'IdSucursalDocumento', width: 0, align: 'center', hidden: true, hidedlg: false, editrules : { required: true }, key: true },
                            { name: 'CompaniaDesc',        width: ($( window ).width())/5, align: 'left', editable: true, sortable: true },
                            { name: 'SucursalDesc',        width: ($( window ).width())/5, align: 'center', editable: true, sortable: false },
                            { name: 'TipoDocumentoDesc',   width: ($( window ).width())/5, align: 'center', editable: true, sortable: false },
                            { name: 'DocumentoTicketFlag', width: ($( window ).width())/15,  align: 'center', editable: true, sortable: false },
                            { name: 'SerieFormato',        width: ($( window ).width())/15,  align: 'center', editable: true, sortable: false },
                            { name: 'RangoDesdeFormato',   width: ($( window ).width())/10,  align: 'center', editable: true, sortable: false },
                            { name: 'RangoHastaFormato',   width: ($( window ).width())/10,  align: 'center', editable: true, sortable: false },
                            { name: 'NumeroActual',        width: ($( window ).width())/10,  align: 'center', editable: true, sortable: false },
                            
                            { name: 'Estado',              width: ( $( window ).width() )/10, align: 'center', editable: false, formatter: 'select', edittype: "select", editoptions: s_Estado_Valores, sortable: false },
                            
                            { name: 'edit', width: 20, sortable: false, search: false,
                                formatter:function()
                                {
                                    return "<span style='cursor:pointer; margin: 0 auto;' class='ui-icon ui-icon-pencil' onclick='location.href=\"<?=buildUrl('ptovta/addedit', 'block=001&s_TipoProc=upd&i_Id=' )?>\" + $(this).parent().parent()[0].id;'></span>"
                                }
                            },
                            { name: 'details', width: 20, sortable: false, search: false, 
                                formatter:function()
                                {
                                    return "<span style='cursor:pointer; margin: 0 auto;' class='ui-icon ui-icon-document' onclick='showView( $(this).parent().parent()[0].id );'></span>"
                                }
                            },
                            { name: 'del', width: 20, sortable: false, search: false,
                                formatter:function()
                                {
                                    return "<span style='cursor:pointer; margin: 0 auto;' class='ui-icon ui-icon-trash' onclick='deleteRow( $(this).parent().parent()[0].id );'></span>"
                                }
                            }
                          ],
			viewrecords : true,
			height      : $(window).height()-200, 
			width       : $(window).width() - 20,
            //width       : 600,
            //autowidth   : true,
            sortable    : true,
            multiSort   : true,
            //width: null,
            //shrinkToFit: false,
            emptyrecords: "No se encontro registros",
            //height      : 480,
            rowNum      : 100,
            rownumbers  : true, // show row numbers
            //multiselect : true,//SELECCION MULTIPLE
            pager       : "#jqGridPager",
            //caption     : "Products / Category Primary Grid View"
            onCellSelect: function()
            {

            },
            beforeSelectRow: function ( rowid, e ) 
            {

            }
        }
    );

    $( "#jqGrid" ).jqGrid( 'bindKeys' );
    
    $(window).on
    ( 
        "resize", 
        function () 
        {
            var newWidth = $( "#jqGrid" ).closest( ".ui-jqgrid" ).parent().width() - 20;
            jqGridContent.jqGrid( "setGridWidth", newWidth, true);
        }
    );
</script>

<?=crearFuentePopupIframe( array( "div_id"=>"dialog", "iframe_id"=>"myIframe", "popup_title"=>"Resumen", "modal"=>true ) )?>