📄 vcreatefrominvoice.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.grid;
import javax.swing.table.*;
import java.util.*;
import java.sql.*;
import java.math.*;
import java.text.*;
import java.beans.*;
import java.awt.event.*;
import org.compiere.apps.*;
import org.compiere.util.*;
import org.compiere.model.*;
/**
* Create Transactions for Invoices
*
* @author Jorg Janke
* @version $Id: VCreateFromInvoice.java,v 1.15 2003/04/30 06:24:50 jjanke Exp $
*/
public class VCreateFromInvoice extends VCreateFrom implements VetoableChangeListener
{
/**
* Protected Constructor
* @param mTab MTab
*/
VCreateFromInvoice(MTab mTab)
{
super (mTab);
Log.trace(Log.l1_User, "VCreateFromInvoice");
} // VCreateFromInvoice
private boolean m_actionActive = false;
/**
* Dynamic Init
* @throws Exception if Lookups cannot be initialized
* @return true if initialized
*/
protected boolean dynInit() throws Exception
{
Log.trace(Log.l3_Util, "VCreateFromInvoice.dynInit");
setTitle(Msg.getElement(Env.getCtx(), "C_Invoice_ID", false) + " .. " + Msg.translate(Env.getCtx(), "CreateFrom"));
parameterBankPanel.setVisible(false);
invoiceLabel.setVisible(false);
invoiceField.setVisible(false);
locatorLabel.setVisible(false);
locatorField.setVisible(false);
initBPartner(true);
bPartnerField.addVetoableChangeListener(this);
return true;
} // dynInit
/**
* Init Details - load receipts not invoiced
* @param C_BPartner_ID BPartner
*/
protected void initBPDetails(int C_BPartner_ID)
{
Log.trace(Log.l3_Util, "VCreateFromInvoice.iniBPDateails");
// load Shipments (Receipts) - Completed, Closed
shipmentField.removeActionListener(this);
shipmentField.removeAllItems();
// None
KeyNamePair pp = new KeyNamePair(0,"");
shipmentField.addItem(pp);
// Display
StringBuffer display = new StringBuffer("s.DocumentNo||' - '||")
.append(DB.TO_CHAR("s.MovementDate", DisplayType.Date, Env.getAD_Language(Env.getCtx())));
//
StringBuffer sql = new StringBuffer("SELECT s.M_InOut_ID,").append(display)
.append(" FROM M_InOut s "
+ "WHERE s.C_BPartner_ID=? AND s.IsSOTrx='N' AND s.DocStatus IN ('CL','CO')"
+ " AND s.M_InOut_ID IN "
+ "(SELECT sl.M_InOut_ID FROM M_InOutLine sl"
+ " LEFT OUTER JOIN M_MatchInv mi ON (sl.M_InOutLine_ID=mi.M_InOutLine_ID) "
+ "GROUP BY sl.M_InOut_ID,mi.M_InOutLine_ID,sl.MovementQty "
+ "HAVING (sl.MovementQty<>SUM(mi.Qty) AND mi.M_InOutLine_ID IS NOT NULL)"
+ " OR mi.M_InOutLine_ID IS NULL) "
+ "ORDER BY s.MovementDate");
try
{
PreparedStatement pstmt = DB.prepareStatement(sql.toString());
pstmt.setInt(1, C_BPartner_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
shipmentField.addItem(pp);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error ("VCreateFromInvoice.initBPDetails", e);
}
shipmentField.setSelectedIndex(0);
shipmentField.addActionListener(this);
} // initDetails
/**
* Action Listener
* @param e event
*/
public void actionPerformed(ActionEvent e)
{
super.actionPerformed(e);
if (m_actionActive)
return;
m_actionActive = true;
Log.trace(Log.l3_Util, "VCreateFromInvoice.actionPerformed - " + e.getActionCommand());
// Order
if (e.getSource().equals(orderField))
{
KeyNamePair pp = (KeyNamePair)orderField.getSelectedItem();
int C_Order_ID = 0;
if (pp != null)
C_Order_ID = pp.getKey();
// set Invoice and Shipment to Null
invoiceField.setSelectedIndex(-1);
shipmentField.setSelectedIndex(-1);
loadOrder(C_Order_ID, true);
}
// Shipment
else if (e.getSource().equals(shipmentField))
{
KeyNamePair pp = (KeyNamePair)shipmentField.getSelectedItem();
int M_InOut_ID = 0;
if (pp != null)
M_InOut_ID = pp.getKey();
// set Order and Invoice to Null
orderField.setSelectedIndex(-1);
invoiceField.setSelectedIndex(-1);
loadShipment(M_InOut_ID);
}
m_actionActive = false;
} // actionPerformed
/**
* Change Listener
* @param e event
*/
public void vetoableChange (PropertyChangeEvent e)
{
Log.trace(Log.l3_Util, "VCreateFromInvoice.vetoableChange " + e.getPropertyName() + "=" + e.getNewValue());
// BPartner - load Order/Invoice/Shipment
if (e.getPropertyName() == "C_BPartner_ID")
{
int C_BPartner_ID = ((Integer)e.getNewValue()).intValue();
initBPartnerOIS (C_BPartner_ID, true);
}
tableChanged(null);
} // vetoableChange
/**
* Load Data - Shipment not invoiced
* @param M_InOut_ID InOut
*/
private void loadShipment (int M_InOut_ID)
{
Log.trace(Log.l3_Util, "VCreateFromInvoice.loadShipment - " + M_InOut_ID);
Vector data = new Vector();
StringBuffer sql = new StringBuffer("SELECT l.MovementQty-SUM(NVL(mi.Qty,0)),"
+ " l.C_UOM_ID,uom.UOMSymbol," // 2..3
+ " l.M_Product_ID,p.Name, l.M_InOutLine_ID,l.Line," // 4..7
+ " l.C_OrderLine_ID "); // 8
if (Env.isBaseLanguage(Env.getCtx(), "C_UOM"))
{
sql.append("FROM C_UOM uom, M_InOutLine l, M_Product p, M_MatchInv mi ");
sql.append("WHERE l.C_UOM_ID=uom.C_UOM_ID");
}
else
{
sql.append("FROM C_UOM_Trl uom, M_InOutLine l, M_Product p, M_MatchInv mi ");
sql.append("WHERE l.C_UOM_ID=uom.C_UOM_ID AND uom.AD_Language='").append(Env.getAD_Language(Env.getCtx())).append("'");
}
sql.append(" AND l.M_Product_ID=p.M_Product_ID")
.append(" AND l.M_InOutLine_ID=mi.M_InOutLine_ID(+)")
.append("AND l.M_InOut_ID=? ") // #1
.append("GROUP BY l.MovementQty,l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.Name, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID ")
.append("ORDER BY l.Line");
try
{
PreparedStatement pstmt = DB.prepareStatement(sql.toString());
pstmt.setInt(1, M_InOut_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
Vector line = new Vector(7);
line.add(new Boolean(false)); // 0-Selection
line.add(new Double(rs.getDouble(1))); // 1-Qty
KeyNamePair pp = new KeyNamePair(rs.getInt(2), rs.getString(3).trim());
line.add(pp); // 2-UOM
pp = new KeyNamePair(rs.getInt(4), rs.getString(5));
line.add(pp); // 3-Product
int i = rs.getInt(8);
if (rs.wasNull())
line.add(null); // 4-Order
else
line.add(new KeyNamePair(i," "));
pp = new KeyNamePair(rs.getInt(6), rs.getString(7));
line.add(pp); // 5-Ship
line.add(null); // 6-Invoice
data.add(line);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error ("VCreateFromInvoice.loadShipment", e);
}
loadTableOIS (data);
} // loadShipment
/**
* List number of rows selected
*/
protected void info()
{
TableModel model = dataTable.getModel();
int rows = model.getRowCount();
int count = 0;
for (int i = 0; i < rows; i++)
{
if (((Boolean)model.getValueAt(i, 0)).booleanValue())
count++;
}
statusBar.setStatusLine(String.valueOf(count));
} // infoInvoice
/**
* Save - Create Invoice Lines
* @return true if saved
*/
protected boolean save()
{
Log.trace(Log.l3_Util, "VCreateFromInvoice.save");
// fixed values
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -