<?php 

	include("includes/config.php");

	include("includes/func.php");

	include("classes/safeSQL.class.php");

	$excel_icon = '';

	if (($_SESSION['id'] == ""))

	{

		redirect("login");

	}

	

	include("templates/header.php");

	

	$safeSQL 			= new safeSQL;

	$User_ID			= $_SESSION['id'];

	

	if(isset($_POST['stock']))

	{

			$start_date	=	$_POST['start_date'];

			$end_date	=	$_POST['end_date'];

			$Sql		=	"select `product_stockout`.*, `users`.`username` 

							 from `product_stockout` 

							 Inner Join `users` ON `product_stockout`.`userid` = `users`.`id`

							 where `sold_date` between '$start_date' and '$end_date' 

							 Order By `product_stockout`.`sold_date` DESC";

			$Exe_Quey	=	mysql_query($Sql);

			$Total_num	=	mysql_num_rows($Exe_Quey);

			$counter	=	0;

			if ($Total_num > 0)

			{   $counter++;

				$Todal_Billing	=	0;

				$bottles_sum = 0;

				while($row = mysql_fetch_array($Exe_Quey)){

					$UsersHTML .= "<tr class='even'>";

					

					$UsersHTML .= "<td>" . $row['sold_date']."</td>";

					$UsersHTML .= "<td>" . $row['35ml'] . "</td>";					

					$UsersHTML .= "<td>" . $row['55ml'] . "</td>";

					$UsersHTML .= "<td>" . $row['110ml'] . "</td>";

					$bottles_sum = $row['35ml'] + $row['55ml'] + $row['110ml'];

					$UsersHTML .= "<td>" . $row['username'] . "</td>";
					
					$UsersHTML .= "<td>" . $row['RollOn'] . "</td>";
					
					$row['product'] = round($row['product'], 2);

					
					$UsersHTML .= "<td>" . $row['product'] . "</td>";

					$Todal_Billing	=	$Todal_Billing + $row['product'];

					$UsersHTML .= "</tr>";

					

					$sum35ml	=	$row['35ml']+$sum35ml;

					$sum55ml	=	$row['55ml']+$sum55ml;

					$sum110ml	=	$sum110ml+$row['110ml'];

					

					

					

					

				}

				$avg35ml 	=	$sum35ml/$Total_num;
				$avg35ml 	=   intval($avg35ml);

				$avg55ml 	=	$sum55ml/$Total_num;
				$avg55ml    =   intval($avg55ml);

				$avg110		=	$sum110ml/$Total_num;
				$avg110		=   intval($avg110);

				

				$excel_icon =1;

			

			}else{

				

				$UsersHTML = "<tr align='center'><td colspan='5'>No Records found.</td></tr>";

				$TableSortHeader = '';

			}

					

	}



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/



?>

<!--------------------------->

<link rel="stylesheet" href="calender/development-bundle/themes/base/jquery.ui.all.css" />

<script src="calender/development-bundle/ui/jquery.ui.core.js"></script>

<script type="text/javascript" src="calender/development-bundle/ui/jquery.ui.widget.js"></script>

<link rel="stylesheet" href="calender/development-bundle/demos/demos.css">

<!--------------------------->



<script type="text/javascript" src="javascripts/jquery.maskedinput-1.3.js"></script>

<script type="text/javascript">

 $(document).ready(function(){

		$(".intcheck").keypress(function (e){

		  	var charCode = (e.which) ? e.which : e.keyCode;

		  	if (charCode > 31 && (charCode < 48 || charCode > 57)) {

				return false;

		  	}

		});

		

 });

 

function cancel_check()

{

	window.location.href = 'index.php';

}





$(function() {

		$('#start_date').datepicker({ dateFormat: 'yy-mm-dd' });

		$('#end_date').datepicker({ dateFormat: 'yy-mm-dd' });

});





function stockcheck(Currentstock)

