<?php extract($_POST);
$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);
		 
		
	}
	 
?>
 <style type="text/css">
* {
	margin: 0;
	padding: 0;
	font-size:14px;
}
#tabs {
	font-size: 90%;
	margin: 10px 0;
}
#tabs ul {
	float: left;
	background: #FFFFFF;
	width: auto;
	padding-top: 2px;
}
#tabs li {
	margin-left: 4px;
	list-style: none;
}
* html #tabs li {
	display: inline;
}
#tabs li, #tabs li a {
	float: left;
}
#tabs ul li.active {
	border-top:2px #FFFF66 solid;
	background: #CCCCCC;
}
#tabs ul li.active a {
	color: #333333;
}
#tabs div {
	background: #CCCCCC;
	clear: both;
	padding: 15px;
	min-height: 200px;
}
#tabs div h3 {
	margin-bottom: 12px;
}
#tabs div p {
	line-height: 150%;
}
#tabs ul li a {
	text-decoration: none;
	padding: 8px;
	color: #000;
	font-weight: bold;
}
.thumbs {
	float:left;
	border:#000 solid 1px;
	margin-bottom:20px;
	margin-right:20px;
}
-->
</style>

 
<h2>Account Book</h2>
<div id="container">
  <div id="tabs">
    <ul style="background-color:#999966" >
	<?php 
	 $GetRecord = "Select * from voucher_master where Vprefix  not in('CBJ','MEMO','ChRet') 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="";
  	?>
    <li <?php echo $bg?>>
	<a href="index.php?route=Account/AccountDayBook<?php echo $rurl;?>&tabid=<?php echo $j?>"><?php echo $RowData['GroupName'];?></a></li>
	<?php  $j++;} 
	 $arrBook[]='Day';	 $arrBook[]='Ledger';
	
	 $rx=array('Day','Ledger');
	 for($kl=$j,$k=0;$k<2;$k++){
	 if($_REQUEST['tabid']==$kl)
 	     $bg= "style='background-color:#CCC'";
		 else $bg="";
	?>
	<li <?php echo $bg?>>
	<a href="index.php?route=Account/AccountDayBook<?php echo $rurl;?>&tabid=<?php echo $kl++?>&AcType=<?php  echo $rx[$k];?>"><?php  echo $rx[$k];?> Book</a></li>
	<?php }?>
	
    </ul>
	<?php 
 for($j=0,$i=0;$i<count($arrBook);$i++,$j++)
{	
 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 'JV':
		$LDR='';
		break;
		default: 				
		$LDR='';
		break; 				 				 		 
	 }
 
 ?> 
<div id="<?php echo $j?>"><h3>
<?php 
//echo $_REQUEST['AcType'];
if(isset($_REQUEST['AcType']))
{
echo $_REQUEST['AcType'];
}else{?>
<?php  echo $s->getField('voucher_master','VoucherType',$arrBook[$i],'GroupName')?>
 <?php }?> Book</h3>
 <p>
<form action="" method="post">
	
<table width="60%" border="0" style="border: solid 1px #666666; background:#FFFFFF">
	
	
<tr>
<td><select name="site">
  <option value="0">All</option>
  <?php 
if($_SESSION['AssignedSites']!='0')
	  {$ss="Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")"; }
	  else
	  {$ss="Select loccode,locationname from locations";}
