[Add Payment] Fixes grid pagination
authorEduardo Argal Guibert <eduardo.argal@openbravo.com>
Wed, 18 Jun 2014 19:29:16 +0200
changeset 23838 2fc1f1561afa
parent 23837 3c4d4a1e1c87
child 23839 855e52dc0e16
[Add Payment] Fixes grid pagination
modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js
modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/HQLDataSourceService.java
--- a/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js	Wed Jun 18 18:29:49 2014 +0200
+++ b/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js	Wed Jun 18 19:29:16 2014 +0200
@@ -286,10 +286,13 @@
   // add credit amount
   amount = amount.add(creditamt);
 
+  var orderInvoiceData = orderInvoice.data.localData;
   for (i = 0; i < total; i++) {
-    outstandingAmount = new BigDecimal(String(orderInvoice.getRecord(i).outstandingAmount));
-    if (outstandingAmount.signum() < 0) {
-      negativeamt = negativeamt.add(new BigDecimal(Math.abs(outstandingAmount).toString()));
+    if (isc.isA.Object(orderInvoiceData[i]) && !isc.isA.emptyObject(orderInvoiceData[i])) {
+      outstandingAmount = new BigDecimal(String(orderInvoiceData[i].outstandingAmount));
+      if (outstandingAmount.signum() < 0) {
+        negativeamt = negativeamt.add(new BigDecimal(Math.abs(outstandingAmount).toString()));
+      }        
     }
   }
 
@@ -298,6 +301,9 @@
   }
 
   for (i = 0; i < total; i++) {
+    if (!isc.isA.Object(orderInvoice.getEditValues(i)) || isc.isA.emptyObject(orderInvoice.getEditValues(i))) {
+      continue;
+    }
     writeoff = orderInvoice.getEditValues(i).writeoff;
     amt = new BigDecimal(String(orderInvoice.getEditValues(i).amount || 0));
     if (writeoff === null || writeoff === undefined) {
@@ -530,7 +536,7 @@
       grid = form.getItem('glitem').canvas.viewGrid,
       receivedInField = grid.getFieldByColumnName('received_in'),
       paidOutField = grid.getFieldByColumnName('paid_out'),
-      allRecords = grid.data.allRows.length || 0,
+      allRecords = (grid.data.allRows) ? grid.data.allRows.length : 0,
       glItemTotalItem = form.getItem('amount_gl_items'),
       issotrx = form.getItem('issotrx').getValue(),
       amt, i, bdAmt, receivedInAmt, paidOutAmt;
@@ -792,4 +798,4 @@
     selectedRecords: selectedRecords,
     finFinancialAccount: finFinancialAccount
   }, {}, callbackOnProcessActionHandler);
-};
\ No newline at end of file
+};
--- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/HQLDataSourceService.java	Wed Jun 18 18:29:49 2014 +0200
+++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/HQLDataSourceService.java	Wed Jun 18 19:29:16 2014 +0200
@@ -31,6 +31,7 @@
 import org.apache.commons.lang.StringUtils;
 import org.codehaus.jettison.json.JSONObject;
 import org.hibernate.Query;
+import org.hibernate.ScrollableResults;
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.ModelProvider;
 import org.openbravo.base.model.Property;
@@ -127,15 +128,13 @@
     Table table = getTableFromParameters(parameters);
     boolean justCount = true;
     Query countQuery = getQuery(table, parameters, justCount);
-    String hqlQuery = countQuery.getQueryString();
     int nRows = -1;
-    if (hqlQuery.toUpperCase().contains(GROUPBY)) {
-      // No risk in using list, the request is done always paginated
-      nRows = countQuery.list().size();
-    } else {
-      nRows = ((Number) countQuery.uniqueResult()).intValue();
+    ScrollableResults scrollableResults = countQuery.scroll();
+    if (scrollableResults.last()) {
+      nRows = scrollableResults.getRowNumber();
+      scrollableResults.close();
     }
-    return nRows;
+    return nRows + 1;
   }
 
   @Override