IDEMPIERE-860 Review Payment Processors

This commit is contained in:
Elaine Tan 2013-04-16 15:54:27 +08:00
parent 37ca5f423a
commit 9c8f5b7363
3 changed files with 41 additions and 3 deletions

View File

@ -1964,7 +1964,18 @@ public class MInvoice extends X_C_Invoice implements DocAction
// auto delay capture authorization payment // auto delay capture authorization payment
if (isSOTrx() && !isReversal()) 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) if (ids.length > 0)
{ {
ArrayList<MPaymentTransaction> ptList = new ArrayList<MPaymentTransaction>(); ArrayList<MPaymentTransaction> ptList = new ArrayList<MPaymentTransaction>();
@ -1972,8 +1983,6 @@ public class MInvoice extends X_C_Invoice implements DocAction
for (int id : ids) for (int id : ids)
{ {
MPaymentTransaction pt = new MPaymentTransaction(Env.getCtx(), id, get_TrxName()); MPaymentTransaction pt = new MPaymentTransaction(Env.getCtx(), id, get_TrxName());
totalPayAmt = totalPayAmt.add(pt.getPayAmt()); totalPayAmt = totalPayAmt.add(pt.getPayAmt());
ptList.add(pt); ptList.add(pt);
} }

View File

@ -644,4 +644,32 @@ public class MPaymentTransaction extends X_C_PaymentTransaction implements Proce
return MPaymentTransaction.getAllIDs(Table_Name, whereClause.toString(), trxName); 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);
}
} }

View File

@ -216,6 +216,7 @@ public abstract class PaymentForm implements IPaymentForm {
{ {
int retValue = 0; int retValue = 0;
String sql = "SELECT C_Invoice_ID FROM C_Invoice WHERE C_Order_ID=? " 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 + "ORDER BY C_Invoice_ID DESC"; // last invoice
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;