<?php
include('../config/dbcon.php');
$output = '';

if (isset($_POST["query"])) {
	$search = mysqli_escape_string($connect, $_POST["query"]);
	$query = "SELECT supplier_code,supplier_name,supplier_place,order_number,order_date,sum(part_value) as part_value FROM order_mst where Lower(supplier_name) LIKE Lower('%" . $search . "%') or Lower(supplier_place) LIKE Lower('%" . $search . "%') group by order_number order by order_number";
} else {
	$query = "SELECT supplier_code,supplier_name,supplier_place,order_number,order_date,sum(part_value) as part_value FROM order_mst group by order_number order by order_number";
}
$result = mysqli_query($connect, $query);
if (mysqli_num_rows($result) > 0) {
	$output .= '
	<div class="table-responsive" style="width: 99%; height: 380px;">
		<table id="tblexportData" class="table table bordered" >
			<tr>
	            <th style = "width:200px; text-align: left">Show</th>
				<th style = "width:200px; text-align: left">supplier_code</th>
				<th style = "width:400px; text-align: left">supplier_name</th>
				<th style = "width:200px; text-align: left">supplier_place</th>
				<th style = "width:200px; text-align: left">order_number</th>
				<th style = "width:200px; text-align: left">order_date</th>
				<th style = "width:200px; text-align: right">part_value</th>
			</tr>';
			while($fetch = mysqli_fetch_array($result)) {
		    $output .= '
			<tr>
				<td><a class="float-right btn btn-primary btn-xs" style=" text-align: center" href="showparts? order_number=' . $fetch['order_number'] . '">Show Order</a></td>
			    <td style="text-align: left">' . $fetch["supplier_code"] . '</td>
			    <td style="text-align: left">' . $fetch["supplier_name"] . '</td>
			    <td style="text-align: left">' . $fetch["supplier_place"] . '</td>
			    <td style="text-align: left">' . $fetch["order_number"] . '</td>
			    <td style="text-align: left">' . $fetch["order_date"] . '</td>
			    <td style="text-align: right">' . $fetch["part_value"] . '</td>
			</tr>
		';
	}
	echo $output;
} else {
	echo 'Data Not Found';
}
