<?php include('casa/setup.casa.php');
include('inc_scripts.php');
$title = 'Caja Chica - Gastos menores';
$fecha = DataForms::GET('id');
echo "<title>".AppName.' - '.$title."</title>";


$sql = "SELECT MAX(asis_id) AS mx,asis_tipo FROM rol_usuarios_asistencia
	WHERE us_id = '$USID'
  	AND asis_tipo = 'inicio';";

	$db = new DB();
	$db->dbSQL($sql);
	$db->next();
    $id = $db->dbField('mx');
	$sql2 = "SELECT * FROM rol_usuarios_asistencia
	WHERE asis_id = '$id';";
	$db->dbSQL($sql2);
	$db->next();
    $codigo_universal = $db->dbField('asis_codigo');
?>
<style>
th{background:green;
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-6">
												<a href="<?php echo PATH_HOME.'cajeros-cajachica-ins1/'.$fecha?>" class="btn btn-primary" style='color:white'>
													Crear Nuevo Gasto Menor</a>			
											</div>																																					
										</div>	
										<table id="add-row" class="display table table-striped table-hover" >
											<thead>
												<tr>							
													<th>N&ordm;</th>
													<th>detalles</th>
													<th>monto</th>
													<th>fecha</th>
												</tr>
											</thead>											
											<tbody>
											<?php
											$sql = "SELECT * FROM inventarios_cajachica 
											WHERE caja_fecha LIKE '".$fecha."%'
											AND us_codigo = '$USID'
											AND caja_codigo2 = '$codigo_universal';";	
											$db= new DB();
											$db->dbSQL($sql);
											$html='';
											$i=0;
											while($db->next()){						
											$i++;																																								
												$caja_detalle = $db->dbField('caja_detalle');
												$caja_importe = $db->dbField('caja_importe');
												$caja_fecha	 = $db->dbField('caja_fecha');

												$html.='<tr>';
													$html.='<td align=center>'.$i.'</td>';
													$html.='<td>'.$caja_detalle.'</td>';
													$html.='<td align=right>'.number_format($caja_importe,2).'</td>';
													$html.='<td align=right>'.$caja_fecha.'</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": 25,
	});
});	
</script>