update fremdwährungszahlung
This commit is contained in:
parent
8bdd9a4a99
commit
f8820be87e
3 changed files with 131 additions and 97 deletions
|
|
@ -29,102 +29,123 @@ import org.imixs.workflow.exceptions.PluginException;
|
||||||
*/
|
*/
|
||||||
public class ZahlungseingangSaldoAdapter implements SignalAdapter {
|
public class ZahlungseingangSaldoAdapter implements SignalAdapter {
|
||||||
|
|
||||||
private static Logger logger = Logger.getLogger(ZahlungseingangSaldoAdapter.class.getName());
|
private static Logger logger = Logger.getLogger(ZahlungseingangSaldoAdapter.class.getName());
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ZahlungseingangService zahlungseingangService;
|
ZahlungseingangService zahlungseingangService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method finds the outgoing invoicdes and updates the saldo
|
* This method finds the outgoing invoicdes and updates the saldo
|
||||||
* (payment.total).
|
* (payment.total).
|
||||||
*
|
*
|
||||||
* @throws PluginException
|
* @throws PluginException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ItemCollection execute(ItemCollection document, ItemCollection event)
|
public ItemCollection execute(ItemCollection document, ItemCollection event)
|
||||||
throws AdapterException, PluginException {
|
throws AdapterException, PluginException {
|
||||||
|
|
||||||
updateSaldo(document);
|
updateSaldo(document);
|
||||||
|
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Diese method hängt eine referenz der aktuellen Rechnung an den Zahlungsavis
|
* Diese method hängt eine referenz der aktuellen Rechnung an den Zahlungsavis
|
||||||
*
|
*
|
||||||
* @param document
|
* @param document
|
||||||
* @throws PluginException
|
* @throws PluginException
|
||||||
*/
|
*/
|
||||||
private void updateSaldo(ItemCollection document) throws PluginException {
|
private void updateSaldo(ItemCollection document) throws PluginException {
|
||||||
|
|
||||||
// payment currency
|
// payment currency
|
||||||
String paymentCurrency = document.getItemValueString("payment.currency");
|
String paymentCurrency = document.getItemValueString("payment.currency");
|
||||||
double masterPaymentAmount = document.getItemValueDouble("payment.amount");
|
double masterPaymentAmount = document.getItemValueDouble("payment.amount");
|
||||||
String paymentWarning = document.getItemValueString("payment.warning");
|
String paymentWarning = document.getItemValueString("payment.warning");
|
||||||
|
|
||||||
List<ItemCollection> paymentDetails = zahlungseingangService.loadPaymentDetails(document);
|
List<ItemCollection> paymentDetails = zahlungseingangService.loadPaymentDetails(document);
|
||||||
|
|
||||||
if (paymentDetails.size() == 0) {
|
if (paymentDetails.size() == 0) {
|
||||||
throw new PluginException(PluginException.class.getName(),
|
throw new PluginException(PluginException.class.getName(),
|
||||||
ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED,
|
ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED,
|
||||||
"Bitte wählen Sie die zugeordneten Rechnungen aus.");
|
"Bitte wählen Sie die zugeordneten Rechnungen aus.");
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("......Updating " + paymentDetails.size() + " outgoing invoices....");
|
logger.info("......Updating " + paymentDetails.size() + " outgoing invoices....");
|
||||||
double einzelPayments = 0;
|
|
||||||
for (ItemCollection payment : paymentDetails) {
|
|
||||||
|
|
||||||
ItemCollection invoice = zahlungseingangService.findInvoice(payment.getUniqueID());
|
// Erst müssen wir einmal prüfen ob alle einzel salden ungleich dem
|
||||||
|
// MasterPamyneAmmoutn sind!
|
||||||
|
double einzelPayments = 0;
|
||||||
|
for (ItemCollection payment : paymentDetails) {
|
||||||
|
einzelPayments = einzelPayments + payment.getItemValueFloat("payment.amount");
|
||||||
|
}
|
||||||
|
// Prüfe auf Plausisbilität
|
||||||
|
if (paymentWarning.isEmpty()) {
|
||||||
|
// falls mehr einzelsummen eingeben wurden als der oben angegeben Total Pamyment
|
||||||
|
// dann soll eine Warnung ausgegen werden.
|
||||||
|
if (masterPaymentAmount != einzelPayments) {
|
||||||
|
document.setItemValue("payment.warning", "invalid saldo");
|
||||||
|
throw new PluginException(PluginException.class.getName(),
|
||||||
|
ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED,
|
||||||
|
"Der Zahlungseingang ist nicht identisch mit den ausgebuchten Rechnungssalden. Sollte die Eingabe korrekt sein, wiederholen Sie die Aktion.");
|
||||||
|
}
|
||||||
|
|
||||||
if (invoice != null) {
|
}
|
||||||
String invoiceNumber = invoice.getItemValueString("invoice.number");
|
|
||||||
String invoiceCurrency = invoice.getItemValueString("invoice.currency");
|
|
||||||
|
|
||||||
if (!invoiceCurrency.equals(paymentCurrency)) {
|
einzelPayments = 0;
|
||||||
throw new PluginException(PluginException.class.getName(),
|
for (ItemCollection payment : paymentDetails) {
|
||||||
ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED,
|
|
||||||
"Der Zahlungseingang kann nicht verbucht werden, da die Währung " + paymentCurrency
|
|
||||||
+ " nicht mit der Währung der Rechnung " + invoiceNumber + " übereinstimmt!");
|
|
||||||
}
|
|
||||||
|
|
||||||
float invoiceSaldo = invoice.getItemValueFloat("invoice.saldo");
|
ItemCollection invoice = zahlungseingangService.findInvoice(payment.getUniqueID());
|
||||||
float paymentAmount = payment.getItemValueFloat("payment.amount");
|
|
||||||
einzelPayments = einzelPayments + paymentAmount;
|
|
||||||
|
|
||||||
|
if (invoice != null) {
|
||||||
// vergeiche Beträge
|
String invoiceNumber = invoice.getItemValueString("invoice.number");
|
||||||
if (Math.abs(paymentAmount) > Math.abs(invoiceSaldo)) {
|
String invoiceCurrency = invoice.getItemValueString("invoice.currency");
|
||||||
throw new PluginException(PluginException.class.getName(),
|
float invoiceSaldo = invoice.getItemValueFloat("invoice.saldo");
|
||||||
ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED,
|
float paymentAmount = payment.getItemValueFloat("payment.amount");
|
||||||
"Der Zahlungseingang kann nicht verbucht werden, da der Restsaldo der Rechnung "
|
float invoiceRate = invoice.getItemValueFloat("invoice.rate");
|
||||||
+ invoiceNumber + " kleiner als der Zahlbetrag ist!");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Prüfe auf Plausisbilität
|
|
||||||
if (paymentWarning.isEmpty()) {
|
|
||||||
// falls mehr einzelsummen eingeben wurden als der oben angegeben Total Pamyment
|
|
||||||
// dann soll eine Warnung ausgegen werden.
|
|
||||||
if (masterPaymentAmount > einzelPayments) {
|
|
||||||
document.setItemValue("payment.warning", "invalid saldo");
|
|
||||||
throw new PluginException(PluginException.class.getName(),
|
|
||||||
ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED,
|
|
||||||
"Der Zahlungseingang ist größer als die ausgebuchten Rechnungssalden. Sollte die Eingabe korrekt sein, wiederholen Sie die Aktion.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* Falls die Währung der Rechnung von der Währung der Zahlung abweicht, dann
|
||||||
|
* rechnen wir den PaymentAmmout mit der Rate aus.
|
||||||
|
*/
|
||||||
|
if (!invoiceCurrency.equals(paymentCurrency)) {
|
||||||
|
if (invoiceRate == 0) {
|
||||||
|
throw new PluginException(PluginException.class.getName(),
|
||||||
|
ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED,
|
||||||
|
"Der Zahlungseingang kann nicht verbucht werden, da die Währung " + paymentCurrency
|
||||||
|
+ " nicht mit der Währung der Rechnung " + invoiceNumber + " übereinstimmt!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
invoiceSaldo = invoiceSaldo - paymentAmount;
|
einzelPayments = einzelPayments + paymentAmount;
|
||||||
invoice.setItemValue("invoice.saldo", invoiceSaldo);
|
|
||||||
invoice.event(ZahlungseingangService.EVENT_UPDATE_INVOICE);
|
|
||||||
zahlungseingangService.processInvoice(invoice);
|
|
||||||
|
|
||||||
} else {
|
// vergeiche Beträge
|
||||||
throw new PluginException(PluginException.class.getName(),
|
if (Math.abs(paymentAmount) > Math.abs(invoiceSaldo)) {
|
||||||
ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED, "Rechnung konnte nicht gefunden werden!");
|
throw new PluginException(PluginException.class.getName(),
|
||||||
}
|
ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED,
|
||||||
}
|
"Der Zahlungseingang kann nicht verbucht werden, da der Restsaldo der Rechnung "
|
||||||
|
+ invoiceNumber + " kleiner als der Zahlbetrag ist!");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
// Saldoberechnung in Fremdwärung?
|
||||||
|
if (!invoiceCurrency.equals(paymentCurrency) && invoiceRate != 0) {
|
||||||
|
// Wenn es eien Fremdwährung war korregieren wir den Saldo auf basis des
|
||||||
|
// Umrechnungskurses
|
||||||
|
invoiceSaldo = invoiceSaldo - (paymentAmount * invoiceRate);
|
||||||
|
} else {
|
||||||
|
invoiceSaldo = invoiceSaldo - paymentAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
invoice.setItemValue("invoice.saldo", invoiceSaldo);
|
||||||
|
invoice.event(ZahlungseingangService.EVENT_UPDATE_INVOICE);
|
||||||
|
zahlungseingangService.processInvoice(invoice);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new PluginException(PluginException.class.getName(),
|
||||||
|
ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED, "Rechnung konnte nicht gefunden werden!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -71,6 +71,19 @@
|
||||||
<td /><td /><td /><td /><td />
|
<td /><td /><td /><td /><td />
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<!-- summary -->
|
||||||
|
<tr>
|
||||||
|
<td />
|
||||||
|
|
||||||
|
<td style="text-align: right;font-weight:bold;color:red;">Saldo:</td>
|
||||||
|
|
||||||
|
<td class="" style="text-align: right;color:red;"><h:outputText
|
||||||
|
value="#{workitem.item['invoice.saldo']}">
|
||||||
|
<f:convertNumber minFractionDigits="2" maxFractionDigits="3" locale="de" />
|
||||||
|
</h:outputText></td>
|
||||||
|
<td /><td /><td /><td /><td />
|
||||||
|
</tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
</f:ajax>
|
</f:ajax>
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,7 @@
|
||||||
<th>Referenz</th>
|
<th>Referenz</th>
|
||||||
<th style="width: 100px;">Betrag</th>
|
<th style="width: 100px;">Betrag</th>
|
||||||
<th style="width: 100px;">Zahlung</th>
|
<th style="width: 100px;">Zahlung</th>
|
||||||
<th style="width: 40px;">Währung</th>
|
<th style="width: 100px;">Währungsumsatz</th>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<ui:param name="payments"
|
<ui:param name="payments"
|
||||||
|
|
@ -49,7 +48,7 @@
|
||||||
<td style="text-align: right;"><h:outputText
|
<td style="text-align: right;"><h:outputText
|
||||||
value="#{payment.item['payment.total']}">
|
value="#{payment.item['payment.total']}">
|
||||||
<f:convertNumber minFractionDigits="2" locale="de" />
|
<f:convertNumber minFractionDigits="2" locale="de" />
|
||||||
</h:outputText></td>
|
</h:outputText> <h:outputText value=" #{payment.item['payment.currency']}" /></td>
|
||||||
|
|
||||||
<!-- show payment amount of corresponding invoice entry -->
|
<!-- show payment amount of corresponding invoice entry -->
|
||||||
<ui:repeat var="paymentDetail" value="#{paymentDetails}">
|
<ui:repeat var="paymentDetail" value="#{paymentDetails}">
|
||||||
|
|
@ -59,29 +58,30 @@
|
||||||
<td style="text-align: right;"><h:outputText
|
<td style="text-align: right;"><h:outputText
|
||||||
value="#{paymentDetail.item['payment.amount']}">
|
value="#{paymentDetail.item['payment.amount']}">
|
||||||
<f:convertNumber minFractionDigits="2" locale="de" />
|
<f:convertNumber minFractionDigits="2" locale="de" />
|
||||||
</h:outputText></td>
|
</h:outputText>
|
||||||
|
<h:outputText value=" #{payment.item['payment.currency']}" />
|
||||||
|
</td>
|
||||||
|
|
||||||
|
|
||||||
|
<td style="text-align: right;">
|
||||||
|
<h:outputText rendered="#{payment.item['payment.currency'] eq 'EUR'}"
|
||||||
|
value="#{paymentDetail.item['payment.amount']*workitem.item['invoice.rate']}">
|
||||||
|
<f:convertNumber minFractionDigits="2" locale="de" />
|
||||||
|
</h:outputText>
|
||||||
|
<h:outputText rendered="#{payment.item['payment.currency'] eq 'EUR'}"
|
||||||
|
value=" #{workitem.item['invoice.currency']}" />
|
||||||
|
</td>
|
||||||
|
|
||||||
</ui:fragment>
|
</ui:fragment>
|
||||||
</ui:repeat>
|
</ui:repeat>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<td style="text-align: right;"><h:outputText
|
|
||||||
value="#{payment.item['payment.currency']}" /></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</ui:repeat>
|
</ui:repeat>
|
||||||
|
|
||||||
<!-- summary -->
|
|
||||||
<tr>
|
|
||||||
<td />
|
|
||||||
<td />
|
|
||||||
<td style="text-align: right;font-weight:bold;">Saldo:</td>
|
|
||||||
|
|
||||||
<td class="" style="text-align: right;"><h:outputText
|
|
||||||
value="#{workitem.item['invoice.saldo']}">
|
|
||||||
<f:convertNumber minFractionDigits="2" locale="de" />
|
|
||||||
</h:outputText></td>
|
|
||||||
<td />
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue