<?
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = 'index.php';
		</script>
		<? 
		exit();
		}
$id_empresa = $_SESSION['ss_empresa'];
$id_user = $_SESSION['ss_user'];
$id_autoriza=37;

include("../conex.php");
include("../autoriza.php");

if ($grabar==0)  
{
?>
		<script>
		alert ("No Autorizado");
		parent.location.href = 'index.php';
		</script>
	<? 
	exit();
}
$id= $_POST["id"];
$id_dcto= $_POST["id_dcto"];
$correlativo=$_POST["valor"];
$id_bodega=$_POST["id_bodega"];

$cons_dcto = mysql_query("SELECT * FROM tipo_dcto_num_bodega WHERE Id = $id", $enlace);
$cont=0;
while ( mysql_fetch_object ($cons_dcto) ) 
	{
	$cont = $cont + 1;
	}

	
if ($cont==0) 
{
$esql = "INSERT INTO tipo_dcto_num_bodega (id_empresa, id_dcto, id_bodega, correlativo) VALUES ('$id_empresa', '$id_dcto', '$id_bodega', '$correlativo')";
	$consulta = mysql_query($esql,$enlace);
}
else
{
$esql = "UPDATE tipo_dcto_num_bodega SET correlativo=$correlativo WHERE Id = $id";
    $consulta = mysql_query($esql,$enlace);
	?>
<script language="javascript" type="text/javascript">
alert ("<?=$esql;?>");

</script>
	<?
}

	
	
?>
<script language="javascript" type="text/javascript">
alert ("<?=$cons_dcto.'\nActualizado Con Exito!';?>");
parent.location.href = 'index.php';
</script>