<?php
	
	session_start();
		include('../conectar.php'); 
		if($_SESSION['tipo_usu']=='c' or $_SESSION['tipo_usu']=='a' ){
		}else{
			header('location:error.php');
		}
		if($_SESSION['tipo_usu']=='a'){
			$titulo='Administrador';
		}else{
			$titulo='Secretaria/o';
		}
        $usuario=$_SESSION['username'];
		$sqll=mysql_query("SELECT * FROM usuarios WHERE usu='$usuario'");
		if($dato=mysql_fetch_array($sqll)){
			$nombre=$dato['usu'];
			$palabra=explode(" ", $nombre);
			$nomb=$palabra[0];
		}
		$hoy=date("d-m-Y");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
  <head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

		<title>Principal</title>
		<link href="../estilos/estilos.css" type="text/css" rel="stylesheet">
		<link href="../calendario/calendar-blue.css" rel="stylesheet" type="text/css">
	
	    <script src="../src/js/jscal2.js"></script>
        <script src="../src/js/lang/en.js"></script>
    <link rel="stylesheet" type="text/css" href="../src/css/jscal2.css" />
    <link rel="stylesheet" type="text/css" href="../src/css/border-radius.css" />
    <link rel="stylesheet" type="text/css" href="../src/css/steel/steel.css" />
    <style type="text/css">
