<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}
$parent_name='';
$ledger_name='';
$veh_num='';
$sdate_12 ='';
$page='1';
include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();
$msg = '';


if(isset($_REQUEST['lederid']) && $_REQUEST['lederid']!=''){
$lederid=$_REQUEST['lederid'];
}
else
{
$lederid=0;
}

//-------------from date --------------//
if(isset($_REQUEST['from_date']) && $_REQUEST['from_date']!=''){
$from_date=date('d-m-Y',strtotime($_REQUEST['from_date']));
}
else
{
$from_date=date('d-m-Y');

}
//----------------To date-------------------//
if(isset($_REQUEST['to_date']) && $_REQUEST['to_date']!=''){
$to_date=date('d-m-Y',strtotime($_REQUEST['to_date']));
}
else
{
$to_date=date('d-m-Y');
}

?>

<!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" />
<style>
.newcategoryProfile{ background:#FFFFFF; position:absolute; width:400px; height:250px; z-index:5;
					-webkit-box-shadow: 0px 0px 35px 1px rgba(0,0,0,0.75);
					-moz-box-shadow: 0px 0px 35px 1px rgba(0,0,0,0.75);
					box-shadow: 0px 0px 35px 1px rgba(0,0,0,0.75);}


</style>
<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">

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

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

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

$(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(val)
{ 
 	
	 var page=val;	
	 var ledger_name='';
	 var fromdate='';
	 var todate='';
	
	 	
	 if(document.ledg_frm.lederid){
	 ledger_name= document.ledg_frm.lederid.value;
	 }
	 
	 if(document.ledg_frm.from_date){
	 fromdate= document.ledg_frm.from_date.value;
	 }
	 
	 if(document.ledg_frm.to_date){
	 todate= document.ledg_frm.to_date.value;
	 }
	 
	 	
	var strURL="ajax/account_ledger_parent_data.php?&page="+page;
	if(ledger_name!=''){
	strURL+="&ledger_name="+ledger_name;
	}
	
	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);
   }
 
   
}
$(document).ready(function() {
			   
	$('a.login-window').click(function() {
		
		//Getting the variable's value from a link 
		var loginBox = $(this).attr('href');

		//Fade in the Popup
		$(loginBox).fadeIn(300);
		var id = $(this).find('input[type="hidden"]').val();
		
		add_account(id);
		//Set the center alignment padding + border see css style
		//var popMargTop = ($(loginBox).height() + 24) / 2; 
		//var popMargLeft = ($(loginBox).width() + 24) / 2; 
		var popMargTop = '202'; 
		var popMargLeft = '302'; 
		$(loginBox).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		// Add the mask to body
		$('body').append('<div id="mask"></div>');
		$('#mask').fadeIn(300);
		
		return false;
	});
	
	// When clicking on the button close or the mask layer the popup closed
	$('a.close, #mask').live('click', function() { 
	  $('#mask , .login-popup').fadeOut(300 , function() {
		$('#mask').remove();  
	}); 
	return false;
	});
});

function add_account(){
	
		$.ajax({
		method: 'POST',
		<!--url: 'http://192.168.1.43/FrameWorks/TravancoWebsite/TravancoAdmin/TravancoFinance/viewreceipt/'+empid,-->
		url:'http://192.168.1.41/oilfill/ajax/addledger.php',
		success: function(msg){
			//alert(msg);
			if(msg){
				$("#view_emp").html(msg).show();
				$('#pay_date').datepicker({
					showOn: 'both',
					buttonImage: 'icons_date/calendar.gif',
					buttonImageOnly: true,
					changeMonth: true,
					changeYear: true,
					dateFormat: 'dd-mm-yy'
					});
			}
		}
		});
	}
	
// JavaScript Document
$(document).ready(function() {
						   
					   
	$(document).on('click','a.login-update',function() {
		
		//Getting the variable's value from a link 
		var loginBox = $(this).attr('href');

		//Fade in the Popup
		$(loginBox).fadeIn(300);
		var id = $(this).find('input[type="hidden"]').val();
		
		edit_account(id);
		//Set the center alignment padding + border see css style
		//var popMargTop = ($(loginBox).height() + 24) / 2; 
		//var popMargLeft = ($(loginBox).width() + 24) / 2; 
		var popMargTop = '202'; 
		var popMargLeft = '302'; 
		$(loginBox).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		// Add the mask to body
		$('body').append('<div id="mask"></div>');
		$('#mask').fadeIn(300);
		
		return false;
	});
	
	// When clicking on the button close or the mask layer the popup closed
	$('a.close, #mask').live('click', function() { 
	  $('#mask , .login-popup').fadeOut(300 , function() {
		$('#mask').remove();  
	}); 
	return false;
	});
});

