l37sedoc
(Lloyd S)
April 18, 2021, 1:16am
#1
Hi,
I have this code:
@Subscribe
public void onAfterShow(AfterShowEvent event) {
Map<Object, Object> results = payrollItemsTable.getAggregationResults();
Object totaleNormalebelastingId = payrollItemsTable.getColumn("totaleNormalebelasting").getId();
totaleWerknemersBelasting.setValue((BigDecimal) results.get(totaleNormalebelastingId));
Object totaleSolidariteitsbelastingId = payrollItemsTable.getColumn("totaleSolidariteitsbelasting").getId();
totaleWerknemersSolBelasting.setValue((BigDecimal) results.get(totaleSolidariteitsbelastingId));
Object totaleAovId = payrollItemsTable.getColumn("totaleAov").getId();
totaleAov.setValue((BigDecimal) results.get(totaleAovId));
payrollItemsTable.getColumn("totaleAov").getId();
teBetalen.setValue(((BigDecimal) results.get(totaleNormalebelastingId)).add((BigDecimal) totaleSolidariteitsbelastingId).add((BigDecimal) totaleAovId));
}
The aggregated values are presented nicely. What i want to do now is to have a total of the three aggregated values. I tried the last part of the code in many ways but i can’t seem to get it to work.
teBetalen.setValue(((BigDecimal) results.get(totaleNormalebelastingId)).add((BigDecimal) totaleSolidariteitsbelastingId).add((BigDecimal) totaleAovId));
}
When i add another ID to the first ID i get the a casting to Bigdecimal error.
Can you please help.
Regards,
Lloyd
i.lovtsova
(Irina Lovtsova)
April 20, 2021, 6:52am
#3
Hi!
It seems you forgot to call results.get()
for the second and third id.
Try to use this code:
total.setValue(
((BigDecimal) results.get(aaId))
.add((BigDecimal) results.get(bbId))
.add((BigDecimal) results.get(ccId))
);
Regards,
Irina
l37sedoc
(Lloyd S)
April 20, 2021, 7:16am
#5
Many thanks Irina, works perfectly.
Regards Lloyd
l37sedoc
(Lloyd S)
July 5, 2021, 12:55am
#6
Hi Irina,
I just noticed something. When i select a record the “TotalField” isn’t populated (not calculated). If i filter the record it works fine. I’ve attached a screenshot.
this is the code:
@Subscribe
public void onAfterShow(AfterShowEvent event) {
Map<Object, Object> results = payrollItemsTable.getAggregationResults();
Object totaleNormalebelastingId = payrollItemsTable.getColumn("totaleNormalebelasting").getId();
totaleNormalebelasting.setValue((BigDecimal) results.get(totaleNormalebelastingId));
Object totaleSolidariteitsbelastingId = payrollItemsTable.getColumn("totaleSolidariteitsbelasting").getId();
totaleSolidariteitsbelasting.setValue((BigDecimal) results.get(totaleSolidariteitsbelastingId));
Object totaleAovId = payrollItemsTable.getColumn("totaleAov").getId();
totaleAov.setValue((BigDecimal) results.get(totaleAovId));
Object pensioenId = payrollItemsTable.getColumn("pensioen").getId();
pensioen.setValue((BigDecimal) results.get(pensioenId));
Object pensioenWgId = payrollItemsTable.getColumn("pensioenWg").getId();
pensioenWg.setValue((BigDecimal) results.get(pensioenWgId));
teBetalen.setValue (
((BigDecimal) results.get(totaleNormalebelastingId))
.add((BigDecimal) results.get(totaleSolidariteitsbelastingId))
.add((BigDecimal) results.get(totaleAovId))
);
}
@Install(to = "filter", subject = "afterFilterAppliedHandler")
private void filterAfterFilterAppliedHandler() {
Map<Object, Object> results = payrollItemsTable.getAggregationResults();
Object aggrResult1 = payrollItemsTable.getColumn("totaleNormalebelasting").getId();
totaleNormalebelasting.setValue((BigDecimal) results.get(aggrResult1));
Object aggrResult2 = payrollItemsTable.getColumn("totaleSolidariteitsbelasting").getId();
totaleSolidariteitsbelasting.setValue((BigDecimal) results.get(aggrResult2));
Object aggrResult3 = payrollItemsTable.getColumn("totaleAov").getId();
totaleAov.setValue((BigDecimal) results.get(aggrResult3));
Object aggrResult4 = payrollItemsTable.getColumn("pensioen").getId();
pensioen.setValue((BigDecimal) results.get(aggrResult4));
Object aggrResult5 = payrollItemsTable.getColumn("pensioenWg").getId();
pensioenWg.setValue((BigDecimal) results.get(aggrResult5));
teBetalen.setValue (
((BigDecimal) results.get(aggrResult1))
.add((BigDecimal) results.get(aggrResult2))
.add((BigDecimal) results.get(aggrResult3))
);
}
}
Am i missing something?
Regards
LS
l37sedoc
(Lloyd S)
July 7, 2021, 12:06pm
#7
Solved!
After some more research and trial and error. I came up with this code which works fine for what i want to do.
@Subscribe (“payrollItemsTable”)
public void onPayrollItemsTableSelection(Table.SelectionEvent event) {
event.getSource().getSingleSelected();
assert getItem() != null;
BigDecimal teBetalen = getItem()
.getTotaleNormalebelasting()
.add(getItem().getTotaleSolidariteitsbelasting()).add(getItem().getTotaleAov());
getItem().setTeBetalen(teBetalen);
}
private PayrollItem getItem() {
return payrollItemsTable.getSingleSelected();
}