diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/form/VAllocation.java b/org.adempiere.ui.swing/src/org/compiere/apps/form/VAllocation.java index d712224ed4..64259f6305 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/form/VAllocation.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/form/VAllocation.java @@ -361,20 +361,14 @@ public class VAllocation extends Allocation // Organization if (name.equals("AD_Org_ID")) { - if (value == null) - m_AD_Org_ID = 0; - else - m_AD_Org_ID = ((Integer) value).intValue(); + m_AD_Org_ID = ((Integer) value).intValue(); loadBPartner(); } // Charge else if (name.equals("C_Charge_ID") ) { - if ( value == null ) - m_C_Charge_ID = 0; - else - m_C_Charge_ID = ((Integer) value).intValue(); + m_C_Charge_ID = ((Integer) value).intValue(); setAllocateButton(); } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WAllocation.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WAllocation.java index c34f8ee0df..5dddbf4193 100755 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WAllocation.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WAllocation.java @@ -16,6 +16,10 @@ *****************************************************************************/ package org.adempiere.webui.apps.form; +import static org.compiere.model.SystemIDs.COLUMN_C_INVOICE_C_BPARTNER_ID; +import static org.compiere.model.SystemIDs.COLUMN_C_INVOICE_C_CURRENCY_ID; +import static org.compiere.model.SystemIDs.COLUMN_C_PERIOD_AD_ORG_ID; + import java.math.BigDecimal; import java.util.Vector; import java.util.logging.Level; @@ -47,18 +51,18 @@ import org.adempiere.webui.window.FDialog; import org.compiere.apps.form.Allocation; import org.compiere.model.MLookup; import org.compiere.model.MLookupFactory; -import static org.compiere.model.SystemIDs.*; import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.Msg; import org.compiere.util.Trx; +import org.compiere.util.TrxRunnable; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zul.Borderlayout; import org.zkoss.zul.Center; import org.zkoss.zul.North; -import org.zkoss.zul.South; import org.zkoss.zul.Separator; +import org.zkoss.zul.South; import org.zkoss.zul.Space; /** @@ -409,20 +413,14 @@ public class WAllocation extends Allocation // Organization if (name.equals("AD_Org_ID")) { - if (value == null) - m_AD_Org_ID = 0; - else - m_AD_Org_ID = ((Integer) value).intValue(); + m_AD_Org_ID = ((Integer) value).intValue(); loadBPartner(); } // Charge else if (name.equals("C_Charge_ID") ) { - if ( value == null ) - m_C_Charge_ID = 0; - else - m_C_Charge_ID = ((Integer) value).intValue(); + m_C_Charge_ID = ((Integer) value).intValue(); setAllocateButton(); } @@ -535,10 +533,21 @@ public class WAllocation extends Allocation Env.setContext(Env.getCtx(), form.getWindowNo(), "AD_Org_ID", m_AD_Org_ID); else Env.setContext(Env.getCtx(), form.getWindowNo(), "AD_Org_ID", ""); - Trx trx = Trx.get(Trx.createTrxName("AL"), true); - statusBar.setStatusLine(saveData(form.getWindowNo(), dateField.getValue(), paymentTable, invoiceTable, trx.getTrxName())); - trx.commit(); - trx.close(); + try + { + Trx.run(new TrxRunnable() + { + public void run(String trxName) + { + statusBar.setStatusLine(saveData(form.getWindowNo(), dateField.getValue(), paymentTable, invoiceTable, trxName)); + } + }); + } + catch (Exception e) + { + FDialog.error(form.getWindowNo(), form, "Error", e.getLocalizedMessage()); + return; + } } // saveData /** diff --git a/org.adempiere.ui/src/org/compiere/apps/form/Allocation.java b/org.adempiere.ui/src/org/compiere/apps/form/Allocation.java index 8c71261749..665a761f9d 100644 --- a/org.adempiere.ui/src/org/compiere/apps/form/Allocation.java +++ b/org.adempiere.ui/src/org/compiere/apps/form/Allocation.java @@ -138,9 +138,11 @@ public class Allocation sql = new StringBuilder( MRole.getDefault(Env.getCtx(), false).addAccessSQL( sql.toString(), "p", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO ) ); log.fine("PaySQL=" + sql.toString()); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), null); pstmt.setInt(1, m_C_Currency_ID); pstmt.setTimestamp(2, (Timestamp)date); pstmt.setInt(3, m_C_Currency_ID); @@ -148,7 +150,7 @@ public class Allocation pstmt.setInt(5, m_C_BPartner_ID); if (!isMultiCurrency) pstmt.setInt(6, m_C_Currency_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { Vector line = new Vector(); @@ -171,13 +173,15 @@ public class Allocation // data.add(line); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); } + finally + { + DB.close(rs, pstmt); + } return data; } @@ -266,9 +270,11 @@ public class Allocation // role security sql = new StringBuilder( MRole.getDefault(Env.getCtx(), false).addAccessSQL( sql.toString(), "i", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO ) ); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), null); pstmt.setInt(1, m_C_Currency_ID); pstmt.setTimestamp(2, (Timestamp)date); pstmt.setInt(3, m_C_Currency_ID); @@ -278,7 +284,7 @@ public class Allocation pstmt.setInt(7, m_C_BPartner_ID); if (!isMultiCurrency) pstmt.setInt(8, m_C_Currency_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { Vector line = new Vector(); @@ -309,13 +315,15 @@ public class Allocation if (Env.ZERO.compareTo(open) != 0) data.add(line); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); } + finally + { + DB.close(rs, pstmt); + } return data; } @@ -441,6 +449,7 @@ public class Allocation applied = applied.subtract(discount); writeOff = Env.ZERO; // to be sure overUnder = Env.ZERO; + totalDiff = Env.ZERO; if (totalDiff.abs().compareTo(applied.abs()) < 0 // where less is available to allocate than open && totalDiff.signum() == applied.signum() ) // and the available amount has the same sign @@ -737,11 +746,12 @@ public class Allocation // Allocation Line MAllocationLine aLine = new MAllocationLine (alloc, chargeAmt.negate(), Env.ZERO, Env.ZERO, Env.ZERO); - aLine.set_CustomColumn("C_Charge_ID", m_C_Charge_ID); - //aLine.set_CustomColumn("ChargeAmt", chargeAmt); + aLine.setC_Charge_ID(m_C_Charge_ID); aLine.setC_BPartner_ID(m_C_BPartner_ID); - if (!aLine.save(trxName)) - log.log(Level.SEVERE, "Allocation Line not saved - Charge=" + m_C_Charge_ID); + if (!aLine.save(trxName)) { + StringBuilder msg = new StringBuilder("Allocation Line not saved - Charge=").append(m_C_Charge_ID); + throw new AdempiereException(msg.toString()); + } unmatchedApplied = unmatchedApplied.add(chargeAmt); }