lock Trx when you try created a Payment Allocation
http://sourceforge.net/tracker/?func=detail&aid=2792529&group_id=176962&atid=879332
This commit is contained in:
parent
d5e6e6a596
commit
177abceb8b
|
|
@ -47,6 +47,7 @@ import javax.swing.event.TableModelListener;
|
||||||
import javax.swing.table.DefaultTableModel;
|
import javax.swing.table.DefaultTableModel;
|
||||||
import javax.swing.table.TableModel;
|
import javax.swing.table.TableModel;
|
||||||
|
|
||||||
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
import org.adempiere.plaf.AdempierePLAF;
|
import org.adempiere.plaf.AdempierePLAF;
|
||||||
import org.compiere.apps.ADialog;
|
import org.compiere.apps.ADialog;
|
||||||
import org.compiere.apps.StatusBar;
|
import org.compiere.apps.StatusBar;
|
||||||
|
|
@ -72,12 +73,16 @@ import org.compiere.util.KeyNamePair;
|
||||||
import org.compiere.util.Msg;
|
import org.compiere.util.Msg;
|
||||||
import org.compiere.util.TimeUtil;
|
import org.compiere.util.TimeUtil;
|
||||||
import org.compiere.util.Trx;
|
import org.compiere.util.Trx;
|
||||||
|
import org.compiere.util.TrxRunnable;
|
||||||
import org.compiere.util.Util;
|
import org.compiere.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocation Form
|
* Allocation Form
|
||||||
*
|
*
|
||||||
* @author Jorg Janke
|
* @author Jorg Janke
|
||||||
|
* @author Victor Perez, e-Evolucion
|
||||||
|
* <li> [2792529] lockTrx when you try created a Payment Allocation
|
||||||
|
* <li> https://sourceforge.net/tracker/?func=detail&aid=2792529&group_id=176962&atid=879332
|
||||||
* @version $Id: VAllocation.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
|
* @version $Id: VAllocation.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
|
||||||
*
|
*
|
||||||
* Contributor : Fabian Aguilar - OFBConsulting - Multiallocation
|
* Contributor : Fabian Aguilar - OFBConsulting - Multiallocation
|
||||||
|
|
@ -934,6 +939,12 @@ public class VAllocation extends CPanel
|
||||||
if (m_noInvoices + m_noPayments == 0)
|
if (m_noInvoices + m_noPayments == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Trx.run(new TrxRunnable()
|
||||||
|
{
|
||||||
|
public void run(String trxName)
|
||||||
|
{
|
||||||
// fixed fields
|
// fixed fields
|
||||||
int AD_Client_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "AD_Client_ID");
|
int AD_Client_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "AD_Client_ID");
|
||||||
int AD_Org_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "AD_Org_ID");
|
int AD_Org_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "AD_Org_ID");
|
||||||
|
|
@ -945,15 +956,13 @@ public class VAllocation extends CPanel
|
||||||
//
|
//
|
||||||
if (AD_Org_ID == 0)
|
if (AD_Org_ID == 0)
|
||||||
{
|
{
|
||||||
ADialog.error(m_WindowNo, this, "Org0NotAllowed", null);
|
//ADialog.error(m_WindowNo, this, "Org0NotAllowed", null);
|
||||||
return;
|
new AdempiereException("@Org0NotAllowed@");
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
log.config("Client=" + AD_Client_ID + ", Org=" + AD_Org_ID
|
log.config("Client=" + AD_Client_ID + ", Org=" + AD_Org_ID
|
||||||
+ ", BPartner=" + C_BPartner_ID + ", Date=" + DateTrx);
|
+ ", BPartner=" + C_BPartner_ID + ", Date=" + DateTrx);
|
||||||
|
|
||||||
Trx trx = Trx.get(Trx.createTrxName("AL"), true);
|
|
||||||
|
|
||||||
// Payment - Loop and add them to paymentList/amountList
|
// Payment - Loop and add them to paymentList/amountList
|
||||||
int pRows = paymentTable.getRowCount();
|
int pRows = paymentTable.getRowCount();
|
||||||
TableModel payment = paymentTable.getModel();
|
TableModel payment = paymentTable.getModel();
|
||||||
|
|
@ -987,14 +996,9 @@ public class VAllocation extends CPanel
|
||||||
|
|
||||||
// Create Allocation
|
// Create Allocation
|
||||||
MAllocationHdr alloc = new MAllocationHdr (Env.getCtx(), true, // manual
|
MAllocationHdr alloc = new MAllocationHdr (Env.getCtx(), true, // manual
|
||||||
DateTrx, C_Currency_ID, Env.getContext(Env.getCtx(), "#AD_User_Name"), trx.getTrxName());
|
DateTrx, C_Currency_ID, Env.getContext(Env.getCtx(), "#AD_User_Name"), trxName);
|
||||||
alloc.setAD_Org_ID(AD_Org_ID);
|
alloc.setAD_Org_ID(AD_Org_ID);
|
||||||
if (!alloc.save())
|
alloc.saveEx();
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, "Allocation not created");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For all invoices
|
// For all invoices
|
||||||
int invoiceLines = 0;
|
int invoiceLines = 0;
|
||||||
BigDecimal unmatchedApplied = Env.ZERO;
|
BigDecimal unmatchedApplied = Env.ZERO;
|
||||||
|
|
@ -1035,8 +1039,7 @@ public class VAllocation extends CPanel
|
||||||
DiscountAmt, WriteOffAmt, OverUnderAmt);
|
DiscountAmt, WriteOffAmt, OverUnderAmt);
|
||||||
aLine.setDocInfo(C_BPartner_ID, C_Order_ID, C_Invoice_ID);
|
aLine.setDocInfo(C_BPartner_ID, C_Order_ID, C_Invoice_ID);
|
||||||
aLine.setPaymentInfo(C_Payment_ID, C_CashLine_ID);
|
aLine.setPaymentInfo(C_Payment_ID, C_CashLine_ID);
|
||||||
if (!aLine.save())
|
aLine.saveEx();
|
||||||
log.log(Level.SEVERE, "Allocation Line not written - Invoice=" + C_Invoice_ID);
|
|
||||||
|
|
||||||
// Apply Discounts and WriteOff only first time
|
// Apply Discounts and WriteOff only first time
|
||||||
DiscountAmt = Env.ZERO;
|
DiscountAmt = Env.ZERO;
|
||||||
|
|
@ -1059,9 +1062,7 @@ public class VAllocation extends CPanel
|
||||||
DiscountAmt, WriteOffAmt, OverUnderAmt);
|
DiscountAmt, WriteOffAmt, OverUnderAmt);
|
||||||
aLine.setDocInfo(C_BPartner_ID, C_Order_ID, C_Invoice_ID);
|
aLine.setDocInfo(C_BPartner_ID, C_Order_ID, C_Invoice_ID);
|
||||||
aLine.setPaymentInfo(C_Payment_ID, C_CashLine_ID);
|
aLine.setPaymentInfo(C_Payment_ID, C_CashLine_ID);
|
||||||
if (!aLine.save(trx.getTrxName()))
|
aLine.saveEx();
|
||||||
log.log(Level.SEVERE, "Allocation Line not written - Invoice=" + C_Invoice_ID);
|
|
||||||
|
|
||||||
log.fine("Allocation Amount=" + AppliedAmt);
|
log.fine("Allocation Amount=" + AppliedAmt);
|
||||||
unmatchedApplied = unmatchedApplied.add(AppliedAmt);
|
unmatchedApplied = unmatchedApplied.add(AppliedAmt);
|
||||||
}
|
}
|
||||||
|
|
@ -1082,8 +1083,7 @@ public class VAllocation extends CPanel
|
||||||
Env.ZERO, Env.ZERO, Env.ZERO);
|
Env.ZERO, Env.ZERO, Env.ZERO);
|
||||||
aLine.setDocInfo(C_BPartner_ID, 0, 0);
|
aLine.setDocInfo(C_BPartner_ID, 0, 0);
|
||||||
aLine.setPaymentInfo(C_Payment_ID, 0);
|
aLine.setPaymentInfo(C_Payment_ID, 0);
|
||||||
if (!aLine.save(trx.getTrxName()))
|
aLine.saveEx();
|
||||||
log.log(Level.SEVERE, "Allocation Line not saved - Payment=" + C_Payment_ID);
|
|
||||||
unmatchedApplied = unmatchedApplied.subtract(payAmt);
|
unmatchedApplied = unmatchedApplied.subtract(payAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1094,7 +1094,7 @@ public class VAllocation extends CPanel
|
||||||
if (alloc.get_ID() != 0)
|
if (alloc.get_ID() != 0)
|
||||||
{
|
{
|
||||||
alloc.processIt(DocAction.ACTION_Complete);
|
alloc.processIt(DocAction.ACTION_Complete);
|
||||||
alloc.save();
|
alloc.saveEx();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test/Set IsPaid for Invoice - requires that allocation is posted
|
// Test/Set IsPaid for Invoice - requires that allocation is posted
|
||||||
|
|
@ -1108,11 +1108,11 @@ public class VAllocation extends CPanel
|
||||||
int C_Invoice_ID = pp.getKey();
|
int C_Invoice_ID = pp.getKey();
|
||||||
String sql = "SELECT invoiceOpen(C_Invoice_ID, 0) "
|
String sql = "SELECT invoiceOpen(C_Invoice_ID, 0) "
|
||||||
+ "FROM C_Invoice WHERE C_Invoice_ID=?";
|
+ "FROM C_Invoice WHERE C_Invoice_ID=?";
|
||||||
BigDecimal open = DB.getSQLValueBD(trx.getTrxName(), sql, C_Invoice_ID);
|
BigDecimal open = DB.getSQLValueBD(trxName, sql, C_Invoice_ID);
|
||||||
if (open != null && open.signum() == 0) {
|
if (open != null && open.signum() == 0) {
|
||||||
sql = "UPDATE C_Invoice SET IsPaid='Y' "
|
sql = "UPDATE C_Invoice SET IsPaid='Y' "
|
||||||
+ "WHERE C_Invoice_ID=" + C_Invoice_ID;
|
+ "WHERE C_Invoice_ID=" + C_Invoice_ID;
|
||||||
int no = DB.executeUpdate(sql, trx.getTrxName());
|
int no = DB.executeUpdate(sql, trxName);
|
||||||
log.config("Invoice #" + i + " is paid - updated=" + no);
|
log.config("Invoice #" + i + " is paid - updated=" + no);
|
||||||
} else
|
} else
|
||||||
log.config("Invoice #" + i + " is not paid - " + open);
|
log.config("Invoice #" + i + " is not paid - " + open);
|
||||||
|
|
@ -1122,18 +1122,23 @@ public class VAllocation extends CPanel
|
||||||
for (int i = 0; i < paymentList.size(); i++)
|
for (int i = 0; i < paymentList.size(); i++)
|
||||||
{
|
{
|
||||||
int C_Payment_ID = ((Integer)paymentList.get(i)).intValue();
|
int C_Payment_ID = ((Integer)paymentList.get(i)).intValue();
|
||||||
MPayment pay = new MPayment (Env.getCtx(), C_Payment_ID, trx.getTrxName());
|
MPayment pay = new MPayment (Env.getCtx(), C_Payment_ID, trxName);
|
||||||
if (pay.testAllocation())
|
if (pay.testAllocation())
|
||||||
pay.save();
|
pay.saveEx();
|
||||||
log.config("Payment #" + i + (pay.isAllocated() ? " not" : " is")
|
log.config("Payment #" + i + (pay.isAllocated() ? " not" : " is")
|
||||||
+ " fully allocated");
|
+ " fully allocated");
|
||||||
}
|
}
|
||||||
paymentList.clear();
|
paymentList.clear();
|
||||||
amountList.clear();
|
amountList.clear();
|
||||||
trx.commit();
|
|
||||||
trx.close();
|
|
||||||
|
|
||||||
statusBar.setStatusLine(alloc.getDocumentNo());
|
statusBar.setStatusLine(alloc.getDocumentNo());
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
ADialog.error(m_WindowNo, this, "Error", e.getLocalizedMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
} // saveData
|
} // saveData
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue