<?php
ob_start();
ini_set('session.gc_maxlifetime', 14400);
session_set_cookie_params(14400);
session_start();

if (!isset($_SESSION["nombre"]))
{
    header("Location: ../../login/login.php");
}
else
{
require '../header.php';
require_once('../../config/Conexion.php');
if($_SESSION['almacen']==1){

?>

            <div class="content-wrapper">
                <!-- Breadcrumb Section -->
                <section class="content-header">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12">
                                <nav aria-label="breadcrumb">
                                    <ol class="breadcrumb">
                                        <li class="breadcrumb-item">
                                            <a href="#"><i class="fas fa-home"></i> Panel</a>
                                        </li>
                                        <li class="breadcrumb-item active" aria-current="page">
                                            <a href="list.php">
                                                <i class="module-icon"></i> Inventario General
                                            </a>
                                        </li>
                                    </ol>
                                </nav>
                            </div>
                          
                            <div class="col-sm-12" style="margin-top: 20px;">
                                <div class="card  ">
                                    <div class="card-header bg-primary">
                                        <h3 class="card-title">
                                            <i class="fas fa-search"></i>
                                            Listado de Inventario Productos
                                        </h3>
                                    </div>
                                    <div class="card-body" style="display: block;">
                                        <div class="container-fluid">
                                            <a target="_blank" href="excelinventario.php"<button class="btn btn-success btn-flat" >EXCEL   <i class="fa fa-table" aria-hidden="true"> </button></i></a>
                                            <br>
                                            <br>
                                            <table style="width:100%;" class="table table-bordered" id="producto">
                                                <thead>
                                                <tr>
                                                <th>Almacen</th>
                                                <th width="20%">Nombre Producto</th>
                                                <th>Cod Madre</th>
                                                <th>Codigo</th>
                                                <th>Estado Material</th>
                                                <th>Categoria</th>        
                                                <th>Unidad Medida</th>         
                                                <th>Precio Compra</th>
                                                <th>Precio Venta</th>                 
                                                <th>Cantidad Disponible</th>
                                                </tr>
                                                </thead>
                                                <?php 
               
               $query = "SELECT d.idarticulo,a.nombre,a.descripcion,sum(d.stock)as total,m.nombre as almacen,d.idalmacen FROM inventario_ingreso d 
                        join articulo a on d.idarticulo=a.idarticulo join almacen m on d.idalmacen=m.idalmacen 
                        WHERE d.stock>0 and d.estadomovimiento<=2 and d.estadomaterial!=4 
                        GROUP BY d.idarticulo,m.nombre 
                        ORDER BY a.idcategoria desc";
                           $adicional = mysqli_query($conexion,$query);
                           while ($row = mysqli_fetch_array($adicional)){
         
                             $nombre=$row['nombre'];
                             $idarti=$row['idarticulo'];
                             $almacen=$row['almacen'];
                             $idalmacen=$row['idalmacen'];
                             $descripcion=$row['descripcion'];
                           ?>
         
                          <tr style="font-size:14px; text-align:center; background-color:#CCCCCC"> 
                          <th><?php echo "$almacen"; ?></th>
                          <th><?php echo "$nombre"."/"."$descripcion"; ?></th>
                          <th></th>
                          <th></th>
                          <th></th>
                          <th></th>
                          <th></th>
                          <th></th>
                          <th></th>
                          <th></th>
                          
          
                      <?php
                      $sumacant=0.00;
                    $query = "SELECT c.codigo as madre,d.codigo,d.estadomaterial,d.stock,a.unidad_medida,d.precio_compra,d.precio_venta,d.idarticulo,a.nombre,c.nombre as categoria,d.condicion 
                            FROM inventario_ingreso d join articulo a on d.idarticulo=a.idarticulo 
                            join categoria c on a.idcategoria=c.idcategoria 
                            WHERE d.idarticulo='$idarti' and d.stock>0 and d.estadomovimiento<=2 and d.estadomaterial!=4 and d.idalmacen='$idalmacen' 
                            ORDER BY d.idinventario_ingreso desc";
                           $adicional3 = mysqli_query($conexion,$query);
                        $cont=0;
                        while ($row5 = mysqli_fetch_array($adicional3)){
         
                         if($row5['estadomaterial']==1){
                           $row5['estadomaterial']="Nuevo";
                         }else if($row5['estadomaterial']==2){
                           $row5['estadomaterial']="Usado";
                         }else if($row5['estadomaterial']==3){
                           $row5['estadomaterial']="Reparado";
                         }else if($row5['estadomaterial']==4){
                           $row5['estadomaterial']="Malogrado";
                         }

                         if($row5['condicion'] == 1){
                            $condicion= "<span></span>";
                         }else{
                            $condicion= '<button class="btn btn-warning btn-xs btn-flat">Proceso Garantia</button>';
                         }
                           
                       $ma =$row5['madre']; 
                       $co = $row5['codigo'];
                       $es = $row5['estadomaterial'];
                       $st = $row5['stock'];
                       $uni = $row5['unidad_medida'];
                       $prec = $row5['precio_compra'];
                       $prev = $row5['precio_venta'];
                       $ca = $row5['categoria'];     
         
                       $sumacant=$sumacant+$st;
         
                    ?>
                    <tr style="font-size:14px; text-align:center"> 
                    <th></th>
                    <th><?php echo "$condicion"; ?></th>
                    <th><?php echo "$ma"; ?> </th>
                    <th><?php echo "$co"; ?> </th>
                    <th><?php echo "$es"; ?></th>
                    <th><?php echo "$ca"; ?></th>           
                    <th><?php echo "$uni"; ?></th>
                    <th><?php echo "$prec"; ?></th>
                    <th><?php echo number_format($prev,2); ?></th>
                    <th><?php echo "$st"; ?></th>
                    </tr>
             <?php
                $cont++;
                 }
                   
                ?>
                <tr style="font-size:16px; text-align:center;background-color:#dc3545"> 
                <th colspan="8"></th>
                <th style="font-size:16px; text-align:right; color:#FFFFFF">TOTAL STOCK:</th>
               <th style="font-size:16px;  color:#FFFFFF"><?php echo $sumacant; ?></th>
               </tr>
         <?php 
         
         
         }
         ?>
                      
                                                <tbody>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>                
            </div>

           
               
<?php
}
require '../footer.php';
?>

<?php 
}
ob_end_flush();
?>