<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<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']."_receive_store";	 	
$display_query = "SELECT receive_id, receive_date, supplier_id, delivery_note, value, transport FROM $table_name WHERE receive_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/scroll_table.css" />
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" /> 

<!--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}
								
								 ]
				} );
			} );
		</script>    	

</head>


<body>

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

<div class="page_middle_frame">
      <form action="stock_received.php" method="get" name="dateform" class="today" id="dateform">
        <table width="662" border="0" align="left" cellpadding="0" cellspacing="0" id="table_calendar">
          <tr>
            <td width="40"><label class="label_std">from:</label> </td>
            <td width="238"><?php
		$myCalendar = new tc_calendar("date1", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($ds, $ms, $ys);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2014, 2090);
	 	$myCalendar->writeScript();?></td>
            <td width="32"><label class="label_std">to:</label></td>
            <td width="258"><?php
		$myCalendar = new tc_calendar("date2", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($de, $me, $ye);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2014, 2090);
		$myCalendar->writeScript();?>
            <input name="date" type="hidden" id="date" value="1" />
            <input name="cat" type="hidden" id="cat" value="" /></td>
            <td width="94"><label>
              <input name="button5" type="submit" class="linkbutton"  id="button5" value="Select" />
            </label></td>
          </tr>
        </table>
        &nbsp;&nbsp;&nbsp;&nbsp;
      </form>
</div>
    
<br />
<div class="page_middle_frame">
<table width="662" id="scroll_table" class="data_display" >
	<thead>
		<tr>
		  <th width="112">Date</th>
		  <th width="112">&nbsp;</th>
		  <th width="120">Del_note </th>
          <th width="174" >Supplier</th>
		  <th width="109" >Value</th>
		  <th width="123" >Transport</th>
		</tr>
	</thead>
	<tbody>
  <?php
    $b9=0;
	$b4tot='0.00';
	$b5tot='0.00';
	while($i < $display_num){
		 $b0 = mysql_result($display_result, $i, "receive_id");
		 $b1 = mysql_result($display_result, $i, "receive_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, "delivery_note");
		$b4 = mysql_result($display_result, $i, "value"); 
		$b5 = mysql_result($display_result, $i, "transport"); 
		$b4tot = $b4tot+$b4;
		$b5tot = $b5tot+$b5;
		
		  	$table_name = $_SESSION['db_prefix']."_receive_store_lines";
			$line_query = "SELECT store_item_id, quantity, price FROM $table_name WHERE receive_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 of this receival:</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>";
		
	   
		$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 ><?php echo $b1 ?>&nbsp;</td>
		  <td align="left"><a href="receive_note.php?receive_id=<?php echo $b0?> " onMouseOver="ddrivetip('<?php echo $itemTT ?>', 300)"; onMouseOut="hideddrivetip()"><?php echo $b3?></a></td>
			<td align="left"><a href="receive_note.php?receive_id=<?php echo $b0?> " onMouseOver="ddrivetip('<?php echo $itemTT ?>', 300)"; onMouseOut="hideddrivetip()"> </a><a href="displaySupplier.php?supplier_id=<?php echo $b2 ?>" onMouseOver="ddrivetip('<?php echo $supplierTT ?>', 200)"; onMouseOut="hideddrivetip()"><?php echo $b2a?></a></td>
			<td align="right"><?php echo number_format($b4, 2, '.', ',') ?>&nbsp;</td>
		    <td align="right"><?php echo number_format($b5, 2, '.', ',') ?></td>
		</tr>
		     
		<?php
		$i++; 
	}
	?>
    <tfoot>
    <tr >
		  <td >&nbsp;</td>
		  <td >&nbsp;</td>
		  <td align="left">&nbsp;</td>
		  <td align="right">Totals:</td>
		  <td align="right"><?php echo number_format($b4tot, 2, '.', ',') ?></td>
		  <td align="right"><?php echo number_format($b5tot, 2, '.', ',') ?></td>
	    </tr>
        </tfoot>
	</tbody>
	  <td>          
	
</table>
		
	
</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'); ?>