<?php 
//*********************START HERE*********************AMIT SINGH****************30-10-2012******************************

$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</td>
    <td class="tabledata">Pending Order</td>
  </tr>
<?php $i=0; while($DistinctClient=DB_fetch_array($ClientSQL)) {
$SQlClint=DB_query("SELECT orderNo
FROM salesorder 
INNER JOIN salesorder_details 
ON (salesorder.id=salesorder_details.masterId) 
WHERE salesorder_details.ApprovalStatus='1' AND salesorder.client='".$DistinctClient['id']."' GROUP BY  salesorder.id
ORDER BY orderNo DESC",$db);
$abc=DB_fetch_array($SQlClint);
$Test=DB_num_rows($SQlClint);

$dataarray[]=array('client' => $DistinctClient['c_name'], 'basic' => $Test);	
}

foreach ($dataarray as $key => $row)
  {   
   $volume[$key]  = $row['basic'];
   $edition[$key] = $row['client'];
  }  
array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $dataarray);
 $k=0;
 foreach ($dataarray as $key => $row2)
   {
if($row2['basic']!='0'){
$i++;
 if($i<5){?>  
  <tr>
    <td class="tabledata_fist"><?php echo $row2['client']; ?></td>
    <td class="tabledata1"><?php echo $row2['basic']; ?></td>
  </tr>
<?php }} }?>  
</table> 
<?php  if($i>5) {?>
<div  align="right" class="seemore" ><a href="#" onclick="showpendingordapproval()" >Show More</a></div> 
<?php } ?>