$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>
<?php if($_REQUEST['AcType']=='Ledger') {?>
<td>
<select name="ledgerentry" id="ledgerentry" >
<option value="1" <?php if($_REQUEST['ledgerentry']==1) { ?> selected="selected" <?php } ?>>Single Entry With Narrations</option>
<option value="2" <?php if($_REQUEST['ledgerentry']==2) { ?> selected="selected" <?php } ?>>Double Entry With Narrations </option>
<option value="3" <?php if($_REQUEST['ledgerentry']==3) { ?> selected="selected" <?php } ?>>Double Entry </option>	
<option value="4" <?php if($_REQUEST['ledgerentry']==4) { ?> selected="selected" <?php } ?>>Single Entry </option>	

</select>	
	
</td>
<?php } ?>
<?php if($_REQUEST['AcType']!='Day' ){ ?><td><?php
	
 	if($LDR!=''){
		$LRX=implode("','",$LDR);		
	      $sqlCate = "select * from  accountgroupmaster  where    MainGroupId   = 0  and GroupName in('$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')
 	   $AccountMaster-> AccountLeger($_REQUEST['ledgerid'],'ledgerid','ledgerid',$undergroup);
	  
	 
	   
	   
	   
	   
    ?></td><?php } ?>
	
	
	
	<td><input name="todate" type="text" class="datepicker"  value="<?php  echo $_REQUEST['todate']?>"/></td>
	
<td><input name="fromdate" type="text" class="datepicker"value="<?php  echo $_REQUEST['fromdate']?>" /></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><?php } ?>
<td><input name="Search" type="submit"  value="Search"/></td>
</tr>
</table>
</form>
<br />
	  
	  <?php
	  if($_REQUEST['Search'])
	  {
		$ledgerid=$_REQUEST['ledgerid'];
		$_SESSION['ledgerid']=$_REQUEST['ledgerid'];
		$getLedgerName=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerid."'" ,'AccountName');
		$accountType=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerid."'" ,'openingtype');
		if($accountType=='DR'){$openingDRBalance=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerid."'" ,'openingBalance');}
		elseif($accountType=='CR'){$openingCRBalance=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerid."'" ,'openingBalance');}
		$Viewtype=$_REQUEST['Viewtype'];
		$todate=FormatDateForSQL($_REQUEST['todate']) ;
		$fromdate=FormatDateForSQL($_REQUEST['fromdate']) ;
		if($_REQUEST['AcType']!='Day' && $_REQUEST['AcType']!='Ledger'){
		
	 	$GetRecord1 = "SELECT  A.Voucher_NO ,A.narration,A.VPrefix as Prefixtype,A.id AS Pid, A.Dates ,B.*,(B.amount) AS AMT FROM `account_book` A, account_book_details B where  A.VPrefix  ='".$arrBook[$i]."' and A.Dates between  '".$todate."' and '".$fromdate."' and A.id=B.account_bookid  and B.ledgerid='".$ledgerid."'  "; //group by B.ledgerid 
		$getrc="SELECT  A.Voucher_NO ,A.narration,A.VPrefix as Prefixtype,A.id AS Pid, A.Dates ,B.*,(B.amount) AS AMT FROM `account_book` A, account_book_details B where  A.VPrefix  ='".$arrBook[$i]."' and A.Dates between  '".$todate."' and '".$fromdate."' and A.id=B.account_bookid  and B.ledgerid='".$ledgerid."' ";
	  }
		else if($_REQUEST['AcType']=='Day')
		{
		   if($Viewtype=='ALL'){
 		echo    $GetRecord1 = "SELECT  A.Vprefix,A.Voucher_NO ,A.id AS Pid, A.Dates   FROM `account_book` A where   A.Dates between  '".$todate."' and '".$fromdate."'   order by A.Dates  DESC ";
		  $getrc="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  '".$todate."' and '".$fromdate."' and A.id=B.account_bookid";
		   
		   }else
		  {
		echo   $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   A.Dates between  '".$todate."' and '".$fromdate."'and  B.amount_type='".$Viewtype."' and A.id=B.account_bookid order by B.account_bookid ASC ,B.amount_type DESC  ";
           $getrc="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  '".$todate."' and '".$fromdate."'and  B.amount_type='".$Viewtype."' and A.id=B.account_bookid";
		  
		  }
		}else if($_REQUEST['AcType']=='Ledger' && $_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==4)
		{	
		    
		     $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   A.Dates between  '".$todate."' and '".$fromdate."' and A.id=B.account_bookid  and B.ledgerid='".$ledgerid."'";
		  $getrc="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   A.Dates between  '".$todate."' and '".$fromdate."' and A.id=B.account_bookid  and B.ledgerid='".$ledgerid."'";
  		}
      else if($_REQUEST['AcType']=='Ledger' && $_REQUEST['ledgerentry']==2 || $_REQUEST['ledgerentry']==3 )
       {
	$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  '".$todate."' and '".$fromdate."'and   A.id=B.account_bookid   order by B.account_bookid ASC ,B.amount_type DESC ";
		$getrc="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  '".$todate."' and '".$fromdate."'and   A.id=B.account_bookid";
	
         }
         
	$_SESSION['ledger']=$GetRecord1;  
	$_SESSION['second']=$getrc; 
	$_SESSION['ledgerentry']=$_REQUEST['ledgerentry']; 
	
	// echo $_REQUEST['AcType'];
    	   $ResultData1 = DB_query($GetRecord1,$db);
		   
	 	 $numrows = DB_num_rows($ResultData1);
 	   
	 
	   ?>
	   
	   


<form name="" method="post">
<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr>
    <th>Type of info</th>
    <td><select name="Type_of_info" style="width:107px;">
		<option id="0">Select</option>
		<option id="voucher"<?php echo($_REQUEST['Type_of_info']=='voucher'?'selected':'')?>>voucher</option>
	</select>
	</td>
    <th>Having</th>
    <td><select name="having" style="width:107px;">
		<option id="0">Select</option>
		<option id="voucherno"<?php echo($_REQUEST['having']=='Voucher no'?'selected':'')?>>Voucher no</option>
		<option id="vouchertype"<?php echo($_REQUEST['having']=='Voucher type'?'selected':'')?>>Voucher type</option>
		<option id="narration"<?php echo($_REQUEST['having']=='Narration'?'selected':'')?>>Narration</option>
		<option id="instrumentno"<?php echo($_REQUEST['having']=='Instrument no'?'selected':'')?>>Instrument no</option>
		<option id="ledger"<?php echo($_REQUEST['having']=='Ledger'?'selected':'')?>>Ledger</option>
		<option id="amount"<?php echo($_REQUEST['having']=='Amount'?'selected':'')?>>Amount</option>
	</select>
	</td>
    <th>Range of info</th>
    <td><select name="range_of_info" style="width:107px;">
		<option id="0">Select</option>
		<option id="containing"<?php echo($_REQUEST['range_of_info']=='Containing'?'selected':'')?>>Containing</option>
		<option id="equalto"<?php echo($_REQUEST['range_of_info']=='Equal to'?'selected':'')?>>Equal to</option>
		<option id="startingwith"<?php echo($_REQUEST['range_of_info']=='starting with'?'selected':'')?>>starting with</option>
	</select>
	</td>
    <th>Text</th>
    <td><input type="text" value="<?php echo $_REQUEST['Text_name']; ?>" name="Text_name" /></td>
	<td colspan="2"><center><input type="submit" name="filter" value="Go" /></center></td>
  </tr>
</table>
</form>
	   

