<?php
if($_REQUEST['action']=='delete' and $_REQUEST['removeid']!='')
{
	$update1="update bill_raw_material set status='1' where id='".$_REQUEST['removeid']."'";
	$query1=DB_query($update1,$db);	
}

if($_REQUEST['action']=='removeprocess' and $_REQUEST['removeprocessid']!='')
{
	$update1="update bom_process_operational set status='1' where id='".$_REQUEST['removeprocessid']."'";
	$query1=DB_query($update1,$db);	
}


if($_REQUEST['action']=='removeover' and $_REQUEST['removeoverid']!='')
{
	$update1="update bill_other_overhead set status='1' where id='".$_REQUEST['removeoverid']."'";
	$query1=DB_query($update1,$db);	
}


if(isset($_POST['Update']))
	{
	$del="delete from bill_raw_material  where status='1' and bill_material_id='".$_REQUEST['Id']."'";
	$querydel=DB_query($del,$db);	
	$del2="delete from bom_process_operational  where status='1' and bill_id='".$_REQUEST['Id']."'";
	$queryde2=DB_query($del2,$db);	
	$del3="delete from bill_other_overhead  where status='1' and bill_id='".$_REQUEST['Id']."'";
	$queryde3=DB_query($del3,$db);		
	
	$qty=$_REQUEST['itemcode1'];
	$qty1=count($qty);
	for($i=0;$i<$qty1;$i++)
	{					 	
	$query2=DB_query("select * from bill_raw_material where part_code='".$_REQUEST['itemcode1'][$i]."' and production_process='".$_REQUEST['product_process'][$i]."'
	and bill_material_id='".$_REQUEST['Id']."'",$db);
	$num1=DB_num_rows($query2);
	if($num1>0)
	{     				
	$insert1="update  bill_raw_material set  
	production_process='".$_REQUEST['product_process1'][$i]."',
	part_code='".$_REQUEST['itemcode1'][$i]."' ,
	bom_description='".$_REQUEST['desc1'][$i]."', 
	bom_uom='".$_REQUEST['uom1'][$i]."',
	bom_qty='".$_REQUEST['qty1'][$i]."',
	bom_costlanded_price='".$_REQUEST['costlandprice1'][$i]."',
	bom_amount='".$_REQUEST['amount1'][$i]."',
	status='0' where id='".$_REQUEST['bomid'][$i]."'";
	$ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
	$insertResult2 = DB_query($insert1,$db,$ErrMsg);			 	 		
	}
	}
	$dataitem=$_REQUEST['itemcode'];
	$dataitemcount=count($dataitem);
	for($j=0;$j<$dataitemcount;$j++)
	{
	if(!empty($_REQUEST['itemcode'][$j]) and !empty($_REQUEST['desc'][$j]) and !empty($_REQUEST['qty'][$j]) and !empty($_REQUEST['procesoveram'][$j])
	and !empty($_REQUEST['amount'][$j]))
	{
	$insert1="insert into bill_raw_material set 
	bill_material_id='".$_REQUEST['Id']."',
	production_process='".$_REQUEST['product_process'][$j]."',
	part_code='".$_REQUEST['itemcode'][$j]."',
	bom_description='".$_REQUEST['desc'][$i]."',
	bom_uom='".$_REQUEST['uom'][$i]."',
	bom_qty='".$_REQUEST['qty'][$j]."',
	bom_costlanded_price='".$_REQUEST['costlandprice'][$j]."',
	bom_amount='".$_REQUEST['amount'][$j]."',status='0'";
	$ErrMsg = _('An error occurred Record Not Save') . '. ' . _('The error says');
	$insertResult2 = DB_query($insert1,$db,$ErrMsg);	
	}
	}
	$qty11=$_REQUEST[procesper1];
	$qty2=count($qty11);
	for($i=0;$i<$qty2;$i++)
	{
	$insert2="update  bom_process_operational set 
	process_name='".$_REQUEST['processid1'][$i]."',
	process_per='".$_REQUEST['procesper1'][$i]."', 
	process_amt='".$_REQUEST['procesamt1'][$i]."',
	total_operational_cost='".$_REQUEST['procsstotal1']."'
	where id='".$_REQUEST['processid2'][$i]."'";
	$ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
	$insertResult2 = DB_query($insert2,$db,$ErrMsg);
	}	
	
	$process=$_REQUEST['procesper'];
	$countprocess=count($process);
	for($j=0;$j<$countprocess;$j++)
	{
	if($_REQUEST['processid'][$j]!='0' and !empty($_REQUEST['procesper'][$j]) and !empty($_REQUEST['procesamt'][$j]))	
	{
	$insert2="insert into  bom_process_operational set bill_id='".$_REQUEST['Id']."',
	process_name='".$_REQUEST['processid'][$j]."',
	process_per='".$_REQUEST['procesper'][$j]."', 
	process_amt='".$_REQUEST['procesamt'][$j]."',
	total_operational_cost='".$_REQUEST['procsstotal']."'";
	$ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
	$insertResult2 = DB_query($insert2,$db,$ErrMsg);	
	}
	}					 
	$qty11=$_REQUEST[procesper];
	$qty2=count($qty11);
	for($i=0;$i<$qty2;$i++)
	{					 
	$insert3="update   bill_other_overhead set 
	overhead_process='".$_REQUEST['process_overhead1'][$i]."',
	overhead_per='".$_REQUEST['procesoverper1'][$i]."', 
	overhead_cost='".$_REQUEST['procesoveram1'][$i]."',
	total_overhead_cost='".$_REQUEST['overheadcost1']."'
	where id='".$_REQUEST['processveram1'][$i]."'";
	$ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
	$insertResult2 = DB_query($insert3,$db,$ErrMsg);
	}	
	$overcount=count($_REQUEST['process_overhead']);
	for($j=0;$j<$overcount;$j++)
	{
	if($_REQUEST['process_overhead'][$j]!='0' and !empty($_REQUEST['procesoverper'][$j]) and !empty($_REQUEST['procesoveram'][$j]))	
	{
	
	$insert3="insert into  bill_other_overhead set 
	bill_id='".$_REQUEST['Id']."',
	overhead_process='".$_REQUEST['process_overhead'][$j]."',
	overhead_per='".$_REQUEST['procesoverper'][$j]."', 
	overhead_cost='".$_REQUEST['procesoveram'][$j]."',
	total_overhead_cost='".$_REQUEST['overheadcost']."'";
	$ErrMsg = _('An error occurred Record Not Save') . '. ' . _('The error says');
	$insertResult2 = DB_query($insert3,$db,$ErrMsg);
	} 
	}
	
	
	$update="update bill_material set  
	brach_code='".$_REQUEST['site']."',
	bom_type='".$_REQUEST['bomtype']."',
	description='".$_REQUEST['Description']."',
	bom_location='".$_REQUEST['bomlocation']."',
	revision_no='".$_REQUEST['revisionno']."',
	revision_date='".FormatDateForSQL($_REQUEST['revisiondate'])."',
	prepared_date='".FormatDateForSQL($_REQUEST['prepared_date'])."',
	prepared_by='".$_REQUEST['prepared_by']."',
	approved_by='".$_REQUEST['approved_by']."',
	total_qty='".$_REQUEST['total_qty']."',
	total_costland_price='".$_REQUEST['landedprice']."',
	total_operation_cost='".$_REQUEST['procsstotal']."',
	total_overheadcost='".$_REQUEST['overheadcost']."',
	total_production_rate='".$_REQUEST['totalamount']."' where id='".$_REQUEST['Id']."'";
	$ErrMsg = _('An error occurred Record Not Save') . '. ' . _('The error says');
	$query=DB_query($update,$db,$ErrMsg);
	}
$sql=DB_query("select * from bill_material where id='".$_REQUEST['Id']."'",$db);
$myrow=DB_fetch_array($sql);
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Edit Bill Of Material</h1>
<form action="" method="post">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
  <tr class="row1">
    <td class="tabledata1">Branch</td>
    <td>
    <select name="site" id="site" style="width:150px;">
        <?php 
		$site_sql = "SELECT prefix,loccode, locationname from locations where loccode='".$myrow['brach_code']."' ";
		$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>
  </tr>
  <tr class="row1">
    <td class="tabledata1">BOM No.</td>
    <td><label>
      <input type="text" name="bomno" id="bomno" style="width:150px;" value="<?php echo $myrow['Bom_no']; ?>" readonly>
    </label></td>
    <td class="tabledata1">Type Of BOM</td>
    <td>  <select name="bomtype" id="" style="width:150px;">
      <?php 
		$site_sql2 = "SELECT id,bom_type from bom_type ";
		$site_result1 = DB_query($site_sql2,$db);
		while($site_row2 = DB_fetch_array($site_result1))
		{
		$t1='';
		if($site_row2['id']==$myrow['Bom_type'])
		{
		$t1="selected";	
		}	
		?>
         <option value="<?php echo $site_row2['id']; ?>" <?php echo $t1; ?> ><?php echo $site_row2['bom_type']; ?></option>
            <?php } ?>
    </select></td>
    <td class="tabledata1">Description</td>
    <td><input type="text" name="Description" id="Description" style="width:150px;" value="<?php echo $myrow['description']; ?>" readonly></td>
  </tr>
  <tr class="row1">
    <td class="tabledata1">Location Of BOM</td>
    <td> <select name="bomlocation" id="" style="width:150px;">
        <?php 
		$site_sql3 = "SELECT id,bom_location from bom_location ";
		$site_result2 = DB_query($site_sql3,$db);
		while($site_row3 = DB_fetch_array($site_result2))
		{
			$t2='';
			if($site_row3['id']==$myrow['Bom_location'])
			{
			$t2="selected";	
			}
		?>
         <option value="<?php echo $site_row3['id']; ?>" ><?php echo $site_row3['bom_location']; ?></option>
            <?php } ?>
    </select></td>
    <td class="tabledata1">Revision No.</td>
    <td><input type="text" name="revisionno" id="v" style="width:150px;" value="<?php echo $myrow['revision_no']; ?>" readonly></td>
    <td class="tabledata1">Revision Date</td>
    <td><input type="text" name="revisiondate" id="revisiondate" style="width:150px;"  value="<?php echo $myrow['revision_date']; ?>" ></td>
  </tr>
  <tr class="row1">
    <td class="tabledata1">Prepared Date</td>
    <td><input type="text" name="prepared_date" id="prepared_date" style="width:150px;"  value="<?php echo $myrow['prepared_date']; ?>"></td>
    <td class="tabledata1">Prepared By</td>
    <td><input type="text" name="prepared_by" id="prepared_by" style="width:150px;" value="<?php echo $myrow['prepared_by']; ?>" readonly></td>
    <td class="tabledata1">Approved By</td>
    <td><input type="text" name="approved_by" id="approved_by" style="width:150px;"  value="<?php echo $myrow['approved_by']; ?>" readonly></td>
  </tr>
  <tr class="row1">
    <td class="tabledata1" colspan="8"><center><strong>Finished Product Details</strong></center></td>
    </tr>
  <tr class="row1">
  	 <td class="tabledata1">Item Details</td>
    <td class="tabledata1">Part Code</td>
    <td><input type="text" name="part_code" id="part_code" style="width:120px;" value="<?php echo $myrow['part_code']; ?>" readonly></td>
    <td class="tabledata1">Product Name</td>
    <td><input type="text" name="product_name" id="product_name" style="width:120px;" value="<?php echo $myrow['product_name']; ?>" readonly></td>
    <td class="tabledata1">UOM</td>
    <td><input type="text" name="uom" id="uom" style="width:150px;" value="<?php echo $myrow['uom']; ?>" readonly></td>
  
  </tr>
</table>
<p align="left" style="margin:0px;">
<input type="button" onclick="addRow('dataTable')" value="Add More" />&nbsp;
<input type="button" class="crmbutton small delete"  onclick="deleteRow('dataTable')" value="Delete" />
</p>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata" colspan="10"><div align="center"><strong>BOM - Raw Material And Assembly Item Details</strong></div></td></tr>
  <tr>
  	<td class="tabledata">S.R. No</td>
  	<td class="tabledata">Production Process</td>
    <td class="tabledata">Part Code</td>
    <td class="tabledata">Description</td>
    <td class="tabledata">UOM</td>
    <td class="tabledata">Qty</td>
    <td class="tabledata">Cost Landed Price</td>
    <td class="tabledata">Amount</td>
    <td class="tabledata">Action</td>
  </tr>    
     <?php
     $i=1;
   $raw_mat=DB_query("select * from bill_raw_material where bill_material_id='".$myrow['id']."' and status=0",$db);
   while($raw=DB_fetch_array($raw_mat))
   {   
   ?>
<tr bgcolor="#c1c1c1">
  	<td><?php echo $i; ?></td> 	  	
       <td><select name="product_process[]" id="prodcut_process" style="width:100%">
      <?php $productrow=DB_query("select * from production_process_master where id='".$raw['production_process']."'",$db);
		while($product_row1=DB_fetch_array($productrow))
		{
		?>
		<option value="<?php echo $product_row1['id']; ?>"><?php echo $product_row1['manuf_process_name'];?></option>
		}   	
    	<?php  } ?>	
    </select></td>
    <td><input type="text" name="itemcode1[<?php echo $i; ?>]" id="itemcode1[<?php echo $i; ?>]" style="width:100%" readonly  value="<?php echo $raw['part_code']?>" ></td>
    <td><input type="text" name="desc1[<?php echo $i; ?>]" id="desc1[<?php echo $i; ?>]" style="width:100%"  readonly  value="<?php echo $raw['bom_description']?>" ></td>
    <td><input type="text" name="uom1[<?php echo $i; ?>]" id="uom1" style="width:100%" readonly  value="<?php echo $raw['bom_uom']?>" ></td>
    <td><input type="text" name="qty1[<?php echo $i; ?>]" id="qty1_<?php echo $i; ?>" style="width:100%"  value="<?php echo $raw['bom_qty']?>" ></td>
    <td><input type="text" name="costlandprice1[<?php echo $i; ?>]" id="costlandprice1_<?php echo $i; ?>" style="width:100%"  value="<?php echo $raw['bom_costlanded_price']?>" ></td>
    <td><input type="text" name="amount1[<?php echo $i; ?>]" id="amount1_<?php echo $i; ?>" style="width:100%"  value="<?php echo $raw['bom_amount']?>"  onblur="calamount(<?php echo $i; ?>)">
    <input type="hidden" name="bomid[<?php echo $i; ?>]" value="<?php echo $raw['id']; ?>">
    </td>
    <td><a href="index.php?route=edit_bill_of_material&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=delete&Id=<?php echo $myrow['id'];?>&removeid=<?php echo $raw['id'];  ?>">remove</a></td>
  </tr>
  <?php $i++; } ?>
  <input type="hidden" name="count" id="count" value="<?php echo $i; ?>" />
   <tbody id="dataTable">
