<?
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['sales_del'];
	
	$sqlsale = mysql_query("select * from cf_sales_sub where sale_id ='$id' ");
	while($rwsale = mysql_fetch_array($sqlsale))
	{
		$packsale_box = $rwsale['sale_box'];
		$packsale_no_tin_kg = $rwsale['sale_no_tin_kg'];
		$branchid = $rwpack['branch_id'];
		$literid = $rwpack['liter_id'];
		
		$sqlsku = mysql_query("select * from cf_sku_stock where brnd_id = '$branchid' and ltre_id = '$literid'");
		$rwsku = mysql_fetch_array($sqlsku);
		
		$skupackqty = $rwsku['packqty'];
		$skupackbox = $rwsku['packbox'];
		$updtpackqty = $skupackqty - $packqty;
		$updtpackbox = $skupackbox - $packbox;
		mysql_query("update cf_sku_stock set packqty = '$updtpackqty',packbox='$updtpackbox' where brnd_id = '$branchid' and ltre_id = '$literid'");
		
		//echo "update cf_sku_stock set packqty = '$updtpackqty',packbox='$updtpackbox' where brnd_id = '$branchid' and ltre_id = '$literid'";
		//echo "<br/>";
	
	}
	
	$sql=mysql_query("delete from cf_sales where sales_id='$id'");
	header("location:sales-list.php?msg=You Have Successfully Deleted");
}

function print1($selectype,$clientname)
			{
			
				//$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 Receivable</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>Client 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>Total Recievable</strong></td>
							
							
  					</tr>
					';
				
				$sq_arr_print="SELECT  cf_accountsreceivable.*,cf_client.client_name from  cf_accountsreceivable
inner JOIN cf_client ON cf_client.client_id = cf_accountsreceivable.clientid";

				if($clientname!=''){
				$sq_arr_print.=" and cf_accountsreceivable.clientid = '".$clientname."' ";
				}


				$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['client_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['receiveamount'].'</td>
				
					
				</tr>';
				 
				 $i++;}
			
				$outstr.= ' </table>
		</div>'; 
				echo $outstr;
				exit;
				
			}
			
			
				
			if(isset($_POST['download']))
			{
				$selectype = "Accounts Receivable";
				$clientname = $_POST['clientname'];
								
				print1($selectype,$clientname);
			}

?>

<!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>

<link rel="stylesheet" href="css/chosen.css">

<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 src="js/popup_sales.js" type="text/javascript"></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'
});
});

</script>
<script language="javascript">
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 saletype='';
	 var fromdate='';
	 var todate='';
	 
	 if(document.sales_frm.clientname){
	 clientname= document.sales_frm.clientname.value;
	 } 
	 
	 if(document.sales_frm.from_date){
	 fromdate= document.sales_frm.from_date.value;
	 }
	 
	 if(document.sales_frm.to_date){
	 todate= document.sales_frm.to_date.value;
	 }
	 
	 
	var strURL="ajax/acreceivable_list_data.php?&page="+page;
		
		if(clientname!=''){
		strURL+="&clientname="+clientname;
		}
			
		if(fromdate!=''){
		strURL+="&fromdate="+fromdate;
		}
			
		if(todate!=''){
		strURL+="&todate="+todate;
		}
	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>
<!------------------popup area (view, edit)--------------->

<div class="viewEmployeePopup login-popup"  id="login-box" style="width:800px;height:400px;">
<a href="#" class="close"><img src="images/close.png" class="btn_close" title="Close Window" alt="Close" /></a>
   <div id="popupid"></div>
   
     
    </div>

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

  
  <div class="tabBody">
   <h1>Accounts Receivable </h1>
   
   <form name="sales_frm" id="sales_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">Client Name</p>
     <select name="clientname" id="clientname" class="chzn-select restselect input3">
         <option value="">-Select Client-</option>
		
		
	 <?php
	 	$cf_drop="select * from cf_client ";
		$cf_array=mysql_query($cf_drop);
		if($cf_array && mysql_num_rows($cf_array)>0)
		{
		 	while($cf_res=mysql_fetch_array($cf_array))
			{
			
			?>
			<option value="<?=$cf_res['client_id']?>"><?=$cf_res['client_name']?></option>
			
			<?php
			}
		} 
	 ?>
     </select>
    </div>
     
    <!--<div class="searchField" style="padding-left:20px;">
     <p class="input1">From Date</p>
     <input type="text" name="from_date" id="from_date" style="width:75px;" maxlength="100" class="input1" />
    </div>-->
    
   <!-- <div class="searchField" style="padding-left:20px;">
     <p class="input1">To Date</p>
     <input type="text" name="to_date" id="to_date" style="width:75px;" maxlength="100" class="input1" />
    </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 = '';
$grandtotsales ='';
$i=1;


$sq_arr="SELECT  cf_accountsreceivable.*,cf_client.client_name from  cf_accountsreceivable
inner JOIN cf_client ON cf_client.client_id = cf_accountsreceivable.clientid
";

$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;
}
$totalrecievable=0;
$nolimitarray=mysql_query($nolimitqry);
if($nolimitarray && mysql_num_rows($nolimitarray)>0)
{
while($nolimitres=mysql_fetch_array($nolimitarray))
{
$totalrecievable=$totalrecievable+$nolimitres['receiveamount'];
}
}
?>



  <tr class="heading">
    <td>No</td>    
   
    <td>Client Name</td>
	<td>Total Recievable</td>    
    <td align="center">Receipt</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['client_name'];?></td>     
    <td><?php echo $res['receiveamount'];?></td> 
	
    <td align="center" class="tr_td_r" ><a href="reciept-form.php?reciepttype=accopbal&clientid=<?=$res['clientid']?>&amt=<?=$res['receiveamount']?>&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 $totalrecievable;?></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>
<!----------------------- script for autocomplete------------------------------>
		<script src="js/chosen.jquery.min.js" type="text/javascript">
		</script>
		<script type="text/javascript"> 
			$(".chzn-select").chosen({search_contains: true}); 
		</script>

<!----------------end of script -------------------------------->
</html>
