<?php include('fun-Trial.php'); ?>
<form name="form1" method="post" action=""> 

<table width="70%" border="0">
  <tr>
    <td width="60%"> Select Group Summary:
	<?php    $pcode=$_REQUEST['GroupSummaryLedger'];?>
 	<select name="GroupSummaryLedger" id="GroupSummaryLedger" style="width:auto">	  
  <option value="000">----</option>
  <?php 
	$dashVal = "&nbsp;&nbsp;&nbsp;";
	$sqlCate = "select * from  accountgroupmaster  where    MainGroupId   = 0";
	$rsCate  = DB_query($sqlCate,$db);
	if(DB_num_rows($rsCate)>0)
	{
		while($rowCate =DB_fetch_array($rsCate))
		{
 				$sqlCateSel = "select * from accountgroupmaster where MainGroupId   =".$rowCate['GroupId']." ";
				$rsCateSel	= DB_query($sqlCateSel,$db);
				$px='';
				 if($rowCate['GroupId']==$_REQUEST['GroupSummaryLedger'])
				 $px="selected";
			echo $dashVal;	
		  ?>
		<option value="<?php echo $rowCate['GroupId'];?>"<?php echo $px ?>> 
		<?php echo  $rowCate['GroupName'] ;?></option>
 		<?php			
			 CategoryShow($pcode, $rowCate['GroupId'], $dashVal);
		}
	}
?></select>


	 </td>
    <td  width="40%">
      <input type="submit" name="Go" value="Go">
    
    </td>
  </tr>
</table>
</form>

<?php 
  if($_REQUEST['Go'])
  {
	 $AccountsID=$_REQUEST['GroupSummaryLedger'];
	$r=GetAll_GroupmasterID($_REQUEST['GroupSummaryLedger']);
	 print_r($r);
	if(count($r)>0){
	 $ids= SeperateByCommes($r);
	 }
	 else
	 $ids= $AccountsID;
	 
	 
  ?>
  <table width="100%" border="1">
  <tr>
    <th>Particulars</th>
     <th>Opening Balance</th>
    <th>Debit Amount</th>
    <th>Credit Amount</th>
    <th>Closing Amount</th>
  </tr>
  
    <?php //echo "select * from accountledger where UnderGroup in($ids)";
	$TDR=array();$TCR=array();$OPB=array();$CLB=array();$openingamt1=0;$openingamt2=0;$openingamt=0;
  	 $GetLedger=DB_query("select * from accountledger where UnderGroup in($ids)",$db);
 	//echo DB_num_rows($GetLedger);
	if(DB_num_rows($GetLedger)>0)
	{
	 while($RowGetLedger=DB_fetch_array($GetLedger))
	 {
	 	if($RowGetLedger['openingtype']=='CR')	
	 {
	  $openingamt1=$RowGetLedger['openingBalance'];
	 }
	 else
	 {
	$openingamt2=$RowGetLedger['openingBalance'];	 
	 }	
	 $openingamt=$RowGetLedger['openingBalance'];	
	  $TotalDR=  Get_AccountByLedger($RowGetLedger['AccountsID'],'DR');;
	   $TotalCR=   Get_AccountByLedger($RowGetLedger['AccountsID'],'CR');
	  if($TotalDR>0 || $TotalCR>0)
	  {
	 ?>
  <tr>
      <td><a  onclick='popup("GroupSummary.php?id=<?php  echo $RowGetLedger['AccountsID'].$rurl?> ",700,300)' style="cursor:pointer" ><?php echo $RowGetLedger['AccountName'];?></a></td>
    <td><?php  echo  $openingamt;
		$OPB[]= $openingamt; ?>&nbsp;</td>
    <td><?php echo $TotalDR;
		$TDR[]= $TotalDR;;
		$grand_DR=$TotalDR;+$openingamt2;
		 ?>&nbsp;</td>
    <td><?php echo $TotalCR;
	$TCR[]= $TotalCR;
	$grand_CR=$TotalCR+$openingamt1;?>&nbsp;</td>
	 <?php 
	if($grand_DR>$grand_CR){$closing=round($grand_DR-$grand_CR); $type="DR";
	$CLB[]=$closing;
	}
	elseif($grand_CR>$grand_DR){$closing=round($grand_CR-$grand_DR); $type="CR";
	$CLB[]=$closing;
	}
	else{$closing=$openingamt;$type='';}
	?>
	
	<td><?php if($closing=='0'){echo "";}else{echo $closing;}?> &nbsp;<?php echo $type;?></td>
  </tr>
 <?php }
  
  } 

  ?>
   <tr bgcolor="#CCCCCC">
    <td><div align="right">Total:</div></td>
     <td><?php  echo array_sum($OPB);?>&nbsp;</td>
      <td><?php  echo array_sum($TDR);?>&nbsp;</td>
    
     <td><?php  echo array_sum($TCR);?>&nbsp;</td>
      <td><?php  echo array_sum($CLB);?>&nbsp;</td>
  </tr>
  <?php 
  }?>
</table>

  <?php
  }
?> 
