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:
vpj-cd 2009-05-16 00:58:54 +00:00
parent d5e6e6a596
commit 177abceb8b
1 changed files with 199 additions and 194 deletions

View File

@ -47,6 +47,7 @@ import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.plaf.AdempierePLAF;
import org.compiere.apps.ADialog;
import org.compiere.apps.StatusBar;
@ -72,12 +73,16 @@ import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.compiere.util.TimeUtil;
import org.compiere.util.Trx;
import org.compiere.util.TrxRunnable;
import org.compiere.util.Util;
/**
* Allocation Form
*
* @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 $
*
* Contributor : Fabian Aguilar - OFBConsulting - Multiallocation
@ -934,6 +939,12 @@ public class VAllocation extends CPanel
if (m_noInvoices + m_noPayments == 0)
return;
try
{
Trx.run(new TrxRunnable()
{
public void run(String trxName)
{
// fixed fields
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");
@ -945,15 +956,13 @@ public class VAllocation extends CPanel
//
if (AD_Org_ID == 0)
{
ADialog.error(m_WindowNo, this, "Org0NotAllowed", null);
return;
//ADialog.error(m_WindowNo, this, "Org0NotAllowed", null);
new AdempiereException("@Org0NotAllowed@");
}
//
log.config("Client=" + AD_Client_ID + ", Org=" + AD_Org_ID
+ ", BPartner=" + C_BPartner_ID + ", Date=" + DateTrx);
Trx trx = Trx.get(Trx.createTrxName("AL"), true);
// Payment - Loop and add them to paymentList/amountList
int pRows = paymentTable.getRowCount();
TableModel payment = paymentTable.getModel();
@ -987,14 +996,9 @@ public class VAllocation extends CPanel
// Create Allocation
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);
if (!alloc.save())
{
log.log(Level.SEVERE, "Allocation not created");
return;
}
alloc.saveEx();
// For all invoices
int invoiceLines = 0;
BigDecimal unmatchedApplied = Env.ZERO;
@ -1035,8 +1039,7 @@ public class VAllocation extends CPanel
DiscountAmt, WriteOffAmt, OverUnderAmt);
aLine.setDocInfo(C_BPartner_ID, C_Order_ID, C_Invoice_ID);
aLine.setPaymentInfo(C_Payment_ID, C_CashLine_ID);
if (!aLine.save())
log.log(Level.SEVERE, "Allocation Line not written - Invoice=" + C_Invoice_ID);
aLine.saveEx();
// Apply Discounts and WriteOff only first time
DiscountAmt = Env.ZERO;
@ -1059,9 +1062,7 @@ public class VAllocation extends CPanel
DiscountAmt, WriteOffAmt, OverUnderAmt);
aLine.setDocInfo(C_BPartner_ID, C_Order_ID, C_Invoice_ID);
aLine.setPaymentInfo(C_Payment_ID, C_CashLine_ID);
if (!aLine.save(trx.getTrxName()))
log.log(Level.SEVERE, "Allocation Line not written - Invoice=" + C_Invoice_ID);
aLine.saveEx();
log.fine("Allocation Amount=" + AppliedAmt);
unmatchedApplied = unmatchedApplied.add(AppliedAmt);
}
@ -1082,8 +1083,7 @@ public class VAllocation extends CPanel
Env.ZERO, Env.ZERO, Env.ZERO);
aLine.setDocInfo(C_BPartner_ID, 0, 0);
aLine.setPaymentInfo(C_Payment_ID, 0);
if (!aLine.save(trx.getTrxName()))
log.log(Level.SEVERE, "Allocation Line not saved - Payment=" + C_Payment_ID);
aLine.saveEx();
unmatchedApplied = unmatchedApplied.subtract(payAmt);
}
@ -1094,7 +1094,7 @@ public class VAllocation extends CPanel
if (alloc.get_ID() != 0)
{
alloc.processIt(DocAction.ACTION_Complete);
alloc.save();
alloc.saveEx();
}
// 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();
String sql = "SELECT invoiceOpen(C_Invoice_ID, 0) "
+ "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) {
sql = "UPDATE C_Invoice SET IsPaid='Y' "
+ "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);
} else
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++)
{
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())
pay.save();
pay.saveEx();
log.config("Payment #" + i + (pay.isAllocated() ? " not" : " is")
+ " fully allocated");
}
paymentList.clear();
amountList.clear();
trx.commit();
trx.close();
statusBar.setStatusLine(alloc.getDocumentNo());
}});
}
catch (Exception e)
{
ADialog.error(m_WindowNo, this, "Error", e.getLocalizedMessage());
return;
}
} // saveData