<?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,sum(total_inv_val) as total_inv_val, sum(rec_amount) as rec_amount,sum(balance_amount) as balance_amount,status FROM pinvtotal_mst where Lower(supplier_name) LIKE Lower('%" . $search . "%') or Lower(supplier_code) LIKE Lower('%" . $search . "%') and status = '" ."PENDING". "' group by supplier_name,supplier_code,supplier_place order by supplier_name";
} else {
	$query = "SELECT supplier_code,supplier_name,supplier_place,sum(total_inv_val) as total_inv_val, sum(rec_amount) as rec_amount,sum(balance_amount) as balance_amount,status FROM pinvtotal_mst where status = '" ."PENDING". "' group by supplier_name,supplier_code,supplier_place order by supplier_name";
}
$result = mysqli_query($connect, $query);
if (mysqli_num_rows($result) > 0) {
	$output .= '
	<div class="table-responsive" style="width: 100%; height: 380px;">
		<table id="tblexportData" class="table table bordered" >
			<tr>
	            <th style = "width:200px; text-align: left">Pay</th>
	            <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: right">total_inv_val</th>
				<th style = "width:200px; text-align: right">rec_amount</th>
				<th>balance_amount</th>
				<th>status</th>
			</tr>';
			while($fetch = mysqli_fetch_array($result)) {
		    $output .= '
			<tr>
				<td><a class="float-right btn btn-primary btn-xs" style=" text-align: center; width:60px; height:25px;" href="showos? supplier_code=' . $fetch['supplier_code'] . '">Pay</a></td>
				<td><a class="float-right btn btn-primary btn-xs" style=" text-align: center; width:60px; height:25px;" href="showosbill? supplier_code=' . $fetch['supplier_code'] . '">Show</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: right">' . $fetch["total_inv_val"] . '</td>
			    <td style="text-align: right">' . $fetch["rec_amount"] . '</td>
			    <td style="text-align: right">' . $fetch["balance_amount"] . '</td>
			    <td style="text-align: right">' . $fetch["status"] . '</td>
			</tr>
		';
	}
	echo $output;
} else {
	echo 'Data Not Found';
}