<p style="height:10px;"></p>
	   
	   
 	  <p align="right"><a onclick='popup("LedgerPrint.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>",1000,1000)' href="#"   >Print</a></p>

	  <table width="98%" border="0" cellspacing="3" cellpadding="3" align="center">
    	<tr bgcolor="#666666" style="color:#FFFFFF"><td colspan="8"><strong>Ledger : <?php echo $getLedgerName;?></strong></td></tr>
    	<tr bgcolor="#666666" style="color:#FFFFFF">
    	    <td width="10%"><strong> Date</strong></td>
    	    <td width="20%"><strong>Particulars</strong></td>
			<td width="20%"><strong>Voucher No </strong></td>
     	     <td width="10%"><strong>Voucher Type </strong></td>
			 <td width="10%"><strong>Debit Amount</strong></td>
    	    <td width="10%"><strong>Credit Amount</strong></td>
    	    <?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> 
    	     <td width="40%"><strong>Narrations</strong></td><?php } ?>
			<td  width="5%"><strong>View</strong></td>
   	      </tr>
		  <?php
		   $TCR=array();$TDR=array();  //echo $ledgerid;
		  // echo $_REQUEST['AcType'];
		   //-----------------------------------PARTY SALES-------------------------------------------
		    
			/* if($_REQUEST['AcType']=='Ledger')
			 {
			  
			   
			   //////Temporary Solution for Cess ledgers/////////////////
			   $flag=0;
			  $ledgerid;	 
			   $cess_ledger_name=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerid."'" ,'AccountName');
					
					
				if(strpos($cess_ledger_name,"Cess")!='')
				{
					$flag=1;
					 $GetRecord2="SELECT  * FROM `invoice` A   where   A.invoiceDate   between  '".str_replace('/','-', $todate)."' and '".str_replace('/','-',$fromdate)."'";
					
				}
				else
				{	
					
					
				
				
				//////////////////////////////////////////
				
				$getClientLedger=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerid."'" ,'vender_client');
			 
				$educess=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerid."'" ,'taxid');
			 	//echo $educess;
			 if($getClientLedger!='')
			  	     $GetRecord2="SELECT  * FROM `invoice` A   where   A.invoiceDate   between  '".str_replace('/','-', $todate)."' and '".str_replace('/','-',$fromdate)."'   and A.client_id='".$getClientLedger."'  ";
				 else
				 {	
				     $GetRecord2="SELECT  * FROM `invoice` A   where   A.invoiceDate   between  '".str_replace('/','-', $todate)."' and '".str_replace('/','-',$fromdate)."'    and (A.exciseDuty='".$educess."' or A.ledger_id='".$ledgerid."' or A.Ecess_ledger='".$ledgerid."' or A.SCess_ledger='".$ledgerid."' or VatCst='".$educess."')  ";
				 }
		       	   
				   
				}  
				$_SESSION['ledger1']=$GetRecord2; 
				   $ResultData2 = DB_query($GetRecord2,$db);
			//echo    "1===".$GetRecord2;
 			   while($RowData2 = DB_fetch_array($ResultData2))
			   {?>
				<tr bgcolor="#FFFFFF">
				<td><?php echo ConvertSQLDate($RowData2['invoiceDate'])  ?></td>
				<td>
				<?php  
				if($getClientLedger!='')
				echo $s->getField('accountledger','AccountsID',$RowData2['ledger_id'],'AccountName');
				else
				echo $PartyCode=$s->GetFieldValue('clientmaster',"id='".$RowData2['client_id']."'" ,'c_name');	
				?>			
				
				</td>    
				<td><?php echo $RowData2['invoiceNo']; ?></td>  
				<?php ?>
	    	     <td width="10%">  Sale </td>
				<td><?php  
				//if($RowData2['amount_type']=='DR')
				if($getClientLedger!=''){
				echo $AMTDR=$RowData2['grandTotal'];}
				elseif($getClientLedger==''){
				echo $AMTDR=0;}
				//else
			//	 echo $AMTDR=0;
				 
				$TDR[]= $AMTDR;;
				 ?></td>
				<td><?php  
				//if($RowData2['amount_type']=='CR')
				//echo $AMTCR=$RowData2['AMT'];
				//else
				if($flag=='1'){echo $AMTCR=$RowData2['ECessValue'];}
				else
				
				if($getClientLedger==''){
				 echo $AMTCR=$RowData2['exciseValue'];}
				$TCR[]= $AMTCR;
				?></td>    	    
				 <td>
				 <?php if($_REQUEST['AcType']!='Day' && $_REQUEST['AcType']!='Ledger'){
				 $Vprefixval=$arrBook[$i];
				 }
				 ?>
				 
				 <a href="#" onclick='popup("Report-InvoiceDetails.php?InvoiceId=<?php echo $RowData2['invoice_id'].$rurl?> ",600,600)'><img src="images/search.gif"  width="20" height="20"/></a></td>	    
			</tr>
			
			<?php  
			}
		  
		   
		    }*/
			
			
