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 InfoInvoice extends Info 43 { 44 54 protected InfoInvoice(Frame frame, boolean modal, int WindowNo, String value, 55 boolean multiSelection, String whereClause) 56 { 57 super (frame, modal, WindowNo, "i", "C_Invoice_ID", multiSelection, whereClause); 58 Log.trace(Log.l1_User, "InfoInvoice"); 59 setTitle(Msg.getMsg(Env.getCtx(), "InfoInvoice")); 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 lBPartner_ID = new CLabel(Msg.translate(Env.getCtx(), "C_BPartner_ID")); 105 private VLookup fBPartner_ID; 106 private CLabel lOrder_ID = new CLabel(Msg.translate(Env.getCtx(), "C_Order_ID")); 107 private VLookup fOrder_ID; 108 private VCheckBox fIsPaid = new VCheckBox ("IsPaid", false, false, true, Msg.translate(Env.getCtx(), "IsPaid"), "", false); 109 private VCheckBox fIsSOTrx = new VCheckBox ("IsSOTrx", false, false, true, Msg.translate(Env.getCtx(), "IsSOTrx"), "", false); 110 private CLabel lDateFrom = new CLabel(Msg.translate(Env.getCtx(), "DateInvoiced")); 112 private VDate fDateFrom = new VDate("DateFrom", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateFrom")); 113 private CLabel lDateTo = new CLabel("-"); 114 private VDate fDateTo = new VDate("DateTo", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateTo")); 115 private CLabel lAmtFrom = new CLabel(Msg.translate(Env.getCtx(), "GrandTotal")); 116 private VNumber fAmtFrom = new VNumber("AmtFrom", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtFrom")); 117 private CLabel lAmtTo = new CLabel("-"); 118 private VNumber fAmtTo = new VNumber("AmtTo", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtTo")); 119 120 121 private static final Info_Column[] s_invoiceLayout = { 122 new Info_Column(" ", "i.C_Invoice_ID", IDColumn.class), 123 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), 124 new Info_Column(Msg.translate(Env.getCtx(), "DateInvoiced"), "i.DateInvoiced", Timestamp.class), 125 new Info_Column(Msg.translate(Env.getCtx(), "DocumentNo"), "i.DocumentNo", String .class), 126 new Info_Column(Msg.translate(Env.getCtx(), "C_Currency_ID"), "(SELECT ISO_Code FROM C_Currency c WHERE c.C_Currency_ID=i.C_Currency_ID)", String .class), 127 new Info_Column(Msg.translate(Env.getCtx(), "GrandTotal"), "i.GrandTotal", BigDecimal.class), 128 new Info_Column(Msg.translate(Env.getCtx(), "ConvertedAmount"), "C_Base_Convert(i.GrandTotal, i.C_Currency_ID, i.AD_Client_ID, i.DateAcct, i.AD_Org_ID)", BigDecimal.class), 129 new Info_Column(Msg.translate(Env.getCtx(), "OpenAmt"), "C_Invoice_Open(C_Invoice_ID)", BigDecimal.class, true, true, null), 130 new Info_Column(Msg.translate(Env.getCtx(), "IsPaid"), "i.IsPaid", Boolean .class), 131 new Info_Column(Msg.translate(Env.getCtx(), "IsSOTrx"), "i.IsSOTrx", Boolean .class), 132 new Info_Column(Msg.translate(Env.getCtx(), "Description"), "i.Description", String .class), 133 new Info_Column(Msg.translate(Env.getCtx(), "POReference"), "i.POReference", String .class) 134 }; 135 136 140 private void statInit() throws Exception 141 { 142 lDocumentNo.setLabelFor(fDocumentNo); 143 fDocumentNo.setBackground(CompierePLAF.getInfoBackground()); 144 fDocumentNo.addActionListener(this); 145 lDescription.setLabelFor(fDescription); 146 fDescription.setBackground(CompierePLAF.getInfoBackground()); 147 fDescription.addActionListener(this); 148 fIsPaid.setSelected(false); 152 fIsPaid.addActionListener(this); 153 fIsSOTrx.setSelected(!"N".equals(Env.getContext(Env.getCtx(), p_WindowNo, "IsSOTrx"))); 154 fIsSOTrx.addActionListener(this); 155 fBPartner_ID = new VLookup("C_BPartner_ID", false, false, true, 163 MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, 3499, DisplayType.Search), 164 DisplayType.Search, p_WindowNo); 165 lBPartner_ID.setLabelFor(fBPartner_ID); 166 fBPartner_ID.setBackground(CompierePLAF.getInfoBackground()); 167 fOrder_ID = new VLookup("C_Order_ID", false, false, true, 169 MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, 4247, DisplayType.Search), 170 DisplayType.Search, p_WindowNo); 171 lOrder_ID.setLabelFor(fOrder_ID); 172 fOrder_ID.setBackground(CompierePLAF.getInfoBackground()); 173 lDateFrom.setLabelFor(fDateFrom); 175 fDateFrom.setBackground(CompierePLAF.getInfoBackground()); 176 fDateFrom.setToolTipText(Msg.translate(Env.getCtx(), "DateFrom")); 177 lDateTo.setLabelFor(fDateTo); 178 fDateTo.setBackground(CompierePLAF.getInfoBackground()); 179 fDateTo.setToolTipText(Msg.translate(Env.getCtx(), "DateTo")); 180 lAmtFrom.setLabelFor(fAmtFrom); 181 fAmtFrom.setBackground(CompierePLAF.getInfoBackground()); 182 fAmtFrom.setToolTipText(Msg.translate(Env.getCtx(), "AmtFrom")); 183 lAmtTo.setLabelFor(fAmtTo); 184 fAmtTo.setBackground(CompierePLAF.getInfoBackground()); 185 fAmtTo.setToolTipText(Msg.translate(Env.getCtx(), "AmtTo")); 186 parameterPanel.setLayout(new ALayout()); 188 parameterPanel.add(lDocumentNo, new ALayoutConstraint(0,0)); 190 parameterPanel.add(fDocumentNo, null); 191 parameterPanel.add(lBPartner_ID, null); 192 parameterPanel.add(fBPartner_ID, null); 193 parameterPanel.add(fIsSOTrx, new ALayoutConstraint(0,5)); 194 parameterPanel.add(fIsPaid, null); 195 parameterPanel.add(lDescription, new ALayoutConstraint(1,0)); 197 parameterPanel.add(fDescription, null); 198 parameterPanel.add(lDateFrom, null); 199 parameterPanel.add(fDateFrom, null); 200 parameterPanel.add(lDateTo, null); 201 parameterPanel.add(fDateTo, null); 202 parameterPanel.add(lOrder_ID, new ALayoutConstraint(2,0)); 204 parameterPanel.add(fOrder_ID, null); 205 parameterPanel.add(lAmtFrom, null); 206 parameterPanel.add(fAmtFrom, null); 207 parameterPanel.add(lAmtTo, null); 208 parameterPanel.add(fAmtTo, null); 209 } 213 217 private boolean initInfo () 218 { 219 String bp = Env.getContext(Env.getCtx(), p_WindowNo, "C_BPartner_ID"); 221 if (bp != null && bp.length() != 0) 222 fBPartner_ID.setValue(new Integer (bp)); 223 224 StringBuffer where = new StringBuffer ("i.IsActive='Y'"); 226 if (p_whereClause.length() > 0) 227 where.append(" AND ").append(Util.replace(p_whereClause, "C_Invoice.", "i.")); 228 prepareTable(s_invoiceLayout, 229 " C_Invoice_v i", where.toString(), 231 "2,3,4"); 232 233 return true; 234 } 236 237 238 244 String getSQLWhere() 245 { 246 StringBuffer sql = new StringBuffer (); 247 if (fDocumentNo.getText().length() > 0) 248 sql.append(" AND UPPER(i.DocumentNo) LIKE ?"); 249 if (fDescription.getText().length() > 0) 250 sql.append(" AND UPPER(i.Description) LIKE ?"); 251 if (fBPartner_ID.getValue() != null) 255 sql.append(" AND i.C_BPartner_ID=?"); 256 if (fOrder_ID.getValue() != null) 258 sql.append(" AND i.C_Order_ID=?"); 259 if (fDateFrom.getValue() != null || fDateTo.getValue() != null) 261 { 262 Timestamp from = (Timestamp)fDateFrom.getValue(); 263 Timestamp to = (Timestamp)fDateTo.getValue(); 264 if (from == null && to != null) 265 sql.append(" AND TRUNC(i.DateInvoiced) <= ?"); 266 else if (from != null && to == null) 267 sql.append(" AND TRUNC(i.DateInvoiced) >= ?"); 268 else if (from != null && to != null) 269 sql.append(" AND TRUNC(i.DateInvoiced) BETWEEN ? AND ?"); 270 } 271 if (fAmtFrom.getValue() != null || fAmtTo.getValue() != null) 273 { 274 BigDecimal from = (BigDecimal)fAmtFrom.getValue(); 275 BigDecimal to = (BigDecimal)fAmtTo.getValue(); 276 if (from == null && to != null) 277 sql.append(" AND i.GrandTotal <= ?"); 278 else if (from != null && to == null) 279 sql.append(" AND i.GrandTotal >= ?"); 280 else if (from != null && to != null) 281 sql.append(" AND i.GrandTotal BETWEEN ? AND ?"); 282 } 283 sql.append(" AND i.IsPaid=? AND i.IsSOTrx=?"); 285 286 return sql.toString(); 288 } 290 296 void setParameters(PreparedStatement pstmt) throws SQLException 297 { 298 int index = 1; 299 if (fDocumentNo.getText().length() > 0) 300 pstmt.setString(index++, getSQLText(fDocumentNo)); 301 if (fDescription.getText().length() > 0) 302 pstmt.setString(index++, getSQLText(fDescription)); 303 if (fBPartner_ID.getValue() != null) 307 { 308 Integer bp = (Integer )fBPartner_ID.getValue(); 309 pstmt.setInt(index++, bp.intValue()); 310 Log.trace(Log.l5_DData, "BPartner=" + bp); 311 } 312 if (fOrder_ID.getValue() != null) 314 { 315 Integer order = (Integer )fOrder_ID.getValue(); 316 pstmt.setInt(index++, order.intValue()); 317 Log.trace(Log.l5_DData, "Order=" + order); 318 } 319 if (fDateFrom.getValue() != null || fDateTo.getValue() != null) 321 { 322 Timestamp from = (Timestamp)fDateFrom.getValue(); 323 Timestamp to = (Timestamp)fDateTo.getValue(); 324 Log.trace(Log.l5_DData, "Date From=" + from + ", To=" + to); 325 if (from == null && to != null) 326 pstmt.setTimestamp(index++, to); 327 else if (from != null && to == null) 328 pstmt.setTimestamp(index++, from); 329 else if (from != null && to != null) 330 { 331 pstmt.setTimestamp(index++, from); 332 pstmt.setTimestamp(index++, to); 333 } 334 } 335 if (fAmtFrom.getValue() != null || fAmtTo.getValue() != null) 337 { 338 BigDecimal from = (BigDecimal)fAmtFrom.getValue(); 339 BigDecimal to = (BigDecimal)fAmtTo.getValue(); 340 Log.trace(Log.l5_DData, "Amt From=" + from + ", To=" + to); 341 if (from == null && to != null) 342 pstmt.setBigDecimal(index++, to); 343 else if (from != null && to == null) 344 pstmt.setBigDecimal(index++, from); 345 else if (from != null && to != null) 346 { 347 pstmt.setBigDecimal(index++, from); 348 pstmt.setBigDecimal(index++, to); 349 } 350 } 351 pstmt.setString(index++, fIsPaid.isSelected() ? "Y" : "N"); 352 pstmt.setString(index++, fIsSOTrx.isSelected() ? "Y" : "N"); 353 } 355 360 private String getSQLText (CTextField f) 361 { 362 String s = f.getText().toUpperCase(); 363 if (!s.endsWith("%")) 364 s += "%"; 365 Log.trace(Log.l5_DData, "String=" + s); 366 return s; 367 } } | Popular Tags |