function edit_account(id){

		$.ajax({
		method: 'POST',
		<!--url: 'http://192.168.1.43/FrameWorks/TravancoWebsite/TravancoAdmin/TravancoFinance/viewreceipt/'+empid,-->
		url:'http://192.168.1.41/oilfill/ajax/addledger.php?editid='+id,
		success: function(msg){
			//alert(msg);
			if(msg){
				$("#view_emp").html(msg).show();
				$('#pay_date').datepicker({
					showOn: 'both',
					buttonImage: 'icons_date/calendar.gif',
					buttonImageOnly: true,
					changeMonth: true,
					changeYear: true,
					dateFormat: 'dd-mm-yy'
					});
				
				
			}
		}
		});
	}


</script>
</head>

<body>
<!------------------popup area (view, edit)--------------->



<!---------------popup area ends------------------>
<div class="viewEmployeePopup login-popup"  id="login-box" style="height: 220px;width:500px;
overflow-x: scroll;">
    <a href="#" class="close">
    <img src="images/close.png" class="btn_close" title="Close Window" alt="Close" />
    </a>
    <div id="view_emp"></div>
</div>
<div class="wrapper">
  <div>
<?php 
	include("header.php");
?>
 
</div>
 
 <div class="tabbedArea">
   
  <div class="tabBody">
   <h1>A/c Receivable Ledger List</h1>
   <form name="ledg_frm" id="ledg_frm" method="post"  >
   <div class="searchBox" style="width:93%; margin-right:0px;  padding:0px; ">
   <div align="left">
   <div style="padding:20px;">
      <div class="searchField" style="width: 250px;">
	   <p class="input1">Ledger</p>
	  <select class="chzn-select restselect input1 received_to" name="lederid" required="required" >
     <option value="">Select Ledger</option>
       <?php 
         //$sq_tripno="select * from cf_ledger where ledgertype != 'bankledger' and ledgerid != '195'";
		 $sq_tripno="select * from cf_ledger where groupid = '22'";
   $arrtripno1=mysql_query($sq_tripno);
   while($restripno=mysql_fetch_array($arrtripno1))
   {
  ?>
   <option  value="<?=$restripno['ledgerid']?>"  <?php if($lederid == $restripno['ledgerid']){?> selected="selected"<?php } ?> ><?=$restripno['ledgername']?></option>
        <?php
    }
  ?>
     </select>
    </div>
    <div class="searchField">
     <p class="input1">From Date</p>
    		<input type="text" name="from_date" id="from_date"  class="slabinput input1" style="width:70px;" value="<?=$from_date?>" required="required"/></td>

    </div>
   
    <div class="searchField">
     <p class="input1">To Date</p>
    		<input type="text" name="to_date" id="to_date"  class="slabinput input1" style="width:70px;" value="<?=$to_date?>" required="required"/></td>

    </div>
    
    
    
   
    
    <!--<div class="searchField">
     <p class="input1">Concerned Person</p>
     <input type="text" name="con_person" id="con_person" class="input1" />
    </div>
    
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">From Date</p>
     <input type="text" name="fromdate" id="fromdate" class="input1" />
    </div>
    
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">To Date</p>
     <input type="text" name="todate" id="todate" class="input1" />
    </div>-->
       
    <div class="searchField">
     <input name="button" type="button" class="input1" onClick="Searchdate(1);" value="search" />
    </div>
  </div>
   </div>
   </div>
   </form>
   <div id="popup" align="center"  style="margin-left: 400px;"></div>
   <div id="list">
   <table  border="0" cellspacing="0" cellpadding="0" class="tableList">
  <tr class="heading">
    <td>No</td>    
    <td>Ledger Name</td>    
    <td>Group Name</td>
	<!--<td>Opening Balance</td>-->
    <td>Amount</td>
   <!-- <td>Delete</td>-->
  </tr>
  
  <?php


/*
if(isset($_REQUEST['typename'])){
$typenames=$_REQUEST['typename'];
}*/

$i=1;

	
	   $sq_arr="SELECT a.*,b.category as parent
    FROM cf_ledger a
        LEFT JOIN cf_account_groups b
            ON b.id = a.groupid
    WHERE a.status = '1'";



if(isset($_REQUEST['ledger_name']) && $_REQUEST['ledger_name']!=''){
$ledger_name=$_REQUEST['ledger_name'];
$sq_arr.="and   a.ledgername like '%".$ledger_name."%'";
}
//if(isset($_REQUEST['parent_name']) && $_REQUEST['parent_name']!=''){
//$parent_name=$_REQUEST['parent_name'];
$sq_arr.="and   a.groupid='22'";
//}

$sq_arr.=" order by a.ledgerid asc ";
$query=$sq_arr;
$function="Searchdate";
include("pagingserch.php");
 $sq_arr.=" LIMIT $start, $limit";

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

$array=mysql_query($sq_arr);
if($array && mysql_num_rows($array)>0){
$pagecnt=$start;
while($res=mysql_fetch_array($array))
{
	$cumulative= '';
	$ledgerid = $res['ledgerid'];
$cond = "and b.ledgerid = '$ledgerid' "; 

if(isset($_REQUEST['from_date']) && $_REQUEST['from_date']!=''){
$from_date=date('Y-m-d',strtotime($_REQUEST['from_date']));
$cond.=" and   a.pay_date >= '$from_date'";
}
if(isset($_REQUEST['to_date']) && $_REQUEST['to_date']!=''){
$to_date=date('Y-m-d',strtotime($_REQUEST['to_date']));
$cond.=" and   a.pay_date <= '$to_date'";
}


	$sq_arr11="select * from (SELECT a.transaction_bank  as toid,0 as acctype,a.pay_date as pay_date,a.amount as amount,a.reciept_id as reciept_id,a.purpose as purpose,0 as ref,b.ledgername as ledgername, 1 as type 
    	  FROM cf_reciept a
          LEFT JOIN cf_ledger b ON b.ledgerid = a.from where 1 ".$cond."
          UNION SELECT a.transaction_bank  as toid,0 as acctype,a.pay_date as pay_date,a.amount as amount,a.voucher_id as reciept_id,a.purpose as purpose,0 as ref,b.ledgername as ledgername, 2 as type 
          FROM cf_voucher a
          LEFT JOIN cf_ledger b ON b.ledgerid = a.to where 1 ".$cond."
		  
	UNION SELECT a.journal_id as toid,a.account_type as acctype,a.pay_date as pay_date,a.amount as amount,a.ref_no as reciept_id,a.purpose as purpose,a.journal_reference as ref,b.ledgername as ledgername, 3 as type 
		  FROM cf_journal a 
		  LEFT JOIN cf_ledger b ON b.ledgerid = a.crd_dbt where 1  ".$cond."
		  
		  UNION SELECT  a.pur_acc_id as toid,a.account_type as acctype,a.pay_date as pay_date ,a.acc_amount as amount,a.account_reference as reciept_id,b.ledgername as purpose,0 as ref,b.ledgername as ledgername, 4 as type FROM cf_purchase_account a 
			LEFT JOIN cf_ledger b ON b.ledgerid = a.ven_client_id where 1 ".$cond. " )  k order by k.pay_date ASC";
	
	if($res['cr_dt'] == 1)
	{
		$cumulative= 0-$res['opening_balance'];
	}
	else
	{
		$cumulative= $res['opening_balance'];
	}
	//$cumulative= $res['opening_balance'];
	$sq_arr12=mysql_query($sq_arr11);
	while($rws = mysql_fetch_array($sq_arr12))
	{
	if($rws['type'] ==1 ){
	$cumulative=$cumulative-$rws['amount'];
	?>
	
	<?php } ?>
	<!--------for voucher---------------->
	<?php if($rws['type'] ==2 ){
	$cumulative=$cumulative+$rws['amount'];
	?>
	
	
	<?php } ?>
	<!--------for journal---------------->
	<?php if($rws['type'] ==3 )
	{ 
	if($rws['acctype'] ==1){
	$cumulative=$cumulative-$rws['amount'];
	?>
					

	<?php } else {
	$cumulative=$cumulative+$rws['amount'];
	?>
	 	
	<?php } 
	}?>
	
	<!--------for Purchase---------------->
	<?php if($rws['type'] ==4 )
	{ 
	if($rws['acctype'] ==1){
	$cumulative=$cumulative-$rws['amount'];
	?>
		
				

	<?php } else {
	$cumulative=$cumulative+$rws['amount'];
	?>
	 	
	<?php } 
	}

}
//echo $sq_arr11;
//echo "<br/>------------------------------------";

$pagecnt++;


  ?> 
  <tr>
    <td><?php echo $pagecnt;?></td>
    <td><?php echo $res['ledgername'];?></td>
    <td><?php echo $res['parent'];?></td>
    <?php /*?><td><?php echo $res['opening_balance'];?></td><?php */?>
	<td><?php echo $cumulative;?></td>
   <?php /*?><td class="tr_td_b"> <a href="#login-box" class="login-update" style="font-weight:bold;" data-type=<?php echo $res['ledgerid'];?>><img src="images/edit.png" title="edit"><input type="hidden" name="acc_id" id="acc_id<?php echo $res['ledgerid'];?>" value="<?php echo $res['ledgerid'];?>" /></a></td><?php */?>
   
   <!--<td class="tr_td_r" ><a href="account-ledger.php?del=delete&id=<?php// echo $res['ledgerid']; ?>" onClick="return confirm('Do you really want to delete this field?');"><img src="images/delete.png" title="delete"></a></td>-->
    
   
  </tr>
  <?php 
    }}
  ?>
 
  <!--<tr>
    <td><input type="checkbox">2</td>
    <td>2323d</td>
    <td>jinesh</td>
    <td>jose</td>
    <td>9443274636</td>
    <td>email@gmail.com</td>
    <td>design</td>
    <td>designer</td>
    <td>23/4/11</td>
    <td><div class="deletedStat"></div></td>
    <td><a href="#">
      <div class="actEdit"></div><div class="actDelete"></div>
    </a></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>
