<?php 
// Include the database config file 
include('../../includes/config.php');
require_once("../../includes/dbcontroller.php");
 $db_handle = new DBController();

if(!empty($_POST["sdeliverydate"])){ 
	$deliveries_query="SELECT TruckID FROM deliveries WHERE DATE(DeliveryDate) = '".$_POST['sdeliverydate']."' ORDER BY LastUpdated desc";
	$deliveries_data = $db_handle->runQuery($deliveries_query);
	$truck_fields='';
	if(!empty($deliveries_data)) {
		$deliveries_data = array_column($deliveries_data, 'TruckID');
		$truck_ids=implode(",",$deliveries_data);
		
		$get_relative_truck_query='select Truck_id,TruckName from trucks where Truck_id in ('.$truck_ids.')';
		$get_relative_truck_data = $db_handle->runQuery($get_relative_truck_query);
		$truck_fields=array_column($get_relative_truck_data, 'Truck_id', 'TruckName');
		?>
		<option value="">Please Select Truck</option>
		<?php foreach($truck_fields as $truck_fields_key=>$truck_fields_value) { ?>
		<option value="<?php echo $truck_fields_value; ?>"><?php echo $truck_fields_key; ?></option>
		<?php } 
	}
	else{ ?>
		<option value="">Please Select Truck</option>
	<?php }
}
?>