<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport name="MasterReport" pageWidth="595" pageHeight="842" columnWidth="515" leftMargin="40" rightMargin="40" topMargin="50" bottomMargin="50">
	<style name="Arial_Normal" isDefault="true" fontName="Arial" fontSize="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
	<style name="Arial_Bold" isDefault="false" fontName="Arial" fontSize="12" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
	<style name="Arial_Italic" isDefault="false" fontName="Arial" fontSize="12" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Oblique" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
	<parameter name="ProductsSubreport" class="net.sf.jasperreports.engine.JasperReport">
	</parameter>
	<queryString><![CDATA[SELECT City FROM Address GROUP BY City ORDER BY City]]></queryString>
	<field name="City" class="java.lang.String">
	</field>
	<variable name="ProductTotalPrice" class="java.lang.Float" calculation="System"/>
	<variable name="CityAddressCount" class="java.lang.Integer" calculation="System"/>
	<title>
		<band height="70">
			<line>
				<reportElement x="0" y="0" width="515" height="1"/>
				<graphicElement/>
			</line>
			<staticText>
				<reportElement x="0" y="10" width="515" height="30" style="Arial_Normal"/>
				<textElement textAlignment="Center">
					<font size="22"/>
				</textElement>
				<text><![CDATA[Master Report]]></text>
			</staticText>
			<textField evaluationTime="Report">
				<reportElement x="0" y="40" width="515" height="30" style="Arial_Normal"/>
				<textElement textAlignment="Center">
					<font size="18"/>
				</textElement>
				<textFieldExpression>"Total order value: " + $V{ProductTotalPrice}</textFieldExpression>
			</textField>
		</band>
	</title>
	<pageHeader>
		<band height="21">
			<rectangle>
				<reportElement x="0" y="5" width="515" height="15" backcolor="#333333"/>
				<graphicElement pen="None"/>
			</rectangle>
			<staticText>
				<reportElement mode="Opaque" x="0" y="5" width="515" height="15" forecolor="#ffffff" backcolor="#333333" style="Arial_Bold"/>
				<text><![CDATA[City List]]></text>
			</staticText>
			<line>
				<reportElement x="0" y="20" width="515" height="1"/>
				<graphicElement/>
			</line>
		</band>
	</pageHeader>
	<detail>
		<band height="50">
			<textField>
				<reportElement x="5" y="5" width="100" height="15" isPrintWhenDetailOverflows="true" style="Arial_Bold"/>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{City}]]></textFieldExpression>
			</textField>
			<textField evaluationTime="Band">
				<reportElement x="110" y="5" width="200" height="15" style="Arial_Bold"/>
				<textFieldExpression class="java.lang.String"><![CDATA[$V{CityAddressCount} + " addresses"]]></textFieldExpression>
			</textField>
			<staticText>
				<reportElement isPrintRepeatedValues="false" x="110" y="5" width="100" height="15" isPrintWhenDetailOverflows="true" style="Arial_Bold"/>
				<text><![CDATA[(continued)]]></text>
			</staticText>
			<line>
				<reportElement x="0" y="20" width="515" height="1" isPrintWhenDetailOverflows="true"/>
				<graphicElement/>
			</line>
			<subreport>
				<reportElement isPrintRepeatedValues="false" x="5" y="25" width="325" height="20" isRemoveLineWhenBlank="true" backcolor="#ffcc99"/>
				<subreportParameter name="City">
					<subreportParameterExpression><![CDATA[$F{City}]]></subreportParameterExpression>
				</subreportParameter>
				<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
				<returnValue subreportVariable="PriceSum" toVariable="ProductTotalPrice" calculation="Sum"/>
				<subreportExpression class="net.sf.jasperreports.engine.JasperReport"><![CDATA[$P{ProductsSubreport}]]></subreportExpression>
			</subreport>
			<subreport>
				<reportElement positionType="Float" x="335" y="25" width="175" height="20" isRemoveLineWhenBlank="true" backcolor="#99ccff"/>
				<subreportParameter name="City">
					<subreportParameterExpression><![CDATA[$F{City}]]></subreportParameterExpression>
				</subreportParameter>
				<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
				<returnValue subreportVariable="REPORT_COUNT" toVariable="CityAddressCount"/>
				<subreportExpression class="java.lang.String"><![CDATA["AddressReport.jasper"]]></subreportExpression>
			</subreport>
		</band>
	</detail>
	<pageFooter>
		<band height="40">
			<line>
				<reportElement x="0" y="10" width="515" height="1"/>
				<graphicElement/>
			</line>
			<textField>
				<reportElement x="200" y="20" width="80" height="15"/>
				<textElement textAlignment="Right"/>
				<textFieldExpression class="java.lang.String"><![CDATA["Page " + String.valueOf($V{PAGE_NUMBER}) + " of"]]></textFieldExpression>
			</textField>
			<textField evaluationTime="Report">
				<reportElement x="280" y="20" width="75" height="15"/>
				<textElement/>
				<textFieldExpression class="java.lang.String"><![CDATA[" " + String.valueOf($V{PAGE_NUMBER})]]></textFieldExpression>
			</textField>
		</band>
	</pageFooter>
</jasperReport>

