Steps To Reproduce | - Create a sales order from "F&B España - Región Norte" org to BP "Alimentos y Supermercados, S.A" for 1,000 and book it.
- Go to the Financial Account "Cuenta de Banco"
- Click on tab "Imported Bank Statement"
- Click on new, give it a name, and go to "Bank Statement Lines" tab.
- Click on new, give it a reference, choose "Alimentos y Supermercados, S.A" business partner, set amount in to 1,000.
- Click on save and process, and Match Statement.
- Click on "+" icon to create a transaction.
- Click on Add Payment In/Out
- Choose transaction type "Orders", set the amount to 1,000.
- Select just the 1,000 order created in the previous step.
- Click on process, and choose "Process Received payment/s and deposit", and click on Ok.
- Go to the sales order, and realize that payment schedule record says:
Expected Amount: 1,000
Received Amount: 2,000
Outstanding: -1,000 |
Attached Files | Fix28236.diff [^] (31,356 bytes) 2014-12-04 07:44 [Show Content] [Hide Content]# HG changeset patch
# User Pandeeswari Ramakrishnan <pandeeswari.ramakrishnan@openbravo.com>
# Date 1417618561 -19800
# Wed Dec 03 20:26:01 2014 +0530
# Node ID 2fe4986d49dbd96ce39b18cb131611996863ace8
# Parent 4ccbe7a7da1d0eed0677d7d0baf545607a192c87
Fixes Issue 28236: Payment schedule amount incorrectly calculated.
Payment schedule amount incorrectly calculated when adding a payment from reconcile window to a sales order
diff --git a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java
@@ -1160,15 +1160,18 @@
*/
public static void updatePaymentScheduleAmounts(FIN_PaymentDetail paymentDetail,
FIN_PaymentSchedule paymentSchedule, BigDecimal amount, BigDecimal writeOffAmount) {
- paymentSchedule.setPaidAmount(paymentSchedule.getPaidAmount().add(amount));
- paymentSchedule.setOutstandingAmount(paymentSchedule.getOutstandingAmount().subtract(amount));
- if (writeOffAmount != null && writeOffAmount.compareTo(BigDecimal.ZERO) != 0) {
- paymentSchedule.setPaidAmount(paymentSchedule.getPaidAmount().add(writeOffAmount));
- paymentSchedule.setOutstandingAmount(paymentSchedule.getOutstandingAmount().subtract(
- writeOffAmount));
+ if (paymentSchedule.getOutstandingAmount().compareTo(BigDecimal.ZERO) != 0) {
+ paymentSchedule.setPaidAmount(paymentSchedule.getPaidAmount().add(amount));
+ paymentSchedule.setOutstandingAmount(paymentSchedule.getOutstandingAmount().subtract(amount));
+ if (writeOffAmount != null && writeOffAmount.compareTo(BigDecimal.ZERO) != 0) {
+ paymentSchedule.setPaidAmount(paymentSchedule.getPaidAmount().add(writeOffAmount));
+ paymentSchedule.setOutstandingAmount(paymentSchedule.getOutstandingAmount().subtract(
+ writeOffAmount));
+ }
+ OBDal.getInstance().save(paymentSchedule);
+ CashVATUtil.createInvoiceTaxCashVAT(paymentDetail, paymentSchedule,
+ amount.add(writeOffAmount));
}
- OBDal.getInstance().save(paymentSchedule);
- CashVATUtil.createInvoiceTaxCashVAT(paymentDetail, paymentSchedule, amount.add(writeOffAmount));
if (paymentSchedule.getInvoice() != null) {
updateInvoicePaymentMonitor(paymentSchedule, amount, writeOffAmount);
}
diff --git a/src-util/modulescript/build/classes/org/openbravo/modulescript/UpdatePaymentPlan.class b/src-util/modulescript/build/classes/org/openbravo/modulescript/UpdatePaymentPlan.class
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f5cbad5d2325dfbb9a0c8b5f8e710f83ed6dd2e6
GIT binary patch
literal 1758
zc$}qG+foxj5IsXSyAW2vOVA)*xG1>*QP7|uc;TW{MGA?6r7sSf0an9qYO+Cn_bYt#
z#b>K5w0z(L`~pA4C-v+St1P7~qe-@Ry0_2io}TW_r>`G(0gPfH0UJXJv|~7d5#&R0
zzK!BSxEc+`SST)9xD<L7ER0*YEMQ)BJvW#Zh@~?t0>+GARstPG*Her2tu>|Z$+ZeC
zhl{==D=SjFq24eW!KPai7%BRCBkxz0x2EN`pWpJ!^@^%F+N}op`_-}x)RKI$rMzIN
zBE3lgOFdUkJs^WAxBR*ng#1tBw#@VSM!pni*V~|9OO@=SO|j3)KoV(4tp^0g9{m%z
zqCA4d0yA*A=&0_wl$=c!!fAG@0=ZwfNha51P332N&r?p|`reZEx81VRBu%)rxxHPN
zN&S!)d6GZvdhWTSsv(HZ2TFl-p5BqwsL;__U9r&3!y{42uWLumyI~?-zwKcpWVCSr
z2W?DX(!y06y_m8wjcYcpqszt(+_W)+SsQbh7dWy{4mNJ#w!ly`)e{)}gZrIGDMgAv
z=C4b~B5kN(Kl^Yx)6@x^Z?+ZK+36-CWO%4%O;u<Xc-$27pW5{3y6ZJMv)1TLm%U~0
zrEsG$Sa+LA<o6-W>^GNYJxWPn`TxlG3CEf1bhHXLtkt^G%5zk+=Rl73P3e^@YEEmP
zopL<=Q>1&F+J6>~)nsOclhMu>XZUG>2#1EUgIb<<!FxRW9^!5ExRcV1jNLdyY417U
zFpluf<M;s<Q;4CBwg=fAv=nn65S!|Gg&8i4#o-AfW$YH>v4WX2lkwLWOc_aYbi&G|
ztapfifH~2cOSLu>YxSim-hBH^XzS`5v=y_t9VFgHkr#27QDRYE1*Q(1Vm7Cdz!_%J
z%dGk^gno=;fWzL01)L)$OH>-m$Y2$@XdmlDjB__hbfJ}qWBeY6MQscz?$y8v{&Ac@
z57|!<bCN5Q?32{G89z?u(~QYC6J{B=kF{E+wV!drJRdYFbe2~?;@=3fES$42C@iG;
V6ZHCm>=zg}Eo9;ZWut=Uz5}f++Q|R_
diff --git a/src-util/modulescript/build/classes/org/openbravo/modulescript/UpdatePaymentPlanData.class b/src-util/modulescript/build/classes/org/openbravo/modulescript/UpdatePaymentPlanData.class
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..2be7968a199b532fe76a9815e197845af3dba04e
GIT binary patch
literal 11703
zc%0o>3w)H-mH(g2>&s*a7$G<Ya1?<&89)II&j3RS&C5JMv>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z_EZolX;(#uD%PoDy=mG8+ftq)E2~T(+f@=_E^Dl|lGEhslJl90N(y)<zX>k;KG<zb
ztF1(1&!E?#BDR5E$1wC(Wsv5`k6y<x^g4#3*D(yeAGYRPYbYDN&OveAma}=CN2e<A
zcA|%ho6a=RNkh#rzE7EL8WmD3rQ&5f$(knv-Y681f6dn01n>JO$8R~~1Dwrdu$UML
z@C3F&Y{nWrG9FuG93l+STV(=QvZG%d*h7FkMRPta8s3ybCaxmIgZ##eSH?*hTRzsO
zi}^0|DH=LrLDNBZFoEk}(lCMRAoSC)CIBqp+T;uaq{55ct43%qptK)Q6IW9DD$1?k
zYBxX{fqQ_rOh+1dH;558mrLewXbnN~g=SYa!H|eNeAOWUzLN>p1n_G1DftVA0eFKd
zE>OjVs`!*DE=r?#i8NUtR+k-y*Ci@A8}>e;U~RzjK&?G5Jni}6X&(kp`%rk=^TIRt
znscq8Y<M~{(z?}wQlZmvbc#afQUtKZ2&GGD?-|DT4y*kd_4fwe!Mnyy=MAH6qO%L9
zP=k|b`%+Xf7}m%%hNIK5P^M$4R1=+ktdSb5mD#*2%t5Q1iFSn;nTb1O7Vc!={I*mu
za8}_B(!WFccS-*q=|2!ZW7b>)k*y3hYc0&#(QYBqPHUQowBtQ%)Tu0*MkIa2L}U%a
z{_VyA#E<V8IJ6l!T%m&H8rV(5q_LJGN*2MHMUy8yYCPVhA41PC?ht_cWbj0N@qO?d
SFrFy~?-~<We$}{t-1SEcR&j~|
diff --git a/src-util/modulescript/build/javasqlc/src/org/openbravo/modulescript/UpdatePaymentPlanData.java b/src-util/modulescript/build/javasqlc/src/org/openbravo/modulescript/UpdatePaymentPlanData.java
new file mode 100644
--- /dev/null
+++ b/src-util/modulescript/build/javasqlc/src/org/openbravo/modulescript/UpdatePaymentPlanData.java
@@ -0,0 +1,307 @@
+//Sqlc generated V1.O00-1
+package org.openbravo.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 UpdatePaymentPlanData implements FieldProvider {
+static Logger log4j = Logger.getLogger(UpdatePaymentPlanData.class);
+ private String InitRecordNumber="0";
+ public String finpaymentscheduleid;
+ public String paidamt;
+ public String rownum;
+
+ public String getInitRecordNumber() {
+ return InitRecordNumber;
+ }
+
+ public String getField(String fieldName) {
+ if (fieldName.equalsIgnoreCase("FINPAYMENTSCHEDULEID"))
+ return finpaymentscheduleid;
+ else if (fieldName.equalsIgnoreCase("PAIDAMT"))
+ return paidamt;
+ else if (fieldName.equals("rownum"))
+ return rownum;
+ else {
+ log4j.debug("Field does not exist: " + fieldName);
+ return null;
+ }
+ }
+
+ public static UpdatePaymentPlanData[] dummy(ConnectionProvider connectionProvider) throws ServletException {
+ return dummy(connectionProvider, 0, 0);
+ }
+
+ public static UpdatePaymentPlanData[] dummy(ConnectionProvider connectionProvider, int firstRegister, int numberRegisters) throws ServletException {
+ String strSql = "";
+ strSql = strSql +
+ " SELECT '' AS finpaymentscheduleid, '' AS paidamt 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++;
+ UpdatePaymentPlanData objectUpdatePaymentPlanData = new UpdatePaymentPlanData();
+ objectUpdatePaymentPlanData.finpaymentscheduleid = UtilSql.getValue(result, "FINPAYMENTSCHEDULEID");
+ objectUpdatePaymentPlanData.paidamt = UtilSql.getValue(result, "PAIDAMT");
+ objectUpdatePaymentPlanData.rownum = Long.toString(countRecord);
+ objectUpdatePaymentPlanData.InitRecordNumber = Integer.toString(firstRegister);
+ vector.addElement(objectUpdatePaymentPlanData);
+ 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();
+ }
+ }
+ UpdatePaymentPlanData objectUpdatePaymentPlanData[] = new UpdatePaymentPlanData[vector.size()];
+ vector.copyInto(objectUpdatePaymentPlanData);
+ return(objectUpdatePaymentPlanData);
+ }
+
+ public static String selectAmount(ConnectionProvider connectionProvider, String finpaymentscheduleid) throws ServletException {
+ String strSql = "";
+ strSql = strSql +
+ " SELECT SUM(psd.amount) AS paidamt" +
+ " FROM fin_payment p" +
+ " LEFT JOIN fin_financial_account fa ON p.fin_financial_account_id = fa.fin_financial_account_id, fin_payment_detail pd" +
+ " JOIN fin_payment_scheduledetail psd ON pd.fin_payment_detail_id = psd.fin_payment_detail_id" +
+ " LEFT JOIN fin_payment_schedule psi ON psd.fin_payment_schedule_invoice = psi.fin_payment_schedule_id" +
+ " LEFT JOIN c_invoice i ON psi.c_invoice_id = i.c_invoice_id" +
+ " LEFT JOIN fin_payment_schedule pso ON psd.fin_payment_schedule_order = pso.fin_payment_schedule_id" +
+ " LEFT JOIN c_order o ON pso.c_order_id = o.c_order_id" +
+ " LEFT JOIN c_glitem gli ON pd.c_glitem_id = gli.c_glitem_id" +
+ " WHERE p.fin_payment_id = pd.fin_payment_id" +
+ " AND pso.fin_payment_schedule_id = ?";
+
+ ResultSet result;
+ String strReturn = null;
+ PreparedStatement st = null;
+
+ int iParameter = 0;
+ try {
+ st = connectionProvider.getPreparedStatement(strSql);
+ iParameter++; UtilSql.setValue(st, iParameter, 12, null, finpaymentscheduleid);
+
+ result = st.executeQuery();
+ if(result.next()) {
+ strReturn = UtilSql.getValue(result, "PAIDAMT");
+ }
+ 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();
+ }
+ }
+ return(strReturn);
+ }
+
+ public static UpdatePaymentPlanData[] select(ConnectionProvider connectionProvider) throws ServletException {
+ return select(connectionProvider, 0, 0);
+ }
+
+ public static UpdatePaymentPlanData[] select(ConnectionProvider connectionProvider, int firstRegister, int numberRegisters) throws ServletException {
+ String strSql = "";
+ strSql = strSql +
+ " SELECT fin.fin_payment_schedule_id AS finpaymentscheduleid" +
+ " FROM fin_payment_schedule fin" +
+ " WHERE paidamt <> (SELECT SUM(psd.amount)" +
+ " FROM fin_payment p" +
+ " LEFT JOIN fin_financial_account fa ON p.fin_financial_account_id = fa.fin_financial_account_id, fin_payment_detail pd" +
+ " JOIN fin_payment_scheduledetail psd ON pd.fin_payment_detail_id = psd.fin_payment_detail_id" +
+ " LEFT JOIN fin_payment_schedule psi ON psd.fin_payment_schedule_invoice = psi.fin_payment_schedule_id" +
+ " LEFT JOIN c_invoice i ON psi.c_invoice_id = i.c_invoice_id" +
+ " LEFT JOIN fin_payment_schedule pso ON psd.fin_payment_schedule_order = pso.fin_payment_schedule_id" +
+ " LEFT JOIN c_order o ON pso.c_order_id = o.c_order_id" +
+ " LEFT JOIN c_glitem gli ON pd.c_glitem_id = gli.c_glitem_id" +
+ " WHERE p.fin_payment_id = pd.fin_payment_id" +
+ " and pso.fin_payment_schedule_id = fin.fin_payment_schedule_id)";
+
+ 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++;
+ UpdatePaymentPlanData objectUpdatePaymentPlanData = new UpdatePaymentPlanData();
+ objectUpdatePaymentPlanData.finpaymentscheduleid = UtilSql.getValue(result, "FINPAYMENTSCHEDULEID");
+ objectUpdatePaymentPlanData.rownum = Long.toString(countRecord);
+ objectUpdatePaymentPlanData.InitRecordNumber = Integer.toString(firstRegister);
+ vector.addElement(objectUpdatePaymentPlanData);
+ 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();
+ }
+ }
+ UpdatePaymentPlanData objectUpdatePaymentPlanData[] = new UpdatePaymentPlanData[vector.size()];
+ vector.copyInto(objectUpdatePaymentPlanData);
+ return(objectUpdatePaymentPlanData);
+ }
+
+ public static int update(ConnectionProvider connectionProvider, String totalAmount, String finpaymentscheduleid) throws ServletException {
+ String strSql = "";
+ strSql = strSql +
+ " UPDATE fin_payment_schedule fin" +
+ " SET outstandingamt = amount - TO_NUMBER(?)," +
+ " paidamt = TO_NUMBER(?)" +
+ " WHERE fin.fin_payment_schedule_id = ?";
+
+ int updateCount = 0;
+ PreparedStatement st = null;
+
+ int iParameter = 0;
+ try {
+ st = connectionProvider.getPreparedStatement(strSql);
+ iParameter++; UtilSql.setValue(st, iParameter, 12, null, totalAmount);
+ iParameter++; UtilSql.setValue(st, iParameter, 12, null, totalAmount);
+ iParameter++; UtilSql.setValue(st, iParameter, 12, null, finpaymentscheduleid);
+
+ 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);
+ }
+
+ public static boolean isExecuted(ConnectionProvider connectionProvider) throws ServletException {
+ String strSql = "";
+ strSql = strSql +
+ " SELECT count(*) as exist" +
+ " FROM DUAL" +
+ " WHERE EXISTS (SELECT 1 FROM ad_preference" +
+ " WHERE attribute = 'PaymentPlanUpdated')";
+
+ ResultSet result;
+ boolean boolReturn = false;
+ PreparedStatement st = null;
+
+ try {
+ st = connectionProvider.getPreparedStatement(strSql);
+
+ result = st.executeQuery();
+ if(result.next()) {
+ boolReturn = !UtilSql.getValue(result, "EXIST").equals("0");
+ }
+ 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();
+ }
+ }
+ return(boolReturn);
+ }
+
+ public static int createPreference(ConnectionProvider connectionProvider) throws ServletException {
+ String strSql = "";
+ strSql = strSql +
+ " 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(),'PaymentPlanUpdated')";
+
+ 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);
+ }
+}
diff --git a/src-util/modulescript/src/org/openbravo/modulescript/UpdatePaymentPlan.java b/src-util/modulescript/src/org/openbravo/modulescript/UpdatePaymentPlan.java
new file mode 100644
--- /dev/null
+++ b/src-util/modulescript/src/org/openbravo/modulescript/UpdatePaymentPlan.java
@@ -0,0 +1,44 @@
+/*
+ *************************************************************************
+ * 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) 2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s): ______________________________________.
+ *************************************************************************
+ */
+package org.openbravo.modulescript;
+
+import java.sql.PreparedStatement;
+
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.modulescript.ModuleScript;
+
+public class UpdatePaymentPlan extends ModuleScript {
+
+ public void execute() {
+ try {
+ ConnectionProvider cp = getConnectionProvider();
+ boolean isExecuted = UpdatePaymentPlanData.isExecuted(cp);
+ if (!isExecuted) {
+ UpdatePaymentPlanData[] paymentSchedule = UpdatePaymentPlanData.select(cp);
+ for (UpdatePaymentPlanData ps : paymentSchedule) {
+ String amount = UpdatePaymentPlanData.selectAmount(cp, ps.finpaymentscheduleid);
+ UpdatePaymentPlanData.update(cp, amount, ps.finpaymentscheduleid);
+ }
+ UpdatePaymentPlanData.createPreference(cp);
+ }
+ } catch (Exception e) {
+ handleError(e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src-util/modulescript/src/org/openbravo/modulescript/UpdatePaymentPlan_data.xsql b/src-util/modulescript/src/org/openbravo/modulescript/UpdatePaymentPlan_data.xsql
new file mode 100644
--- /dev/null
+++ b/src-util/modulescript/src/org/openbravo/modulescript/UpdatePaymentPlan_data.xsql
@@ -0,0 +1,109 @@
+<?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) 2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s): ______________________________________.
+ ************************************************************************
+-->
+<SqlClass name="UpdatePaymentPlanData" package="org.openbravo.modulescript">
+ <SqlClassComment></SqlClassComment>
+ <SqlMethod name="dummy" type="preparedStatement" return="multiple">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql>
+ <![CDATA[
+ SELECT '' AS finpaymentscheduleid, '' AS paidamt FROM DUAL
+ ]]>
+ </Sql>
+ <Field name="rownum" value="count"/>
+ </SqlMethod>
+ <SqlMethod name="selectAmount" type="preparedStatement" return="string">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql>
+ <![CDATA[
+ SELECT SUM(psd.amount) AS paidamt
+ FROM fin_payment p
+ LEFT JOIN fin_financial_account fa ON p.fin_financial_account_id = fa.fin_financial_account_id, fin_payment_detail pd
+ JOIN fin_payment_scheduledetail psd ON pd.fin_payment_detail_id = psd.fin_payment_detail_id
+ LEFT JOIN fin_payment_schedule psi ON psd.fin_payment_schedule_invoice = psi.fin_payment_schedule_id
+ LEFT JOIN c_invoice i ON psi.c_invoice_id = i.c_invoice_id
+ LEFT JOIN fin_payment_schedule pso ON psd.fin_payment_schedule_order = pso.fin_payment_schedule_id
+ LEFT JOIN c_order o ON pso.c_order_id = o.c_order_id
+ LEFT JOIN c_glitem gli ON pd.c_glitem_id = gli.c_glitem_id
+ WHERE p.fin_payment_id = pd.fin_payment_id
+ AND pso.fin_payment_schedule_id = ?
+ ]]>
+ </Sql>
+ <Field name="rownum" value="count"/>
+ <Parameter name="finpaymentscheduleid"/>
+ </SqlMethod>
+ <SqlMethod name="select" type="preparedStatement" return="multiple">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql>
+ <![CDATA[
+ SELECT fin.fin_payment_schedule_id AS finpaymentscheduleid
+ FROM fin_payment_schedule fin
+ WHERE paidamt <> (SELECT SUM(psd.amount)
+ FROM fin_payment p
+ LEFT JOIN fin_financial_account fa ON p.fin_financial_account_id = fa.fin_financial_account_id, fin_payment_detail pd
+ JOIN fin_payment_scheduledetail psd ON pd.fin_payment_detail_id = psd.fin_payment_detail_id
+ LEFT JOIN fin_payment_schedule psi ON psd.fin_payment_schedule_invoice = psi.fin_payment_schedule_id
+ LEFT JOIN c_invoice i ON psi.c_invoice_id = i.c_invoice_id
+ LEFT JOIN fin_payment_schedule pso ON psd.fin_payment_schedule_order = pso.fin_payment_schedule_id
+ LEFT JOIN c_order o ON pso.c_order_id = o.c_order_id
+ LEFT JOIN c_glitem gli ON pd.c_glitem_id = gli.c_glitem_id
+ WHERE p.fin_payment_id = pd.fin_payment_id
+ and pso.fin_payment_schedule_id = fin.fin_payment_schedule_id)
+ ]]>
+ </Sql>
+ <Field name="rownum" value="count"/>
+ </SqlMethod>
+ <SqlMethod name="update" type="preparedStatement" return="rowCount">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql>
+ <![CDATA[
+ UPDATE fin_payment_schedule fin
+ SET outstandingamt = amount - TO_NUMBER(?),
+ paidamt = TO_NUMBER(?)
+ WHERE fin.fin_payment_schedule_id = ?
+ ]]>
+ </Sql>
+ <Parameter name="totalAmount"/>
+ <Parameter name="totalAmount"/>
+ <Parameter name="finpaymentscheduleid"/>
+ </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 = 'PaymentPlanUpdated')
+ ]]>
+ </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(),'PaymentPlanUpdated')
+ ]]>
+ </Sql>
+ </SqlMethod>
+</SqlClass>
\ No newline at end of file
|