<tr bgcolor="#c1c1c1">
  	<td><input type="checkbox" name="chk" /><input type="hidden" value="" id="user_shipping" name="user_shipping[]" /><input type="button" name="profile_popup" value="+" id="profile_popup"  onclick="openPopupProfile(this.id)" /></td>
       <td><select name="product_process1[]" id="prodcut_process1" style="width:100%">
    	<option value="0">---Select </option>
    	<?php $productrow=DB_query("select * from production_process_master",$db);
		while($product_row1=DB_fetch_array($productrow))
		{
			?>
			<option value="<?php echo $product_row1['id']; ?>"><?php echo $product_row1['manuf_process_name'];?></option>
		}
    	<?php } ?>    	
    </select></td>
    <td><input type="text" name="itemcode[]" id="itemcode" style="width:100%"readonly></td>
    <td><input type="text" name="desc[]" id="desc" style="width:100%" readonly></td>
    <td><input type="text" name="uom[]" id="uom" style="width:100%" readonly></td>
    <td><input type="text" name="qty[]" id="qty" style="width:100%" ></td>
    <td><input type="text" name="costlandprice[]" id="costlandprice" style="width:100%" ></td>
    <td><input type="text" name="amount[]" id="amount" style="width:100%" onblur="calamount1(this)"></td>
	<td>&nbsp;</td>
  </tr>
   </tbody>
