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 37 43 public class InfoInOut extends Info 44 { 45 54 protected InfoInOut(Frame frame, boolean modal, int WindowNo, String value, 55 boolean multiSelection, String whereClause) 56 { 57 super (frame, modal, WindowNo, "i", "M_InOut_ID", multiSelection, whereClause); 58 Log.trace(Log.l1_User, "InfoInOut"); 59 setTitle(Msg.getMsg(Env.getCtx(), "InfoInOut")); 60 try 62 { 63 statInit(); 64 p_loadedOK = initInfo (); 65 } 66 catch (Exception e) 67 { 68 return; 69 } 70 int no = p_table.getRowCount(); 72 setStatusLine(Integer.toString(no) + " " + Msg.getMsg(Env.getCtx(), "SearchRows_EnterQuery"), false); 73 setStatusDB(Integer.toString(no)); 74 if (value != null && value.length() > 0) 75 { 76 fDocumentNo.setValue(value); 77 executeQuery(); 78 } 79 pack(); 81 fDocumentNo.requestFocus(); 83 } 85 86 private Info_Column[] m_generalLayout; 87 88 private ArrayList m_queryColumns = new ArrayList(); 89 90 private String m_tableName; 91 92 private String m_keyColumn; 93 94 private CLabel lDocumentNo = new CLabel(Msg.translate(Env.getCtx(), "DocumentNo")); 96 private CTextField fDocumentNo = new CTextField(10); 97 private CLabel lDescription = new CLabel(Msg.translate(Env.getCtx(), "Description")); 98 private CTextField fDescription = new CTextField(10); 99 private CLabel lPOReference = new CLabel(Msg.translate(Env.getCtx(), "POReference")); 100 private CTextField fPOReference = new CTextField(10); 101 private CLabel lBPartner_ID = new CLabel(Msg.translate(Env.getCtx(), "C_BPartner_ID")); 105 private VLookup fBPartner_ID; 106 private CLabel lDateFrom = new CLabel(Msg.translate(Env.getCtx(), "MovementDate")); 108 private VDate fDateFrom = new VDate("DateFrom", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateFrom")); 109 private CLabel lDateTo = new CLabel("-"); 110 private VDate fDateTo = new VDate("DateTo", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateTo")); 111 private VCheckBox fIsSOTrx = new VCheckBox ("IsSOTrx", false, false, true, Msg.translate(Env.getCtx(), "IsSOTrx"), "", false); 112 113 114 private static final Info_Column[] s_invoiceLayout = { 115 new Info_Column(" ", "i.M_InOut_ID", IDColumn.class), 116 new Info_Column(Msg.translate(Env.getCtx(), "C_BPartner_ID"), "(SELECT Name FROM C_BPartner bp WHERE bp.C_BPartner_ID=i.C_BPartner_ID)", String .class), 117 new Info_Column(Msg.translate(Env.getCtx(), "MovementDate"), "i.MovementDate", Timestamp.class), 118 new Info_Column(Msg.translate(Env.getCtx(), "DocumentNo"), "i.DocumentNo", String .class), 119 new Info_Column(Msg.translate(Env.getCtx(), "Description"), "i.Description", String .class), 120 new Info_Column(Msg.translate(Env.getCtx(), "POReference"), "i.POReference", String .class), 121 new Info_Column(Msg.translate(Env.getCtx(), "IsSOTrx"), "i.IsSOTrx", Boolean .class) 122 }; 123 124 128 private void statInit() throws Exception 129 { 130 lDocumentNo.setLabelFor(fDocumentNo); 131 fDocumentNo.setBackground(CompierePLAF.getInfoBackground()); 132 fDocumentNo.addActionListener(this); 133 lDescription.setLabelFor(fDescription); 134 fDescription.setBackground(CompierePLAF.getInfoBackground()); 135 fDescription.addActionListener(this); 136 lPOReference.setLabelFor(lPOReference); 137 fPOReference.setBackground(CompierePLAF.getInfoBackground()); 138 fPOReference.addActionListener(this); 139 fIsSOTrx.setSelected(!"N".equals(Env.getContext(Env.getCtx(), p_WindowNo, "IsSOTrx"))); 140 fIsSOTrx.addActionListener(this); 141 fBPartner_ID = new VLookup("C_BPartner_ID", false, false, true, 148 MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, 3499, DisplayType.Search), 149 DisplayType.Search, p_WindowNo); 150 lBPartner_ID.setLabelFor(fBPartner_ID); 151 fBPartner_ID.setBackground(CompierePLAF.getInfoBackground()); 152 lDateFrom.setLabelFor(fDateFrom); 154 fDateFrom.setBackground(CompierePLAF.getInfoBackground()); 155 fDateFrom.setToolTipText(Msg.translate(Env.getCtx(), "DateFrom")); 156 lDateTo.setLabelFor(fDateTo); 157 fDateTo.setBackground(CompierePLAF.getInfoBackground()); 158 fDateTo.setToolTipText(Msg.translate(Env.getCtx(), "DateTo")); 159 parameterPanel.setLayout(new ALayout()); 161 parameterPanel.add(lDocumentNo, new ALayoutConstraint(0,0)); 163 parameterPanel.add(fDocumentNo, null); 164 parameterPanel.add(lBPartner_ID, null); 165 parameterPanel.add(fBPartner_ID, null); 166 parameterPanel.add(fIsSOTrx, new ALayoutConstraint(0,5)); 167 parameterPanel.add(lDescription, new ALayoutConstraint(1,0)); 169 parameterPanel.add(fDescription, null); 170 parameterPanel.add(lDateFrom, null); 171 parameterPanel.add(fDateFrom, null); 172 parameterPanel.add(lDateTo, null); 173 parameterPanel.add(fDateTo, null); 174 parameterPanel.add(lPOReference, new ALayoutConstraint(2,0)); 176 parameterPanel.add(fPOReference, null); 177 } 181 185 private boolean initInfo () 186 { 187 String bp = Env.getContext(Env.getCtx(), p_WindowNo, "C_BPartner_ID"); 189 if (bp != null && bp.length() != 0) 190 fBPartner_ID.setValue(new Integer (bp)); 191 192 StringBuffer where = new StringBuffer ("i.IsActive='Y'"); 194 if (p_whereClause.length() > 0) 195 where.append(" AND ").append(Util.replace(p_whereClause, "M_InOut.", "i.")); 196 prepareTable(s_invoiceLayout, 197 " M_InOut i", 198 where.toString(), 199 "2,3,4"); 200 201 return true; 202 } 204 205 206 212 String getSQLWhere() 213 { 214 StringBuffer sql = new StringBuffer (); 215 if (fDocumentNo.getText().length() > 0) 216 sql.append(" AND UPPER(i.DocumentNo) LIKE ?"); 217 if (fDescription.getText().length() > 0) 218 sql.append(" AND UPPER(i.Description) LIKE ?"); 219 if (fPOReference.getText().length() > 0) 220 sql.append(" AND UPPER(i.POReference) LIKE ?"); 221 if (fBPartner_ID.getValue() != null) 223 sql.append(" AND i.C_BPartner_ID=?"); 224 if (fDateFrom.getValue() != null || fDateTo.getValue() != null) 226 { 227 Timestamp from = (Timestamp)fDateFrom.getValue(); 228 Timestamp to = (Timestamp)fDateTo.getValue(); 229 if (from == null && to != null) 230 sql.append(" AND TRUNC(i.MovementDate) <= ?"); 231 else if (from != null && to == null) 232 sql.append(" AND TRUNC(i.MovementDate) >= ?"); 233 else if (from != null && to != null) 234 sql.append(" AND TRUNC(i.MovementDate) BETWEEN ? AND ?"); 235 } 236 sql.append(" AND i.IsSOTrx=?"); 237 238 return sql.toString(); 240 } 242 248 void setParameters(PreparedStatement pstmt) throws SQLException 249 { 250 int index = 1; 251 if (fDocumentNo.getText().length() > 0) 252 pstmt.setString(index++, getSQLText(fDocumentNo)); 253 if (fDescription.getText().length() > 0) 254 pstmt.setString(index++, getSQLText(fDescription)); 255 if (fPOReference.getText().length() > 0) 256 pstmt.setString(index++, getSQLText(fPOReference)); 257 if (fBPartner_ID.getValue() != null) 259 { 260 Integer bp = (Integer )fBPartner_ID.getValue(); 261 pstmt.setInt(index++, bp.intValue()); 262 Log.trace(Log.l5_DData, "BPartner=" + bp); 263 } 264 if (fDateFrom.getValue() != null || fDateTo.getValue() != null) 266 { 267 Timestamp from = (Timestamp)fDateFrom.getValue(); 268 Timestamp to = (Timestamp)fDateTo.getValue(); 269 Log.trace(Log.l5_DData, "Date From=" + from + ", To=" + to); 270 if (from == null && to != null) 271 pstmt.setTimestamp(index++, to); 272 else if (from != null && to == null) 273 pstmt.setTimestamp(index++, from); 274 else if (from != null && to != null) 275 { 276 pstmt.setTimestamp(index++, from); 277 pstmt.setTimestamp(index++, to); 278 } 279 } 280 pstmt.setString(index++, fIsSOTrx.isSelected() ? "Y" : "N"); 281 } 283 288 private String getSQLText (CTextField f) 289 { 290 String s = f.getText().toUpperCase(); 291 if (!s.endsWith("%")) 292 s += "%"; 293 Log.trace(Log.l5_DData, "String=" + s); 294 return s; 295 } 297 } | Popular Tags |