0

This is my code for Grandtotal but it won't have grandtotal ?

<?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="Warehouse" language="groovy" pageWidth="612" pageHeight="792" columnWidth="572" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <queryString language="SQL">
        <![CDATA[select * from warehouse]]>
    </queryString>
    <field name="PlantUnit" class="java.lang.String"/>
    <field name="Description" class="java.lang.String"/>
    <field name="Size" class="java.lang.String"/>
    <field name="Qty" class="java.lang.String"/>
    <field name="Unit" class="java.lang.String"/>
    <field name="Unit Price" class="java.lang.String"/>
    <field name="Amount" class="java.lang.String"/>
    <variable name="TotalAmount" class="java.lang.String" calculation="Sum">
        <variableExpression><![CDATA[$F{Amount}]]></variableExpression>
    </variable>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="40" splitType="Stretch">
            <staticText>
                <reportElement x="100" y="0" width="409" height="40"/>
                <textElement textAlignment="Center">
                    <font fontName="Times New Roman" size="34" isBold="true"/>
                </textElement>
                <text><![CDATA[WAREHOUSE]]></text>
            </staticText>
        </band>
    </title>
    <pageHeader>
        <band height="15" splitType="Stretch">
            <textField pattern="MMMMM dd, yyyy">
                <reportElement x="457" y="0" width="116" height="15"/>
                <textElement textAlignment="Right">
                    <font fontName="Times New Roman" size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[new SimpleDateFormat("MMMM dd, yyyy").format(new java.util.Date())]]></textFieldExpression>
            </textField>
        </band>
    </pageHeader>
    <columnHeader>
        <band height="12" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="50" height="12"/>
                <textElement textAlignment="Center">
                    <font fontName="Times New Roman" size="10" isBold="true"/>
                </textElement>
                <text><![CDATA[PU]]></text>
            </staticText>
            <staticText>
                <reportElement x="50" y="0" width="184" height="12"/>
                <textElement textAlignment="Center">
                    <font fontName="Times New Roman" size="10" isBold="true"/>
                </textElement>
                <text><![CDATA[DESCRIPTION]]></text>
            </staticText>
            <staticText>
                <reportElement x="234" y="0" width="150" height="12"/>
                <textElement textAlignment="Center">
                    <font fontName="Times New Roman" size="10" isBold="true"/>
                </textElement>
                <text><![CDATA[SIZE]]></text>
            </staticText>
            <staticText>
                <reportElement x="384" y="0" width="50" height="12"/>
                <textElement textAlignment="Center">
                    <font fontName="Times New Roman" size="10" isBold="true"/>
                </textElement>
                <text><![CDATA[QTY]]></text>
            </staticText>
            <staticText>
                <reportElement x="434" y="0" width="40" height="12"/>
                <textElement textAlignment="Center">
                    <font fontName="Times New Roman" size="10" isBold="true"/>
                </textElement>
                <text><![CDATA[UNIT]]></text>
            </staticText>
            <staticText>
                <reportElement x="473" y="0" width="50" height="12"/>
                <textElement textAlignment="Center">
                    <font fontName="Times New Roman" isBold="true"/>
                </textElement>
                <text><![CDATA[COST]]></text>
            </staticText>
            <staticText>
                <reportElement x="523" y="0" width="50" height="12"/>
                <textElement textAlignment="Center">
                    <font fontName="Times New Roman" isBold="true"/>
                </textElement>
                <text><![CDATA[AMOUNT]]></text>
            </staticText>
            <rectangle>
                <reportElement mode="Transparent" x="0" y="0" width="50" height="12"/>
            </rectangle>
            <rectangle>
                <reportElement mode="Transparent" x="50" y="0" width="184" height="12"/>
            </rectangle>
            <rectangle>
                <reportElement mode="Transparent" x="234" y="0" width="150" height="12"/>
            </rectangle>
            <rectangle>
                <reportElement mode="Transparent" x="384" y="0" width="50" height="12"/>
            </rectangle>
            <rectangle>
                <reportElement mode="Transparent" x="434" y="0" width="40" height="12"/>
            </rectangle>
            <rectangle>
                <reportElement mode="Transparent" x="474" y="0" width="49" height="12"/>
            </rectangle>
            <rectangle>
                <reportElement mode="Transparent" x="523" y="0" width="50" height="12"/>
            </rectangle>
        </band>
    </columnHeader>
    <detail>
        <band height="12" splitType="Stretch">
            <textField>
                <reportElement x="0" y="0" width="50" height="12"/>
                <textElement textAlignment="Center">
                    <font fontName="Times New Roman" size="10"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{PlantUnit}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="50" y="0" width="184" height="12"/>
                <textElement textAlignment="Center">
                    <font fontName="Times New Roman" size="10"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{Description}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="234" y="0" width="150" height="12"/>
                <textElement textAlignment="Center">
                    <font fontName="Times New Roman" size="10"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{Size}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="384" y="0" width="50" height="12"/>
                <textElement textAlignment="Center">
                    <font fontName="Times New Roman" size="10"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{Qty}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="433" y="0" width="40" height="12"/>
                <textElement textAlignment="Center">
                    <font fontName="Times New Roman" size="10"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{Unit}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="473" y="0" width="50" height="12"/>
                <textElement textAlignment="Center">
                    <font fontName="Times New Roman"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{Unit Price}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="523" y="0" width="50" height="12"/>
                <textElement textAlignment="Center">
                    <font fontName="Times New Roman"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{Amount}]]></textFieldExpression>
            </textField>
            <rectangle>
                <reportElement mode="Transparent" x="0" y="0" width="50" height="12"/>
            </rectangle>
            <rectangle>
                <reportElement mode="Transparent" x="50" y="0" width="184" height="12"/>
            </rectangle>
            <rectangle>
                <reportElement mode="Transparent" x="234" y="0" width="150" height="12"/>
            </rectangle>
            <rectangle>
                <reportElement mode="Transparent" x="384" y="0" width="50" height="12"/>
            </rectangle>
            <rectangle>
                <reportElement mode="Transparent" x="434" y="0" width="40" height="12"/>
            </rectangle>
            <rectangle>
                <reportElement mode="Transparent" x="474" y="0" width="49" height="12"/>
            </rectangle>
            <rectangle>
                <reportElement mode="Transparent" x="523" y="0" width="50" height="12"/>
            </rectangle>
        </band>
    </detail>
    <columnFooter>
        <band height="12" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="100" height="12"/>
                <textElement>
                    <font fontName="Times New Roman" isBold="true"/>
                </textElement>
                <text><![CDATA[Total Amount]]></text>
            </staticText>
            <textField isBlankWhenNull="true">
                <reportElement x="473" y="0" width="100" height="12"/>
                <textElement textAlignment="Right">
                    <font fontName="Times New Roman"/>
                </textElement>
                <textFieldExpression><![CDATA[$V{TotalAmount}]]></textFieldExpression>
            </textField>
        </band>
    </columnFooter>
    <pageFooter>
        <band height="15" splitType="Stretch">
            <textField>
                <reportElement x="491" y="0" width="56" height="15"/>
                <textElement textAlignment="Right">
                    <font fontName="Times New Roman" size="12"/>
                </textElement>
                <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report">
                <reportElement x="547" y="0" width="25" height="15"/>
                <textElement>
                    <font fontName="Times New Roman" size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
        </band>
    </pageFooter>
    <summary>
        <band height="11" splitType="Stretch"/>
    </summary>
</jasperReport>

Further assistance would be appreciated.

Alex K
  • 22,315
  • 19
  • 108
  • 236
Mac Ching
  • 13
  • 3
  • thx Darshan Lila for editing it – Mac Ching Sep 23 '14 at 05:38
  • Possible duplicate of [How to sum all values in a column in Jaspersoft iReport Designer?](http://stackoverflow.com/questions/13550514/how-to-sum-all-values-in-a-column-in-jaspersoft-ireport-designer) – Alex K Jul 15 '16 at 19:51

1 Answers1

0

You have taken the amount field as string.

<field name="Amount" class="java.lang.String"/>

And your variable type is also string.

<variable name="TotalAmount" class="java.lang.String" calculation="Sum">
        <variableExpression><![CDATA[$F{Amount}]]></variableExpression>
    </variable>

You need to have Amount and TotalAmount variables to be Integer in order for jasper report to be able to calculate the sum. Hence change it to following:

<field name="Amount" class="java.lang.Integer"/>

and

<variable name="TotalAmount" class="java.lang.Integer" calculation="Sum">
        <variableExpression><![CDATA[$F{Amount}]]></variableExpression>
    </variable>

Note : If Amount is already String then convert it to Integer and then feed to jasper report.

Darshan Lila
  • 5,772
  • 2
  • 24
  • 34
  • i tried that sir but there was an error net.sf.jasperrepots.engine.fill.JRexpressionEVALexception:Error evaluating expression: Source Text : $F{Amount} – Mac Ching Sep 23 '14 at 05:51