<?php

session_name('CAKEPHP'); session_start();

$PageSecurity = 4;

$PageName = 'Add Items';

include('includes/session.inc');

include('includes/SQL_CommonFunctions.inc');

include('includes/DefineSuppTransClass.php');

?>

<link href="css/professional/default.css" rel="stylesheet" type="text/css" />

<h2 align="center"><?php echo $title; ?></h2>



<form action="" method="post">	

<div style="overflow:auto; width:100%;">

<table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">

      <tr>

        <th><strong>Item Code</strong></th>

        <th><strong>Item Name </strong></th>

		<th><strong>Description </strong></th>

		<th><strong>UOM</strong></th>

		

      </tr>

	  <?php   

	  $counter = $_REQUEST['rowcount'];

	  $ct = explode("_",$counter);	 

	$catid=array();
	  $maincat=DB_query("select id from  stockmaincategory 
	  where stockmaincategoryname in('SPARE PARTS','SEMI-FINISHED GOODS','RAW MATERIAL')",$db);
	 while($row1=DB_fetch_array($maincat))
	 {
	 $catid[]=$row1['id'];
	 }		
       $catid1=implode("','",$catid); 
		$itemname="Select * from item_master WHERE   CategoryID in('".$catid1."')";
		$item_res=DB_query($itemname,$db);
		 $i=0;
		 while($myrow =DB_fetch_array($item_res))
	     {  
		 $parameter=$myrow['id'];

		 $i=0;

  	if($i%2==0)

	{$bg="#CCCCCC";}

	else

	$bg="#C8BECB";

		$u_sql=DB_query("Select unitname from unitsofmeasure where unitid='".$myrow['mst_unitid']."'",$db);

		$u_row=DB_fetch_array($u_sql);

		$sql="select * from bill_material where part_code='".$myrow['StockID']."'";

		$query=DB_query($sql,$db);

		$bill_raw=DB_fetch_array($query);
		$u_sql=DB_query("Select unitname from unitsofmeasure where unitid='".$myrow['mst_unitid']."'",$db);
		$u_row=DB_fetch_array($u_sql);

	  ?>

	  <tr bgcolor="<?php echo $bg; ?>">

      <td><a href="javascript:loadValue('<?php echo $myrow['StockID'];?>,<?php echo $myrow['item_name'];?>,<?php echo $u_row['unitname'];?>,<?php echo $bill_raw['total_production_rate']; ?>,<?php echo $parameter; ?>,','<?php echo $ct[1];?>')"><?php echo $myrow['StockID'];?></a></td>

        <td><?php echo $myrow['item_name'];?></td>

		<td><?php echo $myrow['item_name'];?></td>

		<td><?php echo $u_row['unitname'];?></td>

		      </tr>

	  <?php } ?>

</table>

</div>

</form>





<script>

function loadValue(str,ct)

{  

	var spl = str.split(",");

	var code = spl[0];

	var name = spl[1];

	var uomid = spl[2];	

	var cost=spl[3];
	var id=spl[4];
 
	if(ct)

	{

	window.opener.document.getElementById('itemcode_'+ct).value = code;

	window.opener.document.getElementById('desc_'+ct).value = name;

	window.opener.document.getElementById('uom_'+ct).value = uomid;

	window.opener.document.getElementById('costlandprice_'+ct).value = cost;
    window.opener.document.getElementById('itemid_'+ct).value = id;
	if(cost!='')

	{

	window.opener.document.getElementById("costlandprice_"+ct).setAttribute('readonly','readonly');

	}		

	}		

	else

	{

	window.opener.document.getElementById('itemcode'+ct).value = code;

	window.opener.document.getElementById('desc'+ct).value = name;

	window.opener.document.getElementById('uom'+ct).value = uomid;

	window.opener.document.getElementById('costlandprice'+ct).value = cost;
    window.opener.document.getElementById('itemid'+ct).value = id;
	if(cost!='')

	{

	window.opener.document.getElementById("costlandprice"+ct).setAttribute('readonly','readonly');

	}

	}

	window.close();

}

</script>

	