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

	
$size1=explode(",",$_REQUEST['size']);
$itemarray=explode(",",$_REQUEST['itemarray']);	
$qtyarray=explode(",",$_REQUEST['qty']);
for($t=0;$t<count($size1);$t++)
{
	$item_array[$t]['id']=$size1[$t];
	$item_array[$t]['size']=$itemarray[$t];
	$item_array[$t]['qty']=$qtyarray[$t];
	
	
}


$tbodyid="'dataTable1'";
$hardwaretable='<p align="left"><input type="button" onclick="addRow1('.$tbodyid.')" value="Add More" id="addmore" class="search" /></p><table width="100%" cellpadding="2" cellspacing="2">
<tr class="row1">
  <td colspan="3" rowspan="2" class="tabledata"><strong>Assembly Details</strong></td>
<td  align="right" class="tabledata"><strong>Item </strong></td>';

foreach($item_array as $key=>$v)
   {

   $hardwaretable.='<td class="tabledata" colspan="2" style="font-size:11px;">'.$s->GetFieldValue('item_master',"id='".$v['id']."'",'item_name').'<input type="hidden" name="mst_itemidasmbly['.$key.']" value="'.$v['id'].'"/><input type="hidden" name="item_size['.$key.']" value="'.$v['size'].'" id="item_size_'.$key.'"/></td>';
  
   }
  $hardwaretable.='</tr><tr class="row1">
  	<td align="right" class="tabledata"><strong>Size </strong></td>';
	foreach($item_array as $key=>$v)
   {

 $hardwaretable.='<td class="tabledata" colspan="2" style="font-size:11px;">'.$s->GetFieldValue('size_master',"id='".$v['size']."'",'size').'</td>';
 } 	





$hardwaretable.='</tr>';








/////////////////////Assembly Items like frame and shutter///////////////////////////


$hardwaretable.='<tr class="row1">
<td class="tabledata"><strong>Assembly (Finished)</strong></td>
<td class="tabledata"><strong>Items</strong></td>
<td class="tabledata"><strong>Basic Rate</strong></td>
<td class="tabledata"><strong>UOM</strong></td>'; 
for($i=0; $i<count($item_array); $i++)
{
$hardwaretable.='<td class="tabledata"><strong>Qty</strong></td>
<td class="tabledata"><strong>Amt</strong></td>';
}
$hardwaretable.='</tr>';


$hardwaretable.='<tbody id="dataTable1"><tr class="row1">
<td>';
$maincatsql=DB_fetch_array(DB_query("Select id from stockmaincategory where stockmaincategoryid='FG' and CompanyId=".$_SESSION['ACGCompanyId'],$db));
$catsql=DB_query("Select * from stockcategory where stockmaincategory=".$maincatsql['id'],$db);
$hardwaretable.='<select name="itemsubcat[]" id="itemsubcat" onchange="getItemList(this.value,this.id)" style="width:120px">';
while($catrow=DB_fetch_array($catsql))
{
	$hardwaretable.='<option value="'.$catrow['id'].'">'.$catrow['categorydescription'].'</option>';	
}
$hardwaretable.='</select></td>
<td><select name="itemdata[]" id="item" onchange="itemBomDetails(this.value,this.id)">
<option value="">Select Item</option>
</select></td>
<td><input type="text" name="basicrateA[]" id="basicrateA" style="width:50px;" readonly /></td>
<td><input type="text" name="" id="uomA" style="width:50px;" readonly/></td>'; 
for($i=0; $i<count($item_array); $i++)
{
$hardwaretable.='<td><input type="text" name="asmbly_qty[0]['.$i.']" id="asmbly_item_qtyA_'.$i.'" value="" readonly  /></td>
				 <td><input type="text" name="asmbly_amt[0]['.$i.']" id="asmbly_item_amtA_'.$i.'" value="" readonly /></td>';
}
$hardwaretable.='<input type="hidden" value="'.$i.'" id="fassmblycnt" /></tr></tbody>';
$hardwaretable.='<tr class="row1"><td><b>Sub Total (A)</b></<td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>';
for($i=0; $i<count($item_array); $i++)
{
$hardwaretable.='<td>&nbsp;</td>
				 <td class="tabledata"><input type="text" name="total[]" id="totalA_'.$i.'" value="" readonly /></td>';
}
$hardwaretable.='<tr>';



//////////////////////////////////////////////////////////////


