I need to generate a PDF report and show the items that are between a date range.
This is the modal where the datepicker and the Generate Report button are found with a onclick="Report()"
that leads to a function in JavaScript
, where it opens the new window with PDF
.
<input id="start" type="date">
<input id="end" type="date">
It is in the function in the js.
function Report()
{
setTimeout(function(){ window.open("http://localhost/WareHouse/reporte.php?fecha=? and fecha2=?"+fecha1+fecha2, "_blank"); }, 1000);
}
This is the structure of the PDF which is generated if I test from postman. Putting data by hand.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php echo'<title>Inventory To Reorder</title>';?>
</head>
<body onload="window.print()">
<?php echo '<img src="http://localhost/WareHouse/assets/img/logo.png" style="position: absolute; top: 0; left: 0; height:6%; width:23%; margin-top:40px; margin-left:40px;"/>';?>
<?php echo '<center style="margin-top:120px; font-size:14pt;"><strong>Inventory To Reorder<strong></center>';?>
<?php echo '<label><center>____________________________________________________________________________</center></label><br>';?>
<?php
require_once('apis/connection.php');
if(isset($_GET['fecha1']) && isset($_GET['fecha2']))
{
$fecha1 = $_GET["fecha1"];
$fecha2 = $_GET["fecha2"];
//Trae todos los item que esten por debajo de su minimo en stock.
$connection = new MySqlServerConnection();
$query = 'SELECT i.description_item,i.quantity,u.name_unit,i.reorder_Level,i.target_Stock,l.name_location,i.commentt,io.quantity_s
FROM inventory_list AS i
INNER JOIN unit_mesurement AS u ON id_unit = fkUnit
INNER JOIN locatiON AS l on id_location = fkLocation
INNER JOIN inventory_output as io on id_output = fkInventory
WHERE '".$fecha1."' AND '".$fecha2."'';
$result = $connection->executeQuery($query,array($fecha1,$fecha2));
if ($result > 0) {
?>
<center>
<table class="table table-striped xd" border="1px;" id="tabla">
<thead>
<tr>
<th style="width: 3%;">Description</th>
<th style="width: 3%;">Quantity</th>
<th style="width: 3%;">Usage</th>
<th style="width: 3%;">Name Unit</th>
<th style="width: 3%;">Reorder Level</th>
<th style="width: 3%;">Target Stock</th>
<th style="width: 3%;">Area</th>
<th style="width: 3%;">Comment</th>
</tr>
</thead>
<?php
$arraycount=count($result);
$i=0;
$total=0;
while ($i < $arraycount)
{
?>
<tr>
<td><center><?php echo $result[$i]['description_item']; ?></td>
<td><p style="color:red;" ><?php echo $result[$i]['quantity']; ?></p></td>
<td>
<?php
$qs = $result[$i]['quantity_s'];
switch (true) {
case ($qs >= 1000 && $qs <= 2000) :
echo " 1000 a 2000 SEMANAL";
break;
case ($qs >= 100 && $qs <= 200) :
echo " 100 a 200 SEMANAL Y/O QUINCENAL";
break;
case ($qs >5 || $qs <6) :
echo "5 a 6 CADA 2 SEMANAS";
break;
}
?>
</td>
<td><?php echo $result[$i]['name_unit']; ?></td>
<td><?php echo $result[$i]['reorder_Level']; ?></td>
<td><?php echo $result[$i]['target_Stock']; ?></td>
<td><?php echo $result[$i]['name_location']; ?></td>
<td><?php echo $result[$i]['commentt']; ?></center></td>
</tr>
<?php $i++;
}
?>
</table><br><br>
</center>
<?php
}
//}
}
?>
</body>
My problem is that I do not know how to do it when you click on the Generate Report button, check the values and execute the query so that it shows me the data within the selected dates.
The PDF and its structure are used to put data directly in postman, now how do I do the same from the date picker?