Skip to content

Commit 3701c8e

Browse files
committed
docu, refactoring (#189)
1 parent 2892a59 commit 3701c8e

9 files changed

Lines changed: 248 additions & 111 deletions

File tree

imixs-adapters-sepa/src/main/java/org/imixs/workflow/sepa/adapter/SEPAAdapter.java

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public void addWorkitemToSepa(ItemCollection workitem, ItemCollection event, Ite
179179
ItemCollection sepaExport;
180180
try {
181181

182-
sepaExport = findSEPAExportByTask(workflowgroup, key, initTask);
182+
sepaExport = sepaWorkflowService.findSEPAExportByWorkflowGroup(workflowgroup, key, initTask);
183183
if (sepaExport == null) {
184184
// create a new one
185185
sepaExport = createNewSEPAExport(key, workflowgroup, initTask, initEvent, type, workitem, debug);
@@ -228,7 +228,7 @@ private void removeWorkitemFromDataGroup(ItemCollection workitem, ItemCollection
228228
ItemCollection sepaExport;
229229
try {
230230

231-
sepaExport = findSEPAExportByTask(workflowgroup, key, 0);
231+
sepaExport = sepaWorkflowService.findSEPAExportByWorkflowGroup(workflowgroup, key, 0);
232232
if (sepaExport != null) {
233233
// Sepa group found remove reference
234234
List<String> refs = workitem.getItemValueList("$workitemref", String.class);
@@ -261,8 +261,7 @@ private ItemCollection createNewSEPAExport(String key, String workflowgroup, int
261261
ItemCollection sepaExport = new ItemCollection()
262262
.workflowGroup(workflowgroup)
263263
.task(taskID)
264-
.event(eventId)
265-
.setItemValue("name", key);
264+
.event(eventId);
266265

267266
// Lookup SEPA config....
268267
ItemCollection bankConfig = null;
@@ -281,7 +280,7 @@ private ItemCollection createNewSEPAExport(String key, String workflowgroup, int
281280
sepaExport.replaceItemValue(WorkflowKernel.MODIFIED, new Date());
282281
// set uniqueId, needed for xslt
283282
sepaExport.setItemValue(WorkflowKernel.UNIQUEID, WorkflowKernel.generateUniqueID());
284-
283+
sepaExport.setItemValue("name", key);
285284
// Invoice/Lastschrift?
286285
if ("OUT".equalsIgnoreCase(type)) {
287286
// copy dbtr data...
@@ -353,35 +352,4 @@ private ItemCollection loadSepaConfig() {
353352
return null;
354353
}
355354

356-
/**
357-
* Helper method to find a matching sepa group
358-
*
359-
* @param key
360-
* @param taskID - optional can be used to restrict the lookup for a specific
361-
* task
362-
* @return
363-
* @throws QueryException
364-
*/
365-
private ItemCollection findSEPAExportByTask(String workflowgroup, String key, int taskID) throws QueryException {
366-
String query = "";
367-
368-
if (taskID > 0) {
369-
query = "(type:workitem) AND ($taskid:" + taskID + ") AND ($workflowgroup:" + workflowgroup
370-
+ ") AND (name:\""
371-
+ key + "\")";
372-
373-
} else {
374-
query = "(type:workitem) AND ($workflowgroup:" + workflowgroup + ") AND (name:\""
375-
+ key + "\")";
376-
377-
}
378-
379-
List<ItemCollection> resultList = workflowService.getDocumentService().find(query, 1, 0, "$modified", true);
380-
381-
if (resultList.size() > 0) {
382-
return resultList.get(0);
383-
}
384-
// no sepa export found
385-
return null;
386-
}
387355
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*******************************************************************************
2+
* Imixs Workflow Technology
3+
* Copyright (C) 2003, 2008 Imixs Software Solutions GmbH,
4+
* http://www.imixs.com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* as published by the Free Software Foundation; either version 2
9+
* of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* General Public License for more details.
15+
*
16+
* You can receive a copy of the GNU General Public
17+
* License at http://www.gnu.org/licenses/gpl.html
18+
*
19+
* Contributors:
20+
* Imixs Software Solutions GmbH - initial API and implementation
21+
* Ralph Soika
22+
*
23+
*******************************************************************************/
24+
package org.imixs.workflow.sepa.controller;
25+
26+
import java.io.Serializable;
27+
import java.util.List;
28+
import java.util.logging.Logger;
29+
30+
import org.imixs.workflow.ItemCollection;
31+
import org.imixs.workflow.engine.DocumentService;
32+
import org.imixs.workflow.exceptions.QueryException;
33+
34+
import jakarta.enterprise.context.ConversationScoped;
35+
import jakarta.inject.Inject;
36+
import jakarta.inject.Named;
37+
38+
/**
39+
* The PaymentRunController is used to show invoices by a payment run
40+
*
41+
* See sections/sepa/payment_run.xhtml
42+
*
43+
*
44+
* @author rsoika
45+
* @version 1.0
46+
*/
47+
48+
@Named
49+
@ConversationScoped
50+
public class PaymentRunController implements Serializable {
51+
52+
private static final long serialVersionUID = 1L;
53+
54+
protected List<ItemCollection> invoiceList = null;
55+
56+
@Inject
57+
DocumentService documentService;
58+
59+
private static Logger logger = Logger.getLogger(PaymentRunController.class.getName());
60+
61+
/**
62+
* This method computes the sum for a given item in a list of workitems. The
63+
* result is rounded to 2 digits.
64+
*
65+
* @param refids - list of workitem uniqueIds
66+
* @param item - name of the item to summarize
67+
* @return sum rounded to 2 digits
68+
*/
69+
public double calculateSum(ItemCollection workitem, String item) {
70+
double result = 0;
71+
72+
List<ItemCollection> invoices = getInvoices(workitem);
73+
if (invoices != null) {
74+
for (ItemCollection doc : invoices) {
75+
result = result + doc.getItemValueDouble(item);
76+
}
77+
}
78+
// rond with 2 digits
79+
return Math.round(result * 100.0) / 100.0;
80+
81+
}
82+
83+
/**
84+
* Loads all invoices for the current sepa run
85+
*
86+
* @return
87+
*/
88+
public List<ItemCollection> getInvoices(ItemCollection workitem) {
89+
90+
if (invoiceList == null) {
91+
String query = "(type:workitem OR type:workitemarchive) AND ($workitemref:"
92+
+ workitem.getUniqueID() + ")";
93+
94+
try {
95+
invoiceList = documentService.find(query, 9999, 0);
96+
97+
} catch (QueryException e) {
98+
logger.warning("Failed to select invoices: " + e.getMessage());
99+
}
100+
}
101+
return invoiceList;
102+
}
103+
104+
}

imixs-adapters-sepa/src/main/java/org/imixs/workflow/sepa/controller/SepaController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import org.imixs.workflow.engine.DocumentService;
3838
import org.imixs.workflow.engine.scheduler.SchedulerController;
3939
import org.imixs.workflow.engine.scheduler.SchedulerService;
40+
import org.imixs.workflow.exceptions.QueryException;
41+
import org.imixs.workflow.faces.data.WorkflowController;
4042
import org.imixs.workflow.sepa.services.SepaScheduler;
4143
import org.imixs.workflow.sepa.services.SepaWorkflowService;
4244

imixs-adapters-sepa/src/main/java/org/imixs/workflow/sepa/services/SepaWorkflowService.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,38 @@ public ItemCollection processSEPAExport(ItemCollection datevExport)
417417
return workflowService.processWorkItem(datevExport);
418418
}
419419

420+
/**
421+
* Helper method to find a matching sepa group
422+
*
423+
* @param key
424+
* @param taskID - optional can be used to restrict the lookup for a specific
425+
* task
426+
* @return
427+
* @throws QueryException
428+
*/
429+
public ItemCollection findSEPAExportByWorkflowGroup(String workflowgroup, String key, int taskID)
430+
throws QueryException {
431+
String query = "";
432+
433+
if (taskID > 0) {
434+
query = "(type:workitem) AND ($taskid:" + taskID + ") AND ($workflowgroup:\"" + workflowgroup
435+
+ "\") AND (name:\"" + key + "\")";
436+
437+
} else {
438+
query = "(type:workitem) AND ($workflowgroup:\"" + workflowgroup + "\") AND (name:\""
439+
+ key + "\")";
440+
441+
}
442+
443+
List<ItemCollection> resultList = workflowService.getDocumentService().find(query, 1, 0, "$modified", true);
444+
445+
if (resultList.size() > 0) {
446+
return resultList.get(0);
447+
}
448+
// no sepa export found
449+
return null;
450+
}
451+
420452
/**
421453
* Helper method verifies all open SEPA exports and returns the latest for the
422454
* given key name. If no open SEPA export exists the method returns null.
@@ -427,6 +459,7 @@ public ItemCollection processSEPAExport(ItemCollection datevExport)
427459
* @return
428460
* @throws QueryException
429461
*/
462+
@Deprecated
430463
public ItemCollection findSEPAExportByTask(String key, int taskID) throws QueryException {
431464
String query = "";
432465
if (taskID <= 0) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
2+
xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
3+
xmlns:h="http://xmlns.jcp.org/jsf/html">
4+
5+
6+
<ui:fragment rendered="#{!readonly}">
7+
<h:panelGroup id="accountselector_id">
8+
<h:selectOneMenu required="#{required?validationController.required:false}"
9+
value="#{workitem.item[item.name]}" disabled="#{item.disabled}">
10+
<c:forEach items="#{sepaController.dbtrList}" var="dbtr">
11+
<f:selectItem itemLabel="#{dbtr.item['dbtr.name']}" itemValue="#{dbtr.item['name']}" />
12+
</c:forEach>
13+
</h:selectOneMenu>
14+
15+
</h:panelGroup>
16+
</ui:fragment>
17+
<ui:fragment rendered="#{readonly}">
18+
<h:outputText value="#{workitem.item[item.name]}" />
19+
</ui:fragment>
20+
21+
</ui:composition>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
2+
xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
3+
xmlns:h="http://xmlns.jcp.org/jsf/html">
4+
5+
6+
<ui:fragment rendered="#{!readonly}">
7+
<h:panelGroup id="accountselector_id">
8+
<h:selectOneMenu required="#{required?validationController.required:false}"
9+
value="#{workitem.item[item.name]}" disabled="#{item.disabled}">
10+
<c:forEach items="#{sepaController.dbtrList}" var="dbtr">
11+
<f:selectItem itemLabel="#{dbtr.item['dbtr.name']}" itemValue="#{dbtr.item['name']}" />
12+
</c:forEach>
13+
</h:selectOneMenu>
14+
15+
</h:panelGroup>
16+
</ui:fragment>
17+
<ui:fragment rendered="#{readonly}">
18+
<h:outputText value="#{workitem.item[item.name]}" />
19+
</ui:fragment>
20+
21+
</ui:composition>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
2+
xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core"
3+
xmlns:h="http://java.sun.com/jsf/html" xmlns:i="http://java.sun.com/jsf/composite/imixs"
4+
xmlns:marty="http://java.sun.com/jsf/composite/marty">
5+
6+
<div>
7+
<table class="imixsdatatable">
8+
<tr>
9+
<th style="">#{message['form.date']}</th>
10+
<th style="">#{message['form.invoicenumber']}</th>
11+
<th style="">#{message['form.company']}</th>
12+
13+
<th style="">#{message['form.amount']}</th>
14+
<th style=""></th>
15+
<th style="">IBAN</th>
16+
<th style="">BIC</th>
17+
</tr>
18+
19+
<c:forEach items="#{paymentRunController.getInvoices(workitem)}" var="invoice">
20+
<tr>
21+
<td>
22+
<h:outputText value="#{invoice.item['invoice.date']}">
23+
<f:convertDateTime pattern="#{message.datePatternShort}" timeZone="#{message.timeZone}" />
24+
</h:outputText>
25+
</td>
26+
<td>
27+
<h:link outcome="/pages/workitems/workitem">
28+
#{invoice.item['invoice.number']}
29+
<f:param name="id" value="#{invoice.item['$uniqueid']}" />
30+
</h:link>
31+
</td>
32+
<td>#{invoice.item['cdtr.name']}</td>
33+
34+
<td style="text-align: right;">
35+
<h:outputText value="#{invoice.item['invoice.total']}">
36+
<f:convertNumber minFractionDigits="2" locale="de" />
37+
</h:outputText>
38+
</td>
39+
40+
<td>#{invoice.item['invoice.currency']}</td>
41+
<td>#{invoice.item ['cdtr.iban']}</td>
42+
<td>#{invoice.item['cdtr.bic']}</td>
43+
</tr>
44+
</c:forEach>
45+
46+
<tr style="border-top: 1px solid #ccc;">
47+
<td />
48+
<td />
49+
<td><strong>Summary</strong></td>
50+
<td style="text-align: right;"><strong>
51+
<h:outputText value="#{paymentRunController.calculateSum(workitem,'invoice.total')}">
52+
<f:convertNumber minFractionDigits="2" locale="de" />
53+
</h:outputText>
54+
</strong></td>
55+
<td><strong>#{invoice.item['invoice.currency']}</strong></td>
56+
<td />
57+
<td />
58+
</tr>
59+
</table>
60+
</div>
61+
62+
63+
</ui:composition>

imixs-adapters-sepa/src/main/webapp/parts/sepa_paymenttype_cdtr.xhtml

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)