Jump to content
We've recently updated our Privacy Statement, available here ×

I got confused with the SUM method


alex.chen_2

Recommended Posts

Our project has a feature that calculating the annual leave balance and it is implementing by Jasper Report, but the author was left, so I hand on even though I never know Jasper Report at all.
Our customer reported that they have the report that when the balance of last year is 0.01, it will be not calculated into the balance of next year. but it will be calculated into the total balance. And we found that if the balance of last year is 0.5, it will be calculated into the balance of next year.

the report of user 1 is the issue on it, the report of  user 2 is which I found that is normal to calculate.

the report of user1:

snipaste_2020-09-21_15-15-25.png.b966a963f8ec629bd465760fff18314e.png

the report of user 2:

snipaste_2020-09-21_15-44-16.png.55afb2b00e721ed036391b3af3344fc8.png

and the jrxml:

<field name="type" class="java.lang.String">   <property name="com.jaspersoft.studio.field.label" value="type"/></field><field name="expiry" class="java.sql.Date">   <property name="com.jaspersoft.studio.field.label" value="expiry"/></field><field name="description" class="java.lang.String">   <property name="com.jaspersoft.studio.field.label" value="description"/></field><field name="days" class="java.math.BigDecimal">   <property name="com.jaspersoft.studio.field.label" value="days"/></field><variable name="total_days" class="java.math.BigDecimal" calculation="Sum">   <variableExpression><![CDATA[sUM($F{days} )]]></variableExpression></variable><variable name="grand_total_days" class="java.math.BigDecimal" calculation="Sum">   <variableExpression><![CDATA[sUM($F{days} )]]></variableExpression></variable><group name="GroupBalance">   <groupExpression><![CDATA[$F{type} + $F{expiry}]]></groupExpression>   <groupHeader>      <band height="17">         <staticText>            <reportElement mode="Opaque" x="0" y="2" width="100" height="15" backcolor="#C7CFD9" uuid="e2ba4ba6-cd52-47e9-941b-a34a61b13136"/>            <box>               <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>               <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>               <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>               <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>            </box>            <textElement textAlignment="Center" verticalAlignment="Middle">               <font isBold="true"/>            </textElement>            <text><![CDATA[Expiry Date]]></text>         </staticText>         <textField pattern="yyyy-MM-dd" isBlankWhenNull="true">            <reportElement x="100" y="2" width="110" height="15" uuid="77a0d59b-f8e2-4b46-93ff-549ea7832c1d"/>            <box>               <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>               <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>               <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>               <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>            </box>            <textElement textAlignment="Left" verticalAlignment="Middle">               <paragraph leftIndent="5"/>            </textElement>            <textFieldExpression><![CDATA[$F{expiry}]]></textFieldExpression>         </textField>         <staticText>            <reportElement mode="Opaque" x="435" y="2" width="60" height="15" backcolor="#C7CFD9" uuid="1c7568e1-33b8-47f3-92e0-278bccff6bc9"/>            <box>               <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>               <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>               <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>               <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>            </box>            <textElement textAlignment="Center" verticalAlignment="Middle"/>            <text><![CDATA[Entitled]]></text>         </staticText>         <staticText>            <reportElement mode="Opaque" x="495" y="2" width="60" height="15" backcolor="#C7CFD9" uuid="6e8d2b7d-b345-47cb-b2fc-c2be23b2acc9"/>            <box>               <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>               <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>               <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>               <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>            </box>            <textElement textAlignment="Center" verticalAlignment="Middle"/>            <text><![CDATA[Taken]]></text>         </staticText>      </band>   </groupHeader>   <groupFooter>      <band height="30">         <staticText>            <reportElement mode="Opaque" x="0" y="0" width="100" height="15" backcolor="#9FA4AB" uuid="be23ccbd-6daa-4d5d-9a15-9b8d099ae884"/>            <textElement textAlignment="Center" verticalAlignment="Middle">               <font isBold="true"/>            </textElement>            <text><![CDATA[Net]]></text>         </staticText>         <frame>            <reportElement x="0" y="0" width="555" height="15" uuid="11b1a535-7008-46b1-ab4d-6fb877fc8382"/>            <box>               <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>               <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>               <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>               <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>            </box>            <textField>               <reportElement x="435" y="0" width="60" height="15" uuid="be3ed2a6-42c6-48de-83b4-f35137458d4e"/>               <box>                  <pen lineWidth="1.5" lineStyle="Double"/>                  <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>                  <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>                  <bottomPen lineWidth="2.5" lineStyle="Double" lineColor="#000000"/>                  <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>               </box>               <textElement textAlignment="Right" verticalAlignment="Middle" markup="none">                  <font isBold="true"/>                  <paragraph rightIndent="5"/>               </textElement>               <textFieldExpression><![CDATA[$V{total_days}]]></textFieldExpression>            </textField>         </frame>      </band>      <band height="10"/>   </groupFooter></group><background>   <band splitType="Stretch"/></background><title>   <band height="80" splitType="Stretch">      <textField>         <reportElement mode="Opaque" x="87" y="0" width="380" height="20" uuid="3f9094a7-9450-48dd-af78-a5ec2359975f"/>         <textElement textAlignment="Center">            <font size="14" isBold="true"/>         </textElement>         <textFieldExpression><![CDATA[$P{ytd} == null ? java.lang.String.format("Annual Leave Balance Status in %d",  $P{year}) : java.lang.String.format("Annual Leave Balance Status YTD %tF", $P{ytd})]]></textFieldExpression>      </textField>      <staticText>         <reportElement mode="Transparent" x="0" y="23" width="100" height="15" backcolor="#9FA4AB" uuid="b0410eb3-0aeb-4b5f-bd10-0ececc2b3dcd"/>         <box>            <bottomPen lineWidth="1.0"/>         </box>         <textElement textAlignment="Left" verticalAlignment="Middle">            <font isBold="true"/>         </textElement>         <text><![CDATA[Employee Name:]]></text>      </staticText>      <textField>         <reportElement x="100" y="23" width="180" height="15" uuid="f7a5c9cd-4f0f-46ed-ba0e-50b5e362fce6"/>         <box>            <bottomPen lineWidth="1.0"/>         </box>         <textElement textAlignment="Left" verticalAlignment="Middle">            <font fontName="Arial Unicode MS" size="10" pdfEncoding="Identity-H"/>            <paragraph leftIndent="5"/>         </textElement>         <textFieldExpression><![CDATA[$P{displayName}]]></textFieldExpression>      </textField>      <staticText>         <reportElement mode="Transparent" x="0" y="39" width="101" height="15" backcolor="#9FA4AB" uuid="c0cb18e0-440e-4afa-9d5a-9eb35f258ba7"/>         <box>            <bottomPen lineWidth="1.0"/>         </box>         <textElement textAlignment="Left" verticalAlignment="Middle">            <font isBold="true"/>         </textElement>         <text><![CDATA[balance:]]></text>      </staticText>      <textField evaluationTime="Report" isBlankWhenNull="true">         <reportElement x="101" y="39" width="119" height="15" uuid="b8647ffb-44b0-4a41-be0e-22883e0104ea"/>         <box>            <bottomPen lineWidth="1.0"/>         </box>         <textElement textAlignment="Left" verticalAlignment="Middle">            <paragraph leftIndent="5" rightIndent="0"/>         </textElement>         <textFieldExpression><![CDATA[$V{grand_total_days} == null? 0 : $V{grand_total_days}]]></textFieldExpression>      </textField>      <staticText>         <reportElement x="220" y="39" width="60" height="15" uuid="755fe4c2-6307-4a39-b5d1-61f683e3d30d"/>         <box>            <bottomPen lineWidth="1.0"/>         </box>         <textElement textAlignment="Left" verticalAlignment="Middle"/>         <text><![CDATA[days]]></text>      </staticText>      <staticText>         <reportElement mode="Opaque" x="0" y="65" width="555" height="15" backcolor="#C7CFD9" uuid="d6447241-4621-43f9-8ec7-62b0178f69a9"/>         <textElement textAlignment="Center" verticalAlignment="Middle">            <font isBold="true"/>            <paragraph leftIndent="5"/>         </textElement>         <text><![CDATA[Details]]></text>      </staticText>   </band></title><detail>   <band height="17" splitType="Stretch">      <textField isStretchWithOverflow="true" isBlankWhenNull="true">         <reportElement x="100" y="0" width="335" height="15" uuid="d0c09db8-10b9-4584-9019-e6f48bf6f677"/>         <box>            <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>            <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>            <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>            <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>         </box>         <textElement verticalAlignment="Middle">            <font fontName="Arial Unicode MS" size="10" pdfEncoding="Identity-H"/>            <paragraph lineSpacing="Single" leftIndent="5"/>         </textElement>         <textFieldExpression><![CDATA[$F{description}]]></textFieldExpression>      </textField>      <textField>         <reportElement x="435" y="0" width="60" height="15" isRemoveLineWhenBlank="true" uuid="b828be7f-fcf2-4f9a-8ee2-96991e23b872">            <printWhenExpression><![CDATA[$F{days}.compareTo( java.math.BigDecimal.valueOf(0) )==1]]></printWhenExpression>         </reportElement>         <box>            <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>            <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>            <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>            <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>         </box>         <textElement textAlignment="Right" verticalAlignment="Middle">            <paragraph rightIndent="5"/>         </textElement>         <textFieldExpression><![CDATA[new java.math.BigDecimal($F{days}.toString())]]></textFieldExpression>      </textField>      <textField>         <reportElement x="495" y="0" width="60" height="15" uuid="00c649fe-6165-4356-8145-0ed2b9c16bf6">            <printWhenExpression><![CDATA[$F{days}.compareTo( java.math.BigDecimal.valueOf(0) )==-1]]></printWhenExpression>         </reportElement>         <box>            <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>            <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>            <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>            <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>         </box>         <textElement textAlignment="Right" verticalAlignment="Middle">            <paragraph rightIndent="5"/>         </textElement>         <textFieldExpression><![CDATA[new java.math.BigDecimal($F{days}.toString())]]></textFieldExpression>      </textField>   </band></detail>

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted Images

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...