<?php 
//***************************MODIFY BY AMIT SINGH********04-12-2012*******************************************************
include('includes/Class_Client.php');
include('includes/Class_www_users.php');

include('functions.php');

$s=new db_query();
//GET Heirarchy from users wise
$deptid=  $s->GetFieldValue('www_users'," id='".$_SESSION['UserID']."' " ,'mst_dpt_heirarchy');
$r=GETUpperDeptUser($_SESSION['UserID'],$deptid,$_SESSION['ACGCompanyId']);
$userlist=  UserDeptList($r);
if(count($userlist)>0)
$userlist=implode(",",$userlist).",".$_SESSION['UserID'];
else
$userlist="'".$_SESSION['UserID']."'";

$LowerDeptList=GETLowerDeptUser($_SESSION['UserID'],$deptid,$_SESSION['ACGCompanyId']);

$lowerlist=  UserDeptList($LowerDeptList);
//echo "<br>--------222--------<br>";
//print_r($LowerDeptList);
if(count($lowerlist)>0)
$lowerlist=implode(",",$lowerlist).",".$_SESSION['UserID'];
else
$lowerlist="'".$_SESSION['UserID']."'";
$userlist;
 //	echo "<br>******************************userlist****************************************************<br>";
$user_id = $_SESSION['ACG_DashBoard_User'];?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php  echo $page_title?></h1>
<div id="slidingDiv">
<form action="" method="post">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
  	<td class="tabledata1">From :</td>
	<td><input type="text" name="From_date" style="width:150px;" value="<?php echo $_REQUEST['From_date']; ?>" class="datepicker" /></td>
 
	<td class="tabledata1">To :</td>
	<td><input type="text" name="To_date" style="width:150px;" value="<?php echo $_REQUEST['To_date']; ?>" class="datepicker" /></td>
</tr>
<tr class="row1"> 
	<td class="tabledata1">Wise :</td>
	<td><select name="wise" id="wise" style="width:150px;" onchange="ShowDiv(this.value,'report','CRMExecutivewiselist.php')">
	<option value="0">Select</option>
	<!--<option value="Period Wise"<?php //echo($_REQUEST['wise']=='Period Wise'?'selected':'') ?>>Period Wise</option>
	<option value="Client Wise"<?php //echo($_REQUEST['wise']=='Client Wise'?'selected':'') ?>>Client Wise</option>-->
	<option value="Executive Wise"<?php echo($_REQUEST['wise']=='Executive Wise'?'selected':'') ?>>Executive Wise</option>
	</select>
	</td>
	<td class="tabledata1">Executive</td>
	<td><div id="report">
	 <select name="Exec_name" style="width:150px;">
		<option value="">Select</option>
	</select></div>
	</td>
</tr>
<tr class="row1">
	<td colspan="4"><p align="center"><input type="submit" name="Search" value="Search" class="search" /></p></td>
</tr>
</table>


<?php  

if($_REQUEST['Search'])
	{
		$fromdate=ConvertSQLDate($_REQUEST['From_date']);
		$todate=ConvertSQLDate($_REQUEST['To_date']);
		$wise=$_REQUEST['wise'];
		$executiveName=$_REQUEST['Exec_name'];
		
		if($_REQUEST['From_date']!='' && $_REQUEST['To_date']!='' )
	{
		$filter[]="visit_date between '".$fromdate."' and '".$todate."'";
	}
	if($_REQUEST['wise']=='Client Wise')
		if($_REQUEST['Exec_name']!='')
		{
			$filter[]="client_id='".$executiveName."'";
		}
	if($_REQUEST['wise']=='Executive Wise')
	{
		if($_REQUEST['Exec_name']!='')
		{
			$filter[]="empid='".$executiveName."'";
		}
	}	
		if($filter!='')
	{
	$filter1=implode(" and ",$filter);
	}
	if($_REQUEST['wise']=='Executive Wise')
	{
	//echo "select * from crm_mst_daily_visit_entry where $filter1";
 $getdata=DB_query("select * from crm_mst_daily_visit_entry where $filter1",$db);
 $query1="select * from crm_mst_daily_visit_entry where $filter1";
 }
 else if($_REQUEST['wise']=='Client Wise')
 {
 	//echo "select * from crm_daily_visit_entry where $filter1";
 	$getdata=DB_query("select * from crm_daily_visit_entry where $filter1",$db);
	$query1="select * from crm_daily_visit_entry where $filter1";
 }
 $_SESSION['query']=$query1;
 
}
unset($_SESSION['visited_area']);
?>
<div style="clear:both;"></div>
</form>
</div>



