使用子报表的返回值时,为什么从组中得到错误的总和?

时间:2016-09-05 16:05:28

标签: variables jasper-reports subreport

我有JasperReport的 sub_employment ,其子报告 sub_salary 我想从SubReport中总结返回值。

这样可行,但总和会忽略最后一条记录。

查看结果PDF

enter image description here

我从“评估时间”和“重置类型”

尝试了所有可能性

可变

<variable name="ACTUAL_HOURS" class="java.lang.Double" resetType="Column" calculation="Sum">
    <initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>
<variable name="ACTUAL_SALARY" class="java.lang.Double" resetType="Column" calculation="Sum">
    <initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>
<variable name="ACTUAL_SALARY_MONTH" class="java.lang.Double" resetType="Column" calculation="Sum">
    <initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>
<variable name="SUM_ACTUAL_HOURS" class="java.lang.Double" calculation="Sum">
    <variableExpression><![CDATA[$V{ACTUAL_HOURS}]]></variableExpression>
    <initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>
<variable name="SUM_ACTUAL_SALARY" class="java.lang.Double" calculation="Sum">
    <variableExpression><![CDATA[$V{ACTUAL_SALARY}]]></variableExpression>
    <initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>
<variable name="SUM_ACTUAL_SALARY_MONTH" class="java.lang.Double" calculation="Sum">
    <variableExpression><![CDATA[$V{ACTUAL_SALARY_MONTH}]]></variableExpression>
    <initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>
<variable name="ENTRY_DATE" class="java.util.Date" calculation="Lowest">
    <variableExpression><![CDATA[$F{entry_date}]]></variableExpression>
</variable>
<variable name="BUSINESS_FUNCTION" class="java.lang.String">
    <variableExpression><![CDATA[$F{business_function}]]></variableExpression>
</variable>

