details:   https://code.openbravo.com/erp/devel/pi/rev/9c12d1443b20
changeset: 25734:9c12d1443b20
user:      Atul Gaware <atul.gaware <at> openbravo.com>
date:      Tue Jan 20 15:42:13 2015 +0100
summary:   Fixes Issue 28591:Reversing a payment is creating wrong invoice 
payment plan
details

Problem is Schedule detail was being updated by payment amount now it is taken
care to update using individual schedule detail amount while creating reverse
payment schedule and payment schedule details.

diffstat:

 
modules/org.openbravo.advpaymentmngt/build/classes/org/openbravo/advpaymentmngt/modulescript/Issue28591UpdatePSD.class
                    |    0 
 
modules/org.openbravo.advpaymentmngt/build/classes/org/openbravo/advpaymentmngt/modulescript/Issue28591UpdatePSDData.class
                |    0 
 
modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/org/openbravo/advpaymentmngt/modulescript/Issue28591UpdatePSD.java
         |   41 +
 
modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/org/openbravo/advpaymentmngt/modulescript/Issue28591UpdatePSD_data.xsql
    |   82 +++
 
modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/src/org/openbravo/advpaymentmngt/modulescript/Issue28591UpdatePSDData.java
 |  253 ++++++++++
 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java
                                     |    6 +-
 6 files changed, 379 insertions(+), 3 deletions(-)

diffs (truncated from 423 to 300 lines):

diff -r 60e70b428ec7 -r 9c12d1443b20 
modules/org.openbravo.advpaymentmngt/build/classes/org/openbravo/advpaymentmngt/modulescript/Issue28591UpdatePSD.class
Binary file 
modules/org.openbravo.advpaymentmngt/build/classes/org/openbravo/advpaymentmngt/modulescript/Issue28591UpdatePSD.class
 has changed
diff -r 60e70b428ec7 -r 9c12d1443b20 
modules/org.openbravo.advpaymentmngt/build/classes/org/openbravo/advpaymentmngt/modulescript/Issue28591UpdatePSDData.class
Binary file 
modules/org.openbravo.advpaymentmngt/build/classes/org/openbravo/advpaymentmngt/modulescript/Issue28591UpdatePSDData.class
 has changed
diff -r 60e70b428ec7 -r 9c12d1443b20 
modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/org/openbravo/advpaymentmngt/modulescript/Issue28591UpdatePSD.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/org/openbravo/advpaymentmngt/modulescript/Issue28591UpdatePSD.java
 Tue Jan 20 15:42:13 2015 +0100
@@ -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.advpaymentmngt.modulescript;
+
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.modulescript.ModuleScript;
+import java.math.BigDecimal;
+
+public class Issue28591UpdatePSD extends ModuleScript {
+  public void execute() {
+    try {
+      ConnectionProvider cp = getConnectionProvider();
+      boolean issue28591UpdatePSD =  
Issue28591UpdatePSDData.updateWrongPSD(cp);
+      if(!issue28591UpdatePSD) {
+        Issue28591UpdatePSDData[] data = Issue28591UpdatePSDData.selectPSD(cp);
+      for (Issue28591UpdatePSDData upsd : data) {
+        Issue28591UpdatePSDData.updatePSDAmount(cp, upsd.outstandingamt, 
upsd.finPaymentScheduledetailId);        
+      }
+      Issue28591UpdatePSDData.createPreference(cp);
+     }
+    } catch (Exception e) {
+      handleError(e);
+    }
+ }
+}
\ No newline at end of file
diff -r 60e70b428ec7 -r 9c12d1443b20 
modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/org/openbravo/advpaymentmngt/modulescript/Issue28591UpdatePSD_data.xsql
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/org/openbravo/advpaymentmngt/modulescript/Issue28591UpdatePSD_data.xsql
    Tue Jan 20 15:42:13 2015 +0100
@@ -0,0 +1,82 @@
+<?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) 2015 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+-->
+<SqlClass name="Issue28591UpdatePSDData" 
package="org.openbravo.advpaymentmngt.modulescript">
+   <SqlClassComment></SqlClassComment>
+   <SqlMethod name="select" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        SELECT '' as fin_payment_scheduledetail_id, '' as outstandingamt 
+        FROM DUAL
+      ]]>
+    </Sql>
+  </SqlMethod>
+   <SqlMethod name="selectPSD" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+      select ps.outstandingamt as outstandingamt, 
max(psd.fin_payment_scheduledetail_id) as fin_payment_scheduledetail_id 
+      from fin_payment_scheduledetail psd 
+      LEFT JOIN fin_payment_schedule ps ON ps.fin_payment_schedule_id = 
COALESCE(psd.fin_payment_schedule_invoice,psd.fin_payment_schedule_order) 
+      where psd.fin_payment_detail_id is null
+      group by ps.fin_payment_schedule_id
+      having sum(psd.amount) <> ps.outstandingamt
+      ]]>
+    </Sql>
+  </SqlMethod>
+  <SqlMethod name="updatePSDAmount" type="preparedStatement" return="rowcount">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        UPDATE FIN_PAYMENT_SCHEDULEDETAIL SET AMOUNT=TO_NUMBER(?)  
+        WHERE FIN_PAYMENT_SCHEDULEDETAIL_ID = ?
+      ]]>
+    </Sql>
+    <Parameter name="outStandingAmount"/>
+    <Parameter name="finPaymentScheduledetailId"/>    
+    </SqlMethod>  
+  <SqlMethod name="updateWrongPSD" type="preparedStatement" return="boolean">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        SELECT count(*) as exist
+        FROM DUAL
+        WHERE EXISTS (SELECT 1 FROM ad_preference
+                      WHERE attribute = 'Issue28591updateWrongPSD')
+      ]]>
+    </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(),
+          'Issue28591updateWrongPSD'
+        )
+      ]]>
+    </Sql>
+  </SqlMethod>
+ </SqlClass>
diff -r 60e70b428ec7 -r 9c12d1443b20 
modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/src/org/openbravo/advpaymentmngt/modulescript/Issue28591UpdatePSDData.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/src/org/openbravo/advpaymentmngt/modulescript/Issue28591UpdatePSDData.java
 Tue Jan 20 15:42:13 2015 +0100
