<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}


$veh_num='';
$sdate_12 ='';
$page='1';
include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();
$msg = '';
$client_namek ='';

if(isset($_REQUEST['del']) && $_REQUEST['del']=='delete')
{
	$id = $_REQUEST['pur_del'];
	$sql=mysql_query("delete from cf_oilpurchase where pur_id='$id'");
	header("location:purchase_list.php?msg=You Have Successfully Deleted");
}

function print1($selectype,$vendortype)
			{
			
				//$userids = $_SESSION['admin_id'];
				
					$dates = date('Y-m-d');
					$names = $selectype.$dates;
					$outstr = NULL;
					header("Content-type: application/vnd.ms-word");
					header("Content-Disposition: attachment;Filename=".$names.".xls");
			
					//set the directory to get image			
					// Query database to get data
					$i = 1;
					'<div id="header" >';
						
						
					$outstr.='
						 <table style="font-family:Arial, Helvetica, sans-serif; font-size:12px;width:500px;border:1px solid #000000; " cellspacing=0 cellpadding=0 ">
						 <tr>
					     	<td colspan="3" style="font-size:14px; min-width:100px; text-align:center; padding:5px; min-width:200px;border-right:1px solid #000000;"><strong>Accounts Payable</strong></td>
    					</tr>
						<tr>
					     	<td style="font-size:14px; min-width:100px; text-align:left; padding:5px; min-width:200px;border-right:1px solid #000000;"><strong>No</strong></td>
    						<td style="font-size:14px; min-width:100px; text-align:left; padding:5px; min-width:200px;border-right:1px solid #000000;"><strong>Vendor Name</strong></td>
    						<td style="font-size:14px; min-width:100px; text-align:left;padding:5px; min-width:200px;border-right:1px solid #000000;"><strong>Pending Amount</strong></td>
							
							
  					</tr>
					';
				
				$sq_arr_print="SELECT  cf_acountspayable.*,cf_reseller.res_name from  cf_acountspayable
inner join cf_reseller on cf_reseller.reseller_id= cf_acountspayable.vendorid";

				if($vendortype!=''){
				$sq_arr_print.=" and cf_acountspayable.vendorid = '".$vendortype."' ";
				}


			
				$resultclientsql=mysql_query($sq_arr_print);	
					
				
				while($row = mysql_fetch_array($resultclientsql))
				{												  
				 	 		
				$outstr.= '<tr>
				<td style="font-size:14px; min-width:100px; text-align:left; padding:5px; min-width:200px;border-right:1px solid #000000; border-top:1px solid #000000;">'.$i.'</td>
				<td style="font-size:14px; min-width:100px; text-align:left; padding:5px; min-width:200px;border-right:1px solid #000000; border-top:1px solid #000000;">'.$row['res_name'].'</td>
				<td style="font-size:14px; min-width:100px; text-align:left; padding:5px; min-width:200px;border-right:1px solid #000000; border-top:1px solid #000000;">'.$row['pendingamount'].'</td>
				
					
				</tr>';
				 
				 $i++;}
			
				$outstr.= ' </table>
		</div>'; 
				echo $outstr;
				exit;
				
			}
			
			
				
			if(isset($_POST['download']))
			{
				$selectype = "Accounts Payable";
				$vendortype = $_POST['vendortype'];
								
				print1($selectype,$vendortype);
			}
?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>OIL FILL</title>
<link href="css/styles.css" rel="stylesheet"  />
<link href="css/menu.css" rel="stylesheet" type="text/css" />
<link type="text/css" href="css_date/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />

<script type="text/javascript" src="scripts_date/jquery-calendar-1.7.2.js"></script>
<script>

