<?php include('casa/setup.casa.php');
include('inc_scripts.php');
$title = 'Traspasos';
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">
										<div class="row" style='width:97%' align='left'>
											<div class="col-sm-3">
												<a href="<?php echo PATH_HOME.'traspasos/nuevo'?>" class="btn btn-primary" style='color:white'>
													Crear Nuevo Traspaso</a>
											</div>																																					
										</div>	
										<table id="add-row" class="display table table-striped table-hover" >
											<thead>
												<tr>																										
													<th>Traspaso</th>
													<th>Cantidad</th>
													<th>fecha</th>
													<th>opciones</TH>
												</tr>
											</thead>											
											<tbody>
											<?php
											$db=new DB();
											$Almacenes = new DB();

											$sql = "SELECT COUNT(tras.traspa_codigo) AS CANT,tras.traspa_codigo AS TRASCODIGO, tras.traspa_fecha AS fecha FROM inventarios_traspasos tras, inventarios_productos prod
											WHERE tras.prod_codigo = prod.prod_codigo 
											AND tras.ubica_codigo<>'0'
											GROUP BY tras.traspa_codigo ORDER BY tras.traspa_id DESC;";											
											$db->dbSQL($sql);
											$CantRegistros = $db->dbNumRows();
											$html='';
											$i=$CantRegistros;
											while($db->next()){	
												$CantProductos = $db->dbField('CANT');							
												$traspa_fecha = $db->dbField('fecha');
												$traspa_codigo = $db->dbField('TRASCODIGO');

												$html.='<tr>';
													$html.='<td>Traspaso N&ordm; '.$i.'</td>';			
													$html.='<td align=right>'.$CantProductos.' productos</td>';			
													$html.='<td>'.$traspa_fecha.'</td>';
													$html.="<td align='center'>
													<a href='".PATH_HOME."traspasos-lista2/".$traspa_codigo."' class='btn btn-primary'>IMPRIMIR</a></td>";
												$html.='</tr>';	
												
												$i--;
												
											}//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": 25,
	});
});	
</script>