<?php

session_cache_limiter('private');
session_start();
$com = "I";
include("DMMYSQLG.php");
include("DSA3000.php");
include("DMMYSQLG.php");
 
$name="Consulta_Saldo_x_Aņo.xls"; 
if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
	header('Content-Type: application/force-download');
else
	header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename="'.$name.'"');
?>
<html>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<?php
 
include("DF30000.inc");
?>
<body>
<div align="center">
  <form name="frm1" id="frm1" method="post" action="" >
  <input name="botf1" type="hidden" value="
  <?php
 
  if(!isset($_POST['t1'])){
  	echo date('j/m/Y');
  }else{
  	echo $_POST['t1'];
  }
  ?>">
      <input name="botf2" type="hidden" value="
  <?php
 
  if(!isset($_POST['t1'])){
  	echo date('j/m/Y');
  }else{
  	echo $_POST['t2'];
  }
  ?>">
    <br>
  <?php
 
  $sql = mysqli_query($con ,"SELECT * FROM dgrefdve where fec_dev = '".date('Y-m-d')."'");
  ?>    
    <table width="1147"  align="center">
      <tr>
        <th colspan="20">&nbsp;</th>
      </tr>
      <tr>
        <th colspan="20">Devolucion de Ventas</th>
      </tr>
      <tr>
        <th width="76"><div align="center">Nota Credito</div></th>
        <th width="74"><div align="center">Con.Sec.</div></th>
        <th width="74"><div align="center">No.Parte</div></th>
		<th width="112"><div align="center">Descrip.</div></th>
		<th width="73"><div align="center">Cve.Ven.</div></th>
        <th width="94"><div align="center">Pre.Unitario</div></th>
        <th width="93"><div align="center">Importe</div></th>
		<th width="83"><div align="center">I.V.A.</div></th>
		<th width="112"><div align="center">Total Factura</div></th>
        <th width="98"><div align="center">Cos.Unita.</div></th>
        <th width="98"><div align="center">Cos.Total</div></th>
		<th width="84"><div align="center">Descuento</div></th>
      </tr>
	<?php

	if(isset($_POST['t1'])){
		$fec = $_POST['t1'];
		include('DF20000.php');
			$fecha_inicial = $f_m;
		$fec = $_POST['t2'];
		include('DF20000.php');
			$fecha_final = $f_m;
		$sql=mysqli_query($con ,"SELECT * FROM dgrefdve where fec_dev between '$fecha_inicial' and '$fecha_final'");
	}
 	include("DE10000.php");
$sql=mysqli_query($con ,"SELECT * FROM dgrefdve where fec_dev between '$fecha_inicial' and '$fecha_final'");
	{
		$sqlx=mysqli_query($con ,"SELECT * FROM dgrefdvd where cons_dev = '".$reg['fol_recep']."'");
		while($regx = mysqli_fetch_array($sqlx))
		{
			echo "<tr>";
			echo "<td><div align='center'>" . $reg["num_dev"] . "$nbsp</div></td>";
			echo "<td> <div align='center'>" . $reg["num_dev"] . "&nbsp</div></td>";
			$result1=mysqli_query($con ,"SELECT * FROM dginvent WHERE dginvent.modulo='".$_SESSION['mod_sis']."' AND   nparte1 = '".$regx['nparte1']."'");
			$row1 = mysqli_fetch_array($result1);
			echo "<td> <div align='center'>" . $row1["nparte1"]."</div></td>";
			echo "<td> <div align='center'>" . $row1["np_desc1"]."</div></td>";
			echo "<td><div align='center'>" . $reg["oper"] . "&</div></td>";
			echo "<td><div align='center'>" . $regx["pu_dev"] . "&</div></td>";
			echo "<td><div align='center'>" . $regx["subtotal"] . "</div></td>";
			echo "<td><div align='center'>" . $regx["iva_tot"] . "</div></td>";
			echo "<td><div align='center'>" . $regx["tot_dev"] . "</div></td>";
			echo "<td><div align='center'>" . $regx["cos_ref"] . "</div></td>";
			$cos_tot = $regx['cos_ref'] * $regx['can_ref'];
			echo "<td><div align='center'>" . $cos_tot . "&nbsp</div></td>";
			echo "<td><div align='center'>" . $regx["des"] . "&nbsp</div></td>";
			echo "<tr>";
		}
	}
	mysqli_close($con);

	?>
    </table>
  </form>
</div>
</body>
</html>