+
| Datum | +Leistungsbezeichnung | +Stunden | +
|---|---|---|
|
+ |
+
+ |
+
+ |
+
| + | + Summe: + | +
+ |
+
| + | + Plan: + | +
+ |
+
| + | + Prozent: + | +
+ |
+
+
| Datum | +Leistungsbezeichnung | +Stunden | +
|---|---|---|
|
+ |
+
+ |
+
+ |
+
| + | + Summe: + | +
+ |
+
| + | + Plan: + | +
+ |
+
| + | + Prozent: + | +
+ |
+
+ *
+ chartCfg = {
+ type: 'bar',
+ data: {
+ datasets: [{
+ data: [20, 10],
+ }],
+ labels: ['1', '2']
+ }
+ }
+ *
+ *
+ *
+ * @return
+ */
+ private String buildHoursChart() {
+
+ accumulateHoursByWeek();
+
+ // Step 2: Prepare the JSON structure and ensure we have all weeks from earliest
+ // to latest
+ JsonArrayBuilder dataBuilderTotal = Json.createArrayBuilder();
+ JsonArrayBuilder labelsBuilder = Json.createArrayBuilder();
+
+ Calendar startCal = Calendar.getInstance();
+ startCal.set(Calendar.YEAR, earliestWeek / 100);
+ startCal.set(Calendar.WEEK_OF_YEAR, earliestWeek % 100);
+
+ Calendar endCal = Calendar.getInstance();
+ endCal.set(Calendar.YEAR, latestWeek / 100);
+ endCal.set(Calendar.WEEK_OF_YEAR, latestWeek % 100);
+
+ while (!startCal.after(endCal)) {
+ int weekNumber = startCal.get(Calendar.WEEK_OF_YEAR);
+ int year = startCal.get(Calendar.YEAR);
+ int yearWeek = year * 100 + weekNumber;
+
+ // Add the saldo for the week or 0.0 if no data
+ RequirementData requirementData = hoursByWeek.getOrDefault(yearWeek, new RequirementData());
+ dataBuilderTotal.add(requirementData.total);
+
+ labelsBuilder.add(weekNumber + "/" + year); // Label as 'week/year'
+
+ // Move to the next week
+ startCal.add(Calendar.WEEK_OF_YEAR, 1);
+ }
+
+ // Step 3: Prepare the JSON structure
+ JsonObjectBuilder jsonBuilder = Json.createObjectBuilder()
+ .add("type", "bar")
+ .add("data", Json.createObjectBuilder()
+ .add("datasets", Json.createArrayBuilder()
+
+ .add(Json.createObjectBuilder() // Third dataset for 'total'
+ .add("label", "Total")
+ .add("backgroundColor", "#4bc0c0")
+ .add("borderWidth", 1)
+ .add("data", dataBuilderTotal)))
+
+ .add("labels", labelsBuilder));
+
+ // Step 4: Return the JSON structure as a string
+ JsonObject chartCfg = jsonBuilder.build();
+ return chartCfg.toString();
+ }
+
+ /**
+ * Helper method to hold zoll and eust totals in an object. Needed to build
+ * totals per week.
+ */
+ class RequirementData {
+ double total = 0.0;
+ String status = "";
+
+ public RequirementData() {
+ // default constructor
+ }
+
+ /**
+ * Adds new stunden
+ *
+ * @param totalNew
+ * @param statusNew
+ */
+ public void add(double totalNew, String statusNew) {
+
+ total = total + totalNew;
+ status = statusNew;
+ }
+
+ }
+
+ public static double round(double value) {
+ BigDecimal bd = BigDecimal.valueOf(value);
+ bd = bd.setScale(2, RoundingMode.HALF_UP);
+ return bd.doubleValue();
+ }
+
+ /**
+ * converts the Map List of a workitem into a List of ItemCollectons
+ */
+ public static List