runden von beträgen
This commit is contained in:
parent
41c6ac7cbf
commit
a739c0ddac
4 changed files with 87 additions and 4 deletions
12
.vscode/launch.json
vendored
Normal file
12
.vscode/launch.json
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
// Wildfly Debug Configuration
|
||||
"configurations": [
|
||||
{
|
||||
"type": "java",
|
||||
"name": "Debug Wildfly",
|
||||
"request": "attach",
|
||||
"hostName": "localhost",
|
||||
"port": "8787"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,10 +1,28 @@
|
|||
package com.alexanderlogistics;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
/**
|
||||
* Rundungs Methode
|
||||
*
|
||||
* See: https://stackoverflow.com/questions/2808535/round-a-double-to-2-decimal-places
|
||||
*
|
||||
* @author rsoika
|
||||
*
|
||||
*/
|
||||
public class InvoiceUtil {
|
||||
|
||||
public static double round(double value) {
|
||||
BigDecimal bd = BigDecimal.valueOf(value);
|
||||
bd = bd.setScale(2, RoundingMode.HALF_UP);
|
||||
return bd.doubleValue();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static double roundConservative(double value) {
|
||||
value = value * 100;
|
||||
long tmp = Math.round(value);
|
||||
return (double) tmp / 100;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,6 @@ public class ZahlungseingangSaldoAdapter implements SignalAdapter {
|
|||
ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED,
|
||||
"Der Zahlungseingang ist nicht identisch mit den ausgebuchten Rechnungssalden. Sollte die Eingabe korrekt sein, wiederholen Sie die Aktion.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -127,7 +126,7 @@ public class ZahlungseingangSaldoAdapter implements SignalAdapter {
|
|||
|
||||
|
||||
// vergeiche Restsaldo mit payment für diese Rechnung
|
||||
if (Math.abs(invoicePaymentAmount) > Math.abs(InvoiceUtil.round(invoiceSaldo))) {
|
||||
if (Math.abs(InvoiceUtil.round(invoicePaymentAmount)) > Math.abs(InvoiceUtil.round(invoiceSaldo))) {
|
||||
throw new PluginException(PluginException.class.getName(),
|
||||
ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED,
|
||||
"Der Zahlungseingang kann nicht verbucht werden, da der Restsaldo der Rechnung "
|
||||
|
|
@ -138,7 +137,7 @@ public class ZahlungseingangSaldoAdapter implements SignalAdapter {
|
|||
invoiceSaldo = invoiceSaldo - invoicePaymentAmount;
|
||||
|
||||
|
||||
|
||||
invoiceSaldo=(float) InvoiceUtil.round(invoiceSaldo);
|
||||
invoice.setItemValue("invoice.saldo", invoiceSaldo);
|
||||
invoice.event(ZahlungseingangService.EVENT_UPDATE_INVOICE);
|
||||
zahlungseingangService.processInvoice(invoice);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
package com.alexanderlogistics;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.imixs.workflow.datev.imports.DatevImportAdapter;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* This test generates random test data
|
||||
*
|
||||
* @author rsoika
|
||||
*
|
||||
*/
|
||||
public class TestRunden {
|
||||
|
||||
public static DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy");
|
||||
public static DecimalFormat decimalFormat = new DecimalFormat("0.00");
|
||||
public static DecimalFormat rateFormat = new DecimalFormat("0.000000");
|
||||
|
||||
private final static Logger logger = Logger.getLogger(TestFormat.class.getName());
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBetrag() {
|
||||
double d1 = 915.1400000000001;
|
||||
double d2 = 915.1400000000002;
|
||||
|
||||
logger.info("d1="+d1);
|
||||
logger.info("d2="+d2);
|
||||
|
||||
logger.info("d1="+InvoiceUtil.round(d1));
|
||||
logger.info("d2="+InvoiceUtil.round(d2));
|
||||
|
||||
if (Math.abs(InvoiceUtil.round(d1)) > Math.abs(InvoiceUtil.round(d2))) {
|
||||
Assert.fail();
|
||||
}
|
||||
logger.info("Test erfolgreich");
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue