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

<?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 validation()
{
 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>
 
<div id="container">
  <div id="tabs" style="width:100%; height:auto; float:left; box-sizing:border-box;">
 
    <ul>
	<?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="";
  	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('Day','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];?> Book</a></li>
	<?php }?>
	
    </ul>
 
	<?php 
 for($j=0,$i=0;$i<count($arrBook);$i++,$j++)
{	
if($_REQUEST['Search'])
	  {		 
 		 $_SESSION['ledgerid']=$_REQUEST['ledgerid'];
		$ledgerid=$_SESSION['ledgerid'];
		//echo $_SESSION['ledgerid'];
 		//echo $_REQUEST['ledgerentry'];
		$_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'];
		$_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['AcType']!='DayBook' && $_REQUEST['AcType']!='Ledger' && $_REQUEST['AcType']!='purch'){
			$GetRecord1="SELECT A.VPrefix  ,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.VPrefix  ='".$arrBook[$i]."' 
			and A.cancel_status=0 ORDER BY  A.Dates ASC";
		}
		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  '".$todate_1."' and '".$fromdate_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  '".$todate_1."' and '".$fromdate_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' )
		{	//echo "manvi";
		$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')
		 {
		 	$GetRec ="SELECT  A.Vprefix,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,  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']);
			}
			
			$GetRec2="Select * from purchase_billbook where bill_book_date between '".$todate_1."' and '".$fromdate_1."'
			 and site='".$_REQUEST['site']."'";
			$ResultData6=DB_query($GetRec2,$db);
			$numrows6 = DB_num_rows($ResultData6);
			while($RowData6=DB_fetch_array($ResultData6))
			{
				$data_array[]=array('Pid'=>$RowData6['id'],'date'=>$RowData6['bill_book_date'],'flag'=>'bill','Voucher_NO'=>$RowData6['bill_book_no'],'Vprefix'=>'Purchase');
			}
			
			//echo "<pre>";
			//print_r($data_array);
			
			
			if(!empty($data_array)){
			foreach ($data_array as $key =>$value)
    		{
    			$data_arrange[$key]= $value['date'];
			}
					
			array_multisort($data_arrange,SORT_ASC,$data_array);
			}
			//echo "<br />----<br />";
			//print_r($data_array);
			
		 }
		 else if($_REQUEST['AcType']=='purch')
		 {
		 	$GetRec="SELECT  A.Vprefix,A.Voucher_NO ,A.id AS Pid, A.Dates   FROM `account_book` A where   A.Dates between  '".$todate_1."' and '".$fromdate_1."' and A.cancel_status=0  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']);
			}
			if($_REQUEST['ledgerid']!="" && $_REQUEST['site']!="0"){
					$GetRec2="Select * from purchase_billbook where bill_book_date between '".$todate_1."' and '".$fromdate_1."' AND vendor='".$s->GetFieldValue('accountledger',"AccountsID='".$_REQUEST['ledgerid']."'",'vender_client')."' AND site='".$_REQUEST['site']."'";
			}else if($_REQUEST['ledgerid']!="" && $_REQUEST['site']=="0"){
					$GetRec2="Select * from purchase_billbook where bill_book_date between '".$todate_1."' and '".$fromdate_1."' AND vendor='".$s->GetFieldValue('accountledger',"AccountsID='".$_REQUEST['ledgerid']."'",'vender_client')."'";
			}else if($_REQUEST['ledgerid']=="" && $_REQUEST['site']!="0"){
					$GetRec2="Select * from purchase_billbook where bill_book_date between '".$todate_1."' and '".$fromdate_1."' AND site='".$_REQUEST['site']."'";
			}else{
					$GetRec2="Select * from purchase_billbook where bill_book_date between '".$todate_1."' and '".$fromdate_1."'";
			}
			$ResultData6=DB_query($GetRec2,$db);
			$numrows6 = DB_num_rows($ResultData6);
			while($RowData6=DB_fetch_array($ResultData6))
			{
				$data_array[]=array('Pid'=>$RowData6['id'],'date'=>$RowData6['bill_book_date'],'flag'=>'bill','Voucher_NO'=>$RowData6['bill_book_no'],'Vprefix'=>'Purchase');
			}
			
			//echo "<pre>";
			//print_r($data_array);
			
			
			if(!empty($data_array)){
				foreach ($data_array as $key =>$value)
    			{
    				$data_arrange[$key]= $value['date'];
				}
			
				array_multisort($data_arrange,SORT_ASC,$data_array);
			}
			//echo "<br />----<br />";
			//print_r($data_array);
			
		 }
	$_SESSION['SAl']=$GetRec;
	$_SESSION['SAl2']=$GetRec2;
	$_SESSION['ACGAccountBookQuery']=$GetRecord1;  
	//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%;">
 <h1>
<?php 
//echo $_REQUEST['AcType'];
if(isset($_REQUEST['AcType']))
{
if($_REQUEST['AcType']=="purch"){
echo "Purchase Bill";
}else{
echo $_REQUEST['AcType'];
}
}else{?>
<?php  echo $s->getField('voucher_master','VoucherType',$arrBook[$i],'GroupName')?>
 <?php }?> Book</h1>

<form action="" method="post" onsubmit="return validation()">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
<td width="33%" style="padding:2px 10px;"><select name="site" style="width:98%;">
  <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="33%" style="padding:2px 10px;">
<select name="ledgerentry" id="ledgerentry" style="width:98%;">
<option value="1" <?php if($_SESSION['ledgerentry']==1) { ?> selected="selected" <?php } ?>>Single Entry With Narrations</option>
<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>	
<option value="4" <?php if($_SESSION['ledgerentry']==4) { ?> selected="selected" <?php } ?>>Single Entry </option>
</select>	
</td>
<?php if($_REQUEST['AcType']!='DayBook' ){ ?>
<td style="padding:2px 10px;"><?php
 	if($LDR!=''){
	$LRX=implode("|",$LDR);		
	  $sqlCate = "select * from  accountgroupmaster  where    GroupName REGEXP '^$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')
	?>
	<select name="ledgerid" style="width:98%;">
	<?php 
 	   $AccountMaster->AccountLeger($_REQUEST['ledgerid'],'ledgerid','ledgerid',$undergroup);	   
	   
    ?></select></td><?php } ?>	
	
	<td><input name="todate"  id="todate" type="text" style="width:98%;" class="datepicker"  value="<?php  echo $_SESSION['todate']?>"/></td>
	
<td><input name="fromdate" id="fromdate" type="text" style="width:98%;" class="datepicker"value="<?php  echo $_SESSION['fromdate']?>" /></td>

<?php 
	 if($_REQUEST['AcType']=='Day'){
	?>
	<td>
	<select name="Viewtype" style="width:98%;">
	<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" class="search"  value="Search"/></td>
</tr>
</table>
</form>
	  

	<form name="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr bgcolor="#d4d4d4" style="height:30px;">
    <td><strong>Type of info</strong></td>
    <td><select name="Type_of_info" style="width:150px;">
		<option value="0">Select</option>
		<option value="voucher"<?php echo($_REQUEST['Type_of_info']=='voucher'?'selected':'')?>>voucher</option>
	</select>
	</td>
    <td><strong>Having</strong></td>
    <td><select name="having" style="width:150px;">
		<option value="0">Select</option>
		<option value="voucherno" <?php echo($_REQUEST['having']=='voucherno'?'selected':'')?>>Voucher no</option>
		<option value="vouchertype"<?php echo($_REQUEST['having']=='vouchertype'?'selected':'')?>>Voucher type</option>
		<option value="narration"<?php echo($_REQUEST['having']=='narration'?'selected':'')?>>Narration</option>
		<option value="instrumentno"<?php echo($_REQUEST['having']=='instrumentno'?'selected':'')?>>Instrument no</option>
		<option value="searchledger"<?php echo($_REQUEST['having']=='ledger'?'selected':'')?>>Ledger</option>
		<option value="amount"<?php echo($_REQUEST['having']=='amount'?'selected':'')?>>Amount</option>
	</select>
	</td>
    <td><strong>Range of info</strong></td>
    <td><select name="range_of_info" style="width:150px;">
		<option  value="0">Select</option>
		<option value="containing"<?php echo($_REQUEST['range_of_info']=='containing'?'selected':'')?>>Containing</option>
		<option value="equalto"<?php echo($_REQUEST['range_of_info']=='equalto'?'selected':'')?>>Equal to</option>
		<option value="startingwith"<?php echo($_REQUEST['range_of_info']=='startingwith'?'selected':'')?>>starting with</option>
	</select>
	</td>
    <td><strong>Text</strong></td>
    <td><input type="text" value="<?php echo $_REQUEST['searchtext']; ?>" name="searchtext" style="width:150px;"/></td>
	<td colspan="2"><input type="submit" name="filter" class="search" value="Go" /></td>
  </tr>
</table>
</form>
 	  <?php
 	  
	
//	unset($_SESSION['ACGAccountBookQuery']);
	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";	
		  					}
		  
		  				break;
	/*	  case 'amount':
		  
		  				 if($range=='equalto')
		  					$filter=" A.Voucher_NO ='".$searchtext."'";
							if($range=='containing')
		  					$filter=" A.Voucher_NO  like'%".$searchtext."%'";					
							if($range=='startingwith')
		  					$filter=" 1=1";	
						break;*/
		   																										
		}
		 
		//echo 		 $_SESSION['ACGAccountBookQuery'];
		// echo "<br>--------------------------------------------------------<br>";
		// echo $ledgerid;
	$todate_1=FormatDateForSQL($_SESSION['todate']);
	$fromdate_1=FormatDateForSQL($_SESSION['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  '".$todate_1."' and '".$fromdate_1."' and A.VPrefix  ='".$arrBook[$i]."' and A.cancel_status=0   ".$query;
	  }
		else if($_REQUEST['AcType']=='Day')
		{
		   if($Viewtype=='ALL'){ 
   		     $GetRecord1 = "SELECT  A.Vprefix,A.Voucher_NO ,A.id AS Pid, A.Dates   FROM `account_book` A where   A.Dates between  '".$todate_1."' and '".$fromdate_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  '".$todate_1."' and '".$fromdate_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  '".$todate_1."' and '".$fromdate_1."' and A.cancel_status=0  ".$query;

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

<?php 
	if($_SESSION['ACGAccountBookQuery']!='' || $GetRec!='')
	{
	// echo $_REQUEST['AcType'];
    	//echo $_SESSION['ACGAccountBookQuery'];
		
		if($GetRecord1!=''){
		$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 style="height:10px;"></p>
	   
	   
 	  <p align="right">
	  <?php 
	  			####New Link for print and export added by Himanshu 18 September 2012 ###### 
	if($_REQUEST['AcType']=='Day' || $_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']?>">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']?>">Export</a></p>
	  
	 <?php 
	 	}
		else
		{
			if($_REQUEST['tabid']=='0')
			{?>
			<a href="PrintAccountBooDetails.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']?>">Export</a></p>
		<?php 
			}
			if($_REQUEST['tabid']=='1')
			{?>
			<a onclick='popup("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']?>",1000,1000)' href="#"   >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>
		<?php 
			}
			
			if($_REQUEST['tabid']=='2')
			{?>
			<a onclick='popup("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']?>",1000,1000)' href="#"   >Print</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></p>
		<?php 
			}
			if($_REQUEST['tabid']=='3')
			{?>
			<a onclick='popup("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']?>",1000,1000)' href="#"   >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></p>
		<?php 
			}
			if($_REQUEST['tabid']=='4')
			{?>
			<a onclick='popup("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']?>",1000,1000)' href="#"   >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></p>
		<?php 
			}
			if($_REQUEST['tabid']=='5')
			{?>
			<a onclick='popup("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']?>",1000,1000)' href="#"   >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></p>
		<?php 
			}
			if($_REQUEST['tabid']=='6')
			{?>
			<a onclick='popup("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']?>",1000,1000)' href="#"   >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></p>
		<?php 
			}
			if($_REQUEST['tabid']=='7')
			{?>
			<a onclick='popup("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']?>",1000,1000)' href="#"   >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></p>
		<?php 
			}
			if($_REQUEST['tabid']=='8')
			{?>
			<a onclick='popup("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']?>",1000,1000)' href="#"   >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></p>
		<?php 
			}
			if($_REQUEST['tabid']=='9')
			{?>
			<a onclick='popup("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']; ?>",1000,1000)' href="#">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></p>
		<?php 
			}
			if($_REQUEST['tabid']=='11')
			{?>
			<a onclick='popup("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']; ?>",1000,1000)' href="#">Print</a>
	  &nbsp;&nbsp;&nbsp;&nbsp;
	  <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']; ?>">Export</a></p>
		<?php 
			}

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

