<?php 
include "../config.php";
$customer= $_POST['customer'];
$product = $_POST['product'];
$vehicle = $_POST['vehicle'];
//$time_from = empty($_POST['timefrom'])?'00:00:00':$_POST['timefrom'];
//$time_to = empty($_POST['timeto'])?'24:00:00':$_POST['timeto'];
//$ticket = $_POST['ticket'];
$date_minimum = mysqli_query($connect,"select min(id),date from ticket");
$date_min_val = mysqli_fetch_assoc($date_minimum);
$date_min_value = $date_min_val['date'];
$date_from = empty($_POST['fromd'])?$date_min_value:$_POST['fromd'];
$date_maximum = mysqli_query($connect,"select CURRENT_DATE() as maxdate");
$date_max_val = mysqli_fetch_assoc($date_maximum);
$date_max_value = $date_max_val['maxdate'];
 $date_to = empty($_POST['tod'])?$date_max_value:$_POST['tod'];
$sno = 0;
$sql_statement="
select date,ticket,tripno,vehicleno, customer, product,cft,emptyweight,editby,delivery,remarks from ticket where status!='deleted' && product like '%$product%' && customer like '%$customer%' && date between '$date_from' and '$date_to' && vehicleno like '%$vehicle%'
";
//echo $sql_statement;
$statement = mysqli_query($connect,$sql_statement);
while($statement_report=mysqli_fetch_array($statement)){
    $customer_code = $statement_report['customer'];
    $cus=mysqli_query($connect,"select name from customerdetails where status !='deleted' && code='$customer_code'");
while($cusshow = mysqli_fetch_array($cus))
{
    $customer_name = $cusshow['name'];
}
$product_code=$statement_report['product'];
$pro=mysqli_query($connect,"select productname from productdetail where status !='deleted' && productcode='$product_code'");
while($proshow = mysqli_fetch_array($pro))
{
   
    $product_name = $proshow['productname'];
}
$ticket_code = $statement_report['ticket'];
$ticket_trip=mysqli_query($connect,"select tripno,date,time from ticket where status !='deleted' && ticket='$ticket_code'");
while($tkt_show = mysqli_fetch_array($ticket_trip))
{
   
    $trip_no = $tkt_show['tripno'];
    $entry_date = $tkt_show['date'];
    $entry_time = $tkt_show['time'];
}
$sno+=1;
$date_create = date_create($statement_report['date']);
$date_change = date_format($date_create,"d/m/y");
//$adjustment = number_format(($statement_report['netqtyori']-$statement_report['netqty']),2,'.','');
//$adjustment_kg =number_format(( $adjustment * $statement_report['unitvalue']),2,'.','');
    $statement_out[]=(object)["Sno"=>$sno,"date"=>$date_change,"ticket"=>$statement_report['ticket'],"tripno"=>$trip_no,"vehicle"=>$statement_report['vehicleno'],"customername"=>$customer_name,"productname"=>$product_name,"capacity"=>$statement_report['cft'],"emptyweight"=>$statement_report['emptyweight'], "Employee"=>$statement_report['editby'],
    "delivery"=>$statement_report['delivery'],"remark"=>$statement_report['remarks']];
}

//$output_final = (object)["products"=>$statement_out,"Cummulative"=>$mini_statement_out];
//$output = (object)["customer"=>$customer,"product"=>$product,"vehicle"=>$vehicle,"timefrom"=>$time_from,"timeto"=>$time_to,"datefrom"=>$date_from,"dateto"=>$date_to,"ticket"=>$ticket];
echo json_encode($statement_out);
?>
