<?php   
session_name('CAKEPHP'); session_start();
$PageSecurity =4;
include('includes/session.inc');
include('includes/function_lib.php');
global $db; 

$size1=explode(",",$_REQUEST['estimationid']);

for($t=0;$t<count($size1);$t++)
{
   if($size1[$t]!='')
   	$item_array1[]=$size1[$t];
	
}
if(!empty($item_array1))
$item_array=implode("','",$item_array1);
else
$item_array='';
$SQLEst=DB_query("SELECT * FROM cstest_estimation_bom_details where master_id='".$_REQUEST['estid']."'",$db);

$data2="";   
$data2.="<table id='deleterrw' width='100%' border='1' cellpadding='3' cellspacing='0'>";
$data2.="</tr>";
$data2.="<tr class='row1'>";
$data2.="<td class='tabledata'>Sr. No.</td>";
$data2.="<td class='tabledata'>&nbsp;</td>";
$data2.="<td class='tabledata'>Item Code</td>";
$data2.="<td class='tabledata'>Item Name</td>";
$data2.="<td class='tabledata'>Size</td>";
$data2.="<td colspan='7' style='text-align:center' class='tabledata'>Qty.</td>";
$data2.="<td class='tabledata'>Price</td>";
$data2.="<td class='tabledata'>Per Unit</td>";
$data2.="<td class='tabledata'>Value</td>";
$data2.="<td class='tabledata'>Discount Type</td>";
$data2.="<td class='tabledata'>Discount Per</td>";
$data2.="<td class='tabledata'>Discount Price</td>";
$data2.="<td class='tabledata'>Value After Discount</td>";
$data2.="</tr>";
$i=0; 
while($GetEsti=DB_fetch_array($SQLEst))
{


				
$SqlHRdQty=DB_query("SELECT * FROM cstest_estimation_bom_details_asmbly where mst_itemid='".$GetEsti['mst_itemid']."' and details_mst_id='".$GetEsti['id']."'
                and id not in('".$item_array."')  ",$db);
$arr='';
$amt=0;
$itemid1='';
$arr_amt='';
while($hrdQty=DB_fetch_array($SqlHRdQty))
{
	$arr[]=$hrdQty['asmbly_item_qty'];
	//$amt=$amt+$hrdQty['asmbly_item_amt'];
	$arr_amt[]=$hrdQty['asmbly_item_amt'];	
}

//print_r($arr);
//foreach($item_array1 as $key=>$v)
//   {
////echo $item_array[$t1]['id'];
//
//$SqlHRdQty1=DB_query("SELECT * FROM cstest_estimation_bom_details_asmbly where mst_itemid='".$GetEsti['mst_itemid']."' and details_mst_id='".$GetEsti['id']."'
//            and id='".$v['id']."'    ",$db);
//
//$hrdQty1=DB_fetch_array($SqlHRdQty1);
//
//	$amt=$amt-$hrdQty1['asmbly_item_amt'];	
//}


 $amt=array_sum($arr_amt);

$sql_item=DB_query("select * from item_master where id='".$GetEsti['mst_itemid']."'",$db);
while($sql_item1=DB_fetch_array($sql_item))
{
$itemid1[]=$sql_item1['mst_unitid'];
$itemid1[]=$sql_item1['conv_unit'];

}
 $unitid=implode("','",$itemid1);
$qtyhrd=implode(",",$arr);
//echo $qtyhrd;
$item_Codeas=$s->GetFieldValue('item_master',"id='".$GetEsti['mst_itemid']."'",'StockID');
$item_names=$s->GetFieldValue('item_master',"id='".$GetEsti['mst_itemid']."'",'item_name');
 $unit=$s->GetFieldValue('item_master',"id='".$GetEsti['mst_itemid']."'",'mst_unitid');
 $conv_unit=$s->GetFieldValue('item_master',"id='".$GetEsti['mst_itemid']."'",'conv_unit');
 $confac=$s->GetFieldValue('item_master',"id='".$GetEsti['mst_itemid']."'",'conv_factor');

$data2.="<tr class='row1' id='hide_".$i."'>";
$data2.="<td style='white-space:nowrap;' class='tabledata'><div id='deactive_".$i."' style='display:block;'>
		<a href='#'   onclick='deactivate(".$i.")'><img src='images/delete1.gif' /></a>
		</div></td>";
$data2.="<td class='tabledata'><input type='hidden' name='item_code[]' id='itemid1_".$i."' value='".$GetEsti['mst_itemid']."' /><input type='hidden' id='hrdqty1A_".$i."' value='".$qtyhrd."'></td>";
$data2.="<td class='tabledata'>".$item_Codeas."</td>";
$data2.="<td class='tabledata' style='white-space:nowrap'>".$item_names."</td>";
$data2.="<td class='tabledata' style'white_space:nowrap'>";
$data2.="<select style='width:100px;' name='size[]' id='size'>";
$data2.="<option>--Select--</option>";
$SQLSize=DB_query("SELECT * FROM size_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
	while($sizeid=DB_fetch_array($SQLSize)){
	$selsize='';
	if($GetEsti['item_size']==$sizeid['id'])
	$selsize='selected';
$data2.="<option value='".$sizeid['id']."' ".$selsize.">".$sizeid['size']."</option>";
}
$data2.="</select>";
$data2.="</td>";





$data2.="<td class='tabledata'><input name='qtytype[".$i."]' type='radio' id='qtyprim_".$i."' value='".$GetEsti['item_prim_qty']."'  onclick='showqty2(this.id)' checked='checked' /></td>";
$data2.="<td class='tabledata'>".$s->getField('unitsofmeasure','unitid',$unit,'unitname')."</td>";

$data2.="<td class='tabledata'><input type='text' name='stock_qty[]'  id='stockqty_".$i."' style='width:50px;' onkeyup='calcValue1(this.value,this.id)' value='".$GetEsti['item_prim_qty']."'  /></td>";
$data2.="<td class='tabledata'><input name='qtytype[".$i."]' type='radio' value='".$GetEsti['item_sec_qty']."' id='qtysec_".$i."' onclick='showqty4(this.id)' /></td>";
$data2.="<td class='tabledata'>".$s->getField('unitsofmeasure','unitid',$conv_unit,'unitname')."</td>";
$data2.="<td class='tabledata'><input type='text' name='secondary_qty[]'  id='secondary_".$i."' style='width:50px;' onkeyup='calcValue1(this.value,this.id)' value='".$GetEsti['item_sec_qty']."'  /></td>";
$data2.="<td class='tabledata'><input type='hidden' name='convfac[]'  id='confac_".$i."' style='width:50px;' value='".$confac."'  /></td>";
$data2.="<td class='tabledata'><input type='text' name='stock_price[]' value='".$amt."'  id='stock_price_".$i."' style='width:50px;'/></td>";
$data2.="<td class='tabledata'><input type='text' name='stock_perunit[]' onfocus='filldefaultAmt(this.value,this.id)' id='stock_perunit_".$i."' style='width:30px;' value='1' /></td>";
$total_amt=round(($GetEsti['item_prim_qty']*$amt)/1,3);

$data2.="<td class='tabledata'><input type='text' name='stock_value[]'  id='stock_value_".$i."' style='width:60px;' onfocus='CalculateTotalLeadAmt(this.value,this.id)' value='".$total_amt."'/></td>";
$data2.="<td class='tabledata'>";
$data2.="<select style='width:80px;' name='PerAmo[]' id='PerAmo_".$i."'>"; 
$data2.="<option value='Amount' >Amount</option>";  
$data2.="<option value='PercentAmt'>Percent Amt</option>";  
$data2.="</select>";   
$data2.="</td>"; 
$totalvalueamt=$total_amt;

$data2.="<td class='tabledata'><input type='text' style='width:50px;' name='Discount[]' id='Discount_".$i."' onkeyup='DiscountAmount1(this.value,this.id)' value='0'
 /></td>";
$data2.="<td class='tabledata'><input type='text' style='width:50px;' name='perc[]' id='perc_".$i."'  readonly='true' value='0'  /></td>";
$data2.="<td class='tabledata'><input type='text' style='width:70px;' name='value_dis[]' id='value_dis_".$i."'  readonly='true' value='".$totalvalueamt."'  /></td>";
$data2.="</tr>";
$i++;} 






$data2.="</table>";
$data2.="<input type='hidden' name='count1' id='count1' value='".$i."'>";


$data3="";
$data3.="";
$data3.="
<input type='hidden' name='hrdcount1' id='hrdcount1' value='".$z."'>";




echo $data2;

