details:   https://code.openbravo.com/erp/devel/pi/rev/e1e05d8bbccb
changeset: 26268:e1e05d8bbccb
user:      Alvaro Ferraz <alvaro.ferraz <at> openbravo.com>
date:      Tue Mar 17 13:17:04 2015 +0100
summary:   Fixes issue 29222: G/L Journal Accounting amounts are not setted 
correctly

Conversion rate to apply to accounting amounts will be getted from the system 
when it is setted as multi-general ledger and from the document when it is not

details:   https://code.openbravo.com/erp/devel/pi/rev/d21dd3116c92
changeset: 26269:d21dd3116c92
user:      Alvaro Ferraz <alvaro.ferraz <at> openbravo.com>
date:      Thu Mar 26 11:01:08 2015 +0100
summary:   Related to issue 29222: Add a build validation to create an alert if 
wrong data

A build validation will be executed to check if it exists wrong data (g/l 
journal accounting with wrong amounts) related to the issue. In that case an 
alert will be created to tell the user to reset accounting, but when fixed it 
will be deactivated to avoid execute it again.
The build validation will only be executed when updating from Q1 or Q1.1, 
because the issue is introduced in Q1 and resolved in Q1.2.

details:   https://code.openbravo.com/erp/devel/pi/rev/fae899b56870
changeset: 26270:fae899b56870
user:      Unai Martirena <unai.martirena <at> openbravo.com>
date:      Thu Mar 26 13:49:13 2015 +0100
summary:   Related to issue 29222: Fix copyright

diffstat:

 
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/GLJournalAccountingCheck.class
     |    0 
 
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/GLJournalAccountingCheckData.class
 |    0 
 
src-util/buildvalidation/src/org/openbravo/buildvalidation/GLJournalAccountingCheck.java
                |   81 ++++
 
src-util/buildvalidation/src/org/openbravo/buildvalidation/GLJournalAccountingCheck_data.xsql
           |  172 ++++++++++
 src/org/openbravo/erpCommon/ad_forms/DocGLJournal.java                         
                         |   28 +-
 5 files changed, 267 insertions(+), 14 deletions(-)

diffs (truncated from 332 to 300 lines):

diff -r 54218273885c -r fae899b56870 
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/GLJournalAccountingCheck.class
Binary file 
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/GLJournalAccountingCheck.class
 has changed
diff -r 54218273885c -r fae899b56870 
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/GLJournalAccountingCheckData.class
Binary file 
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/GLJournalAccountingCheckData.class
 has changed
diff -r 54218273885c -r fae899b56870 
src-util/buildvalidation/src/org/openbravo/buildvalidation/GLJournalAccountingCheck.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/src-util/buildvalidation/src/org/openbravo/buildvalidation/GLJournalAccountingCheck.java
  Thu Mar 26 13:49:13 2015 +0100
