<div ng-include="'views/pageHeader.html'"></div>
<div class="container" style="">
    <div ng-controller="localCadastroController" ng-init="listarEdificios(null)">
        <div class="col-xs-6 col-md-6" style="padding:0">
            <label style="color:#333366; font-size:14pt">BENS POR LOCAL</label>

        </div>
        <div class="col-xs-6 col-md-6" role="navigation" ng-show="mostrartab[0]" style="text-align:right; padding:0">
            <button class="btn btn-default btn-md" ng-click="openModalEtiquetas()">
                Etiquetas
            </button>
            <button class="btn btn-default btn-md" ng-click="openModalCentroCustos()" ng-disabled="root_podeMexerDadosDoBem===false">
                C. Custos
            </button>
            <div class="btn-group" style="text-align:left">
                                <button type="button"
                        
                        class="btn btn-default btn-md dropdown-toggle"
                        data-toggle="dropdown">
                    <span class="glyphicon glyphicon-file"></span> Editar <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" role="menu">
                    <li ng-click="copiarItem(selectedCadastro)" ng-class="{disabled:selectedCadastro==null || mnuDados.PCriar==false}" ng-show="root_podeMexerDadosDoBem===true">
                        <a href="">Copiar</a>
                    </li>
                    <li ng-click="confirmarDuplicarCadastro(itemAcopiar)"
                        popover-placement="left"
                        popover-trigger="mouseenter"
                        data-popover="{{mostrarAreaTransferencia()}}"
                        ng-class="{disabled:itemAcopiar==null || mnuDados.PCriar==false}"><a href="">Colar</a></li>
                    <li ng-click="confirmarApagarCadastro(selectedCadastro)" ng-class="{disabled:selectedCadastro==null || mnuDados.PCriar==false}" ng-show="root_podeMexerDadosDoBem===true"><a href="">Apagar</a></li>
                    <li ng-click="openModalMudarDeLocal()" ng-class="{disabled:mnuDados.PCriar==false}" ng-show="root_podeMexerDadosDoBem===true"><a href="">Mover bens de local</a></li>
                    <li ng-click="openModalResponsavelLocal()" ng-class="{disabled:mnuGESTAO.PCriar==false || mostraAplicarGestor()===false }"><a href="">Gestor</a></li>
                </ul>
            </div>


            <button popover-placement="top"
                    popover-trigger="mouseenter"
                    data-popover="Editar"
                    ng-click="openModalNovoCadastro(selectedCadastro);" type="button"
                    ng-show="items.length>0 && selectedCadastro!=null"
                    ng-disabled="mnuDados.PEditar==false || root_podeMexerDadosDoBem===false"
                    class="btn btn-default btn-md">
                <span class="glyphicon glyphicon-pencil"></span>
            </button>
            <button popover-placement="top"
                    popover-trigger="mouseenter"
                    data-popover="Novo Registo"
                    ng-click="openModalNovoCadastro();" type="button"
                    ng-disabled="mnuDados.PCriar==false"
                    class="btn btn-primary btn-md">
                <span class="glyphicon glyphicon-plus"></span>
            </button>

        </div>

        <!--Botoes do separador 2-->
        <div class="col-xs-6 col-md-6" role="navigation" ng-show="mostrartab[1]" style="text-align:right; padding:0">
            <button popover-placement="top"
                    popover-trigger="mouseenter"
                    data-popover="Guardar"
                    ng-click="guardarConferencias()"
                    type="button"
                    ng-show="listaVerificacoes.length>0 && IdConf>0"
                    ng-disabled="conferenciaTrancada()"
                    class="btn btn-success btn-md">
                <span class="glyphicon glyphicon-ok"></span>
            </button>

            <div class="btn-group" style="text-align:left">
                <button type="button"
                        class="btn btn-default btn-md dropdown-toggle"
                        ng-show="listaVerificacoes.length>0"
                        data-toggle="dropdown">
                    <span class="glyphicon glyphicon-print"></span><span class="caret"></span>
                </button>
                <ul class="dropdown-menu" role="menu" style="right: 0; left: auto;">
                    <li ng-click="printFichaConferencias(false)">
                        <a href="">Conferência de Bens</a>
                    </li>
                    <li ng-click="printFichaConferencias(true)">
                        <a href="">Conferência de Bens (Excel)</a>
                    </li>
                    <li ng-click="printFichaConferenciasErros(false)">
                        <a href="">Falhas Encontradas</a>
                    </li>

                </ul>
            </div>


        </div>
        <div class="col-md-12"></div>
        <ul class="nav nav-tabs">
            <li ng-class="{active:mostrartab[0]}" ng-click="changeTab(0)"><a href="">Bens por Local</a></li>
            <li ng-class="{active:mostrartab[1]}" ng-click="changeTab(1)"><a href="">Conferência de Bens</a></li>
            
        </ul>
        
        
                
        <div ng-show="mostrartab[0]" style="border:1px solid #DDD; min-height:480px; border-top:none; padding:5px">
            <div class="col-md-4" style="padding:3px">
                <div class="table-responsive sep1" style="height:405px">
                    <table class="table">
                        <tr>
                            <!--<th></th>-->
                            <th colspan="3">
                                <div style="background-color:#DDD">


                                    <input type="text" placeholder="" class="form-control" style="cursor:default"
                                           popover-placement="top"
                                           popover-trigger="mouseenter"
                                           data-popover="Nome da Entidade"
                                           ng-click=""
                                           readonly="readonly" ng-model="selectedEdificio.NomeEntidade" />
                                </div>
                            </th>

                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <h4>Edifício</h4>

                                <select class="form-control"
                                        ng-model="selectedEdificio"
                                        ng-change="selEdificio(selectedEdificio,null)"
                                        ng-options="e.EdificioEntidade for e in edificios">
                                    <option value="">Qualquer Edifício...</option>
                                </select>
                            </td>
                            <td style="text-align:right">
                                <button popover-placement="top"
                                        popover-trigger="mouseenter"
                                        data-popover="Remover Edifício"
                                        ng-click="confirmarApagarEdificio(selectedEdificio)"
                                        type="button"
                                        ng-disabled="mnuTabelas.PApagar==false || edificios.length==0 || selectedEdificio==null"
                                        class="btn btn-warning btn-sm">
                                    <span class="glyphicon glyphicon-remove"></span>
                                </button>

                                <button popover-placement="top"
                                        popover-trigger="mouseenter"
                                        data-popover="Novo Edifício"
                                        ng-click="edificioEditRow()"
                                        type="button"
                                        ng-disabled="mnuTabelas.PEditar==false"
                                        class="btn btn-primary btn-sm">
                                    <span class="glyphicon glyphicon-plus"></span>
                                </button>
                                <button popover-placement="top"
                                        popover-trigger="mouseenter"
                                        data-popover="Editar Edifício"
                                        type="button"
                                        class="btn btn-default btn-sm"
                                        ng-click="edificioEditRow(selectedEdificio)"
                                        ng-disabled="mnuTabelas.PEditar==false || edificios.length==0 || selectedEdificio==null">

                                    <span class="glyphicon glyphicon-pencil"></span>
                                </button>
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <h4>Piso</h4>
                                <select class="form-control"
                                        ng-model="selectedPiso"
                                        ng-change="selPiso(selectedPiso,null)"
                                        ng-options="p.Descricao for p in selectedEdificio.LstPiso">
                                    <option value="">Qualquer Piso...</option>
                                </select>
                            </td>
                            <td style="text-align:right">
                                <button popover-placement="top"
                                        popover-trigger="mouseenter"
                                        data-popover="Remover Piso"
                                        ng-click="confirmarApagarPiso(selectedPiso)"
                                        type="button"
                                        ng-disabled="mnuTabelas.PApagar==false ||selectedEdificio.LstPiso.length==0 || selectedPiso==null"
                                        class="btn btn-warning btn-sm">
                                    <span class="glyphicon glyphicon-remove"></span>
                                </button>
                                <button popover-placement="top"
                                        popover-trigger="mouseenter"
                                        data-popover="Novo Piso"
                                        ng-click="pisoEditRow()"
                                        type="button"
                                        ng-disabled="mnuTabelas.PApagar==false"
                                        class="btn btn-primary btn-sm">
                                    <span class="glyphicon glyphicon-plus"></span>
                                </button>
                                <button popover-placement="top"
                                        popover-trigger="mouseenter"
                                        data-popover="Editar Piso"
                                        type="button"
                                        class="btn btn-default btn-sm"
                                        ng-click="pisoEditRow(selectedPiso)"
                                        ng-disabled="mnuTabelas.PEditar==false || selectedEdificio.LstPiso.length==0 || selectedPiso==null">
                                    <span class="glyphicon glyphicon-pencil"></span>
                                </button>
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <h4>Sala</h4>
                                <select class="form-control"
                                        ng-model="selectedSala"
                                        ng-change="selSala(selectedSala,null)"
                                        ng-options="s.Descricao for s in selectedPiso.LstSala">
                                    <option value="">Qualquer Sala...</option>
                                </select>
                            </td>
                            <td style="text-align:right">
                                <button popover-placement="top"
                                        popover-trigger="mouseenter"
                                        data-popover="Remover Sala"
                                        ng-click="confirmarApagarSala(selectedSala)"
                                        type="button"
                                        ng-disabled="mnuTabelas.PApagar==false ||selectedPiso.LstSala.length==0 || selectedSala==null"
                                        class="btn btn-warning btn-sm">
                                    <span class="glyphicon glyphicon-remove"></span>
                                </button>
                                <button popover-placement="top"
                                        popover-trigger="mouseenter"
                                        data-popover="Nova Sala"
                                        ng-click="salaEditRow()"
                                        type="button"
                                        ng-disabled="mnuTabelas.PApagar==false"
                                        class="btn btn-primary btn-sm">
                                    <span class="glyphicon glyphicon-plus"></span>
                                </button>
                                <button popover-placement="top"
                                        popover-trigger="mouseenter"
                                        data-popover="Editar Sala"
                                        type="button"
                                        class="btn btn-default btn-sm"
                                        ng-click="salaEditRow(selectedSala)"
                                        ng-disabled="mnuTabelas.PEditar==false || selectedPiso.LstSala.length==0 || selectedSala==null">
                                    <span class="glyphicon glyphicon-pencil"></span>
                                </button>
                            </td>
                        </tr>
                    </table>
                </div>

            </div>

            <div class="col-md-8" style="padding:3px">

                <form name="frm1" class="container-fluid sep1" style="height:405px" id="tabCadastro">

                    <div class="table-responsive">
                        <table class="table table-striped table-hover">
                            <tr>
                                <th style="width:100px">Nº Inv</th>
                                <th>Designação</th>
                                <th>Localização</th>
                            </tr>
                            <tr ng-repeat="item in items"
                                class="apontar"
                                ng-class="{info:selectedCadastro.Pk_Inventario==item.Pk_Inventario}"
                                ng-click="selCadastro(item)">
                                <td ng-style="verificaCorAbateBloqueio(item)">
                                    {{item.NumInventario}}
                                    <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true" ng-show="item.TemAbate" popover-placement="top" popover-trigger="mouseenter" data-popover="Abatido"></span>
                                </td>
                                <td>{{item.Nome}}</td>
                                <td>{{item.Localizacao}}</td>
                            </tr>
                        </table>
                    </div>
                </form>

                <p align="right" style="margin-top:10px">
                    <button ng-click="carregarCadastroLocalizacao(false)" type="button"
                            ng-disabled="itemsLoaded==false || totalLoaded==0"
                            class="btn btn-primary btn-md">
                        <span class="glyphicon glyphicon-forward"></span> Ver Mais
                    </button>
                    <img src="images/preloader.gif" width="32" ng-hide="itemsLoaded==true" style="margin-left:30px; margin-right:30px" />
                </p>

            </div>
        </div>
        <!--Conferencia de bens-->
        <div ng-show="mostrartab[1]" collapse="false" style="border:1px solid #DDD; min-height:480px; border-top:none; padding:5px">
            <div class="col-md-9"></div>
            <div class="col-md3" style="text-align:right">
                <label class="">
                    Procurar por - Nº Inventario  <input type="checkbox" ng-model="procurarPorNumInv" />
                </label>
            </div>
                        
            <div class="col-md-8">
                <label>{{getNomeEntidade()}}</label>
                <span>{{getDescricaoLocal(false)}}</span>
                
                
            </div>

            <div class="input-group col-md-4" ng-show="procurarPorNumInv==false">
                <span class="input-group-addon" id="basic-addon1">
                    <span class="glyphicon glyphicon-barcode" aria-hidden="true"></span>
                </span>
                <input type="text"
                       class="form-control"
                       ng-model="codbarras"
                       placeholder="Código de Barras..."
                       ut-focus="focusCodbarras"
                       numbers-only maxlength="13"
                       ng-change="getCadastroEAN13()" />

                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-search" aria-hidden="true"></span>
                </span>

            </div>
            <div class="input-group col-md-4" ng-show="procurarPorNumInv==true">
                
                <input type="text"
                       class="form-control"
                       ng-model="numInvProc"
                       placeholder="Nº Inventário..."
                       numbers-only maxlength="13"
                       ng-change="procuraInventarioNum(numInvProc)" />

                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-search" aria-hidden="true"></span>
                </span>

            </div>

            
            <br />
            
            <label>Total de Bens</label> <span class="badge">{{getTotalBens()}}</span>
            <label>Conferidos</label> <span class="badge">{{getConferidos()}}</span>
            <label>Total de Páginas</label> <span class="badge" style="margin-right:10px">{{getTotalPaginas()}}</span>
                        
            
            <button ng-click="mostraErrosVerificacao()" type="button"
                    ng-show="getTotalErros()>0"
                    class="btn btn-warning btn-sm" style="margin-bottom:5px">
                <span class="glyphicon glyphicon-warning-sign"></span>
                <span class="badge">{{getTotalErros()}}</span>
            </button>
            
            <br/>
            
            <div class="table-responsive" style="border: 1px solid #DDD;  overflow:auto; min-height:360px; height:360px" id="tabContainer">
            
                <table class="table table-striped table-hover" id="tabconf">
                    <thead>
                        <tr>
                            <th style="width:80px">Nº Inv</th>
                            <th>Designação</th>
                            <th style="width:50px; text-align:center">Conferido</th>
                        </tr>

                    </thead>

                    <tbody>
                        <tr ng-repeat="item in selectedPagina"
                            class="apontar"
                            ng-class="{info:selectedItemProcurado.NumInventario == item.NumInventario}"
                            ng-click="">
                            <td>{{item.NumInventario}}</td>
                            <td>{{item.NomeBem}}</td>
                            <td style="text-align:center"><input type="checkbox" ng-model="item.Conferido" ng-disabled="conferenciaTrancada()" /></td>
                        </tr>
                    </tbody>
                </table>
                                
            </div>
            <div style="text-align:right; padding-top:10px">
                
                <div class="btn-group" role="group" aria-label="...">
                    <button ng-click="selPagina(0)" type="button"
                            ng-disabled="paginaAtual==0"
                            class="btn btn-default btn-sm">
                         Primeiro
                    </button>
                    <button ng-click="selPaginaAnterior()" type="button"
                            ng-disabled="paginaAtual==0"
                            class="btn btn-default btn-sm">
                        <span class="glyphicon glyphicon-backward"></span> Anterior
                    </button>
                    <button ng-click="selPaginaAnterior()" type="button"
                            ng-disabled="true"
                            class="btn btn-default btn-sm">
                        Pág. {{getPaginaAtual()}}
                    </button>
                    <button ng-click="selPaginaSeguinte()" type="button"
                            ng-disabled="paginaAtual==getTotalPaginas()-1"
                            class="btn btn-default btn-sm">
                        Seguinte <span class="glyphicon glyphicon-forward"></span>
                    </button>
                    <button ng-click="selPagina(getTotalPaginas()-1)" type="button"
                            ng-disabled="paginaAtual==getTotalPaginas()-1"
                            class="btn btn-default btn-sm">
                        Ultimo
                    </button>
                    
                </div>

                
            </div>
            <button ng-click="trancarConferencias()" type="button"
                    class="btn btn-warning btn-sm" style="margin-bottom:5px" ng-disabled="" ng-show="IdConf>0">
                {{descricaoBotaoTrancar()}}
                
            </button>
                        
            
        </div>
    </div>
</div>

