Related to issue 30108: Add a modulescript to update created clients
authorAlvaro Ferraz <alvaro.ferraz@openbravo.com>
Mon, 22 Jun 2015 20:24:40 +0200
changeset 27133 f7c344c707ee
parent 27132 ff0929e96ca2
child 27134 3282f8efffd9
Related to issue 30108: Add a modulescript to update created clients

A new modulescript has been added in order to activate the "Show in Header" flag, to clients with "Central Maintenance" flag activated, for "AR Receipt" and "AP Payment" documents and "Business Partner" accounting dimension, in Client - Dimensions tab.
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdatePaymentBPClientDimension.class
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdatePaymentBPClientDimensionData.class
src-util/modulescript/src/org/openbravo/modulescript/UpdatePaymentBPClientDimension.java
src-util/modulescript/src/org/openbravo/modulescript/UpdatePaymentBPClientDimension_data.xsql
Binary file src-util/modulescript/build/classes/org/openbravo/modulescript/UpdatePaymentBPClientDimension.class has changed
Binary file src-util/modulescript/build/classes/org/openbravo/modulescript/UpdatePaymentBPClientDimensionData.class has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-util/modulescript/src/org/openbravo/modulescript/UpdatePaymentBPClientDimension.java	Mon Jun 22 20:24:40 2015 +0200
@@ -0,0 +1,41 @@
+/*
+ *************************************************************************
+ * 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) 2015 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+package org.openbravo.modulescript;
+
+import java.sql.PreparedStatement;
+import org.apache.log4j.Logger;
+
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.modulescript.ModuleScript;
+
+public class UpdatePaymentBPClientDimension extends ModuleScript {
+  private static final Logger log4j = Logger.getLogger(UpdatePaymentBPClientDimension.class);
+  public void execute() {
+    try {
+      ConnectionProvider cp = getConnectionProvider();
+      boolean isExecuted = UpdatePaymentBPClientDimensionData.isExecuted(cp);
+      if (!isExecuted) {
+        UpdatePaymentBPClientDimensionData.update(cp);
+        UpdatePaymentBPClientDimensionData.createPreference(cp);
+      }
+    } catch (Exception e) {
+      handleError(e);
+    }
+  }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-util/modulescript/src/org/openbravo/modulescript/UpdatePaymentBPClientDimension_data.xsql	Mon Jun 22 20:24:40 2015 +0200
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ *************************************************************************
+ * 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) 2015 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+-->
+<SqlClass name="UpdatePaymentBPClientDimensionData" package="org.openbravo.modulescript">
+   <SqlClassComment></SqlClassComment>  
+   <SqlMethod name="dummy" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+      SELECT '' AS show_in_header FROM DUAL
+      ]]>
+    </Sql>
+    <Field name="rownum" value="count"/>
+  </SqlMethod> 
+  <SqlMethod name="update" type="preparedStatement" return="rowCount">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        UPDATE AD_Client_AcctDimension
+        SET show_in_header = 'Y'
+        WHERE (docbasetype = 'ARR'
+        OR docbasetype = 'APP')
+        AND dimension = 'BP'
+        AND show_in_header = 'N'
+        AND ad_client_id IN (
+            SELECT ad_client_id
+            FROM ad_client
+            WHERE acctdim_centrally_maintained = 'Y'
+        )
+      ]]>
+    </Sql>
+  </SqlMethod>
+  <SqlMethod name="isExecuted" type="preparedStatement" return="boolean">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        SELECT count(*) as exist
+        FROM DUAL
+        WHERE EXISTS (SELECT 1 FROM ad_preference
+                      WHERE attribute = 'PaymentBPClientDimensionUpdated')
+      ]]>
+    </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
+           ) VALUES (
+           get_uuid(), '0', '0', 'Y', '0', NOW(), '0', NOW(),'PaymentBPClientDimensionUpdated')
+         ]]>
+        </Sql>
+   </SqlMethod>
+</SqlClass>