<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Backorder Report - Summary" pageWidth="792" pageHeight="612" orientation="Landscape" columnWidth="752" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
	<property name="ireport.zoom" value="1.0"/>
	<property name="ireport.x" value="273"/>
	<property name="ireport.y" value="0"/>
	<parameter name="as_site_code" class="java.lang.String"/>
	<parameter name="frm_order_date" class="java.util.Date"/>
	<parameter name="to_order_date" class="java.util.Date"/>
	<queryString>
		<![CDATA[select ITEM_CODE,
ITEM_DESCR,
CUST_CODE,
CUST_NAME,
SUM(ORD_QTY) AS ORD_QTY,
SUM(ORD_VALUE) AS ORD_VALUE,
SUM(SHIP_QTY) AS SHIP_QTY,
SUM(SHIP_VALUE) AS SHIP_VALUE,
SUM(ORD_QTY-SHIP_QTY) AS BACKORDER_QTY,
SUM(ORD_VALUE-SHIP_VALUE) AS BACKORDER_VALUE,
SUM(STOCK_QTY) AS INV_QTY,
SITE_DESCR
from
(
select sorder.site_code, sorder.sale_order,sorddet.line_no,sorder.order_date,sorder.due_date,sorder.status_date,sorder.cust_code,customer.cust_name,sorddet.quantity as ord_qty,(sorddet.quantity*sorddet.rate) as ord_value,0 as ship_qty,0 as ship_value,sorddet.item_code,item.descr as item_descr,ddf_get_stock(sorder.site_code,sorddet.item_code) as stock_qty,ddf_get_site_descr(sorder.site_code) as site_descr
from
sorder,sorddet,customer,item
where sorder.order_date between $P{frm_order_date} AND $P{to_order_date}
and sorder.site_code =  '$P!{as_site_code}'
and sorder.confirmed = 'Y' and sorder.status = 'P' and sorddet.sale_order = sorder.sale_order and customer.cust_code = sorder.cust_code and item.item_code = sorddet.item_code
union all
select sorder.site_code,sorder.sale_order,sorditem.line_no,sorder.order_date,sorditem.due_date,sorder.status_date,sorder.cust_code,customer.cust_name,0 as ord_qty,0 as ord_value,sum(sorditem.qty_desp) as ship_qty,sum(sorditem.qty_desp*sorditem.rate) as ship_value,sorditem.item_code,item.descr as item_descr,0 as stock_qty,ddf_get_site_descr(sorder.site_code) as site_descr
from sorder,sorditem,customer,item
where sorder.order_date between $P{frm_order_date} AND $P{to_order_date}
and sorder.site_code =  '$P!{as_site_code}'
and sorder.confirmed = 'Y' and sorder.status = 'P' and sorditem.sale_order = sorder.sale_order and customer.cust_code = sorder.cust_code and item.item_code = sorditem.item_code
group by sorder.site_code,sorder.sale_order,sorditem.line_no,sorder.order_date,sorditem.due_date,sorder.status_date,sorder.cust_code,customer.cust_name,sorditem.item_code,item.descr)
group by item_code,item_descr,cust_code,cust_name,site_descr having sum(ord_qty-ship_qty) > 0]]>
	</queryString>
	<field name="ITEM_CODE" class="java.lang.String"/>
	<field name="ITEM_DESCR" class="java.lang.String"/>
	<field name="ORD_QTY" class="java.lang.Double"/>
	<field name="ORD_VALUE" class="java.lang.Double"/>
	<field name="SHIP_QTY" class="java.lang.Double"/>
	<field name="SHIP_VALUE" class="java.lang.Double"/>
	<field name="BACKORDER_QTY" class="java.lang.Double"/>
	<field name="BACKORDER_VALUE" class="java.lang.Double"/>
	<field name="INV_QTY" class="java.lang.Double"/>
	<field name="SITE_DESCR" class="java.lang.String"/>
	<field name="CUST_CODE" class="java.lang.String"/>
	<field name="CUST_NAME" class="java.lang.String"/>
	<sortField name="CUST_CODE"/>
	<variable name="variable1" class="java.util.Date" resetType="None">
		<variableExpression><![CDATA[new java.util.Date()]]></variableExpression>
	</variable>
	<variable name="ord_tot" class="java.lang.Double" resetType="Group" resetGroup="CUSTOMER" calculation="Sum">
		<variableExpression><![CDATA[$F{ORD_VALUE}]]></variableExpression>
	</variable>
	<variable name="ship_tot" class="java.lang.Double" resetType="Group" resetGroup="CUSTOMER" calculation="Sum">
		<variableExpression><![CDATA[$F{SHIP_VALUE}]]></variableExpression>
	</variable>
	<variable name="backord_tot" class="java.lang.Double" resetType="Group" resetGroup="CUSTOMER" calculation="Sum">
		<variableExpression><![CDATA[$F{BACKORDER_VALUE}]]></variableExpression>
	</variable>
	<variable name="ord_grand" class="java.lang.Double" calculation="Sum">
		<variableExpression><![CDATA[$F{ORD_VALUE}]]></variableExpression>
	</variable>
	<variable name="ship_grand" class="java.lang.Double" calculation="Sum">
		<variableExpression><![CDATA[$F{SHIP_VALUE}]]></variableExpression>
	</variable>
	<variable name="backord_grand" class="java.lang.Double" calculation="Sum">
		<variableExpression><![CDATA[$F{BACKORDER_VALUE}]]></variableExpression>
	</variable>
	<group name="CUSTOMER" isReprintHeaderOnEachPage="true">
		<groupExpression><![CDATA[$F{CUST_CODE}]]></groupExpression>
		<groupHeader>
			<band height="18">
				<textField>
					<reportElement x="93" y="2" width="174" height="16"/>
					<textElement textAlignment="Left">
						<font fontName="Times New Roman" isBold="true"/>
					</textElement>
					<textFieldExpression class="java.lang.String"><![CDATA[$F{CUST_NAME}]]></textFieldExpression>
				</textField>
				<staticText>
					<reportElement x="17" y="0" width="76" height="18"/>
					<textElement textAlignment="Left" verticalAlignment="Middle">
						<font fontName="Times New Roman" isBold="true"/>
					</textElement>
					<text><![CDATA[Customer Name : ]]></text>
				</staticText>
				<line>
					<reportElement x="0" y="17" width="750" height="1"/>
				</line>
			</band>
		</groupHeader>
		<groupFooter>
			<band height="20">
				<staticText>
					<reportElement x="185" y="1" width="159" height="18"/>
					<textElement textAlignment="Left" verticalAlignment="Middle">
						<font fontName="Times New Roman" isBold="true"/>
					</textElement>
					<text><![CDATA[Customer Code Wise Total]]></text>
				</staticText>
				<textField pattern="0.00">
					<reportElement x="329" y="1" width="87" height="18"/>
					<textElement textAlignment="Right" verticalAlignment="Middle">
						<font fontName="Times New Roman"/>
					</textElement>
					<textFieldExpression class="java.lang.Double"><![CDATA[$V{ord_tot}]]></textFieldExpression>
				</textField>
				<textField pattern="0.00">
					<reportElement x="482" y="1" width="85" height="18"/>
					<textElement textAlignment="Right" verticalAlignment="Middle">
						<font fontName="Times New Roman"/>
					</textElement>
					<textFieldExpression class="java.lang.Double"><![CDATA[$V{ship_tot}]]></textFieldExpression>
				</textField>
				<textField pattern="0.00">
					<reportElement x="636" y="1" width="100" height="18"/>
					<textElement textAlignment="Right" verticalAlignment="Middle">
						<font fontName="Times New Roman"/>
					</textElement>
					<textFieldExpression class="java.lang.Double"><![CDATA[$V{backord_tot}]]></textFieldExpression>
				</textField>
				<line>
					<reportElement x="0" y="0" width="750" height="1"/>
				</line>
				<line>
					<reportElement x="0" y="19" width="750" height="1"/>
				</line>
			</band>
		</groupFooter>
	</group>
	<background>
		<band splitType="Stretch"/>
	</background>
	<pageHeader>
		<band height="79" splitType="Stretch">
			<textField>
				<reportElement x="2" y="10" width="748" height="17"/>
				<textElement textAlignment="Center">
					<font fontName="Times New Roman" size="12" isBold="true"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{SITE_DESCR}]]></textFieldExpression>
			</textField>
			<line>
				<reportElement x="0" y="56" width="750" height="1"/>
			</line>
			<staticText>
				<reportElement x="0" y="29" width="752" height="18"/>
				<textElement textAlignment="Center">
					<font fontName="Times New Roman" size="14" isBold="true"/>
				</textElement>
				<text><![CDATA[Backorder Report - Summary]]></text>
			</staticText>
			<textField pattern="MM/dd/yy">
				<reportElement x="36" y="10" width="133" height="17"/>
				<textElement>
					<font fontName="Times New Roman"/>
				</textElement>
				<textFieldExpression class="java.util.Date"><![CDATA[$V{variable1}]]></textFieldExpression>
			</textField>
			<staticText>
				<reportElement x="4" y="10" width="28" height="17"/>
				<textElement>
					<font fontName="Times New Roman" isBold="true"/>
				</textElement>
				<text><![CDATA[Date:]]></text>
			</staticText>
			<staticText>
				<reportElement x="675" y="9" width="20" height="20"/>
				<textElement>
					<font fontName="Times New Roman" isBold="false"/>
				</textElement>
				<text><![CDATA[Page]]></text>
			</staticText>
			<staticText>
				<reportElement x="709" y="9" width="10" height="14"/>
				<textElement>
					<font fontName="Times New Roman" isBold="false"/>
				</textElement>
				<text><![CDATA[of]]></text>
			</staticText>
			<textField evaluationTime="Page">
				<reportElement x="697" y="9" width="13" height="20"/>
				<textElement>
					<font fontName="Times New Roman"/>
				</textElement>
				<textFieldExpression class="java.lang.Integer"><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
			</textField>
			<staticText>
				<reportElement x="17" y="58" width="70" height="18"/>
				<textElement textAlignment="Left" verticalAlignment="Middle">
					<font fontName="Times New Roman" isBold="true"/>
				</textElement>
				<text><![CDATA[Item]]></text>
			</staticText>
			<textField evaluationTime="Report">
				<reportElement x="722" y="9" width="15" height="20"/>
				<textElement>
					<font fontName="Times New Roman"/>
				</textElement>
				<textFieldExpression class="java.lang.Integer"><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
			</textField>
			<staticText>
				<reportElement x="88" y="58" width="165" height="18"/>
				<textElement textAlignment="Left" verticalAlignment="Middle">
					<font fontName="Times New Roman" isBold="true"/>
				</textElement>
				<text><![CDATA[Item Description]]></text>
			</staticText>
			<staticText>
				<reportElement x="267" y="58" width="77" height="18"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font fontName="Times New Roman" isBold="true"/>
				</textElement>
				<text><![CDATA[Order Qty]]></text>
			</staticText>
			<staticText>
				<reportElement x="344" y="58" width="74" height="18"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font fontName="Times New Roman" isBold="true"/>
				</textElement>
				<text><![CDATA[Order Value]]></text>
			</staticText>
			<staticText>
				<reportElement x="417" y="58" width="77" height="18"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font fontName="Times New Roman" isBold="true"/>
				</textElement>
				<text><![CDATA[Ship Qty]]></text>
			</staticText>
			<staticText>
				<reportElement x="494" y="58" width="72" height="18"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font fontName="Times New Roman" isBold="true"/>
				</textElement>
				<text><![CDATA[Ship Value]]></text>
			</staticText>
			<staticText>
				<reportElement x="569" y="58" width="77" height="18"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font fontName="Times New Roman" isBold="true"/>
				</textElement>
				<text><![CDATA[BackOrder Qty]]></text>
			</staticText>
			<staticText>
				<reportElement x="650" y="58" width="84" height="18"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font fontName="Times New Roman" isBold="true"/>
				</textElement>
				<text><![CDATA[BackOrder Value]]></text>
			</staticText>
			<line>
				<reportElement x="0" y="78" width="750" height="1"/>
			</line>
		</band>
	</pageHeader>
	<detail>
		<band height="18" splitType="Stretch">
			<textField>
				<reportElement x="88" y="0" width="174" height="18"/>
				<textElement textAlignment="Left">
					<font fontName="Times New Roman"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{ITEM_DESCR}]]></textFieldExpression>
			</textField>
			<textField pattern="0.00">
				<reportElement x="267" y="0" width="77" height="18"/>
				<textElement textAlignment="Right">
					<font fontName="Times New Roman"/>
				</textElement>
				<textFieldExpression class="java.lang.Double"><![CDATA[$F{ORD_QTY}]]></textFieldExpression>
			</textField>
			<textField pattern="0.00">
				<reportElement x="344" y="0" width="74" height="18"/>
				<textElement textAlignment="Right">
					<font fontName="Times New Roman"/>
				</textElement>
				<textFieldExpression class="java.lang.Double"><![CDATA[$F{ORD_VALUE}]]></textFieldExpression>
			</textField>
			<textField pattern="0.00">
				<reportElement x="17" y="0" width="70" height="18"/>
				<textElement textAlignment="Left">
					<font fontName="Times New Roman"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{ITEM_CODE}]]></textFieldExpression>
			</textField>
			<textField pattern="0.00">
				<reportElement x="417" y="0" width="77" height="18"/>
				<textElement textAlignment="Right">
					<font fontName="Times New Roman"/>
				</textElement>
				<textFieldExpression class="java.lang.Double"><![CDATA[$F{SHIP_QTY}]]></textFieldExpression>
			</textField>
			<textField pattern="0.00">
				<reportElement x="494" y="0" width="73" height="18"/>
				<textElement textAlignment="Right">
					<font fontName="Times New Roman"/>
				</textElement>
				<textFieldExpression class="java.lang.Double"><![CDATA[$F{SHIP_VALUE}]]></textFieldExpression>
			</textField>
			<textField pattern="0.00">
				<reportElement x="569" y="0" width="77" height="18"/>
				<textElement textAlignment="Right">
					<font fontName="Times New Roman"/>
				</textElement>
				<textFieldExpression class="java.lang.Double"><![CDATA[$F{BACKORDER_QTY}]]></textFieldExpression>
			</textField>
			<textField pattern="0.00">
				<reportElement x="650" y="0" width="84" height="18"/>
				<textElement textAlignment="Right">
					<font fontName="Times New Roman"/>
				</textElement>
				<textFieldExpression class="java.lang.Double"><![CDATA[$F{BACKORDER_VALUE}]]></textFieldExpression>
			</textField>
		</band>
	</detail>
	<pageFooter>
		<band splitType="Stretch"/>
	</pageFooter>
	<summary>
		<band height="19" splitType="Stretch">
			<textField pattern="0.00">
				<reportElement x="637" y="1" width="100" height="18"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font fontName="Times New Roman"/>
				</textElement>
				<textFieldExpression class="java.lang.Double"><![CDATA[$V{backord_grand}]]></textFieldExpression>
			</textField>
			<textField pattern="0.00">
				<reportElement x="481" y="1" width="85" height="18"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font fontName="Times New Roman"/>
				</textElement>
				<textFieldExpression class="java.lang.Double"><![CDATA[$V{ship_grand}]]></textFieldExpression>
			</textField>
			<textField pattern="0.00">
				<reportElement x="330" y="1" width="87" height="18"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font fontName="Times New Roman"/>
				</textElement>
				<textFieldExpression class="java.lang.Double"><![CDATA[$V{ord_grand}]]></textFieldExpression>
			</textField>
			<staticText>
				<reportElement x="185" y="1" width="158" height="18"/>
				<textElement textAlignment="Left" verticalAlignment="Middle">
					<font fontName="Times New Roman" isBold="true"/>
				</textElement>
				<text><![CDATA[Grand Total]]></text>
			</staticText>
		</band>
	</summary>
</jasperReport>
