From eb0154d0d1f69981f908336d87db21e0c0ea389c Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Thu, 3 Aug 2023 12:05:05 +0200 Subject: [PATCH] debitor statistik --- .../CargosoftController.java | 2 +- .../DebitorStatistikController.java | 80 ++++++++++++++----- .../DebitorStatistikData.java | 10 +-- .../alexanderlogistics/OPListController.java | 5 +- .../src/main/webapp/pages/dbtr-stats.xhtml | 61 +++----------- 5 files changed, 81 insertions(+), 77 deletions(-) diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/CargosoftController.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/CargosoftController.java index 7358320..6c0f461 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/CargosoftController.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/CargosoftController.java @@ -194,7 +194,7 @@ public class CargosoftController implements Serializable { try { List result = documentService.find(query, 20, 0, "$modified", true); - logger.info("found " + result.size() + " debitors..."); + logger.fine("found " + result.size() + " debitors..."); if (result != null) { for (ItemCollection dbtr : result) { // Aenderugn 22. Jun wir geben das K/D direkt witer diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/DebitorStatistikController.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/DebitorStatistikController.java index 87d3af2..f6b4481 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/DebitorStatistikController.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/DebitorStatistikController.java @@ -18,12 +18,15 @@ import java.util.TreeMap; import java.util.logging.Logger; import java.util.stream.Collectors; +import javax.annotation.PostConstruct; import javax.enterprise.context.ConversationScoped; +import javax.faces.context.FacesContext; import javax.inject.Inject; import javax.inject.Named; import org.imixs.workflow.ItemCollection; import org.imixs.workflow.engine.DocumentService; +import org.imixs.workflow.exceptions.PluginException; import org.imixs.workflow.exceptions.QueryException; import org.imixs.workflow.faces.data.WorkflowController; import org.imixs.workflow.office.views.SearchController; @@ -54,12 +57,32 @@ public class DebitorStatistikController implements Serializable { @Inject protected SearchController searchController; - // private ItemCollection workitem = null; + @Inject + protected KreditorDebitorService kreditorDebitorService; - public DebitorStatistikController() { - // workitem = new ItemCollection(); + /** + * Initialize default behavior initialize an opitonal id from the query string + * + */ + @PostConstruct + public void init() { + // extract the processref and page from the query string + FacesContext fc = FacesContext.getCurrentInstance(); + Map paramMap = fc.getExternalContext().getRequestParameterMap(); + + String id = paramMap.get("dbtr.number"); + if (id != null && !id.isEmpty()) { + workflowController.getWorkitem().setItemValue("dbtr.number", id); + try { + ItemCollection dbtr = kreditorDebitorService.findDebitor(id); + if (dbtr != null) { + workflowController.getWorkitem().setItemValue("dbtr.name", dbtr.getItemValueString("_vendor_name")); + } + } catch (PluginException e) { + // e.printStackTrace(); + } + } } - public ItemCollection getWorkitem() { return workflowController.getWorkitem(); } @@ -68,6 +91,15 @@ public class DebitorStatistikController implements Serializable { return 0; } + /** + * Gibt eine bookmarkable url zurück. + * Wir vom Aktualisieren button in der Page genutzt + * + * @return + */ + public String getBookmark() { + return "/pages/dbtr-stats.xhtml?dbtr.number=" + getDbtNr() + "&faces-redirect=true"; + } /* * Gesamt */ @@ -78,6 +110,9 @@ public class DebitorStatistikController implements Serializable { } public int getRechnungen() { int result = 0; + if (getDbtNr().isEmpty()) { + return 0; + } try { result = documentService .count("(type:workitem OR type:workitemarchive) AND dbtr.number:" + getDbtNr() @@ -99,7 +134,9 @@ public class DebitorStatistikController implements Serializable { } public int getRechnungenBezahlt() { int result = 0; - + if (getDbtNr().isEmpty()) { + return 0; + } try { result = documentService .count("(type:workitem OR type:workitemarchive) AND dbtr.number:" + getDbtNr() @@ -120,7 +157,9 @@ public class DebitorStatistikController implements Serializable { } public int getRechnungenOffen() { int result = 0; - + if (getDbtNr().isEmpty()) { + return 0; + } try { result = documentService .count("(type:workitem) AND dbtr.number:" + getDbtNr() @@ -141,6 +180,9 @@ public class DebitorStatistikController implements Serializable { } public int getRechnungenFaellig() { int result = 0; + if (getDbtNr().isEmpty()) { + return 0; + } try { result = documentService .count("(type:workitem) AND dbtr.number:" + getDbtNr() @@ -161,6 +203,9 @@ public class DebitorStatistikController implements Serializable { } public int getRechnungenGemahnt() { int result = 0; + if (getDbtNr().isEmpty()) { + return 0; + } try { result = documentService .count("(type:workitem ) AND dbtr.number:" + getDbtNr() @@ -181,7 +226,9 @@ public class DebitorStatistikController implements Serializable { } public int getRechnungenInkasso() { int result = 0; - + if (getDbtNr().isEmpty()) { + return 0; + } try { result = documentService .count("(type:workitem OR type:workitemarchive) AND dbtr.number:" + getDbtNr() @@ -197,7 +244,7 @@ public class DebitorStatistikController implements Serializable { * * @return */ - private String getDbtNr() { + public String getDbtNr() { String dbtNr = getWorkitem().getItemValueString("dbtr.number"); if (dbtNr.startsWith("D") || dbtNr.startsWith("K")) { dbtNr = dbtNr.substring(1); @@ -246,16 +293,18 @@ public class DebitorStatistikController implements Serializable { // recompute stats = new TreeMap(); - + if (getDbtNr().isEmpty()) { + return stats; + } // invoice.date:[20210101 TO 20210201] DateFormat df = new SimpleDateFormat("yyyymmdd"); - String query = "(type:workitemarchive) AND dbtr.number:" + getDbtNr() + String query = "(type:workitemarchive) AND invoice.date:[20221201 TO 20500101] AND dbtr.number:" + getDbtNr() + " AND $workflowgroup:\"Rechnungsausgang\" AND ($taskid:[5900 TO 5999])"; // query = query + " AND (invoice.date:[" + df.format(from) + " TO " + // df.format(to) + "])"; - logger.info("query = " + query); + logger.fine("query = " + query); try { List invoices = documentService .findStubs(query, 9999, 0, "$created", false); @@ -263,14 +312,12 @@ public class DebitorStatistikController implements Serializable { for (ItemCollection invoice : invoices) { try { - logger.warning("Rechnung: " + invoice.getUniqueID()); + logger.fine("Rechnung: " + invoice.getUniqueID()); Date invoiceDate = invoice.getItemValueDate("invoice.date"); Date invoiceDueDate = invoice.getItemValueDate("invoice.duedate"); Date paymentDate = findPaymentDateByWorkitem(invoice); if (paymentDate == null) { - // fall back method logger.warning("Es wurde kein Zahlungseingang gefunden"); - // paymentDate = findPaymentDateByLog(invoice); continue; } @@ -281,10 +328,8 @@ public class DebitorStatistikController implements Serializable { // create a new one statData = new DebitorStatistikData(invoiceDate); } - // jetzt irgendwas ausrechnen statData.compute(invoiceDate, invoiceDueDate, paymentDate); - // .. und wieder speichern stats.put(statData.toString(), statData); @@ -300,10 +345,7 @@ public class DebitorStatistikController implements Serializable { } catch (QueryException e) { logger.severe("Failed to get statistic: " + e.getMessage()); } - // Step 2: Sort the list based on the alphanumeric order of the keys - - // stats = new TreeMap<>(stats); completeMissingMonths(); return stats; diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/DebitorStatistikData.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/DebitorStatistikData.java index 5d05709..ea07475 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/DebitorStatistikData.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/DebitorStatistikData.java @@ -48,9 +48,9 @@ public class DebitorStatistikData { // und was nun? count++; - logger.info("...invoiceDate= " + invoiceDate); - logger.info("...invoiceDueDate= " + invoiceDueDate); - logger.info("...paymentDate= " + paymentDate); + logger.fine("...invoiceDate= " + invoiceDate); + logger.fine("...invoiceDueDate= " + invoiceDueDate); + logger.fine("...paymentDate= " + paymentDate); // Fälligkeit in Tagen long milliseconds1 = invoiceDate.getTime(); @@ -58,7 +58,7 @@ public class DebitorStatistikData { // Berechnen Sie die Differenz in Millisekunden long diffMilliseconds = milliseconds2 - milliseconds1; long dueTime = diffMilliseconds / (24 * 60 * 60 * 1000); - logger.info("...Fälligkeit in tagen= " + dueTime); + logger.fine("...Fälligkeit in tagen= " + dueTime); totalDueDays = totalDueDays + dueTime; // averageDueDays = (long) (totalDueDays / count); @@ -73,7 +73,7 @@ public class DebitorStatistikData { // Fix differenz // paymentTime = paymentTime - dueTime; - logger.info("...Zahlung erfolgte nach tagen= " + paymentTime); + logger.fine("...Zahlung erfolgte nach tagen= " + paymentTime); totalPaymentDays = totalPaymentDays + paymentTime; // averagePaymentDays = (long) (totalPaymentDays / count); averagePaymentDays = Math.round((double) totalPaymentDays / count); diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListController.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListController.java index 0a12a9c..758c94c 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListController.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListController.java @@ -97,7 +97,8 @@ public class OPListController implements Serializable { } // Compute all open invoices if TASK_ERSTELLUNG.... - if (workflowController.getWorkitem().getTaskID() == TASK_ERSTELLUNG) { + if (workflowController.getWorkitem().getTaskID() == 0 + || workflowController.getWorkitem().getTaskID() == TASK_ERSTELLUNG) { // return empty list if dbtr is not set if (_dbtrNumber == null || _dbtrNumber.isEmpty()) { @@ -117,7 +118,7 @@ public class OPListController implements Serializable { lastDbtrNumber = _dbtrNumber; lastCurrencyFilter = currencyFilter; invoiceList = new ArrayList(); - logger.info("....loading open Invoices for " + _dbtrNumber); + logger.fine("....loading open Invoices for " + _dbtrNumber); // Aus der dbtrNummer muss das führendde D entfernt werden // wir speichern dieses zwar im Zahlungseingangs Workflow, aber eine diff --git a/office-alexander-logistics-app/src/main/webapp/pages/dbtr-stats.xhtml b/office-alexander-logistics-app/src/main/webapp/pages/dbtr-stats.xhtml index 2b1f73a..7ba689f 100644 --- a/office-alexander-logistics-app/src/main/webapp/pages/dbtr-stats.xhtml +++ b/office-alexander-logistics-app/src/main/webapp/pages/dbtr-stats.xhtml @@ -5,22 +5,16 @@ xmlns:a="http://xmlns.jcp.org/jsf/passthrough" xmlns:i="http://xmlns.jcp.org/jsf/composite/imixs" template="/layout/template.xhtml"> - - - - - - - - - - @@ -78,9 +65,6 @@ - - -

@@ -113,19 +97,13 @@

-
-
- -
-

Überblick - -

+

#{debitorStatistikController.workitem.item['dbtr.name']}

@@ -136,43 +114,26 @@ pt:data-item="dbtr.number" pt:data-resultlist="autocomplete-resultlist-cargosoft" pt:autocomplete="off" /> - - - - +
- test=#{debitorStatistikController.workitem.item['dbtr.number']} -
- - -

Statistik

- - - - - + +

Statistik

+ + + +

Offene Posten

- -
- - -
- -
- -