<?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>Client Name</td>
  <td>Vendor Name</td>
  <td>Date</td>
  <td>Type</td>
  <td>No of Jar </td>    
    <td>Amount</td>    
  <!--<td align="center">Edit</td>-->
    <td align="center">Delete</td>
  </tr>
  
<?php

$client_id ='';
$fromdate='';
$todate='';

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

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



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

$i=1;
$sq_arr="select * from cf_jar_purchase where jar_purchase_type != 'jar_sales' ";

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

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

$sq_arr.=" order by jar_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;
}

 $totjar_no ='';
 $totjar_amount ='';


$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>
       
    <?php 
      $vendor_name='';
    $client_name='';
    $clientid = $res['jar_clientid']; 
        
    if($res['jar_purchase_type'] == 'purchase' || $res['jar_purchase_type'] == 'jarpurchasereturn')
    {
      
          $sq_ven=mysql_query("select * from cf_reseller where reseller_id = '$client_id'");
        $resven=mysql_fetch_array($sq_ven);
      $vendor_name = $resven['res_name'];
    }
    else if($res['jar_purchase_type'] == 'purchasereturn')
    {
      $sq_client=mysql_query("select * from cf_client where client_id = '$clientid'");
        $resclt=mysql_fetch_array($sq_client);
      $client_name = $resclt['client_name'];
    }
    
    
    ?>  
     <td><?php echo $client_name;?></td>
   <td><?php echo $vendor_name;?></td>
   <td><?php echo date(('d-m-Y'),strtotime($res['date']));?></td>  
   <td><?php if($res['jar_purchase_type'] == 'purchase'){ echo "Jar Purchase";  } else if($res['jar_purchase_type'] == 'purchasereturn') {  echo "jar Sales Return"; } else if($res['jar_purchase_type'] == 'jarpurchasereturn') {  echo "Jar Purchase Return"; }  ?></td>
   </td>
     <td><?php echo $res['jar_no'];?></td>     
     <td><?php echo $res['jar_amount'];?></td>     
     <?php /*?><td align="center" class="tr_td_b"><a href="add-jar-purchase.php?jar_mainid=<?=$res['jar_id']?>"><img src="images/edit.png" title="edit"></a></td><?php */?>
   
   <td align="center" class="tr_td_r" ><a href="jar_purchase_list.php?jar_del=<?=$res['jar_id']?>&qty=<?=$res['jar_no']?>&amt=<?=$res['jar_amount']?>&client_id=<?=$res['jar_clientid']?>&del=delete" onClick="return confirm('Do you really want to delete this field?');"><img src="images/delete.png" title="delete"></a></td>
  </tr>
  <?php 
  $totjar_no += $res['jar_no'];
  $totjar_amount += $res['jar_amount'];
 
    }}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></td>
     <td>Total</td>
     <td><?=$totjar_no?></td>     
     <td><?=$totjar_amount?></td>     
    
     <td></td>
     <td></td>
   </tr>
</table>

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