<band height="14">
        <printWhenExpression><![CDATA[$V{IS_VALID}]]></printWhenExpression>
        <subreport>
            <reportElement x="0" y="0" width="489" height="14" isRemoveLineWhenBlank="true" uuid="0b445260-50f1-4a00-bd12-b278d3d18ec1"/>
            <subreportParameter name="REPORT_RESOURCE_BUNDLE">
                <subreportParameterExpression><![CDATA[$P{REPORT_RESOURCE_BUNDLE}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="OWNER">
                <subreportParameterExpression><![CDATA[$P{OWNER}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="PRODUCT_NAME">
                <subreportParameterExpression><![CDATA[$P{PRODUCT_NAME}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="COPYRIGHT">
                <subreportParameterExpression><![CDATA[$P{COPYRIGHT}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="USER">
                <subreportParameterExpression><![CDATA[$P{USER}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="USER_FIRSTNAME">
                <subreportParameterExpression><![CDATA[$P{USER_FIRSTNAME}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="USER_LASTNAME">
                <subreportParameterExpression><![CDATA[$P{USER_LASTNAME}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="USER_EMAIL">
                <subreportParameterExpression><![CDATA[$P{USER_EMAIL}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="USER_NAME">
                <subreportParameterExpression><![CDATA[$P{USER_NAME}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="EMPLOYEE_ABBREVIATION">
                <subreportParameterExpression><![CDATA[$P{EMPLOYEE_ABBREVIATION}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="REPORT_NAME">
                <subreportParameterExpression><![CDATA[$P{REPORT_NAME}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="PRINT_DATE">
                <subreportParameterExpression><![CDATA[$P{PRINT_DATE}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="VALID_DATE">
                <subreportParameterExpression><![CDATA[$P{VALID_DATE}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="SHOW_EMPLOYMENT_TOTAL">
                <subreportParameterExpression><![CDATA[$P{SHOW_EMPLOYMENT_TOTAL}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="ROUND_SALARY_MONTH_SINGLE">
                <subreportParameterExpression><![CDATA[$P{ROUND_SALARY_MONTH_SINGLE}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="ROUND_SALARY_YEAR_TOTAL">
                <subreportParameterExpression><![CDATA[$P{ROUND_SALARY_YEAR_TOTAL}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="ROUND_SALARY_YEAR_SINGLE">
                <subreportParameterExpression><![CDATA[$P{ROUND_SALARY_YEAR_SINGLE}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="ROUND_SALARY_MONTH_TOTAL">
                <subreportParameterExpression><![CDATA[$P{ROUND_SALARY_MONTH_TOTAL}]]></subreportParameterExpression>
            </subreportParameter>
            <dataSourceExpression><![CDATA[$F{hr_employment\$hr_employee_salary}]]></dataSourceExpression>
            <returnValue subreportVariable="SUM_ACTUAL_SALARY_MONTH" toVariable="ACTUAL_SALARY_MONTH"/>
            <returnValue subreportVariable="SUM_ACTUAL_SALARY" toVariable="ACTUAL_SALARY"/>
            <returnValue subreportVariable="SUM_ACTUAL_HOURS" toVariable="ACTUAL_HOURS"/>
            <subreportExpression><![CDATA["sub_salary.jasper"]]></subreportExpression>
        </subreport>
    </band>

摘要

<summary>
    <band height="15">
        <textField>
            <reportElement x="0" y="1" width="150" height="14" uuid="79b0b8d3-e91d-4b24-81fe-b40c16934fd8"/>
            <textElement verticalAlignment="Middle">
                <font size="10"/>
            </textElement>
            <textFieldExpression><![CDATA["Total"]]></textFieldExpression>
        </textField>
        <textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
            <reportElement style="label-W-B-L" x="360" y="1" width="70" height="14" uuid="747fd18d-4afe-4343-bd66-ee8897309e59"/>
            <textElement textAlignment="Right" verticalAlignment="Middle">
                <font size="10"/>
                <paragraph leftIndent="2"/>
            </textElement>
            <textFieldExpression><![CDATA[$V{SUM_ACTUAL_SALARY_MONTH}]]></textFieldExpression>
        </textField>
        <textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
            <reportElement style="label-W-B-L" x="255" y="1" width="35" height="14" uuid="01a90af5-5fec-42e5-a69e-be21f034b51b"/>
            <textElement textAlignment="Right" verticalAlignment="Middle">
                <font size="10"/>
                <paragraph leftIndent="2"/>
            </textElement>
            <textFieldExpression><![CDATA[$V{SUM_ACTUAL_HOURS}]]></textFieldExpression>
        </textField>
        <textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
            <reportElement style="label-W-B-L" x="290" y="1" width="70" height="14" uuid="7dfc669e-3d34-4aa0-afc0-b9be20db5a7a"/>
            <textElement textAlignment="Right" verticalAlignment="Middle">
                <font size="10"/>
                <paragraph leftIndent="2"/>
            </textElement>
            <textFieldExpression><![CDATA[$V{SUM_ACTUAL_SALARY}]]></textFieldExpression>
        </textField>
        <line>
            <reportElement x="0" y="0" width="489" height="1" uuid="f7997151-3c20-4e44-b574-c07709f3b35f"/>
            <graphicElement>
                <pen lineWidth="1.0"/>
            </graphicElement>
        </line>
    </band>
</summary>

1 个答案:

答案 0 :(得分:3)

是的,这就是变量

计算
<variable name="SUM_ACTUAL_SALARY_MONTH" class="java.lang.Double" calculation="Sum">
    <variableExpression><![CDATA[$V{ACTUAL_SALARY_MONTH}]]></variableExpression>
    <initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>

之前完成从子报告返回$V{ACTUAL_SALARY_MONTH}

您有多种解决方案

textField

中添加最后一个值
    $V{SUM_ACTUAL_SALARY_MONTH}.doubleValue()+$V{ACTUAL_SALARY_MONTH}.doubleValue()

textField表达式为:

<textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
        <reportElement style="label-W-B-L" x="255" y="1" width="35" height="14" uuid="01a90af5-5fec-42e5-a69e-be21f034b51b"/>
        <textElement textAlignment="Right" verticalAlignment="Middle">
            <font size="10"/>
            <paragraph leftIndent="2"/>
        </textElement>
        <textFieldExpression><![CDATA[$V{SUM_ACTUAL_SALARY_MONTH}.doubleValue()+$V{ACTUAL_SALARY_MONTH}.doubleValue()]]></textFieldExpression>
</textField>

注意:子报表中的变量ACTUAL_SALARY_MONTH返回值不应该有计算和resetType。

<variable name="ACTUAL_SALARY_MONTH" class="java.lang.Double">
    <initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>

对返回值使用sum函数。

主变量需要有计算System

  

不进行任何计算,并且不评估表达式,即值   此变量将是其上设置的最后一个值。有用的存储   部分结果或计算的最终结果。

主变量

<variable name="SUM_ACTUAL_SALARY_MONTH" class="java.lang.Double" calculation="System"/>

子报告返回值

<returnValue subreportVariable="SUM_ACTUAL_SALARY" toVariable="SUM_ACTUAL_SALARY_MONTH" calculation="Sum"/>

注意:calculation="Sum"上使用returnValue的方式。