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

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

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

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));
}

if(isset($_REQUEST['clientboxid'])){
$clientboxid=$_REQUEST['clientboxid'];
}
$i=1;
$saleTot =0; $saleAmountTot =0;
$sq_arr="select cf_sales.*,cf_client.*,cf_sales_sub.sale_rate,cf_sales_sub.prd_id as prd_id,cf_sales_sub.sale_no_tin_kg from cf_sales join cf_client on cf_sales.sales_clientid = cf_client.client_id join cf_sales_sub on cf_sales.sales_id=
cf_sales_sub.sale_id where 1";

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

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

if($clientboxid!=''){
$sq_arr.=" and cf_sales.sales_clientid = '".$clientboxid."' ";
}


/*if($sdate_12!=''){
$sq_arr.=" and date='".$sdate."' ";
}*/
$sq_arr.=" order by cf_sales.sales_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=10;
}
$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><a href="#login-box" class="login-window" data-id=<?php echo $res['sales_id'];?> data-chk=<?php echo $res['sales_type'];?> style="color:#AA2D58"><?php echo "SL-". $res['sales_code'];?></a></td>
    <?php 
	$sq_product=mysql_query("select * from cf_open_oil where open_stock_id = '".$res['prd_id']."'");
	$rws = mysql_fetch_array($sq_product);
	?>
	<td><?php echo $rws['item_name'];?></td>   
	<td><?php echo $res['sale_no_tin_kg']; $saleTot +=$res['sale_no_tin_kg'];?></td> 
  <td><?php echo $res['sale_rate'];?></td>     
    <td><?php echo $res['sales_type'];?></td>     
	<td><?php echo $res['client_name'];?></td>     
    <td><?php echo date(('d-m-Y'),strtotime($res['sales_date']));?></td>     
   <td><?php echo $res['sales_tot']; $saleAmountTot+=$res['sales_tot']; ?></td> 
    <td align="center" class="tr_td_r" ><a href="sales-list.php?sales_del=<?=$res['sales_id']?>&del=delete&clientids=<?=$res['sales_clientid']?>" 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>&nbsp;</td>
    <td><strong><?php echo $saleTot;?></strong></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
     <td>&nbsp;</td>
    <td><strong><?php echo  $saleAmountTot;?></strong></td>
    <td>&nbsp;</td>
  </tr>
  
</table>
  
   <div align="right" style="padding-top:10px;"><?=$pagination?></div>