<?php
include("../include/config.php");
require_once "../include/Database_functions.php";
?>

  <table  border="0" cellspacing="0" cellpadding="0" class="tableList"  style="margin-left:20px; ">
  
  <?php

$clientname ='';
$fromdate='';
$todate='';
$grandtotsales ='';
if(isset($_REQUEST['clientname'])){
$clientname=$_REQUEST['clientname'];
}

$i=1;


$sq_arr="SELECT  cf_accountsreceivable.*,cf_client.client_name from  cf_accountsreceivable
inner JOIN cf_client ON cf_client.client_id = cf_accountsreceivable.clientid
";

if($clientname!=''){
$sq_arr.=" and cf_accountsreceivable.clientid = '".$clientname."' ";
}


//$sq_arr.=" group by cf_client.client_id";


$nolimitqry=$query=$sq_arr;

$function="Searchdate";
include("../paging.php");
$sq_arr.=" LIMIT $start, $limit";

if(isset($_REQUEST['page'])){
$page=$_REQUEST['page'];
}else{
$page=10;
}
$totalrecievable=0;
$nolimitarray=mysql_query($nolimitqry);
if($nolimitarray && mysql_num_rows($nolimitarray)>0)
{
while($nolimitres=mysql_fetch_array($nolimitarray))
{

$totalrecievable=$totalrecievable+$nolimitres['receiveamount'];
}
}
?>

<tr class="heading">
    <td>No</td>    
    <td>Client Name</td>
	<td>Total Recievable</td>    
    <td align="center">Receipt</td>
  </tr>

<?php
$array=mysql_query($sq_arr);
if($array && mysql_num_rows($array)>0){
$pagecnt=$start;
while($res=mysql_fetch_array($array))
{
//------------get the clientname-----------------------//
$pagecnt++;


  ?> 
<tr>
    <td><?php echo $pagecnt;?></td>

    <td><?php echo $res['client_name'];?></td>     
    <td><?php echo $res['receiveamount'];?></td>   
   
    <td align="center" class="tr_td_r" ><a href="reciept-form.php?reciepttype=accopbal&clientid=<?=$res['clientid']?>&amt=<?=$res['receiveamount']?>&accid=<?=$res['sales_id']?>"><img src="images/payslip.jpg" width="20" height="20"></a></td>
	
	
  </tr>
  <?php 
    }}else{?>
	 <tr>
    <td class="errorMessage"  style="border-right:0px;border-bottom:0px; "><font color="#FF0000">No Records Found</font></td></tr>
	<? }
  ?>
  <tr><td colspan="3"></td><td><b>Grand Total:<?php echo $totalrecievable;?></b></td></tr>
  
</table>
  
   <div align="right" style="padding-top:10px;"><?=$pagination?></div>