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

<div class="titleBody descripProy">
    <ul>
        <li>
            Producto m&aacute;s Vendido
            <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/0";
    $( '#myIframe' ).attr( 'src', '<?=buildUrlComplet( 'alm.php/transacciones/listItem' )?>' + s_param );
    $( '#dialog' ).dialog( 'open' );	
}
asignarItem = function( id_item, item_descripcion )
{
    console.log( arguments );
    $( "#ItemCodigo" ).val( id_item );
    $( "#content_desc_item" ).html( item_descripcion );
    $( "#tmp_id_item" ).val( id_item );
}
closeWindow = function()
{
    $( '#dialog' ).dialog( 'close' );
}
verificarCambios = function( s_value )
{
    if( s_value != $( "#tmp_id_item" ).val() )
    {
    	$( "#content_desc_item" ).html( "" );
    	$( "#tmp_id_item" ).val( "" );
    }
}
</script>
<script>
imprimirRpt = function()
{
    var strFormSerialize = $( 'form' ).serialize();
    window.open( '<?=buildUrl( "rep/gridItemResumen" )?>' + '?' + strFormSerialize, '_BLANK' );
}
exportarExcelRpt = function()
{
    var strFormSerialize = $( 'form' ).serialize();
    strFormSerialize +=  "&export_excel=1";
    window.open( '<?=buildUrl( 'rep/gridItemResumen' )?>' + '?' + strFormSerialize, '_BLANK' );
}
</script>
<div class="block">
    <form action="" method="post" name="form1" id="form1">
        <input type="hidden" name="IdCompania" value="<?=$IdCompania?>"/>
        <table class="marco" style="background:#E3E9E2" width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td width="95%">
                    <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="ItemCodigo" class="label">C&oacute;digo:</label></td>
                                        <td nowrap="nowrap">
                                            <input type="hidden" id="tmp_id_item" value="">
                                            <input type="text" class="text" name="ItemCodigo" id="ItemCodigo"  size="16"
                                                    onblur="verificarCambios( this.value );"
                                                    onfocus="this.select();"
                                                    value="<?=$s_IdItem?>"
                                                    />
                                            <script type="text/javascript">
                                            $( "#ItemCodigo" ).keypress
                                            ( 
                                                function( e ) 
                                                {
                                                    //console.log( e.which );
                                                    if( e.which == 43 ){ return false; }
                                                    if( e.which == 13 ){ findControl( 1 ); return false; }
                                                    return true;
                                                }
                                            );
                                            </script>
                                            <input id="btnAgregar" type="button" class="button" value="Buscar" onclick="openPopup();"/>
                                        </td>
                                        
                                        <td nowrap="nowrap"><label for=IdProveedor class="label">Proveedor:</label></td>
                                        <td nowrap="nowrap">
                                            <?=crearCombo( array( "name"=>"IdProveedor", "ParamId"=>"getIdPersona", "ParamDesc"=>"getNombreCompleto", "style"=>"width:55%" ), MST_ProveedorMastFN::selectActivos(), "XXXXX" )?>
                                        </td>
                                        
                                        <td nowrap="nowrap"><label for=IdLinea class="label">Linea:</label></td>
                                        <td nowrap="nowrap">
                                            <select class="combo" name="IdLinea" id="IdLinea" style="width:70%;">
                                                <option value=""> - Seleccione - </option>
                                                <?php foreach ( MST_ClaseLineaFN::selectActivos() as $s_Key => $o_MST_ClaseLineaBN ){ ?>
                                                <option value="<?=$o_MST_ClaseLineaBN->getIdLinea()?>" ><?=$o_MST_ClaseLineaBN->getDescripcion()?> </option>
                                                <?php } ?>
                                            </select>
                                        </td>
                                        <td nowrap="nowrap"><label for=Vendedor class="label">Vendedor:</label></td>
                                        <td nowrap="nowrap">
                                            <?=crearCombo( array( "name"=>"Vendedor", "ParamId"=>"getCodigoVendedor", "ParamDesc"=>"getNombreVendedor", "required"=>"required", "style"=>"width:70%" ), $a_VTA_Vendedor ); ?>
                                        </td>
                                    </tr>
                                     <tr>
                                        <td nowrap="nowrap"><label for="CodigoBarras" class="label">Cod Barras:</label></td>
                                        <td> <input type="text" class="text" name="CodigoBarras" id="CodigoBarras" size="16" /> </td>
                                        
                                        <td nowrap="nowrap"><label for=AlmacenCodigo class="label">Almac&eacute;n:</label></td>
                                        <td nowrap="nowrap">
                                            <select class="combo" name="AlmacenCodigo" id="AlmacenCodigo" style="width:70%;">
                                                <?php foreach ( ALM_AlmacenMastFN::recuperarAlmacenParaVentas() as $s_Key => $o_ALM_AlmacenMastBN ){ ?>
                                                <option value="<?=$o_ALM_AlmacenMastBN->getIdAlmacen()?>" ><?=$o_ALM_AlmacenMastBN->getDescripcionLocal()?> </option>
                                                <?php } ?>
                                            </select>
                                        </td>
                                        
                                        <td nowrap="nowrap">
                                                <label for="IdItem" class="label">Fecha:</label>
                                        </td>
                                        <td nowrap="nowrap">
                                            <input type="text" class="text" name="FechaDocumento1" id="FechaDocumento1" size="10" style="text-align:center;" value="<?=$FechaInicio?>">
                                            <script type="text/javascript">
                                            $( "#FechaDocumento1" ).datepicker( { dateFormat: "yy-mm-dd", changeYear:true, yearRange: "-3:+1", changeMonth: true, onClose: function (){ this.focus(); } } );
                                            </script>
                                            <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: "-3:+1", 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="imprimirRpt();" value="Imprimir" class="button">
                    <input type="hidden" name="export_excel" id="export_excel" value="">
                    <!--<input type="button" onclick="findControlEx();" value="Excel" class="button">-->
                </td>
            </tr>
        </table>
    </form>
</div>
<?php include_partial( "gridItemResumen" ); ?>
<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();
        }
    }
);
$( "#IdItem" ).focus();
<?php if( $s_IdItem ){ ?>
setTimeout
(
    function () 
    {
    	findControl();
    }, 
    1000
);
<?php } ?>
</script>
