<?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 item_mst WHERE Lower(partno) LIKE Lower('%" . $search . "%') or Lower(description_one) LIKE Lower('%" . $search . "%') or Lower(description_two) LIKE Lower('%" . $search . "%') or Lower(hsn_code) LIKE Lower('%" . $search . "%') or Lower(segment) LIKE Lower('%" . $search . "%') ORDER BY partno Limit $noofrow";
} else {
	$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'];
	}
	$query = "SELECT * FROM item_mst ORDER BY partno LIMIT $noofrow";
}
$result = mysqli_query($connect, $query);
if (mysqli_num_rows($result) > 0) {
	$output .= '
	<div class="table-responsive" style="width: 170%; overflow:auto; height: 40%;">
		<table id="tblexportData" style="font-size:18px;" class="table table bordered" >
			<tr>
				<th style="text-align: left">Edit</th>
				<!--th style="text-align: left">Delete</th-->
				<th style = "text-align: left">Part_Number</th>
				<th style = "text-align: left">Description_One</th>
				<th style = "text-align: left">Description_Two</th>
				<th style = "text-align: left">Hsn_Code</th>
				<th style = "text-align: right">List</th>
				<th style = "text-align: right">Disc_Per</th>
				<th style = "text-align: right">Disc_Amt</th>
				<th style = "text-align: right">Cost</th>
				<th style = "text-align: right">Stk_Qty</th>
				<th style = "text-align: right">Moq</th>
				<th style = "text-align: right">Box_Qty</th>				
				<th style = "text-align: right">Mrp</th>
				<th style = "text-align: right">Sgst_Per</th>
				<th style = "text-align: right">Sgst_Amt</th>
				<th style = "text-align: right">Cgst_Per</th>
				<th style = "text-align: right">Cgst_Amt</th>
				<th style = "text-align: right">Igst_Per</th>
				<th style = "text-align: right">Igst_Amt</th>
				<th style = "text-align: right">Op_Stk</th>				
				<th style = "text-align: right">Stk_Val</th>
				<th style = "text-align: left">Unit</th>				
				<th style = "text-align: right">Ly_Sales</th>
				<th style = "text-align: right">Cy_Sales</th>
				<th style = "text-align: right">Pending</th>
				<th style = "text-align: right">Dispatch</th>
				<th style = "text-align: right">Min_Qty</th>
				<th style = "text-align: right">Max_Qty</th>
				<th style = "text-align: right">Reord_Qty</th>
				<th style = "text-align: left">Segment</th>
				<th style = "text-align: left">Remarks</th>
			</tr>';
	while ($row = mysqli_fetch_array($result)) {
		$output .= '
			<tr>
				<td style="text-align: center"><button type="button" style="width:60px; height:25px;" name="update" id="' . $row["id"] . '" class="update btn btn-success btn-xs">Edit</button></td>  
				<!--td style="text-align: center"><button type="button" style="width:60px;" name="delete" id="' . $row["id"] . '" class="delete btn btn-danger btn-xs">Delete</button></td-->
				<!--td style = "width:200px; text-align: left">' . $row["partno"] . '</td-->
				<td style = "width:200px; text-align: left">' . $row["partno"] . '</td>
				<td style = "width:600px; text-align: left">' . $row["description_one"] . '</td>
				<td style = "width:250px; text-align: left">' . $row["description_two"] . '</td>
				<td style = "width:60px; text-align: left">' . $row["hsn_code"] . '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["list"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["disc_per"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["disc_amt"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["cost"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["stk_qty"], 0, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["moq"], 0, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["boxqty"], 0, '.', ''). '</td>				
				<td style = "width:60px; text-align: right">' . number_format($row["mrp"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["sgst_per"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["sgst_amt"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["cgst_per"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["cgst_amt"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["igst_per"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["igst_amt"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["op_stk"], 0, '.', ''). '</td>				
				<td style = "width:60px; text-align: right">' . number_format($row["stk_val"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: left">' . $row["unit"] . '</td>				
				<td style = "width:60px; text-align: right">' . number_format($row["ly_sales"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["cy_sales"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["pending"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["dispatch1"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["min_qty"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["max_qty"], 2, '.', ''). '</td>
				<td style = "width:60px; text-align: right">' . number_format($row["reord_qty"], 2, '.', ''). '</td>
				<td style = "width:250px; text-align: left">' . $row["segment"] . '</td>
				<td style = "width:250px; text-align: left">' . $row["remarks"] . '</td>
			</tr>
		';
	}
	echo $output;
} else {
	echo 'Data Not Found';
}