<table width="100%" border="1" cellspacing="0" cellpadding="3" align="center" style="border:#666666 solid 2px;">
<tr style="height:30px;">
	<td class="tabledata" style="padding-top:5px; padding-bottom:5px; padding-left:5px; border-bottom:#000000 1px solid;"><strong>Ledger : <?php echo $getLedgerName;?></strong></td>
	<td class="tabledata" style="padding-top:5px; padding-bottom:5px; padding-left:5px; border-bottom:#000000 1px solid;">&nbsp;</td>
	<td class="tabledata" style="padding-top:5px; padding-bottom:5px; padding-left:5px; border-bottom:#000000 1px solid;">&nbsp;</td>
	<td class="tabledata" style="padding-top:5px; padding-bottom:5px; padding-left:5px; border-bottom:#000000 1px solid;">&nbsp;</td>
	<td class="tabledata" style="padding-top:5px; padding-bottom:5px; padding-left:5px; border-bottom:#000000 1px solid;">&nbsp;</td>
	<td class="tabledata" style="padding-top:5px; padding-bottom:5px; padding-left:5px; border-bottom:#000000 1px solid;">&nbsp;</td>
	<td class="tabledata" style="padding-top:5px; padding-bottom:5px; padding-left:5px; border-bottom:#000000 1px solid;">&nbsp;</td>
	<td class="tabledata" style="padding-top:5px; padding-bottom:5px; padding-left:5px; border-bottom:#000000 1px solid;">&nbsp;</td>
