<?php
error_reporting(0);
?>
<link href="css/accountbook_css.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Account Book</h1> 
<script>
$(document).ready(function(){
	$('.having1').change(function(){
		$.ajax({url:'ajax_get_search_criteria.php?id='+$(this).val(),method:'post',success:function(result){
			$('#range_of_info1').html(result);
		}});
	});
	$('form[name="main_account"]').submit(function(){
		if($('.having1').val()!='0')
		{
			if($('#range_of_info1').val()=='0')
			{
				alert("Please Select the Range");
				$('#range_of_info1').focus();
				return false;
			}	
			else
			{
				if($('input[name="searchtext"]').val()=='')
				{
					alert("Please Fill the searching text");
					$('input[name="searchtext"]').focus();
					return false;
				}
			}
		}
	});

})
</script>

<?php extract($_POST);
//echo "manvi----".ini_get('mysql.connect_timeout');
$PageSecurity = 1;
$tabindex=0;
include('includes/Class_AccountBook.php');
include('includes/AccountGroupMaster_Class.php');
$title = _('Account Book');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;
 include('includes/SQL_CommonFunctions.inc');
 function CategoryShow($pcode, $PcateID, $dashVal )
	{
	    global $db;
		static $i=0;;
		 
 	    $sqlCate = "select * from accountgroupmaster  where  MainGroupId = '".$PcateID."'";
 		$rsCate  = DB_query($sqlCate,$db);	
 		if(DB_num_rows($rsCate)>0)
		{
			while($rowCate = DB_fetch_array($rsCate))
			{
  				  $arr1[]=$rowCate['GroupId'];
 				  CategoryShow($pcode,$rowCate['GroupId'], $dashVal);
 			}
 		}
	//print_r($arr1);
		return($arr1);
	}
?>
<script >
function getLedgerName(str)
    {
	  $('.modal22').show();
      if(str!=0)
      {
	   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)
		{  $('.modal22').hide();
          //alert(xmlhttp.responseText);
         document.getElementById("ledgerid").innerHTML=xmlhttp.responseText;
	     
	     }
	      
		}
	
	
	xmlhttp.open("GET","check_data_fin.php?section=Drledgername&site="+str,true);
	xmlhttp.send();
  }
}

function validation()
{
	if(document.getElementById("ledgerentry").value=='1' || document.getElementById("ledgerentry").value=='4')
	{
	  if(document.getElementById("ledgerid").value=='0')
	  {
	  	alert("Please Select Ledger");
        return false;
        document.getElementById("ledgerid").focus();
      }
	}
	
 todate =document.getElementById("todate").value;
 fromdate =document.getElementById("fromdate").value;
 if(todate=='' || fromdate=='')
 {
 alert("Please Select From and To date");
 return false;
 } 
 return true;
}
</script>

<style type="text/css">
.modal22 {
	display: none;
	position: fixed;
	z-index: 1000;
	top: 0;
	left: 0;
	height: 100%;
	width: 100%;
	background: rgba( 105, 105, 105, .4 )50% 50%no-repeat;
}
</style>
 
<div id="container">
	<div class="modal22"><center><div style="font-size:50px;margin-top:200px;">Loading...</div></center></div>
  <div id="tabs">
    <ul>
	<?php 
	 $GetRecord = "Select * from voucher_master where Vprefix  not in('CBJ','MEMO','ChRet','Purchase','Invoice') order by GroupName  ";
  	 $ResultData = DB_query($GetRecord,$db);
	 $j=0;
   	 while($RowData = DB_fetch_array($ResultData))
	 {	 
	   $arrBook[]=$RowData['VoucherType'];
	  // $arrBook=array('Ledger','Bank','Cash','Contra');
	  if($_REQUEST['tabid']==$j)
 	     $bg= "style='background-color:#CCC'";
		 else $bg="";
  	if($RowData['GroupName']=="Purchase Bill Book"){
  	?>
    <li><a href="index.php?route=Account/AccountBook_new<?php echo $rurl;?>&tabid=<?php echo $j?>&AcType=<?php  echo "purch";?>"><?php echo $RowData['GroupName'];?></a></li>
	<?php }else{ ?>
	<li><a href="index.php?route=Account/AccountBook_new<?php echo $rurl;?>&tabid=<?php echo $j?>"><?php echo $RowData['GroupName'];?></a></li>
	<?php } ?>
	<?php  $j++;
	} 
	 $arrBook[]='Day';
	 $arrBook[]='Ledger';  
	 $rx=array('DayBook','Ledger'); 
	 for($kl=$j,$k=0;$k<2;$k++){
	 if($_REQUEST['tabid']==$kl)
 	 $bg= "style='background-color:#CCC'";
	 else $bg="";
	?>
	<li<?php //print_r($rx[$k])?> >
	<a href="index.php?route=Account/AccountBook_new<?php echo $rurl;?>&tabid=<?php echo $kl++?>&AcType=<?php  echo $rx[$k];?>"><?php  echo $rx[$k];?> <?php echo ($rx[$k]!="DayBook")?"Book":""; ?></a></li>
	<?php }?>	
    </ul>
 
	<?php 	
	//echo "<pre>";
	//print_r($arrBook);
