details:   https://code.openbravo.com/erp/devel/main/rev/b00acb11b3f0
changeset: 20063:b00acb11b3f0
user:      Sandra Huguet <sandra.huguet <at> openbravo.com>
date:      Wed Apr 10 15:49:11 2013 +0200
summary:   Fixed bug 23527 Reset accounting is not work properly with filter 
dates

details:   https://code.openbravo.com/erp/devel/main/rev/68337fa5610d
changeset: 20064:68337fa5610d
user:      David Miguelez <david.miguelez <at> openbravo.com>
date:      Wed Apr 10 19:32:57 2013 +0200
summary:   Fixes Issue 23528. Adds ModuleScript for updating the column
that sets the button names.

diffstat:

 
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateOpenClosePeriodsButton.class
     |    0 
 
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateOpenClosePeriodsButtonData.class
 |    0 
 
src-util/modulescript/src/org/openbravo/modulescript/UpdateOpenClosePeriodsButton.java
                |   49 ++++++
 
src-util/modulescript/src/org/openbravo/modulescript/UpdateOpenClosePeriodsButton_data.xsql
           |   80 ++++++++++
 src/org/openbravo/financial/ResetAccounting.java                               
                       |   35 ++++-
 5 files changed, 161 insertions(+), 3 deletions(-)

diffs (198 lines):

diff -r 905aa948183a -r 68337fa5610d 
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateOpenClosePeriodsButton.class
Binary file 
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateOpenClosePeriodsButton.class
 has changed
diff -r 905aa948183a -r 68337fa5610d 
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateOpenClosePeriodsButtonData.class
Binary file 
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateOpenClosePeriodsButtonData.class
 has changed
diff -r 905aa948183a -r 68337fa5610d 
src-util/modulescript/src/org/openbravo/modulescript/UpdateOpenClosePeriodsButton.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/src-util/modulescript/src/org/openbravo/modulescript/UpdateOpenClosePeriodsButton.java
    Wed Apr 10 19:32:57 2013 +0200
