<?php
session_start();
if (isset($_SESSION['usuario'])){
	$user=$_SESSION['usuario'];
}
else
{
	?>
	<script>
	location.href="index.php?errorusuario=3";
	</script>
	<?php
}

date_default_timezone_set("America/Mexico_City");

include("conexion.php");

//DATOS DE USUARIO
$cons="Select nombre,tipo,idClinica,caja FROM usuarios WHERE idUsuario='$user'";
$res=mysql_query($cons,$conex) or die ("No se realizó la consulta en usuarios");
$nombreuser=mysql_result($res,0,'nombre');
$tipo=mysql_result($res,0,'tipo');
$caja=mysql_result($res,0,'caja');
if($caja=="")
{
	$caja="A";
}
$clini=mysql_result($res,0,'idClinica');

//OBTENGO FOLIO Y OBTENGO UNO MAS
$cons30="SELECT max(folio) as folio FROM salida WHERE caja='$caja'";
$res30=mysql_query($cons30,$conex) or die ("No se realizo cons30");
$folioant=mysql_result($res30,0,'folio');
$nuevofolio=$folioant+1;

$cons300="SELECT max(idSalida) as nocontrol FROM salida";
$res300=mysql_query($cons300,$conex) or die ("No se realizo cons300");
$controlant=mysql_result($res300,0,'nocontrol');
$nuevocontrol=$controlant+1;

echo "<input name='folio' type='hidden' id='folio' value='".$nuevofolio."' size='5'>";

?>

<!doctype html>
<html>
<head>
	<meta charset="ISO-8859-1">
	<title>CLINISYS - PV</title>
	<link href="ucaestilos.css" rel="stylesheet" type="text/css" />
	<script src="scripts/jquery-1.12.4.min.js"></script>
	<script src="pv_ajax.js" language="javascript"></script>

	<link rel="stylesheet" type="text/css" href="css/ddsmoothmenu.css" />
	<script type="text/javascript" src="scripts/ddsmoothmenu.js"></script>
	<script type="text/javascript">
	ddsmoothmenu.init({
		mainmenuid: "smoothmenu1", //menu DIV id
		orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
		classname: 'ddsmoothmenu', //class added to menu's outer DIV
		customtheme: ["#0D3356", "#A9C238"],
		contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
	})
</script>
<!-- termina menu -->
<link rel="stylesheet" type="text/css" href="css/jquery.datetimepicker.css"/>
<script src="scripts/jquery.datetimepicker.full.min.js"></script>
<script>
jQuery.datetimepicker.setLocale('es');

function validareposicion()
{
	if(document.getElementById('repo').checked==true)
	{
		var password;
		var pass1="ClinicaO";
		password=prompt('Inserte su contraseña:','');
		if (password==pass1)
		{
			alert('Clave correcta! Click OK para continuar!');
		}
		else
		{
			document.getElementById('repo').checked=false;
			alert('Clave erronea!');
		}
	}
	else
	{alert("Reposición cancelada");}
}
</script>
<style>
#tablacontenido
{
	height:150px;
}
.observaciones
{
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
	font-weight: bold;
	color:#000000;
}
.concepto
{
	font-family: Arial, Helvetica, sans-serif;
	font-size: 20px;
	font-weight: bold;
}
.avisoDescuento
{
	font-family: Arial, Helvetica, sans-serif;
	font-size: 16px;
	color:#C10000;
}
.tratamientoTitulo
{
	font-family: Arial, Helvetica, sans-serif;
	font-size: 20px;
	font-weight: bold;
	color:#FFF;
}
.pv_precio
{
	font-family: Arial, Helvetica, sans-serif;
	font-size: 18px;
	color:#000;
}

.pv_descuento
{
	font-family: Arial, Helvetica, sans-serif;
	font-size: 16px;
	color:#999;
}