<h1><?php if($_REQUEST['wise']!=''){ echo '('.$_REQUEST['wise'].')';}?></h1>

<?php 
if($_REQUEST['wise']=='Executive Wise') { ?>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr>
	<td align="left" width="50%">
		<table width="100%" border="0" cellspacing="0" cellpadding="3">
  		<tr class="row1">
        	<td class="tabledata1">Name</td>
    		<td>
			<?php echo 	strtoupper($s->GetFieldValue('empmaster',"mst_www_userid in(".$_REQUEST['Exec_name'].")",'emp_name'));?>
			</td>
  		</tr>
  		<tr class="row1">
    		<td class="tabledata1">Designation</td>
    		<td><?php $Dept_code=$s->GetFieldValue('empmaster',"mst_www_userid in(".$_REQUEST['Exec_name'].")",'designation');
					  echo $s->GetFieldValue('desigmaster',"id='".$Dept_code."'",'designame');?>
			</td>
 		</tr>
		</table>
	</td>
	<td align="right" width="50%">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr class="row1">
			<td class="tabledata1">Date From : <?php echo $_REQUEST['From_date']?></td>
			<td class="tabledata1"> To : <?php echo $_REQUEST['To_date']?></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Area visited</td>
		<td><?php 
		$Visited_SQL=DB_query("select distinct(visited_area) from crm_mst_daily_visit_entry where empid='".$_REQUEST['Exec_name']."'",$db);
		if(DB_num_rows($Visited_SQL)>1)
		{
		$Area=array();
		while($visitedArea=DB_fetch_array($Visited_SQL))
		{
		echo $visitedArea['visited_area'].", ";
		}
		}
		else
		{
		$visitedArea=DB_fetch_array($Visited_SQL);
		echo $visitedArea['visited_area'];
		}
		?></td>
		</tr>
		</table>
	</td>	
</tr>
</table>
<div>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td class="tabledata" rowspan="2">S.No.</td>
    <td class="tabledata" rowspan="2">Client</td>
    <td class="tabledata" rowspan="2">Cotact Officer<br />
      Tel. No.</td>
    <td class="tabledata" colspan="3"><center>RESPONCE</center></td>
    <td class="tabledata" rowspan="2">New<br />
      Client</td>
    <td class="tabledata" rowspan="2">Remarks By Executive</td>
     <td class="tabledata" rowspan="2">Comments By Superior</td>
  </tr>
<tr class="row1">
    <td class="tabledata">Quote</td>
    <td class="tabledata">Sample</td>
    <td class="tabledata">Call again</td>
    </tr>
<?php 
$i=1;
while($rowRecord=DB_fetch_array($getdata)){
	//echo "select *  from  crm_mst_daily_visit_entry A ,crm_daily_visit_entry B where A.id =B.mst_crm_entryid and A.id='".$rowRecord['id']."'";
$getquery1=DB_query( "select *  from  crm_mst_daily_visit_entry A ,crm_daily_visit_entry B where A.id =B.mst_crm_entryid and A.id='".$rowRecord['id']."'",$db);
while($row_lead=DB_fetch_array($getquery1)){?>
  <tr class="row1">
    <td style="padding-top:5px; padding-bottom:5px;"><?php echo $i++; ?></td>
    <td><?php echo $s->GetFieldValue('clientmaster',"id='".$row_lead['client_id']."'",'c_name'); ?></td>
    <td><?php echo $row_lead['ClientContact']; ?></td>
    <td><center><?php if($row_lead['quotes']==1){echo 'Y';} ?></center></td>
    <td><center><?php if($row_lead['sample']==1){echo 'Y';} ?></center></td>
    <td><center><?php if($row_lead['callagain']==1){echo 'Y';} ?></center></td>
    <td><?php echo $row_lead['newclient']; ?></td>
    <td><?php echo $row_lead['remark']; ?></td>
     <td><?php echo $row_lead['comment']; ?></td>
	</tr>
	<?php  } } ?>
</table>
<div align="center"><a href="#" onclick="popup('daily_report-print.php?wise=<?php echo $_REQUEST['wise'];?>&search=<?php echo $_REQUEST['Search'];?>&from=<?php  echo  $_REQUEST['From_date']; ?>&to=<?php echo $_REQUEST['To_date'] ;?>&exeid=<?php echo $_REQUEST['Exec_name']; ?>',1200,600)">Print</a></div>
<?php }
















 
else if($_REQUEST['wise']=='Client Wise'){ ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>Name</td>
    <td><?php 	echo 	strtoupper($s->GetFieldValue('clientmaster',"id='".$_REQUEST['Exec_name']."'",'c_name'));
	
	
	
	?></td>
  </tr>
</table>
</div>

<!-- left part --><div style="width:300px; float:right;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>Date From : <?php echo $_REQUEST['From_date']?></td>
    <td> To : <?php echo $_REQUEST['To_date']?></td>
  </tr>
</table>
</div>





<br />
<!--Table 1 Start here --><div>
<table width="100%" border="1" cellspacing="0" cellpadding="0" style="border-collapse:collapse; border:#000000 solid 1px;">
  <tr>
    <th rowspan="2">S.No.</th>
    <th rowspan="2">Executive Name</th>
    <th rowspan="2">Cotact Officer<br />
      Tel. No.</th>
    <th colspan="3"><center>RESPONCE</center></th>
    <th rowspan="2">New<br />
      Client</th>
     <th rowspan="2">Remarks By Executive </th>
     <th rowspan="2">Comments By Superior</th>
  </tr>
  <tr>
    <th>Quote</th>
    <th>Sample</th>
    <th>Call again</th>
    </tr>
<?php 
$i=1;
	while($rowRecord1=DB_fetch_array($getdata))
	{
	//echo "select *  from  crm_mst_daily_visit_entry A ,crm_daily_visit_entry B where A.id =B.mst_crm_entryid and B.id='".$rowRecord1['id']."'";
	 $getquery2=DB_query( "select *  from  crm_mst_daily_visit_entry A ,crm_daily_visit_entry B where A.id =B.mst_crm_entryid and B.id='".$rowRecord1['id']."'",$db);
	
while($row_lead3=DB_fetch_array($getquery2))
{

?>
  <tr bgcolor="#e7e7e7">
    <td style="padding-top:5px; padding-bottom:5px;"><?php echo $i++; ?></td>
    <td><?php echo $s->GetFieldValue('empmaster',"mst_www_userid='".$row_lead3['empid']."'",'emp_name'); ?></td>
    <td><?php echo $row_lead3['ClientContact']; ?></td>
    <td><center><?php if($row_lead3['quotes']==1){echo 'Y';} ?></center></td>
    <td><center><?php if($row_lead3['sample']==1){echo 'Y';} ?></center></td>
    <td><center><?php if($row_lead3['callagain']==1){echo 'Y';} ?></center></td>
    <td><?php echo $row_lead3['newclient']; ?></td>
    <td><?php echo $row_lead3['remark']; ?></td>
    <td><?php echo $row_lead3['comment']; ?></td>
	</tr>
	<?php  } } ?>
</table>
<div align="center"><a href="#" onclick="popup('daily_report-print.php?wise=<?php echo $_REQUEST['wise'];?>&from=<?php  echo  $_REQUEST['From_date']; ?>&to=<?php echo $_REQUEST['To_date'] ;?>',1000,600)">Print</a></div>
<?php } ?>


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


</div>
</div>
</tr>
</fieldset>
</div>
 