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

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


// cabeza 
       $sql_in = "SELECT * FROM oprodu_antofagasta";	
		
		$res_in = mysql_query($sql_in,$enlace);	
		$row=0;
		while (mysql_fetch_object ($res_in))
          {
		  $txtndcto=mysql_result($res_in, $row, "Opr_numero");
		  $desc = mysql_result($res_in, $row, "Opr_desca3");
		
		
			  
	///  Busca en Factura 
	
		   $sql_in_det = "SELECT * FROM salida where num_dcto=$txtndcto";
		  
		  $res_in_det = mysql_query($sql_in_det,$enlace);
            $rowdet=0;
            while (mysql_fetch_object ($res_in_det))
		      {
		     $id_factura=mysql_result($res_in_det, $rowdet, "id");
			 $neto = mysql_result($res_in_det, $rowdet, "neto");
			
			  }
			 $descuento=round($neto*$desc/100);
			   $neto=round($neto-$descuento);
			   
		     $iva=round($neto*.19);
			 
			 $total=$neto+$iva;
			 
			
	//**************  Actualiza facturas *********
    
		 
			 
	$wsql = "UPDATE salida SET neto=$neto, iva=$iva, total=$total, descuento=$descuento WHERE id=$id_factura";
			$consulta = mysql_query($wsql,$enlace);	 



		 
			$csql="UPDATE pago_cliente SET valor=$total WHERE num_salida=$id_factura AND tipo='C' ";
			
			$con = mysql_query($csql,$enlace); 

		 	  
		  $row+=1;
	  }





	
		?>
<script>
	alert("Traspaso realizado con exito");
	window.top.open('','_parent','');window.top.close();
</script>
		
	
	
