<?php include "conexion.inc" ?>
<?php include "validacion.php" ?>
<!doctype html>
<html lang="es">
	<head>
		<?php include '../index/head.php'; ?>
		<?php
			if (isset($_POST['Guardar']))
			{
				//Crear variables
				$cR01 = $_POST['cV01'];											// Serie
				$cR02 = $_POST['cV02'];											// Pedido
				$cR03 = $_POST['cV03'];											// Linea
				$cR04 = substr($_POST['cV04'], 0, strripos($_POST['cV04'], '.'));	// Id Vendedor
				// conexión
				$servername = $svr_servidor;
				$conectioninfo = array("Database"=>$svr_base, "UID"=>$svr_usuario, "PWD"=>$svr_contrasena, "CharacterSet"=>"UTF-8");
				$conexion = sqlsrv_connect($servername, $conectioninfo);
				if ($conexion == false)
				{
					$mensaje = "Existe un error al intentar conectarse con el servidor...";
				}
				else
				{
					/* ACTUALIZO RUTA */
					$sql = "UPDATE PEDVENTALIN \n"
						  ."SET CODVENDEDOR = ".$cR04." \n"
						  ."WHERE (NUMSERIE = '".$cR01."') AND (NUMPEDIDO = ".$cR02.") AND (NUMLIN = ".$cR03.")";
					$params = array();
					$options = array("scrollable" => SQLSRV_CURSOR_KEYSET);
					// Lanzar la consulta
					$resultado = sqlsrv_query($conexion, $sql);
					if ( $resultado )
					{
						 $something = "Submission successful.";
					}
					else
					{
						 $something = "Submission unsuccessful.";
						 die( print_r( sqlsrv_errors(), true));
					}
					sqlsrv_free_stmt($resultado);
				}
				sqlsrv_close($conexion);
				echo "<script languaje='javascript' type='text/javascript'> self.close(); </script>";
			}
		?>
	</head>
	<body class="nav-md" onLoad="recargar();">
		<div class="container body">
			<div class="main_container">
				<div class="right_col" role="main">
				<div class="">
					<!-- page content -->
					<div class="clearfix"></div>
					<div class="row">
						<div class="col-md-12 col-sm-12 col-xs-12">	
							<div class="x_panel">
								<div class="x_content">
									<form name="neo99" class="form-vertical" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" onsubmit="return valida_campos(this)">
										<div class="row">
											<div class="form-group">
												<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">Serie 
												</label>
												<div class="col-md-6 col-sm-6 col-xs-12">
													<input type="text" name="cV01" id="first-name" value="<?php echo $_GET['id']; ?>" required="required" class="form-control col-md-7 col-xs-12" readonly>
												</div>
											</div>
											<div class="form-group">
												<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">Pedido 
												</label>
												<div class="col-md-6 col-sm-6 col-xs-12">
													<input type="text" name="cV02" id="first-name" value="<?php echo $_GET['id2']; ?>" required="required" class="form-control col-md-7 col-xs-12" readonly>
												</div>
											</div>
											<div class="form-group">
												<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">Linea 
												</label>
												<div class="col-md-6 col-sm-6 col-xs-12">
													<input type="text" name="cV03" id="first-name" value="<?php echo $_GET['id3']; ?>" required="required" class="form-control col-md-7 col-xs-12" readonly>
												</div>
											</div>
											<div class="form-group">
												<div class='form-group'>
													<label>Vendedor</label>
													<div class='input-group'>
														<input type='text' class='form-control' name='cV04' readonly>
														<span class='input-group-btn'>
															<button type='button' class='btn btn-dark' onclick='popup01()'><i class='fa fa-search'></i></button>
														</span>
													</div>
												</div>
											</div>
										</div>
										</br>
										<div class="row">
											<div class="form-group">
												<button type="submit" class="btn btn-success" name="Guardar">
													<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span> Guardar/Actualizar
												</button>
												<button type="button" class="btn btn-danger" onclick="self.close();">
													<span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></span> Cancelar
												</button>
											</div>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<?php include '../index/fbody.php'; ?>
	</body>
</html>
<script>
	function valida_campos(f)
	{
		if (this.neo99.cV04.value == '')
		{
			alert("Ingrese justificación.");
			this.neo99.cV04.focus();
			return false;
		}
	}
</script>
<script>
	var mipopup;
	function popup01()
	{
		posicion_x=(screen.width/2)-(600/2);
		posicion_y=(screen.height/2)-(580/2)-50;
		mipopup = window.open("vendedores.php", "SelecVen", "width=600, Height=580, menubar=0, toolbar=0,directories=0,scrollbars=no,resizable=no,left="+posicion_x+",top="+posicion_y+"");
		mipopup.focus()
	}
</script>