<?php
$usuario = $_COOKIE["usuario"];
$nivel = $_COOKIE["nivel"];
if($nivel=="administrador"){$cobrador=$_GET["usuario"];
    
}else{
    $cobrador=$usuario;
}
?>

<style>
    th,td{
        text-align: left;
    }
    *{
        font-family: Arial;
        font-size: 12px;
        font-wight:light;

    }
table,td,th{
    border:gray 1px solid;
    border-collapse: collapse;
    font-size: 12px;
}

th{
    background: green;
    color:white;
}
</style>
<?php
include_once("../php/config.php");
    $sql_empresa = mysql_query("SELECT * FROM empresa") or die(mysql_error());
$enombre= @mysql_result($sql_empresa,0,"nombre");
$etelefono= @mysql_result($sql_empresa,0,"telefono");   
$edireccion= @mysql_result($sql_empresa,0,"direccion"); 
$ernc= @mysql_result($sql_empresa,0,"rnc"); 
$eemail= @mysql_result($sql_empresa,0,"email"); 
    
?>
<span class="datos_empres2" style="font-size: 30px;font-weight: bolder;font-family: 'Arial black'"><?php echo $enombre;?></span><b><br>
<span class="datos_empres"><?php echo $etelefono;?> </span><br>
<span class="datos_empres"><?php echo $edireccion;?> </span><br>
<span class="datos_empres"><?php echo $ernc;?></span><br>
<h3 style="font-size: 25px; text-decoration: underline;">Reporte de compras</h3>
<?php

include_once("../php/formatos.php");
$proveedor = $_GET["proveedor"];
$usuario = $_GET["usuario"];

$termino = $_GET["termino"];
$fecha1 = $_GET["fecha1"];
$fecha2 = $_GET["fecha2"];
$estado = $_GET["estado"];
echo "<b>Fecha:</b> desde <font color='blue'>".$fecha1."</font> hasta <font color='blue'>".$fecha2."</font>, <b>Usuario</b>: <font color='red'>".$cobrador."</font><br>";
echo "<b>Proveedor:</b> <font color='blue'>".$proveedor."</font>, ";
echo " <b>(Termino compra: </b><font color='green'>".$termino.")</font>";

