Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/01/2019, 14:07
karenlorenadg
 
Fecha de Ingreso: octubre-2008
Ubicación: Colombia
Mensajes: 448
Antigüedad: 15 años, 7 meses
Puntos: 2
Como arreglo este filtro en php de mis ventas

Hola a todos, tengo un problema con esta consulta. Tiene la opcion para consultar llas ventas de una fecha a otra en especifico, Todo funciona bien hasta cierto tiempo, pero resulta que ahora cuando consulto or ejemplo las fechas de Diciembre 15 de 2018 a Enero 15 de 2019 me hace la consulta desde todos los registros de años anteriores, es decir, que si tengo el sistema desde el 2017 me muestra los registros del 2017 hasta el 2019, no se que ppasa ni como solucionarlo.

Aqui les dejo el codigo de mi consulta

<form action="salesreport.php" method="get" class="form-horizontal">
<center><strong>De : <input type="text" style="width: 223px; padding:14px;" name="d1" class="tcal" value="" placeholder="mm/dd/aa" /> A: <input type="text" style="width: 223px; padding:14px;" name="d2" class="tcal" value="" placeholder="mm/dd/aa" />
<button class="btn btn-info" style="width: 123px; height:50px; margin-top:-8px;margin-left:8px;" type="submit"> Ver Reporte</button>
<a href="salesreport.php?d1=0&d2=0"><button class="btn btn-danger" style="width: 145px; height:50px; margin-top:-8px;margin-left:8px;"> Limpiar Reporte</button></a>
</strong></center>
</form>
<br>
<div class="content" id="content">
<div style="font-weight:bold; text-align:center;font-size:14px;margin-bottom: 15px;">
REPORTE DE VENTAS DE: <font color="#01A9DB"><b> &nbsp;<?php echo $_GET['d1'] ?>&nbsp;a&nbsp;<?php echo $_GET['d2'] ?></b></font>
</div>

<div class="table-responsive">
<table class="table table-bordered table-hover table-striped table-responsive" data-plugin="DataTable" id="resultTable" style="text-align: left;" cellspacing="0" width="100%">
<thead>
<tr>
<th width="10%"> Num de Orden </th>
<th width="10%"> Producto </th>
<th width="10%"> Cant. </th>
<th width="10%"> Categoria </th>
<th width="10%"> Fecha Trans. </th>
<th width="10%"> Cantidad </th>
<th width="10%"> Ganancia </th>
</tr>
</thead>
<tbody>

<?php
include('config/connect.php');
$d1=$_GET['d1'];
$d2=$_GET['d2'];
$result = $db->prepare("SELECT * FROM sales_order WHERE date BETWEEN :a AND :b ORDER by transaction_id DESC ");
$result->bindParam(':a', $d1);
$result->bindParam(':b', $d2);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<tr class="record">
<td><?php echo $row['invoice']; ?></td>
<td><?php echo $row['gen_name']; ?></td>
<td><?php echo $row['qty']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['date']; ?></td>



<td style="text-align:right"><?php echo $row['amount']; ?></td>
<td style="text-align:right">
<?php echo $row['profit']; ?></td>
</tr>
<?php
}
?>

</tbody>
<thead>
<tr>
<th colspan="5" style="border-top:1px solid #999999" ><p align="left"> Total: </th>
<th colspan="1" style="border-top:1px solid #999999"> <p align="right">$
<?php
function formatMoney($number, $fractional=false) {
if ($fractional) {
$number = sprintf('%.2f', $number);
}
while (true) {
$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
if ($replaced != $number) {
$number = $replaced;
} else {
break;
}
}
return $number;
}
$d1=$_GET['d1'];
$d2=$_GET['d2'];
$results = $db->prepare("SELECT sum(amount) FROM sales WHERE date BETWEEN :a AND :b");
$results->bindParam(':a', $d1);
$results->bindParam(':b', $d2);
$results->execute();
for($i=0; $rows = $results->fetch(); $i++){
$dsdsd=$rows['sum(amount)'];
echo formatMoney($dsdsd, true);
}
?>
</th>
<th colspan="1" style="border-top:1px solid #999999"> <p align="right">$
<?php
$resultia = $db->prepare("SELECT sum(profit) FROM sales WHERE date BETWEEN :c AND :d");
$resultia->bindParam(':c', $d1);
$resultia->bindParam(':d', $d2);
$resultia->execute();
for($i=0; $cxz = $resultia->fetch(); $i++){
$zxc=$cxz['sum(profit)'];
echo formatMoney($zxc, true);
}
?>
</th>

</tr>
</thead>
</table>
</div>
</div>
__________________
Desarrollo de Aplicaciones de Escritorio, Sitios Web, Audio y Video en SISGUS