</tr>
<tr>
	<td class="tabledata"  style="width:65px; border-right:1px solid #333333;"><strong> Date</strong></td>
	<td class="tabledata"  style="width:290px; border-right:1px solid #333333;"><strong>Particulars</strong></td>
	<td class="tabledata"  style="width:120px; border-right:1px solid #333333;"><strong>V. No </strong></td>
	<td class="tabledata" style="width:50px; border-right:1px solid #333333;"><strong>V. Type </strong></td>
	<td class="tabledata" style="width:120px; border-right:1px solid #333333;"><span class="tabledata" style="padding-top:5px; padding-bottom:5px; padding-left:5px; border-bottom:#000000 1px solid;"><strong>Debit Amount</strong></span></td>
	<td class="tabledata" style="width:120px; border-right:1px solid #333333;"><span class="tabledata" style="padding-top:5px; padding-bottom:5px; padding-left:5px; border-bottom:#000000 1px solid;"><span class="tabledata" style="width:120px; border-right:1px solid #333333;"><strong>Credit Amount</strong></span></span></td>
	<?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> 
	<td class="tabledata" style="width:280px; border-right:1px solid #333333;"><strong>Remarks</strong></td>
	<?php } ?>
	<td class="tabledata" style="width:50px; border-right:1px solid #333333;"><strong>View</strong></td>
