[aprm-windows]fixes in generate credit and actual payment
authorSandra Huguet <sandra.huguet@openbravo.com>
Thu, 05 Jun 2014 11:33:12 +0200
changeset 23706 b859f9f030b4
parent 23705 15cc78043f81
child 23707 a2e9e7b7fb08
[aprm-windows]fixes in generate credit and actual payment
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_ELEMENT.xml
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/AddPaymentDefaultValuesExpression.java
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/AddPaymentDefaultValuesHandler.java
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/PaymentOutAddPaymentDefaultValues.java
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/hqlinjections/AddPaymentOrderInvoicesTransformer.java
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java
modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_ELEMENT.xml	Thu Jun 05 08:38:17 2014 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_ELEMENT.xml	Thu Jun 05 11:33:12 2014 +0200
@@ -168,6 +168,18 @@
 <!--4AC57284C5C745EB9087C105222EDF02-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
 <!--4AC57284C5C745EB9087C105222EDF02--></AD_ELEMENT>
 
+<!--4BFB1532D2684F2B9997BF3B5555BFCB--><AD_ELEMENT>
+<!--4BFB1532D2684F2B9997BF3B5555BFCB-->  <AD_ELEMENT_ID><![CDATA[4BFB1532D2684F2B9997BF3B5555BFCB]]></AD_ELEMENT_ID>
+<!--4BFB1532D2684F2B9997BF3B5555BFCB-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--4BFB1532D2684F2B9997BF3B5555BFCB-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--4BFB1532D2684F2B9997BF3B5555BFCB-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--4BFB1532D2684F2B9997BF3B5555BFCB-->  <COLUMNNAME><![CDATA[generateCredit]]></COLUMNNAME>
+<!--4BFB1532D2684F2B9997BF3B5555BFCB-->  <NAME><![CDATA[Generate Credit]]></NAME>
+<!--4BFB1532D2684F2B9997BF3B5555BFCB-->  <PRINTNAME><![CDATA[Generate Credit]]></PRINTNAME>
+<!--4BFB1532D2684F2B9997BF3B5555BFCB-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--4BFB1532D2684F2B9997BF3B5555BFCB-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
+<!--4BFB1532D2684F2B9997BF3B5555BFCB--></AD_ELEMENT>
+
 <!--519F3CD67106443CBF25694F1BB6E92B--><AD_ELEMENT>
 <!--519F3CD67106443CBF25694F1BB6E92B-->  <AD_ELEMENT_ID><![CDATA[519F3CD67106443CBF25694F1BB6E92B]]></AD_ELEMENT_ID>
 <!--519F3CD67106443CBF25694F1BB6E92B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml	Thu Jun 05 08:38:17 2014 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml	Thu Jun 05 11:33:12 2014 +0200
@@ -686,6 +686,29 @@
 <!--A95732C0B3794D79B2E945D50872D931-->  <DISPLAYTITLE><![CDATA[N]]></DISPLAYTITLE>
 <!--A95732C0B3794D79B2E945D50872D931--></OBUIAPP_PARAMETER>
 
+<!--ACCFACE260B24599969EC724A567EB28--><OBUIAPP_PARAMETER>
+<!--ACCFACE260B24599969EC724A567EB28-->  <OBUIAPP_PARAMETER_ID><![CDATA[ACCFACE260B24599969EC724A567EB28]]></OBUIAPP_PARAMETER_ID>
+<!--ACCFACE260B24599969EC724A567EB28-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--ACCFACE260B24599969EC724A567EB28-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--ACCFACE260B24599969EC724A567EB28-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--ACCFACE260B24599969EC724A567EB28-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--ACCFACE260B24599969EC724A567EB28-->  <NAME><![CDATA[Generate Credit]]></NAME>
+<!--ACCFACE260B24599969EC724A567EB28-->  <SEQNO><![CDATA[1080]]></SEQNO>
+<!--ACCFACE260B24599969EC724A567EB28-->  <AD_REFERENCE_ID><![CDATA[12]]></AD_REFERENCE_ID>
+<!--ACCFACE260B24599969EC724A567EB28-->  <COLUMNNAME><![CDATA[generateCredit]]></COLUMNNAME>
+<!--ACCFACE260B24599969EC724A567EB28-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--ACCFACE260B24599969EC724A567EB28-->  <FIELDLENGTH><![CDATA[0]]></FIELDLENGTH>
+<!--ACCFACE260B24599969EC724A567EB28-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--ACCFACE260B24599969EC724A567EB28-->  <ISFIXED><![CDATA[N]]></ISFIXED>
+<!--ACCFACE260B24599969EC724A567EB28-->  <EVALUATEFIXEDVALUE><![CDATA[N]]></EVALUATEFIXEDVALUE>
+<!--ACCFACE260B24599969EC724A567EB28-->  <OBUIAPP_PROCESS_ID><![CDATA[9BED7889E1034FE68BD85D5D16857320]]></OBUIAPP_PROCESS_ID>
+<!--ACCFACE260B24599969EC724A567EB28-->  <STARTINNEWLINE><![CDATA[N]]></STARTINNEWLINE>
+<!--ACCFACE260B24599969EC724A567EB28-->  <DISPLAYLOGIC><![CDATA[false]]></DISPLAYLOGIC>
+<!--ACCFACE260B24599969EC724A567EB28-->  <READONLYLOGIC><![CDATA[true]]></READONLYLOGIC>
+<!--ACCFACE260B24599969EC724A567EB28-->  <DISPLAYEDROWS><![CDATA[5]]></DISPLAYEDROWS>
+<!--ACCFACE260B24599969EC724A567EB28-->  <DISPLAYTITLE><![CDATA[Y]]></DISPLAYTITLE>
+<!--ACCFACE260B24599969EC724A567EB28--></OBUIAPP_PARAMETER>
+
 <!--B2E975E0ADE3445C90DA81F0F492EA1C--><OBUIAPP_PARAMETER>
 <!--B2E975E0ADE3445C90DA81F0F492EA1C-->  <OBUIAPP_PARAMETER_ID><![CDATA[B2E975E0ADE3445C90DA81F0F492EA1C]]></OBUIAPP_PARAMETER_ID>
 <!--B2E975E0ADE3445C90DA81F0F492EA1C-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/AddPaymentDefaultValuesExpression.java	Thu Jun 05 08:38:17 2014 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/AddPaymentDefaultValuesExpression.java	Thu Jun 05 11:33:12 2014 +0200
