Fixed bug 26969: "There is a difference" field is not work as expected
authorSandra Huguet <sandra.huguet@openbravo.com>
Mon, 30 Jun 2014 18:20:18 +0200
changeset 23940 69c0b3b3b14a
parent 23939 56087fa8788d
child 23941 a4db5fde5ca2
Fixed bug 26969: "There is a difference" field is not work as expected
modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js
--- a/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js	Mon Jun 30 18:29:05 2014 +0200
+++ b/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js	Mon Jun 30 18:20:18 2014 +0200
@@ -382,12 +382,20 @@
       receivedFrom = form.getItem('received_from').getValue() || '',
       totalGLItems = new BigDecimal(String(form.getItem('amount_gl_items').getValue() || 0)),
       diffAmt = actualPayment.add(credit).subtract(total),
-      expectedDiffAmt = expectedPayment.add(credit).subtract(total).add(totalGLItems);
-  differenceItem.setValue(Number(diffAmt.toString()));
-  if (expectedDiffAmt.signum() === 0) {
-    expectedDifferenceItem.setValue(Number(diffAmt.toString()));
+      amount = total;
+
+  if ((actualPayment.signum() === 0) || (actualPayment.compareTo(expectedPayment) > 0)) {
+    amount = actualPayment;
+  }
+  if (credit.signum() !== 0) {
+    amount = amount.add(credit);
+  }
+  if (expectedPayment.compareTo(total.abs()) > 0) {
+    differenceItem.setValue(Number(expectedPayment.subtract(total)));
+  } else if (amount.compareTo(total) > 0) {
+    differenceItem.setValue(Number(amount.subtract(total)));
   } else {
-    expectedDifferenceItem.setValue(Number(expectedDiffAmt.toString()));
+    differenceItem.setValue(Number('0'));
   }
   if (diffAmt.signum() !== 0) {
     OB.APRM.AddPayment.updateDifferenceActions(form);