<?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);
   }
}
?>
<script type="text/javascript">
function showSlidingDiv(){
$("#slidingDiv").animate({"height": "toggle"}, { duration: 700 });
}
</script>
<style>
#slidingDiv {
    display: none;
	height:100px;
	background-color: #D9D6DA;
	padding:20px;
}
</style>
<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=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 align="center"><a href="#" onClick="showSlidingDiv(); return false;">SEARCH</a></div>

<div id="slidingDiv" class="centre" >
<table width="50%" border="0" cellspacing="1" cellpadding="2" align="center">
  <tr>
	<th width="40%"><strong>Branch</strong></th>
    <td width="10%">
	 <select name="site" id="site" >
    <option value="0">All Branches</option>
     <?php 
		$site_sql = "Select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
		$site_result = DB_query($site_sql,$db);
		while($site_row = DB_fetch_array($site_result))
		{
		?>
         <option value="<?php echo $site_row['loccode']; ?>" ><?php echo $site_row['locationname']; ?></option>
            <?php } ?>
    </select></td>
	<th width="40%"><strong>Sub Category</strong></th>
    <td width="10%">
	<div id="mrnno1">
     <select  name="subcategory" id="subcategory">
	 <option  value="000">Select Category</option>
	<?php 
		$sql = "SELECT  * FROM stockcategory";
		$resultStkLocs = DB_query($sql,$db);
		while ($myrow=DB_fetch_array($resultStkLocs)){
 				echo '<option Value="'.$myrow['id'].'">' . $myrow['categorydescription'].'</option>';
 		
       }

	?> </select>
	</div>
	
	</td></tr>
   
	
  </table>
  <br />
  
  <p align="center"><input name="Search" type="submit" value="Search" /></p>
  
</div>


<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">Bom Item Details</td>
<td class="tabledata">Total RawMaterial Qty</td>
</tr>
<?php
    if(isset($_POST['Search']))
	{   $iddata=array();
    	$site=$_REQUEST['site'];
		
		$stockcat=$_REQUEST['subcategory'];
		if($site!='000')
		{
			$filter[]="brach_code='".$site."'";
		}
		
		if($stockcat!='000')
		 {		
		 $sqlsubcat=DB_query("select * from item_master where SubCategoryID='".$stockcat."'",$db);
		 while($sqlcat=DB_fetch_array($sqlsubcat))
		 {	
		 $iddata[]=$sqlcat['id'];
		 }
		 $catid=implode("','",$iddata);
		$filter[]="part_id in('".$catid."')";
		}
		 if(isset($filter))
		 {
		 if(count($filter)>0)
		
			{
			$filter1=implode(" and ",$filter);
			$sql="Select * from bill_material where CompanyId='".$_SESSION['ACGCompanyId']."' and $filter1";
			}
			}
	}
	
  else
  $sql="Select * from bill_material where CompanyId='".$_SESSION['ACGCompanyId']."'";
 //echo $sql;	
 $sql1=DB_query($sql,$db);
$i=0;
$num=DB_num_rows($sql1);
if($num>0)
{
while($myrow=DB_fetch_array($sql1))
{
?>
<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=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=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>
<a href="bomprint.php?Id=<?php echo $myrow['id'];?>" target="_blank">Print</a>
<a href="index.php?route=bill_of_material_copy&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=edit&Id=<?php echo $myrow['id'];?>">Copy</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 $branch=$s->getField('item_master','id',$myrow['part_id'],'item_name');?></td>
<td><?php echo $myrow['total_qty'];?></td>
</tr>
<?php $i++;}}
else { ?>
	<tr bgcolor="#FFFFFF">
<td colspan="9">No Records Find</td>
</tr>
<?php }   ?>
	
</table>

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