</table>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata" nowrap>Total Raw Material And Assembly Item Qty</td>
    <td><input type="text" name="total_qty" id="total_qty" style="width:100%"  value="<?php echo $myrow['total_qty']; ?>" onblur="calqty();"></td>
    <td class="tabledata" nowrap>Total Cost Landed Price</td>
    <td><input type="text" name="landedprice" id="landedprice" style="width:100%"  value="<?php echo $myrow['total_costland_price']; ?>" onblur="caltotal();"></td>
  </tr>
</table>

    		


<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top"> 
	
	<p align="left" style="margin:0px;">
<input type="button" onclick="addRow('dataTable1')" value="Add More Process" />&nbsp;
<input type="button" class="crmbutton small delete"  onclick="deleteRow('dataTable1')" value="Delete" />
</p>
	 
    <table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata" colspan="5">Process Operational Cost</td>
  </tr>
  
  <tr>
    <td class="tabledata" scope="col">S. No.</td>
    <td class="tabledata" scope="col">Process</td>
    <td class="tabledata" scope="col">%</td>
    <td class="tabledata" scope="col">Amount</td>
    <td class="tabledata">Action</td>
  </tr>
  
  <?php
  $k=1;
  $raw_mat1=DB_query("select * from bom_process_operational  where bill_id='".$myrow['id']."'and status='0'",$db);
   while($raw1=DB_fetch_array($raw_mat1))
   {   
  ?>  
<tr bgcolor="#c1c1c1">
    <td><?php echo $k; ?></td>
    <td><select name="processid1[]" id="process" style="width:100%">
    	<?php       	
    	$productrow=DB_query("select * from production_process_master where id='".$raw1['process_name']."'",$db);
		while($product_row1=DB_fetch_array($productrow))
		{
			?>
			<option value="<?php echo $product_row1['id']; ?>"><?php echo $product_row1['manuf_process_name'];?></option>
		}
    	
    	<?php } ?>
    	
    </select>
    	
    	 </td>
    <td><input type="text" name="procesper1[<?php echo $k; ?>]"   id="procesper1_<?php echo $k; ?>" value="<?php echo $raw1['process_per']; ?>" /></td>
    <td><input type="text" name="procesamt1[<?php echo $k; ?>]" id="procesamt1_<?php echo $k; ?>" value="<?php echo $raw1['process_amt']; ?>" onblur="calpercentage1(<?php echo $k; ?>);"/>
    	<input type="hidden" name="processid2[]" value="<?php echo $raw1['id']; ?>">
    	    </td>
    	    <td><a href="index.php?route=edit_bill_of_material&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=removeprocess&Id=<?php echo $myrow['id'];?>&removeprocessid=<?php echo $raw1['id'];  ?>">remove</a></td>
  </tr>
  <?php $k++; } ?>
  <input type="hidden" name="count1" value="<?php echo $k; ?>" id="count1"/>
  <tbody id="dataTable1">
