<?php include('casa/setup.casa.php');
include('inc_scripts.php');
$title = 'Apertura de Caja';
echo "<title>".AppName.' - '.$title."</title>";

//$fecha = date('Y-m-d');
	$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();

	$asis_apertura = $db->dbField('asis_apertura');
	if($asis_apertura != 0){
		echo '<script>self.location="'.PATH_HOME.'cajas-cobrar/ver";</script>';
	}
	$codigo_caja = $db->dbField('asis_codigo');
	$asis_fecha = $db->dbField('asis_fecha');
	$asis_hora = $db->dbField('asis_hora');
?>
<style>
th{background:#1269DB;
color:white;}
img.logos{max-width:77%;}	
</style>
</head>
<body>
		<?php include('inc_menu-cajas.php');?>
		<br><br><br><br><br>

		<form>	
					<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="row">	
										<div class="col-md-3 col-lg-4">&nbsp;</div>										
										<div class="col-md-6 col-lg-4">
											<div class="form-group form-group-default">
												<label>Monto de Apertura:</label>
												<input id='txtMonto' type="number" class="form-control">
											</div>														
											<div class="form-group form-group-default">
												<label>Fecha:</label>
												<input value='<?php echo $asis_fecha; ?>' type="text" class="form-control" disabled>
											</div>
											<div class="form-group form-group-default">
												<label>Hora:</label>
												<input value='<?php echo $asis_hora; ?>' type="text" class="form-control" disabled>
											</div>
										</div>
										<div class="col-md-3 col-lg-4">&nbsp;</div>																					
									</div>
								</div>
								<div class="card-action"><center>
									<div id='res'></div>
									<input type="hidden" id='codApertura' value='<?php echo $codigo_caja; ?>'>
									<button class="btn btn-info" type='submit'><b> REGISTRAR E INICIAR CAJA </b></button>	</center>								
								</div>
							</div>
						</div>
						
					</div></form>

	<?php include('inc_pie.php');?>
</body>
</html>
<script>
$('form').on('submit', function(event) {
  event.preventDefault();

  $.post('<?php echo PATH_HOME.'cajeros-apertura2/'. md5(uniqid()); ?>',{
	'txtMonto': $('#txtMonto').val(), 	 
	'codApertura': $('#codApertura').val(), 	 	 
    'MxEncoder': '<?php echo sha1(uniqid()); ?>'
  },function(data){
    $('#res').html(data);
  });  
});
</script>