📄 vmatch.java
字号:
ColumnInfo[] layout = new ColumnInfo[] {
new ColumnInfo(" ", ".", IDColumn.class, false, false, ""),
new ColumnInfo(Msg.translate(Env.getCtx(), "DocumentNo"), ".", String.class), // 1
new ColumnInfo(Msg.translate(Env.getCtx(), "Date"), ".", Timestamp.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "C_BPartner_ID"),".", KeyNamePair.class, "."), // 3
new ColumnInfo(Msg.translate(Env.getCtx(), "Line"), ".", KeyNamePair.class, "."),
new ColumnInfo(Msg.translate(Env.getCtx(), "M_Product_ID"), ".", KeyNamePair.class, "."), // 5
new ColumnInfo(Msg.translate(Env.getCtx(), "Qty"), ".", Double.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "Matched"), ".", Double.class)
};
xMatchedTable.prepareTable(layout, "", "", false);
xMatchedToTable.prepareTable(layout, "", "", true);
// Visual
CompiereColor.setBackground (this);
// Listener
matchFrom.addActionListener(this);
matchTo.addActionListener(this);
bSearch.addActionListener(this);
xMatchedTable.getSelectionModel().addListSelectionListener(this);
xMatchedToTable.getModel().addTableModelListener(this);
bProcess.addActionListener(this);
sameBPartner.addActionListener(this);
sameProduct.addActionListener(this);
sameQty.addActionListener(this);
// Init
cmd_matchFrom();
statusBar.setStatusLine("");
statusBar.setStatusDB(0);
} // dynInit
/**
* Dispose
*/
public void dispose()
{
m_frame.dispose();
} // dispose
/*************************************************************************/
/**
* Action Listener
* @param e event
*/
public void actionPerformed (ActionEvent e)
{
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
if (e.getSource() == matchFrom)
cmd_matchFrom();
else if (e.getSource() == matchTo)
cmd_matchTo();
else if (e.getSource() == bSearch)
cmd_search();
else if (e.getSource() == bProcess)
cmd_process();
else if (e.getSource() == sameBPartner
|| e.getSource() == sameProduct
|| e.getSource() == sameQty)
cmd_searchTo();
setCursor(Cursor.getDefaultCursor());
} // actionPerformed
/**
* Match From Changed - Fill Match To
*/
private void cmd_matchFrom()
{
// Log.trace(Log.l5_DData, "VMatch.cmd_matchFrom");
String selection = (String)matchFrom.getSelectedItem();
Vector vector = new Vector(2);
if (selection.equals(m_matchOptions[MATCH_INVOICE]))
vector.add(m_matchOptions[MATCH_SHIPMENT]);
else if (selection.equals(m_matchOptions[MATCH_ORDER]))
vector.add(m_matchOptions[MATCH_SHIPMENT]);
else // shipment
{
vector.add(m_matchOptions[MATCH_INVOICE]);
vector.add(m_matchOptions[MATCH_ORDER]);
}
matchTo.setModel(new DefaultComboBoxModel(vector));
// Set Title
xMatchedBorder.setTitle(selection);
xMatchedScrollPane.repaint();
// Reset Table
xMatchedTable.setRowCount(0);
// sync To
cmd_matchTo();
} // cmd_matchFrom
/**
* Match To Changed - set Title
*/
private void cmd_matchTo()
{
// Log.trace(Log.l5_DData, "VMatch.cmd_matchTo");
String selection = (String)matchTo.getSelectedItem();
xMatchedToBorder.setTitle(selection);
xMatchedToScrollPane.repaint();
// Reset Table
xMatchedToTable.setRowCount(0);
} // cmd_matchTo
/**
* Search Button Pressed - Fill xMatched
*/
private void cmd_search()
{
Log.trace(Log.l3_Util, "VMatch.cmd_search");
// ** Create SQL **
int display = matchFrom.getSelectedIndex();
String matchToString = (String)matchTo.getSelectedItem();
int matchTo = MATCH_INVOICE;
if (matchToString.equals(m_matchOptions[MATCH_SHIPMENT]))
matchTo = MATCH_SHIPMENT;
else if (matchToString.equals(m_matchOptions[MATCH_ORDER]))
matchTo = MATCH_ORDER;
tableInit(display, matchTo); // sets m_sql
// ** Add Where Clause **
// Product
if (onlyProduct.getValue() != null)
{
Integer Product = (Integer)onlyProduct.getValue();
m_sql.append(" AND lin.M_Product_ID=").append(Product);
}
// BPartner
if (onlyVendor.getValue() != null)
{
Integer Vendor = (Integer)onlyVendor.getValue();
m_sql.append(" AND hdr.C_BPartner_ID=").append(Vendor);
}
// Date
Timestamp from = (Timestamp)dateFrom.getValue();
Timestamp to = (Timestamp)dateTo.getValue();
if (from != null && to != null)
m_sql.append(" AND ").append(m_dateColumn).append(" BETWEEN ")
.append(DB.TO_DATE(from)).append(" AND ").append(DB.TO_DATE(to));
else if (from != null)
m_sql.append(" AND ").append(m_dateColumn).append(" >= ").append(DB.TO_DATE(from));
else if (to != null)
m_sql.append(" AND ").append(m_dateColumn).append(" <= ").append(DB.TO_DATE(to));
// ** Load Table **
tableLoad (xMatchedTable);
xMatched.setValue(Env.ZERO);
// Status Info
statusBar.setStatusLine(matchFrom.getSelectedItem().toString()
+ "# = " + xMatchedTable.getRowCount(),
xMatchedTable.getRowCount() == 0);
statusBar.setStatusDB(0);
} // cmd_search
/**
* Process Button Pressed - Process Matching
*/
private void cmd_process()
{
Log.trace(Log.l4_Data, "VMatch.cmd_process");
// Matched From
int matchedRow = xMatchedTable.getSelectedRow();
if (matchedRow < 0)
return;
// KeyNamePair BPartner = (KeyNamePair)xMatchedTable.getValueAt(matchedRow, I_BPartner);
KeyNamePair lineMatched = (KeyNamePair)xMatchedTable.getValueAt(matchedRow, I_Line);
KeyNamePair Product = (KeyNamePair)xMatchedTable.getValueAt(matchedRow, I_Product);
int M_Product_ID = Product.getKey();
double totalQty = m_xMatched.doubleValue();
// Matched To
for (int row = 0; row < xMatchedToTable.getRowCount(); row++)
{
IDColumn id = (IDColumn)xMatchedToTable.getValueAt(row, 0);
if (id != null && id.isSelected())
{
// need to be the same product
KeyNamePair ProductCompare = (KeyNamePair)xMatchedToTable.getValueAt(row, I_Product);
if (Product.getKey() != ProductCompare.getKey())
continue;
KeyNamePair lineMatchedTo = (KeyNamePair)xMatchedToTable.getValueAt(row, I_Line);
// Qty
double qty = 0.0;
if (matchMode.getSelectedIndex() == MODE_NOTMATCHED)
qty = ((Double)xMatchedToTable.getValueAt(row, I_QTY)).doubleValue(); // doc
qty -= ((Double)xMatchedToTable.getValueAt(row, I_MATCHED)).doubleValue(); // matched
if (qty > totalQty)
qty = totalQty;
totalQty -= qty;
// Invoice or PO
boolean invoice = true;
if (matchFrom.getSelectedIndex() == MATCH_ORDER ||
matchTo.getSelectedItem().equals(m_matchOptions[MATCH_ORDER]))
invoice = false;
// Get Shipment_ID
int M_InOutLine_ID = 0;
int Line_ID = 0;
if (matchFrom.getSelectedIndex() == MATCH_SHIPMENT)
{
M_InOutLine_ID = lineMatched.getKey(); // upper table
Line_ID = lineMatchedTo.getKey();
}
else
{
M_InOutLine_ID = lineMatchedTo.getKey(); // lower table
Line_ID = lineMatched.getKey();
}
// Create it
createMatchRecord(invoice, M_InOutLine_ID, Line_ID, M_Product_ID, qty);
}
}
// requery
cmd_search();
} // cmd_process
/*************************************************************************/
/**
* List Selection Listener - get Info and fill xMatchedTo
* @param e event
*/
public void valueChanged (ListSelectionEvent e)
{
if (e.getValueIsAdjusting())
return;
// Log.trace(Log.l4_Data, "VMatch.valueChanged");
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
cmd_searchTo();
setCursor(Cursor.getDefaultCursor());
} // valueChanged
/**
* Fill xMatchedTo
*/
private void cmd_searchTo()
{
int row = xMatchedTable.getSelectedRow();
Log.trace(Log.l3_Util, "VMatch.cmd_searchTo", "Row=" + row);
double qty = 0.0;
if (row < 0)
{
xMatchedToTable.setRowCount(0);
}
else
{
// ** Create SQL **
String displayString = (String)matchTo.getSelectedItem();
int display = MATCH_INVOICE;
if (displayString.equals(m_matchOptions[MATCH_SHIPMENT]))
display = MATCH_SHIPMENT;
else if (displayString.equals(m_matchOptions[MATCH_ORDER]))
display = MATCH_ORDER;
int matchTo = matchFrom.getSelectedIndex();
tableInit (display, matchTo); // sets m_sql
// ** Add Where Clause **
KeyNamePair BPartner = (KeyNamePair)xMatchedTable.getValueAt(row, I_BPartner);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -