<?php include('casa/setup.casa.php');
$titulo = 'Crear nuevo Producto';
include('inc_head.php');
?>
<style>
.input-group-text{
	color:white;
	text-align:left;
	font-weight:bold;
}	
</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">
						<form>
							<div class="card">
								<div class="card-header">
									<div class="card-title"><?php echo $titulo;?></div>
								</div>
								<div class="card-body">
									<div class="row">										
										<div class="col-md-4">														
											<div class="form-group">																																																																																																										
												<div class="input-group mb-2">													
													<div class="input-group-prepend">
														<span class="input-group-text bg-dark">Categorías:</span></div>												
													<select id='cmbCategorias' class="form-control">
														<option value="">Categorías Productos</option>
														<?php 
														 $db=new DB();										
														 $sql = "SELECT * FROM ventas_categorias
														 WHERE categ_visible = '1'		
														 ORDER BY categ_id ASC;";
														 $db->dbSQL($sql);
														 $html='';
														 while($db->next()){															
														 	 $categ_codigo = $db->dbField('categ_codigo');
															 $categ_nombre = caresp($db->dbField('categ_nombre'));															
															 	$html.='<option value="'.$categ_codigo.'">'.$categ_nombre.'</option>';
															 
														 }//wend 
														 echo $html;
														?>
													</select>
												</div><div class="input-group mb-2">													
													<div class="input-group-prepend">
														<span class="input-group-text bg-dark">Nombre:</span></div>												
													<input id='txtNombre' type="text" class="form-control">
												</div>												
												<div class="input-group mb-2">													
													<div class="input-group-prepend">
														<span class="input-group-text bg-dark">Cantidad:</span></div>												
													<input id='txtCantidad' type="number" step='1' class="form-control">
												</div>
												<div class="input-group mb-2">													
													<div class="input-group-prepend">
														<span class="input-group-text bg-dark">Precio Unitario:</span></div>												
													<input id='txtPrecio' type="number" step='0.5' class="form-control">
												</div>
																																																																																																																																																																																																																																																																																																																																																																														
											</div>																																																						
										</div>		
										<div class="col-md-7">														
											<div class="form-group">																																																																																																										
												<div class="input-group mb-2">													
													<div class="input-group-prepend">
														<span class="input-group-text bg-dark">Detalles <br> del Producto:</span></div>												
													<textarea id='txtDetalles' rows='7' class="form-control"></textarea>
												</div>																																																																																																																																																																																																																																																																																																																																																																														
											</div>																																																						
										</div>	
										
										
									</div>
								</div>
								<div class="card-action"><center>
									<div id='res'></div>
									<a href='<?php echo PATH_HOME.'productos/listado'; ?>' class="btn btn-info"><b> CANCELAR </b></a>
									<button class="btn btn-dark" type='submit'><b> GUARDAR DATOS </b></button>	</center>								
								</div>
							</div>
						</form>
						</div>
					</div>
				</div>
				
			</div>
			<?php include('inc_pie.php');?>
		</div>
		
		
	</div>
</body>
</html>
<script>
$('form').on('submit', function(event) {
  event.preventDefault();

  $.post('<?php echo PATH_HOME.'productos-ins2/'. sha1(uniqid()); ?>',{
	 'codigo': '<?php echo $code; ?>', 
	 'cmbCategorias': $('#cmbCategorias').val(), 
	 'txtNombre': $('#txtNombre').val(), 
	 'txtCantidad': $('#txtCantidad').val(), 
	 'txtPrecio': $('#txtPrecio').val(), 
	 'txtDetalles': $('#txtDetalles').val(), 
	 'MxEncoder': '<?php echo sha1(uniqid()); ?>'
  },function(data){
    $('#res').html(data);
  });  
});
</script>