<?php
session_name('CAKEPHP'); session_start();

ob_start();
$PageSecurity = 1;
include('config.php');
//include('includes/ConnectDB.inc');
//include('includes/function_lib.php');
//include('includes/LanguageSetup.php');
//include('includes/DateFunctions.inc');
$Compamies=DB_query("select * from companies",$db);
$CompamiesRow=DB_fetch_array($Compamies);
?>
<link href="css/purchses1.css" rel="stylesheet" type="text/css" />

<div style="color:#006699; font-size:16px; font-weight:900; padding:10px; text-align:center;"><?php echo $CompamiesRow['CompanyName']?> <br />
Activity Defintion
</div>
	<div align="center"><strong><?php echo $_SESSION['mess']; ?></strong> </div>
	
	<body>
<div id="page">
		
  <div id="form">
	<p id="foo" align="right" style="padding-right:10px;"> <a href="#" id="fis" onClick="javascript:toggle_visibility('foo');" >Print</a> </p>

<?php 
echo $_REQUEST['boqIDD'];

$DOCsql=DB_query("SELECT * FROM boq_entry WHERE id='".$_REQUEST['boqIDD']."' and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
if(DB_num_rows($DOCsql)>0){
$i=0;
	  $Doc=DB_fetch_array($DOCsql);
	  extract($Doc);
  ?>
<h1>BOQ Template Entry</h1>
<!-- Body Content Start -->

<div id="body_content">
	<!-- TAble 1 Start --><div style="overflow:auto; margin-left:auto; margin-right:auto;" width="100%">
	
	<table width="100%" border="1" cellspacing="0" cellpadding="3" class="">
	<input type="text" name="boq_id" value="<?php echo $_REQUEST['boqIDD']; ?>">
	<input type="text" name="so_id" value="<?php echo $salesorder_id; ?>">
	<input type="text" name="boqno" value="<?php echo $boq_no; ?>">
   		<td class="label">Branch</td>
   		<td><input type="text" name="branch" value="<?php echo $s->GetfieldValue('salesorder',"id='".$salesorder_id."'",'branch'); ?>"></td>
    	<td class="label" >BOQ No</td>
	 	<td ><input type="text" name="boq_no" value="will be auto generated" readonly /></td>
	 	<td class="label">Date</td>
		<td><input name="boq_date" type="text" value="<?php echo ConvertSQLDate($project_date); ?>"  class="datepicker"/></td>
	</tr>
	
	<tr>
		 <td class="label">Order No</td>
		 <td><input type="text" name="order_no" value="<?php echo $s->GetfieldValue('salesorder',"id='".$salesorder_id."'",'orderNo'); ?>" readonly/></td>
		 <td class="label">Order Date</td>
		 <td><input type="text" name="order_date" value="<?php echo ConvertSQLDate($s->GetfieldValue('salesorder',"id='".$salesorder_id."'",'orderDate')); ?>" readonly/></td>
		 <td class="label">Client Name</td>
		 <td><input type="text" name="boq_client" readonly value="<?php $c_id = $s->GetfieldValue('salesorder',"id='".$salesorder_id."'",'client');
		 echo $s->GetfieldValue('clientmaster',"id='".$c_id."'",'c_name');?>"></td>
	</tr>
	<tr> 
		 <td class="label">PO No</td>
		 <td><input type="text" name="po_no"  value="<?php echo $s->GetfieldValue('salesorder',"id='".$salesorder_id."'",'PORefNo'); ?>" readonly /></td>
		 <td class="label">PO Date</td>
		 <td><input type="text" name="po_date" value="<?php echo ConvertSQLDate($s->GetfieldValue('salesorder',"id='".$salesorder_id."'",'customerPODate')); ?>" readonly/></td>
		 <td class="label">Handled By</td>
		 <td><input type="text" name="handeled_by" value="<?php echo $project_handeled_by; ?>" ></td>
  </tr>
</table>
	</div>
	<br />
<!-- TAble 2 Start -->
<!-- TAble 2 Close -->
</div><!-- Body Content Close -->

<table border="1" width="100%" cellpadding="2" cellspacing="4">
<?php 
	 $query = "SELECT * from boq_entry_details WHERE master_id='".$id."' group by master_id";
	$res = DB_query($query,$db) or die(DB_error());
	$m=0;
	while($result = DB_fetch_array($res)){
	 $x = $result['itemCode'];
	?>
	<tr class="rowdata">
	<td class="label">Item Name</td>
	<td><input type="hidden" name="itemCode[]" value="<?php echo $result['itemCode']; ?>"/><?php echo $s->GetFieldVAlue('item_master',"id='".$result['itemCode']."'",'item_name'); ?></td>
	</tr>
	<tr class="rowdata">
	<td class="label">Activity Group</td>
	<td class="label">Activity Name</td>
	<td class="label">Description</td>
	<td class="label">Unit</td>
	<td class="label">Rate</td>
	<td class="label">Quantity</td>
	<td class="label">Amount</td>
	<td class="label">Start Date</td>
	<td class="label">End Date</td>
	<td class="label">Remark</td>
	<td class="label">Delete</td>
</tr>
	<input type="hidden" name="mst_id[]" value="<?php echo $result['master_id']; ?>"/>
	<input type="hidden" name="so_det_id[]" value="<?php echo $result['salesorder_id']; ?>"/>
	<?php
	 $Subcat=$s->GetFieldVAlue('item_master',"id='".$result['itemCode']."'",'SubCategoryID');
	$sqlactivityGroup=DB_query("select * from sub_activity_defination where inventory_group_id='".$Subcat."'",$db);
	while($AcGroup=DB_fetch_array($sqlactivityGroup)){
	$m++;
	?>
	<input type="hidden" name="noOfRows[]" value="<?php echo $m; ?>"/>
	<input type="hidden" name="so_det_id[]" value="<?php echo $result['id']; ?>"/>
	<input type="hidden" name="act_group[]" value="<?php echo $s->GetFieldValue('sub_activity_group',"id='".$AcGroup['group_name']."'",'group_name'); ?>"/>
	<input type="hidden" name="act_name[]" value="<?php echo $AcGroup['activity_name']; ?>"/>
		<tr class="rowdata">
			<td height="61"><?php echo $s->GetFieldValue('sub_activity_group',"id='".$AcGroup['group_name']."'",'group_name'); ?></td>
			<td><?php echo $AcGroup['activity_name']; ?></td>
			<td><textarea id="description<?php echo $m;?>" name="description[]"><?php echo $result['work_description']; ?></textarea></td>
			<td ><input type="text" name="act_unit[]" value="<?php echo $s->GetFieldValue('unitsofmeasure',"unitid='".$AcGroup['unit']."'",'unitname'); ?>" readonly style="width:80px;height:50px;"/></td>
			<td><input type="text" name="act_rate[]" id="act_rate_<?php echo $m; ?>" value="<?php echo $AcGroup['rate']; ?>" readonly style="width:80px;height:50px;"/></td>
			<td><input type="text" name="ActQuantity[]" onchange="get_amount('<?php echo $m;?>');" value="<?php echo $result['quantity']; ?>" id="ActQuantity_<?php echo $m; ?>" style="width:80px;height:50px;" class="validate"/></td>
			<td><input type="text" name="ActAmount[]" id="ActAmount_<?php echo $m; ?>" value="<?php echo $result['amount']; ?>" readonly style="width:80px;height:50px;" /></td>
			<td><input name="fromdate1[]" value="<?php echo ConvertSQLDate($result['startdate']); ?>" type="text"  class="datepicker" style="width:80px;height:50px;" /></td>
			<td><input name="enddate1[]" value="<?php echo ConvertSQLDate($result['enddate']); ?>" type="text"  class="datepicker" style="width:80px;height:50px;"/></td>
			<td><textarea id="act_r_<?php echo $m; ?>" name="text[]"><?php echo $result['remarks']; ?></textarea></td>
			<td><a href="index.php?route=PMS/Transcations/boq_templates_entry<?php echo $rurl;?>&action=delete&opn=<?php echo $id; ?>" onclick="return confirm('Are you sure you want to delete?')"> <img src="images/Icon_Delete.png" /></a></td>
		</tr>
		<?php }  ?>
<?php } ?>
<tr>
	<td colspan="5"></td>
	<td colspan="1" style="text-align:center;">Total Project Amount</td>
	<td colspan="1" style="text-align:center;"><input type = "text" name= "total_amount" id="total_amount"  /
	 /> </td>
	 <td></td>
  </tr>
  <tr>
  <td colspan="8"></td>
  <td> Prepared By </td>
  <td><?php
   echo $s->GetFieldValue('www_users',"id='".$_SESSION['UserID']."'",'userid'); ?></td>
  </tr>
<tr> 
	<td colspan="13" style="text-align:center;">
	<input type="submit" name="savedata" value="save" class="search" onClick="return validates()"></td>
</tr>

</table>
<?php } 
?>
 
</div>
</div>
