<?php 
include("../config.php");
$query = mysqli_query($conn, "SELECT * FROM `tracking` WHERE lr_no = '".$_GET['lr_no']."' ORDER BY t_date,follow_up_time ASC");
$detail = array();
while ($rows = mysqli_fetch_assoc($query)) {
	$detail[] = $rows;
}
$table = '';
$master_vendor  = combine(getAllRecords('vendor_master'), 'id', 'name');

$lr_table = mysqli_query($conn, "SELECT * FROM `lr_mst` WHERE `lr_no` = '".$_GET['lr_no']."'");
$lr_table_row = mysqli_fetch_assoc($lr_table);


$table .= '
<tr>
	<td class="text-center">'.$lr_table_row["lr_no"].'</td>
	<td class="text-center">'.risFormatDate($lr_table_row["l_date"],'d-m-Y').'</td>
	<td class="text-center">'.$lr_table_row["truck_no"].'</td>
	<td class="text-left">'.@$master_vendor[$lr_table_row["consignor_name"]].'</td>
	<td class="text-left">'.@$master_vendor[$lr_table_row["consignee_name"]].'</td>
	<td class="text-center"></td>
	<td class="text-center">'.$lr_table_row["from_place"].'</td>
	<td class="text-center">'.$lr_table_row["to_place"].'</td>
	<td class="text-center">'.$lr_table_row["from_place"].'</td>
	<td class="text-center">BOOKING</td>
</tr>
';
if(count($detail) > 0){
	foreach ($detail as $key => $detail_data) {
		$lr = mysqli_query($conn, "SELECT * FROM `lr_mst` WHERE `lr_no` = '".$detail_data["lr_no"]."'");
		$lr_row = mysqli_fetch_assoc($lr);

		if($detail_data['tracking_status'] == 'P'){
			$label = 'ON THE WAY';
		}else{
			$label = 'REACHED';
		}

		$table .= '
		<tr>
			<td class="text-center">'.$detail_data["lr_no"].'</td>
			<td class="text-center">'.risFormatDate($lr_row["t_date"],'d-m-Y').'</td>
			<td class="text-center">'.$lr_row["truck_no"].'</td>
			<td class="text-left">'.@$master_vendor[$lr_row["consignor_name"]].'</td>
			<td class="text-left">'.@$master_vendor[$lr_row["consignee_name"]].'</td>
			<td class="text-center">'.$detail_data["follow_up_time"].'</td>
			<td class="text-center">'.$lr_row["from_place"].'</td>
			<td class="text-center">'.$lr_row["to_place"].'</td>
			<td class="text-center">'.$detail_data["location"].'</td>
			<td class="text-center">'.$label.'</td>
		</tr>
		';
	}
}else{
	$table .= '<tr>
		<td colspan="10" class="text-center">NO DATA FOUND...!!!</td>
	</tr>
	';
}
$data = array('status' => 'success', 'total_count' => $total, 'tbody' => $table);
	echo json_encode($data);
    die();
?>