@@ -0,0 +1,81 @@
+/*
+ *************************************************************************
+ * 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):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.buildvalidation;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.servlet.ServletException;
+import org.openbravo.database.ConnectionProvider;
+
+/**
+ * This validation is related to this issue: 
https://issues.openbravo.com/view.php?id=29222
+ *  
+ * G/L Journal accounting records could have wrong amounts, if document rate 
is not the same 
+ * than current system rate
+ */
+public class GLJournalAccountingCheck extends BuildValidation {
+ 
+  final static private int Q1_VERSION = 25704;
+  final static private int Q1_1_VERSION = 25735 ;
+  final static private String ALERT_RULE = "Wrong G/L Journal Accounting 
amounts";
+  final static private String ALERT_NAME = ALERT_RULE + ". Please reset 
accounting of G/L Journal %s document";
+  final static private String AD_WINDOW = "132";
+  final static private String AD_TAB = "160";
+  final static private String ERROR_MSG = "Wrong G/L Journal accounting data. 
Please review alerts (Alert Rule: " + ALERT_RULE + ") and reset accounting of 
wrong entries to fix the data"; 
+  
+  public List<String> execute() {    
+    ArrayList<String> errors = new ArrayList<String>();
+    try {
+      ConnectionProvider cp = getConnectionProvider(); 
+      String version = GLJournalAccountingCheckData.getModuleVersion(cp);
+      int intVersion = 
Integer.valueOf(version.substring(version.lastIndexOf('.') + 1));
+      if (intVersion >= Q1_VERSION && intVersion <= Q1_1_VERSION)
+      {
+        if (!GLJournalAccountingCheckData.hasPreference(cp))
+        {    
+          GLJournalAccountingCheckData[] documentList = 
GLJournalAccountingCheckData.getWrongGLJournalAccountingClients(cp);        
+          for (GLJournalAccountingCheckData document : documentList) {
+            createAlert(cp, document.adClientId);
+          }
+          if (documentList != null && documentList.length > 0) {
+            errors.add(ERROR_MSG);          
+          }        
+          else {
+            GLJournalAccountingCheckData.createPreference(cp);
+          }
+        }
+      }
+    } catch (Exception e) {
+      return handleError(e);
+    }
+    return errors;
+  }
+    
+  private void createAlert(ConnectionProvider cp, String clientId) throws 
ServletException {    
+    if (!GLJournalAccountingCheckData.existsAlertRule(cp, ALERT_RULE, 
clientId)) {
+      GLJournalAccountingCheckData.insertAlertRule(cp, clientId, ALERT_RULE, 
AD_TAB);
+    }
+    final String alertRuleId = GLJournalAccountingCheckData.getAlertRuleId(cp, 
ALERT_RULE, clientId);
+    for (GLJournalAccountingCheckData document : 
GLJournalAccountingCheckData.getWrongGLJournalAccountingDocuments(cp, 
clientId)) {
+      if (!GLJournalAccountingCheckData.existsAlert(cp, alertRuleId, 
document.glJournalId)) {
+        GLJournalAccountingCheckData.insertAlert(cp, clientId, 
String.format(ALERT_NAME, document.recordinfo), alertRuleId, 
document.recordinfo, document.glJournalId);
+      }
+    }
+  }
+}
diff -r 54218273885c -r fae899b56870 
src-util/buildvalidation/src/org/openbravo/buildvalidation/GLJournalAccountingCheck_data.xsql
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/src-util/buildvalidation/src/org/openbravo/buildvalidation/GLJournalAccountingCheck_data.xsql
     Thu Mar 26 13:49:13 2015 +0100
