<?
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = '../index.php';
		</script>
		<? 
		exit();
		}
$id_empresa = $_SESSION['ss_empresa'];
$id_user = $_SESSION['ss_user'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Cuadra total vs detalles</title>
<?
include("../conex.php");
$txtfecha=$_POST["txtfecha"];
$dia = substr ($txtfecha, 0, 2);
$mes = substr ($txtfecha, 3, 2);
$mes2=$mes;
$aņo = substr ($txtfecha, 6, 4);
$ano2=$aņo;

?>

</head>
<body>
<div align="center">revisa LIBRO DE VENTAS MES DE  <?=$mes?> DEL <?=$aņo?></div>
  <div align="center">

    <table width="80%" border="0">
      <tr bgcolor="#CCCCCC">

        <th scope="col"><div align="center">RUT</div></th>
       
        <th scope="col"><div align="center">Nro</div></th>
		<th scope="col"><div align="center">Neto</div></th>
		<th scope="col"><div align="center">SubTotal</div></th>
        	<th scope="col"><div align="center">Diferencia</div></th>
            <th scope="col"><div align="center">Estado 1</div></th>
      </tr>
		<?			
		$total_neto=0;
		$total_sub_total=0;
/*
			SELECT num_dcto, neto-sum(sub_total) as net FROM salida, movimiento WHERE rut_cliente<>'00.000.000-0' AND extract(month from fecha_emision)='07' 
AND extract(year from fecha_emision)='2015' AND (salida.tipo_dcto=2 OR salida.tipo_dcto=6 OR salida.tipo_dcto=7) and id_soe =salida.id group by num_dcto

SELECT rut_cliente, num_dcto, salida.factor*neto as net, salida.factor, sum(movimiento.factor*sub_total) as sub_tot, salida.tipo_dcto,salida.factor*neto-sum(movimiento.factor*sub_total)  FROM salida, movimiento WHERE rut_cliente<>'00.000.000-0' AND extract(month from fecha_emision)='10' AND extract(year from fecha_emision)='2015' AND (salida.tipo_dcto=2 OR salida.tipo_dcto=6 OR salida.tipo_dcto=7  OR salida.tipo_dcto=33  OR salida.tipo_dcto=61 OR salida.tipo_dcto=56) and id_soe =salida.id group by id_soe
	*/	
	$sqlfs =  "SELECT rut_cliente, num_dcto, salida.factor*neto as net, sum(movimiento.factor*sub_total) as sub_tot, salida.tipo_dcto, salida.factor*neto-sum(movimiento.factor*sub_total) as dif FROM salida, movimiento WHERE rut_cliente<>'00.000.000-0' AND extract(month from fecha_emision)='$mes2' AND extract(year from fecha_emision)='$ano2' AND (salida.tipo_dcto=2 OR salida.tipo_dcto=6 OR salida.tipo_dcto=7  OR salida.tipo_dcto=33  OR salida.tipo_dcto=61 OR salida.tipo_dcto=56) and id_soe =salida.id group by id_soe AND extract(month from fecha)<>'$mes2'";
		  	$resfs = mysql_query($sqlfs,$enlace);	
			$cont=0;
			while (mysql_fetch_object ($resfs))
				{
				
			$rut = mysql_result($resfs, $cont, "rut_cliente");
				$nro = mysql_result($resfs, $cont, "num_dcto");
				$tipo_dcto = mysql_result($resfs, $cont, "salida.tipo_dcto");
			
				$net = mysql_result($resfs, $cont, "net");
			
	           $sub_total = mysql_result($resfs, $cont, "sub_tot");
	$dif = mysql_result($resfs, $cont, "dif");
		
			 $esta="OK";
		//if ($dif!=0) 
		  {$esta="Error";
			?>
		
        	<tr>
		       
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong>	  <?=$rut?> </strong></span></div></td>
				
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong>
	            	 <?=$tipo_dcto?> <?=$nro?>
				</strong></span></div></td>
                
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="right"><span class="Estilo1"><strong>   <?=$net?></strong></span></div></td>
				
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="right"><span class="Estilo1"><strong>
				  <?=$sub_total?>
			    </strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="right"><span class="Estilo1"><strong>
				  <?=$dif?>
			    </strong></span></div></td>
<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="right"><span class="Estilo1"><strong>
				  <?=$esta;?>
			    </strong></span></div></td>
	        </tr>	
			<?
			
			}
			$cont+=1;
			}
			?>
			    </table>
		<form name="form1" method="post" action="">

	  <input type="button" name="imprimir" id="imprimir" value="Imprimir" onClick="fun_imprimir();">
	 <input type="button" name="Cerrar" id="Cerrar" value="Cerrar" onClick="cerrar();">
    </form>
  </div>
</body>
</html>

<script language="javascript" type="text/javascript">
function cerrar()
    {
     window.top.open('','_parent','');
      window.top.close();
    }
function fun_imprimir()
	{
	document.getElementById('imprimir').style.display = "none";
	window.print();
	document.getElementById('imprimir').style.display = "block";
	};

</script>