diff --git a/migration/i1.0a-release/oracle/201304150457_IDEMPIERE-294.sql b/migration/i1.0a-release/oracle/201304150457_IDEMPIERE-294.sql new file mode 100644 index 0000000000..aa5cc8e3fe --- /dev/null +++ b/migration/i1.0a-release/oracle/201304150457_IDEMPIERE-294.sql @@ -0,0 +1,7 @@ +-- Apr 15, 2013 3:54:49 PM IST +-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator +UPDATE AD_Process SET AccessLevel='6',Updated=TO_DATE('2013-04-15 15:54:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_ID=200018 +; + +SELECT register_migration_script('201304150457_IDEMPIERE-294.sql') FROM dual +; diff --git a/migration/i1.0a-release/postgresql/201304150457_IDEMPIERE-294.sql b/migration/i1.0a-release/postgresql/201304150457_IDEMPIERE-294.sql new file mode 100644 index 0000000000..7cf1c749de --- /dev/null +++ b/migration/i1.0a-release/postgresql/201304150457_IDEMPIERE-294.sql @@ -0,0 +1,7 @@ +-- Apr 15, 2013 3:54:49 PM IST +-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator +UPDATE AD_Process SET AccessLevel='6',Updated=TO_TIMESTAMP('2013-04-15 15:54:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_ID=200018 +; + +SELECT register_migration_script('201304150457_IDEMPIERE-294.sql') FROM dual +; diff --git a/org.adempiere.base/src/org/compiere/model/MInvoice.java b/org.adempiere.base/src/org/compiere/model/MInvoice.java index 8cd679090e..4b780f2b0c 100644 --- a/org.adempiere.base/src/org/compiere/model/MInvoice.java +++ b/org.adempiere.base/src/org/compiere/model/MInvoice.java @@ -1964,7 +1964,18 @@ public class MInvoice extends X_C_Invoice implements DocAction // auto delay capture authorization payment if (isSOTrx() && !isReversal()) { - int[] ids = MPaymentTransaction.getAuthorizationPaymentTransactionIDs(getC_Order_ID(), getC_Invoice_ID(), get_TrxName()); + StringBuilder whereClause = new StringBuilder(); + whereClause.append("C_Order_ID IN ("); + whereClause.append("SELECT C_Order_ID "); + whereClause.append("FROM C_OrderLine "); + whereClause.append("WHERE C_OrderLine_ID IN ("); + whereClause.append("SELECT C_OrderLine_ID "); + whereClause.append("FROM C_InvoiceLine "); + whereClause.append("WHERE C_Invoice_ID = "); + whereClause.append(getC_Invoice_ID()).append("))"); + int[] orderIDList = MOrder.getAllIDs(MOrder.Table_Name, whereClause.toString(), get_TrxName()); + + int[] ids = MPaymentTransaction.getAuthorizationPaymentTransactionIDs(orderIDList, getC_Invoice_ID(), get_TrxName()); if (ids.length > 0) { ArrayList ptList = new ArrayList(); @@ -1972,8 +1983,6 @@ public class MInvoice extends X_C_Invoice implements DocAction for (int id : ids) { MPaymentTransaction pt = new MPaymentTransaction(Env.getCtx(), id, get_TrxName()); - - totalPayAmt = totalPayAmt.add(pt.getPayAmt()); ptList.add(pt); } diff --git a/org.adempiere.base/src/org/compiere/model/MPackage.java b/org.adempiere.base/src/org/compiere/model/MPackage.java index cc3c0c551c..093e16b945 100644 --- a/org.adempiere.base/src/org/compiere/model/MPackage.java +++ b/org.adempiere.base/src/org/compiere/model/MPackage.java @@ -443,11 +443,23 @@ public class MPackage extends X_M_Package sb.append("FROM M_InOutLine "); sb.append("WHERE M_InOut_ID = ?) "); sb.append("ORDER BY C_OrderLine_ID DESC"); - int C_Invoice_ID = DB.getSQLValue(get_TrxName(), sb.toString(), getM_InOut_ID()); - if (C_Invoice_ID > 0) - invoice = new MInvoice(getCtx(), C_Invoice_ID, get_TrxName()); + int C_Order_ID = DB.getSQLValue(get_TrxName(), sb.toString(), getM_InOut_ID()); + if (C_Order_ID > 0) + order = new MOrder(getCtx(), C_Order_ID, get_TrxName()); } } + + if (invoice == null && order != null) + { + StringBuilder sb = new StringBuilder(); + sb.append("SELECT C_Invoice_ID "); + sb.append("FROM C_Invoice "); + sb.append("WHERE C_Order_ID = ? "); + sb.append("ORDER BY C_Invoice_ID DESC"); + int C_Invoice_ID = DB.getSQLValue(get_TrxName(), sb.toString(), order.getC_Order_ID()); + if (C_Invoice_ID > 0) + invoice = new MInvoice(getCtx(), C_Invoice_ID, get_TrxName()); + } } MClientInfo ci = MClientInfo.get(getCtx(), getAD_Client_ID(), get_TrxName()); diff --git a/org.adempiere.base/src/org/compiere/model/MPaymentTransaction.java b/org.adempiere.base/src/org/compiere/model/MPaymentTransaction.java index 7a21a9c088..44cec5649e 100644 --- a/org.adempiere.base/src/org/compiere/model/MPaymentTransaction.java +++ b/org.adempiere.base/src/org/compiere/model/MPaymentTransaction.java @@ -644,4 +644,32 @@ public class MPaymentTransaction extends X_C_PaymentTransaction implements Proce return MPaymentTransaction.getAllIDs(Table_Name, whereClause.toString(), trxName); } + + public static int[] getAuthorizationPaymentTransactionIDs(int[] orderIDList, int C_Invoice_ID, String trxName) + { + StringBuilder sb = new StringBuilder(); + if (orderIDList != null) + { + for (int orderID : orderIDList) + sb.append(orderID).append(","); + } + + String orderIDs = sb.toString(); + if (orderIDs.length() > 0) + orderIDs = orderIDs.substring(0, orderIDs.length() - 1); + + StringBuilder whereClause = new StringBuilder(); + whereClause.append("TenderType='").append(MPaymentTransaction.TENDERTYPE_CreditCard).append("' "); + whereClause.append("AND TrxType='").append(MPaymentTransaction.TRXTYPE_Authorization).append("' "); + if (orderIDs.length() > 0 && C_Invoice_ID > 0) + whereClause.append(" AND (C_Order_ID IN (").append(orderIDs).append(") OR C_Invoice_ID=").append(C_Invoice_ID).append(")"); + else if (orderIDs.length() > 0) + whereClause.append(" AND C_Order_ID IN ('").append(orderIDs).append(")"); + else if (C_Invoice_ID > 0) + whereClause.append(" AND C_Invoice_ID=").append(C_Invoice_ID); + whereClause.append(" AND IsApproved='Y' AND IsVoided='N' AND IsDelayedCapture='N' "); + whereClause.append("ORDER BY DateTrx DESC"); + + return MPaymentTransaction.getAllIDs(Table_Name, whereClause.toString(), trxName); + } } diff --git a/org.adempiere.ui/src/org/compiere/grid/PaymentForm.java b/org.adempiere.ui/src/org/compiere/grid/PaymentForm.java index 812624dfdf..ffd2718012 100644 --- a/org.adempiere.ui/src/org/compiere/grid/PaymentForm.java +++ b/org.adempiere.ui/src/org/compiere/grid/PaymentForm.java @@ -216,6 +216,7 @@ public abstract class PaymentForm implements IPaymentForm { { int retValue = 0; String sql = "SELECT C_Invoice_ID FROM C_Invoice WHERE C_Order_ID=? " + + "AND DocStatus NOT IN ('VO','RE') " + "ORDER BY C_Invoice_ID DESC"; // last invoice PreparedStatement pstmt = null; ResultSet rs = null;