<script>

function showledger(str)
{
   var xmlhttp;
   if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
         //alert(xmlhttp.responseText);
	  document.getElementById("ledger_name").innerHTML=xmlhttp.responseText;
	}
	}
	//alert("ajax_ledger_branch.php?site="+str);
	xmlhttp.open("GET","ajax_ledger_branch.php?site="+str,true);
	xmlhttp.send();
}

</script>

<?php include('fun-Trial_branch.php');?>
<form name="trial" method="post">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td width="13%" align="right">Branch</td>
    <td width="35%"><select name="site" id="site" onchange="showledger(this.value);" >
	<option value="0">Select</option>
	<?php $sql_branch=DB_query("select * from locations where  loccode in ('".$_SESSION['AssignedBranch']."')",$db);
		while($row_branch=DB_fetch_array($sql_branch))
		{
	   ?>
	<option value="<?php echo $row_branch['loccode']; ?>" <?php if($_REQUEST['site']==$row_branch['loccode']) { ?> selected <?php } ?> ><?php echo $row_branch['locationname']; ?></option>	
   <?php } ?>
   </select>
    </td>
	<td width="13%" align="right">Ledger</td>
	<td><?php 
          if($_REQUEST['site']!='0')
        {
 	      $sql_trial=DB_query("SELECT * FROM accountledger inner join accountledger_dtls on accountledger.AccountsID=accountledger_dtls.accountledger_id where site='".$_REQUEST['site']."' group by AccountsID ORDER BY AccountName ASC",$db);
        }
        else
        {
        	$sql_trial=DB_query("SELECT * FROM accountledger inner join accountledger_dtls on accountledger.AccountsID=accountledger_dtls.accountledger_id group by AccountsID ORDER BY AccountName ASC",$db);
        }

 	      	?>
	 <select name="ledger_name"  id="ledger_name" >
	 <option value="0">Select</option>
	 <?php while($sql_trialRow=DB_fetch_array($sql_trial)) {?>
	 <option value="<?php echo $sql_trialRow['AccountsID']; ?>"<?php echo($sql_trialRow['AccountsID']==$_REQUEST['ledger_name']?'selected':''); ?>><?php echo $sql_trialRow['AccountName']; ?></option>
	<?php }?></select></td>
</tr>
<tr class="row1">	
	<td align="right">From Date</td>
	<td><input type="text" name="from_date" value="<?php if(isset($_REQUEST['from_date'])) { echo $_REQUEST['from_date'];  } 
	else {  echo ConvertSQLDate($_SESSION['financialYrStart']); } ?>" class="datepicker"  /></td>
	<td align="right">To Date</td>
	<td><input type="text" name="to_date" value="<?php if(isset($_REQUEST['to_date'])) { echo $_REQUEST['to_date'];  } 
	else {  echo ConvertSQLDate($_SESSION['financialYrEnd']); } ?>" class="datepicker"  /></td>
	</tr>
<tr class="row1">
	<td colspan="4" style="text-align:center;"><input type="submit" name="search" value="Search" class="search" /></td>
</tr>
</table>
</form>
<?php 
	if($_REQUEST['reset'])
	{	
	$GetLedger="select * from accountledger order by  AccountName ASC ";
	}