<tr bgcolor="#c1c1c1">
    <td><input type="checkbox" name="chk" /><input type="hidden" value="" id="user_shipping" name="user_shipping[]" />
       	
    </td>
    <td><select name="processid[]=" style="width:100%">
    	<option value="0">---Select </option>
    	<?php       	
    	$productrow=DB_query("select * from production_process_master",$db);
		while($product_row1=DB_fetch_array($productrow))
		{
			?>
			<option value="<?php echo $product_row1['id']; ?>"><?php echo $product_row1['manuf_process_name'];?></option>
		}
    	
    	<?php } ?>
    	
    </select>    	
    	 </td>
    <td><input type="text" name="procesper[]"   id="procesper"/></td>
    <td><input type="text" name="procesamt[]" id="procesamt" onblur="calpercentage(this);" /></td>
	<td>&nbsp;</td>
	
  </tr></tbody>
</table>
	
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
    	<tr><td class="tabledata">Total Operational Cost</td><td><input type="text" name="procsstotal" readonly id="procsstotal" style="width:100%" value="<?php echo $myrow['total_operation_cost']; ?>" onblur="operationcost(this);"></td></tr>
    </table>
	</td>


    <td valign="top">  
    	 <p align="left" style="margin:0px;">
<input type="button" onclick="addRow('dataTable2')" value="Add More Process" />&nbsp;
<input type="button" class="crmbutton small delete"  onclick="deleteRow('dataTable2')" value="Delete" />
</p>
       <table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata" colspan="5">Other Overhead Cost</td>
  </tr>
  <tr>
    <td class="tabledata">S. No.</td>
    <td class="tabledata">Process</td>
    <td class="tabledata">%</td>
    <td class="tabledata">Amount</td>
    <td class="tabledata">action</td>
  </tr>
  
  <?php 
   $j=1;
  $raw_mat2=DB_query("select * from bill_other_overhead  where bill_id='".$myrow['id']."' and status='0'",$db);
   while($raw2=DB_fetch_array($raw_mat2))
   {   
  ?>
 
<tr bgcolor="#c1c1c1">
    <td><?php echo $j; ?></td>
    <td><select name="process_overhead1[]" style="width:100%">
    	
    	<?php       	
    	$productrow=DB_query("select * from production_process_master where id='".$raw2['overhead_process']."'",$db);
		while($product_row1=DB_fetch_array($productrow))
		{
			?>
			<option value="<?php echo $product_row1['id']; ?>"><?php echo $product_row1['manuf_process_name'];?></option>
		}
    	
    	<?php  } ?>
    	
    </select>
    	
    	 </td>
    <td><input type="text" name="procesoverper1[<?php echo $j; ?>]"  id="procesoverper1_<?php echo $j; ?>"  value="<?php echo $raw2['overhead_per']; ?>" /></td>
    <td><input type="text" name="procesoveram1[<?php echo $j; ?>]" id="procesoveram1_<?php echo $j; ?>"    value="<?php echo $raw2['overhead_cost']; ?>" onblur="caloverpercentage1(<?php echo $j; ?>)"/>
    	<input type="hidden" name="processveram1[<?php echo $j; ?>]" value="<?php echo $raw2['id']; ?>">
    </td>
    <td><a href="index.php?route=edit_bill_of_material&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=removeover&Id=<?php echo $myrow['id'];?>&removeoverid=<?php echo $raw2['id'];  ?>">remove</a></td>
  </tr>
  <?php $j++; } ?>
  <input type="hidden" name="count2" value="<?php echo $j; ?>" id="count2"/>
   <tbody id="dataTable2">
