<?php
include("../include/config.php");
require_once "../include/Database_functions.php";
$i=1;
$id='';
$status='';
$recieved_amnt='';
$pending_amnt='';
$veh_namefield='';
$datefield='';
$frmdate11='';
$todate_11='';

if(isset($_REQUEST['client']))
{
$id=$_REQUEST['client'];
}
if(isset($_REQUEST['status']))
{
	$status=$_REQUEST['status'];
}
if(isset($_REQUEST['ab']))
{
$i=$_REQUEST['ab'];
}
if(isset($_REQUEST['veh_namefield']))
{
$veh_namefield=$_REQUEST['veh_namefield'];
}
if(isset($_REQUEST['datefield']))
{
$datefield=$_REQUEST['datefield'];
}
if($status==''){
$status='O';
}
if($status=='O'){
$table="tbl_voucher";
$datfield='add_date';
}
if($status=='F'){
$table="tbl_fuel_voucher";
$datfield='dates';
}
if($status=='M'){
$table="tbl_maint_voucher";
$datfield='dates';
}

if($status=='Dr'){
$table="tbl_driver_voucher";
$datfield='dates';
}

if($status=='Cr'){
$table="tbl_cleaner_voucher";
$datfield='dates';
}

if($status=='Insvouc'){
$table="tbl_insur_voucher";
$datfield='dates';
}

if($status=='Pollvouc'){
$table="tbl_poll_voucher";
}

if($status=='Taxvouc'){
$table="tbl_tax_voucher";
}

if($status=='Fitvouc'){
$table="tbl_fittness_voucher";
}

if($status=='Pervouc'){
$table="tbl_permit_voucher";
}


if($status=='Payvouc'){
//$table="tbl_voucher";
	$sql = "SELECT count(*) as cnt FROM tbl_voucher where category = 'P'";
}
else
{
	$sql = "SELECT count(*) as cnt FROM ".$table;
}



//$sql = "SELECT count(*) as cnt FROM ".$table;
$qrysql=mysql_query($sql);
$qrysql=mysql_fetch_object($qrysql);
	if($qrysql->cnt==0){
	if($status=='M')
	{
		$sql = "SELECT count(*) as cnt FROM tbl_maint_voucher";	
		$qrysql=mysql_query($sql);
		$qrysql=mysql_fetch_object($qrysql);
		$table="tbl_maint_voucher";
	}
	}
	if($qrysql->cnt==0){
	if($status=='F')
	{
		$sql = "SELECT count(*) as cnt FROM tbl_fuel_voucher";
		$qrysql=mysql_query($sql);
		$qrysql=mysql_fetch_object($qrysql);
		$table="tbl_fuel_voucher";
	}
	}
	if($qrysql->cnt==0){
	if($status=='Dr')
	{
		$sql = "SELECT count(*) as cnt FROM tbl_driver_voucher";
		$qrysql=mysql_query($sql);
		$qrysql=mysql_fetch_object($qrysql);
		$table="tbl_driver_voucher";
	}
	}
	if($qrysql->cnt==0){
	if($status=='Cr')
	{
		$sql = "SELECT count(*) as cnt FROM tbl_cleaner_voucher";
		$qrysql=mysql_query($sql);
		$qrysql=mysql_fetch_object($qrysql);
		$table="tbl_cleaner_voucher";
	}
	}
	
	if($qrysql->cnt==0){
	if($status=='Insvouc')
	{
		$sql = "SELECT count(*) as cnt FROM tbl_insur_voucher";
		$qrysql=mysql_query($sql);
		$qrysql=mysql_fetch_object($qrysql);
		$table="tbl_insur_voucher";
	}
	}
	
	
	if($qrysql->cnt==0){
	if($status=='Pollvouc')
	{
		$sql = "SELECT count(*) as cnt FROM tbl_poll_voucher";
		$qrysql=mysql_query($sql);
		$qrysql=mysql_fetch_object($qrysql);
		$table="tbl_poll_voucher";
	}
	}
	
	if($qrysql->cnt==0){
	if($status=='Taxvouc')
	{
		$sql = "SELECT count(*) as cnt FROM tbl_tax_voucher";
		$qrysql=mysql_query($sql);
		$qrysql=mysql_fetch_object($qrysql);
		$table="tbl_tax_voucher";
	}
	}
	
	if($qrysql->cnt==0){
	if($status=='Fitvouc')
	{
		$sql = "SELECT count(*) as cnt FROM tbl_fittness_voucher";
		$qrysql=mysql_query($sql);
		$qrysql=mysql_fetch_object($qrysql);
		$table="tbl_fittness_voucher";
	}
	}
	
	if($qrysql->cnt==0){
	if($status=='Pervouc')
	{
		$sql = "SELECT count(*) as cnt FROM tbl_permit_voucher";
		$qrysql=mysql_query($sql);
		$qrysql=mysql_fetch_object($qrysql);
		$table="tbl_permit_voucher";
	}
	}
	
	
	if($qrysql->cnt==0){
	if($status=='Payvouc')
	{
		$sql = "SELECT count(*) as cnt FROM tbl_voucher where category = 'P'";
		$qrysql=mysql_query($sql);
		$qrysql=mysql_fetch_object($qrysql);
		$table="tbl_voucher";
	}
	}
	
	
	



if(isset($_REQUEST['frmdate1'])){
$frmdate11=$_REQUEST['frmdate1'];
$from=$_REQUEST['frmdate1'];
}
if(isset($_REQUEST['todate_1'])){
$todate_11=$_REQUEST['todate_1'];
$to=$_REQUEST['todate_1'];
}



?>
 <table width="98%" border="0" cellspacing="0" cellpadding="0">
   <tr>
      <th width="10%" align="left" valign="middle">Bill No</th>
      <th width="12%" align="left" valign="middle">Vechicle No</th>
      <th width="11%" align="left" valign="middle">Towards</th>
      <th width="31%" align="left" valign="middle">Received</th>
      <th colspan="2" align="left" valign="middle">Due date</th>
	  <th colspan="2" align="left" valign="middle">Print</th>
	  <th align="left" valign="left">Create Xml</th>
      <?
	  if($status=='O'){?>
      <? }else{?>
	  <? }?>
    </tr>
  	<?php
	$adjacents = 3;
	$page=1;
	
	if($status=='Payvouc')
	{
		$sql = "SELECT * FROM tbl_voucher where  category = 'P' ";
	}
	else
	{
		$sql = "SELECT * FROM ".$table." where  1 ";
	}
	
	
	
	if($id!='')
	$sql.=" and id='$id'";
	if($status=='O'){
	$datfield='add_date';
	}
	if($status=='F'){
	$datfield='dates';
	}
	if($status=='M'){
	$datfield='dates';
	}
	if($frmdate11!='' && $todate_11!=''){
	$sql.=" and ".$datfield." between '$from' and '$to' ";
	}
	if($frmdate11!='' && $todate_11==''){
	$sql.=" and ".$datfield.">='".$from."' ";
	}
	if($frmdate11=='' && $todate_11!=''){
	$sql.=" and ".$datfield." <='".$to."' ";
	}
   	$query=$sql;
	 $limit=10;
	$function="Client";
	include("../paging.php");
	$sql.=" order by id desc LIMIT $start, $limit";
	$result = mysql_query($sql);
	
	$i=1;
	if($qrysql->cnt>0){
	while($arr=mysql_fetch_array($result))
	{
	if($status=='O'){
	?>
	<tr>
      <td class="tr_td"><input type="hidden" id="id<?=$i;?>" value="<?php echo $arr['autonumber'];?>" />
	  <?php echo $arr['id'];?></td>
      <td class="tr_td"><?php echo $arr['vechno']; ?></td>
      <td class="tr_td"><?php echo $arr['purpose']; ?></td>
     
      <td class="tr_td">
	  <? if(isset($arr['recieved_amnt']))
	  {
	  if($arr['recieved_amnt']!=''){
	   echo $arr['recieved_amnt']; 
	  }
	  }
	  ?>
	  </td>
      <td colspan="2" class="tr_td"><? echo date("m-d-Y",strtotime($arr['add_date']));?></td>
	  <td colspan="2" class="tr_td"><a href="print_tripsheet.php?veh_no=<?php echo $arr['id'];?>"><img src="images/icon4.jpg" width="22" height="20" /></a></td>
	    <td class="tr_td tr_td_r">  <?php 
	   		if($arr['category'] == 'G')
			{ ?>
			
			 <td colspan="2" class="tr_td"><a href="print_tripsheet.php?veh_no=<?php echo $arr['id'];?>" ><img src="images/icon4.jpg" width="22" height="20" /></a></td>
				 <a href="createjournal.php?id=<?php echo $arr['id'];?>" ><font color="#000000">Download.xml</font></a>
			<?php } 
	   ?>	   
	   
	    <?php 
	   		if($arr['category'] == 'C')
			{ ?>
			<td colspan="2" class="tr_td"><a href="print_tripsheet.php?veh_no=<?php echo $arr['id'];?>"><img src="images/icon4.jpg" width="22" height="20" /></a></td>
				 <a href="createcontra.php?id=<?php echo $arr['id'];?>" ><font color="#000000">Download.xml</font></a>
			<?php } 
	   ?></td>
      </tr>
	<?
	}//other vocuher
	//Fule voucher
	if($status=='F'){?>
	
	<tr>
      <td class="tr_td"><input type="hidden" id="id<?=$i;?>" value="<?php echo $arr['auto_number'];?>" />
	  <?php echo $arr['id'];?></td>
      <td class="tr_td"><?php echo $arr['vehicle_number']; ?></td>
      <td class="tr_td"><?php echo $arr['paid_towards']; ?></td>
      <td class="tr_td">
	   <?php echo $arr['amount']; ?>	  </td>
      <td colspan="2" class="tr_td tr_td_r"><? echo date("m-d-Y",strtotime($arr['dates']));?></td>
	  <td colspan="2" class="tr_td"><a href="printfuel_voucher.php?fuel_id=<?php echo $arr['id'];?>" target="_blank"><img src="images/icon4.jpg" width="22" height="20" /></a></td>
	    <td class="tr_td tr_td_r">  <a href="createfuel.php?id=<?php echo $arr['id'];?>" target="_blank"><font color="#000000">Download.xml</font></a></td>
    </tr>
	<? }
	//Maintanance voucher
	if($status=='M'){?>
	<tr>
      <td class="tr_td"><input type="hidden" id="id<?=$i;?>" value="<?php echo $arr['auto_number'];?>" />
	  <?php echo $arr['id'];?></td>
      <td class="tr_td"><?php echo $arr['maint_id']; ?></td>
      <td class="tr_td"><?php echo $arr['paid_towards']; ?></td>
      <td class="tr_td">
	   <?php echo $arr['amount']; ?>	  </td>
      <td colspan="2" class="tr_td tr_td_r"><? echo date("m-d-Y",strtotime($arr['dates']));?></td>
	  <td colspan="2" class="tr_td"><a href="printmaint_voucher.php?maint_no=<?php echo $arr['id'];?>" target="_blank"><img src="images/icon4.jpg" width="22" height="20" /></a></td>
	    <td class="tr_td tr_td_r">  <a href="createmaintenance.php?id=<?php echo $arr['id'];?>" target="_blank"><font color="#000000">Download.xml</font></a></td>
    </tr>
	
	<? }
	//Driver voucher
	if($status=='Dr'){?>
	<tr>
      <td class="tr_td"><input type="hidden" id="id<?=$i;?>" value="<?php echo $arr['auto_number'];?>" />
	  <?php echo $arr['id'];?></td>
      <td class="tr_td"><?php echo $arr['vechicle_no']; ?></td>
      <td class="tr_td"><?php echo $arr['paid_towards']; ?></td>
      <td class="tr_td">
	   <?php echo $arr['amount']; ?>	  </td>
      <td colspan="2" class="tr_td tr_td_r"><? echo date("m-d-Y",strtotime($arr['dates']));?></td>
	  <td colspan="2" class="tr_td tr_td_r"><a href="printdriver-voucher.php?drvid=<?php echo $arr['id'] ?>" target="_blank"><img src="images/icon4.jpg" width="22" height="20" /></a></td>
	    <td class="tr_td tr_td_r">  <a href="createmaintenance.php?id=<?php echo $arr['id'];?>" target="_blank"><font color="#000000">Download.xml</font></a></td>
    </tr>
	
	<? }
	//Cleaner voucher
	if($status=='Cr'){?>
	<tr>
      <td class="tr_td"><input type="hidden" id="id<?=$i;?>" value="<?php echo $arr['auto_number'];?>" />
	  <?php echo $arr['id'];?></td>
      <td class="tr_td"><?php echo $arr['vechicle_no']; ?></td>
      <td class="tr_td"><?php echo $arr['paid_towards']; ?></td>
      <td class="tr_td">
	   <?php echo $arr['amount']; ?>	  </td>
      <td colspan="2" class="tr_td tr_td_r"><? echo date("m-d-Y",strtotime($arr['dates']));?></td>
	  <td colspan="2" class="tr_td tr_td_r"><a href="printcleaner-voucher.php?clnid=<?php echo $arr['id'] ?>" target="_blank"><img src="images/icon4.jpg" width="22" height="20" /></a></td>
	    <td class="tr_td tr_td_r">  <a href="createmaintenance.php?id=<?php echo $arr['id'];?>" target="_blank"><font color="#000000">Download.xml</font></a></td>
    </tr>
	
	<? }
	
	//Insurance voucher
	if($status=='Insvouc'){?>
	<tr>
      <td class="tr_td"><input type="hidden" id="id<?=$i;?>" value="<?php echo $arr['auto_number'];?>" />
	  <?php echo $arr['id'];?></td>
      <td class="tr_td"><?php echo $arr['vechicle_no']; ?></td>
      <td class="tr_td"><?php echo $arr['paid_towards']; ?></td>
      <td class="tr_td">
	   <?php echo $arr['amount']; ?>	  </td>
      <td colspan="2" class="tr_td tr_td_r"><? echo date("m-d-Y",strtotime($arr['dates']));?></td>
	  <td colspan="2" class="tr_td tr_td_r"><a href="printinsurance-voucher.php?clnid=<?php echo $arr['id'] ?>" target="_blank"><img src="images/icon4.jpg" width="22" height="20" /></a></td>
	    <td class="tr_td tr_td_r">  <a href="createmaintenance.php?id=<?php echo $arr['id'];?>" target="_blank"><font color="#000000">Download.xml</font></a></td>
    </tr>
	
	<? }
	
	 
	 //Pollution voucher
	if($status=='Pollvouc'){?>
	<tr>
      <td class="tr_td"><input type="hidden" id="id<?=$i;?>" value="<?php echo $arr['auto_number'];?>" />
	  <?php echo $arr['id'];?></td>
      <td class="tr_td"><?php echo $arr['vechicle_no']; ?></td>
      <td class="tr_td"><?php echo $arr['paid_towards']; ?></td>
      <td class="tr_td">
	   <?php echo $arr['amount']; ?>	  </td>
      <td colspan="2" class="tr_td tr_td_r"><? echo date("m-d-Y",strtotime($arr['dates']));?></td>
	  <td colspan="2" class="tr_td tr_td_r"><a href="printpollution-voucher.php?clnid=<?php echo $arr['id'] ?>" target="_blank"><img src="images/icon4.jpg" width="22" height="20" /></a></td>
	    <td class="tr_td tr_td_r">  <a href="createmaintenance.php?id=<?php echo $arr['id'];?>" target="_blank"><font color="#000000">Download.xml</font></a></td>
    </tr>
	
	<? }
	
	 //Tax voucher
	if($status=='Taxvouc'){?>
	<tr>
      <td class="tr_td"><input type="hidden" id="id<?=$i;?>" value="<?php echo $arr['auto_number'];?>" />
	  <?php echo $arr['id'];?></td>
      <td class="tr_td"><?php echo $arr['vechicle_no']; ?></td>
      <td class="tr_td"><?php echo $arr['paid_towards']; ?></td>
      <td class="tr_td">
	   <?php echo $arr['amount']; ?>	  </td>
      <td colspan="2" class="tr_td tr_td_r"><? echo date("m-d-Y",strtotime($arr['dates']));?></td>
	  <td colspan="2" class="tr_td tr_td_r"><a href="printtax-voucher.php?clnid=<?php echo $arr['id'] ?>" target="_blank"><img src="images/icon4.jpg" width="22" height="20" /></a></td>
	    <td class="tr_td tr_td_r">  <a href="createmaintenance.php?id=<?php echo $arr['id'];?>" target="_blank"><font color="#000000">Download.xml</font></a></td>
    </tr>
	
	<? }
	
	//Tax voucher
	if($status=='Fitvouc'){?>
	<tr>
      <td class="tr_td"><input type="hidden" id="id<?=$i;?>" value="<?php echo $arr['auto_number'];?>" />
	  <?php echo $arr['id'];?></td>
      <td class="tr_td"><?php echo $arr['vechicle_no']; ?></td>
      <td class="tr_td"><?php echo $arr['paid_towards']; ?></td>
      <td class="tr_td">
	   <?php echo $arr['amount']; ?>	  </td>
      <td colspan="2" class="tr_td tr_td_r"><? echo date("m-d-Y",strtotime($arr['dates']));?></td>
	  <td colspan="2" class="tr_td tr_td_r"><a href="printfittness-voucher.php?clnid=<?php echo $arr['id'] ?>" target="_blank"><img src="images/icon4.jpg" width="22" height="20" /></a></td>
	    <td class="tr_td tr_td_r">  <a href="createmaintenance.php?id=<?php echo $arr['id'];?>" target="_blank"><font color="#000000">Download.xml</font></a></td>
    </tr>
	
	<? }
	
	//Tax voucher
	if($status=='Pervouc'){?>
	<tr>
      <td class="tr_td"><input type="hidden" id="id<?=$i;?>" value="<?php echo $arr['auto_number'];?>" />
	  <?php echo $arr['id'];?></td>
      <td class="tr_td"><?php echo $arr['vechicle_no']; ?></td>
      <td class="tr_td"><?php echo $arr['paid_towards']; ?></td>
      <td class="tr_td">
	   <?php echo $arr['amount']; ?>	  </td>
      <td colspan="2" class="tr_td tr_td_r"><? echo date("m-d-Y",strtotime($arr['dates']));?></td>
	  <td colspan="2" class="tr_td tr_td_r"><a href="printpermit-voucher.php?clnid=<?php echo $arr['id'] ?>" target="_blank"><img src="images/icon4.jpg" width="22" height="20" /></a></td>
	    <td class="tr_td tr_td_r">  <a href="createmaintenance.php?id=<?php echo $arr['id'];?>" target="_blank"><font color="#000000">Download.xml</font></a></td>
    </tr>
	
	<? }
	
	//Payment voucher
	if($status=='Payvouc'){?>
	<tr>
      <td class="tr_td"><input type="hidden" id="id<?=$i;?>" value="<?php echo $arr['auto_number'];?>" />
	  <?php echo $arr['id'];?></td>
      <td class="tr_td"><?php echo $arr['vechno']; ?></td>
      <td class="tr_td"><?php echo $arr['towards']; ?></td>
      <td class="tr_td">
	   <?php echo $arr['cash']; ?>	  </td>
      <td colspan="2" class="tr_td tr_td_r"><? echo date("m-d-Y",strtotime($arr['add_date']));?></td>
	  <td colspan="2" class="tr_td tr_td_r"><a href="printpayment-voucher.php?clnid=<?php echo $arr['id'] ?>" target="_blank"><img src="images/icon4.jpg" width="22" height="20" /></a></td>
	    <td class="tr_td tr_td_r">  <a href="createmaintenance.php?id=<?php echo $arr['id'];?>" target="_blank"><font color="#000000">Download.xml</font></a></td>
    </tr>
	
	<? }
	
	
	 $i++;
	 }
	 if($status=='F'){?>
	  <tr>
      <td  colspan="7" align="right"><a style="cursor:hand;cursor:pointer;" onclick="Client(1);"></a></td></tr>
	 <?
	 }if($status=='M'){?>
	  <tr>
      <td  colspan="7" align="right"><a style="cursor:hand;cursor:pointer;" onclick="Client(1);"></a></td></tr>
	 <?
	 }
	 }else{?>
	 
	 <tr>
      <td class="tr_td_r" colspan="8">No Records Found</td></tr>
	 <? }
	?></table>
	
	 <div align="right" style="padding-top:10px;"><?=$pagination?></div>