//onfocus="calculateAllAmt(this.id)"






//////////////////Hardware Items/////////////////////////////

$coun= count($item_array);
  $coun1=($coun*2)+4;

$hardwaretable.='<tr class="row1"><td class="tabledata" colspan='.$coun1.'><strong>Sub Assembly Details</strong></td></tr>';


$hardwaretable.='<tr class="row1">
<td class="tabledata"><strong>Sub Group</strong></td>
<td class="tabledata"><strong>Items</strong></td>
<td class="tabledata" colspan=2><strong>Basic Rate</strong></td>'; 
for($i=0; $i<count($item_array); $i++)
{
$hardwaretable.='<td class="tabledata"><strong>Qty</strong></td>
<td class="tabledata"><strong>Amt</strong></td>';
}
$hardwaretable.='</tr>';


$k=0;
$ProdManuSQL=DB_query("SELECT * FROM product_manufacture where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
while($prodManuf=DB_fetch_array($ProdManuSQL)){
  $hardwaretable.='<tr class="row1">
    <td>'.$prodManuf['manufacturer'].'<input type="hidden" name="mst_asmbly_cat_id['.$k.']" id="manufac" value="'.$prodManuf['id'].'" /></td>
    <td>';
	$GetItemsSQL=DB_query("select * from item_master where make='".$prodManuf['id']."' and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	$hardwaretable.='<select style="width:150px;" name="mst_asmbly_item_id['.$k.']" id="manufact_'.$k.'" onchange="showbascicamt(this.value,this.id)">
      <option value="">--Select--</option>';
	  while($GetItemsFors=DB_fetch_array($GetItemsSQL)){
	  $hardwaretable.='<option value="'.$GetItemsFors['id'].'">'.$GetItemsFors['item_name'].'</option>';
	  }
	 	  $hardwaretable.='</select></td>
	  <td ><input type="text" name="asmbly_basicrate['.$k.']" id="basicrate_'.$k.'" style="width:50px;" /></td>
	<td ><input type="text" name="" id="uomaT_'.$k.'" style="width:50px;" readonly 	/></td>';
	for($i=0; $i<count($item_array); $i++)
		{
		$hardwaretable.='<td><input type="text" name="asmbly_item_qty['.$k.']['.$i.']" id="asmbly_item_qty_'.$k.'_'.$i.'" value="" onkeyup="calcItemAmt1(this.value,'.$k.','.$i.')" onblur="calcItemAmt1(this.value,'.$k.','.$i.')"/></td>
							<td><input type="text" name="asmbly_item_amt['.$k.']['.$i.']" id="asmbly_item_amt_'.$k.'_'.$i.'" value="" readonly /></td>'; 	
		}
  $hardwaretable.='</tr>';
  $k++;
  }
  $hardwaretable.='<tr class="row1">
  <td><b>Sub Total (B)</b></td>
  <td></td>
  <td colspan=2></td>';
  for($i=0; $i<count($item_array); $i++)
  {
  		$hardwaretable.='<td></td>
						<td class="tabledata"><input type="text" name="" value="" id="total_hw_amt_id_'.$i.'" readonly /></td>';	
  }
  $hardwaretable.='</tr>';
  $hardwaretable.='<tr class="row1">
  <td colspan="2"><b>Total Amount(C=A+B)</b></td>
  <td colspan=2></td>';
  for($i=0; $i<count($item_array); $i++)
  {
  		$hardwaretable.='<td></td>
						<td class="tabledata"><input type="text" name="" value="" id="totalC_'.$i.'" readonly/></td>';	
  }
  $hardwaretable.='</tr>';
   $hardwaretable.='<tr class="row1">
  <td colspan="2"><b>Grand Total (D=C*Q)</b></td>
  <td colspan=2></td>';
 
  for($i=0; $i<count($item_array); $i++)
  {
  
   
  		$hardwaretable.='<td></td>
						<td class="tabledata"><input type="text" name="" value="" id="totalD_'.$i.'" readonly/>
						  <input type="hidden" name="totalqtyabc" id="totalqtyabc_'.$i.'" value="'.$item_array[$i][qty].'" >
						</td>';	
  }
  $hardwaretable.='</tr>';
  $hardwaretable.='<input type="hidden" id="count" value="'.$k.'" name="counthw" />

  </table>';
////////////////////////////////////////////////////////////////////////////////////////////////////	
	
	
	
	echo $hardwaretable;
	

?>