//------------------------------------PARTY PURCHASES--------------------------------------------------------

		     if($_REQUEST['AcType']=='Ledger')
			 {
			 $getClientLedger=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerid."'" ,'vender_client');
			 $getPartyCode=$s->GetFieldValue('suppliers',"id='".$getClientLedger."'" ,'vendor_code');
			 $educess=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerid."'" ,'taxid');
			 
			 if($getClientLedger!='')
			    $GetRecord2="SELECT  * FROM `purchase_billbook` A   where   A.bill_date   between  '".str_replace('/','-', $todate)."' and '".str_replace('/','-',$fromdate)."'      and A.vendor='".$getPartyCode."'  ";
			    else
				 {
				    $GetRecord2="SELECT  * FROM `purchase_billbook` A   where   A.bill_date   between  '".str_replace('/','-', $todate)."' and '".str_replace('/','-',$fromdate)."'      and ( A.ledger_list='".$ledgerid."'  or A.exciseDuty_id='".$educess."' or taxname='".$educess."'  ) ";
				 }
				
				  $_SESSION['ledger1']=$GetRecord2;
				   
				 //echo "2===".$GetRecord2;
				   $ResultData2 = DB_query($GetRecord2,$db) ;
				 
 			   while($RowData2 = DB_fetch_array($ResultData2))
			   {?>
				<tr bgcolor="#FFFFFF">
				<td><?php echo ConvertSQLDate($RowData2['bill_date'])  ?></td>
				<td><?php  //echo $RowData2['ledgerid']; ?>
				<?php  
				//echo "<br>".$RowData2['ledger_list'];
				if($getClientLedger!='')
				echo $s->getField('accountledger','AccountsID',$RowData2['ledger_list'],'AccountName');
				else
				echo $PartyCode=$s->GetFieldValue('suppliers',"vendor_code='".$RowData2['vendor']."'" ,'vendor_name');
				?>			</td>    
				<td><?php echo $RowData2['bill']; ?></td>  
				<?php ?>
	    	     <td width="10%">Purchase  </td>
				<td><?php if($getClientLedger!=''){
	 			echo $AMTDR=0;}
				else if($educess!=''){echo $AMTDR=$RowData2['Excise_Duty'];}
				else {echo $AMTDR=$RowData2['basic_amount'];}
	 			$TDR[]= $AMTDR;
				 ?></td>
				<td><?php  
				if($getClientLedger!=''){
				echo  $AMTCR=$RowData2['grand_total'];}
				else {$AMTCR=0;}
				$TCR[]= $AMTCR;
				?></td>    	    
				 
				 
				 
				 <td>
				 <?php if($_REQUEST['AcType']!='Day' && $_REQUEST['AcType']!='Ledger'){
				 $Vprefixval=$arrBook[$i];
				 }
				 ?> 
				 <a href="#" onclick='popup("DispPurchBillBook.php?viewId=<?php  echo $RowData2['id'].$rurl?>",600,600)'><img src="images/search.gif"  width="20" height="20"/></a></td>	    
			</tr>
			
			<?php  
			}
		  
		   
		    }			
			
