<?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="packing_slip_rep_subreport1" pageWidth="792" pageHeight="612" orientation="Landscape" columnWidth="792" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
	<property name="ireport.zoom" value="1.5"/>
	<property name="ireport.x" value="723"/>
	<property name="ireport.y" value="0"/>
	<parameter name="despId" class="java.lang.String"/>
	<queryString>
		<![CDATA[SELECT
     CASE WHEN DESPATCHDET."LINE_NO__SORD" IS NULL THEN ' ' ELSE DESPATCHDET."LINE_NO__SORD" END AS DESPATCHDET_LINE_NO__SORD,
     CASE WHEN DESPATCHDET.ITEM_CODE IS NULL THEN ' ' ELSE DESPATCHDET.ITEM_CODE END AS DESPATCHDET_ITEM_CODE,
	SORDDET.CUST_ITEM__REF  AS CUST_ITEM__REF,
     NVL((SELECT CI.DESCR FROM CUSTOMERITEM CI WHERE
     DESPATCH.CUST_CODE__DLV = CI.CUST_CODE  AND DESPATCHDET.ITEM_CODE = CI.ITEM_CODE AND SORDDET.CUST_ITEM__REF = CI.ITEM_CODE__REF),ITEM.DESCR) AS CUST_ITEM_DESCR,
     CASE WHEN DESPATCHDET."LOT_NO" IS NULL THEN ' ' ELSE DESPATCHDET."LOT_NO" END AS DESPATCHDET_LOT_NO,
     DESPATCHDET.EXP_DATE AS DESPATCHDET_EXP_DATE,
     CASE WHEN DESPATCHDET."QUANTITY" IS NULL THEN 0 ELSE  DESPATCHDET."QUANTITY" END AS DESPATCHDET_QUANTITY,
     CASE WHEN DESPATCHDET."QUANTITY__ORD" IS NULL THEN 0 ELSE DESPATCHDET."QUANTITY__ORD" END AS DESPATCHDET_QUANTITY__ORD,
     (SELECT SUM(DT.QUANTITY) FROM DESPATCHDET DT WHERE DT.DESP_ID = DESPATCHDET.DESP_ID AND DT.LINE_NO__SORD = DESPATCHDET.LINE_NO__SORD) AS SHIP_QTY,
     DESPATCHdet.desp_id,
     1 as cntr
FROM
     "DESPATCHDET" DESPATCHDET,
     "SORDDET" SORDDET,
     "DESPATCH" DESPATCH,
     "ITEM" ITEM
WHERE
   DESPATCHDET.DESP_ID = DESPATCH.DESP_ID
   AND SORDDET.SALE_ORDER = DESPATCHDET.SORD_NO
   AND SORDDET.LINE_NO = DESPATCHDET.LINE_NO__SORD
   AND ITEM.ITEM_CODE = DESPATCHDET.ITEM_CODE
   AND DESPATCH.DESP_ID = '$P!{despId}'
ORDER BY DESPATCHDET.DESP_ID,DESPATCHDET.LINE_NO__SORD]]>
	</queryString>
	<field name="DESPATCHDET_LINE_NO__SORD" class="java.lang.String"/>
	<field name="DESPATCHDET_LOT_NO" class="java.lang.String"/>
	<field name="SHIP_QTY" class="java.lang.Double"/>
	<field name="DESPATCHDET_QUANTITY__ORD" class="java.lang.Double"/>
	<field name="DESPATCHDET_QUANTITY" class="java.lang.Double"/>
	<field name="DESPATCHDET_ITEM_CODE" class="java.lang.String"/>
	<field name="CUST_ITEM__REF" class="java.lang.String"/>
	<field name="CUST_ITEM_DESCR" class="java.lang.String"/>
	<field name="DESPATCHDET_EXP_DATE" class="java.util.Date"/>
	<field name="DESP_ID" class="java.lang.String"/>
	<field name="cntr" class="java.lang.Double"/>
	<variable name="ordQtySum" class="java.lang.Double" resetType="Group" resetGroup="Item_Lot_Line" calculation="Sum">
		<variableExpression><![CDATA[new java.lang.Double($F{DESPATCHDET_QUANTITY__ORD}.doubleValue())]]></variableExpression>
	</variable>
	<variable name="shipQtySum" class="java.lang.Double" resetType="Group" resetGroup="Item_Lot_Line" calculation="Sum">
		<variableExpression><![CDATA[new java.lang.Double($F{SHIP_QTY}.doubleValue())]]></variableExpression>
	</variable>
	<variable name="compute_1" class="java.lang.Double" resetType="Group" resetGroup="Item_Lot_Line" calculation="Sum">
		<variableExpression><![CDATA[new java.lang.Double($F{DESPATCHDET_QUANTITY}.doubleValue())]]></variableExpression>
	</variable>
	<variable name="compute_2" class="java.lang.Double" resetType="Group" resetGroup="Item_Lot_Line" calculation="Sum">
		<variableExpression><![CDATA[new java.lang.Double($F{cntr}.doubleValue())]]></variableExpression>
	</variable>
	<variable name="ordQtySum_1" class="java.lang.Double" resetType="Group" resetGroup="Item_Lot_Line">
		<variableExpression><![CDATA[new java.lang.Double($V{ordQtySum}.doubleValue()/$V{compute_2}.doubleValue())]]></variableExpression>
	</variable>
	<variable name="shipQtySum_1" class="java.lang.Double" resetType="Group" resetGroup="Item_Lot_Line">
		<variableExpression><![CDATA[new java.lang.Double($V{shipQtySum}.doubleValue()/$V{compute_2}.doubleValue())]]></variableExpression>
	</variable>
	<variable name="compute_3" class="java.lang.Double" incrementType="Group" incrementGroup="Item_Lot_Line" calculation="Sum">
		<variableExpression><![CDATA[new java.lang.Double($V{ordQtySum_1}.doubleValue())]]></variableExpression>
	</variable>
	<variable name="compute_4" class="java.lang.Double" incrementType="Group" incrementGroup="Item_Lot_Line" calculation="Sum">
		<variableExpression><![CDATA[new java.lang.Double($V{shipQtySum_1}.doubleValue())]]></variableExpression>
	</variable>
	<group name="Item_Lot_Line">
		<groupExpression><![CDATA[$F{DESPATCHDET_LINE_NO__SORD}+$F{DESPATCHDET_ITEM_CODE}+$F{DESPATCHDET_LOT_NO}]]></groupExpression>
		<groupHeader>
			<band height="22">
				<staticText>
					<reportElement x="478" y="11" width="22" height="10"/>
					<textElement>
						<font fontName="Courier New" size="7"/>
					</textElement>
					<text><![CDATA[Qty :]]></text>
				</staticText>
				<textField isBlankWhenNull="true">
					<reportElement x="10" y="2" width="31" height="9"/>
					<textElement>
						<font fontName="Courier New" size="7"/>
					</textElement>
					<textFieldExpression class="java.lang.String"><![CDATA[$F{DESPATCHDET_LINE_NO__SORD}]]></textFieldExpression>
				</textField>
				<textField isBlankWhenNull="true">
					<reportElement x="52" y="2" width="88" height="9"/>
					<textElement>
						<font fontName="Courier New" size="7"/>
					</textElement>
					<textFieldExpression class="java.lang.String"><![CDATA[$F{DESPATCHDET_ITEM_CODE}]]></textFieldExpression>
				</textField>
				<textField isBlankWhenNull="true">
					<reportElement x="340" y="11" width="51" height="10"/>
					<textElement>
						<font fontName="Courier New" size="7"/>
					</textElement>
					<textFieldExpression class="java.lang.String"><![CDATA[$F{DESPATCHDET_LOT_NO}]]></textFieldExpression>
				</textField>
				<staticText>
					<reportElement x="309" y="11" width="31" height="10"/>
					<textElement>
						<font fontName="Courier New" size="7"/>
					</textElement>
					<text><![CDATA[Lot# :]]></text>
				</staticText>
				<textField pattern="MM/dd/yy" isBlankWhenNull="true">
					<reportElement x="426" y="11" width="51" height="10"/>
					<textElement>
						<font fontName="Courier New" size="7"/>
					</textElement>
					<textFieldExpression class="java.util.Date"><![CDATA[$F{DESPATCHDET_EXP_DATE}]]></textFieldExpression>
				</textField>
				<staticText>
					<reportElement x="403" y="11" width="23" height="10"/>
					<textElement>
						<font fontName="Courier New" size="7"/>
					</textElement>
					<text><![CDATA[Exp :]]></text>
				</staticText>
				<textField evaluationTime="Group" evaluationGroup="Item_Lot_Line" pattern="0" isBlankWhenNull="true">
					<reportElement x="504" y="11" width="51" height="10"/>
					<textElement textAlignment="Right">
						<font fontName="Courier New" size="7"/>
					</textElement>
					<textFieldExpression class="java.lang.Double"><![CDATA[$V{compute_1}]]></textFieldExpression>
				</textField>
				<textField isBlankWhenNull="true">
					<reportElement x="307" y="1" width="148" height="9"/>
					<textElement>
						<font fontName="Courier New" size="7"/>
					</textElement>
					<textFieldExpression class="java.lang.String"><![CDATA[$F{CUST_ITEM_DESCR}]]></textFieldExpression>
				</textField>
				<textField evaluationTime="Group" evaluationGroup="Item_Lot_Line" pattern="0" isBlankWhenNull="true">
					<reportElement x="702" y="1" width="51" height="10"/>
					<textElement textAlignment="Right">
						<font fontName="Courier New" size="7"/>
					</textElement>
					<textFieldExpression class="java.lang.Double"><![CDATA[$V{shipQtySum_1}]]></textFieldExpression>
				</textField>
				<textField isBlankWhenNull="true">
					<reportElement x="167" y="1" width="122" height="9"/>
					<textElement>
						<font fontName="Courier New" size="7"/>
					</textElement>
					<textFieldExpression class="java.lang.String"><![CDATA[$F{CUST_ITEM__REF}]]></textFieldExpression>
				</textField>
				<textField evaluationTime="Group" evaluationGroup="Item_Lot_Line" pattern="0" isBlankWhenNull="true">
					<reportElement x="621" y="1" width="51" height="10"/>
					<textElement textAlignment="Right">
						<font fontName="Courier New" size="7"/>
					</textElement>
					<textFieldExpression class="java.lang.Double"><![CDATA[$V{ordQtySum_1}]]></textFieldExpression>
				</textField>
			</band>
		</groupHeader>
		<groupFooter>
			<band/>
		</groupFooter>
	</group>
	<background>
		<band splitType="Stretch"/>
	</background>
	<title>
		<band splitType="Stretch"/>
	</title>
	<pageHeader>
		<band height="21" splitType="Stretch">
			<staticText>
				<reportElement x="307" y="5" width="150" height="10"/>
				<textElement>
					<font fontName="Courier New" size="7"/>
				</textElement>
				<text><![CDATA[SKU Description]]></text>
			</staticText>
			<staticText>
				<reportElement x="167" y="5" width="122" height="10"/>
				<textElement>
					<font fontName="Courier New" size="7"/>
				</textElement>
				<text><![CDATA[Customer SKU]]></text>
			</staticText>
			<staticText>
				<reportElement x="52" y="5" width="88" height="10"/>
				<textElement>
					<font fontName="Courier New" size="7"/>
				</textElement>
				<text><![CDATA[SKU]]></text>
			</staticText>
			<staticText>
				<reportElement x="621" y="5" width="51" height="10"/>
				<textElement textAlignment="Right">
					<font fontName="Courier New" size="7"/>
				</textElement>
				<text><![CDATA[Ord Qty]]></text>
			</staticText>
			<staticText>
				<reportElement x="10" y="5" width="31" height="10"/>
				<textElement>
					<font fontName="Courier New" size="7"/>
				</textElement>
				<text><![CDATA[Line#:]]></text>
			</staticText>
			<staticText>
				<reportElement x="702" y="5" width="51" height="10"/>
				<textElement textAlignment="Right">
					<font fontName="Courier New" size="7"/>
				</textElement>
				<text><![CDATA[Shp Qty]]></text>
			</staticText>
			<line>
				<reportElement x="10" y="2" width="763" height="1"/>
			</line>
			<line>
				<reportElement x="10" y="18" width="763" height="1"/>
			</line>
		</band>
	</pageHeader>
	<columnHeader>
		<band splitType="Stretch"/>
	</columnHeader>
	<detail>
		<band splitType="Stretch"/>
	</detail>
	<columnFooter>
		<band splitType="Stretch"/>
	</columnFooter>
	<pageFooter>
		<band/>
	</pageFooter>
	<summary>
		<band height="18" splitType="Stretch">
			<textField evaluationTime="Group" evaluationGroup="Item_Lot_Line" pattern="0" isBlankWhenNull="true">
				<reportElement x="702" y="5" width="51" height="10"/>
				<textElement textAlignment="Right">
					<font fontName="Courier New" size="7"/>
				</textElement>
				<textFieldExpression class="java.lang.Double"><![CDATA[$V{compute_4}]]></textFieldExpression>
			</textField>
			<line>
				<reportElement x="10" y="15" width="763" height="2"/>
				<graphicElement>
					<pen lineStyle="Dashed"/>
				</graphicElement>
			</line>
			<staticText>
				<reportElement x="10" y="5" width="51" height="10"/>
				<textElement>
					<font fontName="Courier New" size="7"/>
				</textElement>
				<text><![CDATA[Totals . . :]]></text>
			</staticText>
			<textField evaluationTime="Group" evaluationGroup="Item_Lot_Line" pattern="0" isBlankWhenNull="true">
				<reportElement x="621" y="5" width="51" height="10"/>
				<textElement textAlignment="Right">
					<font fontName="Courier New" size="7"/>
				</textElement>
				<textFieldExpression class="java.lang.Double"><![CDATA[$V{compute_3}]]></textFieldExpression>
			</textField>
			<line>
				<reportElement x="10" y="0" width="763" height="2"/>
				<graphicElement>
					<pen lineStyle="Dashed"/>
				</graphicElement>
			</line>
		</band>
	</summary>
</jasperReport>