$sql = mysql_query("select * from compras where 
                    proveedor like '%".$proveedor."%'
                    and usuario like '%".$usuario."%'
					and fecha between '$fecha1' and '$fecha2'") or die(mysql_error());

echo "<table><th>Orden #</th><th>Fecha</th><th>Proveedor</th><th>Monto Moneda local</th><th>Producto</th><th>Balance GOURDE</th>";
while($r = mysql_fetch_array($sql)){
    $c++;
    ///$total+=$r["total"];
    $balance+=$r["balance"];
    $costo+=$r["costo"];
    $impuestos+=$r["impuesto"];
    
    echo "<tr>";
    echo "<td>".$r["id_venta"]."</td>";
    echo "<td>".$r["proveedor"]."</td>";
    echo "<td>".$r["ncf"]."</td>";
    echo "<td>".fecha($r["fecha"])."</td>";

    echo "<td>".decimal($r["costo"])."</td>";
    echo "<td>".decimal($r["producto"])."</td>";
    
    echo "<td>".decimal($r["total"])."</td>";
    
   
    
    echo "</tr>";
}
 echo "</table>";
 echo "</br>";
 

 
 $sqlIe = mysql_query("select sum(total_costo) as total from detalle_compra where tipo_impuesto='0.00' and fecha between '$fecha1' and '$fecha2'") or die(mysql_error());
$sqlI18 = mysql_query("select sum(total_costo) as total from detalle_compra where tipo_impuesto='18.00' and fecha between '$fecha1' and '$fecha2'") or die(mysql_error());
$sqlI16 = mysql_query("select sum(total_costo) as total from detalle_compra where tipo_impuesto='16.00' and fecha between '$fecha1' and '$fecha2'") or die(mysql_error());
$sqlI13 = mysql_query("select sum(total_costo) as total from detalle_compra where tipo_impuesto='13.00' and fecha between '$fecha1' and '$fecha2'") or die(mysql_error());
$sqlI10 = mysql_query("select sum(total_costo) as total from detalle_compra where tipo_impuesto='10.00' and fecha between '$fecha1' and '$fecha2'") or die(mysql_error());
$sqlTarjeta = mysql_query("select sum(total) as total from compras where termino='Tarjeta' and fecha between '$fecha1' and '$fecha2'") or die(mysql_error());
$sqlCredito = mysql_query("select sum(total) as total from compras where termino='Credito' and fecha between '$fecha1' and '$fecha2'") or die(mysql_error());
$sqlEfectivo = mysql_query("select sum(total) as total from compras where termino='Efectivo' and fecha between '$fecha1' and '$fecha2'") or die(mysql_error());
$sqlCheque = mysql_query("select sum(total) as total from compras where termino='Cheque' and fecha between '$fecha1' and '$fecha2'") or die(mysql_error());

echo "<br>";
echo "<table>";
echo "<td  bgcolor='yellow'>TOTAL</td>";
echo "<td  bgcolor='yellow'>".@decimal(mysql_result($sqlI18,0,"total") + mysql_result($sqlI16,0,"total") + mysql_result($sqlI13,0,"total") + mysql_result($sqlI10,0,"total") +  mysql_result($sqlIe,0,"total"))."</td>";
echo "<tr>";

echo "<td>TOTAL OPERACIONES EXENTAS</td>";
echo "<td>".@decimal(mysql_result($sqlIe,0,"total"))."</td><tr>";



echo "<td>TOTAL OPERACIONES GRABADAS AL 18%</td>";
echo "<td>".@decimal(mysql_result($sqlI18,0,"total"))."</td>";
echo "<td>VALOR ITBIS</td>";
$s18 = mysql_result($sqlI18,0,"total");
echo "<td>".@decimal($s18 - $s18 / 1.18)."</td><tr>";

echo "<td>TOTAL OPERACIONES GRABADAS AL 16%</td>";
echo "<td>".@decimal(mysql_result($sqlI16,0,"total"))."</td>";
echo "<td>VALOR ITBIS</td>";
$s16 = mysql_result($sqlI16,0,"total");
echo "<td>".@decimal($s16 - $s16 / 1.16)."</td><tr>";

echo "<td>TOTAL OPERACIONES GRABADAS AL 13%</td>";
echo "<td>".@decimal(mysql_result($sqlI13,0,"total"))."</td>";
echo "<td>VALOR ITBIS</td>";
$s13 = mysql_result($sqlI13,0,"total");
echo "<td>".@decimal($s13 - $s13 / 1.13)."</td><tr>";


echo "<td>TOTAL OPERACIONES GRABADAS AL 10%</td>";
echo "<td>".@decimal(mysql_result($sqlI10,0,"total"))."</td>";
echo "<td>VALOR ITBIS</td>";
$s10 = mysql_result($sqlI10,0,"total");
echo "<td>".@decimal($s10 - $s10 / 1.10)."</td><tr>";

echo "<td>TOTAL OPERACIONES GRABADAS</td>";
echo "<td>".@decimal(mysql_result($sqlI18,0,"total") + mysql_result($sqlI16,0,"total") + mysql_result($sqlI13,0,"total") + mysql_result($sqlI10,0,"total"))."</td>";
echo "<tr>";
echo "<td bgcolor='yellow'></td><tr>";
echo "<td>TOTAL COMPRAS EN EFECTIVO</td>";
echo "<td>".@decimal(mysql_result($sqlEfectivo,0,"total"))."</td><tr>";
echo "<td>TOTAL COMPRAS A CREDITO</td>";
echo "<td>".@decimal(mysql_result($sqlCredito,0,"total"))."</td><tr>";
echo "<td>TOTAL COMPRAS TARJETA DE CREDITO</td>";
echo "<td>".@decimal(mysql_result($sqlTarjeta,0,"total"))."</td><tr>";
echo "<td>TOTAL COMPRAS CHEQUE</td>";
echo "<td>".@decimal(mysql_result($sqlCheque,0,"total"))."</td><tr>";

echo "</table>";

 ///echo "<b>Pagado:</b><font color='red'>".decimal($mora)."</font><br>";
 echo "<br><b>BALANCE PENDIENTE:</b><font color='green'>".decimal($balance)."</font><br>";

?>