I need that when selecting the date range by means of datepicker
, verify if there is data or not within the range when executing the query in the file php
, if there are not any send a message.
Since there is no data, it will not generate a PDF.
This is in my function js
:
function Report(fecha1,fecha2,status)
{
var fecha1 =document.getElementById("start").value;
var fecha2 =document.getElementById("end").value;
if()//valida si la consulta tiene datos desde el rango seleccionado
{
}
//solamente valida si estan vacios los campos
if (fecha1 == '' || fecha2 == '') {
$("#fecha1").parent().addClass('has-error');
$("#fecha2").parent().addClass('has-error');
document.getElementById("errorMessageDate").style.display = "block";
document.getElementById("errorMessageDate").innerHTML = "Ingresa una fecha valida.";
document.location.href="#errorMessageDate";
}
else
{
setTimeout(function(){ window.open("http://localhost/WareHouse/outputReport.php?fecha1="+fecha1+"&fecha2="+fecha2+"&status="+status, "_blank"); }, 1000);
$('#myModalReport').modal('hide');initArticles();
console.log(fecha1);
console.log(fecha2);
}
}
Check the information, from the php file:
if(isset($_GET['fecha1']) && isset($_GET['fecha2']) && isset($_GET['status']))
{
$fecha1 = date('Y-m-d', strtotime(str_replace('/','-',$_GET['fecha1'])));
$fecha2 = date('Y-m-d', strtotime(str_replace('/','-',$_GET['fecha2'])));
$fecha1 = $_GET["fecha1"];
$fecha2 = $_GET["fecha2"];
$status = $_GET["status"];
//Trae todos los item que esten por debajo de su minimo en stock.
$connection = new MySqlServerConnection();
$query = "SELECT i.description_item,io.quantity_s,i.reorder_level,i.target_Stock,
io.observations,io.registerDate_Output ,l.name_location,i.status,c.name_category,io.employee
FROM inventory_output AS io
INNER JOIN inventory_list AS i ON numFile = fkInventory
INNER JOIN category as c on id_category = fkInventory
INNER JOIN location as l on id_location = name_area
WHERE io.registerDate_Output BETWEEN '".$fecha1."' AND '".$fecha2."' AND i.status = 1";
$result = $connection->executeQuery($query,array($fecha1,$fecha2,$status));
if ($result > 0) {...}