<?php 
if(isset($_POST['save']))
{

for($i=0;$i<$_REQUEST['count1'];$i++)
{
	$mst_usersid=$_REQUEST['mst_usersid'][$i];
	$target_value=$_REQUEST['target_amm'][$i];
	$date = date("Y");
	$date1 = date("Y")+1;
	$insert = "insert into crmsales_target set 
									mst_usersid='".$mst_usersid."',
									fin_year='".$date."-".$date1."',
									target='".$target_value."', 
									published_data='".date('Y-m-d')."',
									created_by='".$_SESSION['UserID']."',
									CompanyId='".$_SESSION['ACGCompanyId']."',
									month='".date("M")."'";
	$result_user_target = DB_query($insert,$db);
	
	
}
}
if(isset($_POST['GO']))
{
  $fin_year=$_REQUEST['fin_year'];
  $month=$_REQUEST['month'];
  $filter='';
  if($fin_year!='000')
   $filter[]="fin_year='".$fin_year."'";
   if($month!='000')
   $filter[]="month='".$month."'";
  
	if(count($filter)>0)
	{
	   $searchdata=implode(" and ", $filter);
 	 echo "select * from crmsales_target where  $searchdata";
		$sql=DB_query("select * from crmsales_target where $searchdata",$db);
	}
}
?>

<div style="width:800px; margin-left:auto; margin-right:auto;">
<fieldset>
<legend>Users Target V/S Achievement</legend>
<!-- Start Table 1 --><div>
<form name="searchform" method="post" action="">
<table width="80%" border="0" cellspacing="1" cellpadding="2" align="left">
  <tr bgcolor="#e7e7e7">
  <?php ?>
    <th>Financial year</th>
    <td><select name="fin_year" style="width:150px;">
	<option value="000">Select</option>
	<option value="2012-2013">2012-2013</option>
	</select></td>
    <th>Month</th>
    <td><select name="month" style="width:150px;">
	<option value="000">Select</option>
	<option value="jan">January</option>
	<option value="feb">February</option>
	<option value="march">March</option>
	<option value="apr">April</option>
	<option value="may">May</option>
	<option value="jun">Jume</option>
	<option value="jul">July</option>
	<option value="aug">August</option>
	<option value="sept">September</option>
	<option value="oct">Octoober</option>
	<option value="nov">November</option>
	<option value="dec">December</option>
	</select></td>

  </tr>
  <tr bgcolor="#e7e7e7">
    <th>Start date</th>
    <td><input name="st" type="text" style="width:150px;" class="datepicker" /></td>
    <th>End date</th>
    <td><input name="st" type="text"  style="width:150px;" class="datepicker" /></td>
  </tr>
  <tr>
    <td colspan="3" style="padding-left:150px;"><center>
	<input type="submit" value="GO"  name="GO" class="bottonsview"  style="-moz-border-radius:10px; -webkit-border-radius:10px; "/></center></td>
	<td>&nbsp;</td>

  </tr>
</table>
</form>
</div><!-- Close Table 1 -->
<div style="clear:both;"></div>
<!-- Start Table 1 --><div>
<form name="users_targetform" method="post" action="">
<table width="80%" border="0" cellspacing="1" cellpadding="2" align="left">
  <tr>
    <th><center>User Name</center></th>
    <th><center>Target amount</center></th>
    <th><center>Target Achieved</center></th>
    <th><center>Difference</center></th>
  </tr>
  <?php 
  $i=0;
  $query_target = DB_query("select id,userid,realname from www_users where realname!='Admin' and companyid='".$_SESSION['ACGCompanyId']."'",$db);
  while($target_fetch_array=DB_fetch_array($query_target)) {?>
  <tr bgcolor="#e7e7e7">
    <td>
		<input name="mst_usersid[<?php echo $i; ?>]" readonly type="hidden" value="<?php echo $target_fetch_array['id']; ?>" />
	
	<input name="user_name[<?php echo $i; ?>]" readonly type="text" value="<?php echo $target_fetch_array['realname']; ?>" /></td>
    <td><input name="target_amm[<?php echo $i; ?>]" type="text" style=" width:150px;" /></td>
    <td><center>60000</center></td>
    <td><center>+10000</center></td>
  </tr>
  <?php $i++; } ?>
  <input type="hidden" name="count1" value="<?php echo $i; ?>" />
  <tr>
    <td colspan="3" style="padding-left:100px;"><center><input name="save" type="submit" value="Save" class="bottonsview"  style="-moz-border-radius:10px; -webkit-border-radius:10px; "/></center></td>
	<td>&nbsp;</td>

  </tr>
</table>
</form>


</div><!-- Close Table 1 -->





</fieldset>

</div>