<?php require "_header.php";?>
<div id="main-report" align="center">
<?php
	if($_SESSION['cCompany_id']!="" && isset($_SESSION['cCompany_id'])){
	$repid = 1;
		$header_row_string = "<u>Group Wise A/C List</u>";
		$title_array = array();
		$title_array[0] = "A/C Name & Address,left,30%";
		$title_array[1] = "Phone,left,17%";
		$title_array[2] = "Opn.Balance,left,17%";
		
		$condition = " acmaster.company_id = '".$_SESSION['cCompany_id']."'";
		
		$obj = new Query2Report();
	
		$obj->setHtmlPath("report/report-account-master-group-list-result.html");
		$obj->createHeaderRow($header_row_string);
		
		$sql = "SELECT distinct acmaster.account_groupid,acgroup.account_groupname
				FROM ams_accountmaster acmaster,ams_accountgroup acgroup WHERE 
					 acmaster.account_groupid = acgroup.account_groupid AND
		             acgroup.company_id = '".$_SESSION['cCompany_id']."' AND ".$condition; 
				
		$result = dbQuery($sql);
		
		if(dbRows($result)>0){
			while($data = dbArray($result)){
				$obj->reportid="report-table-".$repid;
		
				$record_id = $data['account_groupid'];
				$record_name = $data['account_groupname'];
				$condition = " acmaster.company_id = '".$_SESSION['cCompany_id']."'
							 AND acmasterdetail.company_id = '".$_SESSION['cCompany_id']."'
							 AND acmaster.account_id = acmasterdetail.account_id 
							 AND acmasterdetail.year_id = '".$_SESSION['cYear']."'";
				$query = "SELECT 
							Concat(acmaster.account_name,'<br/>',acmaster.account_address) AS Acc_Name,
							acmaster.account_phone AS Phone,
							acmasterdetail.account_opbalance Opn_Balance
						FROM ams_accountmaster acmaster,
							ams_accountmasterdetail acmasterdetail 
						WHERE acmaster.account_groupid = '$record_id' AND ".$condition;
				$out = dbQuery($query);
				if(dbRows($out)>0){
					$obj->reportData .= "<br /><br /><div align=\"left\">
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Group Code : <b>".$record_id."</b><br />
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Group Name: <b>".$record_name."</b></div>"; 
					$obj->generateReport($query,$title_array);
				}
				
				?>
				<script type="text/javascript">
					Ext.onReady(function(){
						var grid = new Ext.ux.grid.TableGrid('<?php echo $obj->reportid ;?>', {
							stripeRows: true // stripe alternate rows
						});
						grid.render();
					});
				</script>
				<?php
				$repid++;
			
			}
		}
			
		$obj->saveReportData();
		$obj->displayReportData(); 	
		?>
		
	<?php }
?>

</div>
<?php require "_footer.php";?>