<!--
.Estilo1 {color: #000000}
-->
    </style>
</head>
	<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>

	<script type="text/javascript">

			
							///////////////////////////////////////////////////////MASCARA NUMERICA //////////////////////////////////////////////


		function aceptar() {
			location.href="index.php?cadena_busqueda=<? echo $cadena_busqueda?>";
		}
			
		
		function puntitos(donde,caracter,campo)
{
var decimales = false
campo = eval("donde.form." + campo)
	for (d =0; d < campo.length; d++)
		{
		if(campo[d].checked == true)
			{
			dec = new Number(campo[d].value)
			break;
			}
		}
	if (dec != 0)
		{decimales = true}




pat = /[\*,\+,\(,\),\?,\\,\$,\[,\],\^]/
valor = donde.value
largo = valor.length
crtr = true
if(isNaN(caracter) || pat.test(caracter) == true)
	{
	if (pat.test(caracter)==true) 
		{caracter = "\\" + caracter}
	carcter = new RegExp(caracter,"g")
	valor = valor.replace(carcter,"")
	donde.value = valor
	crtr = false
	}
else
	{
	var nums = new Array()
	cont = 0
	for(m=0;m<largo;m++)
		{
		if(valor.charAt(m) == "" || valor.charAt(m) == " " || valor.charAt(m) == ".")
			{continue;}
		else{
			nums[cont] = valor.charAt(m)
			cont++
			}
		
		}
	}

if(decimales == true) {
	ctdd = eval(1 + dec);
	nmrs = 1
	}
else {
	ctdd = 1; nmrs = 3
	}
var cad1="",cad2="",cad3="",tres=0
if(largo > nmrs && crtr == true)
	{
	for (k=nums.length-ctdd;k>=0;k--){
		cad1 = nums[k]
		cad2 = cad1 + cad2
		tres++
		if((tres%3) == 0){
			if(k!=0){
				cad2 = "" + cad2
				}
			}
		}
		
	for (dd = dec; dd > 0; dd--)	
	{cad3 += nums[nums.length-dd] }
	if(decimales == true)
	{cad2 += "." + cad3}
	 donde.value = cad2
	}
donde.focus()
}	

function imprimir(numrec) {
		window.open("../fpdf/imprimir_recibomx.php?numrec="+numrec);
	
		}	
        </script>



	</head>
<?php 



$nomb=$_POST["algo"];
$numfac=$_POST["numfac"];
$dsccli=$_POST["dsccli"];
$salact=$_POST["salact"];
$nuevosaldo=$_POST["nuevosaldo"];
$pagacon=$_POST["pagacon"];
$vuelto=$_POST["vuelto"];
$accion=$_POST["accion"];
$accion2=$_GET["accion"];
$monabo=$_POST["monabo"];
$cdgcli=$_POST["cdgcli"];




?>

    
    
    
    
	<body>
		<div id="pagina">
			<div id="zonaContenido">
				<div align="center">
				<div id="tituloForm" class="header">Recibo Anulado </div>
				<p>&nbsp;</p>
				<div id="formulario3" class="contenido">
				<form id="formulario" name="formulario" method="post" action="guardar_tiquete.php">
                    <table class="fuente8" width="96%" cellspacing=0 cellpadding=3 border=0>
						<tr>
						  <td colspan="10" class="header2">Detalle</td>
						</tr>
						<tr>
						  <td width="15%">&nbsp;</td>
						  <td colspan="6">&nbsp;</td>
						  <td>&nbsp;</td>
						  <td colspan="2">&nbsp;</td>
					  </tr>
						<tr>
									          <?php
			
			
			////
			
	//////////////////////////////////////////////////////////// Anulacion del recibo en pagos clientes ///////////////////////////////////////		
			if ($accion2=="baja") {
	$numrec=$_GET["numrec"];
	echo $numrec;
	
	
		//////////////////////////////////////////////////////////  Modifica la el saldo en la 2101  CXC //////////////////////////////////////////
	 			
	$sel_recibo="SELECT * FROM pagos_clientes WHERE numrec = $numrec ";
		$rs_total=mysql_query($sel_recibo);
			$monabo=mysql_result($rs_total,0,"montot");
			$monto=mysql_result($rs_total,0,"montot");
			$numfac=mysql_result($rs_total,0,"numfac");
			$cdgcli=mysql_result($rs_total,0,"cdgcli");
			$cdgusu=mysql_result($rs_total,0,"cdgusu");
				$fecrec=mysql_result($rs_total,0,"fecrec");
					$montot=mysql_result($rs_total,0,"montot");
						$pagacon=mysql_result($rs_total,0,"pagcon");
							$vuelto=mysql_result($rs_total,0,"vuelto");
								$nuevosaldo=mysql_result($rs_total,0,"nuevosaldo");
			
	 
	  $sel_saldoactual="SELECT  salact, dsccli, fecfac  FROM web_2101 WHERE numfac = $numfac ";
		$rs_actual=mysql_query($sel_saldoactual);
			$total=mysql_result($rs_actual,0,"salact");
			$dsccli=mysql_result($rs_actual,0,"dsccli");
			$fecfac=mysql_result($rs_actual,0,"fecfac");
			
		$nuevosaldo = $total +  $monto ;
  
	  $sel_anulacion="UPDATE web_2101 SET salact='$nuevosaldo' WHERE numfac='$numfac'";
		$rs_abono=mysql_query($sel_anulacion);
	
		/////////////////////////////////////////////////////////// Modifica el saldo en la  0301 clientes ///////////////////////////////////////////
	$sel_Saldo="SELECT  Sum(salact) AS totalfac FROM web_2101 WHERE cdgcli = $cdgcli";
		$rs_facturas=mysql_query($sel_Saldo);
		$suma=mysql_result($rs_facturas,0,"totalfac");

	 $sel_abono="UPDATE web_0301 SET salact='$suma' WHERE cdgcli = $cdgcli";
		$rs_abono=mysql_query($sel_abono);
		
		$query="UPDATE pagos_clientes SET estrec='0', montot='0', nomusu='$nomb',  fecmod='$hoy' WHERE numrec='$numrec'";
	$rs_query=mysql_query($query);

}
			
			
					  ?>
						  <td><span class="Estilo1">Cliente</span></td>
						  <td colspan="6"><input id="dsccli" type="text"  name="dsccli" size="40" value="<? echo $dsccli ?> " readonly="readonly" /></td>
						<td><span class="Estilo1">Fecha</span></td>
						  <td colspan="2"><input  name="fecha" type="text" id="fecha" value="<? echo $fecrec?>" readonly="readonly" /></td>
					  </tr>
						<tr>
						  <td>&nbsp;</td>
						  <td colspan="6">&nbsp;</td>
						  <td>&nbsp;</td>
						  <td colspan="2">&nbsp;</td>
					  </tr>
						<tr>
                 
						  <td><span class="Estilo1">N. Factura</span></td>
						  <td colspan="6"><input id="numfac" type="text"  name="numfac" value="<? echo $numfac?>" readonly /></td>
						  <td><span class="Estilo1">Cajero</span></td>
						  <td colspan="2"><input id="algo" type="text"  name="algo" value="<? echo $cdgusu?>" readonly></td>
					  </tr>
						<tr>
						  
						   <td><span class="Estilo1">Fecha</span></td>
						  <td colspan="6"><input id="fecfac" type="text"  name="fecfac" value="<? echo $fecfac?>" readonly /></td>
						 
						  <td width="8%"><span class="Estilo1">Monto</span></td>
                            <td width="25%"><input id="salact" type="text"  name="salact" value="<? echo number_format($salact,2,".",",")?>" readonly="readonly" /></td>
						</tr>
					  <tr>	
						  <td><span class="Estilo1">Abono</span></td>
						  <td colspan="6"><input id="monabo" type="text"  name="monabo" value="<? echo number_format($monabo,2,".",",")?>"  onblur="validar_Monto()" onchange="validar_Monto()" 
						 readonly="readonly"  /></td>
						  <td><span class="Estilo1">Saldo</span></td>
						<td><input id="nuevosaldo" type="text"  name="nuevosaldo" value="<? echo number_format($nuevosaldo,2,".",",")?>" readonly="readonly" /></td>
					  </tr>
						<tr>
						  <td colspan="10"><div align="center"><span class="Estilo1">Pagar </span>	 
					          <input id="pagacon" type="text"  name="pagacon" value="<? echo number_format($pagacon,2,".",",")?>" onblur="Calcular_Vuelto()" onchange="Calcular_Vuelto()" readonly="readonly"/>					      
					      </div></td>
					    </tr>
						<tr>
						  <td colspan="10">  <div align="center"><span class="Estilo1">Vuelto</span>
					        <input   a id="vuelto" type="text"  name="vuelto" value="<? echo number_format($vuelto,2,".",",")?>" readonly="" />
					      </div></td>
						  <td width="1%" rowspan="4">&nbsp;</td>
					  </tr>
					
						<tr>
						  <td>&nbsp;</td>
						  <td colspan="6">                        
						  <td>&nbsp;</td>
						  <td colspan="2">&nbsp;</td>
					  </tr>
						<tr>
						  <td>&nbsp;</td>
						  <td colspan="6">                        					                            
						  <td width="8%">&nbsp;</td>
						  <td colspan="2">&nbsp;</td>
						</tr>
			
						<tr>
						  <td>&nbsp;</td>
					      <td width="1%">&nbsp;</td>
					      <td width="6%">&nbsp;</td>
					      <td width="6%">&nbsp;</td>
					      <td width="6%">&nbsp;</td>
					      <td width="6%">&nbsp;</td>
					      <td width="6%">&nbsp;</td>
					      <td>&nbsp;</td>
					      <td>&nbsp;</td>
					      <td width="20%"><img src="../img/Undo_48x48-32.png" alt="Salir" width="48" height="48" border="0" align="absmiddle"  class="aCentro" title="Salir" onclick="aceptar()" onmouseover="style.cursor=cursor"></td>
						</tr>
              </table>
                  </form>
			 </div>
		  </div>
		</div>
	</body>
</html>
