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

<script>
findControl = function ()
{
    if( $( "#IdItem" ).val() == "" )
    {
        alert( "Seleccione un Item." );
        return false;
    }
    if( $( "#IdAlmacen" ).val() == "" )
    {
        alert( "Seleccione Almacen.." );
        return false;
    }
    strFormSerialize = $( 'form' ).serialize();
    relaodGrid( strFormSerialize );
}

relaodGrid = function( s_url_param )
{
    jQuery( '#jqGrid' ).jqGrid( 'clearGridData' );
    jQuery( '#jqGrid' ).jqGrid( 'setGridParam', { url: '<?=buildUrl( 'rep/gridMov' )?>?' + s_url_param } );
    jQuery( '#jqGrid' ).trigger( 'reloadGrid' );
}

showView = function( i_Id )
{
	$( '#myIframe' ).attr( 'src', '<?=buildUrlComplet( 'alm.php/transacciones/viewdel', 's_TipoProc=shw&i_Id=' )?>' + i_Id );
    $( '#dialog' ).dialog( 'open' );
}
</script>

<script>
    var s_Estado_Valores = { value: "PR:Preparación;RE:Rechazado;AP:Aprobado;AN:Anulado;CO:Compleatado" };

    var jqGridContent = $( "#jqGrid" );
    jqGridContent.jqGrid
    (
        {
            url         : 'nothing',
            mtype       : "POST",
            datatype    : "json",
            editurl     : 'edicionData.php',                        
            colNames    : [ 'Id', 'Fecha', 'Almacen', 'Transacción', 'Documento', 'Persona', 'Ingreso', 'Salida', 'Stock Actual', 'Lote', 'Usuario', '' ],
            colModel    : 
                          [
                            { name: 'IdItem',                 width: 0, align: 'center', hidden: true, hidedlg: false, editrules : { required: true }, key: true },
                            { name: 'FechaTransaccion',       width: ($( window ).width())/18, align: 'center', editable: false, sortable: false },
                            { name: 'DescripcionAlmacen',     width: ($( window ).width())/18, align: 'center', editable: false, sortable: false },
                            { name: 'TransaccionDesc',        width: ($( window ).width())/12, align: 'center', editable: false, sortable: false },
                            { name: 'DocumentoRefFiscal',     width: ($( window ).width())/13, align: 'center', editable: false, sortable: false },
                            { name: 'PerProvClieDescripcion', width: ($( window ).width())/5, align: 'left', editable: false, sortable: false },
                            { name: 'StockIngreso',           width: ($( window ).width())/20, align: 'center', editable: false, sortable: false },
                            { name: 'StockSalida',            width: ($( window ).width())/20, align: 'center', editable: false, sortable: false },
                            { name: 'StockActual',            width: ($( window ).width())/20, align: 'center', editable: false, sortable: false },
                            { name: 'IdLote',                 width: ($( window ).width())/18, align: 'center', editable: false, sortable: false },
                            
                            
                            { name: 'UsuarioCreacion',        width: ($( window ).width())/18, align: 'center', editable: false, sortable: false },
                            
                            { name: 'edit', width: 20, sortable: false, search: false,
                                formatter:function()
                                {
                                	var o_Data = arguments[2];
                                    if( $( "#tmp_id_item" ).val() == "" )
                                    {
                                    	$( "#tmp_id_item" ).val( o_Data.IdItem );
                                        $( "#content_desc_item" ).html( o_Data.DescripcionItem );
                                    }
                                    if( o_Data.ReferenciaTipoDocumento == "NT" )
                                    {
                                        return "<span style='cursor:pointer; margin: 0 auto;' class='ui-icon ui-icon-document' title='Mostrar Detalles' onclick='showView( \""+o_Data.IdConcatTrx+"\" );'></span>"
                                    }
                                    return "";
                                }
                            }
                          ],
			viewrecords : true,
			height      : $(window).height()-200, 
			width       : $(window).width() - 20,
            sortable    : true,
            multiSort   : true,
            emptyrecords: "No se encontro registros",
            rowNum      : 9999,
            rownumbers  : false, // show row numbers
            pager       : "#jqGridPager",
            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"=>"dialog2", "iframe_id"=>"myIframe2", "popup_title"=>"Buscar Item", "popup_width"=>"580", "popup_height"=>"350" ) )?>

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