<?php 
$PageSecurity = 2;
include('includes/DefineSuppTransClass.php');
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
include('includes/session.inc');
include('includes/function_lib.php');
include('includes/fun-HRClass.php');


if($_REQUEST['bom1']!=''){
$sql=DB_query("Select * from bill_material where id='".$_REQUEST['bom1']."'",$db);
$row1=DB_fetch_array($sql);
$subcatname=$s->GetFieldValue('stockcategory',"id='".$row1['subcatid']."'",'categorydescription');  
 $unitname= $s->GetFieldValue('unitsofmeasure',"unitid='".$row1['part_id']."'",'unitname');		  
$data1='';
$data1.="<table width='100%%' border='0' cellspacing='0' cellpadding='0'>
  <tr>
    <td colspan='7' class='tabledata1'>Pick Item
      <input type='text' name='item_popup'  id='item_popup'    class='search'/></td>
    </tr>
	  <tr><th ><input type='hidden' name='partid' id='partid' value='".$row1['part_id']."' />
        <input name='subcatid' id='subcatid' type='hidden' value='".$row1['subcatid']."' />Part Code</th>
	<td><input type='text' name='part_code' id='part_code' style='width:180px;' value='".$row1['part_code']."'
	 readonly='readonly'></td>
    <th >Product Name</th>
    <td><input type='text' name='product_name' id='product_name' style='width:180px;' value='".$row1['product_name']."' readonly='readonly'></td>
    <th>Category</th>
    <td><input type='text' name='subcatname' id='subcatname' style='width:150px;' value='".$subcatname."' readonly='readonly'></td>
   <th>UOM</th>
    <td><input type='text' name='finished_uom' id='finished_uom' style='width:150px;' value='".$unitname."' readonly='readonly'></td>
</tr>
</table>";

$data2='';
$data2.="<table width='100%' border='1' cellpadding='3' cellspacing='0' style='border-collapse:collapse; border:#666666 solid 1px;'>
  <tr>
    <td class='tabledata1' colspan='9'><h3 style='color:#000000; font-size:16px;'><strong>BOM - Raw Material And Assembly Item Details</strong></h3></td></tr>
  <tr>
  	<td class='tabledata'>Select</td>
    <td class='tabledata'>Production Process</td>
	<td class='tabledata'>&nbsp;</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>
    </tr>";
   $i=0;
   $billraw=DB_query("select * from bill_raw_material where bill_material_id='".$_REQUEST['bom1']."'",$db);
   while($billrawdata=DB_fetch_array($billraw))
   {   
   $itemcode=$s->GetFieldValue('item_master',"id='".$billrawdata['mst_itemid']."'",'StockID');
   $itemname=$s->GetFieldValue('item_master',"id='".$billrawdata['mst_itemid']."'",'item_name');
  $unit= $s->GetFieldValue('unitsofmeasure',"unitid='".$billrawdata['mst_itemid']."'",'unitname');	
   
  $data2.="<tr>
  	<td class='tabledata'><input type='checkbox' name='chk' /><input type='hidden' value='' id='user_shipping' name='user_shipping[]' /></td>
	
        <td class='tabledata'><select name='product_process[]' id='prodcut_process' style='width:100%'>
		<option value='0'>---Select </option>";
    	 $productrow=DB_query("select * from production_process_master",$db);
		 $numrow=DB_num_rows($productrow);
		 
		while($product_row1=DB_fetch_array($productrow))
		{    $p='';
		    if($product_row1['id']==$billrawdata['production_process'])
			$p='selected';
			$data2.="<option value=".$product_row1['id']." ".$p.">".$product_row1['manuf_process_name']."</option>";		
    	 } 
    	
    $data2.="</select></td>
	<td class='tabledata'><input type='hidden' name='itemid[]' id='itemid_".$i."' value='".$billrawdata['mst_itemid']."' /></td>
    <td class='tabledata'><input type='text' name='itemcode[]' id='itemcode_".$i."' style='width:100%' value='".$itemcode."' readonly></td>
    <td class='tabledata'><input type='text' name='desc[]' id='desc_".$i."' style='width:100%' value='".$itemname."'   readonly></td>
    <td class='tabledata'><input type='text' name='uom[]' id='uom_".$i."' style='width:100%' value='".$unit."'  readonly></td>
    <td class='tabledata'><input type='text' name='qty[]' id='qty_".$i."' style='width:100%' value='".$billrawdata['bom_qty']."' ></td>
    <td class='tabledata'><input type='text' name='costlandprice[]' id='costlandprice_".$i."' style='width:100%' value='".$billrawdata['bom_costlanded_price']."'   ></td>
    <td class='tabledata'><input type='text' name='amount[]' id='amount_".$i."' style='width:100%' onfocus='calamount1(".$i.")'
	value='".$billrawdata['bom_amount']."'></td>
  </tr>";
  $i++; }
  
    
  
   $data2.="<input type='text' name='hiditemcount' id='hiditemcount'  />
   <input type='text' name='' value='".$i."' id='edit_cnt' /> ";
   $data2.=" <tbody id='dataTable'>
  <tr>
  	<td class='tabledata'><input type='checkbox' name='chk' /><input type='hidden' value='' id='user_shipping' name='user_shipping[]' /></td>
	
        <td class='tabledata'><select name='product_process[]' id='prodcut_process' style='width:100%'>
		
    	<option value='0'>---Select </option>";
    	 $productrow=DB_query("select * from production_process_master",$db);
		while($product_row1=DB_fetch_array($productrow))
		{
			
			$data2.="<option value=".$product_row1['id'].">".$product_row1['manuf_process_name']."</option>";
		
    	
    	} 
    	
    $data2.="</select></td>
	<td class='tabledata'><input type='hidden' name='itemid[]' id='itemid' /></td>
    <td class='tabledata'><input type='text' name='itemcode[]' id='itemcode' style='width:100%' readonly></td>
    <td class='tabledata'><input type='text' name='desc[]' id='desc' style='width:100%' readonly></td>
    <td class='tabledata'><input type='text' name='uom[]' id='uom' style='width:100%' readonly></td>
    <td class='tabledata'><input type='text' name='qty[]' id='qty' style='width:100%' ></td>
    <td class='tabledata'><input type='text' name='costlandprice[]' id='costlandprice' style='width:100%' ></td>
    <td class='tabledata'><input type='text' name='amount[]' id='amount' style='width:100%' onfocus='calamount(this)'></td>
  </tr>
   </tbody>   
</table>";
$data3='';
$data3.="<table width='100%' border='1' cellpadding='3' cellspacing='0' style='border-collapse:collapse; border:#666666 solid 1px;'>
  <tr>
    <td class='tabledata'><strong>Total Raw Material And Assembly Item Qty</strong></td>
    <td><input type='text' name='total_qty' id='total_qty' style='width:100%' onfocus='calqty(this);' value='".$row1['total_qty']."'  ></td>
    <td class='tabledata'><strong>Total Cost Landed Price</strong></td>
    <td><input type='text' name='landedprice' id='landedprice' style='width:100%' onfocus='caltotal1(".$i.");' value='".$row1['total_costland_price']."'  ></td>
  </tr>
</table>";

$data4='';
$data4.="<table width='100%' border=1' cellpadding='3' cellspacing='0' style='border-collapse:collapse; border:#666666 solid 1px;'>
  <tr>
    <td class='tabledata' colspan='4'>Add More Operational Cost</td>
  </tr>
  
  <tr>
    <td class='tabledata'>S. No.</td>
    <td class='tabledata'>Process</td>
    <td class='tabledata'>%</td>
    <td class='tabledata'>Amount</td>
  </tr>
  <tbody id='dataTable1'>";
  $sqlbomop=DB_query("select * from bom_process_operational  where bill_id='".$_REQUEST['bom1']."'",$db);
  while($sqlbomrow=DB_fetch_array($sqlbomop))
  {
  $data4.="<tr>
    <td class='tabledata'><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>";
       	$productrow=DB_query("select * from production_process_master",$db);
		while($product_row1=DB_fetch_array($productrow))
		{
		$k='';
		if($product_row1['id']==$sqlbomrow['process_name'])
		$k='selected';
			
			$data4.="<option value=".$product_row1['id']." ".$k.">".$product_row1['manuf_process_name']."</option>";
		
    	
    	 } 
    	
    $data4.="</select></td>";
    $data4.="<td><input type='text' name='procesper[]'  value='".$sqlbomrow['process_per']."'   id='procesper'/></td>
    <td><input type='text' name='procesamt[]' id='procesamt' value='".$sqlbomrow['process_amt']."'   onfocus='calpercentage(this);' /></td>
  </tr>";
  }
  $data4.="</tbody>

    	<tr><td class='tabledata1'><strong>Total Operational Cost</strong></td>
		<td colspan='3'><input type='text' name='procsstotal' value='".$row1['total_operation_cost']."' id='procsstotal' style='width:100%' onfocus='operationcost(this);'></td></tr>


</table>";

$data5='';
$data5="<table width='100%' border='1' cellpadding='3' cellspacing='0' style='border-collapse:collapse; border:#666666 solid 1px;'>
  <tr>
    <td class='tabledata' colspan='4'>Add More  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>
  </tr>
   <tbody id='dataTable2'>";
   $sqloverhead=DB_query("select * from bill_other_overhead  where bill_id='".$_REQUEST['bom1']."'",$db);
   while($sqlrowov=DB_fetch_array($sqloverhead))
   {
   
  $data5.="<tr>
    <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>";
    	      	
    	$productrow=DB_query("select * from production_process_master",$db);
		while($product_row1=DB_fetch_array($productrow))
		{
		$t='';
		if($product_row1['id']==$sqlrowov['overhead_process'])
		$t='selected';
			
			$data5.="<option value=".$product_row1['id']." ".$t.">".$product_row1['manuf_process_name']."</option>";
		
    	
    	 }
    	
   $data5.="</select>    	
    	 </td>
    <td><input type='text' name='procesoverper[]' value='".$sqlrowov['overhead_per']."'    id='procesoverper' /></td>
    <td><input type='text' name='procesoveram[]' id='procesoveram' value='".$sqlrowov['overhead_cost']."'   onfocus='caloverpercentage(this)'/></td>
  </tr>";
  }
  $data5.="</tbody><tr>
    	  <td class='tabledata1'><strong>Total Overhead Cost</strong></td>
    	  <td colspan='3'><input type='text' name='overheadcost' id='overheadcost' value='".$row1['total_overheadcost']."' style='width:100%' onfocus='overheadcostcal(this);'></td></tr></table>";
	
	$data6='';
	$data6="<table width='100%' border='1' cellpadding='3' cellspacing='0' style='border-collapse:collapse; border:#666666 solid 1px;'>
<tr>
<td class='tabledata' style='width:200px;'><strong>Total Production Rate Of Bill Of Material</strong></td>
<td><input type='text' name='totalamount' id='totalamount' value='".$row1['total_production_rate']."' style='width:100%' onfocus='totalamountcal(this);'></td>
</tr>
</table>";


echo $data=$data1."__".$data2."__".$data3."__".$data4."__".$data5."__".$data6;
}
?>

