<?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>Vendor</td>
    <td>Date</td>
	<td>Product</td>    
    <td>Oil Kg</td>    
    <td>Pinnaku Kg</td>   
  </tr>
<?php

$purchase_type ='';
$fromdate='';
$todate='';
$prdtype='';
$reseller_id='';

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

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

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_purchase as pur left join cf_product as prd on pur.purchase_prdid = prd.product_id where 1 ";

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

if($reseller_id!=''){
  $sq_arr.=" and purchase_vendorid = '".$reseller_id."' ";
}

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


/*if($sdate_12!=''){
$sq_arr.=" and date='".$sdate."' ";
}*/
$sq_arr.=" order by purchase_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;$pinnakutotal = 0;
$puroil_total = 0;
while($res=mysql_fetch_array($array))
{
//------------get the clientname-----------------------//
$pagecnt++;

  ?> 
<tr>
    <td><?php echo $pagecnt;?></td>
    <?php 
		$vendorid = $res['purchase_vendorid'];	
        $sq_ven=mysql_query("select * from cf_reseller where reseller_id = '$vendorid'");
    	$resven=mysql_fetch_array($sq_ven);
    ?>	
     <td><?php echo $resven['res_name'];?></td>
     <td><?php echo date('d-m-Y' ,strtotime($res['purchase_addate']));?></td>
     <td><?php  if($res['product_name'] != '') 
	 {echo $res['product_name'];}
	 else
	 {
	 	echo "Coconut Conversion";
	 }?></td>  
     <td><?php echo $res['purchase_total'];  $puroil_total += $res['purchase_total'];?></td>
     <td><?php echo $res['purchase_pinna_total']; $pinnakutotal += $res['purchase_pinna_total'];?></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 class="heading"> 
     <td></td>
     <td></td> 
     <td></td> 
     <td>Total</td>  
     <td><?=$puroil_total?></td>     
     <td><?=$pinnakutotal?></td>      
         
  </tr>
</table>
  
   <div align="right" style="padding-top:10px;"><?=$pagination?></div>