<?
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>Nota de Venta</title>
<form id="form1" name="form1" method="post" action="index.php" target="_self">
<?
include("../conex.php");

 $id_vendedor=$_GET["id"];
 $id_bodega=$_POST["id_bodega"];

$txtfecha=$_POST["fecha"];

$dia = substr ($txtfecha, 0, 2);
$mes = substr ($txtfecha, 3, 2);
$mes2=$mes;
$año = substr ($txtfecha, 6, 4);
if ($mes=='01') $mes = "ENERO";
if ($mes=='02') $mes = "FEBRERO";
if ($mes=='03') $mes = "MARZO";
if ($mes=='04') $mes = "ABRIL";
if ($mes=='05') $mes = "MAYO";
if ($mes=='06') $mes = "JUNIO";
if ($mes=='07') $mes = "JULIO";
if ($mes=='08') $mes = "AGOSTO";
if ($mes=='09') $mes = "SEPTIEMBRE";
if ($mes=='10') $mes = "OCTUBRE";
if ($mes=='11') $mes = "NOVIEMBRE";
if ($mes=='12') $mes = "DICIEMBRE";
?>
<style type="text/css">
<!--
.Estilo1 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;}
.Estilo2 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color:#FF0000}
-->
</style>
</head>  <br>
<body LINK="#FFFFFF" VLINK="#FFFFFF" ALINK="#FFFFFF">
<div align="center" class="titulos2">LISTADO DE NOTAS  MES DE  <?=$mes?> DEL <?=$año?> Bodega <?=$bodega?> Vendedor <?=$vende?></div>
  <div align="center">

    <table width="80%" border="0">
      <tr bgcolor="#CCCCCC">
	  	<th width="5%" scope="col"><div align="center">Correlativo</div></th>
        <th width="5%" scope="col"><div align="center">Día</div></th>
        <th width="7%" scope="col"><div align="center">Hora</div></th>
        <th width="9%" scope="col"><div align="center">RUT</div></th>
        <th width="21%" scope="col"><div align="center">Cliente</div></th>
        <th width="8%" scope="col"><div align="center">Nro</div></th>
        <th width="10%" scope="col"><div align="center">Total</div></th>
        <th width="9%" scope="col"><div align="center">NºFactura</div></th>
      </tr>
		<?	 
		
		$total_total=0;
  
		
			
		$sqlfs = "SELECT * FROM salida, tipo_dcto WHERE extract(month from fecha_emision)='$mes2'  AND extract(year from fecha_emision)='$año' AND tipo_dcto.descripcion='NOTA VENTA' AND tipo_dcto.id = salida.tipo_dcto AND salida.empresa = $id_empresa AND vendedor = $id_vendedor  AND salida.bodega = $id_bodega AND rut_cliente<>'00.000.000-0' ORDER BY num_dcto";
		
			
		  	$resfs = mysql_query($sqlfs,$enlace);	
			$cont=0;
			while (mysql_fetch_object ($resfs))
				{
				$fecha = mysql_result($resfs, $cont, "fecha_emision");
				$dia = substr ($fecha, 8, 2);
				$iddcto = mysql_result($resfs, $cont, "tipo_dcto");
				if($iddcto==3)$dcto='NV';
						
				$hora = mysql_result($resfs, $cont, "hora");
				
				$factura='';
				$estado2 = mysql_result($resfs, $cont, "documento_control");
				
				$rut = mysql_result($resfs, $cont, "rut_cliente");
				if ($rut!=''){
				$sqlc = "SELECT * FROM nombres WHERE rut='$rut'";
		  		$resc = mysql_query($sqlc,$enlace);
				
				$nombre = mysql_result($resc, 0, "razon_social");
				}
				else 
				{
				$nombre = "Boleta";
				$rut="&nbsp;";
				}
				$nro = mysql_result($resfs, $cont, "num_dcto");
				$idasal = mysql_result($resfs, $cont, "id");		
				$total = mysql_result($resfs, $cont, "total");
				$total_total+=$total;
				$total=number_format($total,0,',','.');
				
				if ($estado2!=null) 
						{
                        $factura = mysql_result($resfs, $cont, "documento_control");
						$sqlfx = "SELECT num_dcto FROM salida WHERE id=$factura";
		  	            $resfx = mysql_query($sqlfx,$enlace);
						$factura = mysql_result($resfx, 0, "num_dcto");
						}

		  	?>
			<tr>
		        <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong><?=$cont+1?></strong></span></div></td>
                 <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong><?=$dia?></strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong><?=$hora?> </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><?=$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><?=$nombre?></strong></span></div></td>
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong><?=$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><?=$total?></strong></span></div></td>
				
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong>
	            	<?=$factura?>
				</strong></span></div></td>
				
	        </tr>	
			<?
		
			$cont+=1;	
			}
			
			$total_total=number_format($total_total,0,',','.');
			?>
			<tr>
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong>
	            
				</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>
	            
				</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></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></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></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>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>
					<?=$total_total;?>
				</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>
	            	
				</strong></span></div></td>
	        </tr>
			
			
    </table>
	
	
	<form name="form1" method="post" action="">
	  <td width="30%" align="rigth">
			<input type="submit" name="salir" value="Salir" onClick="fun_salir();"/>
		</td>
         <td width="30%" align="rigth">
	  <input type="button" name="imprimir" id="imprimir" value="Imprimir" onClick="fun_imprimir();">
	  </td>
	 
    </form>

  </div>
</body>
</html>

<script language="javascript" type="text/javascript">
function fun_salir()
	{
	 document.form1.submit();
	}
function fun_imprimir()
	{
	document.getElementById('imprimir').style.display = "none";
	window.print();
	document.getElementById('imprimir').style.display = "block";
	};

</script>
</script>