From 6630a0e6c77808763e6a095c3fda8a6cc8af4795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Henke?= Date: Wed, 12 Jan 2022 10:47:26 +0100 Subject: [PATCH] summarizing --- build.gradle | 2 +- .../timetrack/modules/done/DoneModel.java | 46 +++++++++++++++++++ src/main/webapp/pages/done/init.xhtml | 5 ++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 08e40f0..0f763a4 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'war' apply plugin: 'eclipse' group = 'jottyfan' -version = '1.1.8' +version = '1.1.9' description = """timetrack""" diff --git a/src/main/java/de/jottyfan/timetrack/modules/done/DoneModel.java b/src/main/java/de/jottyfan/timetrack/modules/done/DoneModel.java index 9c3c7b6..e9a3526 100644 --- a/src/main/java/de/jottyfan/timetrack/modules/done/DoneModel.java +++ b/src/main/java/de/jottyfan/timetrack/modules/done/DoneModel.java @@ -11,7 +11,10 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import java.util.TimeZone; import javax.enterprise.context.SessionScoped; @@ -121,6 +124,49 @@ public class DoneModel implements Model, Serializable { times.add(new TimeBean(defineNewTime(currentHour, currentMinute + 30), "link")); times.add(new TimeBean(defineNewTime(currentHour, currentMinute + 45), "link")); } + + /** + * summarizes the billings in horizon2020 notation + * + * @return the billings summary + */ + public String getSummaryBilling() { + Map map = new HashMap<>(); + for (DailySummaryBean bean : getAllJobs()) { + String shortcut = bean.getBillingShortcut(); + Double time = bean.getDurationHours(); + Double sumTime = map.get(shortcut); + sumTime = sumTime == null ? time : (sumTime + time); + map.put(shortcut, sumTime); + } + StringBuilder buf = new StringBuilder(); + boolean first = true; + for (Entry entry : map.entrySet()) { + buf.append(first ? "" : ", "); + String key = entry.getKey(); + if (key == null || key.equals("null")) { + buf.append("$ "); + } else { + buf.append(entry.getKey()).append(" "); + } + buf.append("(").append(entry.getValue()).append(")"); + first = false; + } + return buf.toString(); + } + + /** + * summarizes the time of a days work in commaseparated values + * + * @return the summarized times + */ + public String getSummaryTime() { + Double sum = 0d; + for (DailySummaryBean bean : getAllJobs()) { + sum += bean.getDurationHours(); + } + return sum.toString(); + } private Calendar getCurrentTime() { return new GregorianCalendar(TimeZone.getTimeZone("Europe/Berlin")); diff --git a/src/main/webapp/pages/done/init.xhtml b/src/main/webapp/pages/done/init.xhtml index aa74de7..71673e9 100644 --- a/src/main/webapp/pages/done/init.xhtml +++ b/src/main/webapp/pages/done/init.xhtml @@ -84,6 +84,11 @@ + + + + +