<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport name="ShipmentsReport" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="812" leftMargin="15" rightMargin="15" topMargin="10" bottomMargin="10">
	<style name="Arial_Normal" isDefault="true" fontName="Arial" fontSize="8" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
	<style name="Arial_Bold" isDefault="false" fontName="Arial" fontSize="8" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
	
	<subDataset name="Country_Orders">
		<parameter name="Country" class="java.lang.String"/>
		<queryString><![CDATA[
			SELECT ShippedDate, ShipRegion, ShipCity, Freight 
			FROM Orders 
			WHERE 
				ShipCountry = $P{Country} AND 
				ShippedDate IS NOT NULL
		]]></queryString>
		<field name="ShippedDate" class="java.sql.Timestamp"/>
		<field name="ShipRegion" class="java.lang.String"/>
		<field name="ShipCity" class="java.lang.String"/>
		<field name="Freight" class="java.lang.Float"/>
	</subDataset>
	
	<queryString><![CDATA[
		SELECT DISTINCT ShipCountry FROM Orders
	]]></queryString>
	<field name="ShipCountry" class="java.lang.String"/>
	
	<detail>
		<band height="100">
			<textField>
				<reportElement x="0" y="0" width="500" height="15"/>
				<textElement>
					<font fontName="Arial_Bold" size="10"/>
				</textElement>
				<textFieldExpression>"Shipments to " + $F{ShipCountry}</textFieldExpression>
			</textField>
			
			<crosstab name="CountryShipments" isRepeatColumnHeaders="false">
				<reportElement x="0" y="20" width="812" height="60" mode="Opaque"/>
				
				<crosstabParameter name="Country" class="java.lang.String">
					<parameterValueExpression>$F{ShipCountry}</parameterValueExpression>
				</crosstabParameter>
				
				<crosstabDataset>
					<dataset>
						<datasetRun subDataset="Country_Orders">
							<datasetParameter name="Country">
								<datasetParameterExpression><![CDATA[$F{ShipCountry}]]></datasetParameterExpression>
							</datasetParameter>
						</datasetRun>
					</dataset>
				</crosstabDataset>
				
				<rowGroup name="Region" width="50" totalPosition="End">
					<bucket>
						<bucketExpression class="java.lang.String">$F{ShipRegion}</bucketExpression>
					</bucket>
					<crosstabRowHeader>
						<cellContents>
							<box leftBorder="2Point" bottomBorder="2Point" rightBorder="2Point"/>
							<textField>
								<reportElement x="5" y="5" width="40" height="40"/>
								<textFieldExpression><![CDATA[$V{Region} == null ? "No region" : $V{Region}]]></textFieldExpression>
							</textField>
						</cellContents>
					</crosstabRowHeader>
					<crosstabTotalRowHeader>
						<cellContents backcolor="#60FFFF">
							<box leftBorder="2Point" bottomBorder="2Point" rightBorder="2Point"/>
							<textField>
								<reportElement x="5" y="5" width="110" height="20"/>
								<textFieldExpression>$P{Country} + " Total"</textFieldExpression>
							</textField>
						</cellContents>
					</crosstabTotalRowHeader>
				</rowGroup>
				
				<rowGroup name="City" width="70" totalPosition="End">
					<bucket>
						<bucketExpression class="java.lang.String">$F{ShipCity}</bucketExpression>
					</bucket>
					<crosstabRowHeader>
						<cellContents>
							<box bottomBorder="2Point" rightBorder="2Point"/>
							<textField>
								<reportElement x="5" y="5" width="60" height="15"/>
								<textFieldExpression>$V{City}</textFieldExpression>
							</textField>
						</cellContents>
					</crosstabRowHeader>
					<crosstabTotalRowHeader>
						<cellContents backcolor="#E0FFFF">
							<box bottomBorder="2Point" rightBorder="2Point"/>
							<staticText>
								<reportElement x="5" y="5" width="60" height="15"/>
								<text>Total</text>
							</staticText>
						</cellContents>
					</crosstabTotalRowHeader>
				</rowGroup>
				
				<columnGroup name="ShipYear" height="30" totalPosition="End" headerPosition="Stretch">
					<bucket>
						<bucketExpression class="java.util.Date">CrosstabApp.truncateToYear($F{ShippedDate})</bucketExpression>
					</bucket>
					<crosstabColumnHeader>
						<cellContents>
							<box topBorder="2Point" bottomBorder="2Point" rightBorder="2Point"/>
							<rectangle radius="10">
								<reportElement x="4" y="4" width="52" height="22"/>
								<graphicElement pen="1Point"/>
							</rectangle>
							<textField pattern="yyyy">
								<reportElement x="5" y="5" width="50" height="20"/>
								<textElement textAlignment="Center" verticalAlignment="Middle"/>
								<textFieldExpression class="java.util.Date">$V{ShipYear}</textFieldExpression>
							</textField>
						</cellContents>
					</crosstabColumnHeader>
					<crosstabTotalColumnHeader>
						<cellContents backcolor="#FFFF60">
							<box topBorder="2Point" bottomBorder="2Point" rightBorder="2Point"/>
							<staticText>
								<reportElement x="5" y="5" width="20" height="15"/>
								<text>Total</text>
							</staticText>
						</cellContents>
					</crosstabTotalColumnHeader>
				</columnGroup>
				
				<columnGroup name="ShipMonth" height="40" totalPosition="End">
					<bucket>
						<bucketExpression class="java.util.Date">CrosstabApp.truncateToMonth($F{ShippedDate})</bucketExpression>
					</bucket>
					<crosstabColumnHeader>
						<cellContents>
							<box bottomBorder="2Point" rightBorder="2Point"/>
							<textField pattern="MMM">
								<reportElement x="5" y="5" width="20" height="30"/>
								<textFieldExpression class="java.util.Date">$V{ShipMonth}</textFieldExpression>
							</textField>
						</cellContents>
					</crosstabColumnHeader>
					<crosstabTotalColumnHeader>
						<cellContents backcolor="#FFFFC0">
							<box bottomBorder="2Point" rightBorder="2Point"/>
							<textField>
								<reportElement x="5" y="5" width="20" height="30"/>
								<textFieldExpression>msg("{0,date,yyyy} Total", $V{ShipYear})</textFieldExpression>
							</textField>
						</cellContents>
					</crosstabTotalColumnHeader>
				</columnGroup>

				<measure name="FreightSum" class="java.lang.Float" calculation="Sum">
					<measureExpression>$F{Freight}</measureExpression>
				</measure>
				
				<crosstabCell width="30" height="25">
					<cellContents backcolor="#FFFFFF">
						<box bottomBorder="1Point" rightBorder="1Point"/>
						<textField pattern="#0.0">
							<reportElement x="0" y="0" width="25" height="25"/>
							<textElement textAlignment="Right" verticalAlignment="Middle"/>
							<textFieldExpression class="java.lang.Float">$V{FreightSum}</textFieldExpression>
						</textField>
					</cellContents>
				</crosstabCell>
				
				<crosstabCell width="30" height="25" columnTotalGroup="ShipMonth">
					<cellContents backcolor="#FFFFC0">
						<box bottomBorder="1Point" rightBorder="1Point"/>
						<textField pattern="#0.0">
							<reportElement x="0" y="0" width="25" height="25" style="Arial_Bold"/>
							<textElement textAlignment="Right" verticalAlignment="Middle"/>
							<textFieldExpression class="java.lang.Float">$V{FreightSum}</textFieldExpression>
						</textField>
					</cellContents>
				</crosstabCell>
				
				<crosstabCell width="35" height="25" columnTotalGroup="ShipYear">
					<cellContents backcolor="#FFFF60">
						<box bottomBorder="1Point" rightBorder="1Point"/>
						<textField pattern="#0.0">
							<reportElement x="0" y="0" width="30" height="25" style="Arial_Bold"/>
							<textElement textAlignment="Right" verticalAlignment="Middle"/>
							<textFieldExpression class="java.lang.Float">$V{FreightSum}</textFieldExpression>
						</textField>
					</cellContents>
				</crosstabCell>
				
				<crosstabCell height="25" rowTotalGroup="City">
					<cellContents backcolor="#E0FFFF">
						<box bottomBorder="1Point" rightBorder="1Point"/>
						<textField pattern="#0.0">
							<reportElement x="0" y="0" width="25" height="25"/>
							<textElement textAlignment="Right" verticalAlignment="Middle"/>
							<textFieldExpression class="java.lang.Float">$V{FreightSum}</textFieldExpression>
						</textField>
					</cellContents>
				</crosstabCell>
				
				<crosstabCell rowTotalGroup="City" columnTotalGroup="ShipMonth">
					<cellContents backcolor="#E0FFC0">
						<box bottomBorder="1Point" rightBorder="1Point"/>
						<textField pattern="#0.0">
							<reportElement x="0" y="0" width="25" height="25" style="Arial_Bold"/>
							<textElement textAlignment="Right" verticalAlignment="Middle"/>
							<textFieldExpression class="java.lang.Float">$V{FreightSum}</textFieldExpression>
						</textField>
					</cellContents>
				</crosstabCell>
				
				<crosstabCell rowTotalGroup="City" columnTotalGroup="ShipYear">
					<cellContents backcolor="#E0FF60">
						<box bottomBorder="1Point" rightBorder="1Point"/>
						<textField pattern="#0.0">
							<reportElement x="0" y="0" width="30" height="25" style="Arial_Bold"/>
							<textElement textAlignment="Right" verticalAlignment="Middle"/>
							<textFieldExpression class="java.lang.Float">$V{FreightSum}</textFieldExpression>
						</textField>
					</cellContents>
				</crosstabCell>
				
				<crosstabCell height="30" rowTotalGroup="Region">
					<cellContents backcolor="#60FFFF">
						<box bottomBorder="1Point" rightBorder="1Point"/>
						<textField pattern="#0.0">
							<reportElement x="0" y="0" width="25" height="30" style="Arial_Bold"/>
							<textElement textAlignment="Right" verticalAlignment="Middle"/>
							<textFieldExpression class="java.lang.Float">$V{FreightSum}</textFieldExpression>
						</textField>
					</cellContents>
				</crosstabCell>
				
				<crosstabCell rowTotalGroup="Region" columnTotalGroup="ShipMonth">
					<cellContents backcolor="#60FFC0">
						<box bottomBorder="1Point" rightBorder="1Point"/>
						<textField pattern="#0.0">
							<reportElement x="0" y="0" width="25" height="30" style="Arial_Bold"/>
							<textElement textAlignment="Right" verticalAlignment="Middle"/>
							<textFieldExpression class="java.lang.Float">$V{FreightSum}</textFieldExpression>
						</textField>
					</cellContents>
				</crosstabCell>
				
				<crosstabCell rowTotalGroup="Region" columnTotalGroup="ShipYear">
					<cellContents backcolor="#60FF60">
						<box bottomBorder="1Point" rightBorder="1Point"/>
						<textField pattern="#0.0">
							<reportElement x="0" y="0" width="30" height="30" style="Arial_Bold"/>
							<textElement textAlignment="Right" verticalAlignment="Middle"/>
							<textFieldExpression class="java.lang.Float">$V{FreightSum}</textFieldExpression>
						</textField>
					</cellContents>
				</crosstabCell>
				
			</crosstab>
		</band>
	</detail>
</jasperReport>

