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 InfoCashLine extends Info 43 { 44 53 protected InfoCashLine(Frame frame, boolean modal, int WindowNo, String value, 54 boolean multiSelection, String whereClause) 55 { 56 super (frame, modal, WindowNo, "cl", "C_CashLine_ID", multiSelection, whereClause); 57 Log.trace(Log.l1_User, "InfoCashLine"); 58 setTitle(Msg.getMsg(Env.getCtx(), "InfoCashLine")); 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 fName.setValue(value); 76 executeQuery(); 77 } 78 pack(); 80 fName.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 lName = new CLabel(Msg.translate(Env.getCtx(), "Name")); 95 private CTextField fName = new CTextField(10); 96 private CLabel lCashBook_ID = new CLabel(Msg.translate(Env.getCtx(), "C_CashBook_ID")); 97 private VLookup fCashBook_ID; 98 private CLabel lInvoice_ID = new CLabel(Msg.translate(Env.getCtx(), "C_Invoice_ID")); 101 private VLookup fInvoice_ID; 102 private CLabel lBankAccount_ID = new CLabel(Msg.translate(Env.getCtx(), "C_BankAccount_ID")); 105 private VLookup fBankAccount_ID; 106 private CCheckBox cbAbsolute = new CCheckBox (Msg.translate(Env.getCtx(), "AbsoluteAmt")); 107 private CLabel lDateFrom = new CLabel(Msg.translate(Env.getCtx(), "StatementDate")); 109 private VDate fDateFrom = new VDate("DateFrom", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateFrom")); 110 private CLabel lDateTo = new CLabel("-"); 111 private VDate fDateTo = new VDate("DateTo", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateTo")); 112 private CLabel lAmtFrom = new CLabel(Msg.translate(Env.getCtx(), "Amount")); 113 private VNumber fAmtFrom = new VNumber("AmtFrom", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtFrom")); 114 private CLabel lAmtTo = new CLabel("-"); 115 private VNumber fAmtTo = new VNumber("AmtTo", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtTo")); 116 117 118 private static final Info_Column[] s_cashLayout = { 119 new Info_Column(" ", "cl.C_CashLine_ID", IDColumn.class), 120 new Info_Column(Msg.translate(Env.getCtx(), "C_CashBook_ID"), 121 "(SELECT cb.Name FROM C_CashBook cb WHERE cb.C_CashBook_ID=c.C_CashBook_ID)", String .class), 122 new Info_Column(Msg.translate(Env.getCtx(), "Name"), 123 "c.Name", String .class), 124 new Info_Column(Msg.translate(Env.getCtx(), "StatementDate"), 125 "c.StatementDate", Timestamp.class), 126 new Info_Column(Msg.translate(Env.getCtx(), "Line"), 127 "cl.Line", Integer .class), 128 new Info_Column(Msg.translate(Env.getCtx(), "Amount"), 131 "cl.Amount", BigDecimal.class, true, true, null), 132 new Info_Column(Msg.translate(Env.getCtx(), "C_Invoice_ID"), 134 "(SELECT i.DocumentNo||'_'||" + DB.TO_CHAR("i.DateInvoiced",DisplayType.Date,Env.getAD_Language(Env.getCtx())) 135 + "||'_'||" + DB.TO_CHAR("i.GrandTotal",DisplayType.Amount,Env.getAD_Language(Env.getCtx())) 136 + " FROM C_Invoice i WHERE i.C_Invoice_ID=cl.C_Invoice_ID)", String .class), 137 new Info_Column(Msg.translate(Env.getCtx(), "C_BankAccount_ID"), 138 "(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=cl.C_BankAccount_ID)", String .class), 139 new Info_Column(Msg.translate(Env.getCtx(), "C_Charge_ID"), 140 "(SELECT ca.Name FROM C_Charge ca WHERE ca.C_Charge_ID=cl.C_Charge_ID)", String .class), 141 new Info_Column(Msg.translate(Env.getCtx(), "DiscountAmt"), 143 "cl.DiscountAmt", BigDecimal.class), 144 new Info_Column(Msg.translate(Env.getCtx(), "WriteOffAmt"), 145 "cl.WriteOffAmt", BigDecimal.class), 146 new Info_Column(Msg.translate(Env.getCtx(), "Description"), 147 "cl.Description", String .class) 148 }; 149 150 154 private void statInit() throws Exception 155 { 156 lName.setLabelFor(fName); 157 fName.setBackground(CompierePLAF.getInfoBackground()); 158 fName.addActionListener(this); 159 fCashBook_ID = new VLookup("C_CashBook_ID", false, false, true, 167 MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, 5249, DisplayType.TableDir), 168 DisplayType.TableDir, p_WindowNo); 169 lCashBook_ID.setLabelFor(fCashBook_ID); 170 fCashBook_ID.setBackground(CompierePLAF.getInfoBackground()); 171 fInvoice_ID = new VLookup("C_Invoice_ID", false, false, true, 173 MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, 5354, DisplayType.Search), 174 DisplayType.Search, p_WindowNo); 175 lInvoice_ID.setLabelFor(fInvoice_ID); 176 fInvoice_ID.setBackground(CompierePLAF.getInfoBackground()); 177 fBankAccount_ID = new VLookup("C_BankAccount_ID", false, false, true, 179 MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, 5295, DisplayType.TableDir), 180 DisplayType.TableDir, p_WindowNo); 181 lBankAccount_ID.setLabelFor(fBankAccount_ID); 182 fBankAccount_ID.setBackground(CompierePLAF.getInfoBackground()); 183 lDateFrom.setLabelFor(fDateFrom); 187 fDateFrom.setBackground(CompierePLAF.getInfoBackground()); 188 fDateFrom.setToolTipText(Msg.translate(Env.getCtx(), "DateFrom")); 189 lDateTo.setLabelFor(fDateTo); 190 fDateTo.setBackground(CompierePLAF.getInfoBackground()); 191 fDateTo.setToolTipText(Msg.translate(Env.getCtx(), "DateTo")); 192 lAmtFrom.setLabelFor(fAmtFrom); 193 fAmtFrom.setBackground(CompierePLAF.getInfoBackground()); 194 fAmtFrom.setToolTipText(Msg.translate(Env.getCtx(), "AmtFrom")); 195 lAmtTo.setLabelFor(fAmtTo); 196 fAmtTo.setBackground(CompierePLAF.getInfoBackground()); 197 fAmtTo.setToolTipText(Msg.translate(Env.getCtx(), "AmtTo")); 198 parameterPanel.setLayout(new ALayout()); 200 parameterPanel.add(lCashBook_ID, new ALayoutConstraint(0,0)); 202 parameterPanel.add(fCashBook_ID, null); 203 parameterPanel.add(lName, null); 204 parameterPanel.add(fName, null); 205 parameterPanel.add(cbAbsolute, new ALayoutConstraint(0,5)); 206 parameterPanel.add(lInvoice_ID, new ALayoutConstraint(1,0)); 208 parameterPanel.add(fInvoice_ID, null); 209 parameterPanel.add(lDateFrom, null); 210 parameterPanel.add(fDateFrom, null); 211 parameterPanel.add(lDateTo, null); 212 parameterPanel.add(fDateTo, null); 213 parameterPanel.add(lBankAccount_ID, new ALayoutConstraint(2,0)); 215 parameterPanel.add(fBankAccount_ID, null); 216 parameterPanel.add(lAmtFrom, null); 217 parameterPanel.add(fAmtFrom, null); 218 parameterPanel.add(lAmtTo, null); 219 parameterPanel.add(fAmtTo, null); 220 } 224 228 private boolean initInfo () 229 { 230 StringBuffer where = new StringBuffer ("cl.C_Cash_ID=c.C_Cash_ID"); 232 if (p_whereClause.length() > 0) 234 where.append(" AND ").append(Util.replace(p_whereClause, "C_CashLine.", "cl.")); 235 prepareTable (s_cashLayout, 236 "C_Cash c, C_CashLine cl", 237 where.toString(), 238 "2,3,cl.Line"); 239 240 return true; 241 } 243 244 245 251 String getSQLWhere() 252 { 253 StringBuffer sql = new StringBuffer (); 254 if (fName.getText().length() > 0) 255 sql.append(" AND UPPER(c.Name) LIKE ?"); 256 if (fCashBook_ID.getValue() != null) 258 sql.append(" AND c.C_CashBook_ID=?"); 259 if (fInvoice_ID.getValue() != null) 261 sql.append(" AND cl.C_Invoice_ID=?"); 262 if (fDateFrom.getValue() != null || fDateTo.getValue() != null) 264 { 265 Timestamp from = (Timestamp)fDateFrom.getValue(); 266 Timestamp to = (Timestamp)fDateTo.getValue(); 267 if (from == null && to != null) 268 sql.append(" AND TRUNC(c.StatementDate) <= ?"); 269 else if (from != null && to == null) 270 sql.append(" AND TRUNC(c.StatementDate) >= ?"); 271 else if (from != null && to != null) 272 sql.append(" AND TRUNC(c.StatementDate) BETWEEN ? AND ?"); 273 } 274 if (fAmtFrom.getValue() != null || fAmtTo.getValue() != null) 276 { 277 BigDecimal from = (BigDecimal)fAmtFrom.getValue(); 278 BigDecimal to = (BigDecimal)fAmtTo.getValue(); 279 if (cbAbsolute.isSelected()) 280 sql.append(" AND ABS(cl.Amount)"); 281 else 282 sql.append(" AND cl.Amount"); 283 if (from == null && to != null) 285 sql.append(" <=?"); 286 else if (from != null && to == null) 287 sql.append(" >=?"); 288 else if (from != null && to != null) 289 { 290 if (from.compareTo(to) == 0) 291 sql.append(" =?"); 292 else 293 sql.append(" BETWEEN ? AND ?"); 294 } 295 } 296 297 Log.trace(Log.l6_Database, "InfoCashLine.getWhereClause", sql.toString()); 298 return sql.toString(); 299 } 301 307 void setParameters(PreparedStatement pstmt) throws SQLException 308 { 309 int index = 1; 310 if (fName.getText().length() > 0) 311 pstmt.setString(index++, getSQLText(fName)); 312 if (fCashBook_ID.getValue() != null) 314 { 315 Integer cb = (Integer )fCashBook_ID.getValue(); 316 pstmt.setInt(index++, cb.intValue()); 317 Log.trace(Log.l5_DData, "CashBook=" + cb); 318 } 319 if (fInvoice_ID.getValue() != null) 321 { 322 Integer i = (Integer )fInvoice_ID.getValue(); 323 pstmt.setInt(index++, i.intValue()); 324 Log.trace(Log.l5_DData, "Invoice=" + i); 325 } 326 if (fDateFrom.getValue() != null || fDateTo.getValue() != null) 328 { 329 Timestamp from = (Timestamp)fDateFrom.getValue(); 330 Timestamp to = (Timestamp)fDateTo.getValue(); 331 Log.trace(Log.l5_DData, "Date From=" + from + ", To=" + to); 332 if (from == null && to != null) 333 pstmt.setTimestamp(index++, to); 334 else if (from != null && to == null) 335 pstmt.setTimestamp(index++, from); 336 else if (from != null && to != null) 337 { 338 pstmt.setTimestamp(index++, from); 339 pstmt.setTimestamp(index++, to); 340 } 341 } 342 if (fAmtFrom.getValue() != null || fAmtTo.getValue() != null) 344 { 345 BigDecimal from = (BigDecimal)fAmtFrom.getValue(); 346 BigDecimal to = (BigDecimal)fAmtTo.getValue(); 347 if (cbAbsolute.isSelected()) 348 { 349 if (from != null) 350 from = from.abs(); 351 if (to != null) 352 to = to.abs(); 353 } 354 Log.trace(Log.l5_DData, "Amt From=" + from + ", To=" + to + ", Absolute=" + cbAbsolute.isSelected()); 355 if (from == null && to != null) 356 pstmt.setBigDecimal(index++, to); 357 else if (from != null && to == null) 358 pstmt.setBigDecimal(index++, from); 359 else if (from != null && to != null) 360 { 361 if (from.compareTo(to) == 0) 362 pstmt.setBigDecimal(index++, from); 363 else 364 { 365 pstmt.setBigDecimal(index++, to); 366 pstmt.setBigDecimal(index++, from); 367 } 368 } 369 } 370 } 372 377 private String getSQLText (CTextField f) 378 { 379 String s = f.getText().toUpperCase(); 380 if (!s.endsWith("%")) 381 s += "%"; 382 Log.trace(Log.l5_DData, "String=" + s); 383 return s; 384 } } | Popular Tags |