<?php
function materialshow2($PcateID,$size,$dashVal)
{
	global $db;
	$spacebar = $dashVal ;
	$totalqty1=$totalqty1;
	$s=new db_query(); 		

	$sqlCate = "select * from bill_material where id = '".$PcateID."'";
	$rsCate  = DB_query($sqlCate,$db);	
	$rowCate = DB_fetch_array($rsCate);
	//$query_comprole=DB_query("select * from bill_raw_material where  bill_material_id='".$rowCate['id']."' AND product_size1='".$size."'",$db);
	$query_comprole=DB_query("select * from bill_raw_material where  bill_material_id='".$rowCate['id']."'",$db);
	
	while($row_comprole=DB_fetch_array($query_comprole))
	{			  
		$bom=$s->getField('bill_material','part_id',$row_comprole['mst_itemid'],'id');
		$unitid=$s->getField('item_master','id',$row_comprole['mst_itemid'],'mst_unitid');
	?>	
		 <tr bgcolor="#FFFFFF">
				<td colspan="2"><?php echo $spacebar;?><img src="images/bent-arrow1.jpg" height="20" width="15" />&nbsp;<?php echo $s->getField('item_master','id',$row_comprole['mst_itemid'],'item_name');?>(<?php echo $s->getField('item_master','id',$row_comprole['mst_itemid'],'StockID');?>)</td>
				<td><?php echo $row_comprole['bom_qty']; echo "&nbsp;"; echo $s->GetFieldValue('unitsofmeasure',"unitid='".$s->getField('item_master','id',$row_comprole['mst_itemid'],'mst_unitid')."'",'unitname');?></td>
				<td><?php echo $row_comprole['bom_sec_qty']; echo "&nbsp;"; echo $s->GetFieldValue('unitsofmeasure',"unitid='".$s->getField('item_master','id',$row_comprole['mst_itemid'],'conv_unit')."'",'unitname');?></td>
				<td><?php echo $row_comprole['bom_costlanded_price'];?></td>
				<td><?php echo $row_comprole['bom_amount'];?></td>
			  </tr>
		<?php if($bom!='')
		{
			materialshow2($bom,$row_comprole['product_size1'],$spacebar);
		}else{
			materialshow3($row_comprole['mst_itemid'],$row_comprole['product_size1'],$spacebar);
		}?>
		<?php	
	}?>
	<?php 
}

function materialshow3($PcateID,$size,$dashVal)
{
	global $db;
	$spacebar .= $dashVal;
	$s=new db_query();
	$sqlCate = "select * from bill_material where part_id = '".$PcateID."'";
	$rsCate  = DB_query($sqlCate,$db);	
	if(DB_num_rows($rsCate)>0)
	{
		$rowCate = DB_fetch_array($rsCate);
		//$query_comprole=DB_query("select * from bill_raw_material where bill_material_id='".$rowCate['id']."' AND product_size1='".$size."'",$db);
		$query_comprole=DB_query("select * from bill_raw_material where bill_material_id='".$rowCate['id']."'",$db);
		?>
		 
		<?php
		while($row_comprole=DB_fetch_array($query_comprole))
		{
			$bom=$s->getField('bill_material','part_id',$row_comprole['mst_itemid'],'id');
			$unitid=$s->getField('item_master','id',$row_comprole['mst_itemid'],'mst_unitid');	
		?>
			
			  <tr>
				<td colspan="2"><?php echo $spacebar;?>|--&nbsp;<?php echo $s->getField('item_master','id',$row_comprole['mst_itemid'],'item_name');?>(<?php echo $s->getField('item_master','id',$row_comprole['mst_itemid'],'StockID');?>)</td>
				<td><?php echo $s->getField('size_master','id',$row_comprole['product_size1'],'size');?></td>
				<td><?php echo $row_comprole['bom_uom'];?></td>
				<td><?php echo $row_comprole['bom_qty'];?></td>
				<td><?php echo $row_comprole[''];?></td>
				<td><?php echo $row_comprole[''];?></td>
				<td><?php echo $row_comprole[''];?></td>
				<td><?php echo $row_comprole[''];?></td>
			  </tr>
		<?php } 
		
	}	
}?>