.pv_pagar
{
	font-family: Arial, Helvetica, sans-serif;
	font-size: 34px;
	color:#467ECA;
	border-top:1px dotted #999;
}
</style>
</head>
<!--<body onLoad="abrirdatos()">-->
<BODY>
	<table width="1200" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
		<tr>
			<td width="800" bgcolor="#DFDFDF"><div align="left"><img src="img/top04.jpg" width="800" height="40"></div></td>
		</tr>
		<tr>
			<td>

				<table width="100%" border="0" align="center">
					<tr>
						<td width="90%" height="20" bgcolor="#0D3356">
							<?php include ("newmenu.php"); ?>
						</td>
						<td width="10%" bgcolor="#999999" align="center"><a href="cerrar.php" class="style6" style="text-decoration:none;">Cerrar Sesi&oacute;n</a></td>
					</tr>
				</table>
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td width="12%" valign="top">
							<?php
							if (isset($_GET['error']))
							{
								$error=$_GET['error'];
								if ($error==1)
								{
									?>
									<script>
									alert("No existe el expediente del paciente, intenta de nuevo!");
									</script>
									<?php
								}
								if ($error==2)
								{
									?>
									<script>
									alert("No existe la clave de doctor, intenta de nuevo!");
									</script>
									<?php
								}
							}
							?>

							<form name="formventa" method="post" action="svventa.php">
								<table width="1100" border="0" cellpadding="0" cellspacing="2">
									<tr>
										<td>

											<table width="100%" border="0" cellpadding="0" cellspacing="5" bgcolor="#FFF">
												<tr>
													<td width="72%"><table width="100%" border="0" cellspacing="3" cellpadding="0">
														<tr>
															<td width="130" height="25" class="style4">Fecha: <input name="fecha" type="text" class="cuadrotexto calendar" id="datetimepicker" value="<?php echo date("Y-m-d"); ?>" style="width:95px;" maxlength="10">
															</td>
															<td width="170" class="style4">No. de Control: <input name="control" type="text" class="folio" id="control" value="<?php echo $nuevocontrol;?>" size="8" readonly>
																<input name="clinica" type="hidden" id="clinica" value="<?php echo $clini;?>">
																<input name="usuario" type="hidden" id="usuario" value="<?php echo $nombreuser;?>">
															</td>

															<td width="200" align="left" class="style4">CAJA:
																<input name="caja" type="text" class="caja" id="caja" value="<?php echo $caja;?>" size="2" readonly>&nbsp;
															 Folio:
																<input name="folio" type="text" class="folio" id="folio" value="<?php echo $nuevofolio;?>" size="6" readonly>
															</td>
															<td width="135"><input name="button" type="button" class="botonDefault" id="button" value="Nuevo Paciente" onClick="javascript:nvopac()"></td>
															<td width="165"><input name="button2" type="button" class="botonDefault" id="button2" value="Nvo. Pac. Pediatrico" onClick="javascript:nvopacped()"></td>
														</tr>

													</table>

													<table border="0" cellpadding="0" cellspacing="5" style="background-color:#DADADA; width:100%;">
														<tr>
															<td height="21" colspan="2"><div align="left">
																<input name="pp" type="checkbox" id="pp">
																<span class="style4">Paciente Odontopedi&aacute;trico</span></div></td>
																<td>
																	<!--<input name="repo" type="checkbox" id="repo" onClick="javascript:validareposicion()" value="si">
																	<span class="style4">Reposici&oacute;n</span>-->
																</td>
															</tr>
															<tr>

																<td width="127" height="21"><div align="right"><span class="style4">Expediente: </span></div></td>
																<td width="73"><input name="expediente" type="text" class="cuadrotexto" id="expediente" size="10" maxlength="15"></td>
																<td width="562"><div align="left">
																	<input name="Submit2" type="button" class="boton2" value="Buscar" onClick="javascript:paciente()">
																</div></td>
															</tr>

															<tr>
																<td width="127" height="21"><div align="right"><span class="style4">Paciente: </span></div></td>
																<td colspan="2"><div id="nombrepaciente"> </div></td>
															</tr>

															<tr>
																<td height="21"><div align="right"><span class="style4">Matr&iacute;cula Alumno: </span></div></td>
																<td ><input name="clavedoctor" type="text" class="cuadrotexto" id="clavedoctor" size="10" maxlength="15"></td>
																<td><div align="left">
																	<input name="Submit22" type="button" class="boton2" value="Buscar" onClick="javascript:doctor()">
																</div></td>

															</tr>
															<tr>
																<td height="21"><div align="right"><span class="style4">Alumno: </span></div></td>
																<td colspan="2" ><div id="nombredoctor"> </div></td>
															</tr>
														</table></td>
													</tr>
												</table>

											</td>
										</tr>
										<tr>
											<td>
												<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#F2F3F4">
													<tr>
														<td><table width="100%" border="0" align="right" cellpadding="0" cellspacing="10" bgcolor="#A9C238">
															<tr>
																<td>
																	<div align="left" class="tratamientoTitulo">Tratamiento:
																		<select name='tratamiento' id='tratamiento' class='cuadrotexto'>
																			<?php
																			$cons="SELECT * FROM tratamientocompleto WHERE Activo='Si' ORDER BY tratamientoCompleto ASC";
																			$res=mysql_query($cons,$conex) or die ("No se pudo consultar los tratamientos");

																			while ($campo=mysql_fetch_assoc($res))
																			{
																				echo "<option value=".$campo['idTratamiento']." >".utf8_encode($campo['tratamientoCompleto'])."</option>";
																			}

																			?>
																		</select>
																		<input name="Submit4" type="button" class="boton2" value="Seleccionar" onClick="addtratamiento()">

																	</div>
																</td>
															</tr>
														</table>
													</td>
												</tr>
											</table>
											<table width="100%" border="0" cellpadding="0" cellspacing="5">
												<tr>
													<td width="72%">
														<div id="tablacontenido">
															<?php
															echo "<p align='center' class='style10'><br><br>Seleccione Tratamiento</p><input type='hidden' name='idtratamiento' id='idtratamiento' value='0'>";
															?>
														</div>
														<table width="400" border="0" align="center" cellpadding="0" cellspacing="5">
															<tr>
																<td class="observaciones">Observaciones:</td>
															</tr>
															<tr>
																<td><textarea name="observaciones" cols="80" rows="3" class="cuadrotexto" id="observaciones"></textarea></td>
															</tr>
														</table>
													</td>
												</tr>
											</table>

										</td>
									</tr>
								</table>

								<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
									<tr>
										<td width="490"><!--<input name="Submit3" type="button" class="boton1" value="Cancelar venta" onClick="javascript:cancelaventa()">--></td>

										<td width="490">



											<div align="right">

												<input name="Submit" type="button" class="boton1" value="Ejecutar Venta" onClick="ejecutaventa()">

											</div></td>

										</tr>

									</table>

								</form>
								<br /></td>
							</tr>
							<tr>
								<td height="26" style="background-color:#0D3356;">
									<div align="center" id="noimprimible">
										<table width="99%" border="0" align="center" cellpadding="2" cellspacing="0">
											<tr>
												<td align="center" class="style8">Desarrollado para la Universidad Cuauht&eacute;moc por <a href="http://www.upweb.mx" target="_blank"><img src="img/webmaster.svg" style="height:16px; vertical-align:bottom;"></a></td>
											</tr>
										</table>
									</div></td>
								</tr>

							</table></td>

						</tr>

					</table>
					<?php
					$fechadehoy=date("Y-m-d");
					?>
					<script>
					$('#datetimepicker').datetimepicker({
						lang:'es',
						timepicker:false,
						format:'Y-m-d',
						formatDate:'Y-m-d',
						//minDate:'-<?php echo $fechadehoy;?>'//or 1986/12/08
						minDate:0
					});
					</script>
				</body>

				</html>