if($_REQUEST['search'])
{
    if($_REQUEST['site']!='0')
    {
	    $clientid='';

		$client_data=DB_query("select distinct id from clientmaster where Site in ('".$_REQUEST['site']."')",$db);
		while($row_client=DB_fetch_array($client_data))
		{
		$clientid[]=$row_client['id'];
		}
		$vendor='';
		
		$client_data1=DB_query("select distinct id from suppliers where site in ('".$_REQUEST['site']."')",$db);
		while($row_client1=DB_fetch_array($client_data1))
		{
		$vendor[]=$row_client1['id'];
		}		
	
		if(!empty($clientid))
		$clintid1=implode(",",$clientid);
		if(!empty($vendor))
		$vendor1=implode(",",$vendor);
		
		$accid='';
	if(!empty($clientid))
	{
		$acc_data=DB_query("select * from accountledger where vender_client in(".$clintid1.") and ledgertype='client'",$db);
		while($row_ledger=DB_fetch_array($acc_data))
		{
		 $accid[]=$row_ledger['AccountsID']; 
		}
	}
	if(!empty($vendor))
	{
		$acc_data1=DB_query("select * from accountledger where vender_client in(".$vendor1.") and ledgertype='vendor'",$db);
		while($row_ledger1=DB_fetch_array($acc_data1))
		{
		 $accid[]=$row_ledger1['AccountsID']; 
		}
	}
	   array_unique($accid);
	      if(!empty($accid))
	      {
	        $accid1=implode(",",$accid);

			$acc_data2=DB_query("select * from accountledger where AccountsID not in(".$accid1.") ",$db);
		}
		else
		{
		$acc_data2=DB_query("select * from accountledger  ",$db);	
		}
			while($row_ledger2=DB_fetch_array($acc_data2))
			{
			 $accid2[]=$row_ledger2['AccountsID']; 
			}
			array_unique($accid2);
			if(!empty($accid2) && !empty($accid))
			$result= array_merge($accid, $accid2);
	       array_unique($result);
			if(!empty($result))
		    $accid3=implode(",",$result);
    }	
    else
    {
      $accid3='';	
    }

 	$from_date=ConvertSQLDate($_REQUEST['from_date']);
 	$_SESSION['from_date']=$_REQUEST['from_date'];
 	$_SESSION['to_date']=$_REQUEST['to_date'];
	$to_date=ConvertSQLDate($_REQUEST['to_date']);
	$ledger_name=$_REQUEST['ledger_name'];
	if($_REQUEST['ledger_name']!='0')
	{
	 $_SESSION['ledgerID']=$_REQUEST['ledger_name'];
	}
	else
	{
		 $_SESSION['ledgerID']=$accid3;
	} 

		if($_REQUEST['ledger_name']!='0')
		{
		$GetLedger="select * from accountledger where AccountsID='".$_REQUEST['ledger_name']."' order by  AccountName ASC ";
		}
		else
		{
		if(!empty($accid3))
		$GetLedger="select * from accountledger  where AccountsID in(".$accid3.")  order by  AccountName ASC";
		else
    	$GetLedger="select * from accountledger  WHERE ledgertype IS  NULL OR ledgertype NOT LIKE 'closing_stock'  order by  AccountName ASC";
		}
	$_SESSION['qry']=$GetLedger;

	if($_REQUEST['site']!='0')
	{
		$_SESSION['ledgerwisetrialsite']=$_REQUEST['site'];
	}

	//echo "<br>". $GetLedger;	
?>
  <p align="right">
  <a href="APRLedgerWise-TrialBalance_ptint.php?b=true" target="_blank" class="search">Print</a>  <a href="APRLedgerWise-TrialBalance_Exl.php" class="search">Export</a>
  </p>
<table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
  <tr>
    <th width="4%">S. No.</th>
    <th>Ledger Name</th>
    <th width="12%">Account Type</th>
    <th width="8%" class="text-center">Opening (DR)</th>
	<th width="8%" class="text-center">Opening (CR)</th>
    <th width="8%" class="text-center">Total Debit</th>
    <th width="8%" class="text-center">Total Credit</th>
    <th width="8%" class="text-center">Closing (DR)</th>  
    <th width="8%" class="text-center">Closing (CR)</th>
  </tr>  
  <?php   	
	$GetLedger=DB_query($GetLedger,$db);
 	if(DB_num_rows($GetLedger)>0)
	{
			$add_opening=array();
			$add_TD=array();
			$add_TC=array();
			$add_CL=array();
			$closing_DR='';
			$closing_CR='';
			$total_DR='';
			$total_CR='';
			$add_OPDR=array();
			$k=0;
		 while($RowGetLedger=DB_fetch_array($GetLedger))
		 {	 
		 	$etaxDetails='';
			$staxDetails='';
			$vendorDetails='';
			$clientDetails='';
			$roundDetails='';
			$etaxDR=''; $etaxCR=''; $staxDR='';$staxCR=''; $purchCR=''; $invDR='';$ledgerPosting='';$legderDR=''; $legderCR='';
			$cessDetails='';$cessDR='';$roundDR=''; $roundCR='';$servicetaxDetails='';$servicetaxCR='';$clientDetails1='';$invserviceDR='';
		    $freightDetails='';$freightDR='';$surDetails='';$surDR='';$packDetails='';$packDR='';$addDetails='';$addDR='';
		    $cessDetails=='';$cessDR='';$scessDetails='';$scesscR='';$roundDetails='';$roundserviceDetails='';$roundDR='';
	        $roundCR='';$roundserviceDR='';$roundserviceCR='';
		 	
		 	$master_party_id=$RowGetLedger['vender_client'];	
			$master_tax_id=$RowGetLedger['taxid'];	
			$ledgertype=$RowGetLedger['ledgertype'];
			$ledger_id=$RowGetLedger['AccountsID'];	
	 
	 
	 if($_REQUEST['from_date']!='' && $_REQUEST['to_date']!='')
	 {
	 	   $TDR= Get_AccountByLedger($RowGetLedger['AccountsID'],'DR',$from_date,$to_date,$_REQUEST['site']);
	  	   $TCR= Get_AccountByLedger($RowGetLedger['AccountsID'],'CR',$from_date,$to_date ,$_REQUEST['site']);
			//echo "++++".$TDR."<br />";

			if($ledgertype!='')
		   {

		   	     if($ledgertype=='excisetax'){				
					    $etaxDetails=yearlyETaxAccountByTransactions($master_tax_id,$from_date,$to_date ,$_REQUEST['site']);
					    $etaxDR=$etaxDetails[0]; $etaxCR=$etaxDetails[1];
						}else{$etaxDetails='';$etaxDR='';$etaxCR='';}

					if($ledgertype=='salestax'){					
					   $staxDetails=yearlySTaxAccountByTransactions($master_tax_id,$from_date,$to_date ,$_REQUEST['site']);
					   $staxDR=$staxDetails[0]; $staxCR=$staxDetails[1];
					}else{$staxDetails='';$staxDR=''; $staxCR='';}

					if($ledgertype=='vendor'){						
						 $vendorDetails=yearlyVendorAccountByTransactions($master_party_id,$from_date,$to_date ,$_REQUEST['site']);
					     $purchCR=$vendorDetails;
					   }else{$vendorDetails='';$purchCR='';}

					if($ledgertype=='client'){						
						$clientDetails=yearlyClientAccountByTransactions($master_party_id,$from_date,$to_date ,$_REQUEST['site']);
						 $invDR=$clientDetails;
					  }else{$clientDetails='';$invDR='';}
					
					if($ledgertype=='freight'){						
						 $freightDetails=yearlyFreightAccountByTransactions($ledger_id,$from_date,$to_date ,$_REQUEST['site']);
						  $freightDR=$freightDetails[0]; $freightCR=$freightDetails[1];
					}else{$freightDetails='';$freightDR='';$freightCR='';}

					if($ledgertype=='surcharge'){					
						$surDetails=yearlySurchargeAccountByTransactions($ledger_id,$from_date,$to_date ,$_REQUEST['site']);
						$surDR=$surDetails[0];  $surCR=$surDetails[1]; 					   
					}else{$surDetails='';$surDR='';$surCR='';}

					if($ledgertype=='pckcharge'){
						 $packDetails=yearlyPkgChargesAccountByTransactions($ledger_id,$from_date,$to_date ,$_REQUEST['site']);			
					     $packDR=$packDetails[0];  $packCR=$packDetails[1];; 
					}else{$packDetails='';$packDR='';$packCR='';}

					if($ledgertype=='addcharge'){					
						$addDetails=yearlyAddChargesAccountByTransactions($ledger_id,$from_date,$to_date ,$_REQUEST['site']);			
					    $addDR=$addDetails[0];$addCR=$addDetails[1]; 
					}else{$addDetails='';$addDR='';$addCR='';}

					if($ledgertype=='cess')	{					
						$cessDetails=yearlyCessAccountByTransactions($master_tax_id,$from_date,$to_date ,$_REQUEST['site']);			
					    $cessDR=$cessDetails[0]; $cessCR=$cessDetails[1];  
					}else{$cessDetails='';$cessDR='';$cessCR='';}

					 if($ledgertype=='insurance'){							
							 $insurance=yearlyinsuranceAccountByTransactions($master_tax_id,$from_date,$to_date ,$_REQUEST['site']);
						   	 $insuranceDR=$insurance[0]; $insuranceCR=$insurance[1]; 
							}else{$insurance='';$insuranceDR='';$insuranceCR='';}
							
					    if($ledgertype=='sales'){							
							$salesdata=yearlyLedgerPostingByTransactions($ledger_id,$from_date,$to_date ,$_REQUEST['site']);
						   	$salesDR=$salesdata[0]; $salesCR=$salesdata[1]; 
							}else{$salesdata='';$salesDR='';$salesCR='';}
					
					    if($ledgertype=='round'){						
						    $roundDetails=yearlyRoundOffByTransactions($ledger_id,$from_date,$to_date ,$_REQUEST['site']);
						    $roundDR=$roundDetails[0];
						    $roundCR=$roundDetails[1];
					    }else{$roundDetails='';$roundDR='';$roundCR='';}	
                
		   }
		   else
		   {
			    $ledgerPosting=yearlyLedgerPostingByTransactions($RowGetLedger['AccountsID'],$from_date,$to_date ,$_REQUEST['site']);
			    $legderDR=$ledgerPosting[0]; $legderCR=$ledgerPosting[1];			  
				$etaxDetails='';
				$staxDetails='';
				$vendorDetails='';
				$clientDetails='';
				$roundDetails='';
				$invserviceDR='';$clientDetails1='';
				$scesscR='';$scessDetails='';
				$roundserviceDR='';
				$roundserviceCR='';
				$roundserviceDetails='';
				$etaxDR=''; $etaxCR=''; $staxDR='';$staxCR=''; $purchCR=''; $invDR='';$freightDR='';$surDR='';$packDR=''; $addDR='';				
				$cessDetails='';$cessDR='';$roundDR=''; $roundCR='';
		  }	
	
	 }
	 else
	 {
	   $TDR= Get_AccountByLedger($RowGetLedger['AccountsID'],'DR','','' ,$_REQUEST['site']);
	   $TCR= Get_AccountByLedger($RowGetLedger['AccountsID'],'CR','','' ,$_REQUEST['site']);
	
		if($ledgertype!='') {
             
	      if($ledgertype=='excisetax'){
	          if($_SESSION['FDATE']!='' && $_SESSION['TDATE']!='')
	          {$etaxDetails=yearlyETaxAccountByTransactions($master_tax_id,$_SESSION['FDATE'],$_SESSION['TDATE'],$_REQUEST['site']);}
	          else{$etaxDetails=yearlyETaxAccountByTransactions($master_tax_id,'','',$_REQUEST['site']);}
	           $etaxDR=$etaxDetails[0]; $etaxCR=$etaxDetails[1];
		   }else{$etaxDetails='';$etaxDR='';$etaxCR='';}

	      if($ledgertype=='salestax'){
	       if($_SESSION['FDATE']!='' && $_SESSION['TDATE']!='')
	       {$staxDetails=yearlySTaxAccountByTransactions($master_tax_id,$_SESSION['FDATE'],$_SESSION['TDATE'],$_REQUEST['site']);}
	       else {$staxDetails=yearlySTaxAccountByTransactions($master_tax_id,'','',$_REQUEST['site']);} 
	       $staxDR=$staxDetails[0];  $staxCR=$staxDetails[1];
	     }else{$staxDetails='';$staxDR=''; $staxCR='';}

	    if($ledgertype=='vendor'){
			if($_SESSION['FDATE']!='' && $_SESSION['TDATE']!='')
			{$vendorDetails=yearlyVendorAccountByTransactions($master_party_id,$_SESSION['FDATE'],$_SESSION['TDATE'],$_REQUEST['site']);}
		    else {$vendorDetails=yearlyVendorAccountByTransactions($master_party_id,'','',$_REQUEST['site']);} $purchCR=$vendorDetails;
	    }else{$vendorDetails='';$purchCR='';}

		if($ledgertype=='client'){
			if($_SESSION['FDATE']!='' && $_SESSION['TDATE']!='')
			{$clientDetails=yearlyClientAccountByTransactions($master_party_id,$_SESSION['FDATE'],$_SESSION['TDATE'],$_REQUEST['site']);}
			else{$clientDetails=yearlyClientAccountByTransactions($master_party_id,'','',$_REQUEST['site']);} $invDR=$clientDetails;
	    }else{$clientDetails='';$invDR='';}
	
	   if($ledgertype=='freight')	{
			if($_SESSION['FDATE']!='' && $_SESSION['TDATE']!='')
			{$freightDetails=yearlyFreightAccountByTransactions($ledger_id,$_SESSION['FDATE'],$_SESSION['TDATE'],$_REQUEST['site']);}
			else{$freightDetails=yearlyFreightAccountByTransactions($ledger_id,'','',$_REQUEST['site']);} 
			$freightDR=$freightDetails[0];$freightCR=$freightDetails[1];
	   }else{$freightDetails='';$freightDR='';$freightCR='';}

		if($ledgertype=='surcharge'){
			if($_SESSION['FDATE']!='' && $_SESSION['TDATE']!='')
			{$surDetails=yearlySurchargeAccountByTransactions($ledger_id,$_SESSION['FDATE'],$_SESSION['TDATE'],$_REQUEST['site']);}
			else{$surDetails=yearlySurchargeAccountByTransactions($ledger_id,'','',$_REQUEST['site']);} 
	        $surDR=$surDetails[0];  $surCR=$surDetails[1]; 	   
	   }else{$surDetails='';$surDR='';$surCR='';}

	   if($ledgertype=='pckcharge'){
			if($_SESSION['FDATE']!='' && $_SESSION['TDATE']!='')
			{$packDetails=yearlyPkgChargesAccountByTransactions($ledger_id,$_SESSION['FDATE'],$_SESSION['TDATE'],$_REQUEST['site']);}
			else{$packDetails=yearlyPkgChargesAccountByTransactions($ledger_id,'','',$_REQUEST['site']);} 	   
		    $packDR=$packDetails[0];  $packCR=$packDetails[1];; 
	   }else{$packDetails='';$packDR='';$packCR='';}

	  if($ledgertype=='addcharge'){
			if($_SESSION['FDATE']!='' && $_SESSION['TDATE']!='')
			{$addDetails=yearlyAddChargesAccountByTransactions($ledger_id,$_SESSION['FDATE'],$_SESSION['TDATE'],$_REQUEST['site']);}
			else{$addDetails=yearlyAddChargesAccountByTransactions($ledger_id,'','',$_REQUEST['site']);} 	
		    $addDR=$addDetails[0];$addCR=$addDetails[1]; 
	  }else{$addDetails='';$addDR='';$addCR='';}

	  if($ledgertype=='cess'){
			if($_SESSION['FDATE']!='' && $_SESSION['TDATE']!='')
			{$cessDetails=yearlyCessAccountByTransactions($master_tax_id,$_SESSION['FDATE'],$_SESSION['TDATE'],$_REQUEST['site']);}
			else{$cessDetails=yearlyCessAccountByTransactions($master_tax_id,'','',$_REQUEST['site']);}		
		    $cessDR=$cessDetails[0]; $cessCR=$cessDetails[1];  
	  }else{$cessDetails='';$cessDR='';$cessCR='';}

	 if($ledgertype=='insurance'){
			if($_SESSION['FDATE']!='' && $_SESSION['TDATE']!='')
			{$insurance=yearlyinsuranceAccountByTransactions($master_tax_id,$_SESSION['FDATE'],$_SESSION['TDATE'],$_REQUEST['site']);}
		    else{ $insurance=yearlyinsuranceAccountByTransactions($master_tax_id,'','',$_REQUEST['site']);}
			$insuranceDR=$insurance[0]; $insuranceCR=$insurance[1]; 
	   }else{$insurance='';$insuranceDR='';$insuranceCR='';}
			
	    if($ledgertype=='sales'){
			if($_SESSION['FDATE']!='' && $_SESSION['TDATE']!='')
			{$salesdata=yearlyLedgerPostingByTransactions($ledger_id,$_SESSION['FDATE'],$_SESSION['TDATE'],$_REQUEST['site']);}
		    else{ $salesdata=yearlyLedgerPostingByTransactions($ledger_id,'','',$_REQUEST['site']);}
			$salesDR=$salesdata[0]; $salesCR=$salesdata[1]; 
		}else{$salesdata='';$salesDR='';$salesCR='';}
	
	 if($ledgertype=='round'){
		if($_SESSION['FDATE']!='' && $_SESSION['TDATE']!='')
		{$roundDetails=yearlyRoundOffByTransactions($ledger_id,$_SESSION['FDATE'],$_SESSION['TDATE'],$_REQUEST['site']);}
		else{$roundDetails=yearlyRoundOffByTransactions($ledger_id,'','',$_REQUEST['site']);} 
		$roundDR=$roundDetails[0];
		$roundCR=$roundDetails[1];
	  }else{$roundDetails='';$roundDR='';$roundCR='';}	
	  $legderDR='';$legderCR=''; }

	else {

		if($_SESSION['FDATE']!='' && $_SESSION['TDATE']!=''){
		$ledgerPosting=yearlyLedgerPostingByTransactions($ledger_id,$_SESSION['FDATE'],$_SESSION['TDATE'],$_REQUEST['site']);}else{
		$ledgerPosting=yearlyLedgerPostingByTransactions($ledger_id,'','',$_REQUEST['site']);} 
		$legderDR=$ledgerPosting[0]; $legderCR=$ledgerPosting[1];		
		$etaxDetails='';$etaxDR=''; $etaxCR=''; 
		$staxDetails='';$staxDR='';$staxCR=''; 
		$vendorDetails='';$purchCR=''; 
		$clientDetails='';$invDR='';
		$freightDetails='';$freightDR='';
		$surDetails='';$surDR='';
		$packDetails='';$packDR='';
		$addDetails='';$addDR='';$salesDR='';$salesCR='';
		$cessDetails='';$cessDR='';$insuranceDR='';$insuranceCR='';
		$roundDetails='';$roundDR='';$roundCR='';$freightCR='';$surCR='';$packCR='';$addCR='';$cessCR='';
		
	   }
}
	/* $total_DR=$TDR+$etaxDR+$staxDR+$invDR+$legderDR+$freightDR+$surDR+$packDR+$addDR+$cessDR+$roundDR+$insuranceDR+$salesDR;
	 $total_CR=$TCR+$etaxCR+$staxCR+$purchCR+$legderCR+$roundCR+$freightCR+$surCR+$packCR+$addCR+$cessCR+$insuranceCR+$salesCR;	 */

	 $total_DR=$TDR;
	 $total_CR=$TCR;

	
		$openingDR=''; $openingCR='';
		$OPDR=$openingDR; $OPCR=$openingCR;
		
		//echo $RowGetLedger['AccountsID']."<br>";
		$led_opening=getledgeropeningyearwise($RowGetLedger['AccountsID'],$_REQUEST['site']);
		$ledger_dr_tot=get_opening_filter_basis($RowGetLedger['AccountsID'],$_REQUEST['site'],$_SESSION['FDATE'],'DR');
		$ledger_cr_tot=get_opening_filter_basis($RowGetLedger['AccountsID'],$_REQUEST['site'],$_SESSION['FDATE'],'CR');

		if($ledger_dr_tot>$ledger_cr_tot)
		{
			$diff_dr=$ledger_dr_tot-$ledger_cr_tot;
		}
		else
		{
			$diff_cr=$ledger_cr_tot-$ledger_dr_tot;
		}

		    if(isset($led_opening[DR]))
		     {   
		     	$add_OPDR[]=$led_opening[DR]; 
		     	$OPDR=$led_opening[DR];  
		     }
         if(isset($led_opening[CR]))
           {
            	$add_OPCR[]=$led_opening[CR]; 
            	//$OPCR=$led_opening[CR]+$diff_cr;  
            	$OPCR=$led_opening[CR];  
           }//$OPDR='0';
	
	  if(($total_DR!='' || $total_CR!='' || $OPDR!='' || $OPCR!='') && ($total_DR!=0 || $total_CR!=0 || $OPDR!=0 || $OPCR!=0)) {   
	  ?>
<tr>
	<td><?php $k++; echo $k; ?></td>
	<td><?php echo $RowGetLedger['AccountName']; ?></td>
	<td><?php //echo naturegroup($RowGetLedger['UnderGroup']);
	   echo $group_name=$s->getField('accountgroupmaster','GroupId',$RowGetLedger['UnderGroup'],'GroupName'); //echo "<br />".$TCR;?></td>
    <td style="text-align:right"><?php echo $OPDR; ?></td>
	<td style="text-align:right"><?php echo $OPCR; ?></td>
	<td style="text-align:right"><?php
				if($total_DR!='')
				$add_TD[]=$total_DR;
				echo $total_DR ; ?></td>
			    <td style="text-align:right"><?php 
				if($total_CR!='')
				$add_TC[]=$total_CR;
				echo $total_CR ;?></td>
				<?php 
				$Gtotal_DR=$OPDR+$total_DR;
				$Gtotal_CR=$OPCR+$total_CR;
				if($Gtotal_DR>$Gtotal_CR)
				{$closing_DR=$Gtotal_DR-$Gtotal_CR; $closing_CR='';}
				elseif($Gtotal_CR>$Gtotal_DR)
				{$closing_CR=$Gtotal_CR-$Gtotal_DR; $closing_DR='';}
				else{$closing_CR='0'; $closing_DR='0';}
				?>
	<td style="text-align:right"><?php if($closing_DR!=''){echo $closing_DR;}else{echo $closing_DR=0;;} $add_closeDR[]=$closing_DR;?></td>
	<td style="text-align:right"><?php if($closing_CR!=''){echo $closing_CR;}else{echo $closing_CR=0;} $add_closeCR[]=$closing_CR;?></td>
</tr>

  <?php  $trial_balance[]=array("AccountName"=>$RowGetLedger['AccountName'],"groupname"=>$group_name,"opening_type"=>$led_opening[1],"opening_amt_dr"=>$OPDR,"opening_amt_cr"=>$OPCR,"Debitamt"=>$total_DR,"creditamt"=>$total_CR,"site"=>$_REQUEST['site']);
    }
   } 
   //echo "<pre>";
   //print_r($add_closeCR);
    //echo "<pre>";
   //print_r($add_closeDR);
$_SESSION['trail_balce']=$trial_balance;
  ?>
  <tr>
  <td colspan="3" style="text-align:right"><strong>Total</strong></td>
  <td style="text-align:right"><strong><?php if($add_OPDR!='')echo array_sum($add_OPDR); //if($add_OPDR!='')echo array_sum($add_OPDR)+$diff_dr;?></strong></td>
  <td style="text-align:right"><strong><?php if($add_OPCR!='')echo array_sum($add_OPCR);//if($add_OPCR!='')echo array_sum($add_OPCR)+$diff_cr;?></strong></td>
  <td style="text-align:right"><strong><?php 
// echo Get_TotalAccountByLedger('DR' ,$from_date,$to_date);
 //echo "<br>";
 echo array_sum($add_TD); ?></strong></td>
  <td style="text-align:right"><strong><?php echo array_sum($add_TC); ?></strong></td>
  <td style="text-align:right"><strong><?php if(!empty($add_closeDR)) echo array_sum($add_closeDR);?></strong></td>
  <td style="text-align:right"><strong><?php if(!empty($add_closeCR)) echo array_sum($add_closeCR);?></strong></td>
  </tr>
<?php   }  ?>
</table>
<?php } ?>

<script type="text/javascript">
		function showledger(str)
	{
   
	var xmlhttp;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		var data=xmlhttp.responseText;
	
	//document.getElementById("hid-Godown-div").innerHTML=data[0];
	$('#ledger_name').html(data);
	//alert(data[0]);
	//document.getElementById("empdta").innerHTML=data[1];
	
	}
	}
	xmlhttp.open("GET","ajax_ledger_summary_branch.php?site="+str,true);
	xmlhttp.send();
}

</script>