agl debitor metric service
This commit is contained in:
parent
d5d4b21434
commit
633bcdd3d6
1 changed files with 31 additions and 7 deletions
|
|
@ -18,13 +18,22 @@ import org.imixs.workflow.exceptions.QueryException;
|
|||
import jakarta.annotation.security.DeclareRoles;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.annotation.security.RunAs;
|
||||
import jakarta.ejb.TransactionAttribute;
|
||||
import jakarta.ejb.TransactionAttributeType;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.enterprise.event.Observes;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
/**
|
||||
* Dieser Service reagiert auch ProcessingEvents und speichert/aktualisert die
|
||||
* Dieser Service reagiert auch ProcessingEvents und speichert/aktualisiert die
|
||||
* zugehörige Debitoren Metric Entity.
|
||||
* <p>
|
||||
* Der Service liest in einem AFTER_PROCESS Event den alten invoice.saldo aus.
|
||||
* Hierzu wird die Rechnung in einer neuen Transaktion geladen was einem
|
||||
* 'Dirty-Read' entspricht. Dadurch kennt die Methode den letzten saldo der
|
||||
* Rechnung. Hat sich nun der aktuelle Saldo geändert, aktualisiert der Serivce
|
||||
* die entsprechende Metric.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@DeclareRoles({ "org.imixs.ACCESSLEVEL.NOACCESS", "org.imixs.ACCESSLEVEL.READERACCESS",
|
||||
|
|
@ -42,7 +51,6 @@ public class MetricDebitorService {
|
|||
|
||||
public static final String METRIC_INVOICES = "invoices";
|
||||
public static final String TYPE_METRIC_DEBITOR = "metric.debitor";
|
||||
public static final String ITEM_LAST_METRIC = "metric.saldo";
|
||||
public static final String ITEM_SALDO = "invoice.saldo";
|
||||
|
||||
@Inject
|
||||
|
|
@ -68,7 +76,8 @@ public class MetricDebitorService {
|
|||
|
||||
// verify if saldo has changed.....
|
||||
double invoiceSaldo = invoice.getItemValueDouble(ITEM_SALDO);
|
||||
if (invoiceSaldo == invoice.getItemValueDouble(ITEM_LAST_METRIC)) {
|
||||
double lastInvoiceSaldo = readDirtySaldo(invoice.getUniqueID());
|
||||
if (invoiceSaldo == lastInvoiceSaldo) {
|
||||
// no change - no metric update!
|
||||
return;
|
||||
}
|
||||
|
|
@ -82,9 +91,9 @@ public class MetricDebitorService {
|
|||
|
||||
// Saldo-Berechnung wie bisher
|
||||
debitorSaldo = metric.getItemValueDouble(ITEM_SALDO);
|
||||
if (invoice.hasItem(ITEM_LAST_METRIC)) {
|
||||
debitorSaldo = debitorSaldo - invoice.getItemValueDouble(ITEM_LAST_METRIC);
|
||||
}
|
||||
debitorSaldo = debitorSaldo - lastInvoiceSaldo;
|
||||
|
||||
// update debitor saldo
|
||||
debitorSaldo = InvoiceUtil.round(debitorSaldo + invoiceSaldo);
|
||||
|
||||
// Speichern in der Datenbank
|
||||
|
|
@ -100,6 +109,21 @@ public class MetricDebitorService {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This helper method reads the 'dirty' saldo in a new transaction. This is used
|
||||
* for calculating the new total saldo
|
||||
*
|
||||
* @param uniqueid
|
||||
*/
|
||||
@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
|
||||
public double readDirtySaldo(String uniqueid) {
|
||||
double result = 0;
|
||||
ItemCollection dirtyInvoice = documentService.load(uniqueid);
|
||||
result = dirtyInvoice.getItemValueDouble(ITEM_SALDO);
|
||||
logger.info("---Dirty last Saldo was : " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method loads a metric entity. If no metric entity exits, the method
|
||||
* creates a new one.
|
||||
|
|
@ -142,7 +166,7 @@ public class MetricDebitorService {
|
|||
* verwendet.
|
||||
*
|
||||
*/
|
||||
public void initMetric(ItemCollection metric) {
|
||||
protected void initMetric(ItemCollection metric) {
|
||||
String dbtrNumber = metric.getItemValueString("dbtr.number");
|
||||
double saldo = metric.getItemValueDouble(ITEM_SALDO);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue