<?php
 if($_REQUEST['Delete'])
{
for($i=0;$i<count($_REQUEST['leadid']);$i++){
 $del="delete from bill_material where id='".$_REQUEST['leadid'][$i]."'";
 $query=DB_query($del,$db);
 $del1="delete from bill_raw_material where bill_material_id='".$_REQUEST['leadid'][$i]."'"	;
 $query1=DB_query($del1,$db);
  $del2="delete from bom_process_operational where bill_id='".$_REQUEST['Id'][$i]."'";
  $query2=DB_query($del2,$db);
   $del3="delete from bill_other_overhead where bill_id='".$_REQUEST['Id'][$i]."'";
  $query3=DB_query($del3,$db);
  }
}
?>
<script language="javascript" type="text/javascript">
function LeadData()
{	
	myCheckboxArray = document.myform.elements["leadid[]"];
	var t=myCheckboxArray.length;
	//alert(myCheckboxArray);
	if(document.getElementById('leadid').checked==true)
	{	
	if(t==undefined)
	document.getElementById('leadid_'+1).checked=true;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=true;	
	}	
	}
	else
	{
	if(t==undefined)		
	document.getElementById('leadid_'+1).checked=false;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=false;	
	}
	}
}
</script> 
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<form name="myform" method="post">
<div class="tab_div">
<h1>BOM List</h1>
<p align="left">
<a href="index.php?route=Production/bom/bill_of_material&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><input type="button" name="Create" value="Add BOM" class="search"/></a>
<input type="submit" name="Delete" value="Delete" class="search" onclick="return confirm('Are you sure you want to delete?')" />
</p>

<div style="width:100%; overflow:auto; height:auto;">
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
<tr>
<td class="tabledata"><input name="leadid" type="checkbox"   id="leadid" onclick="LeadData()"    /></td>
<td class="tabledata">Branch</td>
<td class="tabledata">BOM No.</td>
<td class="tabledata">Prepared Date</td>
<td class="tabledata">Total RawMaterial Qty</td>
<td class="tabledata">Total CostLanded </td>
<td class="tabledata">Total OT Cost</td>
<td class="tabledata">Total Overhead Cost</td>
<td class="tabledata">Total Production Rate </td>
</tr>
<?php
$sql=DB_query("Select * from bill_material where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);	
$i=0;
$num=DB_num_rows($sql);
if($num>0)
{
while($myrow=DB_fetch_array($sql))
{
?>
<tr class="row1">
<td style="white-space:nowrap;"><input name="leadid[]" type="checkbox" id="leadid_<?php echo $i+1; ?>"   value="<?php  echo $myrow['id']?>" />
	
	<a href="index.php?route=Production/bom/edit_bill_of_material&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=edit&Id=<?php echo $myrow['id'];?>"><img src="images/icon_edit.gif" width="12px"  height="12" /></a>
	
	<a href="index.php?route=Production/bom/view_bill_of_material&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=edit&Id=<?php echo $myrow['id'];?>"><img src="images/search.gif" width="12px"  height="12" /></a>
	</td>
<td><?php   echo  $branch=$s->getField('locations','loccode',$myrow['brach_code'],'locationname');?></td>
<td><?php echo $myrow['Bom_no'];?></td>
<td><?php echo ConvertSQLDate($myrow['prepared_date']);?></td>
<td><?php echo $myrow['total_qty'];?></td>
<td><?php echo $myrow['total_costland_price'];?></td>
<td><?php echo $myrow['total_operation_cost'];?></td>
<td><?php echo $myrow['total_overheadcost'];?></td>
<td><?php echo $myrow['total_production_rate'];?></td>
</tr>
<?php $i++;}}
else { ?>
	<tr bgcolor="#FFFFFF">
<td colspan="9">No Records Find</td>
</tr>
<?php }   ?>
	
</table>

</div>
</div>
</form>