$(document).ready(function(){
$('#from_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

$(document).ready(function(){
$('#to_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});


function getXMLHTTP()
	 { //fuction to return the xml http object
	var xmlhttp=false;	
		try
		{
		xmlhttp=new XMLHttpRequest();
		}
		catch(e)	
		{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch(e)
			{
				try
				{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1)
				{
				xmlhttp=false;
				}
			}
		}
	return xmlhttp;
	}   


function Searchdate(page,val)
{ 
 	
	 var page=page;	
	 var vendortype='';
	 var fromdate='';
	 var todate='';
	 
	 if(document.purchase_frm.vendortype){
	 vendortype= document.purchase_frm.vendortype.value;
	 } 
	 
	 if(document.purchase_frm.from_date){
	 fromdate= document.purchase_frm.from_date.value;
	 }
	 
	 if(document.purchase_frm.to_date){
	 todate= document.purchase_frm.to_date.value;
	 }
	  
	 
	var strURL="ajax/acpayable_list_data.php?&page="+page;
	
	if(vendortype!=''){
	strURL+="&vendortype="+vendortype;
	}
	
	if(fromdate!=''){
	strURL+="&fromdate="+fromdate;
	}
	
	if(todate!=''){
	strURL+="&todate="+todate;
	}
	
	//alert(strURL);
	
	var req = getXMLHTTP();
   if (req)
   {
     req.onreadystatechange = function()
     {
		 
			if ((req.readyState == 0)||(req.readyState == 1)||(req.readyState == 2)||(req.readyState == 3))
      		{
			//document.getElementById('order').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			//document.getElementById('Cakeorder').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			}
		 
		 
      if (req.readyState == 4)
      {
	 // only if "OK"
	 	if (req.status == 200)
	 	{ 
	   document.getElementById('list').innerHTML=req.responseText;
	//	document.getElementById('Cakeorder').innerHTML=req.responseText;
	 	}
	  else 
	 	{
   	   alert("There was a problem while using XMLHTTP:\n" + req.statusText);

	 }
     }
     }
   req.open("GET", strURL, true);
   req.send(null);
   }
 
   
}
function showClientcodedropdown(str){
var xmlhttp;    
if (str=="")
  {
  document.getElementById("txtcodeshow").innerHTML="";
  Searchdate(1,str);
  return;
  }
  
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	   document.getElementById("txtcodeshow").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","clientajax_code_dropdown.php?str="+str,true);
xmlhttp.send();
}
</script>
</head>

<body>

<div class="wrapper">
   <div>
<?php 
	include("header.php");
?>
</div>
 
 <div class="tabbedArea" style="position:relative; margin-top:">

  
  <div class="tabBody">
   <h1>Accounts Payable </h1>
   
   <form name="purchase_frm" id="purchase_frm" method="post"  >
   <div class="searchBox" style="width:93%; margin-right:0px;  padding:0px; ">
   <div style="padding:20px;">
    
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">Vendor</p>
     <select name="vendortype" class="input1">
         <option value="">-Select Vendor-</option>
		 <?php 
		 $sq_resell=mysql_query("select * from cf_reseller"); 
		 while($resel=mysql_fetch_array($sq_resell))
			{
		?>
			<option value="<?=$resel['reseller_id']?>" ><?=$resel['res_name']?></option>
        <?php
			} ?>
     </select>
    </div>
	
	
	
   
       
    <div class="searchField">
     <input name="button" type="button" class="input1" onClick="Searchdate(1);" value="search" />
    </div>
	
	<div class="searchField" style="padding-left:60px;margin-right: 20px;">
    <input name="download" type="submit" class="input1"  value="download" />
    </div>
  
   </div>
   </div>
   </form>
   
   
   <div class="searchBox" style="width:93%; margin-right:0px;  padding:0px;">
  
   
   <div id="list">
   <table  border="0" cellspacing="0" cellpadding="0" class="tableList"  style="margin-left:20px; ">
   <?php
  
$master = '';
$notification = '';
$trip = '';
$accounting = '';
$accpay = '';
$report = '';
$grandtotpayable ='';
$i=1; 


$sq_arr="SELECT  cf_acountspayable.*,cf_reseller.res_name from  cf_acountspayable
inner join cf_reseller on cf_reseller.reseller_id= cf_acountspayable.vendorid
";

//$sq_arr.=" order by pur_id desc ";
$nolimitqry=$query=$sq_arr;
//echo $query;
$function="Searchdate";
include("pagingserch.php");
$sq_arr.=" LIMIT $start, $limit";

if(isset($_REQUEST['page'])){
$page=$_REQUEST['page'];
}else{
$page=1;
}

$totalpayable=0;
$nolimitarray=mysql_query($nolimitqry);
if($nolimitarray && mysql_num_rows($nolimitarray)>0)
{
while($nolimitres=mysql_fetch_array($nolimitarray))
{
$totalpayable=$totalpayable+$nolimitres['pendingamount'];
}
}

?>

 
  
  <tr class="heading">
    <td>No</td>    
   
	<td>Vendor Name</td>
	<td>Pending Amount</td>
	<td>Pay</td>
  </tr>
  
  <?php

$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>
     
	 <td><?php echo $res['res_name'];?></td>
   
     <td><?php echo $res['pendingamount'];?></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>
	<a href="voucher-form.php?vouchertype=accoppbal&empid=<?=$res['vendorid']?>&salamt=<?=$res['pendingamount']?>&accid=<?=$res['ledgerid']?>"><img src="images/payslip.jpg" width="20" height="20"></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="3"></td><td><b>Grand Total:<?php echo $totalpayable;?></b></td></tr>
</table>

  <div align="right" style="padding-top:10px;"><?=$pagination?></div> 
  </div>
  </div>
 </div>
 <div class="footer"><p>Powered by <a href="http://www.aadhocc.co.uk/" target="_blank">Aadhocc</a></p></div>
 
</div>
<div class="quicLInksCover">
 <?php 
	include("leftlink.php");
?>

</div>
</body>
</html>