for($j=0,$i=0;$i<count($arrBook);$i++,$j++){	
if($_REQUEST['Search'])
{	
	  	//echo "<pre>";
	  	//print_r($_REQUEST);
	  	//$s->getField('account_book_search_criteria_details','id',$_REQUEST['range_of_info'],'operator');
	  //	exit;
 		$_SESSION['ledgerid']=$_REQUEST['ledgerid'];
		$ledgerid=$_SESSION['ledgerid'];
		
		$vendorid=$s->getField('accountledger','AccountsID',$ledgerid,'vender_client');
                 $_SESSION['vender']=$vendorid;
		//echo $_SESSION['ledgerid'];
 		//echo $_REQUEST['ledgerentry'];
		$_SESSION['ledgerid']=$_REQUEST['ledgerid'];
		$getLedgerName=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerid."'" ,'AccountName');
		
		$Viewtype=$_REQUEST['Viewtype'];
		$_SESSION['Viewtype']=$_REQUEST['Viewtype'];
		$_SESSION['ledgerentry']=$_REQUEST['ledgerentry']; 
		
		$todate=FormatDateForSQL($_REQUEST['todate']) ;
		$fromdate=FormatDateForSQL($_REQUEST['fromdate']) ;

		$_SESSION['todate']=$_REQUEST['todate'];
		$_SESSION['fromdate']=$_REQUEST['fromdate'];
		
		/////Alternative - Date Format was clashing in the online version/////
		$todate_new=$_REQUEST['todate'];
		$fromdate_new=$_REQUEST['fromdate'];
		$fromdate_brk=explode('/',$fromdate_new);
		$fromdate_1=$fromdate_brk[2]."-".$fromdate_brk[1]."-".$fromdate_brk[0];
		$todate_brk=explode('/',$todate_new);
		$todate_1=$todate_brk[2]."-".$todate_brk[1]."-".$todate_brk[0];
		//////////////////////////////////////////////////////////////////////
		
		if($_REQUEST['site']=='0')
		{
		$site_data=array();
		$sql_site=DB_query("select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
		while($row_site=DB_fetch_array($sql_site))
		{
		$site_data[]=$row_site['loccode'];
		}
		$site_data1=implode("','",$site_data);
		$site_branch="Branch in('".$site_data1."')";
		$site_branch1="site in('".$site_data1."')";		
		}
		else
		{
		$site_branch="Branch='".$_REQUEST['site']."'";
		$site_brach1="site='".$_REQUEST['site']."'";
		}
		if($_REQUEST['site']=='0')
		{
		$sitedata=implode("','",explode(",",$_SESSION['UserSites']));
		
		}
		else
		{
		$sitedata=$_REQUEST['site'];
		}

		
		//print_r($arrBook);
		//echo $arrBook[$i];
		//echo "<br />".$_REQUEST['tabid'];
		if($_REQUEST['AcType']!='DayBook' && $_REQUEST['AcType']!='Ledger' && $_REQUEST['AcType']!='purch'){
		 	
		  $cash_recipt_sql=DB_fetch_assoc(DB_query("select VoucherType from voucher_master where VPrefix='CR'",$db));
		 // echo $cash_recipt_sql['VoucherType'];
		  
		 
		if($_REQUEST['having']!='0')
		{
		  	   	$caption=$s->getField('account_book_search_criteria','id',$_REQUEST['having'],'caption');
		  	    $start_operator=$s->getField('account_book_search_criteria_details','id',$_REQUEST['range_of_info'],'start_operator');
		  	    $end_operator=$s->getField('account_book_search_criteria_details','id',$_REQUEST['range_of_info'],'end_operator');
		  	    $caption1="A.$caption";
		  	    	
		  	    	if($_REQUEST['having']=='2' && ($_REQUEST['range_of_info']=='10' || $_REQUEST['range_of_info']=='11'))
		  	 		{ $val=explode('-',$_REQUEST['searchtext']);
		  	 		  $val1=$val[2]; 
		  	 		  $oper=DB_fetch_assoc(DB_query("select REPLACE(start_operator,'str11','substring_index') AS start_operator, end_operator FROM account_book_search_criteria_details where id='".$_REQUEST['range_of_info']."'",$db));
		  	 		  $start_operator=$oper['start_operator'];
		  	 		  $end_operator=$oper['end_operator'];
		  	 		  $caption1="";
		  		  	}
		  		  	elseif($_REQUEST['having']=='6' && ($_REQUEST['range_of_info']=='8' || $_REQUEST['range_of_info']=='9'))
		  		  	{	
		  		  		$oper=DB_fetch_assoc(DB_query("select start_operator, end_operator FROM account_book_search_criteria_details where id='".$_REQUEST['range_of_info']."'",$db));
		  		  		$caption1="b.$caption";		
		  		  		 $start_operator=$oper['start_operator'];
		  	 		  $end_operator=$oper['end_operator'];
		  		  		$val1=$_REQUEST['searchtext'];
		  		  	}
		  		  	elseif($_REQUEST['having']=='6' && $_REQUEST['range_of_info']!='8' && $_REQUEST['range_of_info']!='9')
		  		  	{	
		  		  		$oper=DB_fetch_assoc(DB_query("select start_operator, end_operator FROM account_book_search_criteria_details where id='".$_REQUEST['range_of_info']."'",$db));
		  		  		$caption1="b.amount";		
		  		  		
		  		  		 $start_operator=$oper['start_operator'];
		  	 		  	$end_operator=$oper['end_operator'];
		  		  		$val1=$_REQUEST['searchtext'];
		  		  	}
		  		  	else
		  	 	   		$val1=$_REQUEST['searchtext'];		  	 
		  	    
		  	     $cond=" and $caption1$start_operator$val1$end_operator" ;
		  	     if($_REQUEST['having']=='7')
		  	     {
		  	     	$cond="";
		  	     }
		  	}
		  	else
		  	{
		  		$cond="";
		  	}
		  	     //echo $_SESSION['ledgerid'];
		  	  if($ledgerid!='0')
		  	  {
		  	       $GetRecord1="SELECT A.VPrefix  ,A.Voucher_NO ,A.id AS Pid, A.Dates FROM account_book A, account_book_details b WHERE A.id=b.account_bookid and A.Dates between  '".$fromdate_1."' and '".$todate_1."' and $site_branch
			            and A.VPrefix  ='".$arrBook[$i]."' and b.ledgerid='".$_SESSION['ledgerid']."' and A.cancel_status=0 ".$cond." group by A.Voucher_NO ORDER BY  A.Dates ASC";
			   }
			   else
			   {
			   	  $GetRecord1="SELECT A.VPrefix  ,A.Voucher_NO ,A.id AS Pid, A.Dates FROM account_book A, account_book_details b WHERE A.id=b.account_bookid and A.Dates between  '".$fromdate_1."' and '".$todate_1."' and $site_branch
			            and A.VPrefix  ='".$arrBook[$i]."' and A.cancel_status=0 ".$cond." group by A.Voucher_NO ORDER BY A.Dates ASC";
			   }  

			   $_SESSION['printaccountbook']=$GetRecord1;       

				 //echo $GetRecord1."<br>";
		}
		else if($_REQUEST['AcType']=='Day')
		{

		   if($Viewtype=='ALL')
		   { //echo "manvi";
				 $GetRecord1 = "SELECT  A.Vprefix,A.Voucher_NO ,A.id AS Pid, A.Dates   FROM `account_book` A where   A.Dates between  '".$fromdate_1."' and '".$todate_1."' and $site_branch and A.cancel_status=0 ORDER BY  A.Dates ASC"; 
				//$GetRecord2="Select * from purchase_billbook where site='".$_REQUEST['site']."' and bill_book_date between '".$todate_1."' and '".$fromdate_1."'";
		   }else
		  {
		 	$GetRecord1 = "SELECT  A.Vprefix,A.Voucher_NO ,A.id AS Pid, A.Dates ,B.* ,(B.amount) AS AMT  FROM `account_book` A, account_book_details B where   Dates between  '".$fromdate_1."' and '".$todate_1."' and $site_branch  and A.id=B.account_bookid and A.cancel_status=0  order by B.account_bookid ASC ,B.amount_type DESC";
		  }
		    
		}
		else if($_REQUEST['AcType']=='Ledger' )
		{

	 	$ledgertype=$s->getField('accountledger','AccountsID',$_REQUEST['ledgerid'],'ledgertype');
        
        if($ledgertype=='scess')
        {
         $master_tax_id=$s->getField('accountledger','AccountsID',$_REQUEST['ledgerid'],'taxid'); 
        }
       

		if($arrBook[$i]=='Ledger')
		{
			
			if($_REQUEST['site']=="0")
			{
				$con= " "; 
				$con1= " "; 
			}
			else
			{
				$con= " and  branch_name='".$_REQUEST['site']."' "; 
				$con1= " and  b.branch_name='".$_REQUEST['site']."' "; 
			}
			$GetRec ="SELECT A.VPrefix as Prefixtype,A.Voucher_NO ,A.id AS Pid, A.Dates FROM account_book A WHERE   A.Dates between  '".$fromdate_1."' and '".$todate_1."' and $site_branch and A.cancel_status=0   ORDER BY A.Dates ASC ";
			$ResultData5=DB_query($GetRec,$db);
			 $numrows5 = DB_num_rows($ResultData5);
			while($RowData5=DB_fetch_array($ResultData5))
			{
				$data_array[]=array('Pid'=>$RowData5['Pid'],'date'=>$RowData5['Dates'],'flag'=>'voucher','Voucher_NO'=>$RowData5['Voucher_NO'],'Vprefix'=>$RowData5['Prefixtype'],'type'=>'');
			}			
			
			

			if(!empty($data_array)){
			foreach ($data_array as $key =>$value)
    		{
    			$data_arrange[$key]= $value['date'];
			}
					
			array_multisort($data_arrange,SORT_ASC,$data_array);
			}
		}
		
	//$GetRecord1="SELECT A.VPrefix as Prefixtype,A.Voucher_NO ,A.id AS Pid, A.Dates FROM account_book A WHERE   A.Dates between  '".$todate_1."' and '".$fromdate_1."' and $site_branch and A.cancel_status=0   ORDER BY A.Dates ASC";
       
         }
		else if($_REQUEST['AcType']=='DayBook')
		 {
		 
		 	if($arrBook[$i]=='Day')
		   {

		   	if($_REQUEST['site']=='0')
		  		$site_con="";
		  	else
		  		$site_con="and branch_name='".$_REQUEST['site']."'";
				
			//$invoice_day_sql="select * from invoice where invoiceDate between  '".$todate_1."' and '".$fromdate_1."'".$site_con;
              // -      

			//********************************************************************************//

		    $GetRec ="SELECT  A.Vprefix ,A.Voucher_NO ,A.id AS Pid, A.Dates ,A.transation_date_and_time as transdate  FROM `account_book` A where   A.Dates between  '".$fromdate_1."' and '".$todate_1."'
		     and $site_branch and A.cancel_status=0 and VPrefix!=15  order by   A.Dates ASC,  A.id asc ";
			$ResultData5=DB_query($GetRec,$db);
			$numrows5 = DB_num_rows($ResultData5);
			while($RowData5=DB_fetch_array($ResultData5))
			{
				$data_array[]=array('Pid'=>$RowData5['Pid'],'date'=>$RowData5['Dates'],'flag'=>'voucher','Voucher_NO'=>$RowData5['Voucher_NO'],'Vprefix'=>$RowData5['Vprefix'],'transaction_date'=>$RowData5['transdate']);
			}
			
			/*if(!empty($data_array)){
				foreach ($data_array as $key =>$value)
	    		{
	    			$data_arrange[$key]= $value['date'];
				}
					
			array_multisort($data_arrange,SORT_ASC,$data_array);
			}*/

         //echo $GetRecord1;

			if(!empty($data_array)){
			foreach ($data_array as $key =>$value)
    		{
    			$data_arrange[$key]= $value['transaction_date'];
			}
					
			array_multisort($data_arrange,SORT_ASC,$data_array);
			}

			}	
		 
		 }	


	$_SESSION['SAl']=$GetRec;
	$_SESSION['SAl2']=$GetRec2;
	 $_SESSION['ACGAccountBookQuery']=$GetRecord1;  
	 $_SESSION['accountbookquery']=$get_recordbook;
	//echo "<br />".$GetRec;  
	//echo "<br />".$GetRec2;

	}
 if($_REQUEST['tabid']==$i){
 	$BillBookType= $s->getField('voucher_master','VoucherType',$arrBook[$i],'Vprefix');
	switch($BillBookType)
	 {
		case 'CP':
		case 'CR':
		$LDR=array('cash');
		break;
		case 'BP':
		case 'BR':
		$LDR=array('bank');
		break;
		case 'CON':
	    $LDR=array('cash','bank'); 
		break;		
		case 'JV':
		$LDR='';
		break;
		default: 				
		$LDR='';
		break; 				 				 		 
	 }	 
 
 ?> 

<div id="<?php echo $j?>" style="width:100%;">
 <h3>
<?php 
//echo $_REQUEST['AcType'];
if(isset($_REQUEST['AcType']))
{
	if($_REQUEST['AcType']=="purch")
	{
	echo "Purchase Bill";
	}
	else
	{
	echo $_REQUEST['AcType'];
	}
}
else
{?>
<?php  echo $VchName=$s->getField('voucher_master','VoucherType',$arrBook[$i],'GroupName')?>
 <?php 
 }?> <?php echo ($_REQUEST['AcType']!="DayBook")?"Book":""; ?></h3>

<form action="" name="main_account" method="post" onsubmit="return validation()">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
<td width="13%" align="right">Branch</td>
<td width="20%"><select name="site"  onchange="getLedgerName(this.value);">
 <!-- <option value="0">All</option> -->
  <?php 
 	   $ss="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'"; 
$site_sql=DB_query($ss,$db);
while($site_row=DB_fetch_array($site_sql))
{?>
  <option value="<?php echo $site_row['loccode'];?>"<?php echo($_REQUEST['site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
  <?php 	
}
?>
</select></td>
<td width="13%" align="right">Ledgers</td>
<td width="20%">
<select name="ledgerentry" id="ledgerentry" >
<?php if($_REQUEST['AcType']=="Ledger" || $_REQUEST['AcType']!="DayBook") {?>
<option value="1" <?php if($_SESSION['ledgerentry']==1) { ?> selected="selected" <?php } ?>>Single Entry With Narrations</option>
<option value="4" <?php if($_SESSION['ledgerentry']==4) { ?> selected="selected" <?php } ?>>Single Entry </option>	
<?php } if($_REQUEST['AcType']=="DayBook" || $_REQUEST['AcType']!="Ledger") {?>
<option value="2" <?php if($_SESSION['ledgerentry']==2) { ?> selected="selected" <?php } ?>>Double Entry With Narrations </option>
<option value="3" <?php if($_SESSION['ledgerentry']==3) { ?> selected="selected" <?php } ?>>Double Entry </option>
<?php } ?>	
</select>	
</td>
<?php if($_REQUEST['AcType']!='DayBook' ){ ?><?php
 	if($LDR!=''){
	$LRX=implode("|",$LDR);		
	  $sqlCate = "select * from  accountgroupmaster  where    GroupName like '%$LRX' ";
		$rsCate  = DB_query($sqlCate,$db);
		if(DB_num_rows($rsCate)>0)
		{
			while($rowCate =DB_fetch_array($rsCate))
			{
 			$arr1[]=$rowCate['GroupId'];
  			//$arr1[]= CategoryShow($pcode, $rowCate['GroupId'], $dashVal );
 			}
		}
		$rx=array();
		for($l=0;$l<count($arr1);$l++)
		{
		// echo $arr1[$l].'<br>';
		 if(is_array($arr1[$l]))
		 $rx[]=implode(',',$arr1[$l]);
		 else
		  $rx[]=$arr1[$l];
			 
		}
		$undergroup= implode(',',$rx );
		}else{
		$undergroup='';	
		}		
	// if($_REQUEST['AcType']!='Day'&&  $_REQUEST['AcType']!='Ledger')
	?>
<td colspan="2">
	<select name="ledgerid" id="ledgerid" style="width:58%;">
	 <option value="0">ALL</option> 
	<?php 	
	   $test=$_REQUEST['site'];
		   $sqlVendor = DB_query("SELECT id FROM  suppliers 
                WHERE FIND_IN_SET('".$test."',site)",$db);
			if(DB_num_rows($sqlVendor)>0)
			{
				while($rowVendor =DB_fetch_array($sqlVendor))
				{
					 $arrV[]=$rowVendor['id'];
					//$arr3[]= CategoryShow($pcode, $rowCate['GroupId'], $dashVal );
				}
				          $arrV=array_unique($arrV);
                            if(count($arrV)>1)
                            {
                            $impV= implode(',',$arrV );
                            }
                            else
                            {
                            $impV=$arrV[0];
                            }                               
			}             
              
               if($test!='')   
               $sqlClient = DB_query("SELECT id FROM  clientmaster  WHERE FIND_IN_SET('".$test."',Site)",$db);
               else
               $sqlClient = DB_query("SELECT id FROM  clientmaster ",$db);	

			if(DB_num_rows($sqlClient)>0)
			{
				while($rowClient =DB_fetch_array($sqlClient))
				{
					 $arrC[]=$rowClient['id'];
					
				}
				 $arrC=array_unique($arrC);
                  if(count($arrC)>1)
                  {
                  $impC= implode(',',$arrC );}
                  else
                  {
                  $impC= $arrC[0];
                  }
			}

         if($impV!='')
         {
           $arrV_vendor='';
           $sqlVendor1= DB_query("SELECT AccountsID FROM  accountledger  WHERE vender_client in (".$impV.") 
           	and ledgertype='vendor'",$db);
			if(DB_num_rows($sqlVendor1)>0)
			{
				while($rowVendor1=DB_fetch_array($sqlVendor1))
				{
				 $arrV_vendor[]=$rowVendor1['AccountsID'];
					//$arr3[]= CategoryShow($pcode, $rowCate['GroupId'], $dashVal );
				}                           
                               
			}
		}		 
            
               $arrV_vendor=array_unique($arrV_vendor);
               if($impC!='')
		         {
		         $arrV_vendor_client='';
		           $sqlVendor2= DB_query("SELECT AccountsID FROM  accountledger 
		                WHERE vender_client in (".$impC.") and ledgertype='client'",$db);
					if(DB_num_rows($sqlVendor2)>0)
					{
						while($rowVendor2=DB_fetch_array($sqlVendor2))
						{
							 $arrV_vendor_client[]=$rowVendor2['AccountsID'];
							//$arr3[]= CategoryShow($pcode, $rowCate['GroupId'], $dashVal );
						}                        	                               
					}
				}

				 $arrV_vendor_client=array_unique($arrV_vendor_client);          

	             if(!empty($arrV_vendor_client) && !empty($arrV_vendor))
	             {
                 $array_account=array_merge($arrV_vendor_client,$arrV_vendor);

                 }
                  else if(!empty($arrV_vendor_client))
                	$array_account=$arrV_vendor_client;
                  else
                	$array_account=$arrV_vendor;               
                
                 if(!empty($array_account))
                 {
                 	$array_account=array_unique($array_account);
                  $array_account_id= implode(',',$array_account);
                 }
                             
              if(!empty($array_account_id))
              {

               	 $sqlVendor21= DB_query("SELECT AccountsID FROM  accountledger 
		                WHERE AccountsID  not in (".$array_account_id.") and ledgertype not in('client','vendor')  ",$db);
					if(DB_num_rows($sqlVendor21)>0)
					{
						while($rowVendor21=DB_fetch_array($sqlVendor21))
						{
							 $arrV_vendor_client1[]=$rowVendor21['AccountsID'];
							
						}                                   
					}
              }               

               $arrV_vendor_client1=array_unique($arrV_vendor_client1);
                if(!empty($arrV_vendor_client1))
                {
                	
                    $marge_ven_client_arr=array_merge($array_account,$arrV_vendor_client1);
                }
                 else
                 {
                 $marge_ven_client_arr=$arrV_vendor_client1;
                 }
                $imp_ven_client_arr= implode(',',$marge_ven_client_arr);  
                 
	     //***************************************************************************//
	
	     
	  	if($_REQUEST['site']!='0' && isset($_REQUEST['site']) && $imp_ven_client_arr!='')	
	  	{ 		
	  	 
	  	  $ledoption=DB_query("SELECT * FROM accountledger where  AccountsID IN (".$imp_ven_client_arr.") ORDER BY AccountName ASC",$db);
	     }
	    else
	    {
	    
	   $ledoption=DB_query("SELECT * FROM accountledger ORDER BY AccountName ASC",$db); 	
	    }
	   // echo $sql1;
	  
		while($ledoptionres=DB_fetch_array($ledoption))
		{
			?>
			<option value="<?php echo $ledoptionres['AccountsID'];?>" <?php if($_REQUEST['ledgerid']==$ledoptionres['AccountsID']){ ?> selected="selected" <?php }?>><?php echo $ledoptionres['AccountName'] ;?></option>
<?php } ?>
</select></td><?php } else { ?>
<td colspan="2"></td><?php } ?>
</tr>
<tr class="row1">
<td align="right">From Date</td>	
<td><input name="fromdate"  id="fromdate" type="text"  class="datepicker"  value="<?php  echo $_REQUEST['fromdate']?>" placeholder="dd/mm/yyyy" onchange="chkdteformat(this)"/></td>
<td align="right">To Date</td>
<td><input name="todate" id="todate" type="text"  class="datepicker"value="<?php  echo $_REQUEST['todate']?>" placeholder="dd/mm/yyyy" onchange="chkdteformat(this)" /></td>
<?php  if($_REQUEST['AcType']=='Day'){	?>
<td>
	<select name="Viewtype" >
	<option value="ALL" <?php echo ($_REQUEST['Viewtype']=='ALL'?'selected':'')?>>ALL</option>
		<option value="CR"  <?php echo ($_REQUEST['Viewtype']=='CR'?'selected':'')?>>CR</option>
			<option value="DR"  <?php echo ($_REQUEST['Viewtype']=='DR'?'selected':'')?>>DR</option>
	</select>	</td>
	<td></td><?php } else{?>
	<td></td>
	<td></td>
	<?php } ?>
</tr>	
<?php if($_REQUEST['AcType']=='DayBook' ||   $_REQUEST['AcType']=='Ledger') { ?>
<tr class="row1">
<td align="center" colspan="6"><input name="Search" type="submit" class="search"  value="Search"/></td>
</tr>
<?php } ?>
<?php if($_REQUEST['AcType']!='DayBook' &&  $_REQUEST['AcType']!='Ledger') { ?>
<tr class="row1">
<td align="right">Type of Info</td>
<td><select name="Type_of_info" >		
		<option value="voucher"<?php echo($_REQUEST['Type_of_info']=='voucher'?'selected':'')?>>voucher</option>
	</select>
</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row1">	
	 <input type="hidden" name="having" value="0"/>
	 <td colspan="6" align="center"><input name="Search" type="submit" class="search"  value="Search"/></td>
</tr>
<?php } ?>
</table>
</form>
	
 	  <?php 	  

	if($_REQUEST['filter'])
	{
		$q1=$_SESSION['ACGAccountBookQuery'];
		$Typeofinfo=$_REQUEST['Type_of_info'];
	  	$having=$_REQUEST['having'];
		$range=$_REQUEST['range_of_info'];
		$searchtext=$_REQUEST['searchtext'];
		$filter=array();$filter2='';
 		switch($having)
		{
		  case 'voucherno':
		  					if($range=='equalto')
		  					$filter=" A.Voucher_NO ='".$searchtext."'";
							if($range=='containing')
		  					$filter=" A.Voucher_NO  like'%".$searchtext."%'";					
							if($range=='startingwith')
		  					$filter=" 1=1";							
							
		  					break;
		  case 'vouchertype':
		  
					   $Vprefixval1= $s->getField('voucher_master','VPrefix',$searchtext,'VoucherType');
		 					 if($range=='equalto')
		  					$filter=" A.VPrefix ='".$Vprefixval1."'";
							if($range=='containing')
		  					$filter=" A.VPrefix  like'%".$Vprefixval1."%'";					
							if($range=='startingwith')
		  					$filter=" 1=1";	
		  
		  					break;
		  case 'narration':
		  
		  					 if($range=='equalto')
		  					$filter=" A.narration ='".$searchtext."'";
							if($range=='containing')
		  					$filter=" A.narration  like'%".$searchtext."%'";					
							if($range=='startingwith')
		  					$filter=" 1=1";	
							break;														
		  case 'instrumentno':
		  
		  					if($range=='equalto')
		  					$filter=" A.banks_checkno ='".$searchtext."'";
							if($range=='containing')
		  					$filter=" A.banks_checkno  like'%".$searchtext."%'";					
							if($range=='startingwith')
		  					$filter=" 1=1";	
							
							break;
		  case 'searchledger':
		  				
						
					 
						
							 if($range=='equalto')
							 {
							 
		  					 	$daa=$s->GetFieldValue('accountledger',"AccountName = '".$searchtext."'" ,'AccountsID');
							$filter=" 1=1";	
							
							}
							if($range=='containing'){
						 	$daa=$s->GetFieldValue('accountledger',"AccountName like  '%".$searchtext."%'" ,'AccountsID');
 		  					//$ledgerid=$daa;	
							$filter=" 1=1";		
							}
							if($range=='startingwith'){
		  					$filter=" 1=1";	
		  					}
		  
	
		   																										
		}
		
	$todate_1=FormatDateForSQL($_REQUEST['todate']);
	$fromdate_1=FormatDateForSQL($_REQUEST['fromdate']);
	
	
	
	
	$ledgerid=$_SESSION['ledgerid'];
   $_SESSION['searchledger']=$daa;
  $_REQUEST['ledgerentry']=$_SESSION['ledgerentry'];
	$Viewtype=	$_SESSION['Viewtype'];
	
	 $query= " and  ".$filter;

	 
		if($_REQUEST['AcType']!='Day' && $_REQUEST['AcType']!='Ledger')
		{ 
 	   	  $GetRecord1="SELECT A.VPrefix  ,A.Voucher_NO ,A.id AS Pid, A.Dates FROM account_book A WHERE   A.Dates between  '".$fromdate_1."' and '".$todate_1."' and A.VPrefix  ='".$arrBook[$i]."' and A.cancel_status=0   ".$query;
	     }
		else if($_REQUEST['AcType']=='DayBook')
		{
		   if($Viewtype=='ALL'){ 
   		     $GetRecord1 = "SELECT  A.Vprefix,A.Voucher_NO ,A.id AS Pid, A.Dates   FROM `account_book` A where   A.Dates between  '".$fromdate_1."' and '".$todate_1."'   and A.cancel_status=0     $query order by A.Dates desc";
		   
		   
		   }
		   else
		  { 
		    $GetRecord1 = "SELECT  A.Vprefix,A.Voucher_NO ,A.id AS Pid, A.Dates ,B.* ,(B.amount) AS AMT  FROM `account_book` A, account_book_details B where   Dates between  '".$fromdate_1."' and '".$todate_1."'   and A.id=B.account_bookid and A.cancel_status=0   order by A.Dates desc ";
            
		  }
		}
		
		else if($_REQUEST['AcType']=='Ledger' )
		{	
		
	      $GetRecord1="SELECT A.VPrefix as Prefixtype,A.Voucher_NO ,A.id AS Pid, A.Dates FROM account_book A WHERE   A.Dates between  '".$fromdate_1."' and '".$todate_1."' and A.cancel_status=0  ".$query;

         }
		 
	 //  $_SESSION['ACGAccountBookQuery']=$GetRecord1;  	 
	 
	}
	//echo $GetRecord1;
	
	?>

<?php 
    //echo $GetRecord1;
	if($_SESSION['ACGAccountBookQuery']!='' || $GetRec!='')
	{
	// echo $_REQUEST['AcType'];
    	//echo $_SESSION['ACGAccountBookQuery'];
		
		if($GetRecord1!=''){
		$ResultData1 = DB_query($GetRecord1,$db);
		//$ResultData1 = DB_query($_SESSION['ACGAccountBookQuery'],$db);
	     $numrows = DB_num_rows($ResultData1);
		}
 	  	else if($GetRec!='')
		{
	   	$ResultData5=DB_query($GetRec,$db);
		$numrows5 = DB_num_rows($ResultData5);
		}
	   ?>	   
	   
 	  <p align="right">
	  <?php 
	  			####New Link for print and export added by Himanshu 18 September 2012 ###### 
	if($_REQUEST['AcType']=='DayBook' || $_REQUEST['AcType']=='Ledger'){
	  ?>
	  <a target="_blank" href="LedgerPrint.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>" class="search">Print</a>
	  <!--<a onclick='popup("LedgerPrint.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>",1000,1000)' href="#"   >Print</a>-->  |	  
	  <a href="Ledger_Export.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>" class="search">Export</a> 
	 <?php 
	 	}
		else
		{
			if($_REQUEST['tabid']=='0')
			{?>
			<a href="PrintAccountBooDetails.php?site=<?php echo $_REQUEST['site']; ?>&ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&vprifix=4" target="_blank" class="search">Print</a>
	  <a href="ExportBooDetails.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>&vprifix=4" class="search">Export</a>
		<?php 
			}
			if($_REQUEST['tabid']=='1')
			{?>
		<a href="PrintAccountBooDetails.php?site=<?php echo $_REQUEST['site']; ?>&ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&vprifix=3" target="_blank" class="search">Print</a>
		<!--<a  href="PrintAccountBankReceipt.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>" target="_blank"   >Print</a>-->	  
	 <!-- <a href="ExportBankReceipt.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>">Export</a></p>-->
  <a href="ExportBooDetails.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>&vprifix=3" class="search">Export</a>
		<?php 
			}			
			if($_REQUEST['tabid']=='2')
			{?>
		<a href="PrintAccountBooDetails.php?site=<?php echo $_REQUEST['site']; ?>&ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&vprifix=6" target="_blank" class="search">Print</a>
	<!--		<a  href="PrintAccountCashPayment.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>" target="_blank"  >Print</a>-->
	<a href="ExportBooDetails.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>&vprifix=6" class="search">Export</a>	  
	  <!--<a href="ExportCashPayment.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>">Export</a>-->
	 
		<?php 
			}
			if($_REQUEST['tabid']=='3')
			{
				?>
		<a href="PrintAccountBooDetails.php?site=<?php echo $_REQUEST['site']; ?>&ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&vprifix=5" target="_blank" class="search">Print</a>
		<!--	<a  href="PrintAccountCashReceipt.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>" target="_blank"    >Print</a>-->	  
	 <!-- <a href="ExportCashReceipt.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>">Export</a>-->
	 <a href="ExportBooDetails.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>&vprifix=5" class="search">Export</a>
	 
		<?php 
			}
			if($_REQUEST['tabid']=='4')
			{?>
			<a href="PrintAccountBooDetails.php?site=<?php echo $_REQUEST['site']; ?>&ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&vprifix=10" target="_blank" class="search">Print</a>
			<!--<a  href="PrintContra.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>" target="_blank"    >Print</a>-->	  
	  <!--<a href="ExportContra.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>">Export</a>-->
<a href="ExportBooDetails.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>&vprifix=10" class="search">Export</a>
	
		<?php 
			}
			if($_REQUEST['tabid']=='5')
			{?>
		<a href="PrintAccountBooDetails.php?site=<?php echo $_REQUEST['site']; ?>&ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&vprifix=11" target="_blank" class="search">Print</a>
			<!--<a  href="PrintAccountCreditNote.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>"  target="_blank"   >Print</a>-->	  
	  <!--<a href="ExportCreditNote.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>">Export</a>-->
      <a href="ExportBooDetails.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>&vprifix=11" class="search">Export</a>
	
		<?php 
			}
			if($_REQUEST['tabid']=='6')
			{?>
			<a href="PrintAccountBooDetails.php?site=<?php echo $_REQUEST['site']; ?>&ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&vprifix=12" target="_blank" class="search">Print</a>
			<!--<a  href="PrintAccountDebitNote.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>" target="_blank"   >Print</a>-->	  
	  <!--<a href="ExportDebitNote.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>">Export</a>-->
      <a href="ExportBooDetails.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>&vprifix=12" class="search">Export</a>
	
		<?php 
			}
			if($_REQUEST['tabid']=='7')
			{?>
		<a href="PrintAccountBooDetails.php?site=<?php echo $_REQUEST['site']; ?>&ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&vprifix=14" target="_blank" class="search">Print</a>
			<!--<a  href="PrintAccountExciseDeposit.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>" target="_blank"   >Print</a>-->	  
	 <!-- <a href="ExportExciseDeposit.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>">Export</a>-->
     <a href="ExportBooDetails.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>&vprifix=14" class="search">Export</a> 
	
		<?php 
			}
			if($_REQUEST['tabid']=='8')
			{?>
		<a href="PrintAccountBooDetails.php?site=<?php echo $_REQUEST['site']; ?>&ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&vprifix=8" target="_blank" class="search">Print</a>
			<!--<a  href="PrintAccountJournalVoucher.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>"  target="_blank"   >Print</a>-->	  
	 <!-- <a href="ExportJournalVoucher.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>">Export</a>-->
     <a href="ExportBooDetails.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>&vprifix=8" class="search">Export</a>
	
		<?php 
			}
			if($_REQUEST['tabid']=='9')
			{?>
		<a href="PrintAccountBooDetails.php?site=<?php echo $_REQUEST['site']; ?>&ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&vprifix=13" target="_blank" class="search">Print</a>
		<!--	<a  href="Print_Account_JVat_Tax.php?ledgerentry=<?php echo $_REQUEST['ledgerentry'];?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>&ledgername=<?php echo $_REQUEST['ledgerid']; ?>" target="_blank" >Print</a>-->	  
	 <!-- <a href="exp-sals.php?ledgerentry=<?php echo $_REQUEST['ledgerentry'];?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>&ledgername=<?php echo $_REQUEST['ledgerid']; ?>">Export</a>-->
     <a href="ExportBooDetails.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>&vprifix=13" class="search">Export</a>
	
		<?php 
			}
			if($_REQUEST['tabid']=='10')
			{?>
			<a  href="Printvatdeposit.php?ledgerentry=<?php echo $_REQUEST['ledgerentry'];?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>&ledgerdata=<?php echo $_REQUEST['ledgerid']; ?>" target="_blank" class="search">Print</a>	  
	  <a href="Exportvatdeposit.php?ledgerentry=<?php echo $_REQUEST['ledgerentry'];?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>&ledgerdata=<?php echo $_REQUEST['ledgerid']; ?>" class="search">Export</a>
		<?php 
			}
			if($_REQUEST['tabid']=='11')
			{?>
			<a  href="Print_Account_dayBook.php?ledgerentry=<?php echo $_REQUEST['ledgerentry'];?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>&ledgername=<?php echo $_REQUEST['ledgerid']; ?>" target="_blank" class="search">Print</a>	  
	  <a href="exl_Account_dayBook.php?ledgerentry=<?php echo $_REQUEST['ledgerentry'];?>&todate=<?php echo $_REQUEST['todate']?>&fromdate=<?php echo $_REQUEST['fromdate']?>&site=<?php echo  $_REQUEST['site']?>&ledgername=<?php echo $_REQUEST['ledgerid']; ?>" class="search">Export</a>
		<?php 
			}

		}
	 			####New Link for print and export added by Himanshu 18 September 2012 ###### 
	 ?></p>
	

<table width="100%" border="0" cellspacing="0" cellpadding="3" align="center" class="thborder">
<tr>
	<th colspan="8">Ledger : <?php echo $getLedgerName;?></th>
</tr>
<tr>
	<th width="7%">Date</th>
	<th>Particulars</th>
	<th width="10%" style="text-align:center;">V. No.</th>
	<th width="10%" style="text-align:center;">V. Type</th>
	<th width="10%" style="text-align:center;">Debit Amount</th>
	<th width="10%" style="text-align:center;">Credit Amount</th>
	<?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> 
	<th width="20%">Remarks</th>
	<?php } ?>
	<th width="4%" style="text-align:center;">View</th>
</tr>
		  <?php
		   $TCR=array();$TDR=array();  //echo $ledgerid;
		  // echo $_REQUEST['AcType'];
		   //-----------------------------------PARTY SALES-------------------------------------------
		   
	 if(isset($_SESSION['searchledger']) && $_SESSION['searchledger']!='')
	  $ledgerid=$_SESSION['searchledger'];

	   
	 if($_REQUEST['AcType']=='Ledger')
	 {
	 		 //   echo "<br>------------------11------------".$_REQUEST['AcType']."-----------------------------------<br>";
	 	//echo "<pre>";
	 	//print_r($data_array);

	       $_SESSION['leddata']=$data_array;
			if(count($data_array)>0)
			  { 
		  	     $flag='';	
 			   //while($RowData1 = DB_fetch_array($ResultData5))
			   $AMTDR1='';
			   foreach($data_array as $k=>$val)
			   { 
                  //echo "<pre>";
                  //print_r($data_array);


			    if($val['flag']=='voucher')
				{
					if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==4)
					{
						
						
						 
						 
                       if($ledgerid!='0')
                       {
				        $ResultData2=DB_query("select A.id,A.account_bookid,A.amount as AMT,  A.ledgerid as ledgerid,B.amount,B.currency,B.amount_type FROM account_book_details A, account_book_details  B   where A.account_bookid ='". $val['Pid']."' and B.ledgerid='".$ledgerid."' AND A.ledgerid!='".$ledgerid."'   and  A.account_bookid=B.account_bookid  and A.amount!='0.00' and A.amount!='' GROUP BY A.account_bookid ",$db);
				       }
				       else
				       {
				       	$ResultData2=DB_query("select A.id,A.account_bookid,A.amount as AMT,  A.ledgerid as ledgerid,B.amount,B.currency,B.amount_type FROM account_book_details A, account_book_details  B   where A.account_bookid ='". $val['Pid']."'  and  A.account_bookid=B.account_bookid  and A.amount!='0.00' and A.amount!='' GROUP BY A.account_bookid ",$db);
				       } 
				   }
				 else
				 {		
                   if($ledgerid!='0')
                   {
				      $ResultData2=DB_query("select A.id,A.account_bookid,A.amount as AMT,  A.ledgerid as ledgerid,B.amount,B.currency,B.amount_type FROM account_book_details A, account_book_details  B   where A.account_bookid ='".$val['Pid']."'  and B.ledgerid='".$ledgerid."' AND A.ledgerid!='".$ledgerid."' and  A.account_bookid=B.account_bookid 	and A.amount!='0.00' and A.amount!=''",$db);
				    }
				    else
				    {
				    	$ResultData2=DB_query("select A.id,A.account_bookid,A.amount as AMT,  A.ledgerid as ledgerid,B.amount,B.currency,B.amount_type FROM account_book_details A, account_book_details  B   where A.account_bookid ='".$val['Pid']."'  and  A.account_bookid=B.account_bookid and A.amount!='0.00' and A.amount!=''",$db);
				    }  							
	 			 }				
			}	
                
			if(DB_num_rows($ResultData2)>0)
			  {	
			   ?>
			   <tr>
			   <td align="left" valign="top"><?php echo ConvertSQLDate($val['date'])?></td>
			   <td align="left" valign="top">&nbsp;</td>
			   <td align="left" valign="top"><?php echo $val['Voucher_NO'];?></td>
			   <td align="left" valign="top"><?php  if($val['flag']=='voucher'){
					echo  $Vprefixval= $s->getField('voucher_master','VoucherType',$val['Vprefix'],'GroupName');}
					else{echo $val['Vprefix'];}
 				  ?></td>
			   <td align="left" valign="top">&nbsp;</td>
			   <td align="left" valign="top">&nbsp;</td>
			   <?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) { ?> 
			   <td align="left" valign="top"><?php echo $s->getField('account_book','id',$val['Pid'],'narration');  ?></td>
			   <?php } ?>
			   <td style="text-align:center;">
			   <?php if($val['flag']=='voucher'){ ?>
			    <a href="#" onclick='popup("address_book.php?id=<?php echo $val['Pid'].$rurl?>&VPrefix=<?php echo $val['Vprefix'];?>",600,600)'><img src="images/search.png" width="15" height="15" title="View" /></a>
			   <?php }  ?></td>
			   </tr>
 				<?php $AMTDR=0; $AMTCR=0; 				
				 while($RowData2 = DB_fetch_array($ResultData2))
			  	 { 				
                  // echo "<pre>";
                   //print_r($RowData2);

				?>
 				<tr>
				<td align="left" valign="top">&nbsp;</td>
				<td align="left" valign="top">&nbsp;<?php 
				if($val['flag']=='voucher')
				{
				echo $s->GetFieldValue('accountledger',"AccountsID='".$RowData2['ledgerid']."'",'AccountName');				
				}
				?></td> 
				<td align="left" valign="top">&nbsp;</td>   
				<?php ?>
	    	     <td align="left" valign="top"><?php echo $RowData2['VPrefix'];
				  	echo  $s->GetFieldValue('voucher_master',"VoucherType='".$RowData2['VPrefix']."'",'GroupName');?> </td>
				<td style="text-align:right;" valign="top">
				<?php  $AMTDR=0; 			
                
				if($val['flag']=='voucher' ){
				if($RowData2['amount_type']=='DR')
				echo $AMTDR=$RowData2['amount'];}			
				else
				 {echo $AMTDR=0;}
				
				$TDR[]= $AMTDR;
				 ?></td>
				<td style="text-align:right;" valign="top">
				<?php $AMTCR=0;
				
				
				if($val['flag']=='voucher'){
				if($RowData2['amount_type']=='CR')
				echo $AMTCR=$RowData2['amount'];}
				else
				{echo $AMTCR=0;}
				$TCR[]= $AMTCR;

				//print_r($TCR);
				?></td>
				<?php 
				if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> 
				<td align="left" valign="top">&nbsp;</td>    	    
				<?php } ?>
				<td align="left" valign="top">&nbsp;</td>    
			</tr>
			   <?php  
			  
			   } 
			?><!-- <tr bgcolor="#fff"><td colspan="8" align="center"></td></tr> -->
	   <?php }			   
			   }
			?>
			<?php 
	  }	
	 }		
		else if($_REQUEST['AcType']=='DayBook')
		   {
		     
           $_SESSION['leddata']=$data_array;
			  if(count($data_array)>0)
			  { 
		  	     $flag=''; 			
			     $AMTDR1='';
            
			   foreach($data_array as $k=>$val)
			   { 
			    if($val['flag']=='voucher')
			    {
				if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==4)	 
					  { 

					  	$ResultData2=DB_query("select * from account_book_details where account_bookid ='". $val['Pid']."' 
						GROUP BY account_bookid ",$db);
						//echo "<br>". "select * from account_book_details where account_bookid ='". $val['Pid']."'GROUP BY account_bookid";
					  }
					   else					   
					   { 
						// echo "select * from account_book_details where   account_bookid ='". $RowData1['Pid']."'<br>";
					 $ResultData2=DB_query("select * from account_book_details where account_bookid ='".$val['Pid']."'",$db);
						}
					}				
						
			if(DB_num_rows($ResultData2)>0)
			  {		
			   ?>
			   <tr>
			   <td align="left" valign="top"><?php echo ConvertSQLDate($val['date'])?></td>
			   <td align="left" valign="top">&nbsp;</td>
			   <td align="left" valign="top"><?php echo $val['Voucher_NO'];?></td>
			   <td align="left" valign="top"><?php 
			       if($val['flag']=='voucher'){
					echo  $Vprefixval= $s->getField('voucher_master','VoucherType',$val['Vprefix'],'GroupName');}
					else{echo $val['Vprefix'];}
 				  ?> 			   </td>
			   <td align="left" valign="top">&nbsp;</td>
			   <td align="left" valign="top">&nbsp;</td>
			   <?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> 
			   <td align="left" valign="top"><?php	echo $s->getField('account_book','id',$val['Pid'],'narration');  ?></td>
			   <?php } ?>
			   <td align="center" valign="top">				
				<?php if($val['flag']=='voucher'){ ?>
			    <a href="#" onclick='popup("address_book.php?id=<?php echo $val['Pid'].$rurl?>&VPrefix=<?php echo $val['Vprefix'];?>",600,600)'><img src="images/search.png" width="15" height="15" title="View" /></a>
			   <?php } ?></td>
			   </tr>
 				<?php $AMTDR=0; $AMTCR=0; 
				 while($RowData2 = DB_fetch_array($ResultData2))
			  	 { 
				?>
 				<tr bgcolor="#c1c1c1">
				<td align="left" valign="top">&nbsp;</td>
				<td align="left" valign="top">&nbsp;<?php 
				if($val['flag']=='voucher')
				{
				echo $s->GetFieldValue('accountledger',"AccountsID='".$RowData2['ledgerid']."'",'AccountName');				
				}
				
				?></td> 
				<td align="left" valign="top">&nbsp;</td>   
				<?php ?>
	    	     <td align="left" valign="top"><?php
				 echo $RowData2['VPrefix'];
				  	echo  $s->GetFieldValue('voucher_master',"VoucherType='".$RowData2['VPrefix']."'",'GroupName');?> </td>
				<td style="text-align:right;" valign="top"><?php  $AMTDR=0; 
				if($val['flag']=='voucher'){
				if($RowData2['amount_type']=='DR')
				echo $AMTDR=$RowData2['amount'];}
                 else
				 {echo $AMTDR=0;}				
				$TDR[]= $AMTDR;
				 ?></td>
				<td style="text-align:right;" valign="top"><?php $AMTCR=0;
			    if($val['flag']=='voucher'){
				if($RowData2['amount_type']=='CR')
				echo $AMTCR=$RowData2['amount'];}
				else
				{echo $AMTCR=0;}
				$TCR[]= $AMTCR;
				?></td>
				<?php 
				if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> 
				<td align="left" valign="top">&nbsp;</td>    	    
				<?php } ?>
				<td align="left" valign="top">&nbsp;</td>  
			</tr>
            <?php  			 
			   }
			?><!-- <tr bgcolor="#fff"><td colspan="8" align="center" valign="top"></td>
			   </tr> -->
	   <?php }			   
			   }
			?>			
			<?php 
	  }
	    ?>		   
		  <?php }	
	 if($_REQUEST['AcType']!='DayBook' && $_REQUEST['AcType']!='Ledger')
	 {	 	
	 	 	 	$det_cond="";
	 		 	if($_REQUEST['having']=='7')
	 		 	{
	 		 		$caption1=DB_fetch_assoc(DB_query("select * from account_book_search_criteria where id='".$_REQUEST['having']."'",$db));
	 		 		$det_led=DB_fetch_assoc(DB_query("select * from account_book_search_criteria_details where id='".$_REQUEST['range_of_info']."'",$db));
	 		 		$strt= $det_led['start_operator'];
	 		 		$end= $det_led['end_operator'];
	 		 		$val2=$_REQUEST['searchtext'];
	 		 		$caption2=$caption1['caption'];
	 		 		 	$det_cond="and $caption2$strt$val2$end";
	 		 	}
 
 		 if($ResultData1!=''){
 		  if(DB_num_rows($ResultData1)>0){  
		   while($RowData1 = DB_fetch_array($ResultData1)){   
			    if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==4 || $_REQUEST['ledgerentry']==2 || $_REQUEST['ledgerentry']==3){
					   
					   if($ledgerid!=''){ 
					   	if($_REQUEST['having']=='7')
	 		 				{
	 		 				$ResultData2=DB_query("SELECT SUM(amount) as amount,ledgerid,account_bookid,amount_type FROM account_book_details WHERE   ledgerid!='".$_REQUEST['ledgerid']."' and account_bookid ='". $RowData1['Pid']."' ".$det_cond,$db); 
	 		 				}
	 		 				else
	 		 				{
	 		 				  if($ledgerid!='0')
	 		 				  {	
					   		      $ResultData2=DB_query("select A.* FROM account_book_details A   where A.account_bookid ='". $RowData1['Pid']."' and A.ledgerid='".$ledgerid."'",$db);
					   		   }
					   		   else
					   		   {
					   		   	 $ResultData2=DB_query("select A.* FROM account_book_details A   where A.account_bookid ='". $RowData1['Pid']."'",$db);
					   		   }   
							}
					}
					   else
					   {
					   		if($_REQUEST['tabid']==0)
							$cn="and amount_type='CR' ";
							else if($_REQUEST['tabid']==1)
							$cn="and amount_type='DR' ";
							else if($_REQUEST['tabid']==2)
							$cn="and amount_type='CR' ";
							else if($_REQUEST['tabid']==3)
							$cn="and amount_type='DR' ";
							else
							$cn= "";
					 $ResultData2=DB_query("select A.* FROM account_book_details A   where A.account_bookid ='". $RowData1['Pid']."' ".$cn."  ",$db);			
					 //echo "<br />select A.* FROM account_book_details A   where A.account_bookid ='". $RowData1['Pid']."'";
					   }					   
					   }
					else					   
					{
					if($ledgerid!='')
					{
				 	   	if($_REQUEST['having']=='7')
				 	   	{
				 	   		$ResultData223=DB_query("SELECT SUM(amount) as amount,ledgerid,account_bookid,amount_type FROM account_book_details WHERE   ledgerid!='".$_REQUEST['ledgerid']."' and account_bookid ='". $RowData1['Pid']."' ".$det_cond,$db);
				 	   		if(DB_num_rows($ResultData223)>0)
				 	   		{
				 	   			$ResultData2=DB_query("select A.* FROM account_book_details A   where A.account_bookid ='". $RowData1['Pid']."'",$db);
				 	   		}
				 	   	}
				 	   	else{
				 	   	$ResultData2=DB_query("select A.id,A.account_bookid,A.amount as AMT,  B.ledgerid as ledgerid,B.amount,B.currency,B.amount_type FROM account_book_details A, account_book_details  B   where A.account_bookid ='". $RowData1['Pid']."' and A.ledgerid='".$ledgerid."' and  A.account_bookid=B.account_bookid",$db);
				 	   	}
				 	   }
						else
						{
							$ResultData2=DB_query("select A.id,A.account_bookid,A.amount as AMT,  B.ledgerid as ledgerid,B.amount,B.currency,B.amount_type FROM account_book_details A, account_book_details  B   where A.account_bookid ='". $RowData1['Pid']."' and  A.account_bookid=B.account_bookid GROUP BY B.id",$db);
							}
						}
				if(DB_num_rows($ResultData2)>0)
				{	
			   ?>
			   <tr>
			   <td align="left" valign="top"><?php echo $datedata= ConvertSQLDate($RowData1['Dates'])?></td>
			   <td align="left" valign="top">&nbsp;</td>
			   <td align="left" valign="top"><?php echo $vno= $RowData1['Voucher_NO']; ?></td>
			   <td align="left" valign="top"><?php echo  $vpr= $s->GetFieldValue('voucher_master',"VoucherType='".$RowData1['VPrefix']."'",'GroupName');?></td>   
			   <td align="left" valign="top">&nbsp;</td>
			   <td align="left" valign="top">&nbsp;</td>
			   <?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) { ?> 
			   <td align="left" valign="top">
			   <?php	echo $remarks= $s->getField('account_book','id',$RowData1['Pid'],'narration');  ?></td>
			   <?php } ?>
			   <td align="center" valign="top">
				 <a href="#" onclick='popup("address_book.php?id=<?php  echo $RowData1['Pid'].$rurl?>&VPrefix=<?php echo $RowData1['VPrefix'];?>",600,600)'><img src="images/search.png"  width="15" height="15" title="View" /></a></td>	
			   </tr>
  					<?php 
 				 while($RowData2 = DB_fetch_array($ResultData2))
			  	 { 
				 		//echo "<pre>";
						//print_r($RowData2);
				    switch($vpr)
					{
					  case 'CP':  
					             break;
					}
				?>
				<tr bgcolor="#fff">
				<td align="left" valign="top">&nbsp;</td>
				<td align="left" valign="top">
				<?php 
				if($_REQUEST['AcType']!='Day'  &&  $_REQUEST['ledgerentry']!=2 && $_REQUEST['ledgerentry']!=3)
				{  //echo "hi";
					if($ledgerid=='0')
					{
						echo $particular= $s->GetFieldValue('accountledger',"AccountsID='".$RowData2['ledgerid']."'",'AccountName');
					}
					else{
					$acid=DB_query("select ledgerid from account_book_details where ledgerid!='".$RowData2['ledgerid']."' and account_bookid='".$RowData2['account_bookid']."' limit 1 ",$db);
					$acid1=DB_fetch_array($acid);
					 echo $particular=$s->GetFieldValue('accountledger',"AccountsID='".$acid1['ledgerid']."'",'AccountName');}
					}
				else 
				{	
				echo $particular=$s->GetFieldValue('accountledger',"AccountsID='".$RowData2['ledgerid']."'",'AccountName');
				}
				?></td>    
				<td align="left" valign="top">&nbsp;</td>  
				<?php ?>
	    	     <td align="left" valign="top">&nbsp;</td>
				<td align="right" valign="top"><?php  
				if($RowData2['amount_type']=='DR')
				echo $AMTDR=$RowData2['amount'];
				else
				 echo $AMTDR=0;
				 
				$TDR[]= $AMTDR;
				 ?></td>
				<td align="right" valign="top"><?php  
				if($RowData2['amount_type']=='CR')
				echo $AMTCR=$RowData2['amount'];
				else
				 echo $AMTCR=0;
				$TCR[]= $AMTCR;;
				?></td>
				 <?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> 
				<td align="left" valign="top">&nbsp;</td>    	    
				<?php } ?>
				<td align="left" valign="top">&nbsp;</td>    
			</tr>
				
			   <?php 
			  $data_account_dtls[]=array("date"=>$datedata,"particular"=>$particular,"vno"=>$vno,"vtype"=>$vpr,"debit"=>$AMTDR,"credit"=>$AMTCR,"remarks"=>$remarks); 
			   
			   }
			?><!-- <tr bgcolor="#fff"><td height="1" colspan="8" align="center" valign="top"></td>
			   </tr> -->				
			   <?php }
			   $_SESSION['account_voucher_data']= $data_account_dtls;			   
			   }			   
	  	  }
		  //else{echo "<tr><td colspan=4>No Record</td></tr>";}		  
		  }
		}
 		?>
		<?php if($_REQUEST['AcType']=='Ledger')
		{
            if($_REQUEST['site']!='0')
		   {
		   	$sql_check_dtls=DB_query("select B.openingtype,B.openingBalance  from accountledger_dtls B  inner join accountledger A on
            A.AccountsID=B.accountledger_id where A.AccountsID='".$_REQUEST['ledgerid']."' and B.site='".$_REQUEST['site']."' ",$db); 
           }
           else
           {
           	//echo "select B.openingtype,B.openingBalance  from accountledger_dtls B  inner join accountledger A on
           //A.AccountsID=B.accountledger_id where A.AccountsID='".$_REQUEST['']."'";
           $sql_check_dtls=DB_query("select B.openingtype,B.openingBalance  from accountledger_dtls B  inner join accountledger A on
           A.AccountsID=B.accountledger_id where A.AccountsID='".$_REQUEST['ledgerid']."'  ",$db); 
           }
           while($row_dtls=DB_fetch_array($sql_check_dtls))
	        {
	         $opening_amt[$row_dtls['openingtype']][]=$row_dtls['openingBalance']; 
	        }


	        if(!empty($opening_amt[DR]))
	           $dramt=array_sum($opening_amt[DR]);
	        if(!empty($opening_amt[CR]))
	           $cramt=array_sum($opening_amt[CR]);
	         
	        /* if($dramt>$cramt)
	         $openingDRBalance=$dramt-$cramt;
	         else
	         $openingDRBalance=$cramt-$dramt; */



	        $sql_account_dr="select sum(amount) as amount from account_book_details inner join account_book on account_book.id=account_book_details.account_bookid where ledgerid='".$_REQUEST['ledgerid']."' and amount_type='DR' and cancel_status=0 and account_book.Dates < '".$fromdate_1."' and Branch='".$_REQUEST['site']."' and Dates between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."'";
	        $result_account_dr=DB_query($sql_account_dr,$db);
	        $rs_account_dr=DB_fetch_array($result_account_dr);
	        $total_dr_amount=$rs_account_dr[0];


          $sql_account_cr="select sum(amount) as amount from account_book_details inner join account_book on account_book.id=account_book_details.account_bookid where ledgerid='".$_REQUEST['ledgerid']."' and amount_type='CR' and cancel_status=0 and account_book.Dates < '".$fromdate_1."' and Branch='".$_REQUEST['site']."' and Dates between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."'";
	        $result_account_cr=DB_query($sql_account_cr,$db);
	        $rs_account_cr=DB_fetch_array($result_account_cr);
	        $total_cr_amount=$rs_account_cr[0];

	        if($total_dr_amount>$total_cr_amount)
	        {
	        	$cur_bal=$total_dr_amount-$total_cr_amount;
	        }
	        elseif($total_dr_amount<$total_cr_amount)
	        {
	        	$cur_bal1=$total_cr_amount-$total_dr_amount;
	        }

	        //echo $dramt."##".$cramt;
              
       
              $total_dr_amt1=$dramt+$total_dr_amount;
              $total_cr_amt1=$cramt+$total_cr_amount;

              if($total_dr_amt1>$total_cr_amt1)
              	 $bal_amt=$total_dr_amt1-$total_cr_amt1;
              	else
              	 $bal_amt1=$total_cr_amt1-$total_dr_amt1;


              	//echo $total_dr_amount."###".$total_cr_amount;




	               

         
	          

			?>
		<tr>
 		  	<td>&nbsp;</td> 		   
 		  	<td>&nbsp;</td>		  
		  	<td>&nbsp;</td>
 		 	<td align="right">Opening Balance</td>
 		  	<td align="right"><b><?php echo $openingDRBalance=$bal_amt;?></b></td>
 			<td align="right"><b><?php echo $openingCRBalance=$bal_amt1;?></b></td>
			<td>&nbsp;</td>
 			<?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) { ?> <td>&nbsp;</td><?php } ?>
	   </tr><?php }?>
	    <tr>
 		  <td>&nbsp;</td>
 		  <td>&nbsp;</td>
 		  <td>&nbsp;</td>		   
 		  <td align="right">Current Total</td>
 		  <td align="right"><b>
		  <?php 
		  if(!empty($AMTDR1)){$TDR1=array_sum($AMTDR1);}else{$TDR1=0;}
		   if(!empty($AMTDR2)){$TDR2=array_sum($AMTDR2);}else{$TDR2=0;}
		 // echo "<pre>";print_r($TDR);
		  echo round((array_sum($TDR)+$TDR1+$TDR2),2); 
		  //echo "<br /><br />---"; print_r($AMTDR1);
		   ?></b></td>
 		<td align="right"><b><?php 
 		//echo "<pre>";print_r($TCR);
 		if(!empty($AMTCR2)){$TCR2=array_sum($AMTCR2);}else{$TCR2=0;}
 		echo round(array_sum($TCR)+$TCR2,2); ?></b></td>
 		<td>&nbsp;</td>
 		<?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> 
 		<td></td><?php } ?>
	    </tr>
	    <?php if($_REQUEST['AcType']=='Ledger')
	    {
	    ?>
	    <tr>
 		  <td>&nbsp;</td> 		   
 		  <td>&nbsp;</td>		  
		  <td>&nbsp;</td>		  
		   <?php 
		  $DR_total=$openingDRBalance+array_sum($TDR);
		  $CR_total=$openingCRBalance+array_sum($TCR);
		 
		   if($DR_total>$CR_total)
		   {$DR_balance=$DR_total-$CR_total;}
		   if($CR_total>$DR_total)
		   {$CR_balance=$CR_total-$DR_total;}
		   
		   if($DR_total==$CR_total)
		   {
		   		if(isset($openingDRBalance)){
				$DR_balance=$DR_total-$CR_total;}
				else if(isset($openingCRBalance))
				{$CR_balance=$CR_total-$DR_total;}
		   }		   
		   ?>
 		  <td align="right">Closing Balance </td>
 		  <td align="right"><b><?php echo $DR_balance;?></b></td>
 		<td align="right"><b><?php echo $CR_balance;?></b></td>
 		<td>&nbsp;</td>
 		<?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?>
 		<td>&nbsp;</td><?php } ?>
	    </tr>
	    <?php }?>
  	  </table> 
	  <?php } ?>	  	
		 <?php 
   //
   ?>
    </div>
  <?php   
   }
 } ?>
  </div>
</div>
<script language="JavaScript">
function chkdteformat(obj){
var pattern =/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/;
  var input=$(obj).val();
  if(!pattern.test(input))
  {
      alert("Date should be in dd/mm/yyyy Format");
      $(obj).val("");
  }
}
function opendata()
{
	window.open("LedgerPrint.php?ledgerid=<?php echo $_REQUEST['ledgerid'];?>","height=1100,width=1100,toolbar=no,menubar=no,dependent=yes,resizable=yes,scrollbars=yes");
}	
	
</script>