@@ -0,0 +1,172 @@
+<?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="GLJournalAccountingCheckData" 
package="org.openbravo.buildvalidation">
+  <SqlMethod name="select" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql><![CDATA[
+      SELECT '' AS ad_client_id, '' AS ad_role_id, '' as recordinfo, '' AS 
gl_journal_id
+      FROM DUAL
+      ]]>
+    </Sql>
+  </SqlMethod>
+  <SqlMethod name="getModuleVersion" type="preparedStatement" return="string">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        SELECT version
+        FROM ad_module
+        WHERE ad_module_id = '0'        
+      ]]>
+    </Sql>
+  </SqlMethod>
+  <SqlMethod name="hasPreference" type="preparedStatement" return="boolean">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        SELECT count(*) as existpreference
+        FROM ad_preference
+        WHERE attribute = 'GLJournalAccountingCheck'        
+      ]]>
+    </Sql>
+  </SqlMethod>
+  <SqlMethod name="getWrongGLJournalAccountingClients" 
type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql><![CDATA[
+         SELECT DISTINCT t1.ad_client_id
+         FROM gl_journalline t1, fact_acct t2
+         WHERE t1.gl_journal_id = t2.record_id
+         AND t1.gl_journalline_id = t2.line_id
+         AND t1.c_validcombination_id IS NOT NULL
+         AND (t1.amtsourcedr <> t2.amtsourcedr
+         OR t1.amtsourcecr <> t2.amtsourcecr
+         OR t1.amtacctdr <> t2.amtacctdr
+         OR t1.amtacctcr <> t2.amtacctcr)
+      ]]>
+    </Sql>
+  </SqlMethod>  
+  <SqlMethod name="insertAlertRule" type="preparedStatement" return="rowcount">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql><![CDATA[
+      INSERT INTO AD_ALERTRULE (
+        AD_ALERTRULE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
+        CREATED, CREATEDBY,  UPDATED, UPDATEDBY,
+        NAME, AD_TAB_ID, FILTERCLAUSE, TYPE, SQL
+      ) VALUES (
+        get_uuid(), ?, '0', 'Y',
+        now(), '100', now(), '100',
+        ?, ?, '', 'E', ''
+      )
+    ]]></Sql>
+    <Parameter name="clientId"/>
+    <Parameter name="name"/>
+    <Parameter name="tabId"/>
+  </SqlMethod>
+  <SqlMethod name="existsAlertRule" type="preparedStatement" return="boolean">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql><![CDATA[
+       SELECT COUNT(*) AS EXISTING
+       FROM AD_ALERTRULE
+       WHERE NAME = ?
+       AND ISACTIVE = 'Y'
+       AND AD_CLIENT_ID = ?
+      ]]>
+    </Sql>
+    <Parameter name="alertRule"/>
+    <Parameter name="client"/>
+  </SqlMethod>
+  <SqlMethod name="getAlertRuleId" type="preparedStatement" return="string">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql><![CDATA[
+       SELECT MAX(ad_alertrule_id) AS name
+       FROM AD_ALERTRULE
+       WHERE NAME LIKE ?
+       AND AD_CLIENT_ID = ?
+       AND ISACTIVE = 'Y'
+      ]]></Sql>
+    <Parameter name="name"/>
+    <Parameter name="client"/>
+  </SqlMethod> 
+  <SqlMethod name="getWrongGLJournalAccountingDocuments" 
type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql><![CDATA[
+      SELECT DISTINCT t1.gl_journal_id, ad_column_identifier('GL_JOURNAL', 
t1.gl_journal_id, 'en_US') as recordinfo
+      FROM gl_journalline t1, fact_acct t2
+      WHERE t1.gl_journal_id = t2.record_id
+      AND t1.gl_journalline_id = t2.line_id
+      AND t1.c_validcombination_id IS NOT NULL
+      AND t1.ad_client_id = ?
+      AND (t1.amtsourcedr <> t2.amtsourcedr
+      OR t1.amtsourcecr <> t2.amtsourcecr
+      OR t1.amtacctdr <> t2.amtacctdr
+      OR t1.amtacctcr <> t2.amtacctcr)
+      ]]>
+    </Sql>
+    <Parameter name="client"/>
+  </SqlMethod>
+  <SqlMethod name="existsAlert" type="preparedStatement" return="boolean">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql><![CDATA[
+       SELECT COUNT(*) AS EXISTING
+       FROM AD_ALERT
+       WHERE AD_ALERTRULE_ID = ?
+       AND REFERENCEKEY_ID = ?
+       AND ISFIXED = 'N'
+      ]]>
+    </Sql>
+    <Parameter name="alertRule"/>
+    <Parameter name="referencekey_id"/>
+  </SqlMethod>
+  <SqlMethod name="insertAlert" type="preparedStatement" return="rowcount">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql><![CDATA[
+      INSERT INTO AD_Alert (
+        AD_Alert_ID, AD_Client_ID, AD_Org_ID, IsActive,
+        Created, CreatedBy, Updated, UpdatedBy,
+        Description, AD_AlertRule_ID, AD_Role_ID, Record_Id, Referencekey_ID
+      ) VALUES (
+        get_uuid(), ?, '0', 'Y',
+        NOW(), '0', NOW(), '0',
+        ?, ?, '0', ?, ?)
+      ]]>
+    </Sql>
+    <Parameter name="client"/>
+    <Parameter name="description" />
+    <Parameter name="adAlertRuleId" />
+    <Parameter name="recordId" />
+    <Parameter name="referencekey_id" />
+  </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(),
+          'GLJournalAccountingCheck'
+        )
+      ]]>
+    </Sql>
+  </SqlMethod>
+</SqlClass>
\ No newline at end of file
diff -r 54218273885c -r fae899b56870 
src/org/openbravo/erpCommon/ad_forms/DocGLJournal.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocGLJournal.java    Thu Mar 26 
11:31:57 2015 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/DocGLJournal.java    Thu Mar 26 
13:49:13 2015 +0100
@@ -11,7 +11,7 @@
  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
  * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
  * Contributor(s): Openbravo SLU
- * Contributions are Copyright (C) 2001-2010 Openbravo S.L.U.
+ * Contributions are Copyright (C) 2001-2015 Openbravo S.L.U.
  ******************************************************************************
  */
 package org.openbravo.erpCommon.ad_forms;
@@ -36,6 +36,7 @@
   static Logger log4jDocGLJournal = Logger.getLogger(DocGLJournal.class);
 
   private String SeqNo = "0";
+  private String C_AcctSchema_ID;
 
   /**
    * Constructor
@@ -73,6 +74,12 @@
     m_PostingType = data[0].getField("PostingType");
     m_IsOpening = data[0].getField("isopening");
     C_Period_ID = isperiodOpen(conn, data[0].getField("period"));
+    C_Currency_ID = data[0].getField("c_currency_id");
+    try {
+      C_AcctSchema_ID = DocGLJournalData.selectAcctSchema(conn, AD_Client_ID, 
Record_ID);
+    } catch (ServletException e) {
+      log4j.error("Error retrieving the accounting schema (general ledger)", 
e);
+    }
     // Contained Objects
     p_lines = loadLines(conn);
     log4jDocGLJournal.debug("Lines=" + p_lines.length);
@@ -96,8 +103,10 @@

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to