        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>Escritorio</h1>
        </section>

        <!-- Main content -->
        <section class="content">
<?php if(Core::$user->kind==1):?>
  <?php
  $found=false;
$products = ProductData::getInventory();
//print_r($products);
foreach($products as $product){
  $q= OperationData::getQByStock($product->id,StockData::getPrincipal()->id);
if( $q==0 ||  $q<=$product->inventary_min){
    $found=true;
    break;

  }
}
  ?>
<div class="row">
  <div class="col-md-12">
<?php if($found):?>
<div class="btn-group pull-right">
  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
    <i class="fa fa-download"></i> Descargar <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" role="menu">
    <li><a href="report/alerts-word.php">Word 2007 (.docx)</a></li>
    <li><a href="report/alerts-xlsx.php">Excel 2007 (.xlsx)</a></li>
  </ul>
</div>
<?php endif;?>
<?php if($found):?>
<?php
$page = 1;
if(isset($_GET["page"])){
  $page=$_GET["page"];
}
$limit=10;
if(isset($_GET["limit"]) && $_GET["limit"]!="" && $_GET["limit"]!=$limit){
  $limit=$_GET["limit"];
}
if(count($products)>0){

if($page==1){
$curr_products = ProductData::getAllByPage($products[0]->id,$limit);
}else{
$curr_products = ProductData::getAllByPage($products[($page-1)*$limit]->id,$limit);

}
$npaginas = floor(count($products)/$limit);
$spaginas = count($products)%$limit;

if($spaginas>0){ $npaginas++;}

  ?>

  <h3>Pagina <?php echo $page." de ".$npaginas; ?></h3>
<div class="btn-group pull-right">
<?php
$px=$page-1;
if($px>0):
?>
<a class="btn btn-sm btn-default" href="<?php echo "index.php?view=home&limit=$limit&page=".($px); ?>"><i class="glyphicon glyphicon-chevron-left"></i> Atras </a>
<?php endif; ?>

<?php 
$px=$page+1;
if($px<=$npaginas):
?>
<a class="btn btn-sm btn-default" href="<?php echo "index.php?view=home&limit=$limit&page=".($px); ?>">Adelante <i class="glyphicon glyphicon-chevron-right"></i></a>
<?php endif; ?>
</div>
<div class="clearfix"></div>
<br>
<div class="box">
  <div class="box-header">
    <h3 class="box-title">Alerta de Inventario - <?php echo StockData::getPrincipal()->name; ?></h3>

  </div><!-- /.box-header -->
  <div class="box-body no-padding">

<table class="table table-bordered table-hover">
  <thead>
    <th >Codigo</th>
    <th>Nombre del producto</th>
    <th>En Stock</th>
    <th></th>
  </thead>
  <?php
foreach($curr_products as $product):
//  $q=OperationData::getQ($product->id);
  $q= OperationData::getQByStock($product->id,StockData::getPrincipal()->id);

  ?>
  <?php if( $q==0 ||  $q<=$product->inventary_min):?>
  <tr class="<?php if($q==0){ echo "danger"; }else if($q<=$product->inventary_min/2){ echo "danger"; } else if($q<=$product->inventary_min){ echo "warning"; } ?>">
    <td><?php echo $product->id; ?></td>
    <td><?php echo $product->name; ?></td>
    <td><?php echo $q; ?></td>
    <td>
    <?php if($q==0){ echo "<span class='label label-danger'>No hay existencias.</span>";}else if($q<=$product->inventary_min/2){ echo "<span class='label label-danger'>Quedan muy pocas existencias.</span>";} else if($q<=$product->inventary_min){ echo "<span class='label label-warning'>Quedan pocas existencias.</span>";} ?>
    </td>
  </tr>
<?php endif;?>
<?php
endforeach;
?>
</table>
  </div><!-- /.box-body -->
</div><!-- /.box -->
<div class="btn-group pull-right">
<?php

for($i=0;$i<$npaginas;$i++){
  echo "<a href='index.php?view=home&limit=$limit&page=".($i+1)."' class='btn btn-default btn-sm'>".($i+1)."</a> ";
}
?>
</div>
<form class="form-inline">
  <label for="limit">Limite</label>
  <input type="hidden" name="view" value="home">
  <input type="number" value=<?php echo $limit?> name="limit" style="width:60px;" class="form-control">
</form>

<div class="clearfix"></div>

  <?php
}else{
  ?>
  <div class="jumbotron">
    <h2>No hay alertas</h2>
    <p>Por el momento no hay alertas de inventario, estas se muestran cuando el inventario ha alcanzado el nivel minimo.</p>
  </div>
  <?php
}

?>
<?php else:?>
  <div class="jumbotron">
    <h2>No hay alertas</h2>
    <p>Por el momento no hay alertas de inventario, estas se muestran cuando el inventario ha alcanzado el nivel minimo.</p>
  </div>
<?php endif;?>
<br><br><br><br><br><br><br><br><br><br>
  </div>
</div>
<?php endif; ?>
        </section><!-- /.content -->
