<?php include('casa/setup.casa.php');
include('inc_scripts.php');
$title = 'Comprobar Duplicidad de los Productos';
echo "<title>".AppName.' - '.$title."</title>";
?>
<style>
th{background:#156E10;
color:white;
text-align:center;
text-transform:uppercase;}	
</style>
</head>
<body>
	<div class="wrapper">		
	<?php include('inc_menu.php');?>
		<div class="main-panel">
			<div class="content">
				
			<div class="page-inner">
					
					<div class="row">						
						<div class="col-md-12">
							<div class="card">
								<div class="card-header">
									<div class="d-flex align-items-center">
										<h3 class="card-title"><?php echo $title?></h3>																																									
									</div>
								</div>
								
								<div class="card-body">		
																									
									<div class="table-responsive">											
										<table id="add-row" class="display table table-striped table-hover" >
											<thead>
												<tr>		
													<th>N&ordm;</th>		
													<th>item</th>			
													<th>producto</th>
													<th>cantidad</th>
													<th>opciones</TH>
												</tr>
											</thead>											
											<tbody>
											<?php	
											$sql = "SELECT prod_codigo,prod_item, prod_nombre,prod_estado, COUNT(*) AS total
											FROM inventarios_productos
											WHERE prod_item<>'' AND prod_estado = '1'
											GROUP BY prod_item, prod_nombre HAVING total > 1;";												
											/*$sql = "SELECT p.prod_item, p.prod_nombre, u.ubica_codigo,
											COUNT(*) AS total
											FROM inventarios_productos p, inventarios_ubicaciones u
												WHERE prod_item<>''
												AND p.ubica_codigo = u.ubica_codigo
											GROUP BY p.prod_item, p.prod_nombre HAVING total > 1;";	
											*/
											$db= new DB();
											$db->dbSQL($sql);
											$html='';
											$i=0;
											while($db->next()){						
											$i++;																							
												$prod_codigo = $db->dbField('prod_codigo');
												$prod_item = $db->dbField('prod_item');
												$prod_nombre = $db->dbField('prod_nombre');
												$total = $db->dbField('total');

												$html.='<tr>';												
													$html.='<td align=center><b>'.$i.'</b></td>';												
													$html.='<td>'.$prod_item.'</td>';
													$html.='<td>'.$prod_nombre.'</td>';													
													$html.='<td align=center>'.$total.'</td>';	
													$html.="<td><a href='".PATH_HOME."duplicidad-detalles/".$prod_codigo."' class='btn btn-primary ml-auto' style='color:white'>
													DETALLES</a></td>";													
												$html.='</tr>';											
												
											}//wend() 
											
											echo utf8_encode($html);
											?>													
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				
			</div>
			<?php include('inc_pie.php');?>
		</div>
		
		
	</div>
</body>
</html>
<script>
$(document).ready(function() {			
	$('#add-row').DataTable({
		"pageLength": 10,
	});
});	
</script>