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

<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>

<script>
imprimirRpt = function()
{
	var strFormSerialize = $( 'form' ).serialize();
	strFormSerialize += "&controler=printStock";
	window.open( '<?=buildUrl( "rep/printStock" )?>' + '?' + strFormSerialize, '_BLANK' );
}
excelRpt = function()
{
    var strFormSerialize = $( 'form' ).serialize();
    strFormSerialize += "&excel=1";
    window.open( '<?=buildUrl( "rep/printStock" )?>' + '?' + strFormSerialize, '_BLANK' );
}
excelRptPdf = function()
{
    var strFormSerialize = $( 'form' ).serialize();
    window.open( '<?=buildUrl( "rep/printStockPdf" )?>' + '?' + strFormSerialize, '_BLANK' );
}
</script>


<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"> Stock por Almacén</h4>
        </div>
        <div class="form-row mx-1">
            <div class="btn-group dropleft">
                <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    Menu
                </button>
                <div class="dropdown-menu">
                    <a class="dropdown-item" href="javascript:void(0);" onclick="imprimirRpt();" title="Imprimir">Imprimir &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="excelRpt();" title="Exportar Excel">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="excelRptPdf();" title="Exportar Excel">Exportar Pdf &nbsp;&nbsp; <i class="fa fa-list-ol" aria-hidden="true"></i> </a>
                    <div class="dropdown-divider"></div>
                </div>
            </div>
        </div>
    </div>
</div>

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

