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 {
|
||||
|
||||
private static Logger logger = Logger.getLogger(ZahlungseingangSaldoAdapter.class.getName());
|
||||
private static Logger logger = Logger.getLogger(ZahlungseingangSaldoAdapter.class.getName());
|
||||
|
||||
@Inject
|
||||
ZahlungseingangService zahlungseingangService;
|
||||
@Inject
|
||||
ZahlungseingangService zahlungseingangService;
|
||||
|
||||
/**
|
||||
* This method finds the outgoing invoicdes and updates the saldo
|
||||
* (payment.total).
|
||||
*
|
||||
* @throws PluginException
|
||||
*/
|
||||
@Override
|
||||
public ItemCollection execute(ItemCollection document, ItemCollection event)
|
||||
throws AdapterException, PluginException {
|
||||
/**
|
||||
* This method finds the outgoing invoicdes and updates the saldo
|
||||
* (payment.total).
|
||||
*
|
||||
* @throws PluginException
|
||||
*/
|
||||
@Override
|
||||
public ItemCollection execute(ItemCollection document, ItemCollection event)
|
||||
throws AdapterException, PluginException {
|
||||
|
||||
updateSaldo(document);
|
||||
updateSaldo(document);
|
||||
|
||||
return document;
|
||||
}
|
||||
return document;
|
||||
}
|
||||
|
||||
/**
|
||||
* Diese method hängt eine referenz der aktuellen Rechnung an den Zahlungsavis
|
||||
*
|
||||
* @param document
|
||||
* @throws PluginException
|
||||
*/
|
||||
private void updateSaldo(ItemCollection document) throws PluginException {
|
||||
/**
|
||||
* Diese method hängt eine referenz der aktuellen Rechnung an den Zahlungsavis
|
||||
*
|
||||
* @param document
|
||||
* @throws PluginException
|
||||
*/
|
||||
private void updateSaldo(ItemCollection document) throws PluginException {
|
||||
|
||||
// payment currency
|
||||
String paymentCurrency = document.getItemValueString("payment.currency");
|
||||
double masterPaymentAmount = document.getItemValueDouble("payment.amount");
|
||||
String paymentWarning = document.getItemValueString("payment.warning");
|
||||
// payment currency
|
||||
String paymentCurrency = document.getItemValueString("payment.currency");
|
||||
double masterPaymentAmount = document.getItemValueDouble("payment.amount");
|
||||
String paymentWarning = document.getItemValueString("payment.warning");
|
||||
|
||||
List<ItemCollection> paymentDetails = zahlungseingangService.loadPaymentDetails(document);
|
||||
List<ItemCollection> paymentDetails = zahlungseingangService.loadPaymentDetails(document);
|
||||
|
||||
if (paymentDetails.size() == 0) {
|
||||
throw new PluginException(PluginException.class.getName(),
|
||||
ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED,
|
||||
"Bitte wählen Sie die zugeordneten Rechnungen aus.");
|
||||
}
|
||||
if (paymentDetails.size() == 0) {
|
||||
throw new PluginException(PluginException.class.getName(),
|
||||
ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED,
|
||||
"Bitte wählen Sie die zugeordneten Rechnungen aus.");
|
||||
}
|
||||
|
||||
logger.info("......Updating " + paymentDetails.size() + " outgoing invoices....");
|
||||
double einzelPayments = 0;
|
||||
for (ItemCollection payment : paymentDetails) {
|
||||
logger.info("......Updating " + paymentDetails.size() + " outgoing invoices....");
|
||||
|
||||
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)) {
|
||||
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!");
|
||||
}
|
||||
einzelPayments = 0;
|
||||
for (ItemCollection payment : paymentDetails) {
|
||||
|
||||
float invoiceSaldo = invoice.getItemValueFloat("invoice.saldo");
|
||||
float paymentAmount = payment.getItemValueFloat("payment.amount");
|
||||
einzelPayments = einzelPayments + paymentAmount;
|
||||
ItemCollection invoice = zahlungseingangService.findInvoice(payment.getUniqueID());
|
||||
|
||||
|
||||
// vergeiche Beträge
|
||||
if (Math.abs(paymentAmount) > Math.abs(invoiceSaldo)) {
|
||||
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!");
|
||||
}
|
||||
|
||||
|
||||
// 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.");
|
||||
}
|
||||
if (invoice != null) {
|
||||
String invoiceNumber = invoice.getItemValueString("invoice.number");
|
||||
String invoiceCurrency = invoice.getItemValueString("invoice.currency");
|
||||
float invoiceSaldo = invoice.getItemValueFloat("invoice.saldo");
|
||||
float paymentAmount = payment.getItemValueFloat("payment.amount");
|
||||
float invoiceRate = invoice.getItemValueFloat("invoice.rate");
|
||||
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
invoice.setItemValue("invoice.saldo", invoiceSaldo);
|
||||
invoice.event(ZahlungseingangService.EVENT_UPDATE_INVOICE);
|
||||
zahlungseingangService.processInvoice(invoice);
|
||||
einzelPayments = einzelPayments + paymentAmount;
|
||||
|
||||
} else {
|
||||
throw new PluginException(PluginException.class.getName(),
|
||||
ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED, "Rechnung konnte nicht gefunden werden!");
|
||||
}
|
||||
}
|
||||
// vergeiche Beträge
|
||||
if (Math.abs(paymentAmount) > Math.abs(invoiceSaldo)) {
|
||||
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 />
|
||||
</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>
|
||||
|
||||
</f:ajax>
|
||||
|
|
|
|||
|
|
@ -23,8 +23,7 @@
|
|||
<th>Referenz</th>
|
||||
<th style="width: 100px;">Betrag</th>
|
||||
<th style="width: 100px;">Zahlung</th>
|
||||
<th style="width: 40px;">Währung</th>
|
||||
|
||||
<th style="width: 100px;">Währungsumsatz</th>
|
||||
</tr>
|
||||
|
||||
<ui:param name="payments"
|
||||
|
|
@ -49,7 +48,7 @@
|
|||
<td style="text-align: right;"><h:outputText
|
||||
value="#{payment.item['payment.total']}">
|
||||
<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 -->
|
||||
<ui:repeat var="paymentDetail" value="#{paymentDetails}">
|
||||
|
|
@ -59,29 +58,30 @@
|
|||
<td style="text-align: right;"><h:outputText
|
||||
value="#{paymentDetail.item['payment.amount']}">
|
||||
<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:repeat>
|
||||
|
||||
|
||||
|
||||
<td style="text-align: right;"><h:outputText
|
||||
value="#{payment.item['payment.currency']}" /></td>
|
||||
|
||||
</tr>
|
||||
</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>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue