<?php
include('../config/dbcon.php');
$output = '';
if(isset($_POST["query"]))
{
	$query = "SELECT noofrow FROM noofrow_mst WHERE description='noofrow'";
	$rs = mysqli_query($connect, $query) or die("Cannot execute query: $query\n");
	while ($row = mysqli_fetch_assoc($rs)) {
		$noofrow     = $row['noofrow'];
	}
	$search = mysqli_escape_string($connect, $_POST["query"]);
	$query = "SELECT * FROM pinvtotal_mst WHERE Lower(supplier_name) LIKE Lower('%".$search."%') or Lower(supplier_place) LIKE Lower('%".$search."%') or inv_number LIKE Lower('%".$search."%') and inv_type ='" . "INVOICE" . "' Limit $noofrow";}
else
{
	$query = "SELECT noofrow FROM noofrow_mst WHERE description='noofrow'"; //UNIX_TIMESTAMP
	$rs = mysqli_query($connect, $query) or die("Cannot execute query: $query\n");
	while ($row = mysqli_fetch_assoc($rs)) {
		$noofrow     = $row['noofrow'];
	}
	$query = "SELECT * FROM pinvtotal_mst WHERE inv_type ='" . "INVOICE" . "' ORDER BY inv_number LIMIT $noofrow";
}
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
	$output .= '
	<div class="table-responsive" style="width: 130%;">
		<table id="tblexportData" class="table table bordered" >
			<tr>
				<th width="50px" style=" text-align: center">Print</th>
				<th style = "width:100px; text-align: left">inv_number</th>
				<th style = "width:200px; text-align: left">inv_date</th>
				<th style = "width:100px; 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:100px; text-align: right">total_qty</th>
				<th style = "width:100px; text-align: right">total_list_value</th>
				<th style = "width:100px; text-align: right">total_disc_amt</th>
				<th style = "width:100px; text-align: right">total_sales_val</th>
				<th style = "width:100px; text-align: right">total_sgstamt</th>
				<th style = "width:100px; text-align: right">total_cgstamt</th>
				<th style = "width:100px; text-align: right">total_igstamt</th>
				<th style = "width:100px; text-align: right">total_val</th>
				<th style = "width:100px; text-align: right">roundoff</th>
				<th style = "width:100px; text-align: right">total_inv_val</th>
				<th style = "width:100px; text-align: left">tax_code</th>
				<th style = "width:100px; text-align: left">grn_number</th>
			</tr>';
	while($row = mysqli_fetch_array($result))
	{
		$output .= '
			<td><a class="float-right btn btn-primary btn-xs" style=" text-align: center" href="invreprint? inv_number=' . $row['inv_number'] . '& grn_number=' . $row['grn_number'] . '" " target="_blank">Print</a></td>
				<td style="text-align: left">' . $row["inv_number"] . '</td>
				<td style="text-align: left">' . $row["inv_date"] . '</td>
				<td style="text-align: left">' . $row["supplier_code"] . '</td>
				<td style="text-align: left">' . $row["supplier_name"] . '</td>
				<td style="text-align: left">' . $row["supplier_place"] . '</td>
				<td style="text-align: right">' . $row["total_qty"] . '</td>
				<td style="text-align: right">' . $row["total_list_value"] . '</td>
				<td style="text-align: right">' . $row["total_disc_amt"] . '</td>
				<td style="text-align: right">' . $row["total_sales_val"] . '</td>
				<td style="text-align: right">' . $row["total_sgstamt"] . '</td>
				<td style="text-align: right">' . $row["total_cgstamt"] . '</td>
				<td style="text-align: right">' . $row["total_igstamt"] . '</td>
				<td style="text-align: right">' . $row["total_val"] . '</td>
				<td style="text-align: right">' . $row["roundoff"] . '</td>
				<td style="text-align: right">' . $row["total_inv_val"] . '</td>
				<td style="text-align: left">' . $row["tax_code"] . '</td>
				<td style="text-align: left">' . $row["grn_number"] . '</td>
			</tr>
		';
	}
	echo $output;
}
else
{
	echo 'Data Not Found';
}
?>
