<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( 'aprobacion/grid' )?>?' + s_url_param } );
    jQuery( '#jqGrid' ).trigger( 'reloadGrid' );
}

showView = function( i_Id )
{
    $( '#myIframe' ).attr( 'src', '<?=buildUrl( 'aprobacion/process', 's_TipoProc=shw&i_Id=' )?>' + i_Id );
    $( '#dialog' ).dialog( 'open' );
}

closeWindow = function()
{
    $( '#dialog' ).dialog( 'close' );
}

showViewAprob = function( i_Id )
{
    $( '#myIframe' ).attr( 'src', '<?=buildUrl( 'oc/viewdel', 's_TipoProc=apr&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 s_TipoOC_Valores = { value: "N:NORMAL;T:TRANSFERENCIA;" };

    var jqGridContent = $( "#jqGrid" );
    jqGridContent.jqGrid
    (
        {
        	url         : 'nothing',
            mtype       : "POST",
            datatype    : "json",
            editurl     : 'edicionData.php',                        
            colNames    : [ 'IdOrdenCompraConcat', 'Nro Orden', 'Clasificación', 'Proveedor', 'Tipo', 'Moneda', 'Monto', 'Fecha Crea', 'Estado', '' ],
            colModel    : 
                          [
                            { name: 'IdOrdenCompraConcat',    width: 0,   align: 'center', hidden: true, hidedlg: false, editrules : { required: true }, key: true },
                            { name: 'IdOrdenCompra',          width: 60,  align: 'center', editable: false, sortable: true },
                            { name: 'OrdenClasificacionDesc', width: 90,  align: 'center', editable: true, sortable: true },
                            { name: 'NombreProveedor',        width: 210, align: 'left', editable: false, sortable: false },
                            { name: 'TipoOCDesc',           width: 90, align: 'center', editable: false, sortable: false },
                            { name: 'MonedaDesc',           width: 90, align: 'center', editable: true, sortable: true },
                            { name: 'FormatMontoBruto',       width: 90,  align: 'right', editable: true, sortable: true },
                            { name: 'FechaCreacion',          width: 90,  align: 'center', editable: false, sortable: true, formatter: function( cellvalue ){ return cellvalue.substring(0, 10); } },
                            { name: 'EstadoDesc',             width: 90,  align: 'center', editable: true, sortable: true },
                            
                            { 
                                name: 'edit', width: 25, sortable: false, search: false, align: 'center',
                                formatter:function()
                                {
                                    return "<span style='cursor:pointer; margin: 0 auto;' class='ui-icon ui-icon-gear' title='Aprobar Orden de Compra' onclick='showViewAprob( $(this).parent().parent()[0].id );'></span>";
                                }
                            }
                          ],
			viewrecords : true,
			height      : $(window).height()-200, 
			width       : $(window).width() - 20,
            sortable    : true,
            multiSort   : true,
            emptyrecords: "No se encontro registros",
            rowNum      : 15,
            rownumbers  : true, // 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;
            if( newWidth <= 705 )
            {
                jqGridContent.jqGrid( "setGridWidth", newWidth, false );
            }
            else
            {
                jqGridContent.jqGrid( "setGridWidth", newWidth, true);
            }
        }
    );
    if( $( "#jqGrid" ).closest( ".ui-jqgrid" ).parent().width() <= 705 )
    {
        jqGridContent.jqGrid( "setGridWidth", $( "#jqGrid" ).closest( ".ui-jqgrid" ).parent().width() - 5, false );
        //jqGridContent.jqGrid( "setGridWidth", $( "#jqGrid" ).closest( ".ui-jqgrid" ).parent().height() - 270, false );
    }
    else
    {
        jqGridContent.jqGrid( "setGridWidth", $( "#jqGrid" ).closest( ".ui-jqgrid" ).parent().width() - 5, true);
    }
    setTimeout( "findControl();", 500 );
</script>

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