<?
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['jar_del'];		
	$jarno = $_REQUEST['qty'];
	$clientids = $_REQUEST['clientids'];
	$jaramount = $_REQUEST['amt'];
	
	
	mysql_query("update cf_stock set `stock_jar`=`stock_jar`+$jarno");
	
	$reselleres = mysql_query("select * from cf_ledger where ledgertype = 'clientledger' and empid = '$clientids'");
	$resellrw = mysql_fetch_array($reselleres);
	$ledgerids = $resellrw['ledgerid'];
	
	mysql_query("update cf_accountsreceivable set `receiveamount`=`receiveamount`-$jaramount where ledgerid=$ledgerids"); 
	
	$sql=mysql_query("delete from cf_jar_purchase where jar_purchase_type ='jar_sales' and jar_id='$id'");
	
	$acc_ref1=mysql_query("select account_reference from cf_purchase_account where ven_client_id = '1134' and  purchaseid ='$id'");
	$acc_refrow1=mysql_fetch_array($acc_ref1);
	$acc_ref= $acc_refrow1['account_reference'];
	
	$sql=mysql_query("delete from cf_purchase_account where account_reference = '$acc_ref' and ven_client_id = '$ledgerids' and purchaseid ='$id'");
	$sql=mysql_query("delete from cf_purchase_account where ven_client_id = '1134' and  purchaseid ='$id'");
	
	
	header("location:jar_sales_list.php?msg=You Have Successfully Deleted");
}
?>

<!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 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;
	}
	
$(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 Searchdate(page,val)
{ 
 	
	 var page=page;	
	 var vendortype='';
	 var fromdate='';
	 var todate='';
	 
	 if(document.kopra_frm.vendortype){
	 vendortype= document.kopra_frm.vendortype.value;
	 } 
	 
	 if(document.kopra_frm.from_date){
	 fromdate= document.kopra_frm.from_date.value;
	 }
	 
	 if(document.kopra_frm.to_date){
	 todate= document.kopra_frm.to_date.value;
	 }
	 
	
	 
	var strURL="ajax/jar_sale_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>Jar Sales List</h1>
   
   <form name="kopra_frm" id="kopra_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</p>
     <select name="vendortype" class="input1">
         <option value="">-Select Client-</option>
		 <?php 
		 $sq_resell=mysql_query("select * from cf_client"); 
		 while($resel=mysql_fetch_array($sq_resell))
			{
		?>
			<option value="<?=$resel['client_id']?>" ><?=$resel['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>
   </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; ">
  <tr class="heading">
    <td>No</td>    
    <td>Client Name</td>
	<td>Date</td>
	<td>Type</td>
	<td>No of Jar </td>  
	<td>Per Jar Rate</td>    
    <td>Amount</td>    
	<!--<td align="center">Edit</td>-->
    <td align="center">Delete</td>
  </tr>
  
  <?php

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

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


$sq_arr.=" order by jar_id desc ";


//calcutate total
$grandTot = 0;
$jarSaleLists =mysql_query($sq_arr);
if($jarSaleLists && mysql_num_rows($jarSaleLists)>0){
while($val =mysql_fetch_array($jarSaleLists))
{
	$grandTot += $val['jar_amount'];
}
}
echo '<div style="margin-left:22px;margin-top:22px;"><strong >'.('Grand Total : '.$grandTot).'</strong></div>';
//////

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

 $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'] == 'jar_sales')
		{
			$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 date(('d-m-Y'),strtotime($res['date']));?></td>  
	 <td><?php echo "Jar Sales";  ?></td>
	 <td><?php echo $res['jar_no'];?></td>  
	 <td><?php echo $res['jar_per_rate'];?></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_sales_list.php?jar_del=<?=$res['jar_id']?>&qty=<?=$res['jar_no']?>&clientids=<?=$res['jar_clientid']?>&amt=<?=$res['jar_amount']?>&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>Total</td>
	 <td></td>
	 <td></td>
	 <td></td>
     <td><?=$totjar_no?></td>     
     <td>&nbsp;</td>     
    
     <td><?=$totjar_amount?></td>
     <td></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>