@@ -0,0 +1,253 @@
+//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 Issue28591UpdatePSDData implements FieldProvider {
+static Logger log4j = Logger.getLogger(Issue28591UpdatePSDData.class);
+  private String InitRecordNumber="0";
+  public String finPaymentScheduledetailId;
+  public String outstandingamt;
+
+  public String getInitRecordNumber() {
+    return InitRecordNumber;
+  }
+
+  public String getField(String fieldName) {
+    if (fieldName.equalsIgnoreCase("fin_payment_scheduledetail_id") || 
fieldName.equals("finPaymentScheduledetailId"))
+      return finPaymentScheduledetailId;
+    else if (fieldName.equalsIgnoreCase("outstandingamt"))
+      return outstandingamt;
+   else {
+     log4j.debug("Field does not exist: " + fieldName);
+     return null;
+   }
+ }
+
+  public static Issue28591UpdatePSDData[] select(ConnectionProvider 
connectionProvider)    throws ServletException {
+    return select(connectionProvider, 0, 0);
+  }
+
+  public static Issue28591UpdatePSDData[] select(ConnectionProvider 
connectionProvider, int firstRegister, int numberRegisters)    throws 
ServletException {
+    String strSql = "";
+    strSql = strSql + 
+      "        SELECT '' as fin_payment_scheduledetail_id, '' as 
outstandingamt " +
+      "        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++;
+        Issue28591UpdatePSDData objectIssue28591UpdatePSDData = new 
Issue28591UpdatePSDData();
+        objectIssue28591UpdatePSDData.finPaymentScheduledetailId = 
UtilSql.getValue(result, "fin_payment_scheduledetail_id");
+        objectIssue28591UpdatePSDData.outstandingamt = 
UtilSql.getValue(result, "outstandingamt");
+        objectIssue28591UpdatePSDData.InitRecordNumber = 
Integer.toString(firstRegister);
+        vector.addElement(objectIssue28591UpdatePSDData);
+        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();
+      }
+    }
+    Issue28591UpdatePSDData objectIssue28591UpdatePSDData[] = new 
Issue28591UpdatePSDData[vector.size()];
+    vector.copyInto(objectIssue28591UpdatePSDData);
+    return(objectIssue28591UpdatePSDData);
+  }
+
+  public static Issue28591UpdatePSDData[] selectPSD(ConnectionProvider 
connectionProvider)    throws ServletException {
+    return selectPSD(connectionProvider, 0, 0);
+  }
+
+  public static Issue28591UpdatePSDData[] selectPSD(ConnectionProvider 
connectionProvider, int firstRegister, int numberRegisters)    throws 
ServletException {
+    String strSql = "";
+    strSql = strSql + 
+      "      select ps.outstandingamt as outstandingamt, 
max(psd.fin_payment_scheduledetail_id) as fin_payment_scheduledetail_id " +
+      "      from fin_payment_scheduledetail psd " +
+      "      LEFT JOIN fin_payment_schedule ps ON ps.fin_payment_schedule_id = 
COALESCE(psd.fin_payment_schedule_invoice,psd.fin_payment_schedule_order) " +
+      "      where psd.fin_payment_detail_id is null" +
+      "      group by ps.fin_payment_schedule_id" +
+      "      having sum(psd.amount) <> ps.outstandingamt";
+
+    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++;
+        Issue28591UpdatePSDData objectIssue28591UpdatePSDData = new 
Issue28591UpdatePSDData();
+        objectIssue28591UpdatePSDData.outstandingamt = 
UtilSql.getValue(result, "outstandingamt");
+        objectIssue28591UpdatePSDData.finPaymentScheduledetailId = 
UtilSql.getValue(result, "fin_payment_scheduledetail_id");
+        objectIssue28591UpdatePSDData.InitRecordNumber = 
Integer.toString(firstRegister);
+        vector.addElement(objectIssue28591UpdatePSDData);
+        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();
+      }
+    }
+    Issue28591UpdatePSDData objectIssue28591UpdatePSDData[] = new 
Issue28591UpdatePSDData[vector.size()];
+    vector.copyInto(objectIssue28591UpdatePSDData);
+    return(objectIssue28591UpdatePSDData);
+  }
+
+  public static int updatePSDAmount(ConnectionProvider connectionProvider, 
String outStandingAmount, String finPaymentScheduledetailId)    throws 
ServletException {
+    String strSql = "";
+    strSql = strSql + 
+      "        UPDATE FIN_PAYMENT_SCHEDULEDETAIL SET AMOUNT=TO_NUMBER(?)  " +
+      "        WHERE FIN_PAYMENT_SCHEDULEDETAIL_ID = ?";
+
+    int updateCount = 0;
+    PreparedStatement st = null;
+
+    int iParameter = 0;
+    try {

------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to