<?php
$PageSecurity = 2;
include('includes/session.inc');
$title = _('View/Search Items') ;
include('includes/SQL_CommonFunctions.inc');
$table=explode('_',$_REQUEST['party']);
if($table[1]=='clientmaster')
{
$sql="Select assigned_items from clientmaster where id='".$table[0]."'";
}
else {
	$sql="Select assigned_items from suppliers where vendor_code='".$table[0]."'";
}
$result=DB_query($sql,$db);
$myrow=DB_fetch_array($result);

$assignedArray=explode(",",$myrow['assigned_items']);

?>
<table width="70%" cellpadding="1" cellspacing="1" align="center">
	<tr>
		<th>Item</th>
		<!--<?php if($table[1]!='clientmaster'){ ?>
		<th>Unit</th><?php } ?>	-->
			
		<th>Rate</th>
</tr>
<?php 
for($i=0;$i<count($assignedArray);$i++)
{
	$item_sql="Select id,StockID,item_name from item_master where id='".$assignedArray[$i]."'";
	$item_result=DB_query($item_sql,$db);
	$item_row=DB_fetch_array($item_result);
	
	$rateSql=DB_query("Select Rate from rate_master where ItemId='".$item_row['id']."' and PartyId='".$_REQUEST['party']."' and DeActivate='0'",$db);
	if(DB_num_rows($rateSql)>0)
	{
		$rateRow=DB_fetch_array($rateSql);
		$_REQUEST['Rate']=$rateRow['Rate'];
	}
	
?>

	<tr bgcolor="#FFFFFF">
		<td><?php echo $item_row['StockID']." - ".$item_row['item_name']?><input type="hidden" name="ItemId[<?php echo $i;?>]" value="<?php echo $item_row['id'];?>" /></td>
	<!--	<?php if($table[1]!='clientmaster')
		{?>
		<td><select name="uom[]" style="width: 100px;">
			<option value="0">Select</option>
			<?php $sql=DB_query("select * from unitsofmeasure",$db);
			while($row=DB_fetch_array($sql))
			{
				?>
			<option value="<?php echo $row['unitid']; ?>"><?php echo $row['unitname']; ?></option>	
			<?php } ?>
			</select>
			
		</td><?php } ?>-->
		<td><input type="text" name="Rate[<?php echo $i;?>]" id="Rate_<?php echo $i;?>" value="<?php echo $_REQUEST['Rate'];?>" /></td>
	</tr>

<?php 
}
?>
<input type="hidden" name="count" id="count" value="<?php echo $i;?>" />
</table>
