details: /erp/devel/pi/rev/19d4c96ac11a
changeset: 11796:19d4c96ac11a
user: Mikel Irurita <mikel.irurita <at> openbravo.com>
date: Thu Apr 28 17:45:04 2011 +0200
summary: [APRM] Include amount validation (only when completing) while
processing the payment
diffstat:
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java
| 30 ++------
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java
| 35 ++++++++++
2 files changed, 44 insertions(+), 21 deletions(-)
diffs (106 lines):
diff -r d9c495824ed3 -r 19d4c96ac11a
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java
---
a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java
Thu Apr 28 16:55:27 2011 +0200
+++
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java
Thu Apr 28 17:45:04 2011 +0200
@@ -589,29 +589,17 @@
*/
public static void updatePaymentScheduleAmounts(FIN_PaymentSchedule
paymentSchedule,
BigDecimal amount, BigDecimal writeOffAmount) {
- BigDecimal totalPaid = amount;
- BigDecimal outstanding = paymentSchedule.getOutstandingAmount();
+ paymentSchedule.setPaidAmount(paymentSchedule.getPaidAmount().add(amount));
+
paymentSchedule.setOutstandingAmount(paymentSchedule.getOutstandingAmount().subtract(amount));
if (writeOffAmount != null && writeOffAmount.compareTo(BigDecimal.ZERO) !=
0) {
- totalPaid = amount.add(writeOffAmount);
+
paymentSchedule.setPaidAmount(paymentSchedule.getPaidAmount().add(writeOffAmount));
+
paymentSchedule.setOutstandingAmount(paymentSchedule.getOutstandingAmount().subtract(
+ writeOffAmount));
}
- // (totalPaid > 0 && totalPaid <= outstanding) || (totalPaid < 0 &&
totalPaid >= outstanding)
- if ((totalPaid.compareTo(BigDecimal.ZERO) == 1 &&
totalPaid.compareTo(outstanding) <= 0)
- || (totalPaid.compareTo(BigDecimal.ZERO) == -1 &&
totalPaid.compareTo(outstanding) >= 0)) {
-
paymentSchedule.setPaidAmount(paymentSchedule.getPaidAmount().add(amount));
-
paymentSchedule.setOutstandingAmount(paymentSchedule.getOutstandingAmount().subtract(amount));
- if (writeOffAmount != null && writeOffAmount.compareTo(BigDecimal.ZERO)
!= 0) {
-
paymentSchedule.setPaidAmount(paymentSchedule.getPaidAmount().add(writeOffAmount));
-
paymentSchedule.setOutstandingAmount(paymentSchedule.getOutstandingAmount().subtract(
- writeOffAmount));
- }
- OBDal.getInstance().save(paymentSchedule);
- if (paymentSchedule.getInvoice() != null) {
- updateInvoicePaymentMonitor(paymentSchedule.getInvoice(),
paymentSchedule.getDueDate(),
- amount, writeOffAmount);
- }
- } else {
- throw new
OBException(String.format(FIN_Utility.messageBD("APRM_AmountOutOfRange"),
totalPaid
- .toString(), paymentSchedule.getOutstandingAmount().toString()));
+ OBDal.getInstance().save(paymentSchedule);
+ if (paymentSchedule.getInvoice() != null) {
+ updateInvoicePaymentMonitor(paymentSchedule.getInvoice(),
paymentSchedule.getDueDate(),
+ amount, writeOffAmount);
}
}
diff -r d9c495824ed3 -r 19d4c96ac11a
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java
---
a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java
Thu Apr 28 16:55:27 2011 +0200
+++
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java
Thu Apr 28 17:45:04 2011 +0200
@@ -29,6 +29,7 @@
import org.openbravo.advpaymentmngt.dao.TransactionsDao;
import org.openbravo.advpaymentmngt.exception.NoExecutionProcessFoundException;
import org.openbravo.advpaymentmngt.utility.FIN_Utility;
+import org.openbravo.base.exception.OBException;
import org.openbravo.base.secureApp.VariablesSecureApp;
import org.openbravo.dal.core.OBContext;
import org.openbravo.dal.service.OBCriteria;
@@ -114,6 +115,8 @@
if (paymentScheduleDetail.getInvoicePaymentSchedule() != null) {
invoiceDocNos.add(paymentScheduleDetail.getInvoicePaymentSchedule().getInvoice()
.getDocumentNo());
+
validateAmount(paymentScheduleDetail.getInvoicePaymentSchedule(), paymentDetail
+ .getAmount(), paymentDetail.getWriteoffAmount());
FIN_AddPayment.updatePaymentScheduleAmounts(paymentScheduleDetail
.getInvoicePaymentSchedule(), paymentDetail.getAmount(),
paymentDetail
.getWriteoffAmount());
@@ -123,6 +126,8 @@
if (paymentScheduleDetail.getOrderPaymentSchedule() != null) {
orderDocNos.add(paymentScheduleDetail.getOrderPaymentSchedule().getOrder()
.getDocumentNo());
+
validateAmount(paymentScheduleDetail.getOrderPaymentSchedule(), paymentDetail
+ .getAmount(), paymentDetail.getWriteoffAmount());
FIN_AddPayment.updatePaymentScheduleAmounts(paymentScheduleDetail
.getOrderPaymentSchedule(), paymentDetail.getAmount(),
paymentDetail
.getWriteoffAmount());
@@ -430,4 +435,34 @@
}
}
}
+
+ /**
+ * Checks if the amount to pay/receive fits with the outstanding amount in
the invoice or order.
+ *
+ * @param paymentSchedule
+ * Payment plan of the order or invoice where the outstanding
amount is specified.
+ * @param amount
+ * Amount to by paid or received.
+ * @param writeOffAmount
+ * Write off amount.
+ * @return True if the amount is valid.
+ * @throws OBException
+ * Exception explaining why the amount is not valid.
+ */
+ private boolean validateAmount(FIN_PaymentSchedule paymentSchedule,
BigDecimal amount,
+ BigDecimal writeOffAmount) throws OBException {
+ BigDecimal totalPaid = amount;
+ BigDecimal outstanding = paymentSchedule.getOutstandingAmount();
+ if (writeOffAmount != null && writeOffAmount.compareTo(BigDecimal.ZERO) !=
0) {
+ totalPaid = amount.add(writeOffAmount);
+ }
+ // (totalPaid > 0 && totalPaid <= outstanding) || (totalPaid < 0 &&
totalPaid >= outstanding)
+ if ((totalPaid.compareTo(BigDecimal.ZERO) == 1 &&
totalPaid.compareTo(outstanding) <= 0)
+ || (totalPaid.compareTo(BigDecimal.ZERO) == -1 &&
totalPaid.compareTo(outstanding) >= 0)) {
+ return true;
+ } else {
+ throw new
OBException(String.format(FIN_Utility.messageBD("APRM_AmountOutOfRange"),
totalPaid
+ .toString(), paymentSchedule.getOutstandingAmount().toString()));
+ }
+ }
}
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits