<?php
session_name('CAKEPHP'); session_start();
ob_start();
$PageSecurity = 1;
include('config.php');
include('includes/ConnectDB.inc');
include('includes/function_lib.php');
include('includes/LanguageSetup.php');
include('includes/DateFunctions.inc');
include('Account/fun-Trial.php');
$ids=$_SESSION['ids'];
?>
<script type="text/javascript" language="javascript">
  function toggle_visibility(id) {
       var e = document.getElementById(id);
	      e.style.display = 'none';
		       //alert(e.style.display);
			   window.print();
    }
  
</script>
<title>Account Group Summary Report</title>
<link rel="stylesheet" href="css/purchase_requision_print.css">
<div class="body_contain">
<div class="tab_div">
<?php 
$logo="<div>";
$logo.="<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
$logo.="<tr>";
$logo.="<td align='left'><img src='images/cloud_logo.jpg' /></td>";
$logo.="<td align='right'><img src='images/right_img.jpg' /></td>";
$logo.="</tr>";
$logo.="<tr>";
$logo.="<td colspan='2'><h1>Account Group Summary Report</h1></td>";
$logo.="</tr>";
$logo.="</table>";
$logo.="</div>";
echo $logo;
?>
<div id="foo">
  <p align="center"><input type="button" onclick="javascript:toggle_visibility('foo');" value="Print" /></p>
</div>
<?php 
$Header="<tr>";
$Header.="<th>Particulars</th>";
$Header.="<th>Opening Balance</th>";
$Header.="<th>Debit Amount</th>";
$Header.="<th>Credit Amount</th>";
$Header.="<th>Closing Amount</th>";
$Header.="</tr>";
?>
 <table width="100%" border="1">
<?php echo $Header; ?>  
    <?php //echo "select * from accountledger where UnderGroup in($ids)";
	$TDR=array();$TCR=array();$OPB=array();$CLB=array();$openingamt1=0;$openingamt2=0;$openingamt=0;
	//echo "select * from accountledger where UnderGroup in($ids)";
	//echo "select AccountsID,vender_client,openingtype,openingBalance,AccountName from accountledger where UnderGroup in($ids)";
  	 $GetLedger=DB_query("select AccountsID,vender_client,openingtype,openingBalance,AccountName from accountledger where UnderGroup in($ids)",$db);
 	//echo DB_num_rows($GetLedger);
	$i=0;
	 $t=DB_num_rows($GetLedger);
	if(DB_num_rows($GetLedger)>0)
	{
	$aks=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)
	  {
	  $aks++;
     
   
   ?>
  <tr>
      <td><b><font size="3px"><?php echo $RowGetLedger['AccountName']//.'==>'.$RowGetLedger['AccountsID'];?></font></b></td>
    <td><div align="right"><span class="style1">
      <?php  echo  $openingamt;
		$OPB[]= $openingamt; ?>
    </span></div></td>
    <td><div align="right"><strong><?php echo $TotalDR;
		$TDR[]= $TotalDR;?></strong></div></td>
    <td><div align="right"><strong><?php echo $TotalCR;
	$TCR[]= $TotalCR;?></strong></div></td>
	 <?php 
	 
	 //echo "CR===".$grand_CR; echo "==="; echo "DR===".$grand_DR; echo "<br />";
	if($TotalDR>$TotalCR){$closing=round($TotalDR-$TotalCR); $type="DR";
	$CLB[]=$closing;
	}
	elseif($TotalCR>$TotalDR){$closing=round($TotalCR-$TotalDR); $type="CR";
	$CLB[]=$closing;
	}
	else{$closing=$openingamt;$type='';}
	?>
	
	<td><div align="right"><span class="style2">
	  <?php if($closing=='0'){echo "";}else{echo $closing;}?>
	</span> &nbsp;<strong><?php echo $type;?></strong></div></td>
  </tr>
 <?php 
 
 if($aks%19==0)
 {?>
 </table>
 </div>
 </div>
 <div class="body_contain">
 <div class="tab_div">
 <?php  echo $logo; ?>
  <table width="100%" border="1">
	<?php echo $Header; ?>
<?php  }
 }
  } 
  ?>
   <tr bgcolor="#CCCCCC">
    <td><div align="right"><strong>Total:</strong></div></td>
     <td><div align="right"><span class="style6">
       <?php  echo array_sum($OPB);?>
     </span></div></td>
      <td><div align="right"><span class="style5">
        <?php  echo array_sum($TDR);?>
      </span></div></td>
    
     <td><div align="right"><span class="style4">
       <?php  echo array_sum($TCR);?>
     </span></div></td>
      <td><div align="right"><span class="style3">
        <?php  echo array_sum($CLB);?>
      </span></div></td>
  </tr>
  <?php 
  }?>
</table>
</div>
</div>