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


include('../include/period_select_date.php');	 
 
$table_name = $_SESSION['db_prefix']."_purchase";	 	
$display_query = "SELECT purchase_id, purchase_date, supplier_id, purchase_order, value, authorised, authorised_by, company FROM $table_name WHERE purchase_date BETWEEN '".$start."' AND '".$end."' ";
	
	$display_result = execsql($display_query);
	$i = 0;
	$display_num = mysql_num_rows($display_result); 
		?> 

<!--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> 
<link rel="stylesheet" href="../window/dhtmlwindow.css" type="text/css" />
<link rel="stylesheet" href="../window/modal.css" type="text/css" />

<script type="text/javascript" src="../window/dhtmlwindow.js"></script>
<script type="text/javascript" src="../window/modal.js"></script>


</head>


<body>
<?php
include ("../navigation/header.php");
include ("../navigation/store_sidebar.php");
$page_name = "Stores-Status purchase";
include ("../navigation/access.php");
if ($permission_num==1) {
?>
<div class="main_frame">
<div class="page_head_frame">
  <label class="label_page_head">Void purchase orders</label></div>

<div class="page_middle_frame">

<?php
$page='void_purchase_order_list.php';
$reference_name='';
$reference='';
include('../include/period_select_block.php');
?>
<div class="page_inside_frame">
Click on status to change.
<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": [[0, "desc" ], [2, "desc" ]],
					"aoColumns": [
								{"iDataSort": 1},
								{"bVisible": false},
                              	{"iDataSort": 3},
								{"bVisible": false},
								{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}					
								 ]
				} );
			} );
		</script>    	
<table width="650" id="scroll_table" class="data_display" >
	<thead>
		<tr>
		  <th width="46">Date</th>
		  <th width="28">&nbsp;</th>
		  <th width="71">Purchase<br>
		    order</th>
		  <th width="23">&nbsp;</th>
		  <th width="99">Company</th>
		  <th width="105">Supplier</th>
          <th width="60" >Value</th>
		  <th width="80" >Status</th>
		  <th width="98" >Authorised by</th>
		  </tr>
	</thead>
	<tbody>
  <?php
    $b9=0;
	$b4tot='0.00';
	$b5tot='0.00';
	while($i < $display_num){
		 $b0 = mysql_result($display_result, $i, "purchase_id");
		 $b1 = mysql_result($display_result, $i, "purchase_date");
		 
				   
		 $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);
		 $suppliers_num = mysql_num_rows($suppliers_result);
		 if ($suppliers_num!=0) {
		  $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");
		 }
		  else {
		  $b2a = '';
		  $b2b = '';
		  $b2c = '';
		  $b2d = '';
		  $b2e = '';
		  $b2f = '';
		  }
		  
		
		$b3 = mysql_result($display_result, $i, "purchase_order");
		$b4 = mysql_result($display_result, $i, "value"); 
		$b5 = mysql_result($display_result, $i, "authorised"); 
		$b4tot = $b4tot+$b4;
		
		$b10 = mysql_result($display_result, $i, "company"); 
		
		$b7 = mysql_result($display_result, $i, "authorised_by"); 
		
		
		  	$table_name = $_SESSION['db_prefix']."_purchase_lines";
			$line_query = "SELECT store_item_id, item_name, quantity, price FROM $table_name WHERE purchase_id = '".$b0."' ";
			$line_result = mySQL_query($line_query);
			$line_num = mysql_num_rows($line_result);
			$line_text='';
			$j=0;
			while ($j<$line_num) {
			 $store_item_id  = mysql_result($line_result, $j, "store_item_id");	
			if ($store_item_id!=0) {	
			  
			   		$table_name6 = $_SESSION['db_prefix']."_store_items";
		 			$item_query = "SELECT item_name FROM $table_name6 WHERE store_item_id = '".$store_item_id."' " ;
					$item_result = execsql($item_query);
					$item_num = mysql_num_rows($item_result);
					if ($item_num !=0) {
		   			       $item_name = mysql_result($item_result, 0, "item_name");
					}
					else {
						$item_name='';
					}
			}
			else {
				$item_name  = mysql_result($line_result, $j, "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++;
			}
			   
		if ($b5=="yes") {$message=0;}	   	
		if ($b5=="no") {$message=0;}
		if ($b5=="void") {$message=6;}		
		//$b8 = mysql_result($displayResult, $i, "reference");
		
				
		 $itemTT =
		   "<b>Items on this purchase order:</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 ?></td>
		  <td align="center"><a href="purchase_order.php?purchase_id=<?php echo $b0?>&message=<?php echo $message ?>" onMouseOver="ddrivetip('<?php echo $itemTT ?>', 300)"; onMouseOut="hideddrivetip()"><?php echo $b3?></a></td>
		  <td align="center"><?php echo $b3?></td>
		  <td align="left"><?php echo $b10 ?></td>
		  <td align="left"><a href="supplier_details.php?supplier_id=<?php echo $b2 ?>" onMouseOver="ddrivetip('<?php echo $supplierTT ?>', 200)"; onMouseOut="hideddrivetip()"><?php echo $b2a?></a></td>
			<td align="right"><a href="supplier_details.php?supplier_id=<?php echo $b2 ?>" onMouseOver="ddrivetip('<?php echo $supplierTT ?>', 200)"; onMouseOut="hideddrivetip()"><?php echo number_format($b4, 2, '.', ',') ?></a></td>
			<td align="center">
            
            
           
            <a href="" onClick="editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/change_purchase_order_status.php?order_no=<?php echo $b3 ?>&status=<?php echo $b5 ?>&company=<?php echo $b2a ?>', 'Change status', 'width=500px,height=200px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false; MM_showHideLayers('wait','','show');"><?php echo $b5 ?></a>
			

</td>
			<td align="left"><?php echo $b7 ?></td>
	      </tr>
		     
		<?php
		$i++; 
	}
	?>
    </tbody>
    <tfoot>
    <tr >
		  <td >&nbsp;</td>
		  <td >&nbsp;</td>
		  <td align="left">&nbsp;</td>
		  <td align="left">&nbsp;</td>
		  <td align="right">&nbsp;</td>
		  <td align="right">Totals:</td>
		  <td align="right"><?php echo number_format($b4tot, 2, '.', ',') ?></td>
		  <td align="right">&nbsp;</td>
		  <td align="right">&nbsp;</td>
		  </tr>
        </tfoot>
	
</table>
		
</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'); ?>