<div id="accordion" class="mb-2">
<form action="" method="post" name="form1" id="form1">
    <input type="hidden" name="IdCompania" value="<?=$IdCompania?>"/>
    <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 show" 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-2 mb-1">
                            <label class="col-form-label" for="IdSucursal">Sucursal</label>
                            <select class="form-control" name="IdSucursal" id="IdSucursal"  style="background-color: khaki;"
                                    onchange="$('#IdAlmacen')[0].options.length = 1; publicForSelectAjaxJSON('<?php echo buildUrlComplet( 'mst.php/item/request' ) ?>', $( 'form' ).serialize() + '&TipoProc=getAlmacen', 'IdAlmacen');">
                                <option value=""> - Seleccione - </option>
                                <?php foreach ( GSS_SucursalFN::selectActivos() as $s_Key => $o_GSS_SucursalBN ){ ?>
                                <option value="<?=$o_GSS_SucursalBN->getIdSucursal()?>" <?php if( $o_GSS_SucursalBN->getIdSucursal()==myUser::getUser()->getIdSucursal() ){ echo "SELECTED"; } ?> ><?=$o_GSS_SucursalBN->getDescripcion()?></option>
                                <?php } ?>
                            </select>
                        </div>
                        <div class="col-md-2 mb-1">
                            <label class="col-form-label" for="IdAlmacen">Almacen</label>
                            <select class="form-control" name="IdAlmacen" id="IdAlmacen"  style="background-color: khaki;">
                                <option value=""> - Seleccione - </option>
                            </select>
                        </div>
                        <div class="col-md-2 mb-1">
                            <label class="col-form-label" for="IdLinea">Linea</label>
                            <select class="form-control" id="IdLinea" name="IdLinea" style="background-color: khaki;"
                                    onchange="$('#IdFamilia')[0].options.length = 1; publicForSelectAjaxJSON('<?php echo buildUrlComplet( 'mst.php/item/request' ) ?>', $( 'form' ).serialize() + '&TipoProc=Familia', 'IdFamilia');">
                                <option value=""> - Seleccione - </option>
                                <?php foreach ( MST_ClaseLineaFN::selectActivos() as $o_MST_ClaseLineaBN ){ ?>
                                <option value="<?=$o_MST_ClaseLineaBN->getIdLinea()?>" > <?=$o_MST_ClaseLineaBN->getDescripcion()?> </option>
                                <?php } ?>
                            </select>
                        </div>
                        <div class="col-md-2 mb-1">
                            <label class="col-form-label" for="IdFamilia">Familia</label>
                            <select class="form-control" name="IdFamilia" id="IdFamilia"  style="background-color: khaki;"
                                    onchange="$('#IdSubFamilia')[0].options.length = 1; publicForSelectAjaxJSON('<?php echo buildUrlComplet( 'mst.php/item/request' ) ?>', $( 'form' ).serialize() + '&TipoProc=SubFamilia', 'IdSubFamilia');">
                                <option value=""> - Seleccione - </option>
                            </select>
                        </div>
                        <div class="col-md-4 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>
                            </select>
                        </div>
                    </div>
                    
                    <div class="form-row mx-0">
                        <div class="col-md-2 mb-1">
                            <label class="col-form-label" for="IdItem">Codigo</label>
                            <input type="text" class="form-control" name="IdItem" id="IdItem" autocomplete="off"></td>
                        </div>
                        <div class="col-md-2 mb-1">
                            <label class="col-form-label" for="DescripcionCompleta">Descripcion</label>
                            <input type="text" class="form-control" name="DescripcionCompleta" id="DescripcionCompleta">
                        </div>
                        <div class="col-md-2 mb-1">
                            <label class="col-form-label" for="IdMarca">Marca</label>
                            <?php crearCombo( array( "id"=>"IdMarca", "ParamId"=>"getIdMarca", "ParamDesc"=>"getDescripcionLocal", ), $a_ALM_Marca ); ?>
                        </div>
                        <div class="col-md-2 mb-1">
                            <label class="col-form-label" for="IdItemTipo">Tipo Item</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 class="col-md-4 mb-1">
                            <label class="col-form-label" for="IdMarca">Opciones</label>
                            
                            <div class="custom-control mt-1" > <!-- class -> custom-checkbox -->
                                <div class="custom-control custom-radio custom-control-inline">
                                    <input type="radio" id="customRadioInline1" name="OpcionesRadio" value="T" class="custom-control-input" checked="checked">
                                    <label class="custom-control-label" for="customRadioInline1">Todo</label>
                                </div>
                                <div class="custom-control custom-radio custom-control-inline">
                                    <input type="radio" id="customRadioInline2" name="OpcionesRadio" value="F" class="custom-control-input">
                                    <label class="custom-control-label" for="customRadioInline2">Fisico>0</label>
                                </div>
                                <div class="custom-control custom-checkbox custom-control-inline">
                                    <input type="checkbox" id="IncluirLote" name="IncluirLote" value="1" class="custom-control-input">
                                    <label class="custom-control-label" for="IncluirLote">Incluir Lote</label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-row mx-0">
                        <div class="col-md-2 mb-1">
                            <label class="col-form-label" for="IdProveedor">Proveedor</label>
                            <select class="form-control" name="IdProveedor" id="IdProveedor">
                                <option value=""> - Seleccione - </option>
                                <?php foreach( $a_MST_PersonaMast  as $o_MST_PersonaMastBN ){ ?>
                                    <option value="<?=$o_MST_PersonaMastBN->getIdPersona()?>"> <?=$o_MST_PersonaMastBN->getNombreCompletoLLeno()?> </option>
                                <?php } ?>
                            </select>
                        </div>
                        <div class="col-md-2 mb-1">
                            <label class="col-form-label" for="IdReferencia">Referencia</label>
                            <!--<select class="form-control" name="IdReferencia" id="IdReferencia">
                                <option value=""> - Seleccione - </option>
                                <?php /*foreach( $a_MST_ReferenciaProducto  as $o_MST_ReferenciaProductoBN ){ */?>
                                    <option value="<?php /*=$o_MST_ReferenciaProductoBN->getIdReferencia()*/?>"> <?php /*=$o_MST_ReferenciaProductoBN->getDescripcion()*/?> </option>
                                <?php /*} */?>
                            </select>-->
                            <input type="text" id="IdReferencia" name="IdReferencia" value="" class="form-control" autocomplete="off" >
                        </div>
                        <div class="col-md-2 mb-1">
                            <label class="col-form-label" for="IdColor">Color</label>
                            <select class="form-control" name="IdColor" id="IdColor">
                                <option value=""> - Seleccione - </option>
                                <?php foreach( $a_MST_Color  as $o_MST_ColorBN ){ ?>
                                    <option value="<?=$o_MST_ColorBN->getIdColor()?>"> <?=$o_MST_ColorBN->getCodigo()?> - <?=$o_MST_ColorBN->getDescripcion()?>  </option>
                                <?php } ?>
                            </select>
                        </div>
                        <div class="col-md-2 mb-1">
                            <label class="col-form-label" for="IdCatTalla">Categoria Talla</label>
                            <select class="form-control" name="IdCatTalla" id="IdCatTalla">
                                <option value=""> - Seleccione - </option>
                                <?php foreach( $a_MST_CategoriaTalla  as $o_MST_CategoriaTallaBN ){ ?>
                                    <option value="<?=$o_MST_CategoriaTallaBN->getIdCatTalla()?>"> <?=$o_MST_CategoriaTallaBN->getDescripcion()?>  </option>
                                <?php } ?>
                            </select>
                        </div>
                        <div class="col-md-2 mb-1">
                            <label class="col-form-label" for="IdTalla">Talla</label>
                            <input type="text" class="form-control" name="IdTalla" id="IdTalla" onfocus="this.select();" autocomplete="off">
                        </div>
                    </div>
                    <div class="text-center mt-2">	
                        <button class="btn btn-primary text-center" type="button" onclick="findControl();">Buscar</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>
    </form>
</div>

<?php include_partial( "grid" ); ?>

<script>
$( "#IdSucursal" ).trigger( "change" );
$( document ).bind
(
    'keyup', 
    function( e ) 
    {
        pr( e.which );
        if( e.which == 13 ) //ENTER
        {
            findControl();
        }
        if( e.which == 107 || e.which == 27 || e.which == 109 ) //tecla + | ESC | -
        {
            $( "#cotent_a_collapse" ).trigger( "click" );
        }        
    }
);
</script>