diff --git a/db/ddlutils/oracle/functions/C_Invoice_Discount.sql b/db/ddlutils/oracle/functions/C_Invoice_Discount.sql index 81844857e8..63be6c2214 100644 --- a/db/ddlutils/oracle/functions/C_Invoice_Discount.sql +++ b/db/ddlutils/oracle/functions/C_Invoice_Discount.sql @@ -59,7 +59,7 @@ BEGIN INTO v_Amount FROM C_InvoicePaySchedule WHERE C_InvoicePaySchedule_ID=p_C_InvoicePaySchedule_ID - AND DiscountDate <= v_PayDate; + AND DiscountDate >= v_PayDate; -- RETURN v_Amount; END IF; diff --git a/db/ddlutils/postgresql/functions/C_Invoice_Discount.sql b/db/ddlutils/postgresql/functions/C_Invoice_Discount.sql index 6915dca361..5e75131594 100644 --- a/db/ddlutils/postgresql/functions/C_Invoice_Discount.sql +++ b/db/ddlutils/postgresql/functions/C_Invoice_Discount.sql @@ -64,7 +64,7 @@ BEGIN INTO v_Amount FROM C_InvoicePaySchedule WHERE C_InvoicePaySchedule_ID=p_C_InvoicePaySchedule_ID - AND DiscountDate <= v_PayDate; + AND DiscountDate >= v_PayDate; -- RETURN v_Amount; END IF; diff --git a/migration/i2.0z/oracle/201408111139_IDEMPIERE-2134.sql b/migration/i2.0z/oracle/201408111139_IDEMPIERE-2134.sql new file mode 100644 index 0000000000..360dee24fd --- /dev/null +++ b/migration/i2.0z/oracle/201408111139_IDEMPIERE-2134.sql @@ -0,0 +1,87 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Aug 11, 2014 11:38:21 AM CEST +-- IDEMPIERE-2134 Issues found on Payment Selection process +UPDATE AD_Process_Para SET DefaultValue='N',Updated=TO_DATE('2014-08-11 11:38:21','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=184 +; + +CREATE OR REPLACE FUNCTION invoiceDiscount +( + p_C_Invoice_ID IN NUMBER, + p_PayDate IN DATE, + p_C_InvoicePaySchedule_ID IN NUMBER +) +RETURN NUMBER +/************************************************************************* + * The contents of this file are subject to the Compiere License. You may + * obtain a copy of the License at http://www.compiere.org/license.html + * Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either + * express or implied. See the License for details. Code: Compiere ERP+CRM + * Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved. + ************************************************************************* + * $Id: C_Invoice_Discount.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $ + *** + * Title: Calculate Payment Discount Amount + * Description: + * - Calculate discountable amount (i.e. with or without tax) + * - Calculate and return payment discount + ************************************************************************/ +AS + v_Amount NUMBER; + v_IsDiscountLineAmt CHAR(1); + v_GrandTotal NUMBER; + v_TotalLines NUMBER; + v_C_PaymentTerm_ID NUMBER(10); + v_C_Currency_ID NUMBER(10); + v_DocDate DATE; + v_PayDate DATE := SysDate; + v_IsPayScheduleValid CHAR(1); + +BEGIN + SELECT ci.IsDiscountLineAmt, i.GrandTotal, i.TotalLines, + i.C_PaymentTerm_ID, i.DateInvoiced, i.IsPayScheduleValid, C_Currency_ID + INTO v_IsDiscountLineAmt, v_GrandTotal, v_TotalLines, + v_C_PaymentTerm_ID, v_DocDate, v_IsPayScheduleValid, v_C_Currency_ID + FROM AD_ClientInfo ci, C_Invoice i + WHERE ci.AD_Client_ID=i.AD_Client_ID + AND i.C_Invoice_ID=p_C_Invoice_ID; + -- What Amount is the Discount Base? + IF (v_IsDiscountLineAmt = 'Y') THEN + v_Amount := v_TotalLines; + ELSE + v_Amount := v_GrandTotal; + END IF; + + -- Anything to discount? + IF (v_Amount = 0) THEN + RETURN 0; + END IF; + IF (p_PayDate IS NOT NULL) THEN + v_PayDate := p_PayDate; + END IF; + + -- Valid Payment Schedule + IF (v_IsPayScheduleValid='Y' AND p_C_InvoicePaySchedule_ID > 0) THEN + SELECT COALESCE(MAX(DiscountAmt),0) + INTO v_Amount + FROM C_InvoicePaySchedule + WHERE C_InvoicePaySchedule_ID=p_C_InvoicePaySchedule_ID + AND DiscountDate >= v_PayDate; + -- + RETURN v_Amount; + END IF; + + -- return discount amount + RETURN paymentTermDiscount (v_Amount, v_C_Currency_ID, v_C_PaymentTerm_ID, v_DocDate, p_PayDate); + +-- Most likely if invoice not found +EXCEPTION + WHEN OTHERS THEN + RETURN NULL; +END invoiceDiscount; +/ + +SELECT register_migration_script('201408111139_IDEMPIERE-2134.sql') FROM dual +; + diff --git a/migration/i2.0z/postgresql/201408111139_IDEMPIERE-2134.sql b/migration/i2.0z/postgresql/201408111139_IDEMPIERE-2134.sql new file mode 100644 index 0000000000..e86f960e6c --- /dev/null +++ b/migration/i2.0z/postgresql/201408111139_IDEMPIERE-2134.sql @@ -0,0 +1,90 @@ +-- Aug 11, 2014 11:38:21 AM CEST +-- IDEMPIERE-2134 Issues found on Payment Selection process +UPDATE AD_Process_Para SET DefaultValue='N',Updated=TO_TIMESTAMP('2014-08-11 11:38:21','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=184 +; + +CREATE OR REPLACE FUNCTION invoiceDiscount +( + p_C_Invoice_ID NUMERIC, + p_paydate timestamp with time zone, + p_C_InvoicePaySchedule_ID NUMERIC +) +RETURNS numeric AS $body$ +/************************************************************************* + * The contents of this file are subject to the Compiere License. You may + * obtain a copy of the License at http://www.compiere.org/license.html + * Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either + * express or implied. See the License for details. Code: Compiere ERP+CRM + * Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved. + * + * converted to postgreSQL by Karsten Thiemann (Schaeffer AG), + * kthiemann@adempiere.org + ************************************************************************* + *** + * Title: Calculate Payment Discount Amount + * Description: + * - Calculate discountable amount (i.e. with or without tax) + * - Calculate and return payment discount + * Test: + * select invoiceDiscount(109, now(), 103) from ad_system; => 0 + ************************************************************************/ +DECLARE + v_Amount NUMERIC; + v_IsDiscountLineAmt CHAR(1); + v_GrandTotal NUMERIC; + v_TotalLines NUMERIC; + v_C_PaymentTerm_ID NUMERIC(10); + v_C_Currency_ID NUMERIC(10); + v_DocDate timestamp with time zone; + v_PayDate timestamp with time zone := now(); + v_IsPayScheduleValid CHAR(1); + +BEGIN + SELECT ci.IsDiscountLineAmt, i.GrandTotal, i.TotalLines, + i.C_PaymentTerm_ID, i.DateInvoiced, i.IsPayScheduleValid, C_Currency_ID + INTO v_IsDiscountLineAmt, v_GrandTotal, v_TotalLines, + v_C_PaymentTerm_ID, v_DocDate, v_IsPayScheduleValid, v_C_Currency_ID + FROM AD_ClientInfo ci, C_Invoice i + WHERE ci.AD_Client_ID=i.AD_Client_ID + AND i.C_Invoice_ID=p_C_Invoice_ID; + + -- What Amount is the Discount Base? + IF (v_IsDiscountLineAmt = 'Y') THEN + v_Amount := v_TotalLines; + ELSE + v_Amount := v_GrandTotal; + END IF; + + -- Anything to discount? + IF (v_Amount = 0) THEN + RETURN 0; + END IF; + IF (p_PayDate IS NOT NULL) THEN + v_PayDate := p_PayDate; + END IF; + + -- Valid Payment Schedule + IF (v_IsPayScheduleValid='Y' AND p_C_InvoicePaySchedule_ID > 0) THEN + SELECT COALESCE(MAX(DiscountAmt),0) + INTO v_Amount + FROM C_InvoicePaySchedule + WHERE C_InvoicePaySchedule_ID=p_C_InvoicePaySchedule_ID + AND DiscountDate >= v_PayDate; + -- + RETURN v_Amount; + END IF; + + -- return discount amount + RETURN paymentTermDiscount (v_Amount, v_C_Currency_ID, v_C_PaymentTerm_ID, v_DocDate, p_PayDate); + +-- Most likely if invoice not found +EXCEPTION + WHEN OTHERS THEN + RETURN NULL; +END; + +$body$ LANGUAGE plpgsql STABLE; + +SELECT register_migration_script('201408111139_IDEMPIERE-2134.sql') FROM dual +; + diff --git a/org.adempiere.base.process/src/org/compiere/process/PaySelectionCreateFrom.java b/org.adempiere.base.process/src/org/compiere/process/PaySelectionCreateFrom.java index 12ad769f87..11c28a83c1 100644 --- a/org.adempiere.base.process/src/org/compiere/process/PaySelectionCreateFrom.java +++ b/org.adempiere.base.process/src/org/compiere/process/PaySelectionCreateFrom.java @@ -19,11 +19,15 @@ package org.compiere.process; import java.math.BigDecimal; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.SQLException; import java.sql.Timestamp; import java.util.logging.Level; +import org.adempiere.exceptions.AdempiereException; +import org.adempiere.exceptions.DBException; import org.compiere.model.MPaySelection; import org.compiere.model.MPaySelectionLine; +import org.compiere.model.X_C_Order; import org.compiere.util.DB; import org.compiere.util.Env; @@ -115,21 +119,27 @@ public class PaySelectionCreateFrom extends SvrProcess StringBuilder sql = new StringBuilder("SELECT C_Invoice_ID,") // Open - .append(" currencyConvert(invoiceOpen(i.C_Invoice_ID, 0)") - .append(",i.C_Currency_ID, ?,?, i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID),") // ##1/2 Currency_To,PayDate + .append(" currencyConvert(invoiceOpen(i.C_Invoice_ID, i.C_InvoicePaySchedule_ID)") + .append(",i.C_Currency_ID, ?,?, i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID) AS PayAmt,") // ##1/2 Currency_To,PayDate // Discount - .append(" currencyConvert(paymentTermDiscount(i.GrandTotal,i.C_Currency_ID,i.C_PaymentTerm_ID,i.DateInvoiced, ?)") // ##3 PayDate - .append(",i.C_Currency_ID, ?,?,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID),") // ##4/5 Currency_To,PayDate + .append(" currencyConvert(invoiceDiscount(i.C_Invoice_ID,?,i.C_InvoicePaySchedule_ID)") // ##3 PayDate + .append(",i.C_Currency_ID, ?,?,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID) AS DiscountAmt,") // ##4/5 Currency_To,PayDate .append(" PaymentRule, IsSOTrx ") // 4..6 - .append("FROM C_Invoice i ") - .append("WHERE IsSOTrx='N' AND IsPaid='N' AND DocStatus IN ('CO','CL')") + .append("FROM C_Invoice_v i WHERE "); + if (X_C_Order.PAYMENTRULE_DirectDebit.equals(p_PaymentRule)) + sql.append("IsSOTrx='Y'"); + else + sql.append("IsSOTrx='N'"); + sql.append(" AND IsPaid='N' AND DocStatus IN ('CO','CL')") .append(" AND AD_Client_ID=?") // ##6 // Existing Payments - Will reselect Invoice if prepared but not paid .append(" AND NOT EXISTS (SELECT * FROM C_PaySelectionLine psl") .append(" INNER JOIN C_PaySelectionCheck psc ON (psl.C_PaySelectionCheck_ID=psc.C_PaySelectionCheck_ID)") .append(" LEFT OUTER JOIN C_Payment pmt ON (pmt.C_Payment_ID=psc.C_Payment_ID)") .append(" WHERE i.C_Invoice_ID=psl.C_Invoice_ID AND psl.IsActive='Y'") - .append(" AND (pmt.DocStatus IS NULL OR pmt.DocStatus NOT IN ('VO','RE')) )"); + .append(" AND (pmt.DocStatus IS NULL OR pmt.DocStatus NOT IN ('VO','RE')) )") + // Don't generate again invoices already on this payment selection + .append(" AND i.C_Invoice_ID NOT IN (SELECT i.C_Invoice_ID FROM C_PaySelectionLine psl WHERE psl.C_PaySelection_ID=?)"); // ##7 // Disputed if (!p_IncludeInDispute) sql.append(" AND i.IsInDispute='N'"); @@ -143,7 +153,7 @@ public class PaySelectionCreateFrom extends SvrProcess sql.append(" AND ("); else sql.append(" AND "); - sql.append("paymentTermDiscount(invoiceOpen(C_Invoice_ID, 0), C_Currency_ID, C_PaymentTerm_ID, DateInvoiced, ?) > 0"); // ## + sql.append("invoiceDiscount(i.C_Invoice_ID,?,i.C_InvoicePaySchedule_ID) > 0"); // ## } // OnlyDue if (p_OnlyDue) @@ -152,7 +162,8 @@ public class PaySelectionCreateFrom extends SvrProcess sql.append(" OR "); else sql.append(" AND "); - sql.append("paymentTermDueDays(C_PaymentTerm_ID, DateInvoiced, ?) >= 0"); // ## + // sql.append("paymentTermDueDays(C_PaymentTerm_ID, DateInvoiced, ?) >= 0"); // ## + sql.append("i.DueDate<=?"); // ## if (p_OnlyDiscount) sql.append(")"); } @@ -197,6 +208,7 @@ public class PaySelectionCreateFrom extends SvrProcess pstmt.setTimestamp(index++, psel.getPayDate()); // pstmt.setInt(index++, psel.getAD_Client_ID()); + pstmt.setInt(index++, p_C_PaySelection_ID); if (p_PaymentRule != null) pstmt.setString(index++, p_PaymentRule); if (p_OnlyDiscount) @@ -229,9 +241,13 @@ public class PaySelectionCreateFrom extends SvrProcess } } } + catch (SQLException e) + { + throw new DBException(e); + } catch (Exception e) { - log.log(Level.SEVERE, sql.toString(), e); + throw new AdempiereException(e); } finally { diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaySelect.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaySelect.java index 5fe683d99e..c4f974cac0 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaySelect.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaySelect.java @@ -39,6 +39,8 @@ import org.adempiere.webui.component.Row; import org.adempiere.webui.component.Rows; import org.adempiere.webui.component.WListbox; import org.adempiere.webui.editor.WDateEditor; +import org.adempiere.webui.event.ValueChangeEvent; +import org.adempiere.webui.event.ValueChangeListener; import org.adempiere.webui.event.WTableModelEvent; import org.adempiere.webui.event.WTableModelListener; import org.adempiere.webui.panel.ADForm; @@ -76,7 +78,7 @@ import org.zkoss.zul.Space; * @version $Id: VPaySelect.java,v 1.3 2006/07/30 00:51:28 jjanke Exp $ */ public class WPaySelect extends PaySelect - implements IFormController, EventListener, WTableModelListener, IProcessUI + implements IFormController, EventListener, WTableModelListener, IProcessUI, ValueChangeListener { /** @todo withholding */ @@ -164,6 +166,8 @@ public class WPaySelect extends PaySelect onlyDue.setText(Msg.getMsg(Env.getCtx(), "OnlyDue")); dataStatus.setText(" "); dataStatus.setPre(true); + onlyDue.addActionListener(this); + fieldPayDate.addValueChangeListener(this); // bGenerate.addActionListener(this); bCancel.addActionListener(this); @@ -322,11 +326,18 @@ public class WPaySelect extends PaySelect dispose(); // Update Open Invoices - else if (e.getTarget() == fieldBPartner || e.getTarget() == bRefresh || e.getTarget() == fieldDtype) + else if (e.getTarget() == fieldBPartner || e.getTarget() == bRefresh || e.getTarget() == fieldDtype + || e.getTarget() == fieldPaymentRule || e.getTarget() == onlyDue) loadTableInfo(); } // actionPerformed + @Override + public void valueChange(ValueChangeEvent e) { + if (e.getSource() == fieldPayDate) + loadTableInfo(); + } + /** * Table Model Listener * @param e event diff --git a/org.adempiere.ui/src/org/compiere/apps/form/PayPrint.java b/org.adempiere.ui/src/org/compiere/apps/form/PayPrint.java index c0214f5922..37817a3bb0 100644 --- a/org.adempiere.ui/src/org/compiere/apps/form/PayPrint.java +++ b/org.adempiere.ui/src/org/compiere/apps/form/PayPrint.java @@ -17,6 +17,8 @@ *****************************************************************************/ package org.compiere.apps.form; +import static org.compiere.model.SystemIDs.REFERENCE_PAYMENTRULE; + import java.math.BigDecimal; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -28,11 +30,9 @@ import org.compiere.model.MLookupFactory; import org.compiere.model.MLookupInfo; import org.compiere.model.MPaySelectionCheck; import org.compiere.model.MPaymentBatch; -import static org.compiere.model.SystemIDs.*; import org.compiere.util.CLogger; import org.compiere.util.DB; import org.compiere.util.Env; -import org.compiere.util.KeyNamePair; import org.compiere.util.Language; import org.compiere.util.ValueNamePair; @@ -54,45 +54,6 @@ public class PayPrint { /** Logger */ public static CLogger log = CLogger.getCLogger(PayPrint.class); - public ArrayList getPaySelectionData() - { - ArrayList data = new ArrayList(); - - log.config(""); - int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx()); - - // Load PaySelect - String sql = "SELECT C_PaySelection_ID, Name || ' - ' || TotalAmt FROM C_PaySelection " - + "WHERE AD_Client_ID=? AND Processed='Y' AND IsActive='Y'" - + "ORDER BY PayDate DESC"; - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement(sql, null); - pstmt.setInt(1, AD_Client_ID); - rs = pstmt.executeQuery(); - // - while (rs.next()) - { - KeyNamePair pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); - data.add(pp); - } - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql, e); - } - finally - { - DB.close(rs, pstmt); - rs = null; - pstmt = null; - } - - return data; - } - public String bank; public String currency; public BigDecimal balance; diff --git a/org.adempiere.ui/src/org/compiere/apps/form/PaySelect.java b/org.adempiere.ui/src/org/compiere/apps/form/PaySelect.java index 636d6d6727..44fa79b307 100644 --- a/org.adempiere.ui/src/org/compiere/apps/form/PaySelect.java +++ b/org.adempiere.ui/src/org/compiere/apps/form/PaySelect.java @@ -25,6 +25,8 @@ import java.util.ArrayList; import java.util.Properties; import java.util.logging.Level; +import org.adempiere.exceptions.AdempiereException; +import org.adempiere.exceptions.DBException; import org.compiere.minigrid.ColumnInfo; import org.compiere.minigrid.IDColumn; import org.compiere.minigrid.IMiniTable; @@ -173,7 +175,7 @@ public class PaySelect try { sql = MRole.getDefault().addAccessSQL( - "SELECT doc.c_doctype_id,doc.name FROM c_doctype doc WHERE doc.ad_client_id = ? AND doc.docbasetype in ('API','APC') ORDER BY 2", "doc", + "SELECT doc.c_doctype_id,doc.name FROM c_doctype doc WHERE doc.ad_client_id = ? AND doc.docbasetype in ('API','APC','ARI','ARC') ORDER BY 2", "doc", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO); KeyNamePair dt = new KeyNamePair(0, ""); @@ -214,7 +216,7 @@ public class PaySelect i.GrandTotal-paymentTermDiscount(i.GrandTotal,i.C_PaymentTerm_ID,i.DateInvoiced,SysDate) AS DueAmount, currencyConvert(i.GrandTotal-paymentTermDiscount(i.GrandTotal,i.C_PaymentTerm_ID,i.DateInvoiced,SysDate,null), i.C_Currency_ID,xx100,SysDate) AS PayAmt - FROM C_Invoice i, C_BPartner bp, C_Currency c, C_PaymentTerm p + FROM C_Invoice_v i, C_BPartner bp, C_Currency c, C_PaymentTerm p WHERE i.IsSOTrx='N' AND i.C_BPartner_ID=bp.C_BPartner_ID AND i.C_Currency_ID=c.C_Currency_ID @@ -226,16 +228,16 @@ public class PaySelect m_sql = miniTable.prepareTable(new ColumnInfo[] { // 0..4 new ColumnInfo(" ", "i.C_Invoice_ID", IDColumn.class, false, false, null), - new ColumnInfo(Msg.translate(ctx, "DueDate"), "paymentTermDueDate(i.C_PaymentTerm_ID, i.DateInvoiced) AS DateDue", Timestamp.class, true, true, null), + new ColumnInfo(Msg.translate(ctx, "DueDate"), "i.DueDate AS DateDue", Timestamp.class, true, true, null), new ColumnInfo(Msg.translate(ctx, "C_BPartner_ID"), "bp.Name", KeyNamePair.class, true, false, "i.C_BPartner_ID"), new ColumnInfo(Msg.translate(ctx, "DocumentNo"), "i.DocumentNo", String.class), new ColumnInfo(Msg.translate(ctx, "C_Currency_ID"), "c.ISO_Code", KeyNamePair.class, true, false, "i.C_Currency_ID"), // 5..9 new ColumnInfo(Msg.translate(ctx, "GrandTotal"), "i.GrandTotal", BigDecimal.class), - new ColumnInfo(Msg.translate(ctx, "DiscountAmt"), "paymentTermDiscount(i.GrandTotal,i.C_Currency_ID,i.C_PaymentTerm_ID,i.DateInvoiced, ?)", BigDecimal.class), - new ColumnInfo(Msg.getMsg(ctx, "DiscountDate"), "SysDate-paymentTermDueDays(i.C_PaymentTerm_ID,i.DateInvoiced,SysDate)", Timestamp.class), - new ColumnInfo(Msg.getMsg(ctx, "AmountDue"), "currencyConvert(invoiceOpen(i.C_Invoice_ID,i.C_InvoicePaySchedule_ID),i.C_Currency_ID, ?,?,i.C_ConversionType_ID, i.AD_Client_ID,i.AD_Org_ID)", BigDecimal.class), - new ColumnInfo(Msg.getMsg(ctx, "AmountPay"), "currencyConvert(invoiceOpen(i.C_Invoice_ID,i.C_InvoicePaySchedule_ID)-paymentTermDiscount(i.GrandTotal,i.C_Currency_ID,i.C_PaymentTerm_ID,i.DateInvoiced, ?),i.C_Currency_ID, ?,?,i.C_ConversionType_ID, i.AD_Client_ID,i.AD_Org_ID)", BigDecimal.class) + new ColumnInfo(Msg.translate(ctx, "DiscountAmt"), "invoiceDiscount(i.C_Invoice_ID,?,i.C_InvoicePaySchedule_ID)", BigDecimal.class), + new ColumnInfo(Msg.getMsg(ctx, "DiscountDate"), "COALESCE((SELECT discountdate from C_InvoicePaySchedule ips WHERE ips.C_InvoicePaySchedule_ID=i.C_InvoicePaySchedule_ID),i.DateInvoiced+p.DiscountDays+p.GraceDays) AS DiscountDate", Timestamp.class), + new ColumnInfo(Msg.getMsg(ctx, "AmountDue"), "currencyConvert(invoiceOpen(i.C_Invoice_ID,i.C_InvoicePaySchedule_ID),i.C_Currency_ID, ?,?,i.C_ConversionType_ID, i.AD_Client_ID,i.AD_Org_ID) AS AmountDue", BigDecimal.class), + new ColumnInfo(Msg.getMsg(ctx, "AmountPay"), "currencyConvert(invoiceOpen(i.C_Invoice_ID,i.C_InvoicePaySchedule_ID)-invoiceDiscount(i.C_Invoice_ID,?,i.C_InvoicePaySchedule_ID),i.C_Currency_ID, ?,?,i.C_ConversionType_ID, i.AD_Client_ID,i.AD_Org_ID) AS AmountPay", BigDecimal.class) }, // FROM "C_Invoice_v i" @@ -271,7 +273,7 @@ public class PaySelect MLookupInfo info = MLookupFactory.getLookup_List(language, AD_Reference_ID); String sql = info.Query.substring(0, info.Query.indexOf(" ORDER BY")) + " AND " + info.KeyColumn - + " IN (SELECT PaymentRule FROM C_BankAccountDoc WHERE C_BankAccount_ID=?) " + + " IN (SELECT PaymentRule FROM C_BankAccountDoc WHERE C_BankAccount_ID=? AND IsActive='Y') " + info.Query.substring(info.Query.indexOf(" ORDER BY")); PreparedStatement pstmt = null; ResultSet rs = null; @@ -283,7 +285,7 @@ public class PaySelect ValueNamePair vp = null; while (rs.next()) { - vp = new ValueNamePair(rs.getString(2), rs.getString(3)); // returns also not active + vp = new ValueNamePair(rs.getString(2), rs.getString(3)); data.add(vp); } } @@ -321,7 +323,7 @@ public class PaySelect } // if (onlyDue) - sql += " AND paymentTermDueDate(i.C_PaymentTerm_ID, i.DateInvoiced) <= ?"; + sql += " AND i.DueDate <= ?"; // KeyNamePair pp = bpartner; int C_BPartner_ID = pp.getKey(); @@ -362,7 +364,11 @@ public class PaySelect } catch (SQLException e) { - log.log(Level.SEVERE, sql, e); + throw new DBException(e); + } + catch (Exception e) + { + throw new AdempiereException(e); } finally {