Fixes bug 20428: Record_ID2 column is taking values when posting documents of the new financial flows when it should point just debt/payments
authorEduardo Argal Guibert <eduardo.argal@openbravo.com>
Mon, 07 May 2012 10:54:55 +0200
changeset 16496 566af5c10315
parent 16495 c748fcb063d8
child 16497 c7d28f77823d
Fixes bug 20428: Record_ID2 column is taking values when posting documents of the new financial flows when it should point just debt/payments
modules/org.openbravo.advpaymentmngt/build/classes/org/openbravo/advpaymentmngt/modulescript/UpdateRecordId2Value.class
modules/org.openbravo.advpaymentmngt/build/classes/org/openbravo/advpaymentmngt/modulescript/UpdateRecordId2ValueData.class
modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/org/openbravo/advpaymentmngt/modulescript/UpdateRecordId2Value.java
modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/org/openbravo/advpaymentmngt/modulescript/UpdateRecordId2Value_data.xsql
modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/src/org/openbravo/advpaymentmngt/modulescript/UpdateRecordId2ValueData.java
src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java
src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java
src/org/openbravo/erpCommon/ad_forms/DocInvoice.java
src/org/openbravo/erpCommon/ad_forms/DocLine_FINFinAccTransaction.java
src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java
src/org/openbravo/erpCommon/ad_forms/DocLine_FINReconciliation.java
src/org/openbravo/erpCommon/ad_forms/DocLine_FinPaymentSchedule.java
Binary file modules/org.openbravo.advpaymentmngt/build/classes/org/openbravo/advpaymentmngt/modulescript/UpdateRecordId2Value.class has changed
Binary file modules/org.openbravo.advpaymentmngt/build/classes/org/openbravo/advpaymentmngt/modulescript/UpdateRecordId2ValueData.class has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/org/openbravo/advpaymentmngt/modulescript/UpdateRecordId2Value.java	Mon May 07 10:54:55 2012 +0200
@@ -0,0 +1,39 @@
+/* 
+ *************************************************************************
+ * 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) 2012 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+package org.openbravo.advpaymentmngt.modulescript;
+
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.modulescript.ModuleScript;
+
+public class UpdateRecordId2Value extends ModuleScript {
+
+  /**
+   * This modulescript removes value for record_id2 in fact_acct table when this 
+   * one points no debt/paymnet.
+   */
+  @Override
+  public void execute() {
+    try {
+      ConnectionProvider cp = getConnectionProvider();
+      UpdateRecordId2ValueData.update(cp);
+    } catch (Exception e) {
+      handleError(e);
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/org/openbravo/advpaymentmngt/modulescript/UpdateRecordId2Value_data.xsql	Mon May 07 10:54:55 2012 +0200
@@ -0,0 +1,39 @@
+<?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) 2012 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+-->
+<SqlClass name="UpdateRecordId2ValueData" package="org.openbravo.advpaymentmngt.modulescript">
+  <SqlClassComment></SqlClassComment>
+  <SqlMethod name="select" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        SELECT 1 as name from dual
+      ]]>
+    </Sql>
+  </SqlMethod>
+  <SqlMethod name="update" type="preparedStatement" return="rowCount">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        UPDATE FACT_ACCT SET RECORD_ID2 = NULL 
+        WHERE NOT EXISTS (SELECT 1 FROM C_DEBT_PAYMENT WHERE C_DEBT_PAYMENT_ID = RECORD_ID2)
+      ]]>
+    </Sql>
+  </SqlMethod>
+</SqlClass>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/src/org/openbravo/advpaymentmngt/modulescript/UpdateRecordId2ValueData.java	Mon May 07 10:54:55 2012 +0200
@@ -0,0 +1,114 @@
+//Sqlc generated V1.O00-1
+package org.openbravo.advpaymentmngt.modulescript;
+
+import java.sql.*;
+
+import org.apache.log4j.Logger;
+
+import javax.servlet.ServletException;
+
+import org.openbravo.data.FieldProvider;
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.data.UtilSql;
+import java.util.*;
+
+class UpdateRecordId2ValueData implements FieldProvider {
+static Logger log4j = Logger.getLogger(UpdateRecordId2ValueData.class);
+  private String InitRecordNumber="0";
+  public String name;
+
+  public String getInitRecordNumber() {
+    return InitRecordNumber;
+  }
+
+  public String getField(String fieldName) {
+    if (fieldName.equalsIgnoreCase("name"))
+      return name;
+   else {
+     log4j.debug("Field does not exist: " + fieldName);
+     return null;
+   }
+ }
+
+  public static UpdateRecordId2ValueData[] select(ConnectionProvider connectionProvider)    throws ServletException {
+    return select(connectionProvider, 0, 0);
+  }
+
+  public static UpdateRecordId2ValueData[] select(ConnectionProvider connectionProvider, int firstRegister, int numberRegisters)    throws ServletException {
+    String strSql = "";
+    strSql = strSql + 
+      "        SELECT 1 as name from dual";
+
+    ResultSet result;
+    Vector<java.lang.Object> vector = new Vector<java.lang.Object>(0);
+    PreparedStatement st = null;
+
+    try {
+    st = connectionProvider.getPreparedStatement(strSql);
+
+      result = st.executeQuery();
+      long countRecord = 0;
+      long countRecordSkip = 1;
+      boolean continueResult = true;
+      while(countRecordSkip < firstRegister && continueResult) {
+        continueResult = result.next();
+        countRecordSkip++;
+      }
+      while(continueResult && result.next()) {
+        countRecord++;
+        UpdateRecordId2ValueData objectUpdateRecordId2ValueData = new UpdateRecordId2ValueData();
+        objectUpdateRecordId2ValueData.name = UtilSql.getValue(result, "name");
+        objectUpdateRecordId2ValueData.InitRecordNumber = Integer.toString(firstRegister);
+        vector.addElement(objectUpdateRecordId2ValueData);
+        if (countRecord >= numberRegisters && numberRegisters != 0) {
+          continueResult = false;
+        }
+      }
+      result.close();
+    } catch(SQLException e){
+      log4j.error("SQL error in query: " + strSql + "Exception:"+ e);
+      throw new ServletException("@CODE=" + Integer.toString(e.getErrorCode()) + "@" + e.getMessage());
+    } catch(Exception ex){
+      log4j.error("Exception in query: " + strSql + "Exception:"+ ex);
+      throw new ServletException("@CODE=@" + ex.getMessage());
+    } finally {
+      try {
+        connectionProvider.releasePreparedStatement(st);
+      } catch(Exception ignore){
+        ignore.printStackTrace();
+      }
+    }
+    UpdateRecordId2ValueData objectUpdateRecordId2ValueData[] = new UpdateRecordId2ValueData[vector.size()];
+    vector.copyInto(objectUpdateRecordId2ValueData);
+    return(objectUpdateRecordId2ValueData);
+  }
+
+  public static int update(ConnectionProvider connectionProvider)    throws ServletException {
+    String strSql = "";
+    strSql = strSql + 
+      "        UPDATE FACT_ACCT SET RECORD_ID2 = NULL " +
+      "        WHERE NOT EXISTS (SELECT 1 FROM C_DEBT_PAYMENT WHERE C_DEBT_PAYMENT_ID = RECORD_ID2)";
+
+    int updateCount = 0;
+    PreparedStatement st = null;
+
+    try {
+    st = connectionProvider.getPreparedStatement(strSql);
+
+      updateCount = st.executeUpdate();
+    } catch(SQLException e){
+      log4j.error("SQL error in query: " + strSql + "Exception:"+ e);
+      throw new ServletException("@CODE=" + Integer.toString(e.getErrorCode()) + "@" + e.getMessage());
+    } catch(Exception ex){
+      log4j.error("Exception in query: " + strSql + "Exception:"+ ex);
+      throw new ServletException("@CODE=@" + ex.getMessage());
+    } finally {
+      try {
+        connectionProvider.releasePreparedStatement(st);
+      } catch(Exception ignore){
+        ignore.printStackTrace();
+      }
+    }
+    return(updateCount);
+  }
+}
--- a/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java	Mon May 07 10:53:04 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java	Mon May 07 10:54:55 2012 +0200
@@ -295,7 +295,7 @@
         String strPaymentId = data[i].getField("FIN_Payment_ID");
         if (strPaymentId != null && !strPaymentId.equals("")) {
           docLine.setFinPaymentId(strPaymentId);
-          docLine.m_Record_Id2 = strPaymentId;
+          // docLine.m_Record_Id2 = strPaymentId;
           FIN_PaymentDetail detail = OBDal.getInstance().get(FIN_PaymentDetail.class,
               paymentDetail_ID);
           docLine
--- a/src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java	Mon May 07 10:53:04 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java	Mon May 07 10:54:55 2012 +0200
@@ -477,7 +477,7 @@
         String strPaymentId = data[i].getField("FIN_Payment_ID");
         if (strPaymentId != null && !strPaymentId.equals(""))
           docLine.setFinPaymentId(strPaymentId);
-        docLine.m_Record_Id2 = strPaymentId;
+        // docLine.m_Record_Id2 = strPaymentId;
         docLine.setIsPrepayment(data[i].getField("isprepayment"));
         docLine.setCGlItemId(data[i].getField("cGlItemId"));
         docLine.setPaymentAmount(data[i].getField("PaymentAmount"));
--- a/src/org/openbravo/erpCommon/ad_forms/DocInvoice.java	Mon May 07 10:53:04 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocInvoice.java	Mon May 07 10:54:55 2012 +0200
@@ -201,7 +201,7 @@
         DocLine_FinPaymentSchedule dpLine = new DocLine_FinPaymentSchedule(DocumentType, Record_ID,
             Line_ID);
         log4jDocInvoice.debug(" dpLine.m_Record_Id2 = " + data[i].finPaymentScheduleId);
-        dpLine.m_Record_Id2 = data[i].finPaymentScheduleId;
+        // dpLine.m_Record_Id2 = data[i].finPaymentScheduleId;
         dpLine.C_Currency_ID_From = data[i].cCurrencyId;
         dpLine.isPaid = data[i].ispaid;
         dpLine.Amount = data[i].amount;
--- a/src/org/openbravo/erpCommon/ad_forms/DocLine_FINFinAccTransaction.java	Mon May 07 10:53:04 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLine_FINFinAccTransaction.java	Mon May 07 10:54:55 2012 +0200
@@ -169,7 +169,7 @@
   public DocLine_FINFinAccTransaction(String DocumentType, String TrxHeader_ID, String TrxLine_ID) {
     super(DocumentType, TrxHeader_ID, TrxLine_ID);
     Line_ID = TrxLine_ID;
-    m_Record_Id2 = Line_ID;
+    // m_Record_Id2 = Line_ID;
   }
 
   public String getServletInfo() {
--- a/src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java	Mon May 07 10:53:04 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java	Mon May 07 10:54:55 2012 +0200
@@ -143,7 +143,8 @@
   public DocLine_FINPayment(String DocumentType, String TrxHeader_ID, String TrxLine_ID) {
     super(DocumentType, TrxHeader_ID, TrxLine_ID);
     Line_ID = TrxLine_ID;
-    m_Record_Id2 = Line_ID;
+    // TODO:Review Record_id2 implementation for new flow
+    // m_Record_Id2 = Line_ID;
   }
 
   public String getServletInfo() {
--- a/src/org/openbravo/erpCommon/ad_forms/DocLine_FINReconciliation.java	Mon May 07 10:53:04 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLine_FINReconciliation.java	Mon May 07 10:54:55 2012 +0200
@@ -155,7 +155,7 @@
   public DocLine_FINReconciliation(String DocumentType, String TrxHeader_ID, String TrxLine_ID) {
     super(DocumentType, TrxHeader_ID, TrxLine_ID);
     Line_ID = TrxLine_ID;
-    m_Record_Id2 = Line_ID;
+    // m_Record_Id2 = Line_ID;
   }
 
   public String getServletInfo() {
--- a/src/org/openbravo/erpCommon/ad_forms/DocLine_FinPaymentSchedule.java	Mon May 07 10:53:04 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLine_FinPaymentSchedule.java	Mon May 07 10:54:55 2012 +0200
@@ -37,7 +37,7 @@
   public DocLine_FinPaymentSchedule(String DocumentType, String TrxHeader_ID, String TrxLine_ID) {
     super(DocumentType, TrxHeader_ID, TrxLine_ID);
     Line_ID = TrxLine_ID;
-    m_Record_Id2 = Line_ID;
+    // m_Record_Id2 = Line_ID;
   }
 
   public String getLine_ID() {