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

<style type="text/css">
.ui-dialog .ui-dialog-titlebar-close 
{
    position: absolute;
    right: .3em;
    top: 50%;
    width: 20px;
    margin: -10px 0 0 0;
    padding: 1px;
    height: 20px;
    background-position: -96px -128px;
    /*background-image: url("images/ui-icons_056b93_256x240.png");*/
    background-image: url("<?=Constantes::ROOT_DIR_APP?>web/css/jquery/themes/start_1.12.1/images/ui-icons_056b93_256x240.png");
}
</style>

<div class="shadow-sm p-3 mb-2 bg-white rounded card card-body">
    <div class="row">
        <div class="col mb-1">
            <h4 class="text-info text-nowrap mb-0">Maestro de Producto</h4>
        </div>
        <div class="col mb-1 text-right">

            <!--<input type="button" class="btn btn-primary" value="Nuevo" onclick="location.href='<?=buildUrl( "item/addedit", "s_TipoProc=nvo" )?>';" >-->



        	<!--
            
            <div class="btn-group dropleft">
                <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    Opciones
                </button>
                <div class="dropdown-menu">
                    <a class="dropdown-item" href="javascript:void(0);" onclick="location.href='<?buildUrl( "item/addedit", "s_TipoProc=nvo" )?>';" title="Nuevo Item">Nuevo &nbsp;&nbsp; <i class="fa fa-file-alt" aria-hidden="true"></i></a>
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="<?/*=buildUrl( "item/exportExcel", "" )*/?>" target="_blank">Exportar Excel &nbsp;&nbsp; <i class="fa fa-list-ol" aria-hidden="true"></i> </a>
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="javascript:void(0)" onclick="" target="_blank" title="">Importar Excel &nbsp;&nbsp; <i class="fa fa-list-ol" aria-hidden="true"></i> </a>
                </div>
            </div>
           -->
            <div class="btn-group dropleft">
                <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    Opciones
                </button>
                <div class="dropdown-menu">
                    <a class="dropdown-item" href="javascript:void(0);" onclick="location.href='<?=buildUrl( "item/addedit", "s_TipoProc=nvo" )?>';" title="Nuevo Item">Nuevo &nbsp;&nbsp; <i class="fa fa-file-alt" aria-hidden="true"></i></a>
                    <!--<div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="javascript:void(0)" onclick="location.href='<?/*=buildUrl( "item/listStkMin", "" )*/?>';" title="Stock Minimo">Stock Minimo &nbsp;&nbsp; <i class="fa fa-list-ol" aria-hidden="true"></i> </a>
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="javascript:void(0)" onclick="location.href='<?/*=buildUrl( "item/listPromo", "" )*/?>';" title="">Promo / Pack &nbsp;&nbsp; <i class="fa fa-list-ol" aria-hidden="true"></i> </a>-->
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
changeIcon = function( elm, name )
{
    var elms    = $( elm ).find( "svg" );
    var elm_sel = elms.first();

    if( $( "#" + name ).is( ":visible" ) )
    {
        $( elm_sel ).removeClass( "fa-angle-down" );
        $( elm_sel ).addClass( "fa-angle-right" );
    }
    else
    {
        $( elm_sel ).removeClass( "fa-angle-right" );
        $( elm_sel ).addClass( "fa-angle-down" );
    }
}
</script>
<div id="accordion" class="mb-2">
    <div class="card">
        <div class="card-header">
            <a data-toggle="collapse" href="#collapseThree" aria-expanded="true" aria-controls="collapse1" 
                class="text-info" onclick="changeIcon( this,'collapseThree' );" id="cotent_a_collapse" 
                >
                <h5 class="mb-0"> Filtro <i class="fas fa-angle-right pull-right"></i></h5>
            </a>
        </div>
        <div id="collapseThree" class="collapse" data-parent="#accordion">
            <div class="card-body pb-1" style="background-color: antiquewhite;">
                <form class="" name="form1" id="form1" method="POST" action="">
                    <div class="form-row mx-0">
                        <div class="col-md-3 mb-1">
                            <label class="col-form-label" for="Codigo">C&oacute;digo</label>
                            <input type="text" class="form-control" name="Codigo" id="Codigo" placeholder="Codigo de Producto">
                        </div>
                        <div class="col-md-3 mb-1">
                            <label class="col-form-label" for="DescripcionCompleta">Descripci&oacute;n</label>
                            <input type="text" class="form-control" name="DescripcionCompleta" id="DescripcionCompleta" placeholder="Descripcion del Producto">
                        </div>
                        <div class="col-md-3 mb-1">
                            <label class="col-form-label" for="Estado">Estado</label>
                            <select class="form-control" name="Estado" id="Estado" style="background-color: khaki;">
                                <option value=""> - Seleccione - </option>
                                <option value="A" selected=""> ACTIVO </option>
                                <option value="I"> INACTIVO </option>
                            </select>
                        </div>
                        <div class="col-md-3 mb-1">
                            <label class="col-form-label" for="IdItemTipo">Tipo Producto</label>
                            <select class="form-control" name="IdItemTipo" id="IdItemTipo" style="background-color: khaki;">
                                <option value=""> - Seleccione - </option>
                                <?php foreach ( ALM_ItemTipoFN::selectActivos() as $i_Key => $o_ALM_ItemTipoBN ){ ?>
                                <option value="<?=$o_ALM_ItemTipoBN->getIdItemTipo()?>"> <?=$o_ALM_ItemTipoBN->getDescripcionLocal()?> </option>
                                <?php } ?>
                            </select>
                        </div>
                    </div>
                    <div class="form-row mx-0">
                        <div class="col-md-3 mb-1">
                            <label class="col-form-label" for="IdLinea">Linea</label>
                            <select class="form-control" name="IdLinea" id="IdLinea"
                                onchange="$('#IdFamilia')[0].options.length = 1; publicForSelectAjaxJSON('<?php echo buildUrl( 'item/request', '' ) ?>', $( 'form' ).serialize() + '&TipoProc=Familia', 'IdFamilia');"
                                 style="background-color: khaki;">
                                <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>
                        </div>
                        <div class="col-md-3 mb-1">
                            <label class="col-form-label" for="IdFamilia">Familia</label>
                            <select class="form-control" name="IdFamilia" id="IdFamilia"
                                onchange="$('#IdSubFamilia')[0].options.length = 1; publicForSelectAjaxJSON('<?php echo buildUrl( 'item/request' ) ?>', $( 'form' ).serialize() + '&TipoProc=SubFamilia', 'IdSubFamilia');"
                                 style="background-color: khaki;">
                                <option value=""> - Seleccione - </option>
                                <?php foreach ( $a_MST_ClaseFamilia as $i_Key => $o_MST_ClaseFamiliaBN ){ ?>
                                <option value="<?=$o_MST_ClaseFamiliaBN->getIdFamilia()?>"> <?=$o_MST_ClaseFamiliaBN->getDescripcion()?> </option>
                                <?php } ?>
                            </select>
                        </div>
                        <div class="col-md-3 mb-1">
                            <label class="col-form-label" for="IdSubFamilia">Sub-Familia</label>
                            <select class="form-control" name="IdSubFamilia" id="IdSubFamilia" style="background-color: khaki;">
                                <option value=""> - Seleccione - </option>
                                <?php foreach ( MST_ClaseSubFamiliaFN::selectActivos() as $i_Key => $o_MST_ClaseSubFamiliaBN ){ ?>
                                <option value="<?=$o_MST_ClaseSubFamiliaBN->getIdSubFamilia()?>"> <?=$o_MST_ClaseSubFamiliaBN->getDescripcion()?> </option>
                                <?php } ?>
                            </select>
                        </div>
                        <div class="col-md-3 mb-1">
                            <label class="col-form-label" for="IdMarca">Marca</label>
                            <select class="form-control" name="IdMarca" id="IdMarca" style="background-color: khaki;">
                                <option value=""> - Seleccione - </option>
                                <?php foreach ( $a_ALM_Marca as $i_Key => $o_ALM_MarcaBN ){ ?>
                                <option value="<?=$o_ALM_MarcaBN->getIdMarca()?>"> <?=$o_ALM_MarcaBN->getDescripcionLocal()?> </option>
                                <?php } ?>
                            </select>
                        </div>
                    </div>
                    <div class="text-center mt-2">
                        <button class="btn btn-primary text-center" type="button" onclick="findControl();">Buscar</button>
                        <button class="btn btn-primary text-center" type="reset" onclick="">Limpiar</button>
                        <a data-toggle="collapse" href="#collapseThree" class="text-info" onclick="changeIcon( $( '#cotent_a_collapse' )[0], 'collapseThree' );" style="background: none;">
                            Contraer <i class="fas fa-angle-up"></i>
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

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

<?php include_partial( "grid" ); ?>
<script>
$( document ).bind
(
    'keyup', 
    function( e ) 
    {
        if( e.which === 13 ) //ENTER
        {
            findControl();
        }
        if( e.which === 107 || e.which === 27 || e.which == 109 ) //tecla +
        {
            $( "#cotent_a_collapse" ).trigger( "click" );
        }
        <?php if( $b_Externo ){ ?>
        if( e.which === 27 ) //ESCAPE
        {
            parent.closeWindow();
        }
        <?php } ?>        
    }
);
</script>
