<?php

session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");
include("function.inc.php");
include("Functions_Trans.php");
set_time_limit(0);

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

if($closeWin == '') $closeWin = 0;

print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<title>Items / Price</title>
<script type="text/javascript" language="javascript">

function SubmitInfo(txtPurId){
	var x =document.purinfo;
	var mainmode = 'updateitemprice';
	
	x.action = "Form_Purchase_Actions.php?mainmode="+mainmode+"&mode=&SPurId="+txtPurId;
	x.submit();
}
function calPrice(itemcode){
	var txtpurnewprice	= 'price'+itemcode;
	var txtpurnewcost	= 'cost'+itemcode;
	var txtpurnewfreight = 'freight'+itemcode;
	var cost = document.getElementById(txtpurnewcost).value;
	var freight = document.getElementById(txtpurnewfreight).value;
	if(cost == '') cost = 0;
	if(freight == '') freight = 0;
	 document.getElementById(txtpurnewprice).value = parseFloat(freight) + parseFloat(cost);
	
}
function CloseForm(){
	opener.document.purchase.submit();
	self.close();
}
</script>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}

.style28 {color: #000000 ;font-size: 12px;}
.titlestyle{
    color: #fff;
    font-size: 13px;
    font-weight: bold;
}
</style>

</head>
<body>
<form name='purinfo' method='post' action=''>


HERE;


	  echo"<table cellpadding='0' cellspacing='0' border='0'  align='left' style='table-layout:fixed'  width='860px'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px;' align='center' valign='middle'>
			<table border='0' width='650px'>
			<tr><td align='left' > <span class='titlestyle'> Items / Price </span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";
		 
echo"<table border='0' cellspacing='1' style='table-layout:fixed'>
	  <col width=150>
	  <col width=360> <col width=100> <col width=100>
	  <col width=110>";
	  
//buttons
echo "<tr height='30' bgcolor='#F7F7F7'>";
echo "<td><button type='button' id='btnsubInfo' name='btnsubInfo' onclick='SubmitInfo($PPurId);return false;' title='Submit Info'><span><span>Submit</span></span></button> ";
echo "<button type='button' id='btnclose' name='btnclose' onclick='CloseForm();return false;' title='Close'><span><span>Close</span></span></button></td>";
echo "<td colspan='2'></td></tr>";
	  
	  
$query = "select distinct temp_purchasesdt.item_code, item_description
		from temp_purchasesdt
		inner join items on items.item_code = temp_purchasesdt.item_code
		where purchase_id=$PPurId
		order by temp_purchasesdt.item_code"; //echo $query;
$res = mysql_query($query,$connection);


echo "<tr height='50' bgcolor='#F7F7F7'><td><span class='style1'>Item Code</span></td><td><span class='style1'>Description</span></td>
	<td><span class='style1'>Cost</span></td><td><span class='style1'>Freight</span></td><td><span class='style1'>Price</span></td>";
echo "</tr>";
$i=0;
while($rows = mysql_fetch_row($res)){

$txtpurnewprice	= 'price'.$i;
$txtpurnewcost	= 'cost'.$i;
$txtpurnewfreight	= 'freight'.$i;

echo "<tr height='30' bgcolor='#F7F7F7'><td><span class='style28'>$rows[0]</span></td>";
echo "<td><span class='style28'>$rows[1]</span></td>";
echo "<td><input type='text' name='$txtpurnewcost' id='$txtpurnewcost' value='".$$txtpurnewcost."' style='width:120px;' onkeypress='return (event.charCode >= 48 && event.charCode <= 57) || (event.charCode== 46) || (event.charCode >= 0 && event.charCode <= 31)' onkeyup=\"calPrice('$i');\"></td>";
echo "<td><input type='text' name='$txtpurnewfreight' id='$txtpurnewfreight' value='".$$txtpurnewfreight."' style='width:120px;' onkeypress='return (event.charCode >= 48 && event.charCode <= 57) || (event.charCode== 46) || (event.charCode >= 0 && event.charCode <= 31)' onkeyup=\"calPrice('$i');\" ></td>";
echo "<td><input type='text' name='$txtpurnewprice' id='$txtpurnewprice' value='".$$txtpurnewfreight."' style='width:120px;' onkeypress='return (event.charCode >= 48 && event.charCode <= 57) || (event.charCode== 46) || (event.charCode >= 0 && event.charCode <= 31)' ></td></tr>";	
$i++;
}




	
echo"</table></div></td><td id='search-content3' style='width:31px;'>&nbsp;</td></tr>";		


	
echo"	<tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:920px;' valign='top'><table width='100%' border=0 height=28px>
		<tr><td style='width:280px;'>&nbsp;</td><td align='right' style='width:74px;'>";
		
	
		
		echo"</td><td width='150' align='left'>";
		
		
		echo"</td><td width='170'>&nbsp;</td></tr>";
		echo"</table></td><td id='search-bottom3' style='height:34px; width:31px;'>&nbsp;</td>";

echo"</td></tr></table>";
	

if($closeWin == 1){
	echo "<script>CloseForm();</script>";
}
          

		  

print <<<HERE

</form>
</body>

HERE;

?>