1 14 package org.compiere.apps.search; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 19 import javax.swing.*; 20 import javax.swing.event.*; 21 import javax.swing.table.*; 22 23 import java.sql.*; 24 import java.text.*; 25 import java.util.*; 26 import java.math.*; 27 28 import org.compiere.apps.*; 29 import org.compiere.grid.ed.*; 30 import org.compiere.minigrid.*; 31 import org.compiere.util.*; 32 import org.compiere.model.*; 33 import org.compiere.plaf.*; 34 import org.compiere.swing.*; 35 36 42 public class InfoPayment extends Info 43 { 44 53 protected InfoPayment(Frame frame, boolean modal, int WindowNo, String value, 54 boolean multiSelection, String whereClause) 55 { 56 super (frame, modal, WindowNo, "p", "C_Payment_ID", multiSelection, whereClause); 57 Log.trace(Log.l1_User, "InfoPayment"); 58 setTitle(Msg.getMsg(Env.getCtx(), "InfoPayment")); 59 try 61 { 62 statInit(); 63 p_loadedOK = initInfo (); 64 } 65 catch (Exception e) 66 { 67 return; 68 } 69 int no = p_table.getRowCount(); 71 setStatusLine(Integer.toString(no) + " " + Msg.getMsg(Env.getCtx(), "SearchRows_EnterQuery"), false); 72 setStatusDB(Integer.toString(no)); 73 if (value != null && value.length() > 0) 74 { 75 fDocumentNo.setValue(value); 76 executeQuery(); 77 } 78 pack(); 80 fDocumentNo.requestFocus(); 82 } 84 85 private Info_Column[] m_generalLayout; 86 87 private ArrayList m_queryColumns = new ArrayList(); 88 89 private String m_tableName; 90 91 private String m_keyColumn; 92 93 private CLabel lDocumentNo = new CLabel(Msg.translate(Env.getCtx(), "DocumentNo")); 95 private CTextField fDocumentNo = new CTextField(10); 96 private CLabel lBPartner_ID = new CLabel(Msg.translate(Env.getCtx(), "C_BPartner_ID")); 100 private VLookup fBPartner_ID; 101 private CLabel lDateFrom = new CLabel(Msg.translate(Env.getCtx(), "DateTrx")); 103 private VDate fDateFrom = new VDate("DateFrom", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateFrom")); 104 private CLabel lDateTo = new CLabel("-"); 105 private VDate fDateTo = new VDate("DateTo", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateTo")); 106 private CLabel lAmtFrom = new CLabel(Msg.translate(Env.getCtx(), "PayAmt")); 107 private VNumber fAmtFrom = new VNumber("AmtFrom", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtFrom")); 108 private CLabel lAmtTo = new CLabel("-"); 109 private VNumber fAmtTo = new VNumber("AmtTo", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtTo")); 110 private VCheckBox fIsReceipt = new VCheckBox ("IsReceipt", false, false, true, Msg.translate(Env.getCtx(), "IsReceipt"), "", false); 111 112 113 private static final Info_Column[] s_paymentLayout = { 114 new Info_Column(" ", "p.C_Payment_ID", IDColumn.class), 115 new Info_Column(Msg.translate(Env.getCtx(), "C_BankAccount_ID"), 116 "(SELECT b.Name || ' ' || ba.AccountNo FROM C_Bank b, C_BankAccount ba WHERE b.C_Bank_ID=ba.C_Bank_ID AND ba.C_BankAccount_ID=p.C_BankAccount_ID)", String .class), 117 new Info_Column(Msg.translate(Env.getCtx(), "C_BPartner_ID"), 118 "(SELECT Name FROM C_BPartner bp WHERE bp.C_BPartner_ID=p.C_BPartner_ID)", String .class), 119 new Info_Column(Msg.translate(Env.getCtx(), "DateTrx"), 120 "p.DateTrx", Timestamp.class), 121 new Info_Column(Msg.translate(Env.getCtx(), "DocumentNo"), 122 "p.DocumentNo", String .class), 123 new Info_Column(Msg.translate(Env.getCtx(), "IsReceipt"), 124 "p.IsReceipt", Boolean .class), 125 new Info_Column(Msg.translate(Env.getCtx(), "C_Currency_ID"), 126 "(SELECT ISO_Code FROM C_Currency c WHERE c.C_Currency_ID=p.C_Currency_ID)", String .class), 127 new Info_Column(Msg.translate(Env.getCtx(), "PayAmt"), 128 "p.PayAmt", BigDecimal.class), 129 new Info_Column(Msg.translate(Env.getCtx(), "ConvertedAmount"), 130 "C_Base_Convert(p.PayAmt,p.C_Currency_ID,p.AD_Client_ID,p.DateTrx,p.AD_Org_ID)", BigDecimal.class), 131 new Info_Column(Msg.translate(Env.getCtx(), "DiscountAmt"), 132 "p.DiscountAmt", BigDecimal.class), 133 new Info_Column(Msg.translate(Env.getCtx(), "WriteOffAmt"), 134 "p.WriteOffAmt", BigDecimal.class) 135 }; 136 137 141 private void statInit() throws Exception  142 { 143 lDocumentNo.setLabelFor(fDocumentNo); 144 fDocumentNo.setBackground(CompierePLAF.getInfoBackground()); 145 fDocumentNo.addActionListener(this); 146 fIsReceipt.setSelected(!"N".equals(Env.getContext(Env.getCtx(), p_WindowNo, "IsSOTrx"))); 147 fIsReceipt.addActionListener(this); 148 fBPartner_ID = new VLookup("C_BPartner_ID", false, false, true, 155 MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, 3499, DisplayType.Search), 156 DisplayType.Search, p_WindowNo); 157 lBPartner_ID.setLabelFor(fBPartner_ID); 158 fBPartner_ID.setBackground(CompierePLAF.getInfoBackground()); 159 lDateFrom.setLabelFor(fDateFrom); 161 fDateFrom.setBackground(CompierePLAF.getInfoBackground()); 162 fDateFrom.setToolTipText(Msg.translate(Env.getCtx(), "DateFrom")); 163 lDateTo.setLabelFor(fDateTo); 164 fDateTo.setBackground(CompierePLAF.getInfoBackground()); 165 fDateTo.setToolTipText(Msg.translate(Env.getCtx(), "DateTo")); 166 lAmtFrom.setLabelFor(fAmtFrom); 167 fAmtFrom.setBackground(CompierePLAF.getInfoBackground()); 168 fAmtFrom.setToolTipText(Msg.translate(Env.getCtx(), "AmtFrom")); 169 lAmtTo.setLabelFor(fAmtTo); 170 fAmtTo.setBackground(CompierePLAF.getInfoBackground()); 171 fAmtTo.setToolTipText(Msg.translate(Env.getCtx(), "AmtTo")); 172 parameterPanel.setLayout(new ALayout()); 174 parameterPanel.add(lDocumentNo, new ALayoutConstraint(0,0)); 176 parameterPanel.add(fDocumentNo, null); 177 parameterPanel.add(lBPartner_ID, null); 178 parameterPanel.add(fBPartner_ID, null); 179 parameterPanel.add(fIsReceipt, new ALayoutConstraint(0,5)); 180 parameterPanel.add(lDateFrom, new ALayoutConstraint(1,2)); 182 parameterPanel.add(fDateFrom, null); 183 parameterPanel.add(lDateTo, null); 184 parameterPanel.add(fDateTo, null); 185 parameterPanel.add(lAmtFrom, new ALayoutConstraint(2,2)); 187 parameterPanel.add(fAmtFrom, null); 188 parameterPanel.add(lAmtTo, null); 189 parameterPanel.add(fAmtTo, null); 190 } 194 198 private boolean initInfo () 199 { 200 String bp = Env.getContext(Env.getCtx(), p_WindowNo, "C_BPartner_ID"); 202 if (bp != null && bp.length() != 0) 203 fBPartner_ID.setValue(new Integer (bp)); 204 205 StringBuffer where = new StringBuffer ("p.IsActive='Y'"); 207 if (p_whereClause.length() > 0) 208 where.append(" AND ").append(Util.replace(p_whereClause, "C_Payment.", "p.")); 209 prepareTable(s_paymentLayout, 210 " C_Payment_v p", 211 where.toString(), 212 "2,3,4"); 213 214 return true; 215 } 217 218 219 225 String getSQLWhere() 226 { 227 StringBuffer sql = new StringBuffer (); 228 if (fDocumentNo.getText().length() > 0) 229 sql.append(" AND UPPER(p.DocumentNo) LIKE ?"); 230 if (fBPartner_ID.getValue() != null) 232 sql.append(" AND p.C_BPartner_ID=?"); 233 if (fDateFrom.getValue() != null || fDateTo.getValue() != null) 235 { 236 Timestamp from = (Timestamp)fDateFrom.getValue(); 237 Timestamp to = (Timestamp)fDateTo.getValue(); 238 if (from == null && to != null) 239 sql.append(" AND TRUNC(p.DateTrx) <= ?"); 240 else if (from != null && to == null) 241 sql.append(" AND TRUNC(p.DateTrx) >= ?"); 242 else if (from != null && to != null) 243 sql.append(" AND TRUNC(p.DateTrx) BETWEEN ? AND ?"); 244 } 245 if (fAmtFrom.getValue() != null || fAmtTo.getValue() != null) 247 { 248 BigDecimal from = (BigDecimal)fAmtFrom.getValue(); 249 BigDecimal to = (BigDecimal)fAmtTo.getValue(); 250 if (from == null && to != null) 251 sql.append(" AND p.PayAmt <= ?"); 252 else if (from != null && to == null) 253 sql.append(" AND p.PayAmt >= ?"); 254 else if (from != null && to != null) 255 sql.append(" AND p.PayAmt BETWEEN ? AND ?"); 256 } 257 sql.append(" AND p.IsReceipt=?"); 258 259 Log.trace(Log.l6_Database, "InfoPayment.getWhereClause", sql.toString()); 260 return sql.toString(); 261 } 263 269 void setParameters(PreparedStatement pstmt) throws SQLException 270 { 271 int index = 1; 272 if (fDocumentNo.getText().length() > 0) 273 pstmt.setString(index++, getSQLText(fDocumentNo)); 274 if (fBPartner_ID.getValue() != null) 276 { 277 Integer bp = (Integer )fBPartner_ID.getValue(); 278 pstmt.setInt(index++, bp.intValue()); 279 Log.trace(Log.l5_DData, "BPartner=" + bp); 280 } 281 if (fDateFrom.getValue() != null || fDateTo.getValue() != null) 283 { 284 Timestamp from = (Timestamp)fDateFrom.getValue(); 285 Timestamp to = (Timestamp)fDateTo.getValue(); 286 Log.trace(Log.l5_DData, "Date From=" + from + ", To=" + to); 287 if (from == null && to != null) 288 pstmt.setTimestamp(index++, to); 289 else if (from != null && to == null) 290 pstmt.setTimestamp(index++, from); 291 else if (from != null && to != null) 292 { 293 pstmt.setTimestamp(index++, from); 294 pstmt.setTimestamp(index++, to); 295 } 296 } 297 if (fAmtFrom.getValue() != null || fAmtTo.getValue() != null) 299 { 300 BigDecimal from = (BigDecimal)fAmtFrom.getValue(); 301 BigDecimal to = (BigDecimal)fAmtTo.getValue(); 302 Log.trace(Log.l5_DData, "Amt From=" + from + ", To=" + to); 303 if (from == null && to != null) 304 pstmt.setBigDecimal(index++, to); 305 else if (from != null && to == null) 306 pstmt.setBigDecimal(index++, from); 307 else if (from != null && to != null) 308 { 309 pstmt.setBigDecimal(index++, from); 310 pstmt.setBigDecimal(index++, to); 311 } 312 } 313 pstmt.setString(index++, fIsReceipt.isSelected() ? "Y" : "N"); 314 } 316 321 private String getSQLText (CTextField f) 322 { 323 String s = f.getText().toUpperCase(); 324 if (!s.endsWith("%")) 325 s += "%"; 326 Log.trace(Log.l5_DData, "String=" + s); 327 return s; 328 } } | Popular Tags |