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



$SQLparant=DB_query("select * from estimation_sheet where id='".$_REQUEST['estimationid']."'",$db);

$typeAS=DB_fetch_array($SQLparant);

$data1="";
$data1.="<select name='type' id='type' style='width:150px;'>";
$data1.="<option value=''>Select</option>";
$TypetSQL=DB_query("SELECT * FROM type_master",$db); 
while($Type=DB_fetch_array($TypetSQL)){
$selty='';
if($Type['id']==$typeAS['id'])
$selty='selected';
$data1.="<option value='".$Type['id']."' ".$selty.">".$Type['name']."</option>";
 }
$data1.="</select>";





$SQLEst=DB_query("SELECT * FROM estimation_sheet_details where parant_id='".$_REQUEST['estimationid']."'",$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 class='tabledata'>Grade</td>";
$data2.="<td 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.="<td class='tabledata'>Total Stock</td>";
$data2.="</tr>";


$i=0; 

while($GetEsti=DB_fetch_array($SQLEst)){
$SqlHRdQty=DB_query("SELECT * FROM estimation_hardware_part where mst_itemid='".$GetEsti['id']."' and mst_parantid='".$_REQUEST['estimationid']."'",$db);
$arr='';
while($hrdQty=DB_fetch_array($SqlHRdQty))
{
	$arr[]=$hrdQty['hbqty'];
}
//echo "<pre>";
//print_r($arr);
$qtyhrd=implode(",",$arr);
//echo $qtyhrd;
$item_Codeas=$s->GetFieldValue('item_master',"id='".$GetEsti['prod_id']."'",'StockID');
$item_names=$s->GetFieldValue('item_master',"id='".$GetEsti['prod_id']."'",'item_name');

$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['prod_id']."' /><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['size_id']==$sizeid['id'])
	$selsize='selected';
$data2.="<option value='".$sizeid['id']."' ".$selsize.">".$sizeid['size']."</option>";
}
$data2.="</select>";
$data2.="</td>";
$data2.="<td class='tabledata' style='white-space:nowrap'>";
$data2.="<select style='width:100px;' name='grade[]' id='grade'>";
$data2.="<option>--Select--</option>";
$SQLgrade=DB_query("SELECT * FROM product_grade",$db); 
		while($gradeid=DB_fetch_array($SQLgrade)){
$data2.="<option value='".$gradeid['id']."'>".$gradeid['grade']."</option>";
}
$data2.="</select>";
$data2.="</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['wqty']."'  /></td>";
$data2.="<td class='tabledata'><input type='text' name='stock_price[]'  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>";
$data2.="<td class='tabledata'><input type='text' name='stock_value[]'  id='stock_value_".$i."' style='width:60px;' onfocus='CalculateTotalLeadAmt(this.value,this.id)'/></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>";
$data2.="<td class='tabledata'><input type='text' style='width:50px;' name='Discount[]' id='Discount_".$i."' onkeyup='DiscountAmount1(this.value,this.id)' /></td>";
$data2.="<td class='tabledata'><input type='text' style='width:50px;' name='perc[]' id='perc_".$i."'  readonly='true'  /></td>";
$data2.="<td class='tabledata'><input type='text' style='width:70px;' name='value_dis[]' id='value_dis_".$i."'  readonly='true'  /></td>";
$data2.="<td class='tabledata'><input type='text' name='total_stock[]' id='total_stock1_".$i."' style='width:50px;'   readonly='true' /></td>";
$data2.="</tr>";
$i++;} 



//$data2.="<tbody id='dataTable'>";
//$data2.="<tr class='row1'>";
//$data2.="<td style='white-space:nowrap;' class='tabledata'><input name='delitem[]' type='checkbox' value='' /></td>";
//$data2.="<td class='tabledata'><input type='hidden' name='item_code[]' id='itemid' value='' /></td>";
//$data2.="<td class='tabledata'><input type='text' name='' id='itemcode' value='' style='width:60px;' /></td>";
//$data2.="<td class='tabledata' style='white-space:nowrap'><input type='text' style='width:90px;' name='item_name[]' id='itemname' value='' /></td>";
//$data2.="<td class='tabledata' style='white-space:nowrap'><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)){
//$data2.="<option value='".$sizeid['id']."'>".$sizeid['size']."</option>";
// }
//$data2.="<td class='tabledata' style='white-space:nowrap'>";
//$data2.="<select style='width:100px;' name='grade[]' id='grade'>";
//$data2.="<option>--Select--</option>";
//$SQLgrade=DB_query("SELECT * FROM product_grade",$db); 
//while($gradeid=DB_fetch_array($SQLgrade)){
//$data2.="<option value='".$gradeid['id']."'>".$gradeid['grade']."</option>";
//}
//$data2.="<td class='tabledata'><input type='text' name='stock_qty[]'  id='stockqty' style='width:50px;' onkeyup='calcValue1(this.value,this.id)'  /></td>";
//$data2.="<td class='tabledata'><input type='text' name='stock_price[]'  id='stock_price' style='width:50px;'/></td>";
//$data2.="<td class='tabledata'><input type='text' name='stock_perunit[]' onfocus='filldefaultAmt(this.value,this.id)' id='stock_perunit' style='width:30px;' value='1' /></td>";
//$data2.="<td class='tabledata'><input type='text' name='stock_value[]'  id='stock_value' style='width:60px;' onfocus='CalculateTotalLeadAmt(this.value,this.id)'/></td>";
//$data2.="<td class='tabledata'><select style='width:80px;' name='PerAmo[]' id='PerAmo' >";
//$data2.="<option value='Amount' >Amount</option>";
//$data2.="<option value='PercentAmt'>Percent Amt</option>";
//$data2.="</select>";
//$data2.="</td>";
//$data2.="<td class='tabledata'><input type='text' style='width:50px;' name='Discount[]' id='Discount' onkeyup='DiscountAmount1(this.value,this.id)' /></td>";
//$data2.="<td class='tabledata'><input type='text' style='width:50px;' name='perc[]' id='perc'  readonly='true'  /></td>";
//$data2.="<td class='tabledata'><input type='text' style='width:70px;' name='value_dis[]' id='value_dis'  readonly='true'  /></td>";
//$data2.="<td class='tabledata'><input type='text' name='total_stock[]' id='total_stock' style='width:50px;'   readonly='true' /></td>";
//$data2.="</tr>";
//$data2.="</tbody>";





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