@@ -91,6 +91,8 @@
           return handler.getDefaultConvertedAmount(requestMap);
         case StandardPrecision:
           return handler.getDefaultStandardPrecision(requestMap);
+        case GenerateCredit:
+          return handler.getDefaultGeneratedCredit(requestMap);
         }
       } catch (Exception e) {
         log.error("Error trying to get default value of " + strCurrentParam + e.getMessage(), e);
@@ -134,7 +136,7 @@
         "fin_paymentmethod_id"), TransactionType("transaction_type"), CustomerCredit(
         "customer_credit"), IsSOTrx("issotrx"), Payment("fin_payment_id"), Invoice("c_invoice_id"), Order(
         "c_order_id"), ConversionRate("conversion_rate"), ConvertedAmount("converted_amount"), StandardPrecision(
-        "StdPrecision");
+        "StdPrecision"), GenerateCredit("generateCredit");
 
     private String columnname;
 
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/AddPaymentDefaultValuesHandler.java	Thu Jun 05 08:38:17 2014 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/AddPaymentDefaultValuesHandler.java	Thu Jun 05 11:33:12 2014 +0200
@@ -198,4 +198,9 @@
     }
     return pendingAmt;
   }
+
+  String getDefaultGeneratedCredit(Map<String, String> requestMap) throws JSONException {
+    BigDecimal generateCredit = BigDecimal.ZERO;
+    return generateCredit.toPlainString();
+  }
 }
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/PaymentOutAddPaymentDefaultValues.java	Thu Jun 05 08:38:17 2014 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/PaymentOutAddPaymentDefaultValues.java	Thu Jun 05 11:33:12 2014 +0200
@@ -40,18 +40,24 @@
   @Override
   String getDefaultExpectedAmount(Map<String, String> requestMap) throws JSONException {
     // Expected amount is the amount on the editing payment
-    BigDecimal pendingAmt = getPayment(requestMap).getGeneratedCredit();
+    BigDecimal pendingAmt = getPayment(requestMap).getAmount();
     return pendingAmt.toPlainString();
   }
 
   @Override
   String getDefaultActualAmount(Map<String, String> requestMap) throws JSONException {
     // Actual amount is the amount on the editing payment
-    BigDecimal pendingAmt = getPayment(requestMap).getGeneratedCredit();
+    BigDecimal pendingAmt = getPayment(requestMap).getAmount();
     return pendingAmt.toPlainString();
   }
 
   @Override
+  String getDefaultGeneratedCredit(Map<String, String> requestMap) throws JSONException {
+    BigDecimal generateCredit = getPayment(requestMap).getGeneratedCredit();
+    return generateCredit.toPlainString();
+  }
+
+  @Override
   String getDefaultIsSOTrx(Map<String, String> requestMap) {
     return "N";
   }
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/hqlinjections/AddPaymentOrderInvoicesTransformer.java	Thu Jun 05 08:38:17 2014 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/hqlinjections/AddPaymentOrderInvoicesTransformer.java	Thu Jun 05 11:33:12 2014 +0200
@@ -126,7 +126,7 @@
     selectClause
         .append(" COALESCE(inv.grandTotalAmount, ord.grandTotalAmount) as invoicedAmount, ");
     selectClause.append(" SUM(psd.amount) as outstandingAmount, ");