//*************************************************************************************************		   
		   
		  
 		  if(DB_num_rows($ResultData1)>0)
		  { 
		  	     $flag='';	
				  
			   while($RowData1 = DB_fetch_array($ResultData1))
			   { 
			   
			   ?><tr><td colspan="2"><?php echo ConvertSQLDate($RowData1['Dates'])?></td>
			   <td  >
			   <?php if($_REQUEST['AcType']=='Day' )
			   {  echo $RowData1['Voucher_NO'];}
				else if($_REQUEST['AcType']!='Day'){  echo $RowData1['Voucher_NO'];  } ?>
			   </td>
			   <td>
			    <?php   
				
			
			if($_REQUEST['AcType']=='Day' || $_REQUEST['AcType']=='Ledger')
			{
										 
 			echo	 $s->getField('voucher_master','VoucherType',$RowData1['Vprefix'],'VPrefix');
		  	$Vprefixval= $s->getField('voucher_master','VoucherType',$RowData1['Vprefix'],'VoucherType');
			}else{ 			
			echo   $s->GetFieldValue('voucher_master',"VoucherType='".$RowData2['Prefixtype']."'", 'VPrefix');
			//echo $RowData2['amount_type'];
			}
				  ?>
			   
			   </td>
			   <td colspan="2">&nbsp;</td>
			   <td>
				 <?php if($_REQUEST['AcType']!='Day' && $_REQUEST['AcType']!='Ledger'){
				 $Vprefixval=$arrBook[$i];
				 }
				 ?>
				 <a href="#" onclick='popup("address_book.php?id=<?php  echo $RowData1['Pid'].$rurl?>&VPrefix=<?php echo $Vprefixval;?>",600,600)'><img src="images/search.gif"  width="20" height="20"/></a></td>	
			   </tr>
			   	
					<?php 
					//echo "select * from account_book_details where account_bookid ='". $RowData1['Pid']."'";
			   	$ResultData2=DB_query("select * from account_book_details where account_bookid ='". $RowData1['Pid']."'",$db);
				 while($RowData2 = DB_fetch_array($ResultData2))
			  	 { 
				?>
				
				
				<tr >
				<td><?php
			 
				 if($flag==$RowData1['account_bookid'] && $count!=0 && $_REQUEST['AcType']=='Day' || $_REQUEST['ledgerentry']==2 || $_REQUEST['ledgerentry']==3 ){ echo ConvertSQLDate($RowData1['Dates']) ;} 
				else if($_REQUEST['AcType']!='Day' and $_REQUEST['ledgerentry']!=2 and  $_REQUEST['ledgerentry']!=3) { echo ConvertSQLDate($RowData1['Dates']) ;}
					?></td>
				<td><?php 		
				 //echo $GetRecord1;
				 //echo $RowData1['ledgerid']; ?>
				
				<?php 
				if($_REQUEST['AcType']!='Day'  &&  $_REQUEST['ledgerentry']!=2 && $_REQUEST['ledgerentry']!=3)
				{
				$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 $s->GetFieldValue('accountledger',"AccountsID='".$acid1['ledgerid']."'",'AccountName');
				}
				else 
				{	
							
				echo $s->GetFieldValue('accountledger',"AccountsID='".$RowData2['ledgerid']."'",'AccountName');
				}
				?></td>    
				<td>&nbsp;		 </td>  
				<?php ?>
	    	     <td width="10%"> &nbsp;  </td>
				<td><?php  
				if($RowData2['amount_type']=='DR')
				echo $AMTDR=$RowData2['amount'];
				else
				 echo $AMTDR=0;
				 
				$TDR[]= $AMTDR;;
				 ?></td>
				<td><?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><?php
					 if($flag==$RowData2['account_bookid'] and $count!=0 and $_REQUEST['AcType']=='Day' || $_REQUEST['ledgerentry']==2 || $_REQUEST['ledgerentry']==3 )
					{ echo $s->getField('account_book','id',$RowData2['account_bookid'],'narration'); }
                  else if($_REQUEST['AcType']!='Day' and $_REQUEST['ledgerentry']!=2 and  $_REQUEST['ledgerentry']!=3){
                  	echo $s->getField('account_book','id',$RowData2['account_bookid'],'narration'); } ?></td>    	    
				 <?php } ?>
				 <td></td>    
			</tr>
				
			   <?php 
			   
			   }
			?><tr><td colspan="7"><hr></td></tr>
				
				
				
				
			   <?php 
			   
			   }
			?>
			
			<?php 
	  }
		  //else{echo "<tr><td colspan=4>No Record</td></tr>";}
 		?>
		<?php if($_REQUEST['AcType']=='Ledger'){?>
		<tr bgcolor="#666666" style="color:#FFFFFF">
 		  <td>&nbsp;</td>
 		   
 		  <td>&nbsp;</td>
		  
		  <td>&nbsp;</td>
		  
		   
 		  <td nowrap="nowrap"> <strong>Opening Balance:</strong> </td>
 		  <td><b><?php echo $openingDRBalance;?></b></td>
 		<td><b><?php echo $openingCRBalance;?></b></td>  <td>&nbsp;</td>
 		<?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> <td>&nbsp;</td><?php } ?>
	   </tr><?php }?>
	    <tr bgcolor="#666666" style="color:#FFFFFF">
 		  <td>&nbsp;</td>
 		    <td>&nbsp;</td>
 		  <td>&nbsp;</td>
 		 
		  <?php if($_REQUEST['AcType']=='Day' || $_REQUEST['AcType']=='Ledger'){?>
		   <?php }?>
		   
 		  <td nowrap="nowrap"> <strong>Current Total:</strong></td>
 		  <td><b><?php echo array_sum($TDR); ?></b>&nbsp;</td>
 		<td><b><?php echo array_sum($TCR); ?></b></td> <td>&nbsp;</td>
 		<?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> <td>&nbsp;</td><?php } ?>
	    </tr>
	    <?php if($_REQUEST['AcType']=='Ledger'){?>
	    <tr bgcolor="#666666" style="color:#FFFFFF">
 		  <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> <strong>Closing Balance:</strong> </td>
 		  <td><b><?php echo $DR_balance;?></b></td>
 		<td><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
	if($_REQUEST['filter'])
{
	$Typeofinfo=$_REQUEST['Type_of_info'];
	$having=$_REQUEST['having'];
	$range=$_REQUEST['range_of_info'];
	$Textname=$_REQUEST['Text_name'];
	if($_REQUEST['having']=='Voucher no' && $_REQUEST['range_of_info']=='Equal to')
	{
	$filter1[]="and A.Voucher_NO = '".$Textname."'";
	}
	if($_REQUEST['having']=='Voucher no' && $_REQUEST['range_of_info']=='Containing')
	{
	$filter1[]="and A.Voucher_NO like'%".$Textname."%'";
	}
	if($_REQUEST['having']=='Voucher no' && $_REQUEST['range_of_info']=='starting with')
	{
	$filter1[]="and A.Voucher_NO like'".$Textname."%'";
	}
	//*****   Voucher Type  **********************//
	
	if($_REQUEST['having']=='Voucher type' && $_REQUEST['range_of_info']=='Equal to')
	{
	 $Vprefixval1= $s->getField('voucher_master','VPrefix',$Textname,'VoucherType');
	$filter1[]="and A.VPrefix = '".$Vprefixval1."'";
	}
	if($_REQUEST['having']=='Voucher type' && $_REQUEST['range_of_info']=='Containing')
	{
	$Vprefixval1= $s->getField('voucher_master','VPrefix',$Textname,'VoucherType');
	$filter1[]="and A.VPrefix like'%".$Vprefixval1."%'";
	}
	if($_REQUEST['having']=='Voucher type' && $_REQUEST['range_of_info']=='starting with')
	{
	$Vprefixval1= $s->getField('voucher_master','VPrefix',$Textname,'VoucherType');
	$filter1[]="and A.VPrefix like'".$Vprefixval1."%'";
	}
	
	
	//*******************************************  Narations **********************//
	
	
	
	if($_REQUEST['having']=='Narration' && $_REQUEST['range_of_info']=='Containing')
	{
	$filter1[]="and narration like'%".$Textname."%'";
	}
	if($_REQUEST['having']=='Narration' && $_REQUEST['range_of_info']=='Equal to')
	{
	$filter1[]="and narration = '".$Textname."'";
	}
	if($_REQUEST['having']=='Narration' && $_REQUEST['range_of_info']=='starting with')
	{
	$filter1[]="and A.narration like'".$Textname."%'";
	}
	//******************************** Instrument No     ********************************//
	
	
	if($_REQUEST['having']=='Instrument no' && $_REQUEST['range_of_info']=='Containing')
	{
	$filter1[]="and A.banks_checkno like'%".$Textname."%'";
	}
	if($_REQUEST['having']=='Instrument no' && $_REQUEST['range_of_info']=='Equal to')
	{
	$filter1[]="and A.banks_checkno = '".$Textname."'";
	}
	if($_REQUEST['having']=='Instrument no' && $_REQUEST['range_of_info']=='starting with')
	{
	$filter1[]="and A.banks_checkno like'".$Textname."%'";
	}
	
	//******************************   amount   ***********************************//
	if($_REQUEST['having']=='Amount' && $_REQUEST['range_of_info']=='Equal to')
	{
	$filter1[]="and B.amount = '".$Textname."'";
	}
	if($_REQUEST['having']=='Amount' && $_REQUEST['range_of_info']=='Containing')
	{
	$filter1[]="and B.amount like'%".$Textname."%'";
	}
	if($_REQUEST['having']=='Amount' && $_REQUEST['range_of_info']=='starting with')
	{
	$filter1[]="and B.amount like'".$Textname."%'";
	}
	
	
	
	
	
	
	//******************************   Ledger   ***********************************//
	
	if($_REQUEST['having']=='Ledger' && $_REQUEST['range_of_info']=='Containing')
	{
		//echo 	$s->GetFieldValue('accountledger',"AccountName like '%".$Textname."%'" ,'AccountsID');	
	//$getid1[]=$s->GetFieldValue('accountledger',"AccountName like '%".$Textname."%'" ,'AccountsID');
	$daa=DB_query("select AccountsID from accountledger where AccountName like '%".$Textname."%'",$db);
	while($daa1=DB_fetch_array($daa))
	{
	$getid1[]=$daa1['AccountsID'];	
	}	
	
	$getid=implode("','",$getid1);	
	
    $filter1[]="and B.ledgerid in ('".$getid."')";
	}
	if($_REQUEST['having']=='Ledger' && $_REQUEST['range_of_info']=='Equal to')
	{
	//echo $s->GetFieldValue('accountledger',"AccountName ='".$Textname."'" ,'AccountsID');	
	 $getid=$s->GetFieldValue('accountledger',"AccountName ='".$Textname."'" ,'AccountsID');	
	
	$filter1[]="and B.ledgerid = '".$getid."'";
	}
	if($_REQUEST['having']=='Ledger' && $_REQUEST['range_of_info']=='starting with')
	{
	$daa=DB_query("select AccountsID from accountledger where AccountName like '".$Textname."%'",$db);
	while($daa1=DB_fetch_array($daa))
	{
	$getid1[]=$daa1['AccountsID'];	
	}	
		//$getid1[]=$s->GetFieldValue('accountledger',"AccountName like '".$Textname."%'" ,'AccountsID');
	$getid=implode("','",$getid1);
	
	
	$filter1[]="and B.ledgerid  in ('".$getid."')";
	}
	
	
	
	//********************************************************************************//
	
	
	if($filter1!='')
	{
		$filter2=implode("and",$filter1);
	}
	
}
?>
<?php if(!empty($filter2)) {

$ledgerid1=$_SESSION['ledgerid'];
$getLedgerName1=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerid1."'" ,'AccountName');
//$ffilter="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  '".$todate."' and '".$fromdate."' and   A.id=B.account_bookid ".$filter2 ." and  B.ledgerid='".$ledgerid1."' order by B.account_bookid ASC ,B.amount_type DESC";
//$_SESSION['ledger']=$ffilter;
$ffilter=$_SESSION['second']." ".$filter2."order by B.account_bookid ASC ,B.amount_type DESC";
$ffilter1=DB_query($ffilter,$db);
//echo $ffilter;
//echo "<br>";
//echo $_SESSION['ledger'];
$_SESSION['ledger']=$ffilter;
{?>

<form name="" method="post">
<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr>
    <th>Type of info</th>
    <td><select name="Type_of_info" style="width:107px;">
		<option id="0">Select</option>
		<option id="voucher"<?php echo($_REQUEST['Type_of_info']=='voucher'?'selected':'')?>>voucher</option>
	</select>
	</td>
    <th>Having</th>
    <td><select name="having" style="width:107px;">
		<option id="0">Select</option>
		<option id="voucherno"<?php echo($_REQUEST['having']=='Voucher no'?'selected':'')?>>Voucher no</option>
		<option id="vouchertype"<?php echo($_REQUEST['having']=='Voucher type'?'selected':'')?>>Voucher type</option>
		<option id="narration"<?php echo($_REQUEST['having']=='Narration'?'selected':'')?>>Narration</option>
		<option id="instrumentno"<?php echo($_REQUEST['having']=='Instrument no'?'selected':'')?>>Instrument no</option>
		<option id="ledger"<?php echo($_REQUEST['having']=='Ledger'?'selected':'')?>>Ledger</option>
		<option id="amount"<?php echo($_REQUEST['having']=='Amount'?'selected':'')?>>Amount</option>
	</select>
	</td>
    <th>Range of info</th>
    <td><select name="range_of_info" style="width:107px;">
		<option id="0">Select</option>
		<option id="containing"<?php echo($_REQUEST['range_of_info']=='Containing'?'selected':'')?>>Containing</option>
		<option id="equalto"<?php echo($_REQUEST['range_of_info']=='Equal to'?'selected':'')?>>Equal to</option>
		<option id="startingwith"<?php echo($_REQUEST['range_of_info']=='starting with'?'selected':'')?>>starting with</option>
	</select>
	</td>
    <th>Text</th>
    <td><input type="text" value="<?php echo $_REQUEST['Text_name']; ?>" name="Text_name" /></td>
  	<td colspan="2"><center><input type="submit" name="filter" value="Go" /></center></td>
  </tr>
</table>
</form>

<p style="clear:both;"></p>
  <p align="right">
  	 <p align="right"><a onclick='popup("LedgerPrint.php?ledgerid=<?php echo $_REQUEST['AcType'];?>&ledgerentry=<?php echo $_REQUEST['ledgerentry']; ?>&ledgerdata=<?php echo $ledgerid; ?>",1000,1000)' href="#"   >Print</a></p></p>
<table width="98%" border="0" cellspacing="3" cellpadding="3" align="center">
    	<tr bgcolor="#666666" style="color:#FFFFFF"><td colspan="8"><strong>Ledger : <?php echo $getLedgerName1;?></strong></td></tr>
    	<tr bgcolor="#666666" style="color:#FFFFFF">
    	    <td width="10%"><strong> Date</strong></td>
    	    <td width="20%"><strong>Particulars</strong></td>
			<td width="20%"><strong>Voucher No </strong></td>
     	     <td width="10%"><strong>Voucher Type </strong></td>
			 <td width="20%"><strong>Debit Amount(INR)</strong></td>
    	    <td width="20%"><strong>Credit Amount(INR).</strong></td>
    	    <?php if($_SESSION['ledgerentry']==1 || $_SESSION['ledgerentry']==2) {      ?> 
    	     <td width="40%"><strong>Narrations</strong></td><?php } ?>
			<td  width="5%"><strong>View</strong></td>
   	      </tr>
		  <?php
		   $TCR=array();$TDR=array();  //echo $ledgerid;
		     if($_REQUEST['AcType']=='Ledger')
			 {
			 $getClientLedger=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerid."'" ,'vender_client');
			 $getPartyCode=$s->GetFieldValue('suppliers',"id='".$getClientLedger."'" ,'vendor_code');
			 $educess=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerid."'" ,'taxid');
			 
			 if($getClientLedger!='')
			    $GetRecord2="SELECT  * FROM `purchase_billbook` A   where   A.bill_date   between  '".str_replace('/','-', $todate)."' and '".str_replace('/','-',$fromdate)."'      and A.vendor='".$getPartyCode."'  ";
			    else
				 {
				    $GetRecord2="SELECT  * FROM `purchase_billbook` A   where   A.bill_date   between  '".str_replace('/','-', $todate)."' and '".str_replace('/','-',$fromdate)."'      and ( A.ledger_list='".$ledgerid."'  or A.exciseDuty_id='".$educess."' or taxname='".$educess."'  ) ";
				 }
				
				  $_SESSION['ledger1']=$GetRecord2;
				   
				 //echo "2===".$GetRecord2;
				   $ResultData2 = DB_query($GetRecord2,$db) ;
				 
 			   while($RowData2 = DB_fetch_array($ResultData2))
			   {?>
				<tr bgcolor="#FFFFFF">
				<td><?php echo ConvertSQLDate($RowData2['bill_date'])  ?></td>
				<td><?php  //echo $RowData2['ledgerid']; ?>
				<?php  
				//echo "<br>".$RowData2['ledger_list'];
				if($getClientLedger!='')
				echo $s->getField('accountledger','AccountsID',$RowData2['ledger_list'],'AccountName');
				else
				echo $PartyCode=$s->GetFieldValue('suppliers',"vendor_code='".$RowData2['vendor']."'" ,'vendor_name');
				?>			</td>    
				<td><?php echo $RowData2['bill']; ?></td>  
				<?php ?>
	    	     <td width="10%">Purchase  </td>
				<td><?php if($getClientLedger!=''){
	 			echo $AMTDR=0;}
				else if($educess!=''){echo $AMTDR=$RowData2['Excise_Duty'];}
				else {echo $AMTDR=$RowData2['basic_amount'];}
	 			$TDR[]= $AMTDR;
				 ?></td>
				<td><?php  
				if($getClientLedger!=''){
				echo  $AMTCR=$RowData2['grand_total'];}
				else {$AMTCR=0;}
				$TCR[]= $AMTCR;
				?></td>    	    
				 
				 
				 
				 <td>
				 <?php if($_REQUEST['AcType']!='Day' && $_REQUEST['AcType']!='Ledger'){
				 $Vprefixval=$arrBook[$i];
				 }
				 ?> 
				 <a href="#" onclick='popup("DispPurchBillBook.php?viewId=<?php  echo $RowData2['id'].$rurl?>",600,600)'><img src="images/search.gif"  width="20" height="20"/></a></td>	    
			</tr>
			
			<?php  
			}
		  
		   
		    }			
			
