<?php
	session_start();
	$nom = $_SESSION['nom_admin'];
?>
<!DOCTYPE html>
<html>
	<head>
		<title>Nuevo insumo</title>
		<link rel="stylesheet" type="text/css" href="./css/prueba.css">
		<script src="./js/jquery.min.js"></script>
        <script type="text/javascript" src="./js/script.js"></script>
<!--        <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Open+Sans">-->
        <?php
        	require ("./Funciones/funciones.php");
			$id = $_GET['id'];

			$conexion = conecta();
			$sql= "SELECT * FROM Insumos where IdInsumo ='$id' and Activo='1' and Eliminado='0'";
			$res = mysqli_query($conexion,$sql);
			$insu = mysqli_fetch_array($res);

			$nombre = $insu['Descripcion'];
			$codigo = $insu['Codigo'];
			$precio = $insu['PrecioCompra'];
			$categoria = $insu['IdProveedor'];
			$moneda = $insu['Moneda'];
			$uni = $insu['UnidPaq'];

			$sqla= "SELECT * FROM Proveedor where activo='1' and eliminado='0'";
			$resa = mysqli_query($conexion,$sqla);
			$numa = mysqli_num_rows($resa);
			
        ?>
        <script type="text/javascript">
        	function formulario(f) { 

				if (f.nombre.value   == '') { alert ('El nombre esta vacio');  
				f.nombre.focus(); return false; } 
				/*if (f.descripcion.value   == '') { alert ('La descripcion esta vacio');  
				f.descripcion.focus(); return false; }*/ 
				if (f.codigo.value  == '') { alert ('El codigo esta vacio'); 
				f.codigo.focus(); return false; } 
				/*if (f.opc.value  == 0) { alert ('Debes seleccionar una categoria'); 
				f.opc.focus(); return false; }*/
				if (f.stock.value  == '') { alert ('Stock vacio'); 
				f.stock.focus(); return false; }
				if (f.precio.value  == '') { alert ('Precio vacio'); 
				f.precio.focus(); return false; }

			}
        </script>
	</head>
	<body>

		<?php include('menu.php');?>
<div id="section" align="center">
</br>

<table border="0">
	<tr>
		<td colspan="3" align="center"> Agregar una moldura nueva</td>
	</tr>
	<tr>
		<td colspan="3"><input type="text" id="idinsumo" value="<?php echo $id;?>" hidden></td></tr>
	<tr><td><br></td></tr>
	<!--<tr>
		<td>Nombre:</td>
		<td><input type="text" id="nombre" name="nombre" placeholder="Nombre*" value="<?php// echo "$nombre";?>"></td>
	</tr>-->
	<tr>
		<td>Codigo:</td>
		<td><input type="text" id="codigo" name="codigo" onBlur="codigocheck(this);" placeholder="Codigo*" value="<?php echo "$codigo";?>"></td>
	</tr>
	<tr>
		<td>Proveedor</td>
		<td><?php echo "<select name=\"opc\" id=\"cats\">
            				<option value=\"0\" selected>Selecciona proveedor*</option>";
							while($resq=mysqli_fetch_array($resa)){
            			
								$idcat = $resq['IdProveedor'];
								$cat = $resq['Nombre'];
								echo $idcat.' '.$cat;
								echo $resq;
								if($categoria == $idcat){
									echo "<option value=\"$idcat\" selected>$cat</option>";
								}else{
								echo "<option value=\"$idcat\">$cat</option>";
								}
		
							}
            		
				echo "</select></br>"; ?></td>
		<td><a href="proveedor_nuevo.php"><button class="botona" >Agregar proveedor</button></a></td>
	</tr>

	<tr>
		<td>Costo:</td>
		<td><input type="number" id="costo" name="preciov" placeholder="Costo*" value="<?php echo $precio ;?>" ></td>
		<td><select id="monedac">
			<?php if($moneda == 1){?>
			<option value="1" selected>Pesos</option>
			<option value="2">Dolares </option>
			<?php }else if($moneda == 2){ ?>
			<option value="1">Pesos</option>
			<option value="2" selected>Dolares</option>
<?php }else{?>
			<option value="1">Pesos</option>
			<option value="2"> Dolares</option>

<?php
}?>
		</select></td>
	</tr>
	<!--<tr>
		<td>Costo varios:</td>
		<td><input type="number" id="varios" placeholder=" Ej. Grapas, hojas, etc..*" ></td>
	</tr>-->
	<tr>
		<td>Costo total:</td>
		<td><input type="number" id="costtot" disabled="disabled" ></td>
	</tr>
	<tr>
		<td>Porcentaje de Venta Fotografos (%)</td>
		<td><input type="number" id="porc" placeholder="Porcentaje de venta" ></td>
	</tr>
	<tr>
		<td>Precio de venta Fotografos:</td>
		<td><input type="number" id="preciov" name="preciov" placeholder="Precio*" value="<?php echo $precio ;?>" ></td>
		<td><select id="monedav">
			<?php if($moneda == 1){?>
			<option value="1" selected>Pesos</option>
			<option value="2">Dolares </option>
			<?php }else if($moneda == 2){ ?>
			<option value="1">Pesos</option>
			<option value="2" selected>Dolares</option>
<?php }else{?>
			<option value="1">Pesos</option>
			<option value="2"> Dolares</option>

<?php
}?>
		</select></td>
	</tr>
	<tr>
		<td>Porcentaje de Venta Mostrador (%)</td>
		<td><input type="number" id="porcm" placeholder="Porcentaje de venta" ></td>
	</tr>
	<tr>
		<td>Precio de venta Mostrador:</td>
		<td><input type="number" id="preciovm" name="preciov" placeholder="Precio*" value="<?php echo $precio ;?>" ></td>
		<td><select id="monedavm">
			<?php if($moneda == 1){?>
			<option value="1" selected>Pesos</option>
			<option value="2">Dolares </option>
			<?php }else if($moneda == 2){ ?>
			<option value="1">Pesos</option>
			<option value="2" selected>Dolares</option>
<?php }else{?>
			<option value="1">Pesos</option>
			<option value="2"> Dolares</option>

<?php
}?>
		</select></td>
	</tr>
		<td>Precio de Tira:</td>
		<td><input type="number" id="tira" name="preciov" placeholder="Precio de tira completa*"  ></td>

	<tr>
		<td>Unidad de medida:</td>
		<td><select id="unimed">
			<option value="0"> Selecciona una opcion</option>
			<option value="1">Metro lineal</option>
			<option value="2"> Area</option>
			<option value="3">Pieza </option>
		</select></td>
	</tr>
	<tr>
		<td>Desperdicio (CM):</td>
		<td><input type="number" id="desperdicio" placeholder="Desperdicio*" value="<?php echo $uni; ?>"></td>
	</tr>
	<tr><td><br></td></tr>
	<tr>
		<?php if($id == ''){?>
		<td><button id="Guardm" class="boton">Guardar</button></td>
		<?php }else{?>
		<td><button id="ActualizarIns" class="boton">Actualizar</button></td>
			<?php } ?>
	</tr>
</table>
<div id="mensaje"></div>
</div>
		<?php
		/*<div id="form" align="center">
			<h2>Agregar un nuevo insumo</h2>
			<form method="post" action="productos_salvar.php?id=<?php echo "$id";?>" onsubmit="return formulario(this);" enctype="multipart/form-data">
				<input type="text" id="nombre" name="nombre" placeholder="Nombre*" value="<?php echo "$nombre";?>"></br>
				<input type="text" id="codigo" name="codigo" onBlur="codigocheck(this);" placeholder="Codigo*" value="<?php echo "$codigo";?>"></br>
				
				<?php

				echo "<select name=\"opc\" id=\"cats\">
            				<option value=\"0\" selected>Selecciona proveedor*</option>";
            		for($i=0;$i<$numa;$i++){
            			
            			$idcat = mysql_result($resa, $i,"IdCategoria");
            			$cat = mysql_result($resa, $i,"Descripcion");
            			
            			if($categoria == $idcat){
            				echo "<option value=\"$idcat\" selected>$cat</option>";
            			}else{
            			echo "<option value=\"$idcat\">$cat</option>";
            			}

            		}
            		
				echo "</select></br>";

				if($id==''){
					echo "<input type=\"text\" id=\"descripcion\" name=\"descripcion\" placeholder=\"Descripcion\"  ></br>";			
					echo "<input type=\"text\" id=\"preciov\" name=\"preciov\" placeholder=\"Precio*\"  ></br>";
					echo "<input type=\"text\" id=\"stock\" name=\"stock\" placeholder=\"Stock*\"  ></br>";
					/*echo "<select name=\"destacado\" id=\"dest\">
						<option value =\"0\"> Es destacado?</option>";
						if($destacado != 0){
							if($destacado == 0){
								echo "<option value =\"1\" selected> No</option>";
							}elseif($destacado == 1){
								echo "<option value =\"2\" selected> Si</option>";
							}
						}else{
							echo "<option value =\"1\"> No</option>
						<option value =\"2\"> Si</option>";
						}

						
						echo "</select></br>";
					?>
					<input type="text" id="estante" name="ubicacion" placeholder="Estante*" ></br>
					<input type="text" id="fila" name="ubicacion" placeholder="Fila*" ></br>
					<input type="text" id="columna" name="ubicacion" placeholder="Columna*" ></br>
					<?php
					echo "<input type=\"file\" id=\"upimg\" name=\"imagen\" placeholder=\"Imagen\"></br>"; 

					echo "<input type=\"Submit\" class=\"boton\" name=\"enviar\" id=\"Guard\" value=\"Guardar\">";
					
				}
				else{
					echo "<input type=\"text\" id=\"descripcion\" name=\"descripcion\" placeholder=\"Descripcion\"  value=\"$descripcion\"></br>";
					echo "<input type=\"text\" id=\"preciov\" name=\"preciov\" placeholder=\"Precio*\"  value=\"$precio\"></br>";
					echo "<input type=\"text\" id=\"stock\" name=\"stock\" placeholder=\"Stock*\"  value=\"$stock\"></br>"; 
					/*echo "<select name=\"destacado\" id=\"dest\">
						<option value =\"0\"> Es destacado?</option>";
						
							if($destacado == 0){
								echo "<option value =\"1\" selected> No</option>";
								echo "<option value =\"2\"> Si</option>";
							}elseif($destacado == 1){
								echo "<option value =\"1\"> No</option>";
								echo "<option value =\"2\" selected> Si</option>";
							}
							else{
							echo "<option value =\"1\"> No</option>
								<option value =\"2\"> Si</option>";
							}

						
						echo "</select></br>";
					echo "<input type=\"file\" id=\"upimg\" name=\"imagen\" placeholder=\"Imagen\" value=\"$imagen\"></br>"; 
					?>
					<input type="text" id="estante" name="ubicacion" placeholder="Estante*" ></br>
					<input type="text" id="fila" name="ubicacion" placeholder="Fila*" ></br>
					<input type="text" id="columna" name="ubicacion" placeholder="Columna*" ></br>
					<?php
					echo "<input type=\"Submit\" id=\"Guard\" class=\"boton\" name=\"enviar\" value=\"Actualizar\">";

				}
				*/?>
		    </form>
		</br></br></br>
		    <a href="insumos_lista.php">Regresar al listado</a>
		</div>
				<div id="footer" align="center">
            <p>Cuadropolis 2016-2017</p>
        </div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
	</body>
</html>