<tr bgcolor="#c1c1c1">
    <td><input type="checkbox" name="chk" />
	<input type="hidden" value="" id="user_shipping" name="user_shipping[]" />
       	
    </td>
    <td><select name="process_overhead[]=" style="width:100%">
    	<option value="0">---Select </option>
    	<?php       	
    	$productrow=DB_query("select * from production_process_master",$db);
		while($product_row1=DB_fetch_array($productrow))
		{
			?>
			<option value="<?php echo $product_row1['id']; ?>"><?php echo $product_row1['manuf_process_name'];?></option>
		}
    	
    	<?php } ?>
    	
    </select>
    	
    	 </td>
    <td><input type="text" name="procesoverper[]"  id="procesoverper" /></td>
    <td><input type="text" name="procesoveram[]" id="procesoveram"   onblur="caloverpercentage(this)"/></td>
	<td>&nbsp;</td>
  </tr></tbody>
  
    </table>

<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
    	<tr>
    	  <td class="tabledata">Total Overhead Cost</td>
    	  <td><input type="text" name="overheadcost" id="overheadcost" style="width:100%" value="<?php echo $myrow['total_overheadcost']; ?>"onblur="overheadcostcal(this);"></td></tr>
    </table>
    </td>
  </tr>
</table>

<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
<tr>
<td class="tabledata" style="width:194px;">Total Production Rate Of Bill Of Material</td>
<td><input type="text" name="totalamount" id="totalamount" style="width:100%"  value="<?php echo $myrow['total_production_rate']; ?>" onblur="totalamountcal(this);"></td>
</tr>
</table>
<p align="center"><input type="submit" name="Update" value="Update"></p>
</form>


