VOrderDistribution, VOrderReceiptIssue:

* organized imports
* fixed indentation
* added serialVersionUID = 1
This commit is contained in:
teo_sarca 2008-08-18 08:29:25 +00:00
parent 39d29a9116
commit ec6f0ea17c
1 changed files with 140 additions and 95 deletions

View File

@ -15,27 +15,70 @@
*****************************************************************************/ *****************************************************************************/
package org.eevolution.form; package org.eevolution.form;
import java.awt.*; import java.awt.BorderLayout;
import java.awt.event.*; import java.awt.Cursor;
import java.beans.*; import java.awt.FlowLayout;
import java.math.*; import java.awt.event.ActionEvent;
import java.sql.*; import java.awt.event.ActionListener;
import java.util.*; import java.beans.PropertyChangeEvent;
import java.util.logging.*; import java.beans.VetoableChangeListener;
import javax.swing.*; import java.math.BigDecimal;
import javax.swing.event.*; import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.logging.Level;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import org.adempiere.plaf.AdempierePLAF; import org.adempiere.plaf.AdempierePLAF;
import org.compiere.apps.*; import org.compiere.apps.ADialog;
import org.compiere.apps.form.*; import org.compiere.apps.ADialogDialog;
import org.compiere.grid.ed.*; import org.compiere.apps.ConfirmPanel;
import org.compiere.minigrid.*; import org.compiere.apps.ProcessCtl;
import org.compiere.model.*; import org.compiere.apps.StatusBar;
import org.compiere.plaf.*; import org.compiere.apps.form.FormFrame;
import org.compiere.print.*; import org.compiere.apps.form.FormPanel;
import org.compiere.process.*; import org.compiere.grid.ed.VComboBox;
import org.compiere.swing.*; import org.compiere.grid.ed.VLookup;
import org.compiere.util.*; import org.compiere.minigrid.IDColumn;
import org.compiere.minigrid.MiniTable;
import org.compiere.model.MColumn;
import org.compiere.model.MLocator;
import org.compiere.model.MLookup;
import org.compiere.model.MLookupFactory;
import org.compiere.model.MMovement;
import org.compiere.model.MOrder;
import org.compiere.model.MPInstance;
import org.compiere.model.MPInstancePara;
import org.compiere.model.MPrivateAccess;
import org.compiere.model.MProcess;
import org.compiere.model.MQuery;
import org.compiere.model.PrintInfo;
import org.compiere.plaf.CompiereColor;
import org.compiere.print.MPrintFormat;
import org.compiere.print.ReportEngine;
import org.compiere.print.Viewer;
import org.compiere.process.ProcessInfo;
import org.compiere.process.ProcessInfoUtil;
import org.compiere.swing.CLabel;
import org.compiere.swing.CPanel;
import org.compiere.swing.CTabbedPane;
import org.compiere.swing.CTextPane;
import org.compiere.util.ASyncProcess;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.compiere.util.Trx;
import org.eevolution.model.MDDOrder; import org.eevolution.model.MDDOrder;
/** /**
@ -46,8 +89,10 @@ import org.eevolution.model.MDDOrder;
*/ */
public class VOrderDistribution extends CPanel public class VOrderDistribution extends CPanel
implements FormPanel, ActionListener, VetoableChangeListener, implements FormPanel, ActionListener, VetoableChangeListener,
ChangeListener, TableModelListener, ASyncProcess ChangeListener, TableModelListener, ASyncProcess
{ {
private static final long serialVersionUID = 1L;
/** /**
* Initialize Panel * Initialize Panel
* @param WindowNo window * @param WindowNo window
@ -106,13 +151,13 @@ public class VOrderDistribution extends CPanel
private CTextPane info = new CTextPane(); private CTextPane info = new CTextPane();
private JScrollPane scrollPane = new JScrollPane(); private JScrollPane scrollPane = new JScrollPane();
private MiniTable miniTable = new MiniTable(); private MiniTable miniTable = new MiniTable();
private CLabel lDocType = new CLabel(); private CLabel lDocType = new CLabel();
private VComboBox cmbDocType = new VComboBox(); private VComboBox cmbDocType = new VComboBox();
/** User selection */ /** User selection */
private ArrayList<Integer> selection = null; private ArrayList<Integer> selection = null;
/** /**
* Static Init. * Static Init.
* <pre> * <pre>
@ -178,19 +223,19 @@ public class VOrderDistribution extends CPanel
fOrder.addVetoableChangeListener(this); fOrder.addVetoableChangeListener(this);
lOrder.setVisible(false); lOrder.setVisible(false);
fOrder.setVisible(false); fOrder.setVisible(false);
MLookup llocator= MLookupFactory.get (Env.getCtx(), m_WindowNo, 0, 53950, DisplayType.TableDir); MLookup llocator= MLookupFactory.get (Env.getCtx(), m_WindowNo, 0, 53950, DisplayType.TableDir);
fLocator = new VLookup (MLocator.COLUMNNAME_M_Locator_ID, true, false, true, llocator); fLocator = new VLookup (MLocator.COLUMNNAME_M_Locator_ID, true, false, true, llocator);
lLocator.setText(Msg.translate(Env.getCtx(), "M_Locator_ID")); lLocator.setText(Msg.translate(Env.getCtx(), "M_Locator_ID"));
fLocator.addVetoableChangeListener(this); fLocator.addVetoableChangeListener(this);
m_M_Locator_ID = fLocator.getValue(); m_M_Locator_ID = fLocator.getValue();
MLookup llocatorto = MLookupFactory.get (Env.getCtx(), m_WindowNo, 0, 53949, DisplayType.TableDir); MLookup llocatorto = MLookupFactory.get (Env.getCtx(), m_WindowNo, 0, 53949, DisplayType.TableDir);
fLocatorTo = new VLookup ("M_LocatorTo_ID", false, false, true, llocatorto); fLocatorTo = new VLookup ("M_LocatorTo_ID", false, false, true, llocatorto);
lLocatorTo.setText(Msg.translate(Env.getCtx(), "M_LocatorTo_ID")); lLocatorTo.setText(Msg.translate(Env.getCtx(), "M_LocatorTo_ID"));
fLocatorTo.addVetoableChangeListener(this); fLocatorTo.addVetoableChangeListener(this);
m_M_LocatorTo_ID = fLocatorTo.getValue(); m_M_LocatorTo_ID = fLocatorTo.getValue();
// C_Order.C_BPartner_ID // C_Order.C_BPartner_ID
MLookup bpL = MLookupFactory.get (Env.getCtx(), m_WindowNo, 0, 2762, DisplayType.Search); MLookup bpL = MLookupFactory.get (Env.getCtx(), m_WindowNo, 0, 2762, DisplayType.Search);
fBPartner = new VLookup ("C_BPartner_ID", false, false, true, bpL); fBPartner = new VLookup ("C_BPartner_ID", false, false, true, bpL);
@ -245,40 +290,40 @@ public class VOrderDistribution extends CPanel
*/ */
private String getOrderSQL() private String getOrderSQL()
{ {
// Create SQL // Create SQL
StringBuffer sql = new StringBuffer( StringBuffer sql = new StringBuffer(
"SELECT DD_Order_ID, o.Name, dt.Name, DocumentNo, bp.Name, DateOrdered " "SELECT DD_Order_ID, o.Name, dt.Name, DocumentNo, bp.Name, DateOrdered "
+ "FROM M_Movement_Candidate_v ic, AD_Org o, C_BPartner bp, C_DocType dt " + "FROM M_Movement_Candidate_v ic, AD_Org o, C_BPartner bp, C_DocType dt "
+ "WHERE ic.AD_Org_ID=o.AD_Org_ID" + "WHERE ic.AD_Org_ID=o.AD_Org_ID"
+ " AND ic.C_BPartner_ID=bp.C_BPartner_ID" + " AND ic.C_BPartner_ID=bp.C_BPartner_ID"
+ " AND ic.C_DocType_ID=dt.C_DocType_ID" + " AND ic.C_DocType_ID=dt.C_DocType_ID"
+ " AND ic.AD_Client_ID=?"); + " AND ic.AD_Client_ID=?");
if(m_M_Locator_ID != null) if(m_M_Locator_ID != null)
sql.append(" AND ic.M_Locator_ID=").append(m_M_Locator_ID); sql.append(" AND ic.M_Locator_ID=").append(m_M_Locator_ID);
/*if (m_M_Warehouse_ID != null) /*if (m_M_Warehouse_ID != null)
sql.append(" AND ic.M_Warehouse_ID=").append(m_M_Warehouse_ID);*/ sql.append(" AND ic.M_Warehouse_ID=").append(m_M_Warehouse_ID);*/
if(m_M_LocatorTo_ID != null) if(m_M_LocatorTo_ID != null)
sql.append(" AND ic.M_LocatorTo_ID=").append(m_M_LocatorTo_ID); sql.append(" AND ic.M_LocatorTo_ID=").append(m_M_LocatorTo_ID);
if (m_C_BPartner_ID != null) if (m_C_BPartner_ID != null)
sql.append(" AND ic.C_BPartner_ID=").append(m_C_BPartner_ID); sql.append(" AND ic.C_BPartner_ID=").append(m_C_BPartner_ID);
// bug - [ 1713317 ] Generate Shipments (manual) show locked records // bug - [ 1713317 ] Generate Shipments (manual) show locked records
/* begin - Exclude locked records; @Trifon */ /* begin - Exclude locked records; @Trifon */
int AD_User_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID"); int AD_User_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID");
String lockedIDs = MPrivateAccess.getLockedRecordWhere(MOrder.Table_ID, AD_User_ID); String lockedIDs = MPrivateAccess.getLockedRecordWhere(MOrder.Table_ID, AD_User_ID);
if (lockedIDs != null) if (lockedIDs != null)
{ {
if (sql.length() > 0) if (sql.length() > 0)
sql.append(" AND "); sql.append(" AND ");
sql.append("DD_Order_ID").append(lockedIDs); sql.append("DD_Order_ID").append(lockedIDs);
} }
/* eng - Exclude locked records; @Trifon */ /* eng - Exclude locked records; @Trifon */
// //
sql.append(" ORDER BY o.Name,bp.Name,DateOrdered"); sql.append(" ORDER BY o.Name,bp.Name,DateOrdered");
return sql.toString(); return sql.toString();
} }
/** /**
@ -288,12 +333,12 @@ public class VOrderDistribution extends CPanel
{ {
log.info(""); log.info("");
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx()); int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
String sql = ""; String sql = "";
KeyNamePair docTypeKNPair = (KeyNamePair)cmbDocType.getSelectedItem(); KeyNamePair docTypeKNPair = (KeyNamePair)cmbDocType.getSelectedItem();
sql = getOrderSQL(); sql = getOrderSQL();
log.fine(sql); log.fine(sql);
// reset table // reset table
@ -330,7 +375,7 @@ public class VOrderDistribution extends CPanel
} }
// //
miniTable.autoSize(); miniTable.autoSize();
// statusBar.setStatusDB(String.valueOf(miniTable.getRowCount())); // statusBar.setStatusDB(String.valueOf(miniTable.getRowCount()));
} // executeQuery } // executeQuery
/** /**
@ -358,15 +403,15 @@ public class VOrderDistribution extends CPanel
} }
if (cmbDocType.equals(e.getSource())) if (cmbDocType.equals(e.getSource()))
{ {
executeQuery(); executeQuery();
return; return;
} }
// //
saveSelection(); saveSelection();
if (selection != null if (selection != null
&& selection.size() > 0 && selection.size() > 0
&& m_selectionActive // on selection tab && m_selectionActive // on selection tab
&& m_M_Locator_ID != null) && m_M_Locator_ID != null)
generateMovements (); generateMovements ();
else else
dispose(); dispose();
@ -380,7 +425,7 @@ public class VOrderDistribution extends CPanel
{ {
log.info(e.getPropertyName() + "=" + e.getNewValue()); log.info(e.getPropertyName() + "=" + e.getNewValue());
//if (e.getPropertyName().equals("M_Warehouse_ID")) //if (e.getPropertyName().equals("M_Warehouse_ID"))
//m_M_Warehouse_ID = e.getNewValue(); //m_M_Warehouse_ID = e.getNewValue();
if (e.getPropertyName().equals("M_Locator_ID")) if (e.getPropertyName().equals("M_Locator_ID"))
m_M_Locator_ID = e.getNewValue(); m_M_Locator_ID = e.getNewValue();
if (e.getPropertyName().equals("M_LocatorTo_ID")) if (e.getPropertyName().equals("M_LocatorTo_ID"))
@ -439,7 +484,7 @@ public class VOrderDistribution extends CPanel
for (int i = 0; i < rows; i++) for (int i = 0; i < rows; i++)
{ {
IDColumn id = (IDColumn)miniTable.getValueAt(i, 0); // ID in column 0 IDColumn id = (IDColumn)miniTable.getValueAt(i, 0); // ID in column 0
// log.fine( "Row=" + i + " - " + id); // log.fine( "Row=" + i + " - " + id);
if (id != null && id.isSelected()) if (id != null && id.isSelected())
results.add(id.getRecord_ID()); results.add(id.getRecord_ID());
} }
@ -448,10 +493,10 @@ public class VOrderDistribution extends CPanel
return; return;
log.config("Selected #" + results.size()); log.config("Selected #" + results.size());
selection = results; selection = results;
} // saveSelection } // saveSelection
/************************************************************************** /**************************************************************************
* Generate Shipments * Generate Shipments
*/ */
@ -463,7 +508,7 @@ public class VOrderDistribution extends CPanel
Trx trx = Trx.get(trxName, true); //trx needs to be committed too Trx trx = Trx.get(trxName, true); //trx needs to be committed too
//String trxName = null; //String trxName = null;
//Trx trx = null; //Trx trx = null;
m_selectionActive = false; // prevents from being called twice m_selectionActive = false; // prevents from being called twice
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "M_Movement_ID")); statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "M_Movement_ID"));
statusBar.setStatusDB(String.valueOf(selection.size())); statusBar.setStatusDB(String.valueOf(selection.size()));
@ -471,14 +516,14 @@ public class VOrderDistribution extends CPanel
// Prepare Process // Prepare Process
int AD_Process_ID = MProcess.getProcess_ID("M_Generate Movement", trxName); int AD_Process_ID = MProcess.getProcess_ID("M_Generate Movement", trxName);
KeyNamePair docTypeKNPair = (KeyNamePair)cmbDocType.getSelectedItem(); KeyNamePair docTypeKNPair = (KeyNamePair)cmbDocType.getSelectedItem();
MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0); MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
if (!instance.save()) if (!instance.save())
{ {
info.setText(Msg.getMsg(Env.getCtx(), "ProcessNoInstance")); info.setText(Msg.getMsg(Env.getCtx(), "ProcessNoInstance"));
return; return;
} }
//insert selection //insert selection
StringBuffer insert = new StringBuffer(); StringBuffer insert = new StringBuffer();
insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) "); insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
@ -493,7 +538,7 @@ public class VOrderDistribution extends CPanel
insert.append(", "); insert.append(", ");
insert.append(selectedId); insert.append(selectedId);
insert.append(" FROM DUAL "); insert.append(" FROM DUAL ");
if (counter == 1000) if (counter == 1000)
{ {
if ( DB.executeUpdate(insert.toString(), trxName) < 0 ) if ( DB.executeUpdate(insert.toString(), trxName) < 0 )
@ -520,7 +565,7 @@ public class VOrderDistribution extends CPanel
return; return;
} }
} }
//call process //call process
ProcessInfo pi = new ProcessInfo ("VOrderDistribution", AD_Process_ID); ProcessInfo pi = new ProcessInfo ("VOrderDistribution", AD_Process_ID);
pi.setAD_PInstance_ID (instance.getAD_PInstance_ID()); pi.setAD_PInstance_ID (instance.getAD_PInstance_ID());
@ -566,15 +611,15 @@ public class VOrderDistribution extends CPanel
ProcessInfoUtil.setLogFromDB(pi); ProcessInfoUtil.setLogFromDB(pi);
StringBuffer iText = new StringBuffer(); StringBuffer iText = new StringBuffer();
iText.append("<b>").append(pi.getSummary()) iText.append("<b>").append(pi.getSummary())
.append("</b><br>(") .append("</b><br>(")
.append(Msg.getMsg(Env.getCtx(), "InOutGenerateInfo")) .append(Msg.getMsg(Env.getCtx(), "InOutGenerateInfo"))
// Shipments are generated depending on the Delivery Rule selection in the Order // Shipments are generated depending on the Delivery Rule selection in the Order
.append(")<br>") .append(")<br>")
.append(pi.getLogInfo(true)); .append(pi.getLogInfo(true));
info.setText(iText.toString()); info.setText(iText.toString());
// Reset Selection // Reset Selection
//String sql = "UPDATE DD_Order SET IsSelected='N' WHERE " + m_whereClause; //String sql = "UPDATE DD_Order SET IsSelected='N' WHERE " + m_whereClause;
//int no = DB.executeUpdate(sql, null); //int no = DB.executeUpdate(sql, null);
//log.config("Reset=" + no); //log.config("Reset=" + no);
@ -589,7 +634,7 @@ public class VOrderDistribution extends CPanel
// OK to print shipments // OK to print shipments
if (ADialog.ask(m_WindowNo, this, "PrintShipments")) if (ADialog.ask(m_WindowNo, this, "PrintShipments"))
{ {
// info.append("\n\n" + Msg.getMsg(Env.getCtx(), "PrintShipments")); // info.append("\n\n" + Msg.getMsg(Env.getCtx(), "PrintShipments"));
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
int retValue = ADialogDialog.A_CANCEL; // see also ProcessDialog.printShipments/Invoices int retValue = ADialogDialog.A_CANCEL; // see also ProcessDialog.printShipments/Invoices
do do
@ -598,20 +643,20 @@ public class VOrderDistribution extends CPanel
for (int i = 0; i < ids.length; i++) for (int i = 0; i < ids.length; i++)
{ {
int M_Movement_ID = ids[i]; int M_Movement_ID = ids[i];
MPrintFormat format = MPrintFormat.get(Env.getCtx(), MPrintFormat.getPrintFormat_ID("Inventory Move Hdr (Example)", MMovement.Table_ID, 0), false); MPrintFormat format = MPrintFormat.get(Env.getCtx(), MPrintFormat.getPrintFormat_ID("Inventory Move Hdr (Example)", MMovement.Table_ID, 0), false);
MQuery query = new MQuery(MMovement.Table_Name); MQuery query = new MQuery(MMovement.Table_Name);
query.addRestriction(MMovement.COLUMNNAME_M_Movement_ID, MQuery.EQUAL, M_Movement_ID); query.addRestriction(MMovement.COLUMNNAME_M_Movement_ID, MQuery.EQUAL, M_Movement_ID);
// Engine // Engine
PrintInfo info = new PrintInfo(MMovement.Table_Name,MMovement.Table_ID, M_Movement_ID); PrintInfo info = new PrintInfo(MMovement.Table_Name,MMovement.Table_ID, M_Movement_ID);
ReportEngine re = new ReportEngine(Env.getCtx(), format, query, info); ReportEngine re = new ReportEngine(Env.getCtx(), format, query, info);
re.print(); re.print();
new Viewer(re); new Viewer(re);
} }
ADialogDialog d = new ADialogDialog (m_frame, ADialogDialog d = new ADialogDialog (m_frame,
Env.getHeader(Env.getCtx(), m_WindowNo), Env.getHeader(Env.getCtx(), m_WindowNo),
Msg.getMsg(Env.getCtx(), "PrintoutOK?"), Msg.getMsg(Env.getCtx(), "PrintoutOK?"),
JOptionPane.QUESTION_MESSAGE); JOptionPane.QUESTION_MESSAGE);
retValue = d.getReturnCode(); retValue = d.getReturnCode();
} }
while (retValue == ADialogDialog.A_CANCEL); while (retValue == ADialogDialog.A_CANCEL);
@ -622,7 +667,7 @@ public class VOrderDistribution extends CPanel
confirmPanelGen.getOKButton().setEnabled(true); confirmPanelGen.getOKButton().setEnabled(true);
} // generateShipments_complete } // generateShipments_complete
/************************************************************************** /**************************************************************************
* Lock User Interface. * Lock User Interface.
* Called from the Worker before processing * Called from the Worker before processing