<?php

header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=Reporte Venta de inventario.xls");

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

       $parametros = "SELECT * FROM web_0000 ";
       $result_parametros = $mysqli->query($parametros);
       $row_para = $result_parametros->fetch_array();
     
	   $NombreComercial =  $row_para["NOMCOM"];
	   $Razon           =  $row_para["RAZSOC"];
	   $Direccion       =  $row_para["DIREMP"];
	   $Cedula          =  $row_para["CEDJUR"];
	   $Telefono        =  $row_para["NUMTEL"];
	   
	   $monto_impuesto  = 0 ;	
	   $monto_costo     = 0 ;
	   $total           = 0 ;	
	   $monto_presinimp = 0 ;


?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LISTA DE INVENTARIO</title>
</head>
<body>
<table width="50%" border="0" cellspacing="0" cellpadding="0">
    <tr>   </tr>
  <tr>
     <td></td>
 <td colspan="8"  bgcolor="skyblue"><div align="center"><strong>REPORTE VENTA DE INVENTARIO</strong></div></td>
  </tr>
     <tr>   </tr>
  <tr>
      <td width="10%"></td>
    <td  border="1" width="10%"><div align="center"><strong>CODIGO</strong></div></td>
    <td width="37%"><div align="center"><strong>DESCRIPCION</strong></div></td>
    <td width="16%"><div align="center"><strong>EXISTENCIA</strong></div></td>
    <td width="25%"><div align="center"><strong>VENTA S/IVA.</strong></div></td>
	<td width="25%"><div align="center"><strong>IMPUESTO</strong></div></td>
	<td width="25%"><div align="center"><strong>TOTAL S/IVA</strong></div></td>
	<td width="25%"><div align="center"><strong>TOTAL IMPUESTO</strong></div></td>
	<td width="25%"><div align="center"><strong>TOTAL VENTA</strong></div></td>
  </tr>
  
<?php
$cdgfam= 000;
$cdgfam2= 000;	


 $consulta= "select * from web_1001  WHERE tipart  <> 2 AND exiact > 0 ORDER BY   dscart";
	if ($resultado = $mysqli->query($consulta)) 

  	while ($res = $resultado->fetch_assoc()) {		


	$codigo     = $res["CDGART"];
	$cdgbar     = $res["CDGBAR"];
	$cdgbar2    = "Cod. ".$cdgbar;
	$dscart     = $res["DSCART"];
	$costo      = $res["cosart"];
	$existencia = $res["EXIACT"];
	$pre001     = $res["PRE001"];
	$PRECIO     = $res["PRE001"];
	$exiact     = number_format ($existencia, 2);
	$cdgfam     = $res["CDGFAM"];
	$cdgfam     = sprintf("%03d",$cdgfam); 
	$ivporc     = $res["ivporc"]/100+1;	
	$cob_iv     = $res["COB_IV"];
	
	if ($cob_iv==1)	{	
	
	$presinimp = $pre001/$ivporc ;
	$impart = $pre001 - $presinimp;
	
	
	}else {	
	
	$impart = 0;
	$presinimp = $pre001 ;
	
	}
	
	$presinimp = $presinimp  *  $existencia; 
	$impuesto_total =  $impart *  $existencia; 
	$subtotal = $presinimp  + $impuesto_total;
	
	$monto_impuesto = $monto_impuesto + $impuesto_total ;	
	$monto_presinimp = $monto_presinimp + $presinimp  ;
	 
	
?>  

 <tr>
   <td></td>
   <td><div align="left"><?php echo $cdgbar; ?></div></td>
	<td><?php echo $dscart; ?></td>
	<td><div align="center"><?php echo $exiact; ?></div></td>
	<td><div align="right"><?php echo number_format($PRECIO,2); ?></div></td>  
		<td><div align="right"><?php echo number_format($impart,2); ?></div></td>  
	<td><div align="right"><?php echo number_format($presinimp ,2); ?></div></td> 

	<td><div align="right"><?php echo number_format($impuesto_total,2); ?></div></td> 
	<td><div align="right"><?php echo number_format($subtotal,2); ?></div></td> 

                 
 </tr> 
  <?php
  
}
$monto_total = $monto_impuesto + $monto_presinimp;
  ?>
</table>

<table>

 <tr>
   <td></td>
   <td></td>
   <td></td>
   <td></td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
 </tr>
 <tr>
   <td width="6"></td>
   <td width="6"></td>
	<td width="6"></td>
	<td width="365"></td>
	<td width="116">TOTAL</td>  
	<td width="124"></td> 
	<td width="124"><div align="right"><?php echo number_format($monto_presinimp,2); ?></div></td> 
	<td width="124"><div align="right"><?php echo number_format($monto_impuesto,2); ?></div></td> 
	<td width="124"><div align="right"><?php echo number_format($monto_total,2); ?></div></td>                    
 </tr> 
</table>
</body>
</html>