</div></div>





<script language="javascript" type="text/javascript">
function open_items()
{
	window.open("bill_finishproduct.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>","item_popup_window","height=500,width=900,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}
function openPopupProfile(i)
{ 
		window.open("pickrawmaterial.php?rowcount="+i,"profiles_popup_window","height=425,width=640,toolbar=no,menubar=no,dependent=yes,resizable=yes");
}
function calamount(obj)
{         var amount='';
	          	
	   var t=document.getElementById('costlandprice1_'+obj).value;	    
         var k=document.getElementById('qty1_'+obj).value;
        var amount=t*k;
        document.getElementById('amount1_'+obj).value=amount;
		
}

function calamount1(obj)
{      var amount='';
	      var rowCount = document.getElementById('dataTable').rows.length;
	      var arr = obj.id.split("_");
	     var rowx1=0;
	   if (arr[1]==undefined)
	   {
	    var nm='';
	    var t=document.getElementById('costlandprice').value;
	    
         var k=document.getElementById('qty').value;
        var amount=t*k;
        document.getElementById('amount').value=amount;
       }
	 else
	 {
	 var nm='_'+arr[1];
	 }
	  for(var i=1;i<rowCount;i++)
	{   var t=document.getElementById('costlandprice'+nm).value;
	    
         var k=document.getElementById('qty'+nm).value;
        var amount=t*k;
        document.getElementById('amount'+nm).value=amount;
		}
}


function caltotal()
{      
	   var  rowx2=0;  
      var rowx1=0;	
	 var rowCountdata=document.getElementById('dataTable').rows.length;
	  var rowCount = document.getElementById('count').value;
     var obj1=document.getElementById('amount').value;	
     var obj=document.getElementById('amount');
	 var arr = obj.id.split("_");
	 if (arr[1]==undefined)
	 {
	  var nm='';
	 }
	 else
	 {
	 var nm='_'+arr[1];
	 }
	for(var i=1;i<rowCountdata;i++)
	{  		
	rowx2=parseInt(document.getElementById('amount_'+i).value)+parseInt(rowx2);
    }   
    rowx2=parseInt(rowx2)+parseInt(obj1)
    for(var j=1;j<rowCount;j++)
    {  
   	rowx1=parseInt(document.getElementById('amount1_'+j).value)+parseInt(rowx1);
   	} 
   	rowx1=parseInt(rowx2)+parseInt(rowx1);
    document.getElementById('landedprice').value=rowx1;
   }
   function calqty()
    { 
    	
      var  rowx2=0;  
      var rowx1=0;	
	 var rowCountdata=document.getElementById('dataTable').rows.length;
	  var rowCount = document.getElementById('count').value;
     var obj1=document.getElementById('qty').value;	
     var obj=document.getElementById('qty');
	 var arr = obj.id.split("_");
	 if (arr[1]==undefined)
	 {
	  var nm='';
	 }
	 else
	 {
	 var nm='_'+arr[1];
	 }
	for(var i=1;i<rowCountdata;i++)
	{  		
	rowx2=parseInt(document.getElementById('qty_'+i).value)+parseInt(rowx2);
    }   
    rowx2=parseInt(rowx2)+parseInt(obj1)
    for(var j=1;j<rowCount;j++)
    {  
   	rowx1=parseInt(document.getElementById('qty1_'+j).value)+parseInt(rowx1);
   	} 
   	rowx1=parseInt(rowx2)+parseInt(rowx1);
   	document.getElementById('total_qty').value=rowx1;
    }   
   function calpercentage1(str1)
   {
   	    var t=document.getElementById('landedprice').value; 
   	   	var k=document.getElementById('procesper1_'+str1).value;
		 var amount=parseInt(t)*parseInt(k);
        var amount1=parseInt(amount)/100;
        document.getElementById('procesamt1_'+str1).value=amount1;	
   	
   }
    function calpercentage(str1)
   {
   	    var t=document.getElementById('landedprice').value;   	     
   	    var rowCount = document.getElementById('dataTable1').rows.length;
   	       var arr = str1.id.split("_");
   	    
	     var rowx1=0;
	   if (arr[1]==undefined)
	   {
	     var nm='';	    
	     var k=document.getElementById('procesper').value;
         var amount=parseInt(t)*parseInt(k);
         var amount1=parseInt(amount)/100;       
        document.getElementById('procesamt').value=amount1;
       }
	 else
	 {
	 var nm='_'+arr[1];
	 }
	 
	  for(var i=1;i<rowCount;i++)
	{   
		var k=document.getElementById('procesper'+nm).value;
	    var amount=parseInt(t)*parseInt(k);
        var amount1=parseInt(amount)/100;
        document.getElementById('procesamt'+nm).value=amount1;
		}
   	
   }
    function caloverpercentage1(str1)
   {
   	    var t=document.getElementById('landedprice').value; 
   	   	var k=document.getElementById('procesoverper1_'+str1).value;
		 var amount=parseInt(t)*parseInt(k);
        var amount1=parseInt(amount)/100;
        document.getElementById('procesoveram1_'+str1).value=amount1;	
   	
   }
   function caloverpercentage(str1)
   {
   	    var t=document.getElementById('landedprice').value;   	     
   	    var rowCount = document.getElementById('dataTable2').rows.length;
   	       var arr = str1.id.split("_");
   	    
	     var rowx1=0;
	   if (arr[1]==undefined)
	   {
	     var nm='';	    
	     var k=document.getElementById('procesoverper').value;
         var amount=parseInt(t)*parseInt(k);
         var amount1=parseInt(amount)/100;       
        document.getElementById('procesoveram').value=amount1;
       }
	 else
	 {
	 var nm='_'+arr[1];
	 }
	 
	  for(var i=1;i<rowCount;i++)
	{   
		var k=document.getElementById('procesoverper'+nm).value;
	    var amount=parseInt(t)*parseInt(k);
        var amount1=parseInt(amount)/100;
        document.getElementById('procesoveram'+nm).value=amount1;
		}
   	
   }
   function operationcost(str)
   {
   	var rowx2=0;
   	var rowCount = document.getElementById('dataTable1').rows.length;
   	var rowCount1=document.getElementById("count1").value;
         var obj2=document.getElementById('procesamt').value;
	     var obj=document.getElementById('procesamt');
	     var arr = obj.id.split("_");
	     var rowx1=0;
	    if (arr[1]==undefined)
	   {
	    var nm='';
	   }
	   else
	 {
	 var nm='_'+arr[1];
	 }
	 for(var i=1;i<rowCount;i++)
	{
		rowx1=parseInt(document.getElementById('procesamt_'+i).value)+parseInt(rowx1);	
    }
    rowx1=parseInt(rowx1)+parseInt(obj2)
    for(var j=1;j<rowCount1;j++)
    {
    rowx2=parseInt(document.getElementById("procesamt1_"+j).value)+parseInt(rowx2);	
    }
    rowx1=rowx2+rowx1
   document.getElementById('procsstotal').value=rowx1;
   	
   }
   function overheadcostcal(str)
   {
   		var rowx2=0;
   	var rowCount = document.getElementById('dataTable1').rows.length;
   	var rowCount1=document.getElementById("count1").value;
         var obj2=document.getElementById('procesoveram').value;
	     var obj=document.getElementById('procesoveram');
	     var arr = obj.id.split("_");
	     var rowx1=0;
	    if (arr[1]==undefined)
	   {
	    var nm='';
	   }
	   else
	 {
	 var nm='_'+arr[1];
	 }
	 for(var i=1;i<rowCount;i++)
	{
		rowx1=parseInt(document.getElementById('procesoveram_'+i).value)+parseInt(rowx1);	
    }
    rowx1=parseInt(rowx1)+parseInt(obj2)
    for(var j=1;j<rowCount1;j++)
    {
    rowx2=parseInt(document.getElementById("procesoveram1_"+j).value)+parseInt(rowx2);	
    }
    rowx1=rowx2+rowx1
   document.getElementById('overheadcost').value=rowx1;
   
   	
   }
  
   function totalamountcal(str)
   {
   	var t=  document.getElementById('procsstotal').value;
   	var k= document.getElementById('overheadcost').value;
   	var j=document.getElementById('landedprice').value;
   	var amount=parseInt(t)+parseInt(k)+parseInt(j);
   	document.getElementById('totalamount').value=amount;   		
   }

</script>
