<?php use_helper( 'UrlFunctions' ); ?>
<?php use_helper( 'UtilFunctions' ); ?>
<?php use_helper( 'IncludePartial' ); ?>

<div class="titleBody descripProy">
    <ul>
        <li>
            FORMATO 13.1: "REGISTRO DEL INVENTARIO PERMANENTE VALORIZADO"
            <span style="float:right;">
                <img src="<?=Constantes::ROOT_DIR_IMG?>common/buttons/btnXls.png" title="Exportar a Excel" style="cursor:pointer" onclick="exportarExcelRpt();">
            </span>
        </li>
    </ul>
</div>

<script>
openPopup = function()
{
    var s_param = "type/01";
    $( '#myIframe2' ).attr( 'src', '<?=buildUrlComplet( 'alm.php/transacciones/listItem' )?>' + s_param );
    $( '#dialog2' ).dialog( 'open' );	
}
asignarItem = function( id_item, item_descripcion )
{
    console.log( arguments );
    $( "#IdItem" ).val( id_item );
    $( "#content_desc_item" ).html( item_descripcion );
    $( "#tmp_id_item" ).val( id_item );
    closeWindow();
}
closeWindow = function()
{
    $( '#dialog' ).dialog( 'close' );
    $( '#dialog2' ).dialog( 'close' );
}
verificarCambios = function( s_value )
{
    if( s_value != $( "#tmp_id_item" ).val() )
    {
    	$( "#content_desc_item" ).html( "" );
    	$( "#tmp_id_item" ).val( "" );
    }
}
</script>

<script>
validacionForm = function()
{
    if( $( "#IdItem" ).val() == "" )
    {
        //alert( "Seleccione un Item." );
        //return false;
    }
    if( $( "#IdAlmacen" ).val() == "" )
    {
        alert( "Seleccione Almacen.." );
        return false;
    }
    return true;
}
exportarExcelRpt = function()
{
    if( validacionForm() )
    {
        $( "#export_excel" ).val( "1" );
        var strFormSerialize = $( 'form' ).serialize();
        window.open( '<?=buildUrl( "rep/kardexTreceUnoGrid" )?>' + '?' + strFormSerialize, '_BLANK' );
    }
}
findControl = function ()
{
    b_Control = validacionForm();
    if( b_Control )
    {
        strFormSerialize = $( 'form' ).serialize();
        relaodGrid( strFormSerialize );
    }
}
relaodGrid = function( s_url_param )
{
	blockContent( 'jqGridPager' );
    executeAjaxUpdater( 
            "jqGridPager", 
            "<?=buildUrl( 'rep/kardexTreceUnoGrid' )?>", 
            strFormSerialize, 
            function()
            {
            	unBlockContent( 'jqGridPager' );
                
            	//var column = $( '#content_all_row td:nth-child( 4 )' );
            	//modifyTableRowspan( column );
            }
      );
}
</script>

<div class="block">
    <form action="" method="post" name="form1" id="form1">
        <input type="hidden" name="IdCompania" value="<?=$IdCompania?>"/>
        <input type="hidden" name="export_excel" id="export_excel" value="">
        <table class="marco" style="background:#E3E9E2" width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td width="85%">
                    <table width="100%" cellspacing="0" cellpadding="0" border="0">
                        <tr>
                            <td nowrap="nowrap">
                                <table width="100%" cellspacing="1" cellpadding="0" border="0" class="SubCabecera">
                                    <tr>
                                        <td nowrap="nowrap"><label for="StockFlag" class="label">C&oacute;digo:</label></td>
                                        <td nowrap="nowrap">
                                            <input type="hidden" id="tmp_id_item" value="">
                                            <input type="text" class="text" name="IdItem" id="IdItem" 
                                                    onblur="verificarCambios( this.value );"
                                                    onfocus="this.select();"
                                                    value=""
                                                    />
                                            <input id="btnAgregar" type="button" class="button" value="Seleccionar" onclick="openPopup();"/>
                                        </td>
                                        
                                        <td nowrap="nowrap"><label for=IdAlmacen class="label">Almac&eacute;n:</label></td>
                                        <td nowrap="nowrap">
                                            <?=crearSelect( array( "IdAlmacen", "getIdAlmacen", "getDescripcionLocal", "opt_seleccione" => $opt_seleccione ), $a_ALM_AlmacenMast, "ALM00001" )?>
                                        </td>
                                        
                                        <td nowrap="nowrap"><label for=DescripcionCompleta class="label">Fecha ( Inicio ):</label></td>
                                        <td nowrap="nowrap">
                                            <input type="text" class="text" name="FechaDocumento1" id="FechaDocumento1" size="10" style="text-align:center;" value="<?=date( "Y-m" )?>-01">
                                            <script type="text/javascript">
                                            $( "#FechaDocumento1" ).datepicker( { dateFormat: "yy-mm-dd", changeYear:true, yearRange: "-1:+0", changeMonth: true, onClose: function (){ this.focus(); } } );
                                            </script>
                                        </td>
                                    </tr>
                                     <tr>
                                        <td colspan="2">
                                            <div class="labelData" id="content_desc_item" style="font-weight: bold;"> &nbsp; </div> 
                                        </td>
                                        <!-- <td> &nbsp; </td> -->
                                        
                                        <td nowrap="nowrap">
                                            &nbsp;
                                        </td>
                                        <td nowrap="nowrap">
                                            &nbsp;
                                        </td>
                                        <td nowrap="nowrap"><label for="IdItem" class="label">Fecha ( Fin ):</label></td>
                                        <td nowrap="nowrap">
                                            <input type="text" class="text" name="FechaDocumento2" id="FechaDocumento2" size="10" style="text-align:center;" value="<?=$FechaFin?>">
                                            <script type="text/javascript">
                                            $( "#FechaDocumento2" ).datepicker( { dateFormat: "yy-mm-dd", changeYear:true, yearRange: "-1:+0", changeMonth: true, onClose: function (){ this.focus(); } } );
                                            </script>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </td>
                <td>
                    <input type="button" onclick="findControl(1);" value="Buscar" class="button">
                    <!--<input type="button" onclick="findControlEx();" value="Excel" class="button">-->
                </td>
            </tr>
        </table>
    </form>
</div>

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

<script>
//ESCAPE, DETECTA EL F5, CTRL+F5
$( document ).bind
(
    'keyup', 
    function( e ) 
    {
        //console.log( e.which );
        if( e.which === 107 ) //+
        {
        	openPopup();
        }
        if( e.which === 27 ) //ESCAPE
        {
            $( "#IdItem" ).focus();
        }
        if( e.which === 13 ) //ESCAPE
        {
            console.log( "123" );
        }
    }
);
$( "#IdItem" ).focus();
<?php if( $s_IdItem ){ ?>
setTimeout
(
    function () 
    {
    	findControl();
    }, 
    1000
);
<?php } ?>
</script>
<?=crearFuentePopupIframe( array( "div_id"=>"dialog2", "iframe_id"=>"myIframe2", "popup_title"=>"Buscar Producto" ) )?>

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