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



<div id="list">
   <table  border="0" cellspacing="0" cellpadding="0" class="tableList"  style="margin-left:20px; ">
  <tr class="heading">
   <td>No</td>    
    <td>Sales Return Code</td>
  <!--<td>Sales Refer Code</td>-->
  <td>Quantity</td>
   <td>Sales Return Rate</td>
    <td>Sales Type</td>   
  <td>Product</td>
  <td>Client</td>
  <td>Date</td>    
    <td>Total</td> 
    <td align="center">Delete</td>    
  </tr>
  
<?php

$saletype ='';
$fromdate='';
$todate='';


$master = '';
$notification = '';
$trip = '';
$accounting = '';
$accpay = '';
$report = '';

if(isset($_REQUEST['saletype'])){
$saletype=$_REQUEST['saletype'];
}

if(isset($_REQUEST['fromdate'])){
$fromdate=$_REQUEST['fromdate'];
$fromdate1 = date('Y-m-d', strtotime($fromdate));
}

if(isset($_REQUEST['todate'])){
$todate=$_REQUEST['todate'];
$todate1 = date('Y-m-d', strtotime($todate));
}
$i=1;
//$sq_arr="select * from cf_sales_return where 1 ";
$sq_arr="select cf_sales_return.*,cf_client.*,cf_sales_return_sub.sale_return_rate,cf_sales_return_sub.return_prd_id as return_prd_id,cf_sales_return_sub.sale_no_tin_return_kg from cf_sales_return join cf_client on cf_sales_return.sales_return_clientid = cf_client.client_id join cf_sales_return_sub on cf_sales_return_sub.sale_returnid = cf_sales_return.sales_return_id  where 1 ";

if($saletype!=''){
$sq_arr.=" and sales_return_type = '".$saletype."' ";
}

if($fromdate!="" && $todate!=""){
$sq_arr.=" and sales_return_date between '$fromdate1' and '$todate1'";
}


$sq_arr.=" order by sales_return_id desc ";
$query=$sq_arr;
//echo $query;
$function="Searchdate";
include("../paging.php");
$sq_arr.=" LIMIT $start, $limit";

if(isset($_REQUEST['page'])){
$page=$_REQUEST['page'];
}else{
$page=1;
}
$saleTot = 0;$saleReturnTot = 0;
$array=mysql_query($sq_arr);
if($array && mysql_num_rows($array)>0){
$pagecnt=$start;
while($res=mysql_fetch_array($array))
{
$pagecnt++;
  ?> 
  <tr>
     <td><?php echo $pagecnt;?></td>
    <td><a href="#login-box" class="login-window" data-id=<?php echo $res['sales_return_id'];?> data-chk=<?php echo $res['sales_return_type'];?> style="color:#AA2D58"><?php echo "SR-". $res['sales_return_code'];?></a></td>
  <?php /*?><td><?php echo 'SL-'.$res['sales_refno'];?></td><?php */?>
  <td><?php echo $res['sale_no_tin_return_kg']; $saleTot +=$res['sale_no_tin_return_kg'];?></td>  
   <td><?php echo $res['sale_return_rate'];?></td>  
    <td><?php echo $res['sales_return_type'];?></td>

  <?php 
  $sq_product=mysql_query("select * from cf_open_oil where open_stock_id = '".$res['return_prd_id']."'");
  $rws = mysql_fetch_array($sq_product);
  ?>
  <td><?php echo $rws['item_name'];?></td>   
  <td><?php echo $res['client_name'];?></td>   
    <td><?php echo date(('d-m-Y'),strtotime($res['sales_return_date']));?></td>     
    <td><?php echo $res['sales_return_tot']; $saleReturnTot += $res['sales_return_tot']; ?></td> 
    <td align="center" class="tr_td_r" ><a href="delete-sale-return.php?sale_ret_id=<?=$res['sales_return_id']?>&del=delete&return_type=<?=$res['sales_return_type']?>" onClick="return confirm('Do you really want to delete this field?');"><img src="images/delete.png" title="delete"></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><strong>Total</strong></td>   
    <td>&nbsp;</td>
    <td><strong><?php echo $saleTot;?></strong></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><strong><?php echo  $saleReturnTot;?></strong></td>
    <td>&nbsp;</td>
  </tr>
</table>

  <div align="right" style="padding-top:10px;"><?=$pagination?></div> 
  </div>
 