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

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
?>
<script type="text/javascript">
function delete_check(id)
{
	if(confirm('Are you really want to delete!'))
	window.location.href = 'sales_listing.php?delete='+id;
	else
	return false;
}

</script>
    <div id="mainPanel">
<h2>Order Managment</h2>
<a href="order_parchase.php" class="form_button">Add New Order</a> 
<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" style="width:15%;"><span class="blue">Order No.</span></th>
            <td class="col1" style="width:15%;"><span class="blue">Order Date</span></th>
            <td class="col1" style="width:15%;"><span class="blue">Order Reciept Date</span></th>
            <td class="col1" style="width:15%;"><span class="blue">Status</span></th>
            <td class="col1" style="width:10%;"><span class="blue">Product Count</span></th>
            <td class="col1" style="width:35%;"><span class="blue">Action</span></th>
        </tr>
        <tr colspan="5" id="empty_record"  style="display:none;"><td colspan="5"><span style="color:red;">No Order Found!</span></td></tr>
    </thead>
<tbody>
<?php
$sql = "Select purchaseorder.OrderNo,purchaseorder.orderdate, purchaseorder.orderreceiptdate, orderstatus.STATUS,(select count(*) from purchaseorderdetails where purchaseorderdetails.orderid = purchaseorder.id) as Productcount
FROM  `purchaseorder`
INNER JOIN orderstatus ON purchaseorder.orderstatusid = orderstatus.ID
";
$results = mysql_query($sql);
if($count = mysql_num_rows($results) != 0)
{
	while($rows = mysql_fetch_array($results))
	{
		echo '<tr>';
		echo '<td class="col1">'.$count.'</td>';
		echo '<td class="col1">'.$rows['OrderNo'].'</td>';
		echo '<td class="col1">'.$rows['orderdate'].'</td>';
		echo '<td class="col1">'.$rows['orderreceiptdate'].'</td>';
		echo '<td class="col1">'.$rows['STATUS'].'</td>';
		echo '<td class="col1">'.$rows['Productcount'].'</td>';
		echo '<td class="col1"><a class="form_button" href="order_parchase.php?edit='.$rows['id'].'">Adjust</a><a class="form_button" href="order_parchase.php?edit='.$rows['id'].'"> Confirm</a><a class="form_button" href="#" onclick="delete_check('.$rows['id'].')">Delete</a></td>';
		echo '</tr>';
	}
}
else{
	echo "<script type='text/javascript'> document.getElementById('empty_record').style.display = ''; </script>";
}

?>
</tbody>
</table>
</body>
</html>