<?php 
	include("includes/config.php");
	include("includes/func.php");
	
	if (($_SESSION['id'] == ""))
	{
		redirect("login");
	}
	
	include("templates/header.php");

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
?>
    <div id="mainPanel">
<h2>Sales Managment </h2>
<a href="sales_add_edit.php" class="form_button">Add New Sales</a>
<div style="margin-bottom:5px;"></div>
<div style="margin-bottom:20px"></div>
<table width="100%" id="tabling" cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <td class="col1" style="width:5%;"><span class="blue">Sr#</span></th>
            <td class="col1" width="15%"><span class="blue">Category</span></th>
            <td class="col1" width="55%"><span class="blue">Product Name</span></th>
             <td class="col1" width="150%"><span class="blue">Current Stock</span></th>
            <td class="col1" width="150%"><span class="blue">Threshold value</span></th>
            <td class="col1" width="55%"><span class="blue">Quantity Sold</span></th>
            <td class="col1" width="55%"><span class="blue">Edit | Delete</span></th>
        </tr>
        <tr colspan="5" id="empty_record"  style="display:none;"><td colspan="5"><span style="color:red;">No Sale Found!</span></td></tr>
    </thead>
<tbody>
<?php
$count = 0;
$sql = "Select sales.quantitysold, product.producttitle, product.alertcount, category.desc,product.currentstocklevel
From `sales`
Inner Join `product` ON `sales`.productid = `product`.id
Inner Join `category` ON `product`.catid = `category`.id;
";
$results = mysql_query($sql);
if($row = mysql_num_rows($results) != 0)
{
	while($rows = mysql_fetch_array($results))
	{
		$count++;
		echo '<tr>';
		echo '<td class="col1">'.$count.'</td>';
		echo '<td class="col1">'.$rows['desc'].'</td>';
		echo '<td class="col1">'.$rows['producttitle'].'</td>';
		echo '<td class="col1">'.$rows['currentstocklevel'].'</td>';
		echo '<td class="col1">'.$rows['alertcount'].'</td>';
		echo '<td class="col1">'.$rows['quantitysold'].'</td>';
		echo '<td class="col1"><a href="sales_add_edit.php?edit='.$rows['id'].'" class="form_button">Edit</a> <a href="#" onclick="delete_check('.$rows['id'].')" class="form_button">Delete</a></td>';
		echo '</tr>';
	}
}
else{
	echo "<script type='text/javascript'> document.getElementById('empty_record').style.display = ''; </script>";
}
?>
</tbody>
</table>
</body>
</html>