//*************************************************************************************************		   
		   
		 
 		   if(DB_num_rows($ffilter1)>0)
		  { 
		  	     $flag='';	 
			  while($RowData1=DB_fetch_array($ffilter1))
			   {
				if($RowData1['amount_type']=='CR')
				{
					$get_DRLedger="Select ledgerid from account_book_details where account_bookid='".$RowData1['Pid']."' and amount_type='DR'";
					$res=DB_query($get_DRLedger,$db);
				}
				else if($RowData1['amount_type']=='DR')
				{
					$get_CRLedger="Select ledgerid from account_book_details where account_bookid='".$RowData1['Pid']."' and amount_type='CR'";
					
					
					$res=DB_query($get_CRLedger,$db);
				}
				
				//echo $RowData1['account_bookid'];
				if($_REQUEST['AcType']=='Day' || $_SESSION['ledgerentry']==2 || $_SESSION['ledgerentry']==3)
				{
				if($flag!=$RowData1['account_bookid'])
				{
				$flag=$RowData1['account_bookid'];
				$count=1;	
				}
              else
              {
              	 $count=0;
              }	
				}				
				
				$ledger_row=DB_fetch_array($res);
			   ?>
				<tr bgcolor="#FFFFFF">
				<td><?php if($flag==$RowData1['account_bookid'] and $count!=0 and $_REQUEST['AcType']=='Day' || $_SESSION['ledgerentry']==2 || $_SESSION['ledgerentry']==3 ){ echo ConvertSQLDate($RowData1['Dates']) ;} 
				else if($_REQUEST['AcType']!='Day' and $_REQUEST['ledgerentry']!=2 and  $_SESSION['ledgerentry']!=3) { echo ConvertSQLDate($RowData1['Dates']) ;}
					?></td>
				<td><?php 		
				 //echo $GetRecord1;
				 //echo $RowData1['ledgerid']; ?>
				
				<?php 
				if($_REQUEST['AcType']!='Day' and $_SESSION['ledgerentry']!=2 and $_SESSION['ledgerentry']!=3)
				{
				$acid=DB_query("select ledgerid from account_book_details where ledgerid!='".$RowData1['ledgerid']."' and account_bookid='".$RowData1['account_bookid']."' limit 1 ",$db);
				$acid1=DB_fetch_array($acid);
				 echo $s->getField('accountledger','AccountsID',$acid1['ledgerid'],'AccountName');
				}
				else 
				{				
				echo $s->getField('accountledger','AccountsID',$RowData1['ledgerid'],'AccountName');
				}
				?></td>    
				<td><?php if($flag==$RowData1['account_bookid'] and $count!=0 and $_REQUEST['AcType']=='Day' ){  echo $RowData1['Voucher_NO'];}
				else if($_REQUEST['AcType']!='Day'){  echo $RowData1['Voucher_NO'];  } ?></td>  
				<?php ?>
	    	     <td width="10%">  <?php  echo $RowData1['VPrefix'];
				
			
			if($_REQUEST['AcType']=='Day' || $_REQUEST['AcType']=='Ledger')
			{
										 
 			echo	 $s->getField('voucher_master','VoucherType',$RowData1['Vprefix'],'VPrefix');
		  	$Vprefixval= $s->getField('voucher_master','VoucherType',$RowData1['Vprefix'],'VoucherType');
			}else{ 			
			echo   $s->GetFieldValue('voucher_master',"VoucherType='".$RowData1['Prefixtype']."'", 'VPrefix');
			//echo $RowData1['amount_type'];
			}
				  ?>  </td>
				<td><?php  
				if($RowData1['amount_type']=='DR')
				echo $AMTDR=$RowData1['AMT'];
				else
				 echo $AMTDR=0;
				 
				$TDR[]= $AMTDR;;
				 ?></td>
				<td><?php  
				if($RowData1['amount_type']=='CR')
				echo $AMTCR=$RowData1['AMT'];
				else
				 echo $AMTCR=0;
				$TCR[]= $AMTCR;;
				?></td>
				 <?php if($_SESSION['ledgerentry']==1 || $_SESSION['ledgerentry']==2) {      ?> 
				<td><?php
					 if($flag==$RowData1['account_bookid'] and $count!=0 and $_REQUEST['AcType']=='Day' || $_SESSION['ledgerentry']==2 || $_SESSION['ledgerentry']==3 )
					{ echo $s->getField('account_book','id',$RowData1['account_bookid'],'narration'); }
                  else if($_REQUEST['AcType']!='Day' and $_SESSION['ledgerentry']!=2 and  $_SESSION['ledgerentry']!=3){
                  	echo $s->getField('account_book','id',$RowData1['account_bookid'],'narration'); } ?></td>    	    
				 <?php } ?><td>
				 <?php if($_REQUEST['AcType']!='Day' && $_REQUEST['AcType']!='Ledger'){
				 $Vprefixval=$arrBook[$i];
				 }
				 ?>
				 <a href="#" onclick='popup("address_book.php?id=<?php  echo $RowData1['Pid'].$rurl?>&VPrefix=<?php echo $Vprefixval;?>",600,600)'><img src="images/search.gif"  width="20" height="20"/></a></td>	    
			</tr>

			
			<?php  
			}
	  }
		  //else{echo "<tr><td colspan=4>No Record</td></tr>";}
 		?>
		<?php if($_REQUEST['AcType']=='Ledger'){?>
		<tr bgcolor="#666666" style="color:#FFFFFF">
 		  <td>&nbsp;</td>
 		   
 		  <td>&nbsp;</td>
		  
		  <td>&nbsp;</td>
		  
		   
 		  <td nowrap="nowrap"> <strong>Opening Balance:</strong> </td>
 		  <td><b><?php echo $openingDRBalance;?></b></td>
 		<td><b><?php echo $openingCRBalance;?></b></td>  <td>&nbsp;</td>
 		<?php if($_SESSION['ledgerentry']==1 || $_SESSION['ledgerentry']==2) { ?> <td>&nbsp;</td><?php } ?>
	   </tr><?php }?>
	    <tr bgcolor="#666666" style="color:#FFFFFF">
 		  <td>&nbsp;</td>
 		    <td>&nbsp;</td>
 		  <td>&nbsp;</td>
 		 
		  <?php if($_REQUEST['AcType']=='Day' || $_REQUEST['AcType']=='Ledger'){?>
		   <?php }?>
		   
 		  <td nowrap="nowrap"> <strong>Current Total:</strong> </td>
 		  <td><b><?php echo array_sum($TDR); ?></b>&nbsp;</td>
 		<td><b><?php echo array_sum($TCR); ?></b></td> <td>&nbsp;</td>
 		<?php if($_SESSION['ledgerentry']==1 || $_SESSION['ledgerentry']==2) {      ?> <td>&nbsp;</td><?php } ?>
	    </tr>
	    <?php if($_REQUEST['AcType']=='Ledger'){?>
	    <tr bgcolor="#666666" style="color:#FFFFFF">
 		  <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> <strong>Closing Balance:</strong> </td>
 		  <td><b><?php echo $DR_balance;?></b></td>
 		<td><b><?php echo $CR_balance;?></b></td> <td>&nbsp;</td>
 		<?php if($_SESSION['ledgerentry']==1 || $_SESSION['ledgerentry']==2) {      ?>
 		<td>&nbsp;</td><?php } ?>
	    </tr>
	    <?php }?>
  	  </table>
	  
	  <!-------------------------->
	  
<?php } ?>


<!------------------------->
<?php } ?>
      </p>
    </div>
   <?php }
 } ?>
  </div>
</div>
<script language="JavaScript">
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>
