<?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 width="50">SrNo</td> 
    <td>Vendor</td>
	<td>Product</td>
    <td>Purchase Type</td>
    <!--<td>FFA Req</td>
	<td>FFA Got</td>-->
	<td>VehicleNumber</td>
	<td>Driver</td>
    <td>Commodity Kg</td>
    <td>Tin Rate</td>
    <td>Commodity Rate</td>
    <td>Tanker Tonne</td>
    <td>Tanker Freight</td>
    <td>Tax%</td>
    <td>Tax Rs</td>
    <td>Grand Total</td>
	<td>Date</td>
    <!--<td align="center">Print</td>-->
    <td align="center">Edit</td>
    <td align="center">Delete</td>
  </tr>
<?php

$vendortype ='';
$fromdate='';
$todate='';
$prdtype='';
if(isset($_REQUEST['vendortype'])){
$vendortype=$_REQUEST['vendortype'];
}
if(isset($_REQUEST['prdtype'])){
$prdtype=$_REQUEST['prdtype'];
}
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_oilpurchase where 1 ";
if($vendortype!=''){
$sq_arr.=" and pur_vendor_id = '".$vendortype."' ";
}
if($prdtype!=''){
$sq_arr.=" and pur_prd_id = '".$prdtype."' ";
}
if($fromdate!="" && $todate!=""){
$sq_arr.=" and pur_addate between '$fromdate1' and '$todate1'";
}


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

  ?> 
<tr>
    <td><?php echo $pagecnt;?></td>
    <td><?php echo "PR-".$res['pur_id'];?></td>
    <?php
		if($res['pur_type'] == 1)
		{
			$purtype = 'Kg';
		}
		else if($res['pur_type'] == 2)
		{
			$purtype = 'tin';
		}
		else
		{
			$purtype = 'Jar';
		}
	 ?>
    
    <?php 
		$vendorid = $res['pur_vendor_id'];	
        $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>
     <?php 
		$prdid = $res['pur_prd_id'];	
        $sq_prd=mysql_query("select * from cf_open_oil where open_stock_id = '$prdid'");
    	$resprd=mysql_fetch_array($sq_prd);
    ?>	
	 <td><?php echo $resprd['item_name'];?></td>
     <td><?php echo $purtype;?></td>
	 <?php 
		$vehid = $res['vehicleid'];	
        $sq_veh=mysql_query("select * from cf_vehicle where id = '$vehid'");
    	$resveh=mysql_fetch_array($sq_veh);
    ?>	
	 <td><?php echo $resveh['vehiclenum'];?></td>
	 <td><?php echo $res['driver_names'];?></td>
     <?php /*?><td><?php echo $res['pur_ffa_req'];?></td>
     <td><?php echo $res['pur_ffa_got'];?></td><?php */?>
     <td><?php echo $res['pur_com_kg'];?></td>
     <td><?php echo $res['pur_tin_rate'];?></td>
     <td><?php echo $res['pur_com_total'];?></td>
     
     <td><?php echo $res['pur_tank_tonne'];?></td>
     <td><?php echo $res['pur_tank_total'];?></td>
    
     <td><?php echo $res['pur_tax_per'];?></td>
     <td><?php echo $res['pur_tax_rate'];?></td>
     <td><?php echo $res['pur_total']; $grandTot+= $res['pur_total']; ?></td>
	 <td><?php echo date(('d-m-Y'),strtotime($res['pur_addate']));?></td>
    <?php /*?><td align="center" class="tr_td_b"><a href="changepassword.php?user_main=<?=$res['pur_id']?>"><img src="images/edit.png" title="print"></a></td><?php */?>
   <td align="center" class="tr_td_b"><a href="add-purchase.php?pur_mainid=<?=$res['pur_id']?>"><img src="images/edit.png" title="edit"></a></td>
   
   <td align="center" class="tr_td_r" ><a href="purchase_list.php?pur_del=<?=$res['pur_id']?>&del=delete" 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 colspan="2"><strong>Total</strong></td><td colspan="12"></td>
     <td><strong><?php echo $grandTot;?></strong></td><td colspan="4"></td>
 </tr>
  
</table>
  
   <div align="right" style="padding-top:10px;"><?=$pagination?></div>