Skip to content

Commit

Permalink
[26669] Statusänderungen aktiver User wird eingetragen (#737)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daksic28 authored Nov 6, 2024
1 parent f1b224c commit 446cf57
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
13 changes: 11 additions & 2 deletions bundles/ch.elexis.core.data/src/ch/elexis/data/Rechnung.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -33,10 +34,12 @@
import ch.elexis.core.data.service.CoreModelServiceHolder;
import ch.elexis.core.data.service.LocalLockServiceHolder;
import ch.elexis.core.events.MessageEvent;
import ch.elexis.core.model.IContact;
import ch.elexis.core.model.IInvoice;
import ch.elexis.core.model.InvoiceState;
import ch.elexis.core.services.IInvoiceService;
import ch.elexis.core.services.holder.ConfigServiceHolder;
import ch.elexis.core.services.holder.ContextServiceHolder;
import ch.rgw.tools.JdbcLink;
import ch.rgw.tools.JdbcLink.Stm;
import ch.rgw.tools.Money;
Expand Down Expand Up @@ -83,6 +86,7 @@ public class Rechnung extends PersistentObject {
public static final String OUTPUT = "Ausgegeben";
public static final String REMARKS = "Bemerkungen";
public static final String INVOICE_CORRECTION = "Rechnungskorrektur";
public static final String MANDATOR = "Mandator";

static {
addMapping(TABLENAME, BILL_NUMBER, CASE_ID, MANDATOR_ID, "RnDatum=S:D:RnDatum", BILL_STATE,
Expand Down Expand Up @@ -597,9 +601,14 @@ public void setTemporaryState(final int temporaryState, TimeTool expiryDate) {
* @param state as defined by {@link InvoiceState#numericValue()}
*/
public void setStatus(final InvoiceState state) {
set(BILL_STATE, Integer.toString(state.getState()));
set(BILL_STATE, String.valueOf(state.getState()));
set(BILL_STATE_DATE, new TimeTool().toString(TimeTool.DATE_GER));
addTrace(STATUS_CHANGED, Integer.toString(state.getState()));
addTrace(STATUS_CHANGED, String.valueOf(state.getState()));
ContextServiceHolder.get().getActiveUserContact().ifPresent(activeUserContact -> {
String userDescription = String.format("%s %s", activeUserContact.getDescription1(), //$NON-NLS-1$
activeUserContact.getDescription2());
addTrace(MANDATOR, userDescription);
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import ch.elexis.core.model.service.holder.StoreToStringServiceHolder;
import ch.elexis.core.model.util.internal.ModelUtil;
import ch.elexis.core.services.INamedQuery;
import ch.elexis.core.services.holder.ContextServiceHolder;
import ch.rgw.tools.Money;
import ch.rgw.tools.StringTool;
import ch.rgw.tools.TimeTool;
Expand Down Expand Up @@ -54,6 +55,11 @@ public void setState(InvoiceState value) {
setStateDate(LocalDate.now());
getEntityMarkDirty().setState(value);
addTrace(InvoiceConstants.STATUS_CHANGED, Integer.toString(value.numericValue()));
ContextServiceHolder.get().getActiveUserContact().ifPresent(activeUserContact -> {
String userDescription = String.format("%s %s", activeUserContact.getDescription1(), //$NON-NLS-1$
activeUserContact.getDescription2());
addTrace(InvoiceConstants.MANDATOR, userDescription);
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import static ch.elexis.core.ui.constants.UiPreferenceConstants.USERSETTINGS2_EXPANDABLE_COMPOSITES;
import static ch.elexis.core.ui.constants.UiPreferenceConstants.USERSETTINGS2_EXPANDABLE_COMPOSITES_STATES;

import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -824,13 +826,10 @@ public void display() {
+ ((adressat != null) ? adressat.getLabel() : StringUtils.EMPTY));
form.setText(actRn.getLabel());
List<String> trace = actRn.getTrace(Rechnung.STATUS_CHANGED);
for (String s : trace) {
String[] stm = s.split("\\s*:\\s"); //$NON-NLS-1$
StringBuilder sb = new StringBuilder();
sb.append(stm[0]).append(" : ").append( //$NON-NLS-1$
InvoiceState.fromState(Integer.parseInt(stm[1])).getLocaleText());
lbJournal.add(sb.toString());
}
List<String> mandatorTrace = actRn.getTrace(Rechnung.MANDATOR);
List<String> combinedTrace = combineAndSortTrace(trace, mandatorTrace);
combinedTrace.forEach(lbJournal::add);

if (journalSelection != null && journalSelection.length > 0) {
for (int i = 0; i < lbJournal.getItemCount(); i++) {
for (String selection : journalSelection) {
Expand Down Expand Up @@ -890,4 +889,39 @@ public void display() {
}
}

private List<String> combineAndSortTrace(List<String> trace, List<String> mandatorTrace) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy, HH:mm:ss"); //$NON-NLS-1$
return trace.stream().map(statusEntry -> {
// Split the status entry into a timestamp and a status code.
String[] stm = statusEntry.split("\\s*:\\s", 2); //$NON-NLS-1$
String timestampString = stm[0]; // Extract the timestamp part.
String statusText = timestampString + " : " //$NON-NLS-1$
+ InvoiceState.fromState(Integer.parseInt(stm[1])).getLocaleText();
// Find the corresponding mandator entry that matches the timestamp.
String mandatorLabel = mandatorTrace.stream().filter(m -> m.contains(timestampString)).findFirst()
.map(m -> {
// Remove the matched mandator entry from the list to avoid reuse.
mandatorTrace.remove(m);
// Extract the label text from the mandator entry if it contains a colon.
if (m.contains(":")) { //$NON-NLS-1$
String[] parts = m.split(":"); //$NON-NLS-1$
return parts.length > 1 ? parts[parts.length - 1].trim() : ""; //$NON-NLS-1$
}
return ""; //$NON-NLS-1$
}).orElse(""); //$NON-NLS-1$
// Return the status text with or without the mandator label.
return mandatorLabel.isEmpty() ? statusText : statusText + " / " + mandatorLabel; //$NON-NLS-1$
}).sorted((entry1, entry2) -> {
try {
// Parse the dates from the entries for sorting.
Date date1 = dateFormat.parse(entry1.split(" : ")[0]); //$NON-NLS-1$
Date date2 = dateFormat.parse(entry2.split(" : ")[0]); //$NON-NLS-1$
return date1.compareTo(date2);
} catch (Exception e) {
LoggerFactory.getLogger(getClass()).error("Error parsing dates for sorting: {}", e.getMessage(), e); //$NON-NLS-1$
return 0;
}
}).collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public class InvoiceConstants {
public static final String OUTPUT = "Ausgegeben";
public static final String REMARKS = "Bemerkungen";
public static final String INVOICE_CORRECTION = "Rechnungskorrektur";
public static final String MANDATOR = "Mandator";
}

0 comments on commit 446cf57

Please sign in to comment.