Fixes issue when sorting names with blank spaces inside
authorDavid Miguelez <david.miguelez@openbravo.com>
Wed, 15 Feb 2012 20:13:48 +0100
changeset 15494 5bef43263107
parent 15493 41eecb6a3b4f
child 15495 0d2a19dc7dea
Fixes issue when sorting names with blank spaces inside
modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.html
modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportDao.java
--- a/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.html	Wed Feb 15 19:10:02 2012 +0100
+++ b/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.html	Wed Feb 15 20:13:48 2012 +0100
@@ -105,8 +105,8 @@
         return true;
     }
     function onLoadDo(){
-    	
-    	  var selectedGroupBy = null;
+      
+        var selectedGroupBy = null;
         var groupby = null;
         
         this.windowTables = new Array(
@@ -516,51 +516,6 @@
                   </td>
                 </tr>               
                 <tr>
-                  <td class="TitleCell"><span class="LabelText">Amount From</span></td>
-                  <td class="TextBox_btn_ContentCell">
-                    <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
-                      <tr>
-                        <td class="TextBox_ContentCell">
-                          <input dojoType="openbravo:RealNumberTextbox" lowerThan="paramAmountTo" class="TextBox_btn_OneCell_width" type="text" name="inpAmountFrom" id="paramAmountFrom" maxlength="10" value="" outputformat="euroEdition"></input><script>djConfig.searchIds.push("paramAmountFrom");</script>
-                        </td>
-                        <td class="FieldButton_ContentCell">
-                          <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Calendar'; return true;" onblur="window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;" onclick="calculator('frmMain.inpAmountFrom', document.frmMain.inpAmountFrom.value);return false;">
-                            <table class="FieldButton"  onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='Show calculator';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;">
-                              <tr>
-                                <td class="FieldButton_bg">
-                                  <img alt="Calendar" class="FieldButton_Icon FieldButton_Icon_Calc" title="Calendar" src="../../../../../web/images/blank.gif" border="0"></img>
-                                </td>
-                              </tr>
-                            </table>
-                          </a>
-                        </td>
-                      </tr>
-                    </table>
-                  </td>
-                  <td class="ContentCell"></td>
-                  <td class="ContentCell"></td>
-                  <td class="TitleCell"><span class="LabelText">Amount To</span></td>
-                  <td class="TextBox_btn_ContentCell">
-                    <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
-                      <tr>
-                        <td class="TextBox_ContentCell">
-                          <input dojoType="openbravo:RealNumberTextbox" greaterThan="paramAmountFrom" class="TextBox_btn_OneCell_width" type="text" name="inpAmountTo" id="paramAmountTo" maxlength="10" value="" outputformat="euroEdition"></input><script>djConfig.searchIds.push("paramAmountTo");</script>
-                        </td>
-                        <td class="FieldButton_ContentCell">
-                          <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Calendar'; return true;" onblur="window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;" onclick="calculator('frmMain.inpAmountTo', document.frmMain.inpAmountTo.value);return false;">
-                            <table class="FieldButton"  onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='Show calculator';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;">
-                              <tr>
-                                <td class="FieldButton_bg">
-                                  <img alt="Calendar" class="FieldButton_Icon FieldButton_Icon_Calc" title="Calendar" src="../../../../../web/images/blank.gif" border="0"></img>
-                                </td>
-                              </tr>
-                            </table>
-                          </a>
-                        </td>
-                      </tr>
-                    </table>
-                  </td>
-                <tr>
                   <td class="TitleCell"><span class="LabelText">Document Date From</span></td>
                   
                   <td class="TextBox_btn_ContentCell">
@@ -654,6 +609,52 @@
                   </td>
                 </tr>
                 <tr>
+                  <td class="TitleCell"><span class="LabelText">Amount From</span></td>
+                  <td class="TextBox_btn_ContentCell">
+                    <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
+                      <tr>
+                        <td class="TextBox_ContentCell">
+                          <input dojoType="openbravo:RealNumberTextbox" lowerThan="paramAmountTo" class="TextBox_btn_OneCell_width" type="text" name="inpAmountFrom" id="paramAmountFrom" maxlength="10" value="" outputformat="euroEdition"></input><script>djConfig.searchIds.push("paramAmountFrom");</script>
+                        </td>
+                        <td class="FieldButton_ContentCell">
+                          <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Calendar'; return true;" onblur="window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;" onclick="calculator('frmMain.inpAmountFrom', document.frmMain.inpAmountFrom.value);return false;">
+                            <table class="FieldButton"  onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='Show calculator';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;">
+                              <tr>
+                                <td class="FieldButton_bg">
+                                  <img alt="Calendar" class="FieldButton_Icon FieldButton_Icon_Calc" title="Calendar" src="../../../../../web/images/blank.gif" border="0"></img>
+                                </td>
+                              </tr>
+                            </table>
+                          </a>
+                        </td>
+                      </tr>
+                    </table>
+                  </td>
+                  <td class="ContentCell"></td>
+                  <td class="ContentCell"></td>
+                  <td class="TitleCell"><span class="LabelText">Amount To</span></td>
+                  <td class="TextBox_btn_ContentCell">
+                    <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
+                      <tr>
+                        <td class="TextBox_ContentCell">
+                          <input dojoType="openbravo:RealNumberTextbox" greaterThan="paramAmountFrom" class="TextBox_btn_OneCell_width" type="text" name="inpAmountTo" id="paramAmountTo" maxlength="10" value="" outputformat="euroEdition"></input><script>djConfig.searchIds.push("paramAmountTo");</script>
+                        </td>
+                        <td class="FieldButton_ContentCell">
+                          <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Calendar'; return true;" onblur="window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;" onclick="calculator('frmMain.inpAmountTo', document.frmMain.inpAmountTo.value);return false;">
+                            <table class="FieldButton"  onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='Show calculator';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;">
+                              <tr>
+                                <td class="FieldButton_bg">
+                                  <img alt="Calendar" class="FieldButton_Icon FieldButton_Icon_Calc" title="Calendar" src="../../../../../web/images/blank.gif" border="0"></img>
+                                </td>
+                              </tr>
+                            </table>
+                          </a>
+                        </td>
+                      </tr>
+                    </table>
+                  </td>
+                </tr>
+                <tr>
                   <td class="TitleCell"><span class="LabelText">Business Partner</span></td>
                   <td class="List_ContentCell" colspan="2">
                     <table border="0" cellspacing="0" cellpadding="0">
@@ -744,7 +745,7 @@
                     </table>
                   </td>
                   <td><table>
-                   	<tr rowspan="2"><td class="TitleCell"><span class="LabelText">Business Partner Category</span></td></tr>
+                    <tr rowspan="2"><td class="TitleCell"><span class="LabelText">Business Partner Category</span></td></tr>
           <tr rowspan="3"><td class="TitleCell"><span class="LabelText">Empty Business Partner</span></td></tr>
           </table></td>
                   <td colspan="3"><table>
--- a/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportDao.java	Wed Feb 15 19:10:02 2012 +0100
+++ b/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportDao.java	Wed Feb 15 20:13:48 2012 +0100
@@ -77,6 +77,9 @@
 
   private static final long milisecDayConv = (1000 * 60 * 60 * 24);
   static Logger log4j = Logger.getLogger(Utility.class);
+  private java.util.List<String> bpList;
+  private java.util.List<String> bpCategoryList;
+  private java.util.List<String> projectList;
 
   public PaymentReportDao() {
   }
@@ -1196,27 +1199,43 @@
 
       // General boolean rule for comparation when A!=B -->[ (A<B || B="") && A!="" ]
       if (strGroupCrit.equalsIgnoreCase("APRM_FATS_BPARTNER")) {
-        if (BPName.compareTo(data.getField("BPARTNER")) == 0) {
+        if (bpList == null) {
+          createBPList();
+        }
+        int posData = bpList.indexOf(data.getField("BPARTNER"));
+        int pos = bpList.indexOf(BPName);
+
+        if (BPName.equals(data.getField("BPARTNER"))) {
           isBefore = isBeforeStatusAndOrder(transaction, data, strOrdCrit, BPName, BPCategory,
               strProject);
-        } else if ((BPName.compareTo(data.getField("BPARTNER")) < 0 || data.getField("BPARTNER")
-            .equals("")) && !BPName.equals("")) {
+        } else if ((pos < posData || data.getField("BPARTNER").equals("")) && !BPName.equals("")) {
           isBefore = true;
         }
       } else if (strGroupCrit.equalsIgnoreCase("Project")) {
-        if (strProject.compareTo(data.getField("PROJECT")) == 0) {
+        if (projectList == null) {
+          createProjectList();
+        }
+        int posData = projectList.indexOf(data.getField("PROJECT"));
+        int pos = projectList.indexOf(strProject);
+
+        if (strProject.equals(data.getField("PROJECT"))) {
           isBefore = isBeforeStatusAndOrder(transaction, data, strOrdCrit, BPName, BPCategory,
               strProject);
-        } else if ((strProject.compareTo(data.getField("PROJECT")) < 0 || data.getField("PROJECT")
-            .equals("")) && !strProject.equals("")) {
+        } else if ((pos < posData || data.getField("PROJECT").equals("")) && !strProject.equals("")) {
           isBefore = true;
         }
       } else if (strGroupCrit.equalsIgnoreCase("FINPR_BPartner_Category")) {
-        if (BPCategory.compareTo(data.getField("BP_GROUP")) == 0) {
+        if (bpCategoryList == null) {
+          createBPCategoryList();
+        }
+        int posData = bpList.indexOf(data.getField("BP_GROUP"));
+        int pos = bpList.indexOf(BPCategory);
+
+        if (BPCategory.equals(data.getField("BP_GROUP"))) {
           isBefore = isBeforeStatusAndOrder(transaction, data, strOrdCrit, BPName, BPCategory,
               strProject);
-        } else if ((BPCategory.toString().compareTo(data.getField("BP_GROUP")) < 0 || data
-            .getField("BP_GROUP").equals("")) && !BPCategory.equals("")) {
+        } else if ((pos < posData || data.getField("BP_GROUP").equals(""))
+            && !BPCategory.equals("")) {
           isBefore = true;
         }
       } else if (strGroupCrit.equalsIgnoreCase("INS_CURRENCY")) {
@@ -1275,49 +1294,91 @@
 
     if (i == strOrdCritList.length - 1) {
       if (strOrdCritList[i].contains("Project")) {
+        if (projectList == null) {
+          createProjectList();
+        }
+        int posData = projectList.indexOf(data.getField("PROJECT"));
+        int pos = projectList.indexOf(strProject);
+
         isBefore = isBefore
-            || (((strProject.compareTo(data.getField("PROJECT")) < 0) || data.getField("PROJECT")
-                .equals("")) && !strProject.equals(""));
+            || (((pos < posData) || data.getField("PROJECT").equals("")) && !strProject.equals(""));
       }
       if (strOrdCritList[i].contains("FINPR_BPartner_Category")) {
+        if (bpCategoryList == null) {
+          createBPCategoryList();
+        }
+        int posData = bpCategoryList.indexOf(data.getField("BP_GROUP"));
+        int pos = bpCategoryList.indexOf(BPCategory);
+
         isBefore = isBefore
-            || (((BPCategory.compareTo(data.getField("BP_GROUP")) < 0) || data.getField("BP_GROUP")
-                .equals("")) && !BPCategory.equals(""));
+            || (((pos < posData) || data.getField("BP_GROUP").equals("")) && !BPCategory.equals(""));
       }
       if (strOrdCritList[i].contains("APRM_FATS_BPARTNER")) {
+        if (bpList == null) {
+          createBPList();
+        }
+        int posData = bpList.indexOf(data.getField("BPARTNER"));
+        int pos = bpList.indexOf(BPName);
+
         isBefore = isBefore
-            || (((BPName.compareTo(data.getField("BPARTNER")) < 0) || data.getField("BPARTNER")
-                .equals("")) && !BPName.equals(""));
+            || (((pos < posData) || data.getField("BPARTNER").equals("")) && !BPName.equals(""));
       }
       if (strOrdCritList[i].contains("INS_CURRENCY")) {
         isBefore = isBefore
             || (transaction.getCurrency().getISOCode().toString()
                 .compareTo(data.getField("TRANS_CURRENCY")) < 0);
       }
+      if (strOrdCritList[i].contains("Date")) {
+        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
+        try {
+          Date transactionDate = sdf.parse(strOrdCritList[i].toString());
+          Date dataDate = sdf.parse(data.getField("DUE_DATE"));
+          if (transactionDate.before(dataDate)) {
+            isBefore = true;
+          }
+        } catch (ParseException e) {
+          // Exception parsing date
+          log4j.error(e.getMessage(), e);
+        }
+      }
       return isBefore;
     } else {
       if (strOrdCritList[i].contains("Project")) {
-        if ((strProject.compareTo(data.getField("PROJECT")) < 0 || data.getField("PROJECT").equals(
-            ""))
-            && !strProject.equals("")) {
+        if (projectList == null) {
+          createProjectList();
+        }
+        int posData = projectList.indexOf(data.getField("PROJECT"));
+        int pos = projectList.indexOf(strProject);
+
+        if ((pos < posData || data.getField("PROJECT").equals("")) && !strProject.equals("")) {
           isBefore = true;
-        } else if (strProject.compareTo(data.getField("PROJECT")) == 0) {
+        } else if (strProject.equals(data.getField("PROJECT"))) {
           isBefore = isBeforeOrder(transaction, data, strOrdCritList, i + 1, BPName, BPCategory,
               strProject);
         }
       } else if (strOrdCritList[i].contains("FINPR_BPartner_Category")) {
-        if ((BPCategory.compareTo(data.getField("BP_GROUP")) < 0 || data.getField("BP_GROUP")
-            .equals("")) && !BPCategory.equals("")) {
+        if (bpCategoryList == null) {
+          createBPCategoryList();
+        }
+        int posData = bpCategoryList.indexOf(data.getField("BP_GROUP"));
+        int pos = bpCategoryList.indexOf(BPCategory);
+
+        if ((pos < posData || data.getField("BP_GROUP").equals("")) && !BPCategory.equals("")) {
           isBefore = true;
-        } else if (BPCategory.toString().compareTo(data.getField("BP_GROUP")) == 0) {
+        } else if (BPCategory.toString().equals(data.getField("BP_GROUP"))) {
           isBefore = isBeforeOrder(transaction, data, strOrdCritList, i + 1, BPName, BPCategory,
               strProject);
         }
       } else if (strOrdCritList[i].contains("APRM_FATS_BPARTNER")) {
-        if ((BPName.compareTo(data.getField("BPARTNER")) < 0 || data.getField("BPARTNER")
-            .equals("")) && !BPName.equals("")) {
+        if (bpList == null) {
+          createBPList();
+        }
+        int posData = bpList.indexOf(data.getField("BPARTNER"));
+        int pos = bpList.indexOf(BPName);
+
+        if ((pos < posData || data.getField("BPARTNER").equals("")) && !BPName.equals("")) {
           isBefore = true;
-        } else if (BPName.compareTo(data.getField("BPARTNER")) == 0) {
+        } else if (BPName.equals(data.getField("BPARTNER"))) {
           isBefore = isBeforeOrder(transaction, data, strOrdCritList, i + 1, BPName, BPCategory,
               strProject);
         }
@@ -1898,4 +1959,32 @@
     return organizations;
   }
 
+  private void createBPList() {
+    bpList = new ArrayList<String>();
+    OBCriteria<BusinessPartner> critBPartner = OBDal.getInstance().createCriteria(
+        BusinessPartner.class);
+    critBPartner.addOrderBy(BusinessPartner.PROPERTY_NAME, true);
+    for (BusinessPartner bp : critBPartner.list()) {
+      bpList.add(bp.getName());
+    }
+  }
+
+  private void createBPCategoryList() {
+    bpCategoryList = new ArrayList<String>();
+    OBCriteria<Category> critBPCategory = OBDal.getInstance().createCriteria(Category.class);
+    critBPCategory.addOrderBy(Category.PROPERTY_NAME, true);
+    for (Category bpc : critBPCategory.list()) {
+      bpCategoryList.add(bpc.getName());
+    }
+  }
+
+  private void createProjectList() {
+    projectList = new ArrayList<String>();
+    OBCriteria<Project> critProject = OBDal.getInstance().createCriteria(Project.class);
+    critProject.addOrderBy(Project.PROPERTY_NAME, true);
+    for (Project project : critProject.list()) {
+      projectList.add(project.getName());
+    }
+  }
+
 }