Related to issue 34345: Code review improvements
authorMark <markmm82@gmail.com>
Mon, 16 Jan 2017 13:15:25 -0500
changeset 31487 a75ea21e11ec
parent 31486 d8929499d9ff
child 31488 a09d6ae570dd
Related to issue 34345: Code review improvements

Some code review improvements to check the amounts are GREATER THAN (not equals)
and/or LESS THAN (not equals) the filters provided in the UI. If there is not any
amount filter defined then it is not necessary to include a "HAVING" clause to the
query.

Applied these changes to Sales and Purchase Orders reports.
src/org/openbravo/erpCommon/ad_reports/ReportPurchaseDimensionalAnalysesJR.java
src/org/openbravo/erpCommon/ad_reports/ReportSalesDimensionalAnalyzeJR.java
--- a/src/org/openbravo/erpCommon/ad_reports/ReportPurchaseDimensionalAnalysesJR.java	Mon Jan 02 17:15:14 2017 -0500
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportPurchaseDimensionalAnalysesJR.java	Mon Jan 16 13:15:25 2017 -0500
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2015 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -457,16 +457,19 @@
       strOrderby = " ORDER BY 1";
     }
     String strHaving = "";
-    if (!strMayor.equals("") && !strMenor.equals("")) {
-      strHaving = " HAVING (SUM(CONVAMOUNT) >= " + strMayor + " AND SUM(CONVAMOUNT) <= " + strMenor
+    if (!strMayor.isEmpty() && !strMenor.isEmpty()) {
+      // "Greater than" and "Less than" filters are defined
+      strHaving = " HAVING (SUM(CONVAMOUNT) > " + strMayor + " AND SUM(CONVAMOUNT) < " + strMenor
           + ")";
-    } else if (!strMayor.equals("") && strMenor.equals("")) {
-      strHaving = " HAVING (SUM(CONVAMOUNT) >= " + strMayor + ")";
-    } else if (strMayor.equals("") && !strMenor.equals("")) {
-      strHaving = " HAVING (SUM(CONVAMOUNT) <= " + strMenor + ")";
-    } else {
-      strHaving = " HAVING ((SUM(CONVAMOUNT) >= 0 OR SUM(CONVAMOUNTREF) >= 0) OR (SUM(CONVAMOUNT) <= 0 OR SUM(CONVAMOUNTREF) <= 0))";
+    } else if (!strMayor.isEmpty() && strMenor.isEmpty()) {
+      // Only "Greater than" filter is defined
+      strHaving = " HAVING (SUM(CONVAMOUNT) > " + strMayor + ")";
+    } else if (strMayor.isEmpty() && !strMenor.isEmpty()) {
+      // Only "Less than" filter is defined
+      strHaving = " HAVING (SUM(CONVAMOUNT) < " + strMenor + ")";
     }
+    // If "Greater than" and "Less than" filters are not defined it is not necessary to add the
+    // Having clause
     strOrderby = strHaving + strOrderby;
 
     // Checks if there is a conversion rate for each of the transactions of
--- a/src/org/openbravo/erpCommon/ad_reports/ReportSalesDimensionalAnalyzeJR.java	Mon Jan 02 17:15:14 2017 -0500
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportSalesDimensionalAnalyzeJR.java	Mon Jan 16 13:15:25 2017 -0500
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2015 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -597,16 +597,19 @@
       strOrderby = " ORDER BY 1";
     }
     String strHaving = "";
-    if (!strMayor.equals("") && !strMenor.equals("")) {
-      strHaving = " HAVING (SUM(CONVAMOUNT) >= " + strMayor + " AND SUM(CONVAMOUNT) < " + strMenor
+    if (!strMayor.isEmpty() && !strMenor.isEmpty()) {
+      // "Greater than" and "Less than" filters are defined
+      strHaving = " HAVING (SUM(CONVAMOUNT) > " + strMayor + " AND SUM(CONVAMOUNT) < " + strMenor
           + ")";
-    } else if (!strMayor.equals("") && strMenor.equals("")) {
-      strHaving = " HAVING (SUM(CONVAMOUNT) >= " + strMayor + ")";
-    } else if (strMayor.equals("") && !strMenor.equals("")) {
-      strHaving = " HAVING (SUM(CONVAMOUNT) <= " + strMenor + ")";
-    } else {
-      strHaving = " HAVING ((SUM(CONVAMOUNT) >= 0 OR SUM(CONVAMOUNTREF) >= 0) OR (SUM(CONVAMOUNT) <= 0 OR SUM(CONVAMOUNTREF) <= 0))";
-    }
+    } else if (!strMayor.isEmpty() && strMenor.isEmpty()) {
+      // Only "Greater than" filter is defined
+      strHaving = " HAVING (SUM(CONVAMOUNT) > " + strMayor + ")";
+    } else if (strMayor.isEmpty() && !strMenor.isEmpty()) {
+      // Only "Less than" filter is defined
+      strHaving = " HAVING (SUM(CONVAMOUNT) < " + strMenor + ")";
+    } 
+    // If "Greater than" and "Less than" filters are not defined it is not necessary to add the
+    // Having clause
     strOrderby = strHaving + strOrderby;
 
     int limit = 0;