@@ -0,0 +1,49 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2013 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.modulescript;
+
+import org.apache.log4j.Logger;
+import org.openbravo.database.ConnectionProvider;
+
+/**
+ * 
+ * @author dmiguelez
+ */
+public class UpdateOpenClosePeriodsButton extends ModuleScript {
+
+  private static final Logger log4j = 
Logger.getLogger(UpdateOpenClosePeriodsButton.class);
+
+  @Override
+  public void execute() {
+    try {
+      ConnectionProvider cp = getConnectionProvider();
+      // If the preference does not exist in the database yet the modulescript 
must be executed.
+      boolean isUpdated = UpdateOpenClosePeriodsButtonData.isUpdated(cp);
+      if (!isUpdated) {
+        UpdateOpenClosePeriodsButtonData.updatePeriodControl(cp);
+        UpdateOpenClosePeriodsButtonData.updatePeriod(cp);
+        UpdateOpenClosePeriodsButtonData.createPreference(cp);
+      }
+    } catch (Exception e) {
+      handleError(e);
+    }
+  }
+
+}
diff -r 905aa948183a -r 68337fa5610d 
src-util/modulescript/src/org/openbravo/modulescript/UpdateOpenClosePeriodsButton_data.xsql
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/src-util/modulescript/src/org/openbravo/modulescript/UpdateOpenClosePeriodsButton_data.xsql
       Wed Apr 10 19:32:57 2013 +0200
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2013 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+-->
+<SqlClass name="UpdateOpenClosePeriodsButtonData" 
package="org.openbravo.modulescript">
+  <SqlClassComment></SqlClassComment>
+  <SqlMethod name="select" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        SELECT '' as exist FROM DUAL
+      ]]>
+    </Sql>
+  </SqlMethod>
+  <SqlMethod name="isUpdated" type="preparedStatement" return="boolean">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        SELECT count(*) as exist
+        FROM DUAL
+        WHERE EXISTS (SELECT 1 FROM ad_preference
+                      WHERE attribute = 'Period_Open_Close_Button_is_Updated')
+      ]]>
+    </Sql>
+  </SqlMethod>
+  <SqlMethod name="updatePeriodControl" type="preparedStatement" 
return="rowcount">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        UPDATE c_periodcontrol
+        SET openclose = CASE WHEN periodstatus = 'O' THEN 'C' ELSE 'O' END
+      ]]>
+    </Sql>
+  </SqlMethod>
+  <SqlMethod name="updatePeriod" type="preparedStatement" return="rowcount">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        UPDATE C_Period p
+      SET openclose= (SELECT CASE
+            WHEN (max(pc.periodstatus) = min(pc.periodstatus) AND 
min(pc.periodstatus) = 'O') THEN 'C'
+            ELSE 'O'
+            END
+         FROM c_periodcontrol pc
+         WHERE pc.c_period_id = p.c_period_id)
+      ]]>
+    </Sql>
+  </SqlMethod>
+  <SqlMethod name="createPreference" type="preparedStatement" 
return="rowcount">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        INSERT INTO ad_preference (
+          ad_preference_id, ad_client_id, ad_org_id, isactive,
+          createdby, created, updatedby, updated,
+          attribute, value
+        ) VALUES (
+          get_uuid(), '0', '0', 'Y',
+          '0', NOW(), '0', NOW(),
+          'Period_Open_Close_Button_is_Updated', 'Y'
+        )
+      ]]>
+    </Sql>
+  </SqlMethod>
+</SqlClass>
diff -r 905aa948183a -r 68337fa5610d 
src/org/openbravo/financial/ResetAccounting.java
--- a/src/org/openbravo/financial/ResetAccounting.java  Tue Apr 09 02:36:00 
2013 +0200
+++ b/src/org/openbravo/financial/ResetAccounting.java  Wed Apr 10 19:32:57 
2013 +0200
@@ -30,7 +30,6 @@
 import org.hibernate.Query;
 import org.hibernate.criterion.Restrictions;
 import org.openbravo.base.exception.OBException;
-import org.openbravo.base.model.ModelProvider;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.security.OrganizationStructureProvider;
 import org.openbravo.dal.service.OBCriteria;
@@ -210,8 +209,7 @@
     try {
       Table table = OBDal.getInstance().get(Table.class, tableId);
       tableName = table.getName();
-      tableDate = 
ModelProvider.getInstance().getTable(table.getDBTableName()).getColumns().get(0)
-          .getColumnName();
+      tableDate = 
lowerCaseFirst(camelCaseIt(table.getAcctdateColumn().getName()));
       String strUpdate = "update "
           + tableName
           + " set posted='N', processNow=false where posted not in ('N','Y') 
and processed = 'Y' and organization.id in (:orgIds)  ";
@@ -456,4 +454,35 @@
     return exceptionDates.size() == validDates;
   }
 
+  private static String camelCaseIt(String mappingName) {
+    String localMappingName = mappingName.replaceAll("_", " ");
+    String separator = " ";
+    // strip _ at the end
+    while (localMappingName.endsWith(separator)) {
+      localMappingName = localMappingName.substring(0, 
localMappingName.length() - 1);
+    }
+    // strip _ at the beginning
+    while (localMappingName.startsWith(separator)) {
+      localMappingName = localMappingName.substring(1);
+    }
+
+    // "CamelCasing"
+    int pos = localMappingName.indexOf(separator);
+    while (pos != -1) {
+      final String leftPart = localMappingName.substring(0, pos);
+      final String camelLetter = String.valueOf(localMappingName.charAt(pos + 
1)).toUpperCase();
+      final String rightPart = localMappingName.substring(pos + 2);
+      localMappingName = leftPart + camelLetter + rightPart;
+      pos = localMappingName.indexOf(separator);
+    }
+    return localMappingName;
+  }
+
+  private static String lowerCaseFirst(String value) {
+    if (value.length() > 1) {
+      return value.substring(0, 1).toLowerCase() + value.substring(1);
+    }
+    return value;
+  }
+
 }

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to