<?php
//*********************START HERE*********************AMIT SINGH****************30-10-2012******************************
$PageSecurity = 2;
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/function_lib.php');


$ClientSQL=DB_query("Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and  Site='".$_SESSION['AssignedBranch']."' 
		and Zone in(".$_SESSION['AssignedSites'].")",$db); ?>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
  <tr>
    <td class="tabledata">Party Name</td>
    <td class="tabledata">Highest Sale</td>
  </tr>
<?php  while($SQLRow=DB_fetch_array($ClientSQL)) {


$SQlClint=DB_query("SELECT SUM(grandTotal) AS HighestSale 
FROM dispatch 
where party='".$SQLRow['id']."'
ORDER BY HighestSale DESC",$db);
$abc=DB_fetch_array($SQlClint);

$dataarray2[]=array('client' => $SQLRow['c_name'], 'basic' => $abc['HighestSale']);	
}
foreach ($dataarray2 as $key => $row)
  {   
   $volume[$key]  = $row['basic'];
   $edition[$key] = $row['client'];
  }  
array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $dataarray2);
 $k=0;
 foreach ($dataarray2 as $key => $row2)
   {
   if($row2['basic']!=''){
?>  
  <tr>
    <td class="tabledata_fist"><?php echo $row2['client']; ?></td>
    <td class="tabledata1"><?php  if($row2['basic']==''){echo '0';}else{echo $row2['basic'];} ?></td>
  </tr>
<?php } }?> 
</table>