📄 invoicehistory.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.apps.search;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import java.math.*;
import org.compiere.util.*;
import org.compiere.minigrid.*;
import org.compiere.apps.*;
/**
* Price History for BPartner/Product
*
* @author Jorg Janke
* @version $Id: InvoiceHistory.java,v 1.4 2002/01/02 04:52:51 jjanke Exp $
*/
public class InvoiceHistory extends JDialog implements ActionListener
{
/**
* Show Price History
*/
public InvoiceHistory(Dialog frame, int C_BPartner_ID, int M_Product_ID)
{
super(frame, Msg.getMsg(Env.getCtx(), "PriceHistory"), true);
Log.trace(Log.l3_Util, "InvoiceHistory - BPartner=" + C_BPartner_ID
+ ", Product_ID=" + M_Product_ID);
try
{
jbInit();
}
catch(Exception ex)
{
Log.error("InvoiceHistory", ex);
}
dynInit(C_BPartner_ID, M_Product_ID);
AEnv.positionCenterWindow(frame, this);
} // InvoiceHistory
private JPanel panel = new JPanel();
private BorderLayout mainLayout = new BorderLayout();
private JScrollPane centerPanel = new JScrollPane();
private JPanel northPanel = new JPanel();
private JLabel label = new JLabel();
private FlowLayout northLayout = new FlowLayout();
//
private MiniTable m_table = new MiniTable();
private DefaultTableModel m_tableModel = null;
private Vector m_data = new Vector();
private ConfirmPanel confirmPanel = new ConfirmPanel();
/**
* Ststic Init
*/
void jbInit() throws Exception
{
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
panel.setLayout(mainLayout);
label.setText("Label");
northPanel.setLayout(northLayout);
northLayout.setAlignment(FlowLayout.LEFT);
getContentPane().add(panel);
panel.add(centerPanel, BorderLayout.CENTER);
centerPanel.getViewport().add(m_table, null);
panel.add(northPanel, BorderLayout.NORTH);
northPanel.add(label, null);
panel.add(confirmPanel, BorderLayout.SOUTH);
confirmPanel.addActionListener(this);
} // jbInit
/**
* Dynamic Init
*/
private boolean dynInit(int C_BPartner_ID, int M_Product_ID)
{
// Header
Vector columnNames = new Vector();
if (C_BPartner_ID == 0)
columnNames.add(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
else
columnNames.add(Msg.translate(Env.getCtx(), "M_Product_ID"));
columnNames.add(Msg.translate(Env.getCtx(), "PriceActual"));
columnNames.add(Msg.translate(Env.getCtx(), "QtyInvoiced"));
columnNames.add(Msg.translate(Env.getCtx(), "Discount"));
columnNames.add(Msg.translate(Env.getCtx(), "DocumentNo"));
columnNames.add(Msg.translate(Env.getCtx(), "DateInvoiced"));
// Fill Data
int rows = 0;
if (C_BPartner_ID == 0)
rows = queryBPartner(M_Product_ID); // Product By BPartner
else
rows = queryProduct(C_BPartner_ID); // BPartner By Product
// Table
m_tableModel = new DefaultTableModel(m_data, columnNames);
m_table.setModel(m_tableModel);
//
m_table.setColumnClass(0, String.class, true); // Product/Partner
m_table.setColumnClass(1, BigDecimal.class, true); // Price
m_table.setColumnClass(2, Double.class, true); // Quantity
m_table.setColumnClass(3, BigDecimal.class, true); // Discount (%)
m_table.setColumnClass(4, String.class, true); // DocNo
m_table.setColumnClass(5, Timestamp.class, true); // Date
//
m_table.autoSize();
//
return rows != 0;
} // dynInit
/**
* Get Info for Product for given Business Parner
*/
private int queryProduct (int C_BPartner_ID)
{
String sql = "SELECT p.Name,l.PriceActual,l.PriceList,l.QtyInvoiced,"
+ "i.DateInvoiced,dt.PrintName || ' ' || i.DocumentNo As DocumentNo "
+ "FROM C_Invoice i,C_InvoiceLine l,C_DocType dt,M_Product p "
+ "WHERE i.C_Invoice_ID=l.C_Invoice_ID"
+ " AND i.C_DocType_ID=dt.C_DocType_ID"
+ " AND l.M_Product_ID=p.M_Product_ID"
+ " AND i.C_BPartner_ID=? "
+ "ORDER BY i.DateInvoiced DESC";
int rows = fillTable (sql, C_BPartner_ID);
sql = "SELECT Name from C_BPartner WHERE C_BPartner_ID=?";
fillLabel (sql, C_BPartner_ID);
return rows;
} // queryProduct
/**
* Get Info for Business Partners for given Product
*/
private int queryBPartner (int M_Product_ID)
{
String sql = "SELECT bp.Name,l.PriceActual,l.PriceList,l.QtyInvoiced," // 1,2,3,4
+ "i.DateInvoiced,dt.PrintName || ' ' || i.DocumentNo As DocumentNo " // 5,6
+ "FROM C_Invoice i,C_InvoiceLine l,C_DocType dt,C_BPartner bp "
+ "WHERE i.C_Invoice_ID=l.C_Invoice_ID"
+ " AND i.C_DocType_ID=dt.C_DocType_ID"
+ " AND i.C_BPartner_ID=bp.C_BPartner_ID"
+ " AND l.M_Product_ID=? "
+ "ORDER BY i.DateInvoiced DESC";
int rows = fillTable (sql, M_Product_ID);
sql = "SELECT Name from M_Product WHERE M_Product_ID=?";
fillLabel (sql, M_Product_ID);
return rows;
} // qyeryBPartner
/**
* Fill Table
*/
private int fillTable (String sql, int parameter)
{
Log.trace(Log.l6_Database, "SQL=" + sql + "; Parameter=" + parameter);
m_data = new Vector();
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, parameter);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
Vector line = new Vector(6);
// 0-Name, 1-PriceActual, 2-QtyInvoiced, 3-Discount, 4-DocumentNo, 5-DateInvoiced
line.add(rs.getString(1)); // Name
line.add(rs.getBigDecimal(2)); // Price
line.add(new Double(rs.getDouble(4))); // Qty
BigDecimal discountBD = Env.ZERO;
try // discoint can be indefinate
{
double discountD = (rs.getDouble(3)-rs.getDouble(2)) / rs.getDouble(3) * 100;
discountBD = new BigDecimal(discountD);
}
catch (Exception e)
{
discountBD = Env.ZERO;
}
line.add(discountBD); // Discount
line.add(rs.getString(6)); // DocNo
line.add(rs.getTimestamp(5)); // Date
m_data.add(line);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error("InvoiceHistory.fillTable - SQL=" + sql, e);
}
Log.trace(Log.l5_DData, "fillTable #" + m_data.size());
return m_data.size();
} // fillTable
/**
* Set Label
* to product or bp name
*/
private void fillLabel (String sql, int parameter)
{
Log.trace(Log.l6_Database, "SQL=" + sql + "; Parameter=" + parameter);
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, parameter);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
label.setText(rs.getString(1));
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error("InvoiceHistory.fillLabel - SQL=" + sql, e);
}
} // fillLabel
/**
* Action Listener
*/
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals(ConfirmPanel.A_OK))
dispose();
} // actionPerformed
} // InvoiceHistory
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -