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 InfoOrder extends Info 43 { 44 53 protected InfoOrder(Frame frame, boolean modal, int WindowNo, String value, 54 boolean multiSelection, String whereClause) 55 { 56 super (frame, modal, WindowNo, "o", "C_Order_ID", multiSelection, whereClause); 57 Log.trace(Log.l1_User, "InfoOrder"); 58 setTitle(Msg.getMsg(Env.getCtx(), "InfoOrder")); 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 lDescription = new CLabel(Msg.translate(Env.getCtx(), "Description")); 97 private CTextField fDescription = new CTextField(10); 98 private CLabel lPOReference = new CLabel(Msg.translate(Env.getCtx(), "POReference")); 99 private CTextField fPOReference = new CTextField(10); 100 private CLabel lBPartner_ID = new CLabel(Msg.translate(Env.getCtx(), "C_BPartner_ID")); 104 private VLookup fBPartner_ID; 105 private CLabel lDateFrom = new CLabel(Msg.translate(Env.getCtx(), "DateOrdered")); 107 private VDate fDateFrom = new VDate("DateFrom", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateFrom")); 108 private CLabel lDateTo = new CLabel("-"); 109 private VDate fDateTo = new VDate("DateTo", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateTo")); 110 private CLabel lAmtFrom = new CLabel(Msg.translate(Env.getCtx(), "GrandTotal")); 111 private VNumber fAmtFrom = new VNumber("AmtFrom", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtFrom")); 112 private CLabel lAmtTo = new CLabel("-"); 113 private VNumber fAmtTo = new VNumber("AmtTo", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtTo")); 114 private VCheckBox fIsSOTrx = new VCheckBox ("IsSOTrx", false, false, true, Msg.translate(Env.getCtx(), "IsSOTrx"), "", false); 115 116 117 private static final Info_Column[] s_invoiceLayout = { 118 new Info_Column(" ", "o.C_Order_ID", IDColumn.class), 119 new Info_Column(Msg.translate(Env.getCtx(), "C_BPartner_ID"), "(SELECT Name FROM C_BPartner bp WHERE bp.C_BPartner_ID=o.C_BPartner_ID)", String .class), 120 new Info_Column(Msg.translate(Env.getCtx(), "DateOrdered"), "o.DateOrdered", Timestamp.class), 121 new Info_Column(Msg.translate(Env.getCtx(), "DocumentNo"), "o.DocumentNo", String .class), 122 new Info_Column(Msg.translate(Env.getCtx(), "C_Currency_ID"), "(SELECT ISO_Code FROM C_Currency c WHERE c.C_Currency_ID=o.C_Currency_ID)", String .class), 123 new Info_Column(Msg.translate(Env.getCtx(), "GrandTotal"), "o.GrandTotal", BigDecimal.class), 124 new Info_Column(Msg.translate(Env.getCtx(), "ConvertedAmount"), "C_Base_Convert(o.GrandTotal,o.C_Currency_ID,o.AD_Client_ID,o.DateAcct, o.AD_Org_ID)", BigDecimal.class), 125 new Info_Column(Msg.translate(Env.getCtx(), "IsSOTrx"), "o.IsSOTrx", Boolean .class), 126 new Info_Column(Msg.translate(Env.getCtx(), "Description"), "o.Description", String .class), 127 new Info_Column(Msg.translate(Env.getCtx(), "POReference"), "o.POReference", String .class) 128 }; 129 130 134 private void statInit() throws Exception 135 { 136 lDocumentNo.setLabelFor(fDocumentNo); 137 fDocumentNo.setBackground(CompierePLAF.getInfoBackground()); 138 fDocumentNo.addActionListener(this); 139 lDescription.setLabelFor(fDescription); 140 fDescription.setBackground(CompierePLAF.getInfoBackground()); 141 fDescription.addActionListener(this); 142 lPOReference.setLabelFor(lPOReference); 143 fPOReference.setBackground(CompierePLAF.getInfoBackground()); 144 fPOReference.addActionListener(this); 145 fIsSOTrx.setSelected(!"N".equals(Env.getContext(Env.getCtx(), p_WindowNo, "IsSOTrx"))); 146 fIsSOTrx.addActionListener(this); 147 fBPartner_ID = new VLookup("C_BPartner_ID", false, false, true, 154 MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, 3499, DisplayType.Search), 155 DisplayType.Search, p_WindowNo); 156 lBPartner_ID.setLabelFor(fBPartner_ID); 157 fBPartner_ID.setBackground(CompierePLAF.getInfoBackground()); 158 lDateFrom.setLabelFor(fDateFrom); 160 fDateFrom.setBackground(CompierePLAF.getInfoBackground()); 161 fDateFrom.setToolTipText(Msg.translate(Env.getCtx(), "DateFrom")); 162 lDateTo.setLabelFor(fDateTo); 163 fDateTo.setBackground(CompierePLAF.getInfoBackground()); 164 fDateTo.setToolTipText(Msg.translate(Env.getCtx(), "DateTo")); 165 lAmtFrom.setLabelFor(fAmtFrom); 166 fAmtFrom.setBackground(CompierePLAF.getInfoBackground()); 167 fAmtFrom.setToolTipText(Msg.translate(Env.getCtx(), "AmtFrom")); 168 lAmtTo.setLabelFor(fAmtTo); 169 fAmtTo.setBackground(CompierePLAF.getInfoBackground()); 170 fAmtTo.setToolTipText(Msg.translate(Env.getCtx(), "AmtTo")); 171 parameterPanel.setLayout(new ALayout()); 173 parameterPanel.add(lDocumentNo, new ALayoutConstraint(0,0)); 175 parameterPanel.add(fDocumentNo, null); 176 parameterPanel.add(lBPartner_ID, null); 177 parameterPanel.add(fBPartner_ID, null); 178 parameterPanel.add(fIsSOTrx, new ALayoutConstraint(0,5)); 179 parameterPanel.add(lDescription, new ALayoutConstraint(1,0)); 181 parameterPanel.add(fDescription, null); 182 parameterPanel.add(lDateFrom, null); 183 parameterPanel.add(fDateFrom, null); 184 parameterPanel.add(lDateTo, null); 185 parameterPanel.add(fDateTo, null); 186 parameterPanel.add(lPOReference, new ALayoutConstraint(2,0)); 188 parameterPanel.add(fPOReference, null); 189 parameterPanel.add(lAmtFrom, null); 190 parameterPanel.add(fAmtFrom, null); 191 parameterPanel.add(lAmtTo, null); 192 parameterPanel.add(fAmtTo, null); 193 } 197 201 private boolean initInfo () 202 { 203 String bp = Env.getContext(Env.getCtx(), p_WindowNo, "C_BPartner_ID"); 205 if (bp != null && bp.length() != 0) 206 fBPartner_ID.setValue(new Integer (bp)); 207 208 StringBuffer where = new StringBuffer ("o.IsActive='Y'"); 210 if (p_whereClause.length() > 0) 211 where.append(" AND ").append(Util.replace(p_whereClause, "C_Order.", "o.")); 212 prepareTable(s_invoiceLayout, 213 " C_Order o", 214 where.toString(), 215 "2,3,4"); 216 217 return true; 218 } 220 221 222 228 String getSQLWhere() 229 { 230 StringBuffer sql = new StringBuffer (); 231 if (fDocumentNo.getText().length() > 0) 232 sql.append(" AND UPPER(o.DocumentNo) LIKE ?"); 233 if (fDescription.getText().length() > 0) 234 sql.append(" AND UPPER(o.Description) LIKE ?"); 235 if (fPOReference.getText().length() > 0) 236 sql.append(" AND UPPER(o.POReference) LIKE ?"); 237 if (fBPartner_ID.getValue() != null) 239 sql.append(" AND o.C_BPartner_ID=?"); 240 if (fDateFrom.getValue() != null || fDateTo.getValue() != null) 242 { 243 Timestamp from = (Timestamp)fDateFrom.getValue(); 244 Timestamp to = (Timestamp)fDateTo.getValue(); 245 if (from == null && to != null) 246 sql.append(" AND TRUNC(o.DateOrdered) <= ?"); 247 else if (from != null && to == null) 248 sql.append(" AND TRUNC(o.DateOrdered) >= ?"); 249 else if (from != null && to != null) 250 sql.append(" AND TRUNC(o.DateOrdered) BETWEEN ? AND ?"); 251 } 252 if (fAmtFrom.getValue() != null || fAmtTo.getValue() != null) 254 { 255 BigDecimal from = (BigDecimal)fAmtFrom.getValue(); 256 BigDecimal to = (BigDecimal)fAmtTo.getValue(); 257 if (from == null && to != null) 258 sql.append(" AND o.GrandTotal <= ?"); 259 else if (from != null && to == null) 260 sql.append(" AND o.GrandTotal >= ?"); 261 else if (from != null && to != null) 262 sql.append(" AND o.GrandTotal BETWEEN ? AND ?"); 263 } 264 sql.append(" AND o.IsSOTrx=?"); 265 266 return sql.toString(); 268 } 270 276 void setParameters(PreparedStatement pstmt) throws SQLException 277 { 278 int index = 1; 279 if (fDocumentNo.getText().length() > 0) 280 pstmt.setString(index++, getSQLText(fDocumentNo)); 281 if (fDescription.getText().length() > 0) 282 pstmt.setString(index++, getSQLText(fDescription)); 283 if (fPOReference.getText().length() > 0) 284 pstmt.setString(index++, getSQLText(fPOReference)); 285 if (fBPartner_ID.getValue() != null) 287 { 288 Integer bp = (Integer )fBPartner_ID.getValue(); 289 pstmt.setInt(index++, bp.intValue()); 290 Log.trace(Log.l5_DData, "BPartner=" + bp); 291 } 292 if (fDateFrom.getValue() != null || fDateTo.getValue() != null) 294 { 295 Timestamp from = (Timestamp)fDateFrom.getValue(); 296 Timestamp to = (Timestamp)fDateTo.getValue(); 297 Log.trace(Log.l5_DData, "Date From=" + from + ", To=" + to); 298 if (from == null && to != null) 299 pstmt.setTimestamp(index++, to); 300 else if (from != null && to == null) 301 pstmt.setTimestamp(index++, from); 302 else if (from != null && to != null) 303 { 304 pstmt.setTimestamp(index++, from); 305 pstmt.setTimestamp(index++, to); 306 } 307 } 308 if (fAmtFrom.getValue() != null || fAmtTo.getValue() != null) 310 { 311 BigDecimal from = (BigDecimal)fAmtFrom.getValue(); 312 BigDecimal to = (BigDecimal)fAmtTo.getValue(); 313 Log.trace(Log.l5_DData, "Amt From=" + from + ", To=" + to); 314 if (from == null && to != null) 315 pstmt.setBigDecimal(index++, to); 316 else if (from != null && to == null) 317 pstmt.setBigDecimal(index++, from); 318 else if (from != null && to != null) 319 { 320 pstmt.setBigDecimal(index++, from); 321 pstmt.setBigDecimal(index++, to); 322 } 323 } 324 pstmt.setString(index++, fIsSOTrx.isSelected() ? "Y" : "N"); 325 } 327 332 private String getSQLText (CTextField f) 333 { 334 String s = f.getText().toUpperCase(); 335 if (!s.endsWith("%")) 336 s += "%"; 337 Log.trace(Log.l5_DData, "String=" + s); 338 return s; 339 } } | Popular Tags |