<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']."_supply_store";	 	
	$display_query = "SELECT supply_id, supply_date, supplier_id, order_no FROM $table_name WHERE supply_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";
		  }
 
		?> 


<script type="text/javascript" src="../jscript/tablesort.js"></script>
    	
</head>

<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<body>
<?php include ('../include/tooltip.php'); ?>

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


      <form action="stock_stock_supplied.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="scroll_frame_long">
<table width="662" id="table_list" class="sortable-onload-0r rowstyle-alt no-arrow "  >
	<thead>
		<tr>
		  <th width="112" class="sortable-date-dmy">Date</th>
		  <th width="120" class="sortable-text">Job no</th>
          <!--			<th class="sortable-text">Product Name</th>-->
			<th width="174" >&nbsp;</th>
			<th width="109" >&nbsp;</th>
		    <th width="123" >&nbsp;</th>
		</tr>
	</thead>
	<tbody>
  <?php
    $b9=0;
	while($i < $display_num){
		 $b0 = mysql_result($display_result, $i, "supply_id");
		 $b1 = mysql_result($display_result, $i, "supply_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, "supplier_id"); 
//		 $table_name3 = $_SESSION['db_prefix']."_suppliers";
//		 $suppliers_query = "SELECT account_name, post_address, post_place, phone, contact1, cell1 FROM $table_name3 WHERE supplier_id = $b2 " ;
//		 $suppliers_result = execsql($suppliers_query);
//		  $b2a = mysql_result($suppliers_result, 0, "account_name");
//		  $b2b = mysql_result($suppliers_result, 0, "post_address");
//		  $b2c = mysql_result($suppliers_result, 0, "post_place");
//		  $b2d = mysql_result($suppliers_result, 0, "phone");
//		  $b2e = mysql_result($suppliers_result, 0, "contact1");
//		  $b2f = mysql_result($suppliers_result, 0, "cell1");
		  
		
		$b3 = mysql_result($display_result, $i, "order_no");
		
		  	$table_name = $_SESSION['db_prefix']."_supply_store_lines";
			$line_query = "SELECT store_item_id, quantity, price FROM $table_name WHERE supply_id = '".$b0."' ";
			$line_result = mySQL_query($line_query);
			$line_num = mysql_num_rows($line_result);
			$line_text='';
			$j=0;
			while ($j<$line_num) {
			   $line_store_item_id  = mysql_result($line_result, $j, "store_item_id");
			   		$table_name6 = $_SESSION['db_prefix']."_store_items";
		 			$item_query = "SELECT item_name FROM $table_name6 WHERE store_item_id = '".$line_store_item_id."' " ;
		 			$item_result = execsql($item_query);
		   			$item_name = mysql_result($item_result, 0, "item_name");
					
			   $line_quantity  = mysql_result($line_result, $j, "quantity");
			   $line_price  = mysql_result($line_result, $j, "price");
			   $line_text = $line_text.'<tr><td>'.$item_name."</td><td>".$line_quantity."</td><td>".$line_price."</td></tr>";
			   $j++;
			}
			   
			   	
		
		//$b8 = mysql_result($displayResult, $i, "reference");
		
				
		 $itemTT =
		   "<b>Items on this supply:</b><br><table id=table_tool_tip width=300 border=1 ><tr><td>Item</td><td>Quantity</td><td>Price</td></tr>".$line_text."</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>".$b2a."</td></tr><tr><td>Date received:</td><td>".date("d-m-Y", strtotime($b0))."</td></tr></table><br><b>Click for details</b>";
//		   
		//$supplierTT =
//		   "<table id=table_tool_tip width=250 ><tr><td  width=75>Name:</td><td width=175>".$b2a."</td></tr><tr><td>Address:</td><td>".$b2b."</td></tr><tr><td></td><td>".$b2c."</td></tr><tr><td>Contact:</td><td>".$b2e."</td></tr><tr><td>Phone:</td><td>".$b2d."</td></tr><tr><td>Cell:</td><td>".$b2f."</td></tr></table><br><b>Click for details</b>";   
		
		?>
		<tr >
		  <td ><?php echo date("d-m-Y", strtotime($b1 ))?></td>
		  <td align="left"><a href="order_supplied.php?supply_id=<?php echo $b0?> " onMouseOver="ddrivetip('<?php echo $itemTT ?>', 300)"; onMouseOut="hideddrivetip()"><?php echo "J".$b3?></a></td>
			<td align="left"></td>
			<td align="right">&nbsp;</td>
		    <td align="right">&nbsp;</td>
		</tr>
        
		<?php
		$i++;
		  
	}
	
	?>
	</tbody>
	<tfoot>
      </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'); ?>