-    selectClause.append(" 0 as amount, ");
+    selectClause.append(" sum(fp.amount) as amount, ");
     selectClause.append(" case when 0 < 1 then false else true end as writeoff, ");
     if (hasSelectedIds) {
       // if there are selected ids selection is done in the client.
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java	Thu Jun 05 08:38:17 2014 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java	Thu Jun 05 11:33:12 2014 +0200
@@ -942,11 +942,10 @@
           }
 
           payment.getFINPaymentCreditList().clear();
-
+          if (payment.isReceipt() || strAction.equals("R")) {
+            payment.setGeneratedCredit(BigDecimal.ZERO);
+          }
           if (strAction.equals("R")) {
-            if (payment.isReceipt()) {
-              payment.setGeneratedCredit(BigDecimal.ZERO);
-            }
             payment.setUsedCredit(BigDecimal.ZERO);
             for (FIN_PaymentScheduleDetail psd : removedPDS) {
               List<FIN_PaymentPropDetail> ppds = psd.getFINPaymentPropDetailList();
--- a/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js	Thu Jun 05 08:38:17 2014 +0200
+++ b/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js	Thu Jun 05 11:33:12 2014 +0200
@@ -105,7 +105,6 @@
   glitemGrid.removeRecordClick = OB.APRM.AddPayment.removeRecordClick;
   creditUseGrid.selectionChanged = OB.APRM.AddPayment.selectionChangedCredit;
   orderInvoiceGrid.dataArrived = OB.APRM.AddPayment.ordInvDataArrived;
-  OB.APRM.AddPayment.updateDiffereceOff(view.theForm);
 
 };
 
@@ -200,19 +199,21 @@
 
 OB.APRM.AddPayment.actualPaymentOnLoad = function (view) {
 
-  var orderInvoiceGrid = view.theForm.getItem('order_invoice').canvas.viewGrid;
+  var orderInvoiceGrid = view.theForm.getItem('order_invoice').canvas.viewGrid,
+      issotrx = view.theForm.getItem('issotrx').getValue(),
+      payment = view.theForm.getItem('fin_payment_id').getValue(),
+      form = view.theForm;
   if (!isc.isA.ResultSet(orderInvoiceGrid.data) || !orderInvoiceGrid.data.lengthIsKnown()) {
     setTimeout(function () {
       OB.APRM.AddPayment.actualPaymentOnLoad(view);
     }, 500);
     return;
   }
-  var issotrx = view.theForm.getItem('issotrx').getValue(),
-      payment = view.theForm.getItem('fin_payment_id').getValue(),
-      form = view.theForm;
   if (!(!issotrx && payment)) {
     OB.APRM.AddPayment.distributeAmount(view, form);
   }
+  OB.APRM.AddPayment.updateActualExpected(view.theForm);
+  OB.APRM.AddPayment.updateDiffereceOff(view.theForm);
 
 };
 
@@ -235,7 +236,7 @@
   var amount = new BigDecimal(String(form.getItem('actual_payment').getValue() || 0)),
       distributedAmount = new BigDecimal("0"),
       orderInvoice = form.getItem('order_invoice').canvas.viewGrid,
-      scheduledPaymentDetailId, outstandingAmount, j, i, total, chk, credit, glitem;
+      scheduledPaymentDetailId, outstandingAmount, j, i, total, chk, credit, glitem, difference = new BigDecimal(String(form.getItem('difference').getValue() || 0));
 
   // glitems amount
   glitem = new BigDecimal(String(form.getItem('amount_gl_items').getValue() || 0));
@@ -293,7 +294,6 @@
   totalAmt = totalAmt.add(new BigDecimal(String(glItemsTotalItem.getValue() || 0)));
 
   totalItem.setValue(Number(totalAmt.toString()));
-  OB.APRM.AddPayment.updateDiffereceOff(form);
 };
 
 OB.APRM.AddPayment.updateDiffereceOff = function (form) {
@@ -347,11 +347,7 @@
   var orderInvoice = view.theForm.getItem('order_invoice').canvas.viewGrid,
       amount = new BigDecimal(String(view.theForm.getItem('actual_payment').getValue() || 0)),
       distributedAmount = new BigDecimal(String(view.theForm.getItem('amount_inv_ords').getValue() || 0)),
-      total, outstandingAmount, selectedIds, glitem, credit, actualPayment = view.theForm.getItem('actual_payment'),
-      expectedPayment = view.theForm.getItem('expected_payment'),
-      actualPaymentAmount, expectedPaymentAmount, totalAmount, i, totalAmountoutstanding = BigDecimal.prototype.ZERO,
-      difference = new BigDecimal(String(view.theForm.getItem('difference').getValue() || 0)),
-      payment = view.theForm.getItem('fin_payment_id').getValue();
+      total, outstandingAmount, selectedIds, glitem, credit, actualPaymentAmount, expectedPaymentAmount, totalAmount, i, issotrx = view.theForm.getItem('issotrx').getValue();
 
   selectedIds = orderInvoice.selectedIds;
   outstandingAmount = new BigDecimal(String(record.outstandingAmount));
@@ -363,7 +359,7 @@
   // credit amount
   credit = new BigDecimal(String(view.theForm.getItem('used_credit').getValue() || 0));
   amount = amount.add(credit);
-  var issotrx = view.theForm.getItem('issotrx').getValue();
+
   if (issotrx) {
     if (amount.signum() !== 0 && state) {
       if ((outstandingAmount.compareTo(new BigDecimal("0")) < 0) && (amount.compareTo(new BigDecimal("0")) < 0)) {
@@ -382,40 +378,45 @@
         orderInvoice.setEditValue(orderInvoice.getRecordIndex(record), 'amount', Number(outstandingAmount.toString()));
       }
     }
-    for (i = 0; i < selectedIds.length; i++) {
-      outstandingAmount = new BigDecimal(String(orderInvoice.getRecord(i).outstandingAmount));
-      totalAmountoutstanding = totalAmountoutstanding.add(outstandingAmount);
-    }
-    if (selectedIds.length > 0) {
-      expectedPayment.setValue(Number(totalAmountoutstanding));
-    } else {
-      expectedPayment.setValue(Number('0'));
-    }
 
   } else {
-    totalAmount = BigDecimal.prototype.ZERO;
-
     for (i = 0; i < selectedIds.length; i++) {
       if (selectedIds[i] === record.id) {
         orderInvoice.setEditValue(orderInvoice.getRecordIndex(record), 'amount', Number(outstandingAmount.toString()));
       }
-      totalAmount = totalAmount.add(new BigDecimal(String(orderInvoice.getEditedCell(i, 'amount') || 0)));
-    }
-    if (selectedIds.length > 0) {
-      actualPaymentAmount = new BigDecimal(String(view.theForm.getItem('actual_payment').getValue() || 0));
-      actualPayment.setValue(Number((totalAmount.add(difference)).toString()));
-      expectedPaymentAmount = new BigDecimal(String(view.theForm.getItem('expected_payment').getValue() || 0));
-      expectedPayment.setValue(Number((totalAmount.add(difference)).toString()));
-    } else {
-      if (payment) {
-        actualPayment.setValue(Number(difference));
-      } else {
-        actualPayment.setValue(Number(new BigDecimal(String(orderInvoice.getEditedCell(0, 'outstandingAmount') || 0))));
-      }
-      expectedPayment.setValue(Number('0'));
     }
   }
   OB.APRM.AddPayment.updateInvOrderTotal(view.theForm, orderInvoice);
+  OB.APRM.AddPayment.updateActualExpected(view.theForm);
+  OB.APRM.AddPayment.updateDiffereceOff(view.theForm);
+
+
+};
+
+OB.APRM.AddPayment.updateActualExpected = function (form) {
+  var orderInvoice = form.getItem('order_invoice').canvas.viewGrid,
+      issotrx = form.getItem('issotrx').getValue(),
+      totalAmountoutstanding = BigDecimal.prototype.ZERO,
+      difference = new BigDecimal(String(form.getItem('difference').getValue() || 0)),
+      totalAmount = BigDecimal.prototype.ZERO,
+      selectedIds, actualPayment = form.getItem('actual_payment'),
+      actualPaymentAmt = new BigDecimal(String(form.getItem('actual_payment').getValue() || 0)),
+      expectedPayment = form.getItem('expected_payment'),
+      generateCredit = new BigDecimal(String(form.getItem('generateCredit').getValue() || 0)),
+      i;
+  selectedIds = orderInvoice.selectedIds;
+  for (i = 0; i < selectedIds.length; i++) {
+    totalAmountoutstanding = totalAmountoutstanding.add(new BigDecimal(String(orderInvoice.getEditedCell(i, orderInvoice.getFieldByColumnName('outstandingAmount')))));
+    totalAmount = totalAmount.add(new BigDecimal(String(orderInvoice.getEditedCell(i, orderInvoice.getFieldByColumnName('amount')))));
+  }
+  if (selectedIds.length > 0) {
+    expectedPayment.setValue(Number(totalAmountoutstanding));
+  } else {
+    expectedPayment.setValue(Number('0'));
+  }
+  if (!issotrx) {
+    actualPayment.setValue(Number(totalAmount.add(generateCredit)));
+  }
 };
 
 OB.APRM.AddPayment.removeRecordClick = function (rowNum, record) {