<?php 
if($_REQUEST['Delete'])
{
	for($i=0;$i<count($_REQUEST['leadid']);$i++)
	{
	$condition="mst_parantid='".$_REQUEST['leadid'][$i]."'";
	$s->DeleteRecord('estimation_hardware_part', $condition);
	
	$condition1="parant_id='".$_REQUEST['leadid'][$i]."'";
	$s->DeleteRecord('estimation_sheet_details', $condition1);
	
	$condition2="parant_id='".$_REQUEST['leadid'][$i]."'";
	$s->DeleteRecord('estimation_summary', $condition2);
	
	$condition3="id='".$_REQUEST['leadid'][$i]."'";
	$s->DeleteRecord('estimation_sheet', $condition3);
	}
	$s->pageLocation("index.php?route=CostEstimation/estimation_sheet_index".$rurl);
}



if($_REQUEST['Search'])
{
	if($_REQUEST['client']!='')
	{
		$filter[]="client='".$_REQUEST['client']."'";
	}
	
	if($_REQUEST['sheetno']!='')
	{
		$filter[]="id='".$_REQUEST['sheetno']."'";
	}
	if($_REQUEST['fromdate']!='' && $_REQUEST['todate']!='')
	{
		$filter[]="date between '".FormatDateForSQL($_REQUEST['fromdate'])."' and '".FormatDateForSQL($_REQUEST['todate'])."'";
	}
	if($filter!='')
	{
		$filter1=implode(" and ",$filter);
		$sql="select * from estimation_sheet where $filter1 order by id desc";
	}
}


else
{
$sql="select * from estimation_sheet order by id desc";
}
?>
 <script language="javascript" >
function LeadData()
{	
	myCheckboxArray = document.myform.elements["leadid[]"];
	var t=myCheckboxArray.length;
	//alert(myCheckboxArray);
	if(document.getElementById('leadid').checked==true)
	{	
	if(t==undefined)
	document.getElementById('leadid_'+1).checked=true;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=true;	
	}	
	}
	else
	{
	if(t==undefined)		
	document.getElementById('leadid_'+1).checked=false;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=false;	
	}
	}
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Estimation Sheet </h1>
<form method="post" name="myform">
<div class="centre" id="slidingDiv">

<table width="100%" cellpadding="3" cellspacing="0">
		<tr class="row1">
		<td class="tabledata1">Client</td>
		<td><select style="width:150px;"  name="client">
		<option value="0">Select Client</option>
		<?php
		  $ClientSQL="Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$ClientRes=DB_query($ClientSQL,$db);
		while($ClientRow=DB_fetch_array($ClientRes))
		{
 		?>
		<option value="<?php echo $ClientRow['id']?>" <?php echo ($_REQUEST['client']==$ClientRow['id']?'selected':'');?>><?php echo $ClientRow['c_name']?></option>
		<?php  } ?>
 	</select></td>
	
	<td  class="tabledata1">Sheet No</td>
	<td><select name="sheetno" id="sheetno" style="width:150px;">
			<option value="">Select</option>
			<?php $sheetSQL=DB_query("select * from estimation_sheet where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
			while($sheetnum=DB_fetch_array($sheetSQL)){?>
			<option value="<?php echo $sheetnum['id'] ?>"<?php echo ($_REQUEST['sheetno']==$sheetnum['id']?'selected':'');?>><?php echo $sheetnum['sheetno'] ?></option>
			<?php }?>
		</select>
	</td>
</tr>
   <tr class="row1">
   <td class="tabledata1">From</td>
   <td class="demo"><input type="text" name="fromdate" class="datepicker"  style="width:150px;" value="<?php echo $_REQUEST['fromdate'];?>"/></td>
   <td class="tabledata1">To</td>
   <td><input type="text" name="todate"  class="datepicker"  style="width:150px;"  value="<?php echo $_REQUEST['todate'];?>"/></td>
  </tr>
  
   <tr class="row1">
   <td colspan="4"><p align="center"><input type="submit" name="Search" value="Search" class="search"></p></td>
  </tr>
  <tr class="row1">
  	<td colspan="4"><p align="left">
	<a href="index.php?route=CostEstimation/calculation_sheet&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;frmid=<?php echo $_REQUEST['frmid'];?>&amp;NewRequisition=Yes"><input type="button" value="Add New" class="search" /></a>
	<input type="submit" name="Delete"  value="Delete" class="search" />
	</p>
</td>
  </tr>
</table>

</div>

<table width="100%" border="1" cellpadding="3" cellspacing="0">
  <tr>
  	<td class="tabledata"><input name="leadid" type="checkbox"   id="leadid" onclick="LeadData()"    /></td>
    <td class="tabledata">Sheet  No.</td>
    <td class="tabledata">Date</td>
	<td class="tabledata">Client</td>
    <td class="tabledata">Type</td>
    <td class="tabledata">Material Group</td>
    <td class="tabledata">Total Qty</td>
	<td class="tabledata">Total Area</td>
	<td class="tabledata">Total Project Value</td>
  </tr>
  <?php 
  $sql1=DB_query($sql,$db);
  $i=0;
  while($fetchArray=DB_fetch_array($sql1)) {
 
 $sumofqty=$s->GetFieldValue('estimation_sheet_details',"parant_id='".$fetchArray['id']."'",'SUM(wqty)');
 $TotalArea=$s->GetFieldValue('estimation_sheet_details',"parant_id='".$fetchArray['id']."'",'SUM(area)');
 $GrandTotal=$s->GetFieldValue('estimation_sheet_details',"parant_id='".$fetchArray['id']."'",'SUM(grandtotal)');
  
  ?>
<tr class="row1">
	<td style="white-space:nowrap;"><input name="leadid[]" type="checkbox" id="leadid_<?php echo $i+1; ?>"   value="<?php  echo $fetchArray['id']?>" />
	<!--<a href="index.php?route=CRM/dot_request_form&amp;action=Edit&amp;id=<?php echo $fetchArray['id']; ?>&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;frmid=<?php echo $_REQUEST['frmid'];?>"><img src="images/icon_edit.gif" width="12px"  height="12" /></a>
		<a href="index.php?route=CRM/dot_request_form&amp;action=View&amp;id=<?php echo $fetchArray['id']; ?>&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;frmid=<?php echo $_REQUEST['frmid'];?>"><img src="images/search.gif" width="12px"  height="12" /></a>-->
	</td>
    <td><?php echo $fetchArray['sheetno']; ?></td>
    <td><?php echo ConvertSQLDate($fetchArray['date']); ?></td>
    <td><?php echo $s->GetFieldValue('clientmaster',"id='".$fetchArray['client']."'",'c_name'); ?></td>
    <td><?php echo $s->GetFieldValue('type_master',"id='".$fetchArray['type']."'",'name'); ?></td>
    <td><?php echo $s->GetFieldValue('stockcategory',"id='".$fetchArray['material_group']."'",'categorydescription'); ?></td>
    <td><?php echo $sumofqty; ?></td>
	<td><?php echo $TotalArea; ?></td>
	<td><?php echo $GrandTotal; ?></td>
  </tr>
  <?php $i++;} ?>
</table>
</form>
</div>
</div>
