<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse;">
  <tr>
    <td class="tabledata">Executive Name</td>   
    <td class="tabledata">Sale Value</td>   
    <td class="tabledata">Executive Chart</td> 
  </tr>
  <?php

	if($_SESSION['AssignedBranch']!='0')
	  {	  	
  $ss1=" select distinct Sale_Key_Exec from salesorder where  branch in('".$_SESSION['AssignedBranch']."')   and Sale_Key_Exec!=0 order by Sale_Key_Exec ASC";
	  	 $site_sql1=DB_query($ss1,$db);
	  }
	  else
	  {
		$ss1="select distinct Sale_Key_Exec from salesorder where Sale_Key_Exec!=0 order by Sale_Key_Exec ASC";
		$site_sql1=DB_query($ss1,$db);
	  }
	  //echo $ss1;
 
  while($row=DB_fetch_array($site_sql1))
  {
  $grand=0;
 
 
  $row1=DB_query("select sum(basicAmount)as amount from salesorder inner join salesorder_details on salesorder.id=salesorder_details.masterId where  ApprovalStatus='Approved' and  Sale_Key_Exec='".$row['Sale_Key_Exec']."'group by salesorder.id ",$db);
  while($row12=DB_fetch_array($row1))
  {
  $grand=$grand+$row12['amount'];
  }	
  $dataarray[]=array('Sale_Key_Exec' => $row['Sale_Key_Exec'], 'grand' => $grand,);
  }
  
  foreach ($dataarray as $key => $row)
  {   
   $volume[$key]  = $row['grand'];
   $edition[$key] = $row['Sale_Key_Exec'];
  }    
  array_multisort($volume, SORT_DESC, $dataarray); 
  $i=0;
  foreach ($dataarray as $key => $row2)
   {
   if($row2['grand']!=0 && $i<4)
   {	
	 
  ?>
  <tr>
    <td class="tabledata_fist"><?php echo $s->getField('www_users','id',$row2['Sale_Key_Exec'],'realname');  ?></td>
    <td class="tabledata1"><?php echo $row2['grand']; ?></td>
    <td class="tabledata1"><a href="#" class="linkcolor" onclick='popup("barchartshow.php?id=<?php echo $row2['Sale_Key_Exec'] ?>",880,360)'>To View Click</a></td>
    
  </tr>
  <?php } $i++; } ?>
  
</table>
<div  align="right" class="seemore" ><a href="#" onclick="showExecutivesalesdata()" >Show More</a></div>