</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>";

	 
			  $ResultData3 = DB_query( $_SESSION['ACGAccountBookQuery'],$db);
	  	 	  $numrows = DB_num_rows($ResultData3);
			 while($RowData3=DB_fetch_array( $ResultData3 ))
			 {
			    if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==4)
				{
					   $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 ='". $RowData3['Pid']."' and B.ledgerid='".$ledgerid."' AND A.ledgerid!='".$ledgerid."'   and  A.account_bookid=B.account_bookid    GROUP BY A.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 ='".$RowData3['Pid']."' and A.ledgerid='".$ledgerid."' and  A.account_bookid=B.account_bookid",$db);
						
 						}
			
			 if(DB_num_rows($ResultData2)>0)
			  {	 
			 ?>
			 
			<tr bgcolor="#c1c1c1">
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;"><?php echo ConvertSQLDate($RowData3['Dates']) 	?></td>
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>    
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;"><?php echo $RowData3['Voucher_NO'];?> </td>  
				<?php ?>
	    	     <td style="border-right:1px solid #333333;padding-top:5px; padding-bottom:5px; padding-left:5px;"><?php echo $s->GetFieldValue('voucher_master',"VoucherType='".$RowData3['Prefixtype']."'",'GroupName');?></td>
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp; </td>
				 <?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> 
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;"><?php echo $s->getField('account_book','id',$RowData3['Pid'],'narration');?></td>    	    
				<?php } ?>
				  
				 <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">
				  <?php $Vprefixval=$arrBook[$i];	
				  //echo $RowData3['Pid'];			 
				 ?>
				 <a href="#" onclick='popup("address_book.php?id=<?php echo $RowData3['Pid'].$rurl?>&VPrefix=<?php echo $Vprefixval;?>",600,600)'><img src="images/search.gif"  width="50" height="50"/></a>				 </td>    
			</tr>
			<?php 
 				 while($RowData2 = DB_fetch_array($ResultData2))
			  	 { 
				?>
				<tr bgcolor="#c1c1c1">
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp; 
				<?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 style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>  
				<?php ?>
	    	     <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php  
				if($RowData2['amount_type']=='DR')
				{
				//$brk=explode('.',$RowData2['amount']);
				//indianNumberFormat($brk[0],$brk[1]);
				//echo "<br /><br />";
				//echo "_________".number_format($brk[0], 2, ',', ',');
				//echo "<br /><br />";
				echo $AMTDR=$RowData2['amount'];}
				else
				 {echo $AMTDR=0;}
				 
				$TDR[]= $AMTDR;
				 ?></td>
				<td style="border-right:1px solid #333333;padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?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 style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>    	    
				<?php } ?>
				
				 
				 <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>    
			</tr>
				
			   <?php 
			   
			   }
			?><tr bgcolor="#c1c1c1"><td colspan="8" style="border:1px solid #333333;"></td></tr>
			 <?php }
			 }
	 
	 }
		
		else if($_REQUEST['AcType']=='DayBook')
		   {
		     //echo "<br>------------------22--------------".$_REQUEST['AcType']."-----------------------------------<br>";
  		   	 
			  //if(DB_num_rows($ResultData5)>0)
			  if(count($data_array)>0)
			  { 
		  	     $flag='';	
				 
 			   //while($RowData1 = DB_fetch_array($ResultData5))
			   $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);}
					   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);
						}
					}	
					elseif($val['flag']=='bill')
					{
						if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==4)	 
						{
							$ResultData2=DB_query("select * from purchase_billbook where id ='". $val['Pid']."' GROUP BY id ",$db);
						}
						else
						{
							//echo "select * from purchase_billbook where id ='". $val['Pid']."'";
							$ResultData2=DB_query("select * from purchase_billbook where id ='". $val['Pid']."'",$db);
						}
					}	
						
						
			if(DB_num_rows($ResultData2)>0)
			  {		
			   ?>
			   <tr bgcolor="#c1c1c1">
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo ConvertSQLDate($val['date'])?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $val['Voucher_NO'];?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php 
			       if($val['flag']=='voucher'){
					echo  $Vprefixval= $s->getField('voucher_master','VoucherType',$val['Vprefix'],'GroupName');}
					else{echo $val['Vprefix'];}
 				  ?> 			   </td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> 
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php	echo $s->getField('account_book','id',$val['Pid'],'narration');  ?></td><?php } ?>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;"><a href="#" onclick='popup("purch_bill_popup.php?viewId=<?php  echo $val['Pid'].$rurl?>&VPrefix=<?php echo $Vprefixval;?>",600,600)'><img src="images/search.gif"  width="50" height="50"/></a></td>
			   </tr>
 				<?php $AMTDR=0; $AMTCR=0; 
				 while($RowData2 = DB_fetch_array($ResultData2))
			  	 { 
				?>
 				<tr bgcolor="#c1c1c1">
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php 
				if($val['flag']=='voucher'){
				echo $s->GetFieldValue('accountledger',"AccountsID='".$RowData2['ledgerid']."'",'AccountName');
				}else
				{	
					echo $s->GetFieldValue('suppliers',"id='".$RowData2['vendor']."'",'vendor_name');
				}
				?></td> 
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>   
				<?php ?>
	    	     <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php
				 echo $RowData2['VPrefix'];
				  	echo  $s->GetFieldValue('voucher_master',"VoucherType='".$RowData2['VPrefix']."'",'GroupName');?> </td>
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?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="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php $AMTCR=0;
				if($val['flag']=='bill'){
				echo $AMTCR=$RowData2['GrandTotal'];
				}
				elseif($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 style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>    	    
				<?php } ?>
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>    
			</tr>
			   <?php  
			   if($val['flag']=='bill' && ($_REQUEST['ledgerentry']==2 || $_REQUEST['ledgerentry']==3)){
			   		$pckg_ledger=$s->getField('accountledger','AccountsID',$RowData2['pckg_ledger'],'AccountName');
			   		$pckg_val=$s->getField('purchase_billbook','pckg_ledger',$RowData2['pckg_ledger'],'pkg_charges');	
			   ?>
			  <tr bgcolor="#c1c1c1">
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $s->getField('accountledger','AccountsID',$RowData2['ledger'],'AccountName'); ?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php //$s->getField('purchase_billbook','ledger',$RowData2['ledger'],'total_basic_amount'); 
			   echo $AMTDR1[]=$s->GetFieldValue('purchase_billbook',"id=".$RowData2['id']." and ledger=".$RowData2['ledger'],'total_basic_amount');
			   ?></td>
			    <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			    <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   </tr>
			   <?php 
			   $excsql=DB_query("Select Excise_Duty from purchase_bill_details where purch_billbookid=".$RowData2['id']." group by Excise_Duty",$db);
			   while($excrow=DB_fetch_row($excsql))
				{
					if($excrow[0]!=0){
					echo "<tr bgcolor='#c1c1c1'><td style='border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;'>&nbsp;</td><td style='border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;'>";
					echo $s->getField('excise_tax','id',$excrow[0],'caption'); 
					$AMTDR1[]=$s->GetFieldValue('purchase_bill_details','purch_billbookid='.$RowData2['id'].' and Excise_Duty='.$excrow[0].'','SUM(Excise_Duty_value)');
					echo "</td>
					<td style='border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;'>&nbsp;</td>
			   		<td style='border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;'>&nbsp;</td>
					<td style='border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;'>".$s->GetFieldValue('purchase_bill_details','purch_billbookid='.$RowData2['id'].' and Excise_Duty='.$excrow[0].'','SUM(Excise_Duty_value)')."</td><td style='border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;'>&nbsp;</td><td style='border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;'>&nbsp;</td><td style='border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;'>&nbsp;</td></tr>"; 
					 }
				}
				if($pckg_ledger!=''){
			   ?>
			   <tr bgcolor="#c1c1c1">
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $pckg_ledger;?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td>&nbsp;<?php echo $AMTDR1[]=$pckg_val;?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   </tr>
			   <?php } 
					$cessSql1=DB_query("SELECT cess_ID1 FROM purchase_bill_details WHERE 
					purch_billbookid=".$RowData2['id']." and cess_ID1!=0 and Edu_Cess!=0 GROUP BY cess_ID1",$db);
					while($cessRow1=DB_fetch_assoc($cessSql1))
					{
						if(!empty($cessRow1)){
			   ?>
			   <tr bgcolor="#c1c1c1">
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $s->getField('excise_tax','id',$cessRow1['cess_ID1'],'caption');?>&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $AMTDR1[]=$s->GetFieldValue('purchase_bill_details','purch_billbookid='.$RowData2['id'],'SUM(Edu_Cess)')?>&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   </tr>
			   <?php } }
			   $cessSql2=DB_query("SELECT cess_ID2 FROM purchase_bill_details WHERE 
					purch_billbookid=".$RowData2['id']." and cess_ID2!=0 and SHE_Cess!=0 GROUP BY cess_ID2",$db);
					while($cessRow2=DB_fetch_assoc($cessSql2))
					{
						
						if(!empty($cessRow2)){
			   ?>
			   <tr bgcolor="#c1c1c1">
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $s->getField('excise_tax','id',$cessRow2['cess_ID2'],'caption');?>&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $AMTDR1[]=$s->GetFieldValue('purchase_bill_details','purch_billbookid='.$RowData2['id'],'SUM(SHE_Cess)')?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   </tr>
			   <?php } }
			   $vatSql=DB_query("Select vat_cst from purchase_bill_details where purch_billbookid='".$RowData2['id']."' group by vat_cst",$db);
			   $vatnum=DB_num_rows($vatSql);
			   if($vatnum>0)
			   {
			   		while($vatRow=DB_fetch_array($vatSql))
					{
						if($vatRow['vat_cst']!=0){
					?>
					<tr bgcolor="#c1c1c1">
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			  		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $s->getField('sales_tax_master','salestax_id',$vatRow['vat_cst'],'tax_code');?></td>
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $AMTDR1[]=$s->GetFieldValue('purchase_bill_details','purch_billbookid='.$RowData2['id'].' 
					AND vat_cst='.$vatRow['vat_cst'].'','SUM(vat_cst_amt)');?></td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   		</tr>
					<?php } 	
					}
			   }
			   
			   $billChargesSql=DB_query("Select surcharge_ledger, freight_ledger, pckg_ledger, addcharge_ledger 
			   from purchase_billbook where id=".$RowData2['id']."",$db);
			   $billChargesRow=DB_fetch_assoc($billChargesSql);
			   //print_r($billChargesRow);
			   foreach($billChargesRow as $k=>$v)
			   {
			   	if($v!=0){
				$suracotamt=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'sur_oct_amt');
				$freightamt=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'freight');
				$pckamt=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'pkg_charges');
				$addamt=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'add_charges');
				if($suracotamt!=0.00 || $freightamt!=0.00 || $pckamt!=0.00 || $addamt!=0.00)
				{
			   ?>
			   	<tr bgcolor="#c1c1c1">
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			  		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $s->getField('accountledger','AccountsID',$v,'AccountName');?></td>
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;
					<?php if($k=='surcharge_ledger') 
					echo $AMTDR1[]=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'sur_oct_amt');
					elseif($k=='freight_ledger')
					echo $AMTDR1[]=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'freight');
					elseif($k=='pckg_ledger')
					echo $AMTDR1[]=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'pkg_charges');
					elseif($k=='addcharge_ledger')
					echo $AMTDR1[]=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'add_charges');
					?></td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   		</tr>
			   	<?php 			
			   }}
			   }
			   $rnameid=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'round_ledger');
			   $rval=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'round_off');
			   //echo $AMTDR1[]=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'pkg_charges');
			   if($rval!=0){
			   ?>
			   <tr bgcolor="#c1c1c1">
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			  		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $rname=$s->GetFieldValue('accountledger','AccountsID='.$rnameid,'AccountName');?></td>
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php if($rval>0){ echo $rval; $AMTDR1[]=$rval; }else{ echo "&nbsp;";}?></td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php if($rval<0){ echo abs($rval); $TCR[]=abs($rval); }else{ echo "&nbsp;";}?></td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   		</tr>
			   <?php 
			   }
			   }
			   }
			?><tr bgcolor="#c1c1c1"><td colspan="8" style="border-bottom:1px solid #333333;"></td></tr>
	   <?php }
			   
			   }
			?>
			
			<?php 
	  }
		   
		   }
	else if($_REQUEST['AcType']=='purch')
		   {
		     //echo "<br>------------------22--------------".$_REQUEST['AcType']."-----------------------------------<br>";
  		   	 
			  //if(DB_num_rows($ResultData5)>0)
			  if(count($data_array)>0)
			  { 
		  	     $flag='';	
				 
 			   //while($RowData1 = DB_fetch_array($ResultData5))
			   $AMTDR1='';
			   foreach($data_array as $k=>$val)
			   { 
			    if($val['flag']=='bill')
					{
						if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==4)	 
						{
							$ResultData2=DB_query("select * from purchase_billbook where id ='". $val['Pid']."' GROUP BY id ",$db);
							$ResultData21=DB_query("select * from purchase_billbook where id ='". $val['Pid']."' GROUP BY id ",$db);
						}
						else
						{
							//echo "select * from purchase_billbook where id ='". $val['Pid']."'";
							$ResultData2=DB_query("select * from purchase_billbook where id ='".$val['Pid']."'",$db);
							$ResultData21=DB_query("select * from purchase_billbook where id ='".$val['Pid']."'",$db);
						}
					}	
						
						
			if(DB_num_rows($ResultData21)>0)
			  {	
			  $getrow=DB_fetch_array($ResultData21);
			   ?><tr bgcolor="#c1c1c1">
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo ConvertSQLDate($val['date'])?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $val['Voucher_NO']; ?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php 
			       if($val['flag']=='voucher'){
					echo  $Vprefixval= $s->getField('voucher_master','VoucherType',$val['Vprefix'],'GroupName');}
					else{echo $val['Vprefix'];}
 				  ?> 			   </td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> 
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php	echo $getrow['remarks'];  ?></td><?php } ?>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;
				 <a href="#" onclick='popup("purch_bill_popup.php?viewId=<?php  echo $val['Pid'];?>",600,600)'><img src="images/search.gif"  width="50" height="50"/></a></td>	
			   </tr>
 				<?php $AMTDR=0; $AMTCR=0; 
				 while($RowData2 = DB_fetch_array($ResultData2))
			  	 { 
				?>
 				<tr bgcolor="#c1c1c1">
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php 
				if($val['flag']=='voucher'){
				echo $s->GetFieldValue('accountledger',"AccountsID='".$RowData2['ledgerid']."'",'AccountName');
				}else
				{	
					echo $s->GetFieldValue('suppliers',"id='".$RowData2['vendor']."'",'vendor_name');
				}
				?></td> 
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td> 
				<?php ?>
	    	     <td width="151" style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php
				 echo $RowData2['VPrefix'];
				  	echo  $s->GetFieldValue('voucher_master',"VoucherType='".$RowData2['VPrefix']."'",'GroupName');?></td>
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?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="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php $AMTCR=0;
				if($val['flag']=='bill'){
				echo $AMTCR=$RowData2['GrandTotal'];
				}
				elseif($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 style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>    	    
				<?php } ?>
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>    
			</tr>
			   <?php  
			   if($val['flag']=='bill' && ($_REQUEST['ledgerentry']==2 || $_REQUEST['ledgerentry']==3))
			   {
			   $pckg_ledger=$s->getField('accountledger','AccountsID',$RowData2['pckg_ledger'],'AccountName');
			   $pckg_val=$s->getField('purchase_billbook','pckg_ledger',$RowData2['pckg_ledger'],'pkg_charges');	
			   ?>
			   <tr bgcolor="#c1c1c1">
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $s->getField('accountledger','AccountsID',$RowData2['ledger'],'AccountName'); ?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $RowData2['total_basic_amount']; $AMTDR1[]=$RowData2['total_basic_amount'];?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   </tr>
			   <?php 
			   $excsql=DB_query("Select Excise_Duty from purchase_bill_details where purch_billbookid=".$RowData2['id']." group by Excise_Duty",$db);
			   while($excrow=DB_fetch_row($excsql))
				{
					if($excrow[0]!=0 || $excrow[0]!=0.00){
					echo "<tr bgcolor='#c1c1c1'><td style='border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;'>&nbsp;</td><td style='border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;'>&nbsp;";
					echo $s->getField('excise_tax','id',$excrow[0],'caption'); 
					$AMTDR1[]=$s->GetFieldValue('purchase_bill_details','purch_billbookid='.$RowData2['id'].' and Excise_Duty='.$excrow[0].'','SUM(Excise_Duty_value)');
					echo "</td>
					<td style='border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;'>&nbsp;</td>
			   		<td style='border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;'>&nbsp;</td>
					<td style='border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;'>".$s->GetFieldValue('purchase_bill_details','purch_billbookid='.$RowData2['id'].' and Excise_Duty='.$excrow[0].'','SUM(Excise_Duty_value)')."</td>
					<td style='border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;'>&nbsp;</td>
					<td style='border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;'>&nbsp;</td>
					<td style='border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;'>&nbsp;</td>
					</tr>";}
				}
				if($pckg_ledger!=''){
			   ?>
			   <tr bgcolor="#c1c1c1">
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $pckg_ledger;?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $AMTDR1[]=$pckg_val;?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   </tr>
			   <?php } 
					$cessSql1=DB_query("SELECT cess_ID1 FROM purchase_bill_details WHERE 
					purch_billbookid=".$RowData2['id']." and cess_ID1!=0 GROUP BY cess_ID1",$db);
					while($cessRow1=DB_fetch_assoc($cessSql1))
					{
						if(!empty($cessRow1)){
						if($s->GetFieldValue('purchase_bill_details','purch_billbookid='.$RowData2['id'],'SUM(Edu_Cess)')!=0){
			   ?>
			   <tr bgcolor="#c1c1c1">
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $s->getField('excise_tax','id',$cessRow1['cess_ID1'],'caption');?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $AMTDR1[]=$s->GetFieldValue('purchase_bill_details','purch_billbookid='.$RowData2['id'],'SUM(Edu_Cess)')?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   </tr>
			   <?php }} }
			   $cessSql2=DB_query("SELECT cess_ID2 FROM purchase_bill_details WHERE 
					purch_billbookid=".$RowData2['id']." and cess_ID2!=0 GROUP BY cess_ID2",$db);
					while($cessRow2=DB_fetch_assoc($cessSql2))
					{
						if(!empty($cessRow2)){
						if($s->GetFieldValue('purchase_bill_details','purch_billbookid='.$RowData2['id'],'SUM(SHE_Cess)')!=0){
			   ?>
			   <tr bgcolor="#c1c1c1">
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $s->getField('excise_tax','id',$cessRow2['cess_ID2'],'caption');?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $AMTDR1[]=$s->GetFieldValue('purchase_bill_details','purch_billbookid='.$RowData2['id'],'SUM(SHE_Cess)')?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   </tr>
			   <?php } }}
			   $vatSql=DB_query("Select vat_cst from purchase_bill_details where purch_billbookid='".$RowData2['id']."' group by vat_cst",$db);
			   $vatnum=DB_num_rows($vatSql);
			   if($vatnum>0)
			   {
			   		while($vatRow=DB_fetch_array($vatSql))
					{
						if($vatRow['vat_cst']!=0){
					?>
					<tr bgcolor="#c1c1c1">
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			  		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $s->getField('sales_tax_master','salestax_id',$vatRow['vat_cst'],'tax_code');?></td>
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $AMTDR1[]=$s->GetFieldValue('purchase_bill_details','purch_billbookid='.$RowData2['id'].' 
					AND vat_cst='.$vatRow['vat_cst'].'','SUM(vat_cst_amt)');?></td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   		</tr>
					<?php } 	
					}
			   }
			   
			   $billChargesSql=DB_query("Select surcharge_ledger, freight_ledger, pckg_ledger, addcharge_ledger 
			   from purchase_billbook where id=".$RowData2['id']."",$db);
			   $billChargesRow=DB_fetch_assoc($billChargesSql);
			   //print_r($billChargesRow);
			   foreach($billChargesRow as $k=>$v)
			   {
					if($v!=0){
						$suracotamt=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'sur_oct_amt');
						$freightamt=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'freight');
						$pckamt=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'pkg_charges');
						$addamt=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'add_charges');
						if($suracotamt!=0 && $k=='surcharge_ledger'){?>
					   		<tr bgcolor="#c1c1c1">
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $s->getField('accountledger','AccountsID',$v,'AccountName');?></td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;
								<?php echo $AMTDR1[]=$suracotamt;?></td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								</tr>
					   <?php }
					   if($freightamt!=0 && $k=='freight_ledger'){?>
					   		<tr bgcolor="#c1c1c1">
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $s->getField('accountledger','AccountsID',$v,'AccountName');?></td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;
								<?php echo $AMTDR1[]=$freightamt;?></td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								</tr>
					   <?php }
					   if($pckamt!=0 && $k=='pckg_ledger'){?>
					   		<tr bgcolor="#c1c1c1">
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $s->getField('accountledger','AccountsID',$v,'AccountName');?></td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;
								<?php echo $AMTDR1[]=$pckamt;?></td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								</tr>
					   <?php }
					   if($addamt!=0 && $k=='addcharge_ledger'){?>
					   		<tr bgcolor="#c1c1c1">
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $s->getField('accountledger','AccountsID',$v,'AccountName');?></td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;
								<?php echo $AMTDR1[]=$addamt;?></td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
								</tr>
					   <?php }
				   }
			   }
			   $rnameid=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'round_ledger');
			   $rval=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'round_off');
			   //echo $AMTDR1[]=$s->GetFieldValue('purchase_billbook','id='.$RowData2['id'],'pkg_charges');
			   if($rval!=0){
			   ?>
			   <tr bgcolor="#c1c1c1">
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			  		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $rname=$s->GetFieldValue('accountledger','AccountsID='.$rnameid,'AccountName');?></td>
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php if($rval>0){ echo $rval; $AMTDR1[]=$rval; }else{ echo "&nbsp;";}?></td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php if($rval<0){ echo abs($rval); $TCR[]=abs($rval); }else{ echo "&nbsp;";}?></td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
					<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   		</tr>
			   <?php 
			   }
			   }
			   }
			?><tr bgcolor="#c1c1c1"><td colspan="8">&nbsp;<hr></td></tr>
	   <?php }
			   
			   }
			?>
			
			<?php 
	  }else{?><tr bgcolor="#c1c1c1"><td colspan="8">No Record Founds</td></tr><?php }
		   
		   }   
	 if($_REQUEST['AcType']!='DayBook' && $_REQUEST['AcType']!='Ledger' && $_REQUEST['AcType']!='purch'){
	 	  //echo "<br>----------------333----------------".$_REQUEST['AcType']."-----------------------------------<br>";
 		 if($ResultData1!='')
		 {
 		  if(DB_num_rows($ResultData1)>0)
		  {  
		   while($RowData1 = DB_fetch_array($ResultData1))
			   {  
			   
			    if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==4)
				{
					   if($ledgerid!=''){
					   $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);			//echo "<br />select A.* FROM account_book_details A   where A.account_bookid ='". $RowData1['Pid']."'";
					   }
					//  echo "select A.* FROM account_book_details A   where A.account_bookid ='". $RowData1['Pid']."'     "; 
					   
					   }
					else					   
					{
					if($ledgerid!=''){
					   	$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);
							//echo "<br />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";
						}
//echo "--"."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";
						}
						
						
				if(DB_num_rows($ResultData2)>0)
				{	
			   ?>
			   <tr bgcolor="#c1c1c1">
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo ConvertSQLDate($RowData1['Dates'])?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo $RowData1['Voucher_NO'];	  ?></td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php echo  $vpr= $s->GetFieldValue('voucher_master',"VoucherType='".$RowData1['VPrefix']."'",'GroupName');?></td>   
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
			   <?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) { ?> 
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;
			   <?php	echo $s->getField('account_book','id',$RowData1['Pid'],'narration');  ?></td><?php } ?>
			   <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">
				 <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="20" height="20"/></a></td>	
			   </tr>
  					<?php 
 				 while($RowData2 = DB_fetch_array($ResultData2))
			  	 { 
				 		//echo "<pre>";
						//print_r($RowData2);
				    switch($vpr)
					{
					  case 'CP':  
					             break;
					}
				?>
				<tr bgcolor="#c1c1c1">
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp; 
				<?php 
				if($_REQUEST['AcType']!='Day'  &&  $_REQUEST['ledgerentry']!=2 && $_REQUEST['ledgerentry']!=3)
				{ 
				if($ledgerid=='')
				{
					echo $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 $s->GetFieldValue('accountledger',"AccountsID='".$acid1['ledgerid']."'",'AccountName');}
				}
				else 
				{	
				echo $s->GetFieldValue('accountledger',"AccountsID='".$RowData2['ledgerid']."'",'AccountName');
				}
				?></td>    
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>  
				<?php ?>
	    	     <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?php  
				if($RowData2['amount_type']=='DR')
				echo $AMTDR=$RowData2['amount'];
				else
				 echo $AMTDR=0;
				 
				$TDR[]= $AMTDR;;
				 ?></td>
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;<?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 style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>    	    
				<?php } ?>
				<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>    
			</tr>
				
			   <?php 
			   
			   }
			?><tr bgcolor="#c1c1c1"><td colspan="8" style="border:1px solid #333333;">&nbsp;</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 style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
 		   
 		  <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
		  
		  <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&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; height:20px">
 		  <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
 		  <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
 		  <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
 		 
		  <?php if($_REQUEST['AcType']=='Day' || $_REQUEST['AcType']=='Ledger'){?>
		   <?php }?>
		   
 		  <td nowrap="nowrap"> <strong><font size="3">Current Total:</font></strong></td>
 		  <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;"><b><font size="3">
		  <?php 
		  if(!empty($AMTDR1)){$TDR1=array_sum($AMTDR1);}else{$TDR1=0;}
		 // echo "<pre>";print_r($TDR);
		  echo round((array_sum($TDR)+$TDR1),2); 
		  //echo "<br /><br />---"; print_r($AMTDR1);
		   ?></font></b>&nbsp;</td>
 		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;"><b><font size="3"><?php /*echo "<pre>";print_r($TCR);*/echo round(array_sum($TCR),2); ?></font></b></td><td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
 		<?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td><?php } ?>
	    </tr>
	    <?php if($_REQUEST['AcType']=='Ledger'){?>
	    <tr bgcolor="#666666" style="color:#FFFFFF">
 		  <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
 		   
 		  <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
		  
		  <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&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><font size="3">Closing Balance:</font></strong> </td>
 		  <td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;"><b><font size="3"><?php echo $DR_balance;?></font></b></td>
 		<td><b><font size="3"><?php echo $CR_balance;?></font></b></td><td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td>
 		<?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?>
 		<td style="border-right:1px solid #333333; padding-top:5px; padding-bottom:5px; padding-left:5px;">&nbsp;</td><?php } ?>
	    </tr>
	    <?php }?>
  	  </table> 
	  <?php } ?>
	  	
		 <?php 
   //
   ?>
  <?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>
