<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php 
include ("../navigation/header.php");

$page_name = "Stores-main";
include ("../navigation/access.php");

if ($permission_num==1) {

	 include ("../navigation/store_sidebar.php");
     include ("../include/date_set.php"); 
	

	$table_name = $_SESSION['db_prefix']."_store_deliver";	 	
	$display_query = "SELECT * FROM $table_name WHERE date BETWEEN '".$start."' AND '".$end."' ";
	
		$display_result = execsql($display_query);
		$i = 0;
		$display_num = mysql_num_rows($display_result);
		
		if ($display_num==0) {
		  $message="No records to show"; 
		   }
		else  {
		  $message="End of list";
		  }
 
		?> 
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />
<!--reference to main.css removed-->

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script>
<script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table').dataTable( {
					"sScrollY": "500px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 1, "desc" ]],
					"aoColumns": [
								{"iDataSort": 1},
								{"bVisible": false},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}
								 ]
				} );
			} );
		</script>      	
</head>

<body>

<div class="main_frame">
<div class="page_head_frame">
  <label class="label_page_head">Stock supplied</label></div>
   
<br />
<br /><br />
<br />


      <form action="stock_delivered.php" method="get" name="dateform" class="today" id="dateform">
        <table width="705" border="0" align="left" cellpadding="0" cellspacing="0" id="table_calendar">
          <tr>
            <td width="41"><label class="label_std">from:</label> </td>
            <td width="239"><?php
		$myCalendar = new tc_calendar("date1", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($ds, $ms, $ys);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2000, 2030);
	 	$myCalendar->writeScript();?></td>
            <td width="42"><label class="label_std">to:</label></td>
            <td width="291"><?php
		$myCalendar = new tc_calendar("date2", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($de, $me, $ye);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2000, 2030);
		$myCalendar->writeScript();?>
            <input name="date" type="hidden" id="date" value="1" />
            <input name="cat" type="hidden" id="cat" value="" /></td>
            <td width="90"><label>
              <input name="button5" type="submit" class="linkbutton"  id="button5" value="Select" />
            </label></td>
          </tr>
        </table>
        &nbsp;&nbsp;&nbsp;&nbsp;
      </form>
    
<br />
<div class="page_middle_frame">
<table width="662" id="scroll_table" class="data_display"  >
	<thead>
		<tr>
		  <th width="63">Date</th>
		  <th width="34">&nbsp;</th>
		  <th width="160">Item</th>
			<th width="70">Sub store</th>
            <th width="110">Delivered to</th>
          	<th width="55" >Qty</th>
			<th width="62" >Unit Price</th>
		    <th width="72" >Total </th>
		</tr>
	</thead>
	<tbody>
  <?php
    $b9=0;
	while($i < $display_num){
		 $b = mysql_result($display_result, $i, "deliver_id");
		 $b0 = mysql_result($display_result, $i, "date");
		 
		 $table_name2 = $_SESSION['db_prefix']."_store_items";
		 $b1 = mysql_result($display_result, $i, "store_item_id");
		 $table_name2 = $_SESSION['db_prefix']."_store_items";
		 $item_query = "SELECT item_name FROM $table_name2 WHERE store_item_id = '".$b1."' " ;
		 $item_result = execsql($item_query);
		   $b1a = mysql_result($item_result, 0, "item_name");
		 	  
		$b2 = mysql_result($display_result, $i, "delivered_department");
		if ($b2=="") { 
		       $b2 = mysql_result($display_result, $i, "delivered_employee");
		}
		$b3 = mysql_result($display_result, $i, "quantity");
		$b4 = mysql_result($display_result, $i, "price");
		$b5 = mysql_result($display_result, $i, "sub_cat");
		
		//$b8 = mysql_result($displayResult, $i, "reference");
		
		$b7=$b3*$b4;
		$b9 += $b7;
		
		 $itemTT =
		   "<table id=table_tool_tip width=250 ><tr><td  width=75>Item name:</td><td width=175>".$b1a."</td></tr><tr><td>Supplier:</td><td>".$b2."</td></tr></table><br><b>Click for details</b>";
		
		$receiveTT =
		   "<table id=table_tool_tip width=250 ><tr><td  width=75>Item name:</td><td width=175>".$b1a."</td></tr><tr><td>Supplier:</td><td>".$b2."</td></tr><tr><td>Date received:</td><td>".date("d-m-Y", strtotime($b0))."</td></tr></table><br><b>Click for details</b>";
		   
				
		?>
		<tr >
		  <td ><a href="item_received.php?receive_id=<?php echo $b ?> " onMouseover="ddrivetip('<?php echo $receiveTT ?>', 150)"; onMouseout="hideddrivetip()"><?php echo date("d-m-Y", strtotime($b0 ))?>  </a></td>
		  <td ><?php echo $b0 ?>&nbsp;</td>
		  <td ><a href="store_item_display.php?store_item_id=<?php echo $b1 ?> " onMouseover="ddrivetip('<?php echo $itemTT ?>', 260)"; onMouseout="hideddrivetip()">&nbsp;&nbsp;</a><a href="store_item_display.php?store_item_id=<?php echo $b1 ?> " onMouseOver="ddrivetip('<?php echo $itemTT ?>', 260)"; onMouseOut="hideddrivetip()"><?php echo $b1a ?></a></td>
			<td ><?php echo $b5?></td>
			<td align="left"><?php echo $b2?></td>
			<td align="right"><?php echo $b3?></td>
			<td align="right"><?php echo $b4?></td>
		    <td align="right"><?php $b7=$b3*$b4;  echo number_format($b7, 2, '.', ',')?> </td>
		</tr>
        
		<?php
		$i++;
		  
	}
	
	?>
	</tbody>
	<tfoot>
	    <tr >
          <td colspan="7"><div align="right">total:&nbsp;&nbsp;&nbsp;</div></td>
          <td><div align="right"><?php echo number_format($b9, 2, '.', ',')?></div></td>
        </tr> 
  </tfoot>
</table>
		
	<div align="left">
      <label class="label_end">
        <?php  echo $message ?>
      </label>
    </div>
</div>    
</div>
</body>
<?php } else { 
    $_SESSION['denied_return'] = "store/store_main.php";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>