<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root
	xmlns:jsp="http://java.sun.com/JSP/Page"
	xmlns:og="hybs-taglib.tld"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	version="2.0">
<jsp:directive.page language="java" contentType="text/html; charset=UTF-8" />

<og:value command="SQL">
	select count(*) SITSU_CNT
	from AN02 A
	where A.USERID = '{@USER.ID}'
	and A.CDANK = '{@CDANK}'
	and A.FGJ = '1'
	and A.KBUNRUI != 'SCALE'
</og:value>

<og:value command="SQL">
	select {@SITSU_CNT} + count(*) SITSU_CNT
	from AN02 A inner join AN03 B
	on A.CDANK = B.CDANK
	and B.FGJ = '1'
	where A.USERID = '{@USER.ID}'
	and A.CDANK = '{@CDANK}'
	and A.CDSITSU = B.CDSITSU
	and A.FGJ = '1'
	and A.KBUNRUI = 'SCALE'
</og:value>

<og:query command="{@command}" displayMsg="" maxRowCount="100000" quotCheck="false">
	select
		A.KUID, A.DYKAITO, A.NOKAITO
	from AN11 A
	where A.USERID = '{@USER.ID}'
	and A.CDANK = '{@CDANK}'
	and A.FGJ = '1'
	order by A.NOKAITO
</og:query>

<og:value command="SQL" action="ROW_APPEND">
	select A.UNIQ AN02_UNIQS
	from AN02 A
	where A.CDANK = '{@CDANK}'
	and A.FGJ = '1'
	order by A.SEQNO
</og:value>

<og:value command="SET" key="DISPKEYS" value="KUID,DYKAITO,NOKAITO" />

<c:set var="CCNT" value="0" />

<c:forTokens items="${AN02_UNIQS}" delims="," var="AN02_UNIQ" varStatus="status">
	<og:value command="SQL">
		select A.NAIYO, A.CDSITSU, A.KBUNRUI
		from AN02 A
		where A.UNIQ = '{@AN02_UNIQ}'
	</og:value>

	<og:equals val1="{@KBUNRUI}" val2="SCALE" notEquals="true">
		<c:set var="CCNT" value="${CCNT+1}" />

		<og:query command="{@command}" displayMsg="" notfoundMsg="" maxRowCount="100000" quotCheck="false" scope="request">
			select
				A.NOKAITO
				,case
					when '{@KBUNRUI}' in ('CHBOX','RADIO','MENU') and A.FGOTHER = '0' then	KNAME
					else 																	KVAL end S${CCNT}
			from AN12 A
			where A.CDANK = '{@CDANK}'
			and A.CDSITSU = '{@CDSITSU}'
			and A.FGJ = '1'
			order by A.NOKAITO,A.KVAL
		</og:query>

		<og:tableMerge
			command="{@command}"
			action="GROUP"
			display="false"
			masterScope="request"
			scope="request"
			masterKeys="NOKAITO"
			groupAddClms="S${CCNT}"
			separator="|" />
		<og:tableMerge
			command="{@command}"
			action="UNION_CLM"
			display="false"
			slaveScope="request"
			masterKeys="NOKAITO"
			unionClms="S${CCNT}" />

		<og:columnEditor column="S${CCNT}" label="{@NAIYO}" />

	</og:equals>

	<og:equals val1="{@KBUNRUI}" val2="SCALE">
		<og:value command="SQL" action="ROW_APPEND">
			select A.UNIQ AN03_UNIQS
			from AN03 A
			where A.CDANK = '{@CDANK}'
			and A.CDSITSU = '{@CDSITSU}'
			and A.FGJ = '1'
			order by A.SEQNO
		</og:value>

		<c:forTokens items="${AN03_UNIQS}" delims="," var="AN03_UNIQ" varStatus="status">
			<og:value command="SQL">
				select A.KVAL, A.KNAME
				from AN03 A
				where A.UNIQ = '{@AN03_UNIQ}'
			</og:value>

			<c:set var="CCNT" value="${CCNT+1}" />

			<og:query command="{@command}" displayMsg="" notfoundMsg="" maxRowCount="100000" quotCheck="false" scope="request">
				select A.NOKAITO, A.KVALSCL S${CCNT}
				from AN12 A
				where A.CDANK = '{@CDANK}'
				and A.CDSITSU = '{@CDSITSU}'
				and A.KVAL = '{@KVAL}'
				and A.FGJ = '1'
				order by A.NOKAITO,A.KVAL
			</og:query>

			<og:tableMerge
				command="{@command}"
				action="GROUP"
				display="false"
				masterScope="request"
				scope="request"
				masterKeys="NOKAITO"
				groupAddClms="S${CCNT}"
				separator="|" />
			<og:tableMerge
				command="{@command}"
				action="UNION_CLM"
				display="false"
				slaveScope="request"
				masterKeys="NOKAITO"
				unionClms="S${CCNT}" />

			<og:columnEditor column="S${CCNT}" label="{@NAIYO}({@KNAME})" />
		</c:forTokens>
	</og:equals>

</c:forTokens>

<!--
<og:columnEditor column="KVALSCL" renderer="LABEL" />
-->

<og:writeTable
	writerClass	= "Renderer"
	fileURL		= "{@USER.ID}"
	filename	= "allData.xls"
/>

<og:forward page="{@SYS.FILE_OUT_URL}/{@USER.ID}/allData.xls" filename="allData.xls" />

</jsp:root>