{

	var quantity='order_quantity_'+Currentstock;

	var quantitysold = 'current_stock_'+Currentstock;

	var error = 'stock_error_'+Currentstock;

	var qtyele = document.getElementById(quantity);

	var qty = document.getElementById(quantity).value;



	var qtysold = document.getElementById(quantitysold).value;

	if(parseInt(qty) > parseInt(qtysold))

	{

		qtyele.value='0';

		qtyele.focus();

		document.getElementById(error).style.display='inline';

	}else{

		document.getElementById(error).style.display='none';

	}

}





</script>



<style type="text/css">

.excel{

	background:url(images/exportExcel.png) no-repeat;

	display:block;

	height:40px;

	width:37px;

}

</style>

<div id="mainPanel">

    

    

<h2><?php echo $Get_XML_Responce->readXmlArrtibut('xml_report.xml', 'Report');?></h2>



<?php if($excel_icon==1) {?>

<a href="exreport.php?start_date=<?php echo $start_date;?>&end_date=<?php echo $end_date;?>" class="excel" title="Export"></a>

<?php }?>

<form action="" method="POST" name="order_form" id="order_form">

  <input type="hidden" name="order_number" id="order_number_hid" value="" />

  

  <!--------------------------------------------------------------------------------------------------->

  <table width="100%" cellpadding="0" cellspacing="0" border="0" id="tabling1">

    <tr>

      <td nowrap width="13%" align="right" ><label><?php echo $Get_XML_Responce->readXmlArrtibut('xml_report.xml', 'Start_Date');?>:</label></td>

      <td nowrap><input type="text" name="start_date" id="start_date" value="<?php echo date('Y-m-d'); ?>" /></td>

      <td nowrap width="13%" align="right" ><label><?php echo $Get_XML_Responce->readXmlArrtibut('xml_report.xml', 'End_Date');?>:</label></td>

      <td nowrap><input type="text" name="end_date" id="end_date" value="<?php echo date('Y-m-d'); ?>" /></td>

      <td nowrap><input type="submit" class="form_button" value="<?php echo $Get_XML_Responce->readXmlArrtibut('xml_report.xml', 'Enter');?>" id="stock" name="stock"></td>

    </tr>

  </table>

</form>

<br />

<br />

<?php if($UsersHTML!= ''){?>

<table id="tabling1" width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr class="header">

    <td class="col1" width="17%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_report.xml', 'Date');?></span></td>

    <td class="col1" width="17%"><span class="blue">35ml</span></td>

    <td class="col1" width="17%"><span class="blue">55ml</span></td>

    <td class="col1" width="17%"><span class="blue">110ml</span></td>

    <td class="col1" width="17%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_report.xml', 'Sale_Person');?></span></td>
    
    <td class="col1" width="17%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_report.xml', 'Roll On');?></span></td>

    <td class="col1" width="17%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_report.xml', 'Billing');?></span></td>

  </tr>

  <?php echo $UsersHTML; ?>

  <tr class="header">

    <th class="col1" width="17%">Sum</th>

    <td class="col1" width="17%"><?php echo $sum35ml;?></td>

    <td class="col1" width="17%"><?php echo $sum55ml;?>&nbsp;</td>

    <td class="col1" width="17%"><?php echo $sum110ml;?></td>
    
    <td class="col1" width="17%">&nbsp;</td>

   

    <td class="col1" width="17%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_report.xml', 'Total_Billing');?></span></td>

    <td class="col1" width="20%"><?php echo $Todal_Billing; ?></td>

  </tr>

   <tr class="header">

    <th class="col1" width="17%">Average</th>

    <td class="col1" width="17%"><?php echo $avg35ml;?></td>

    <td class="col1" width="17%"><?php echo $avg55ml;?>&nbsp;</td>

    <td class="col1" width="17%"><?php echo $avg110;?></td>

   

    <td class="col1" width="17%"><span class="blue"></span></td>
    
    <td class="col1" width="17%"><span class="blue"></span></td>

    <td class="col1" width="20%"><?php echo intval($Todal_Billing/$Total_num); ?></td>

  </tr>

  

</table>

<?php } ?>



</body>

</html>