$data3="";
$data3.="<table  width='100%' border='1' cellpadding='3' cellspacing='0'>";
$data3.="<tr class='row1'>";
$data3.="<td class='tabledata1' colspan='13'><strong>Hardware Part</strong></td>";
$data3.="</tr>";
$data3.="<tr class='row1'>";
$data3.="<td class='tabledata'>Sr. No.</td>";
$data3.="<td class='tabledata'>&nbsp;</td>";
$data3.="<td class='tabledata'>Item Code</td>";
$data3.="<td class='tabledata'>Item Name</td>";
$data3.="<td class='tabledata'>Qty.</td>";
$data3.="<td class='tabledata'>Price</td>";
$data3.="<td class='tabledata'>Per Unit</td>";
$data3.="<td class='tabledata'>Value</td>";
$data3.="<td class='tabledata'>Discount Type</td>";
$data3.="<td class='tabledata'>Discount Per</td>";
$data3.="<td class='tabledata'>Discount Price</td>";
$data3.="<td class='tabledata'>Value After Discount</td>";
$data3.="<td class='tabledata'>Add</td>";
$data3.="</tr>";

$k=$i;
$z=0;
$SQLhrd=DB_query("SELECT manufac,fin_prod_id,hbbasic,SUM(hbqty) as hbtotalqty FROM estimation_hardware_part 
WHERE mst_parantid='".$_REQUEST['estimationid']."' GROUP BY manufac",$db);
while($GetHard=DB_fetch_array($SQLhrd)){

$HrdItemCode=$s->GetFieldValue('item_master',"id='".$GetHard['fin_prod_id']."'",'StockID');
$HrdItemName=$s->GetFieldValue('item_master',"id='".$GetHard['fin_prod_id']."'",'item_name');




$data3.="<tr class='row1' >";
$data3.="<td style='white-space:nowrap;' class='tabledata'><input name='delitem[]' type='checkbox' value='' /></td>";
$data3.="<td class='tabledata'>";
$data3.="<input type='hidden' name='hardwarepart[$z]' id='hardwarepart' value='".$GetHard['manufac']."' />";
$data3.="<input type='hidden' name='hrditemid[$z]' id='itemid' value='".$GetHard['fin_prod_id']."' /></td>";
$data3.="<td class='tabledata'>".$HrdItemCode."</td>";
$data3.="<td class='tabledata' style='white-space:nowrap'>".$HrdItemName."</td>";
$data3.="<td class='tabledata'><input type='text' name='hrd_qty[$z]'  id='hrdstock_qty2_".$z."' style='width:50px;' onkeyup='calcValue(this.value,".$z.")' value='".$GetHard['hbtotalqty']."'  /></td>";
$data3.="<td class='tabledata'><input type='text' name='hrd_price[$z]'  id='hrdstock_price1_".$z."' value='".$GetHard['hbbasic']."' style='width:50px;'/></td>";
$data3.="<td class='tabledata'><input type='text' name='hrd_perunit[$z]' onfocus='filldefaultAmt(this.value,this.id)' id='hrdstock_perunit1_".$z."' style='width:30px;' value='1' /></td>";
$data3.="<td class='tabledata'><input type='text' name='hrd_value[$z]'  id='hrdstock_value1_".$z."' style='width:60px;' onfocus='CalculateTotalLeadAmt2(this.value,".$z.")'/></td>";
$data3.="<td class='tabledata'>";
$data3.="<select style='width:80px;' name='hrdPerAmo[$z]' id='hrdPerAmo1_".$z."' >";
$data3.="<option value='Amount' >Amount</option>";
$data3.="<option value='PercentAmt'>Percent Amt</option>";
$data3.="</select>";
$data3.="</td>";
$data3.="<td class='tabledata'><input type='text' style='width:50px;' name='hrdDiscount[$z]' id='hrdDiscount1_".$z."' onkeyup='DiscountAmount2(this.value,".$z.")' /></td>";
$data3.="<td class='tabledata'><input type='text' style='width:50px;' name='hrdperc[$z]' id='hrdperc1_".$z."'  readonly='true'  /></td>";
$data3.="<td class='tabledata'><input type='text' style='width:70px;' name='hrdvalue_dis[$z]' id='hrdvalue_dis1_".$z."'  readonly='true'  /></td>";
$data3.="<td class='tabledata'><input type='checkbox' name='addhrdAmt[$z]' value='0' id='addhrdAmt_".$z."' onclick='addtotadhrdamt(".$z.")' /></td>";
$data3.="</tr>";
 $k++;$z++;} 


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




echo $data=$data1."__".$data2."__".$data3;