IDEMPIERE-4557 Order document by DateTrx and Created on Auto Allocation process (#395)
- change the order by for payments from "DateTrx" to "DateTrx, Created, C_Payment_ID" - change the order by for invoices from "DateInvoiced" to "DateInvoiced, Created, C_Invoice_ID" - refactor four JDBC managed queries to use the Query function
This commit is contained in:
parent
0cc35e16f8
commit
56237276ad
|
@ -17,21 +17,21 @@
|
||||||
package org.compiere.process;
|
package org.compiere.process;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.model.MAllocationHdr;
|
import org.compiere.model.MAllocationHdr;
|
||||||
import org.compiere.model.MAllocationLine;
|
import org.compiere.model.MAllocationLine;
|
||||||
|
import org.compiere.model.MBPartner;
|
||||||
import org.compiere.model.MClient;
|
import org.compiere.model.MClient;
|
||||||
import org.compiere.model.MInvoice;
|
import org.compiere.model.MInvoice;
|
||||||
import org.compiere.model.MPaySelectionCheck;
|
import org.compiere.model.MPaySelectionCheck;
|
||||||
import org.compiere.model.MPaySelectionLine;
|
import org.compiere.model.MPaySelectionLine;
|
||||||
import org.compiere.model.MPayment;
|
import org.compiere.model.MPayment;
|
||||||
|
import org.compiere.model.Query;
|
||||||
import org.compiere.util.AdempiereSystemError;
|
import org.compiere.util.AdempiereSystemError;
|
||||||
import org.compiere.util.DB;
|
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.Msg;
|
import org.compiere.util.Msg;
|
||||||
|
|
||||||
|
@ -106,68 +106,33 @@ public class AllocationAuto extends SvrProcess
|
||||||
if (countAlloc > 0)
|
if (countAlloc > 0)
|
||||||
countBP++;
|
countBP++;
|
||||||
}
|
}
|
||||||
else if (p_C_BP_Group_ID != 0)
|
|
||||||
{
|
|
||||||
String sql = "SELECT C_BPartner_ID FROM C_BPartner WHERE C_BP_Group_ID=? ORDER BY Value";
|
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
|
||||||
pstmt.setInt (1, p_C_BP_Group_ID);
|
|
||||||
rs = pstmt.executeQuery ();
|
|
||||||
while (rs.next ())
|
|
||||||
{
|
|
||||||
int C_BPartner_ID = rs.getInt(1);
|
|
||||||
int count = allocateBP (C_BPartner_ID);
|
|
||||||
if (count > 0)
|
|
||||||
{
|
|
||||||
countBP++;
|
|
||||||
countAlloc += count;
|
|
||||||
commitEx();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, sql, e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null; pstmt = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String sql = "SELECT C_BPartner_ID FROM C_BPartner WHERE AD_Client_ID=? ORDER BY Value";
|
String where;
|
||||||
PreparedStatement pstmt = null;
|
int parameter;
|
||||||
ResultSet rs = null;
|
if (p_C_BP_Group_ID != 0)
|
||||||
try
|
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
where = "C_BP_Group_ID=?";
|
||||||
pstmt.setInt (1, Env.getAD_Client_ID(getCtx()));
|
parameter = p_C_BP_Group_ID;
|
||||||
rs = pstmt.executeQuery ();
|
|
||||||
while (rs.next ())
|
|
||||||
{
|
|
||||||
int C_BPartner_ID = rs.getInt(1);
|
|
||||||
int count = allocateBP (C_BPartner_ID);
|
|
||||||
if (count > 0)
|
|
||||||
{
|
|
||||||
countBP++;
|
|
||||||
countAlloc += count;
|
|
||||||
commitEx();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, sql, e);
|
|
||||||
}
|
}
|
||||||
finally
|
else
|
||||||
{
|
{
|
||||||
DB.close(rs, pstmt);
|
where = "AD_Client_ID=?";
|
||||||
rs = null; pstmt = null;
|
parameter = Env.getAD_Client_ID(getCtx());
|
||||||
|
}
|
||||||
|
int[] ids = new Query(getCtx(), MBPartner.Table_Name, where, get_TrxName())
|
||||||
|
.setOrderBy("Value")
|
||||||
|
.setParameters(parameter)
|
||||||
|
.getIDs();
|
||||||
|
for (int C_BPartner_ID : ids)
|
||||||
|
{
|
||||||
|
int count = allocateBP (C_BPartner_ID);
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
countBP++;
|
||||||
|
countAlloc += count;
|
||||||
|
commitEx();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
@ -259,43 +224,27 @@ public class AllocationAuto extends SvrProcess
|
||||||
*/
|
*/
|
||||||
private MPayment[] getPayments (int C_BPartner_ID)
|
private MPayment[] getPayments (int C_BPartner_ID)
|
||||||
{
|
{
|
||||||
ArrayList<MPayment> list = new ArrayList<MPayment>();
|
StringBuilder where = new StringBuilder("IsAllocated='N' AND Processed='Y' AND C_BPartner_ID=?"
|
||||||
StringBuilder sql = new StringBuilder("SELECT * FROM C_Payment ")
|
+ " AND IsPrepayment='N' AND C_Charge_ID IS NULL ");
|
||||||
.append("WHERE IsAllocated='N' AND Processed='Y' AND C_BPartner_ID=?")
|
|
||||||
.append(" AND IsPrepayment='N' AND C_Charge_ID IS NULL ");
|
|
||||||
if (ONLY_AP.equals(p_APAR))
|
if (ONLY_AP.equals(p_APAR))
|
||||||
sql.append("AND IsReceipt='N' ");
|
where.append("AND IsReceipt='N'");
|
||||||
else if (ONLY_AR.equals(p_APAR))
|
else if (ONLY_AR.equals(p_APAR))
|
||||||
sql.append("AND IsReceipt='Y' ");
|
where.append("AND IsReceipt='Y'");
|
||||||
sql.append("ORDER BY DateTrx");
|
List<MPayment> queryList = new Query(getCtx(), MPayment.Table_Name, where.toString(), get_TrxName())
|
||||||
PreparedStatement pstmt = null;
|
.setOrderBy("DateTrx, Created, C_Payment_ID")
|
||||||
ResultSet rs = null;
|
.setParameters(C_BPartner_ID)
|
||||||
try
|
.list();
|
||||||
|
ArrayList<MPayment> list = new ArrayList<MPayment>();
|
||||||
|
for (MPayment payment : queryList)
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement (sql.toString(), get_TrxName());
|
BigDecimal allocated = payment.getAllocatedAmt();
|
||||||
pstmt.setInt (1, C_BPartner_ID);
|
if (allocated != null && allocated.compareTo(payment.getPayAmt()) == 0)
|
||||||
rs = pstmt.executeQuery ();
|
|
||||||
while (rs.next ())
|
|
||||||
{
|
{
|
||||||
MPayment payment = new MPayment (getCtx(), rs, get_TrxName());
|
payment.setIsAllocated(true);
|
||||||
BigDecimal allocated = payment.getAllocatedAmt();
|
payment.saveEx();
|
||||||
if (allocated != null && allocated.compareTo(payment.getPayAmt()) == 0)
|
|
||||||
{
|
|
||||||
payment.setIsAllocated(true);
|
|
||||||
payment.saveEx();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
list.add (payment);
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
catch (Exception e)
|
list.add (payment);
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, sql.toString(), e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null; pstmt = null;
|
|
||||||
}
|
}
|
||||||
m_payments = new MPayment[list.size ()];
|
m_payments = new MPayment[list.size ()];
|
||||||
list.toArray (m_payments);
|
list.toArray (m_payments);
|
||||||
|
@ -309,41 +258,25 @@ public class AllocationAuto extends SvrProcess
|
||||||
*/
|
*/
|
||||||
private MInvoice[] getInvoices (int C_BPartner_ID)
|
private MInvoice[] getInvoices (int C_BPartner_ID)
|
||||||
{
|
{
|
||||||
ArrayList<MInvoice> list = new ArrayList<MInvoice>();
|
StringBuilder where = new StringBuilder("IsPaid='N' AND Processed='Y' AND C_BPartner_ID=? ");
|
||||||
StringBuilder sql = new StringBuilder("SELECT * FROM C_Invoice ")
|
|
||||||
.append("WHERE IsPaid='N' AND Processed='Y' AND C_BPartner_ID=? ");
|
|
||||||
if (ONLY_AP.equals(p_APAR))
|
if (ONLY_AP.equals(p_APAR))
|
||||||
sql.append("AND IsSOTrx='N' ");
|
where.append("AND IsSOTrx='N' ");
|
||||||
else if (ONLY_AR.equals(p_APAR))
|
else if (ONLY_AR.equals(p_APAR))
|
||||||
sql.append("AND IsSOTrx='Y' ");
|
where.append("AND IsSOTrx='Y' ");
|
||||||
sql.append("ORDER BY DateInvoiced");
|
List<MInvoice> queryList = new Query(getCtx(), MInvoice.Table_Name, where.toString(), get_TrxName())
|
||||||
PreparedStatement pstmt = null;
|
.setOrderBy("DateInvoiced, Created, C_Invoice_ID")
|
||||||
ResultSet rs = null;
|
.setParameters(C_BPartner_ID)
|
||||||
try
|
.list();
|
||||||
|
ArrayList<MInvoice> list = new ArrayList<MInvoice>();
|
||||||
|
for (MInvoice invoice : queryList)
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement (sql.toString(), get_TrxName());
|
if (invoice.getOpenAmt(false, null).signum() == 0)
|
||||||
pstmt.setInt (1, C_BPartner_ID);
|
|
||||||
rs = pstmt.executeQuery ();
|
|
||||||
while (rs.next ())
|
|
||||||
{
|
{
|
||||||
MInvoice invoice = new MInvoice (getCtx(), rs, get_TrxName());
|
invoice.setIsPaid(true);
|
||||||
if (invoice.getOpenAmt(false, null).signum() == 0)
|
invoice.saveEx();
|
||||||
{
|
|
||||||
invoice.setIsPaid(true);
|
|
||||||
invoice.saveEx();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
list.add (invoice);
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
catch (Exception e)
|
list.add (invoice);
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, sql.toString(), e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null; pstmt = null;
|
|
||||||
}
|
}
|
||||||
m_invoices = new MInvoice[list.size ()];
|
m_invoices = new MInvoice[list.size ()];
|
||||||
list.toArray (m_invoices);
|
list.toArray (m_invoices);
|
||||||
|
|
Loading…
Reference in New Issue