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

<div class="titleBody descripProy">
    <ul>
        <li>
            Posici&oacute;n de Inventario
        </li>
    </ul>
</div>

<style type="text/css">
.table td, .table th 
{
    /*padding: .2rem;
    vertical-align: top;
    border-top: 1px solid #dee2e6;*/
}
</style>

<script type="text/javascript">
verificarCambios = function( s_value )
{
    if( s_value != $( "#tmp_id_item" ).val() )
    {
        $( "#content_desc_item" ).html( "" );
        $( "#tmp_id_item" ).val( "" );
    }
}
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 );
    ocultarModal( 'exampleModalCenter' );
    findControl();
}
findControl = function ()
{
    if( $( "#IdItem" ).val() == "" )
    {
        //alert( "Seleccione un Item." );
        //return false;
    }
    var strFormSerialize = $( 'form' ).serialize();
    blockContent( 'content_grid' );
    executeAjaxUpdater
    (
        "content_grid",
        "<?=buildUrl( 'bi/gridPosicioninv' )?>", 
        strFormSerialize,
        function( o_json )
        {
            unBlockContent( 'content_grid' );
            if( o_json.error )
            {
                
                alert( o_json.mensaje_error );
                return false;
            }
        } 
    );
}
</script>

<div id="content_alert" style=""></div>

<div class="shadow-lg p-3 mb-3 bg-white rounded">
    <form action="" method="post" name="form1" id="form1">
        <input type="hidden" name="IdCompania" value="<?=$IdCompania?>"/>
        <div class="form-row mx-0">
            <div class="col-sm-10 mb-1">
                <div class="table-responsive">
                    <table  class="table table-borderless" style="margin-bottom: 0;">
                        <tr>
                            <td  nowrap="nowrap" align="right" scope="row"><label for="IdItem">C&oacute;digo:</label></td>
                            <td nowrap="nowrap" >
                                <input type="hidden" id="tmp_id_item" value="">
                                <div class="input-group mb-0 flex-nowrap">
                                    <input type="text" class="form-control form-control-sm" style="width: 80px; text-align: center;" autocomplete="off" name="IdItem" id="IdItem" 
                                        onfocus="this.select();" onblur="verificarCambios( this.value );" value="" 
                                        >
                                    <div class="input-group-append">
                                        <button class="btn btn-outline-secondary btn-sm" type="button" onclick="buscarProductosPopup();">Buscar</button>
                                    </div>
                                </div>
                            </td>

                            <td  nowrap="nowrap" align="right" scope="row">Linea :</td>
                            <td nowrap="nowrap">
                                <select class="form-control form-control-sm" id="IdLinea" name="IdLinea" style="width: 150px;"
                                    onchange="pr( '123' ); $('#IdFamilia')[0].options.length = 1; 
                                    publicForSelectAjaxJSON('<?php echo buildUrlComplet( 'mst.php/item/request', '' ) ?>', $( 'form' ).serialize() + '&TipoProc=Familia', 'IdFamilia'); ">
                                    <option value=""> - Seleccione - </option>
                                    <?php foreach ( $a_MST_ClaseLinea as $i_Key => $o_MST_ClaseLineaBN ){ ?>
                                    <option value="<?=$o_MST_ClaseLineaBN->getIdLinea()?>" > <?=$o_MST_ClaseLineaBN->getDescripcion()?> </option>
                                    <?php } ?>
                                </select>
                            </td>
                            <td  nowrap="nowrap" align="right">Familia :</td>
                            <td nowrap="nowrap">
                                <select class="form-control form-control-sm" id="IdFamilia" name="IdFamilia" style="width: 150px;" onchange="">
                                    <option value=""> - Seleccione - </option>
                                </select>
                            </td>
                            <td  nowrap="nowrap" align="right" scope="row">Marca :</td>
                            <td nowrap="nowrap">
                                <select class="form-control form-control-sm" id="IdMarca" name="IdMarca" style="width: 150px;">
                                    <option value=""> - Seleccione - </option>
                                    <?php foreach ( $a_ALM_Marca as $i_Key => $a_ALM_MarcaBN ){ ?>
                                    <option value="<?=$a_ALM_MarcaBN->getIdMarca()?>" > <?=$a_ALM_MarcaBN->getDescripcionLocal()?> </option>
                                    <?php } ?>
                                </select>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="col-sm-2 mb-1 ">
                <button type="button" class="btn btn-primary btn-block" onclick="findControl();">Buscar</button>
                <button type="button" class="btn btn-primary btn-block" onclick="location.reload();">Limpiar</button>
            </div>
        </div>
    </form>
</div>
<!-- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
<style type="text/css">
#exampleModalCenter .modal
{
    padding: 0 !important;
}
#exampleModalCenter .modal-dialog {
    max-width: 95% !important;
    height: 90%;
    /*  padding: 0;
    margin: 0;*/
}

#exampleModalCenter .modal-content 
{
    /*border-radius: 0 !important;*/
    height: 90%;
}
</style>
<!-- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -->

<!-- Modal 1-->
<div class="modal hide fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLongTitle">Buscar Producto</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <iframe id="iframe_id" src="" style="zoom:0.60;" width="99.6%" height="99.6%" frameborder="0"></iframe>
            </div>
            <!--<div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
                <button type="button" class="btn btn-primary">Save changes</button>
            </div>-->
        </div>
    </div>
</div>
<script type="text/javascript">
buscarProductosPopup = function()
{
    var s_param = "type/0";
    $( '#iframe_id' ).attr( "src", '<?=buildUrlComplet( 'alm.php/transacciones/listItem' )?>' + s_param );
    $( '#exampleModalCenter' ).modal( { show:true } );
}
ocultarModal = function( name_modal )
{
    $( '#' + name_modal ).modal( 'hide' );
}
</script>
<!-- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -->

<div id="content_grid"></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();
        }
    }
);
$( "#IdItem" ).focus();

<?php if( $s_IdItem ){ ?>
setTimeout
(
    function () 
    {
        findControl();
    }, 
    1000
);
<?php } ?>

</script>