<?php require "_header.php"; ?>
<div id="main-report" align="center">
	<style type="text/css">
		table.report {
			width: 80%;
		}
	</style>
	<?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 . " ORDER BY acmaster.account_groupid ASC";

		$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 .= "<h1>
					Group Code : <b>" . $record_id . "</b><br />
					Group Name: <b>" . $record_name . "</b></h1><br />";
					$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->displayReportData();
		if ($obj->rowCount > 0) {
			$HtmlUrl = "account-master-group-list-report-" . $_SESSION["cUserId"] . ".html";
			$HtmlPath = "report/" . $HtmlUrl;

			$obj->setHtmlUrl($HtmlUrl);
			$obj->setHtmlPath($HtmlPath);
			$obj->saveReportData();
			?>
			<script type="text/javascript">
				/*Ext.onReady(function(){
					 var grid = new Ext.ux.grid.TableGrid("report-table", {
							stripeRows: true // stripe alternate rows
						});
						grid.render();
				});*/
			</script>
			<br />
			<form name="frm" id="frm" action="" method="post">
				<input type="hidden" name="txtFile" id="txtFile" value="<?php echo $HtmlUrl; ?>" />
				<input type="button" name="btnPdf" id="btnPdf" value="Print" onClick="SetPageAction('PRINT');" />
				<input type="button" name="btnPdf" id="btnPdf" value="Create PDF" onclick="SetPageAction('PDF');" />
				<input type="button" name="btnHtml" id="btnHtml" value="Create HTML" onclick="SetPageAction('HTML');" />
				<input type="button" name="btnWord" id="btnWord" value="Create WORD" onclick="SetPageAction('WORD');" />
				<input type="button" name="btnExcel" id="btnExcel" value="Create EXCEL" onclick="SetPageAction('Excel');" />
			</form>
			<script language="javascript" type="text/javascript">
				function SetPageAction(varAction) {
					if (varAction == "PRINT") {
						document.frm.action = "print/create-print.php";
						document.frm.target = "_blank";
						document.frm.submit();
					}
					if (varAction == "PDF") {
						document.frm.action = "convertpdf/create-pdf.php";
						document.frm.target = "_blank";
						document.frm.submit();
					}
					else if (varAction == "HTML") {
						document.frm.action = "<?php echo $HtmlPath; ?>";
						document.frm.target = "_blank";
						document.frm.submit();
					}
					else if (varAction == "WORD") {
						document.frm.action = "convertword/create-word.php";
						document.frm.target = "_blank";
						document.frm.submit();
					}
					else if (varAction == "Excel") {
						document.frm.action = "convertword/create-excel.php";
						document.frm.target = "_blank";
						document.frm.submit();
					}
				}
			</script>
		<?php
		} else {
			echo "<br/><b>No Data Found</b>";
		}
	}
	?>
</div>
<br /><br /><br /><br /><br /><br />
<?php require "_footer.php"; ?>