Refactor custom form - ID: 2787613
This commit is contained in:
parent
a15e6a2718
commit
2c902cc459
|
@ -0,0 +1,16 @@
|
|||
package org.compiere.apps;
|
||||
|
||||
import org.compiere.model.DataStatusEvent;
|
||||
|
||||
public interface IStatusBar
|
||||
{
|
||||
public void setStatusDB (String text);
|
||||
|
||||
public void setStatusDB (String text, DataStatusEvent dse);
|
||||
|
||||
public void setStatusLine (String text);
|
||||
|
||||
public void setStatusLine (String text, boolean error);
|
||||
|
||||
public void setInfo (String text);
|
||||
}
|
|
@ -38,7 +38,7 @@ import org.compiere.util.Msg;
|
|||
* @author Jorg Janke
|
||||
* @version $Id: StatusBar.java,v 1.2 2006/07/30 00:51:27 jjanke Exp $
|
||||
*/
|
||||
public class StatusBar extends CPanel
|
||||
public class StatusBar extends CPanel implements IStatusBar
|
||||
{
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
/******************************************************************************
|
||||
* Copyright (C) 2009 Low Heng Sin *
|
||||
* Copyright (C) 2009 Idalica Corporation *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
*****************************************************************************/
|
||||
package org.compiere.apps.form;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.compiere.minigrid.IMiniTable;
|
||||
import org.compiere.process.ProcessInfo;
|
||||
import org.compiere.util.Trx;
|
||||
|
||||
/**
|
||||
* Generate custom form base class
|
||||
*
|
||||
*/
|
||||
public abstract class GenForm
|
||||
{
|
||||
private boolean m_selectionActive = true;
|
||||
private String title;
|
||||
private int reportEngineType;
|
||||
|
||||
private Trx trx;
|
||||
private ProcessInfo pi;
|
||||
|
||||
/** User selection */
|
||||
private ArrayList<Integer> selection = null;
|
||||
|
||||
public void dynInit() throws Exception
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public abstract void configureMiniTable(IMiniTable miniTable);
|
||||
|
||||
public abstract void saveSelection(IMiniTable miniTable);
|
||||
|
||||
public void validate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public String generate()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void executeQuery()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Trx getTrx() {
|
||||
return trx;
|
||||
}
|
||||
|
||||
public void setTrx(Trx trx) {
|
||||
this.trx = trx;
|
||||
}
|
||||
|
||||
public ProcessInfo getProcessInfo() {
|
||||
return pi;
|
||||
}
|
||||
|
||||
public void setProcessInfo(ProcessInfo pi) {
|
||||
this.pi = pi;
|
||||
}
|
||||
|
||||
public boolean isSelectionActive() {
|
||||
return m_selectionActive;
|
||||
}
|
||||
|
||||
public void setSelectionActive(boolean active) {
|
||||
m_selectionActive = active;
|
||||
}
|
||||
|
||||
public ArrayList<Integer> getSelection() {
|
||||
return selection;
|
||||
}
|
||||
|
||||
public void setSelection(ArrayList<Integer> selection) {
|
||||
this.selection = selection;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public int getReportEngineType() {
|
||||
return reportEngineType;
|
||||
}
|
||||
|
||||
public void setReportEngineType(int reportEngineType) {
|
||||
this.reportEngineType = reportEngineType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by org.adempiere.webui.panel.ADForm.openForm(int)
|
||||
* @return
|
||||
*/
|
||||
public Object getForm()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,356 @@
|
|||
/******************************************************************************
|
||||
* Copyright (C) 2009 Low Heng Sin *
|
||||
* Copyright (C) 2009 Idalica Corporation *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
*****************************************************************************/
|
||||
package org.compiere.apps.form;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
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 org.compiere.apps.IStatusBar;
|
||||
import org.compiere.minigrid.IDColumn;
|
||||
import org.compiere.minigrid.IMiniTable;
|
||||
import org.compiere.model.MOrder;
|
||||
import org.compiere.model.MPInstance;
|
||||
import org.compiere.model.MPInstancePara;
|
||||
import org.compiere.model.MPrivateAccess;
|
||||
import org.compiere.model.MRMA;
|
||||
import org.compiere.process.ProcessInfo;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.KeyNamePair;
|
||||
import org.compiere.util.Msg;
|
||||
import org.compiere.util.Trx;
|
||||
|
||||
/**
|
||||
* Generate Shipment (manual) controller class
|
||||
*
|
||||
*/
|
||||
public class InOutGen extends GenForm
|
||||
{
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(InOutGen.class);
|
||||
//
|
||||
|
||||
public Object m_M_Warehouse_ID = null;
|
||||
public Object m_C_BPartner_ID = null;
|
||||
|
||||
public void configureMiniTable(IMiniTable miniTable)
|
||||
{
|
||||
// create Columns
|
||||
miniTable.addColumn("C_Order_ID");
|
||||
miniTable.addColumn("AD_Org_ID");
|
||||
miniTable.addColumn("C_DocType_ID");
|
||||
miniTable.addColumn("DocumentNo");
|
||||
miniTable.addColumn("C_BPartner_ID");
|
||||
miniTable.addColumn("DateOrdered");
|
||||
miniTable.addColumn("TotalLines");
|
||||
//
|
||||
miniTable.setMultiSelection(true);
|
||||
|
||||
// set details
|
||||
miniTable.setColumnClass(0, IDColumn.class, false, " ");
|
||||
miniTable.setColumnClass(1, String.class, true, Msg.translate(Env.getCtx(), "AD_Org_ID"));
|
||||
miniTable.setColumnClass(2, String.class, true, Msg.translate(Env.getCtx(), "C_DocType_ID"));
|
||||
miniTable.setColumnClass(3, String.class, true, Msg.translate(Env.getCtx(), "DocumentNo"));
|
||||
miniTable.setColumnClass(4, String.class, true, Msg.translate(Env.getCtx(), "C_BPartner_ID"));
|
||||
miniTable.setColumnClass(5, Timestamp.class, true, Msg.translate(Env.getCtx(), "DateOrdered"));
|
||||
miniTable.setColumnClass(6, BigDecimal.class, true, Msg.translate(Env.getCtx(), "TotalLines"));
|
||||
//
|
||||
miniTable.autoSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SQL for Orders that needs to be shipped
|
||||
* @return sql
|
||||
*/
|
||||
private String getOrderSQL()
|
||||
{
|
||||
// Create SQL
|
||||
StringBuffer sql = new StringBuffer(
|
||||
"SELECT C_Order_ID, o.Name, dt.Name, DocumentNo, bp.Name, DateOrdered, TotalLines "
|
||||
+ "FROM M_InOut_Candidate_v ic, AD_Org o, C_BPartner bp, C_DocType dt "
|
||||
+ "WHERE ic.AD_Org_ID=o.AD_Org_ID"
|
||||
+ " AND ic.C_BPartner_ID=bp.C_BPartner_ID"
|
||||
+ " AND ic.C_DocType_ID=dt.C_DocType_ID"
|
||||
+ " AND ic.AD_Client_ID=?");
|
||||
|
||||
if (m_M_Warehouse_ID != null)
|
||||
sql.append(" AND ic.M_Warehouse_ID=").append(m_M_Warehouse_ID);
|
||||
if (m_C_BPartner_ID != null)
|
||||
sql.append(" AND ic.C_BPartner_ID=").append(m_C_BPartner_ID);
|
||||
|
||||
// bug - [ 1713317 ] Generate Shipments (manual) show locked records
|
||||
/* begin - Exclude locked records; @Trifon */
|
||||
int AD_User_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID");
|
||||
String lockedIDs = MPrivateAccess.getLockedRecordWhere(MOrder.Table_ID, AD_User_ID);
|
||||
if (lockedIDs != null)
|
||||
{
|
||||
if (sql.length() > 0)
|
||||
sql.append(" AND ");
|
||||
sql.append("C_Order_ID").append(lockedIDs);
|
||||
}
|
||||
/* eng - Exclude locked records; @Trifon */
|
||||
|
||||
//
|
||||
sql.append(" ORDER BY o.Name,bp.Name,DateOrdered");
|
||||
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SQL for Vendor RMA that need to be shipped
|
||||
* @return sql
|
||||
*/
|
||||
private String getRMASql()
|
||||
{
|
||||
StringBuffer sql = new StringBuffer();
|
||||
|
||||
sql.append("SELECT rma.M_RMA_ID, org.Name, dt.Name, rma.DocumentNo, bp.Name, rma.Created, rma.Amt ");
|
||||
sql.append("FROM M_RMA rma INNER JOIN AD_Org org ON rma.AD_Org_ID=org.AD_Org_ID ");
|
||||
sql.append("INNER JOIN C_DocType dt ON rma.C_DocType_ID=dt.C_DocType_ID ");
|
||||
sql.append("INNER JOIN C_BPartner bp ON rma.C_BPartner_ID=bp.C_BPartner_ID ");
|
||||
sql.append("INNER JOIN M_InOut io ON rma.InOut_ID=io.M_InOut_ID ");
|
||||
sql.append("WHERE rma.DocStatus='CO' ");
|
||||
sql.append("AND dt.DocBaseType = 'POO' ");
|
||||
sql.append("AND EXISTS (SELECT * FROM M_RMA r INNER JOIN M_RMALine rl ");
|
||||
sql.append("ON r.M_RMA_ID=rl.M_RMA_ID WHERE r.M_RMA_ID=rma.M_RMA_ID ");
|
||||
sql.append("AND rl.IsActive='Y' AND rl.M_InOutLine_ID > 0 AND rl.QtyDelivered < rl.Qty) ");
|
||||
sql.append("AND NOT EXISTS (SELECT * FROM M_InOut oio WHERE oio.M_RMA_ID=rma.M_RMA_ID ");
|
||||
sql.append("AND oio.DocStatus IN ('IP', 'CO', 'CL')) " );
|
||||
sql.append("AND rma.AD_Client_ID=?");
|
||||
|
||||
if (m_M_Warehouse_ID != null)
|
||||
sql.append(" AND io.M_Warehouse_ID=").append(m_M_Warehouse_ID);
|
||||
if (m_C_BPartner_ID != null)
|
||||
sql.append(" AND bp.C_BPartner_ID=").append(m_C_BPartner_ID);
|
||||
|
||||
int AD_User_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID");
|
||||
String lockedIDs = MPrivateAccess.getLockedRecordWhere(MRMA.Table_ID, AD_User_ID);
|
||||
if (lockedIDs != null)
|
||||
{
|
||||
sql.append(" AND rma.M_RMA_ID").append(lockedIDs);
|
||||
}
|
||||
|
||||
sql.append(" ORDER BY org.Name, bp.Name, rma.Created ");
|
||||
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Query Info
|
||||
*/
|
||||
public void executeQuery(KeyNamePair docTypeKNPair, IMiniTable miniTable)
|
||||
{
|
||||
log.info("");
|
||||
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
|
||||
|
||||
String sql = "";
|
||||
|
||||
if (docTypeKNPair.getKey() == MRMA.Table_ID)
|
||||
{
|
||||
sql = getRMASql();
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = getOrderSQL();
|
||||
}
|
||||
|
||||
log.fine(sql);
|
||||
// reset table
|
||||
int row = 0;
|
||||
miniTable.setRowCount(row);
|
||||
// Execute
|
||||
try
|
||||
{
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
|
||||
pstmt.setInt(1, AD_Client_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
//
|
||||
while (rs.next())
|
||||
{
|
||||
// extend table
|
||||
miniTable.setRowCount(row+1);
|
||||
// set values
|
||||
miniTable.setValueAt(new IDColumn(rs.getInt(1)), row, 0); // C_Order_ID
|
||||
miniTable.setValueAt(rs.getString(2), row, 1); // Org
|
||||
miniTable.setValueAt(rs.getString(3), row, 2); // DocType
|
||||
miniTable.setValueAt(rs.getString(4), row, 3); // Doc No
|
||||
miniTable.setValueAt(rs.getString(5), row, 4); // BPartner
|
||||
miniTable.setValueAt(rs.getTimestamp(6), row, 5); // DateOrdered
|
||||
miniTable.setValueAt(rs.getBigDecimal(7), row, 6); // TotalLines
|
||||
// prepare next
|
||||
row++;
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, sql.toString(), e);
|
||||
}
|
||||
//
|
||||
miniTable.autoSize();
|
||||
// statusBar.setStatusDB(String.valueOf(miniTable.getRowCount()));
|
||||
} // executeQuery
|
||||
|
||||
/**
|
||||
* Save Selection & return selecion Query or ""
|
||||
* @return where clause like C_Order_ID IN (...)
|
||||
*/
|
||||
public void saveSelection(IMiniTable miniTable)
|
||||
{
|
||||
log.info("");
|
||||
// Array of Integers
|
||||
ArrayList<Integer> results = new ArrayList<Integer>();
|
||||
setSelection(null);
|
||||
|
||||
// Get selected entries
|
||||
int rows = miniTable.getRowCount();
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
IDColumn id = (IDColumn)miniTable.getValueAt(i, 0); // ID in column 0
|
||||
// log.fine( "Row=" + i + " - " + id);
|
||||
if (id != null && id.isSelected())
|
||||
results.add(id.getRecord_ID());
|
||||
}
|
||||
|
||||
if (results.size() == 0)
|
||||
return;
|
||||
log.config("Selected #" + results.size());
|
||||
setSelection(results);
|
||||
} // saveSelection
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Generate Shipments
|
||||
*/
|
||||
public String generate(IStatusBar statusBar, KeyNamePair docTypeKNPair, String docActionSelected)
|
||||
{
|
||||
String info = "";
|
||||
log.info("M_Warehouse_ID=" + m_M_Warehouse_ID);
|
||||
String trxName = Trx.createTrxName("IOG");
|
||||
Trx trx = Trx.get(trxName, true); //trx needs to be committed too
|
||||
|
||||
setSelectionActive(false); // prevents from being called twice
|
||||
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateGen"));
|
||||
statusBar.setStatusDB(String.valueOf(getSelection().size()));
|
||||
|
||||
// Prepare Process
|
||||
int AD_Process_ID = 0;
|
||||
|
||||
if (docTypeKNPair.getKey() == MRMA.Table_ID)
|
||||
{
|
||||
AD_Process_ID = 52001; // M_InOut_GenerateRMA - org.adempiere.process.InOutGenerateRMA
|
||||
}
|
||||
else
|
||||
{
|
||||
AD_Process_ID = 199; // M_InOut_Generate - org.compiere.process.InOutGenerate
|
||||
}
|
||||
|
||||
MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
|
||||
if (!instance.save())
|
||||
{
|
||||
info = Msg.getMsg(Env.getCtx(), "ProcessNoInstance");
|
||||
return info;
|
||||
}
|
||||
|
||||
//insert selection
|
||||
StringBuffer insert = new StringBuffer();
|
||||
insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
|
||||
int counter = 0;
|
||||
for(Integer selectedId : getSelection())
|
||||
{
|
||||
counter++;
|
||||
if (counter > 1)
|
||||
insert.append(" UNION ");
|
||||
insert.append("SELECT ");
|
||||
insert.append(instance.getAD_PInstance_ID());
|
||||
insert.append(", ");
|
||||
insert.append(selectedId);
|
||||
insert.append(" FROM DUAL ");
|
||||
|
||||
if (counter == 1000)
|
||||
{
|
||||
if ( DB.executeUpdate(insert.toString(), trxName) < 0 )
|
||||
{
|
||||
String msg = "No Shipments"; // not translated!
|
||||
log.config(msg);
|
||||
info = msg;
|
||||
trx.rollback();
|
||||
return info;
|
||||
}
|
||||
insert = new StringBuffer();
|
||||
insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
|
||||
counter = 0;
|
||||
}
|
||||
}
|
||||
if (counter > 0)
|
||||
{
|
||||
if ( DB.executeUpdate(insert.toString(), trxName) < 0 )
|
||||
{
|
||||
String msg = "No Shipments"; // not translated!
|
||||
log.config(msg);
|
||||
info = msg;
|
||||
trx.rollback();
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
//call process
|
||||
ProcessInfo pi = new ProcessInfo ("VInOutGen", AD_Process_ID);
|
||||
pi.setAD_PInstance_ID (instance.getAD_PInstance_ID());
|
||||
|
||||
// Add Parameter - Selection=Y
|
||||
MPInstancePara ip = new MPInstancePara(instance, 10);
|
||||
ip.setParameter("Selection","Y");
|
||||
if (!ip.save())
|
||||
{
|
||||
String msg = "No Parameter added"; // not translated
|
||||
info = msg;
|
||||
log.log(Level.SEVERE, msg);
|
||||
return info;
|
||||
}
|
||||
//Add Document action parameter
|
||||
ip = new MPInstancePara(instance, 20);
|
||||
// String docActionSelected = (String)docAction.getValue();
|
||||
ip.setParameter("DocAction", docActionSelected);
|
||||
if(!ip.save())
|
||||
{
|
||||
String msg = "No DocACtion Parameter added";
|
||||
info = msg;
|
||||
log.log(Level.SEVERE, msg);
|
||||
return info;
|
||||
}
|
||||
// Add Parameter - M_Warehouse_ID=x
|
||||
ip = new MPInstancePara(instance, 30);
|
||||
ip.setParameter("M_Warehouse_ID", Integer.parseInt(m_M_Warehouse_ID.toString()));
|
||||
if(!ip.save())
|
||||
{
|
||||
String msg = "No Parameter added"; // not translated
|
||||
info = msg;
|
||||
log.log(Level.SEVERE, msg);
|
||||
return info;
|
||||
}
|
||||
|
||||
setTrx(trx);
|
||||
setProcessInfo(pi);
|
||||
|
||||
return info;
|
||||
} // generateShipments
|
||||
}
|
|
@ -0,0 +1,355 @@
|
|||
/******************************************************************************
|
||||
* Copyright (C) 2009 Low Heng Sin *
|
||||
* Copyright (C) 2009 Idalica Corporation *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
*****************************************************************************/
|
||||
package org.compiere.apps.form;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
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.compiere.apps.ADialog;
|
||||
import org.compiere.apps.ADialogDialog;
|
||||
import org.compiere.apps.ConfirmPanel;
|
||||
import org.compiere.apps.ProcessCtl;
|
||||
import org.compiere.apps.StatusBar;
|
||||
import org.compiere.minigrid.IDColumn;
|
||||
import org.compiere.minigrid.MiniTable;
|
||||
import org.compiere.plaf.CompiereColor;
|
||||
import org.compiere.print.ReportCtl;
|
||||
import org.compiere.process.ProcessInfo;
|
||||
import org.compiere.process.ProcessInfoUtil;
|
||||
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.Env;
|
||||
import org.compiere.util.Msg;
|
||||
|
||||
/**
|
||||
* Generate custom form panel
|
||||
*
|
||||
*/
|
||||
public class VGenPanel extends CPanel implements ActionListener, ChangeListener, TableModelListener, ASyncProcess
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private GenForm genForm;
|
||||
|
||||
/** Window No */
|
||||
private int m_WindowNo = 0;
|
||||
/** FormFrame */
|
||||
private FormFrame m_frame;
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(VInOutGen.class);
|
||||
//
|
||||
|
||||
private CTabbedPane tabbedPane = new CTabbedPane();
|
||||
private CPanel selPanel = new CPanel();
|
||||
private CPanel selNorthPanel = new CPanel();
|
||||
private BorderLayout selPanelLayout = new BorderLayout();
|
||||
|
||||
private FlowLayout northPanelLayout = new FlowLayout();
|
||||
private ConfirmPanel confirmPanelSel = new ConfirmPanel(true);
|
||||
private ConfirmPanel confirmPanelGen = new ConfirmPanel(false, true, false, false, false, false, true);
|
||||
private StatusBar statusBar = new StatusBar();
|
||||
private CPanel genPanel = new CPanel();
|
||||
private BorderLayout genLayout = new BorderLayout();
|
||||
private CTextPane info = new CTextPane();
|
||||
private JScrollPane scrollPane = new JScrollPane();
|
||||
private MiniTable miniTable = new MiniTable();
|
||||
|
||||
public VGenPanel(GenForm genForm, int WindowNo, FormFrame frame)
|
||||
{
|
||||
log.info("");
|
||||
this.genForm = genForm;
|
||||
m_WindowNo = WindowNo;
|
||||
m_frame = frame;
|
||||
|
||||
try
|
||||
{
|
||||
jbInit();
|
||||
dynInit();
|
||||
frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
|
||||
frame.getContentPane().add(statusBar, BorderLayout.SOUTH);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
log.log(Level.SEVERE, "init", ex);
|
||||
}
|
||||
} // init
|
||||
|
||||
/**
|
||||
* Static Init.
|
||||
* <pre>
|
||||
* selPanel (tabbed)
|
||||
* fOrg, fBPartner
|
||||
* scrollPane & miniTable
|
||||
* genPanel
|
||||
* info
|
||||
* </pre>
|
||||
* @throws Exception
|
||||
*/
|
||||
void jbInit() throws Exception
|
||||
{
|
||||
CompiereColor.setBackground(this);
|
||||
//
|
||||
selPanel.setLayout(selPanelLayout);
|
||||
|
||||
selNorthPanel.setLayout(northPanelLayout);
|
||||
northPanelLayout.setAlignment(FlowLayout.LEFT);
|
||||
tabbedPane.add(selPanel, Msg.getMsg(Env.getCtx(), "Select"));
|
||||
selPanel.add(selNorthPanel, BorderLayout.NORTH);
|
||||
selPanel.setName("selPanel");
|
||||
selPanel.add(confirmPanelSel, BorderLayout.SOUTH);
|
||||
selPanel.add(scrollPane, BorderLayout.CENTER);
|
||||
scrollPane.getViewport().add(miniTable, null);
|
||||
confirmPanelSel.addActionListener(this);
|
||||
//
|
||||
tabbedPane.add(genPanel, Msg.getMsg(Env.getCtx(), "Generate"));
|
||||
genPanel.setLayout(genLayout);
|
||||
genPanel.add(info, BorderLayout.CENTER);
|
||||
genPanel.setEnabled(false);
|
||||
info.setBackground(AdempierePLAF.getFieldBackground_Inactive());
|
||||
info.setEditable(false);
|
||||
genPanel.add(confirmPanelGen, BorderLayout.SOUTH);
|
||||
confirmPanelGen.addActionListener(this);
|
||||
} // jbInit
|
||||
|
||||
/**
|
||||
* Dynamic Init.
|
||||
* - Create GridController & Panel
|
||||
* - AD_Column_ID from C_Order
|
||||
*/
|
||||
private void dynInit()
|
||||
{
|
||||
genForm.configureMiniTable(miniTable);
|
||||
|
||||
miniTable.setRowSelectionAllowed(true);
|
||||
|
||||
miniTable.getModel().addTableModelListener(this);
|
||||
// Info
|
||||
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateSel"));//@@
|
||||
statusBar.setStatusDB(" ");
|
||||
// Tabbed Pane Listener
|
||||
tabbedPane.addChangeListener(this);
|
||||
} // dynInit
|
||||
|
||||
/**
|
||||
* Dispose
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
if (m_frame != null)
|
||||
m_frame.dispose();
|
||||
m_frame = null;
|
||||
} // dispose
|
||||
|
||||
/**
|
||||
* Action Listener
|
||||
* @param e event
|
||||
*/
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
log.info("Cmd=" + e.getActionCommand());
|
||||
//
|
||||
if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
|
||||
{
|
||||
dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
genForm.validate();
|
||||
} // actionPerformed
|
||||
|
||||
/**
|
||||
* Change Listener (Tab changed)
|
||||
* @param e event
|
||||
*/
|
||||
public void stateChanged (ChangeEvent e)
|
||||
{
|
||||
int index = tabbedPane.getSelectedIndex();
|
||||
genForm.setSelectionActive(index == 0);
|
||||
} // stateChanged
|
||||
|
||||
/**
|
||||
* Table Model Listener
|
||||
* @param e event
|
||||
*/
|
||||
public void tableChanged(TableModelEvent e)
|
||||
{
|
||||
int rowsSelected = 0;
|
||||
int rows = miniTable.getRowCount();
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
IDColumn id = (IDColumn)miniTable.getValueAt(i, 0); // ID in column 0
|
||||
if (id != null && id.isSelected())
|
||||
rowsSelected++;
|
||||
}
|
||||
statusBar.setStatusDB(" " + rowsSelected + " ");
|
||||
} // tableChanged
|
||||
|
||||
/**
|
||||
* Save Selection & return selecion Query or ""
|
||||
* @return where clause like C_Order_ID IN (...)
|
||||
*/
|
||||
public void saveSelection()
|
||||
{
|
||||
// ID selection may be pending
|
||||
miniTable.editingStopped(new ChangeEvent(this));
|
||||
genForm.saveSelection(miniTable);
|
||||
} // saveSelection
|
||||
|
||||
/**************************************************************************
|
||||
* Generate Shipments/Invoices
|
||||
*/
|
||||
public void generate()
|
||||
{
|
||||
info.setText(genForm.generate());
|
||||
|
||||
// Execute Process
|
||||
ProcessCtl worker = new ProcessCtl(this, Env.getWindowNo(this), genForm.getProcessInfo(), genForm.getTrx());
|
||||
worker.start();
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete generating shipments/invoices.
|
||||
* Called from Unlock UI
|
||||
* @param pi process info
|
||||
*/
|
||||
public void generateComplete(ProcessInfo pi)
|
||||
{
|
||||
// Switch Tabs
|
||||
tabbedPane.setSelectedIndex(1);
|
||||
//
|
||||
ProcessInfoUtil.setLogFromDB(pi);
|
||||
StringBuffer iText = new StringBuffer();
|
||||
iText.append("<b>").append(pi.getSummary())
|
||||
.append("</b><br>(")
|
||||
.append(Msg.getMsg(Env.getCtx(), genForm.getTitle()))
|
||||
// Shipments are generated depending on the Delivery Rule selection in the Order
|
||||
.append(")<br>")
|
||||
.append(pi.getLogInfo(true));
|
||||
info.setText(iText.toString());
|
||||
|
||||
// Reset Selection
|
||||
/*
|
||||
String sql = "UPDATE C_Order SET IsSelected='N' WHERE " + m_whereClause;
|
||||
int no = DB.executeUpdate(sql, null);
|
||||
log.config("Reset=" + no);*/
|
||||
|
||||
// Get results
|
||||
int[] ids = pi.getIDs();
|
||||
if (ids == null || ids.length == 0)
|
||||
return;
|
||||
log.config("PrintItems=" + ids.length);
|
||||
|
||||
confirmPanelGen.getOKButton().setEnabled(false);
|
||||
// OK to print shipments
|
||||
if (ADialog.ask(m_WindowNo, this, "PrintShipments"))
|
||||
{
|
||||
// info.append("\n\n" + Msg.getMsg(Env.getCtx(), "PrintShipments"));
|
||||
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
int retValue = ADialogDialog.A_CANCEL; // see also ProcessDialog.printShipments/Invoices
|
||||
do
|
||||
{
|
||||
// Loop through all items
|
||||
for (int i = 0; i < ids.length; i++)
|
||||
{
|
||||
int Record_ID = ids[i];
|
||||
ReportCtl.startDocumentPrint(genForm.getReportEngineType(), Record_ID, this, Env.getWindowNo(this), true);
|
||||
}
|
||||
ADialogDialog d = new ADialogDialog (m_frame,
|
||||
Env.getHeader(Env.getCtx(), m_WindowNo),
|
||||
Msg.getMsg(Env.getCtx(), "PrintoutOK?"),
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
retValue = d.getReturnCode();
|
||||
}
|
||||
while (retValue == ADialogDialog.A_CANCEL);
|
||||
this.setCursor(Cursor.getDefaultCursor());
|
||||
} // OK to print shipments
|
||||
|
||||
//
|
||||
confirmPanelGen.getOKButton().setEnabled(true);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* Lock User Interface.
|
||||
* Called from the Worker before processing
|
||||
* @param pi process info
|
||||
*/
|
||||
public void lockUI (ProcessInfo pi)
|
||||
{
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
setEnabled(false);
|
||||
} // lockUI
|
||||
|
||||
/**
|
||||
* Unlock User Interface.
|
||||
* Called from the Worker when processing is done
|
||||
* @param pi result of execute ASync call
|
||||
*/
|
||||
public void unlockUI (ProcessInfo pi)
|
||||
{
|
||||
setEnabled(true);
|
||||
setCursor(Cursor.getDefaultCursor());
|
||||
//
|
||||
generateComplete(pi);
|
||||
} // unlockUI
|
||||
|
||||
/**
|
||||
* Is the UI locked (Internal method)
|
||||
* @return true, if UI is locked
|
||||
*/
|
||||
public boolean isUILocked()
|
||||
{
|
||||
return isEnabled();
|
||||
} // isUILocked
|
||||
|
||||
/**
|
||||
* Method to be executed async.
|
||||
* Called from the Worker
|
||||
* @param pi ProcessInfo
|
||||
*/
|
||||
public void executeASync (ProcessInfo pi)
|
||||
{
|
||||
} // executeASync
|
||||
|
||||
public CPanel getParameterPanel()
|
||||
{
|
||||
return selNorthPanel;
|
||||
}
|
||||
|
||||
public MiniTable getMiniTable()
|
||||
{
|
||||
return miniTable;
|
||||
}
|
||||
|
||||
public StatusBar getStatusBar()
|
||||
{
|
||||
return statusBar;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* Copyright (C) 2009 Low Heng Sin *
|
||||
* Copyright (C) 2009 Idalica Corporation *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
|
@ -10,83 +10,55 @@
|
|||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
*****************************************************************************/
|
||||
package org.compiere.apps.form;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.VetoableChangeListener;
|
||||
import java.math.BigDecimal;
|
||||
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.compiere.apps.ADialog;
|
||||
import org.compiere.apps.ADialogDialog;
|
||||
import org.compiere.apps.ConfirmPanel;
|
||||
import org.compiere.apps.ProcessCtl;
|
||||
import org.compiere.apps.StatusBar;
|
||||
import org.compiere.grid.ed.VComboBox;
|
||||
import org.compiere.grid.ed.VLookup;
|
||||
import org.compiere.minigrid.IDColumn;
|
||||
import org.compiere.minigrid.MiniTable;
|
||||
import org.compiere.model.MLookup;
|
||||
import org.compiere.model.MLookupFactory;
|
||||
import org.compiere.model.MOrder;
|
||||
import org.compiere.model.MPInstance;
|
||||
import org.compiere.model.MPInstancePara;
|
||||
import org.compiere.model.MPrivateAccess;
|
||||
import org.compiere.model.MRMA;
|
||||
import org.compiere.plaf.CompiereColor;
|
||||
import org.compiere.print.ReportCtl;
|
||||
import org.compiere.print.ReportEngine;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Manual Shipment Selection
|
||||
* Generate Shipment (manual) view class
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: VInOutGen.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
|
||||
*/
|
||||
public class VInOutGen extends CPanel
|
||||
implements FormPanel, ActionListener, VetoableChangeListener,
|
||||
ChangeListener, TableModelListener, ASyncProcess
|
||||
public class VInOutGen extends InOutGen implements FormPanel, ActionListener, VetoableChangeListener
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -8529925342013824806L;
|
||||
private VGenPanel panel;
|
||||
|
||||
/** Window No */
|
||||
private int m_WindowNo = 0;
|
||||
/** FormFrame */
|
||||
private FormFrame m_frame;
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(VInOutGen.class);
|
||||
//
|
||||
|
||||
private CLabel lWarehouse = new CLabel();
|
||||
private VLookup fWarehouse;
|
||||
private CLabel lBPartner = new CLabel();
|
||||
private VLookup fBPartner;
|
||||
private CLabel lDocType = new CLabel();
|
||||
private VComboBox cmbDocType = new VComboBox();
|
||||
private CLabel lDocAction = new CLabel();
|
||||
private VLookup docAction;
|
||||
|
||||
/**
|
||||
* Initialize Panel
|
||||
|
@ -99,13 +71,13 @@ public class VInOutGen extends CPanel
|
|||
m_WindowNo = WindowNo;
|
||||
m_frame = frame;
|
||||
Env.setContext(Env.getCtx(), m_WindowNo, "IsSOTrx", "Y");
|
||||
|
||||
panel = new VGenPanel(this, WindowNo, frame);
|
||||
|
||||
try
|
||||
{
|
||||
fillPicks();
|
||||
jbInit();
|
||||
dynInit();
|
||||
frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
|
||||
frame.getContentPane().add(statusBar, BorderLayout.SOUTH);
|
||||
jbInit();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
|
@ -113,42 +85,15 @@ public class VInOutGen extends CPanel
|
|||
}
|
||||
} // init
|
||||
|
||||
/** Window No */
|
||||
private int m_WindowNo = 0;
|
||||
/** FormFrame */
|
||||
private FormFrame m_frame;
|
||||
|
||||
private boolean m_selectionActive = true;
|
||||
private Object m_M_Warehouse_ID = null;
|
||||
private Object m_C_BPartner_ID = null;
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(VInOutGen.class);
|
||||
//
|
||||
private CTabbedPane tabbedPane = new CTabbedPane();
|
||||
private CPanel selPanel = new CPanel();
|
||||
private CPanel selNorthPanel = new CPanel();
|
||||
private BorderLayout selPanelLayout = new BorderLayout();
|
||||
private CLabel lWarehouse = new CLabel();
|
||||
private VLookup fWarehouse;
|
||||
private CLabel lBPartner = new CLabel();
|
||||
private VLookup fBPartner;
|
||||
private FlowLayout northPanelLayout = new FlowLayout();
|
||||
private ConfirmPanel confirmPanelSel = new ConfirmPanel(true);
|
||||
private ConfirmPanel confirmPanelGen = new ConfirmPanel(false, true, false, false, false, false, true);
|
||||
private StatusBar statusBar = new StatusBar();
|
||||
private CPanel genPanel = new CPanel();
|
||||
private BorderLayout genLayout = new BorderLayout();
|
||||
private CTextPane info = new CTextPane();
|
||||
private JScrollPane scrollPane = new JScrollPane();
|
||||
private MiniTable miniTable = new MiniTable();
|
||||
|
||||
private CLabel lDocType = new CLabel();
|
||||
private VComboBox cmbDocType = new VComboBox();
|
||||
private CLabel lDocAction = new CLabel();
|
||||
private VLookup docAction;
|
||||
|
||||
/** User selection */
|
||||
private ArrayList<Integer> selection = null;
|
||||
/**
|
||||
* Dispose
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
if (m_frame != null)
|
||||
m_frame.dispose();
|
||||
m_frame = null;
|
||||
} // dispose
|
||||
|
||||
/**
|
||||
* Static Init.
|
||||
|
@ -163,42 +108,24 @@ public class VInOutGen extends CPanel
|
|||
*/
|
||||
void jbInit() throws Exception
|
||||
{
|
||||
CompiereColor.setBackground(this);
|
||||
//
|
||||
selPanel.setLayout(selPanelLayout);
|
||||
setTitle("InOutGenerateInfo");
|
||||
setReportEngineType(ReportEngine.SHIPMENT);
|
||||
|
||||
lWarehouse.setLabelFor(fWarehouse);
|
||||
lBPartner.setLabelFor(fBPartner);
|
||||
lBPartner.setText(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
|
||||
lDocAction.setLabelFor(docAction);
|
||||
lDocAction.setText(Msg.translate(Env.getCtx(), "DocAction"));
|
||||
selNorthPanel.setLayout(northPanelLayout);
|
||||
northPanelLayout.setAlignment(FlowLayout.LEFT);
|
||||
tabbedPane.add(selPanel, Msg.getMsg(Env.getCtx(), "Select"));
|
||||
selPanel.add(selNorthPanel, BorderLayout.NORTH);
|
||||
selNorthPanel.add(lWarehouse, null);
|
||||
selNorthPanel.add(fWarehouse, null);
|
||||
selNorthPanel.add(lBPartner, null);
|
||||
selNorthPanel.add(fBPartner, null);
|
||||
selPanel.setName("selPanel");
|
||||
selPanel.add(confirmPanelSel, BorderLayout.SOUTH);
|
||||
selPanel.add(scrollPane, BorderLayout.CENTER);
|
||||
scrollPane.getViewport().add(miniTable, null);
|
||||
confirmPanelSel.addActionListener(this);
|
||||
//
|
||||
tabbedPane.add(genPanel, Msg.getMsg(Env.getCtx(), "Generate"));
|
||||
genPanel.setLayout(genLayout);
|
||||
genPanel.add(info, BorderLayout.CENTER);
|
||||
genPanel.setEnabled(false);
|
||||
info.setBackground(AdempierePLAF.getFieldBackground_Inactive());
|
||||
info.setEditable(false);
|
||||
genPanel.add(confirmPanelGen, BorderLayout.SOUTH);
|
||||
confirmPanelGen.addActionListener(this);
|
||||
|
||||
lDocType.setLabelFor(cmbDocType);
|
||||
selNorthPanel.add(lDocType, null);
|
||||
selNorthPanel.add(cmbDocType, null);
|
||||
selNorthPanel.add(lDocAction, null);
|
||||
selNorthPanel.add(docAction, null);
|
||||
|
||||
panel.getParameterPanel().add(lWarehouse, null);
|
||||
panel.getParameterPanel().add(fWarehouse, null);
|
||||
panel.getParameterPanel().add(lBPartner, null);
|
||||
panel.getParameterPanel().add(fBPartner, null);
|
||||
panel.getParameterPanel().add(lDocType, null);
|
||||
panel.getParameterPanel().add(cmbDocType, null);
|
||||
panel.getParameterPanel().add(lDocAction, null);
|
||||
panel.getParameterPanel().add(docAction, null);
|
||||
} // jbInit
|
||||
|
||||
/**
|
||||
|
@ -206,7 +133,7 @@ public class VInOutGen extends CPanel
|
|||
* Column_ID from C_Order
|
||||
* @throws Exception if Lookups cannot be initialized
|
||||
*/
|
||||
private void fillPicks() throws Exception
|
||||
public void dynInit() throws Exception
|
||||
{
|
||||
// C_OrderLine.M_Warehouse_ID
|
||||
MLookup orgL = MLookupFactory.get (Env.getCtx(), m_WindowNo, 0, 2223, DisplayType.TableDir);
|
||||
|
@ -232,216 +159,40 @@ public class VInOutGen extends CPanel
|
|||
cmbDocType.addActionListener(this);
|
||||
} // fillPicks
|
||||
|
||||
/**
|
||||
* Dynamic Init.
|
||||
* - Create GridController & Panel
|
||||
* - AD_Column_ID from C_Order
|
||||
*/
|
||||
private void dynInit()
|
||||
public void executeQuery()
|
||||
{
|
||||
// create Columns
|
||||
miniTable.addColumn("C_Order_ID");
|
||||
miniTable.addColumn("AD_Org_ID");
|
||||
miniTable.addColumn("C_DocType_ID");
|
||||
miniTable.addColumn("DocumentNo");
|
||||
miniTable.addColumn("C_BPartner_ID");
|
||||
miniTable.addColumn("DateOrdered");
|
||||
miniTable.addColumn("TotalLines");
|
||||
//
|
||||
miniTable.setMultiSelection(true);
|
||||
miniTable.setRowSelectionAllowed(true);
|
||||
// set details
|
||||
miniTable.setColumnClass(0, IDColumn.class, false, " ");
|
||||
miniTable.setColumnClass(1, String.class, true, Msg.translate(Env.getCtx(), "AD_Org_ID"));
|
||||
miniTable.setColumnClass(2, String.class, true, Msg.translate(Env.getCtx(), "C_DocType_ID"));
|
||||
miniTable.setColumnClass(3, String.class, true, Msg.translate(Env.getCtx(), "DocumentNo"));
|
||||
miniTable.setColumnClass(4, String.class, true, Msg.translate(Env.getCtx(), "C_BPartner_ID"));
|
||||
miniTable.setColumnClass(5, Timestamp.class, true, Msg.translate(Env.getCtx(), "DateOrdered"));
|
||||
miniTable.setColumnClass(6, BigDecimal.class, true, Msg.translate(Env.getCtx(), "TotalLines"));
|
||||
//
|
||||
miniTable.autoSize();
|
||||
miniTable.getModel().addTableModelListener(this);
|
||||
// Info
|
||||
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateSel"));//@@
|
||||
statusBar.setStatusDB(" ");
|
||||
// Tabbed Pane Listener
|
||||
tabbedPane.addChangeListener(this);
|
||||
} // dynInit
|
||||
|
||||
/**
|
||||
* Get SQL for Orders that needs to be shipped
|
||||
* @return sql
|
||||
*/
|
||||
private String getOrderSQL()
|
||||
{
|
||||
// Create SQL
|
||||
StringBuffer sql = new StringBuffer(
|
||||
"SELECT C_Order_ID, o.Name, dt.Name, DocumentNo, bp.Name, DateOrdered, TotalLines "
|
||||
+ "FROM M_InOut_Candidate_v ic, AD_Org o, C_BPartner bp, C_DocType dt "
|
||||
+ "WHERE ic.AD_Org_ID=o.AD_Org_ID"
|
||||
+ " AND ic.C_BPartner_ID=bp.C_BPartner_ID"
|
||||
+ " AND ic.C_DocType_ID=dt.C_DocType_ID"
|
||||
+ " AND ic.AD_Client_ID=?");
|
||||
|
||||
if (m_M_Warehouse_ID != null)
|
||||
sql.append(" AND ic.M_Warehouse_ID=").append(m_M_Warehouse_ID);
|
||||
if (m_C_BPartner_ID != null)
|
||||
sql.append(" AND ic.C_BPartner_ID=").append(m_C_BPartner_ID);
|
||||
|
||||
// bug - [ 1713317 ] Generate Shipments (manual) show locked records
|
||||
/* begin - Exclude locked records; @Trifon */
|
||||
int AD_User_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID");
|
||||
String lockedIDs = MPrivateAccess.getLockedRecordWhere(MOrder.Table_ID, AD_User_ID);
|
||||
if (lockedIDs != null)
|
||||
{
|
||||
if (sql.length() > 0)
|
||||
sql.append(" AND ");
|
||||
sql.append("C_Order_ID").append(lockedIDs);
|
||||
}
|
||||
/* eng - Exclude locked records; @Trifon */
|
||||
|
||||
//
|
||||
sql.append(" ORDER BY o.Name,bp.Name,DateOrdered");
|
||||
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SQL for Vendor RMA that need to be shipped
|
||||
* @return sql
|
||||
*/
|
||||
private String getRMASql()
|
||||
{
|
||||
StringBuffer sql = new StringBuffer();
|
||||
|
||||
sql.append("SELECT rma.M_RMA_ID, org.Name, dt.Name, rma.DocumentNo, bp.Name, rma.Created, rma.Amt ");
|
||||
sql.append("FROM M_RMA rma INNER JOIN AD_Org org ON rma.AD_Org_ID=org.AD_Org_ID ");
|
||||
sql.append("INNER JOIN C_DocType dt ON rma.C_DocType_ID=dt.C_DocType_ID ");
|
||||
sql.append("INNER JOIN C_BPartner bp ON rma.C_BPartner_ID=bp.C_BPartner_ID ");
|
||||
sql.append("INNER JOIN M_InOut io ON rma.InOut_ID=io.M_InOut_ID ");
|
||||
sql.append("WHERE rma.DocStatus='CO' ");
|
||||
sql.append("AND dt.DocBaseType = 'POO' ");
|
||||
sql.append("AND EXISTS (SELECT * FROM M_RMA r INNER JOIN M_RMALine rl ");
|
||||
sql.append("ON r.M_RMA_ID=rl.M_RMA_ID WHERE r.M_RMA_ID=rma.M_RMA_ID ");
|
||||
sql.append("AND rl.IsActive='Y' AND rl.M_InOutLine_ID > 0 AND rl.QtyDelivered < rl.Qty) ");
|
||||
sql.append("AND NOT EXISTS (SELECT * FROM M_InOut oio WHERE oio.M_RMA_ID=rma.M_RMA_ID ");
|
||||
sql.append("AND oio.DocStatus IN ('IP', 'CO', 'CL')) " );
|
||||
sql.append("AND rma.AD_Client_ID=?");
|
||||
|
||||
if (m_M_Warehouse_ID != null)
|
||||
sql.append(" AND io.M_Warehouse_ID=").append(m_M_Warehouse_ID);
|
||||
if (m_C_BPartner_ID != null)
|
||||
sql.append(" AND bp.C_BPartner_ID=").append(m_C_BPartner_ID);
|
||||
|
||||
int AD_User_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID");
|
||||
String lockedIDs = MPrivateAccess.getLockedRecordWhere(MRMA.Table_ID, AD_User_ID);
|
||||
if (lockedIDs != null)
|
||||
{
|
||||
sql.append(" AND rma.M_RMA_ID").append(lockedIDs);
|
||||
}
|
||||
|
||||
sql.append(" ORDER BY org.Name, bp.Name, rma.Created ");
|
||||
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Query Info
|
||||
*/
|
||||
private void executeQuery()
|
||||
{
|
||||
log.info("");
|
||||
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
|
||||
|
||||
String sql = "";
|
||||
|
||||
KeyNamePair docTypeKNPair = (KeyNamePair)cmbDocType.getSelectedItem();
|
||||
|
||||
if (docTypeKNPair.getKey() == MRMA.Table_ID)
|
||||
{
|
||||
sql = getRMASql();
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = getOrderSQL();
|
||||
}
|
||||
|
||||
log.fine(sql);
|
||||
// reset table
|
||||
int row = 0;
|
||||
miniTable.setRowCount(row);
|
||||
// Execute
|
||||
try
|
||||
{
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
|
||||
pstmt.setInt(1, AD_Client_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
//
|
||||
while (rs.next())
|
||||
{
|
||||
// extend table
|
||||
miniTable.setRowCount(row+1);
|
||||
// set values
|
||||
miniTable.setValueAt(new IDColumn(rs.getInt(1)), row, 0); // C_Order_ID
|
||||
miniTable.setValueAt(rs.getString(2), row, 1); // Org
|
||||
miniTable.setValueAt(rs.getString(3), row, 2); // DocType
|
||||
miniTable.setValueAt(rs.getString(4), row, 3); // Doc No
|
||||
miniTable.setValueAt(rs.getString(5), row, 4); // BPartner
|
||||
miniTable.setValueAt(rs.getTimestamp(6), row, 5); // DateOrdered
|
||||
miniTable.setValueAt(rs.getBigDecimal(7), row, 6); // TotalLines
|
||||
// prepare next
|
||||
row++;
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, sql.toString(), e);
|
||||
}
|
||||
//
|
||||
miniTable.autoSize();
|
||||
// statusBar.setStatusDB(String.valueOf(miniTable.getRowCount()));
|
||||
executeQuery(docTypeKNPair, panel.getMiniTable());
|
||||
} // executeQuery
|
||||
|
||||
/**
|
||||
* Dispose
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
if (m_frame != null)
|
||||
m_frame.dispose();
|
||||
m_frame = null;
|
||||
} // dispose
|
||||
|
||||
/**
|
||||
* Action Listener
|
||||
* @param e event
|
||||
*/
|
||||
public void actionPerformed (ActionEvent e)
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
log.info("Cmd=" + e.getActionCommand());
|
||||
//
|
||||
if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
|
||||
{
|
||||
dispose();
|
||||
return;
|
||||
}
|
||||
if (cmbDocType.equals(e.getSource()))
|
||||
{
|
||||
executeQuery();
|
||||
executeQuery();
|
||||
return;
|
||||
}
|
||||
//
|
||||
saveSelection();
|
||||
|
||||
validate();
|
||||
} // actionPerformed
|
||||
|
||||
public void validate()
|
||||
{
|
||||
panel.saveSelection();
|
||||
|
||||
ArrayList<Integer> selection = getSelection();
|
||||
if (selection != null
|
||||
&& selection.size() > 0
|
||||
&& m_selectionActive // on selection tab
|
||||
&& isSelectionActive() // on selection tab
|
||||
&& m_M_Warehouse_ID != null)
|
||||
generateShipments ();
|
||||
panel.generate();
|
||||
else
|
||||
dispose();
|
||||
} // actionPerformed
|
||||
panel.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Vetoable Change Listener - requery
|
||||
|
@ -460,285 +211,13 @@ public class VInOutGen extends CPanel
|
|||
executeQuery();
|
||||
} // vetoableChange
|
||||
|
||||
/**
|
||||
* Change Listener (Tab changed)
|
||||
* @param e event
|
||||
*/
|
||||
public void stateChanged (ChangeEvent e)
|
||||
{
|
||||
int index = tabbedPane.getSelectedIndex();
|
||||
m_selectionActive = (index == 0);
|
||||
} // stateChanged
|
||||
|
||||
/**
|
||||
* Table Model Listener
|
||||
* @param e event
|
||||
*/
|
||||
public void tableChanged(TableModelEvent e)
|
||||
{
|
||||
int rowsSelected = 0;
|
||||
int rows = miniTable.getRowCount();
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
IDColumn id = (IDColumn)miniTable.getValueAt(i, 0); // ID in column 0
|
||||
if (id != null && id.isSelected())
|
||||
rowsSelected++;
|
||||
}
|
||||
statusBar.setStatusDB(" " + rowsSelected + " ");
|
||||
} // tableChanged
|
||||
|
||||
/**
|
||||
* Save Selection & return selecion Query or ""
|
||||
* @return where clause like C_Order_ID IN (...)
|
||||
*/
|
||||
private void saveSelection()
|
||||
{
|
||||
log.info("");
|
||||
// ID selection may be pending
|
||||
miniTable.editingStopped(new ChangeEvent(this));
|
||||
// Array of Integers
|
||||
ArrayList<Integer> results = new ArrayList<Integer>();
|
||||
selection = null;
|
||||
|
||||
// Get selected entries
|
||||
int rows = miniTable.getRowCount();
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
IDColumn id = (IDColumn)miniTable.getValueAt(i, 0); // ID in column 0
|
||||
// log.fine( "Row=" + i + " - " + id);
|
||||
if (id != null && id.isSelected())
|
||||
results.add(id.getRecord_ID());
|
||||
}
|
||||
|
||||
if (results.size() == 0)
|
||||
return;
|
||||
log.config("Selected #" + results.size());
|
||||
selection = results;
|
||||
|
||||
} // saveSelection
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Generate Shipments
|
||||
*/
|
||||
private void generateShipments ()
|
||||
public String generate()
|
||||
{
|
||||
log.info("M_Warehouse_ID=" + m_M_Warehouse_ID);
|
||||
String trxName = Trx.createTrxName("IOG");
|
||||
Trx trx = Trx.get(trxName, true); //trx needs to be committed too
|
||||
//String trxName = null;
|
||||
//Trx trx = null;
|
||||
|
||||
m_selectionActive = false; // prevents from being called twice
|
||||
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateGen"));
|
||||
statusBar.setStatusDB(String.valueOf(selection.size()));
|
||||
|
||||
// Prepare Process
|
||||
int AD_Process_ID = 0;
|
||||
KeyNamePair docTypeKNPair = (KeyNamePair)cmbDocType.getSelectedItem();
|
||||
|
||||
if (docTypeKNPair.getKey() == MRMA.Table_ID)
|
||||
{
|
||||
AD_Process_ID = 52001; // M_InOut_GenerateRMA - org.adempiere.process.InOutGenerateRMA
|
||||
}
|
||||
else
|
||||
{
|
||||
AD_Process_ID = 199; // M_InOut_Generate - org.compiere.process.InOutGenerate
|
||||
}
|
||||
|
||||
MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
|
||||
if (!instance.save())
|
||||
{
|
||||
info.setText(Msg.getMsg(Env.getCtx(), "ProcessNoInstance"));
|
||||
return;
|
||||
}
|
||||
|
||||
//insert selection
|
||||
StringBuffer insert = new StringBuffer();
|
||||
insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
|
||||
int counter = 0;
|
||||
for(Integer selectedId : selection)
|
||||
{
|
||||
counter++;
|
||||
if (counter > 1)
|
||||
insert.append(" UNION ");
|
||||
insert.append("SELECT ");
|
||||
insert.append(instance.getAD_PInstance_ID());
|
||||
insert.append(", ");
|
||||
insert.append(selectedId);
|
||||
insert.append(" FROM DUAL ");
|
||||
|
||||
if (counter == 1000)
|
||||
{
|
||||
if ( DB.executeUpdate(insert.toString(), trxName) < 0 )
|
||||
{
|
||||
String msg = "No Shipments"; // not translated!
|
||||
log.config(msg);
|
||||
info.setText(msg);
|
||||
trx.rollback();
|
||||
return;
|
||||
}
|
||||
insert = new StringBuffer();
|
||||
insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
|
||||
counter = 0;
|
||||
}
|
||||
}
|
||||
if (counter > 0)
|
||||
{
|
||||
if ( DB.executeUpdate(insert.toString(), trxName) < 0 )
|
||||
{
|
||||
String msg = "No Shipments"; // not translated!
|
||||
log.config(msg);
|
||||
info.setText(msg);
|
||||
trx.rollback();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//call process
|
||||
ProcessInfo pi = new ProcessInfo ("VInOutGen", AD_Process_ID);
|
||||
pi.setAD_PInstance_ID (instance.getAD_PInstance_ID());
|
||||
|
||||
// Add Parameter - Selection=Y
|
||||
MPInstancePara ip = new MPInstancePara(instance, 10);
|
||||
ip.setParameter("Selection","Y");
|
||||
if (!ip.save())
|
||||
{
|
||||
String msg = "No Parameter added"; // not translated
|
||||
info.setText(msg);
|
||||
log.log(Level.SEVERE, msg);
|
||||
return;
|
||||
}
|
||||
//Add Document action parameter
|
||||
ip = new MPInstancePara(instance, 20);
|
||||
String docActionSelected = (String)docAction.getValue();
|
||||
ip.setParameter("DocAction", docActionSelected);
|
||||
if(!ip.save())
|
||||
{
|
||||
String msg = "No DocACtion Parameter added";
|
||||
info.setText(msg);
|
||||
log.log(Level.SEVERE, msg);
|
||||
return;
|
||||
}
|
||||
// Add Parameter - M_Warehouse_ID=x
|
||||
ip = new MPInstancePara(instance, 30);
|
||||
ip.setParameter("M_Warehouse_ID", Integer.parseInt(m_M_Warehouse_ID.toString()));
|
||||
if(!ip.save())
|
||||
{
|
||||
String msg = "No Parameter added"; // not translated
|
||||
info.setText(msg);
|
||||
log.log(Level.SEVERE, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
// Execute Process
|
||||
ProcessCtl worker = new ProcessCtl(this, Env.getWindowNo(this), pi, trx);
|
||||
worker.start(); // complete tasks in unlockUI / generateShipments_complete
|
||||
//
|
||||
return generate(panel.getStatusBar(), docTypeKNPair, docActionSelected);
|
||||
} // generateShipments
|
||||
|
||||
/**
|
||||
* Complete generating shipments.
|
||||
* Called from Unlock UI
|
||||
* @param pi process info
|
||||
*/
|
||||
private void generateShipments_complete (ProcessInfo pi)
|
||||
{
|
||||
// Switch Tabs
|
||||
tabbedPane.setSelectedIndex(1);
|
||||
//
|
||||
ProcessInfoUtil.setLogFromDB(pi);
|
||||
StringBuffer iText = new StringBuffer();
|
||||
iText.append("<b>").append(pi.getSummary())
|
||||
.append("</b><br>(")
|
||||
.append(Msg.getMsg(Env.getCtx(), "InOutGenerateInfo"))
|
||||
// Shipments are generated depending on the Delivery Rule selection in the Order
|
||||
.append(")<br>")
|
||||
.append(pi.getLogInfo(true));
|
||||
info.setText(iText.toString());
|
||||
|
||||
// Reset Selection
|
||||
/*
|
||||
String sql = "UPDATE C_Order SET IsSelected='N' WHERE " + m_whereClause;
|
||||
int no = DB.executeUpdate(sql, null);
|
||||
log.config("Reset=" + no);*/
|
||||
|
||||
// Get results
|
||||
int[] ids = pi.getIDs();
|
||||
if (ids == null || ids.length == 0)
|
||||
return;
|
||||
log.config("PrintItems=" + ids.length);
|
||||
|
||||
confirmPanelGen.getOKButton().setEnabled(false);
|
||||
// OK to print shipments
|
||||
if (ADialog.ask(m_WindowNo, this, "PrintShipments"))
|
||||
{
|
||||
// info.append("\n\n" + Msg.getMsg(Env.getCtx(), "PrintShipments"));
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
int retValue = ADialogDialog.A_CANCEL; // see also ProcessDialog.printShipments/Invoices
|
||||
do
|
||||
{
|
||||
// Loop through all items
|
||||
for (int i = 0; i < ids.length; i++)
|
||||
{
|
||||
int M_InOut_ID = ids[i];
|
||||
ReportCtl.startDocumentPrint(ReportEngine.SHIPMENT, M_InOut_ID, this, Env.getWindowNo(this), true);
|
||||
}
|
||||
ADialogDialog d = new ADialogDialog (m_frame,
|
||||
Env.getHeader(Env.getCtx(), m_WindowNo),
|
||||
Msg.getMsg(Env.getCtx(), "PrintoutOK?"),
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
retValue = d.getReturnCode();
|
||||
}
|
||||
while (retValue == ADialogDialog.A_CANCEL);
|
||||
setCursor(Cursor.getDefaultCursor());
|
||||
} // OK to print shipments
|
||||
|
||||
//
|
||||
confirmPanelGen.getOKButton().setEnabled(true);
|
||||
} // generateShipments_complete
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Lock User Interface.
|
||||
* Called from the Worker before processing
|
||||
* @param pi process info
|
||||
*/
|
||||
public void lockUI (ProcessInfo pi)
|
||||
{
|
||||
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
this.setEnabled(false);
|
||||
} // lockUI
|
||||
|
||||
/**
|
||||
* Unlock User Interface.
|
||||
* Called from the Worker when processing is done
|
||||
* @param pi result of execute ASync call
|
||||
*/
|
||||
public void unlockUI (ProcessInfo pi)
|
||||
{
|
||||
this.setEnabled(true);
|
||||
this.setCursor(Cursor.getDefaultCursor());
|
||||
//
|
||||
generateShipments_complete(pi);
|
||||
} // unlockUI
|
||||
|
||||
/**
|
||||
* Is the UI locked (Internal method)
|
||||
* @return true, if UI is locked
|
||||
*/
|
||||
public boolean isUILocked()
|
||||
{
|
||||
return this.isEnabled();
|
||||
} // isUILocked
|
||||
|
||||
/**
|
||||
* Method to be executed async.
|
||||
* Called from the Worker
|
||||
* @param pi ProcessInfo
|
||||
*/
|
||||
public void executeASync (ProcessInfo pi)
|
||||
{
|
||||
} // executeASync
|
||||
|
||||
} // VInOutGen
|
||||
}
|
||||
|
|
|
@ -0,0 +1,428 @@
|
|||
/******************************************************************************
|
||||
* Copyright (C) 2009 Low Heng Sin *
|
||||
* Copyright (C) 2009 Idalica Corporation *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
*****************************************************************************/
|
||||
package org.adempiere.webui.apps.form;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EventListener;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.webui.LayoutUtils;
|
||||
import org.adempiere.webui.apps.AEnv;
|
||||
import org.adempiere.webui.component.ConfirmPanel;
|
||||
import org.adempiere.webui.component.DesktopTabpanel;
|
||||
import org.adempiere.webui.component.Grid;
|
||||
import org.adempiere.webui.component.GridFactory;
|
||||
import org.adempiere.webui.component.ListboxFactory;
|
||||
import org.adempiere.webui.component.Tab;
|
||||
import org.adempiere.webui.component.Tabbox;
|
||||
import org.adempiere.webui.component.Tabpanels;
|
||||
import org.adempiere.webui.component.Tabs;
|
||||
import org.adempiere.webui.component.WListbox;
|
||||
import org.adempiere.webui.component.Window;
|
||||
import org.adempiere.webui.event.WTableModelEvent;
|
||||
import org.adempiere.webui.event.WTableModelListener;
|
||||
import org.adempiere.webui.panel.ADForm;
|
||||
import org.adempiere.webui.panel.StatusBarPanel;
|
||||
import org.adempiere.webui.session.SessionManager;
|
||||
import org.adempiere.webui.window.FDialog;
|
||||
import org.adempiere.webui.window.SimplePDFViewer;
|
||||
import org.compiere.apps.ProcessCtl;
|
||||
import org.compiere.apps.form.GenForm;
|
||||
import org.compiere.minigrid.IDColumn;
|
||||
import org.compiere.print.ReportEngine;
|
||||
import org.compiere.process.ProcessInfoUtil;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
import org.zkoss.zk.au.out.AuEcho;
|
||||
import org.zkoss.zk.ui.DesktopUnavailableException;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.Events;
|
||||
import org.zkoss.zk.ui.util.Clients;
|
||||
import org.zkoss.zkex.zul.Borderlayout;
|
||||
import org.zkoss.zkex.zul.Center;
|
||||
import org.zkoss.zkex.zul.North;
|
||||
import org.zkoss.zkex.zul.South;
|
||||
import org.zkoss.zul.Div;
|
||||
import org.zkoss.zul.Html;
|
||||
|
||||
/**
|
||||
* Generate custom form window
|
||||
*
|
||||
*/
|
||||
public class WGenForm extends ADForm implements EventListener, WTableModelListener
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private GenForm genForm;
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(WGenForm.class);
|
||||
//
|
||||
private Tabbox tabbedPane = new Tabbox();
|
||||
private Borderlayout selPanel = new Borderlayout();
|
||||
private Grid selNorthPanel = GridFactory.newGridLayout();
|
||||
// private FlowLayout northPanelLayout = new FlowLayout();
|
||||
private ConfirmPanel confirmPanelSel = new ConfirmPanel(true);
|
||||
private ConfirmPanel confirmPanelGen = new ConfirmPanel(false, true, false, false, false, false, false);
|
||||
private StatusBarPanel statusBar = new StatusBarPanel();
|
||||
private Borderlayout genPanel = new Borderlayout();
|
||||
private Html info = new Html();
|
||||
// private JScrollPane scrollPane = new JScrollPane();
|
||||
private WListbox miniTable = ListboxFactory.newDataTable();
|
||||
|
||||
private int[] m_ids;
|
||||
|
||||
public WGenForm(GenForm genForm)
|
||||
{
|
||||
log.info("");
|
||||
this.genForm = genForm;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initForm()
|
||||
{
|
||||
try
|
||||
{
|
||||
zkInit();
|
||||
dynInit();
|
||||
Borderlayout contentPane = new Borderlayout();
|
||||
this.appendChild(contentPane);
|
||||
contentPane.setWidth("99%");
|
||||
contentPane.setHeight("100%");
|
||||
Center center = new Center();
|
||||
center.setStyle("border: none");
|
||||
contentPane.appendChild(center);
|
||||
center.appendChild(tabbedPane);
|
||||
center.setFlex(true);
|
||||
South south = new South();
|
||||
south.setStyle("border: none");
|
||||
contentPane.appendChild(south);
|
||||
south.appendChild(statusBar);
|
||||
LayoutUtils.addSclass("status-border", statusBar);
|
||||
south.setHeight("22px");
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
log.log(Level.SEVERE, "init", ex);
|
||||
}
|
||||
} // init
|
||||
|
||||
/**
|
||||
* Static Init.
|
||||
* <pre>
|
||||
* selPanel (tabbed)
|
||||
* fOrg, fBPartner
|
||||
* scrollPane & miniTable
|
||||
* genPanel
|
||||
* info
|
||||
* </pre>
|
||||
* @throws Exception
|
||||
*/
|
||||
void zkInit() throws Exception
|
||||
{
|
||||
//
|
||||
selPanel.setWidth("99%");
|
||||
selPanel.setHeight("90%");
|
||||
selPanel.setStyle("border: none; position: absolute");
|
||||
DesktopTabpanel tabpanel = new DesktopTabpanel();
|
||||
tabpanel.appendChild(selPanel);
|
||||
Tabpanels tabPanels = new Tabpanels();
|
||||
tabPanels.appendChild(tabpanel);
|
||||
tabbedPane.appendChild(tabPanels);
|
||||
Tabs tabs = new Tabs();
|
||||
tabbedPane.appendChild(tabs);
|
||||
Tab tab = new Tab(Msg.getMsg(Env.getCtx(), "Select"));
|
||||
tabs.appendChild(tab);
|
||||
|
||||
North north = new North();
|
||||
selPanel.appendChild(north);
|
||||
north.appendChild(selNorthPanel);
|
||||
|
||||
South south = new South();
|
||||
selPanel.appendChild(south);
|
||||
south.appendChild(confirmPanelSel);
|
||||
|
||||
Center center = new Center();
|
||||
selPanel.appendChild(center);
|
||||
center.appendChild(miniTable);
|
||||
center.setFlex(true);
|
||||
miniTable.setHeight("99%");
|
||||
confirmPanelSel.addActionListener(this);
|
||||
//
|
||||
tabpanel = new DesktopTabpanel();
|
||||
tabPanels.appendChild(tabpanel);
|
||||
tabpanel.appendChild(genPanel);
|
||||
tab = new Tab(Msg.getMsg(Env.getCtx(), "Generate"));
|
||||
tabs.appendChild(tab);
|
||||
genPanel.setWidth("99%");
|
||||
genPanel.setHeight("90%");
|
||||
genPanel.setStyle("border: none; position: absolute");
|
||||
center = new Center();
|
||||
genPanel.appendChild(center);
|
||||
Div div = new Div();
|
||||
div.appendChild(info);
|
||||
center.appendChild(div);
|
||||
south = new South();
|
||||
genPanel.appendChild(south);
|
||||
south.appendChild(confirmPanelGen);
|
||||
confirmPanelGen.addActionListener(this);
|
||||
} // jbInit
|
||||
|
||||
/**
|
||||
* Dynamic Init.
|
||||
* - Create GridController & Panel
|
||||
* - AD_Column_ID from C_Order
|
||||
*/
|
||||
public void dynInit()
|
||||
{
|
||||
genForm.configureMiniTable(miniTable);
|
||||
miniTable.getModel().addTableModelListener(this);
|
||||
// Info
|
||||
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateSel"));//@@
|
||||
statusBar.setStatusDB(" ");
|
||||
// Tabbed Pane Listener
|
||||
tabbedPane.addEventListener(Events.ON_SELECT, this);
|
||||
} // dynInit
|
||||
|
||||
public void postQueryEvent()
|
||||
{
|
||||
Clients.showBusy(Msg.getMsg(Env.getCtx(), "Processing"), true);
|
||||
Events.echoEvent("onExecuteQuery", this, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dont call this directly, use internally to handle execute query event
|
||||
*/
|
||||
public void onExecuteQuery()
|
||||
{
|
||||
try
|
||||
{
|
||||
genForm.executeQuery();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Clients.showBusy(null, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action Listener
|
||||
* @param e event
|
||||
*/
|
||||
public void onEvent(Event e)
|
||||
{
|
||||
log.info("Cmd=" + e.getTarget().getId());
|
||||
//
|
||||
if (e.getTarget().getId().equals(ConfirmPanel.A_CANCEL))
|
||||
{
|
||||
dispose();
|
||||
return;
|
||||
}
|
||||
else if (e.getTarget() instanceof Tab)
|
||||
{
|
||||
int index = tabbedPane.getSelectedIndex();
|
||||
genForm.setSelectionActive(index == 0);
|
||||
return;
|
||||
}
|
||||
|
||||
genForm.validate();
|
||||
} // actionPerformed
|
||||
|
||||
/**
|
||||
* Table Model Listener
|
||||
* @param e event
|
||||
*/
|
||||
public void tableChanged(WTableModelEvent e)
|
||||
{
|
||||
int rowsSelected = 0;
|
||||
int rows = miniTable.getRowCount();
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
IDColumn id = (IDColumn)miniTable.getValueAt(i, 0); // ID in column 0
|
||||
if (id != null && id.isSelected())
|
||||
rowsSelected++;
|
||||
}
|
||||
statusBar.setStatusDB(" " + rowsSelected + " ");
|
||||
} // tableChanged
|
||||
|
||||
/**
|
||||
* Save Selection & return selecion Query or ""
|
||||
* @return where clause like C_Order_ID IN (...)
|
||||
*/
|
||||
public void saveSelection()
|
||||
{
|
||||
genForm.saveSelection(miniTable);
|
||||
} // saveSelection
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Generate Shipments
|
||||
*/
|
||||
public void generate()
|
||||
{
|
||||
info.setContent(genForm.generate());
|
||||
|
||||
// Execute Process
|
||||
if (!getDesktop().isServerPushEnabled())
|
||||
getDesktop().enableServerPush(true);
|
||||
|
||||
this.lockUI();
|
||||
final ProcessCtl worker = new ProcessCtl(null, getWindowNo(), genForm.getProcessInfo(), genForm.getTrx());
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
//get full control of desktop
|
||||
org.zkoss.zk.ui.Desktop desktop = WGenForm.this.getDesktop();
|
||||
try {
|
||||
Executions.activate(desktop);
|
||||
try {
|
||||
worker.run(); // complete tasks in unlockUI / generateShipments_complete
|
||||
} finally{
|
||||
unlockUI();
|
||||
//release full control of desktop
|
||||
Executions.deactivate(desktop);
|
||||
}
|
||||
} catch (DesktopUnavailableException e) {
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
} catch (InterruptedException e) {
|
||||
log.log(Level.WARNING, e.getLocalizedMessage(), e);
|
||||
}
|
||||
}
|
||||
};
|
||||
new Thread(runnable).start();
|
||||
//
|
||||
} // generateShipments
|
||||
|
||||
/**
|
||||
* Complete generating shipments.
|
||||
* Called from Unlock UI
|
||||
* @param pi process info
|
||||
*/
|
||||
private void generateComplete ()
|
||||
{
|
||||
Clients.showBusy(null, false);
|
||||
|
||||
// Switch Tabs
|
||||
tabbedPane.setSelectedIndex(1);
|
||||
//
|
||||
ProcessInfoUtil.setLogFromDB(genForm.getProcessInfo());
|
||||
StringBuffer iText = new StringBuffer();
|
||||
iText.append("<b>").append(genForm.getProcessInfo().getSummary())
|
||||
.append("</b><br>(")
|
||||
.append(Msg.getMsg(Env.getCtx(), "InOutGenerateInfo"))
|
||||
// Shipments are generated depending on the Delivery Rule selection in the Order
|
||||
.append(")<br>")
|
||||
.append(genForm.getProcessInfo().getLogInfo(true));
|
||||
info.setContent(iText.toString());
|
||||
|
||||
// Get results
|
||||
int[] ids = genForm.getProcessInfo().getIDs();
|
||||
if (ids == null || ids.length == 0)
|
||||
return;
|
||||
log.config("PrintItems=" + ids.length);
|
||||
|
||||
m_ids = ids;
|
||||
Clients.response(new AuEcho(this, "onAfterProcess", null));
|
||||
|
||||
} // generateShipments_complete
|
||||
|
||||
|
||||
public void onAfterProcess()
|
||||
{
|
||||
// OK to print shipments
|
||||
if (FDialog.ask(getWindowNo(), this, "PrintShipments"))
|
||||
{
|
||||
// info.append("\n\n" + Msg.getMsg(Env.getCtx(), "PrintShipments"));
|
||||
Clients.showBusy("Processing...", true);
|
||||
Clients.response(new AuEcho(this, "onPrintShipments", null));
|
||||
} // OK to print shipments
|
||||
}
|
||||
|
||||
public void onPrintShipments()
|
||||
{
|
||||
// Loop through all items
|
||||
List<File> pdfList = new ArrayList<File>();
|
||||
for (int i = 0; i < m_ids.length; i++)
|
||||
{
|
||||
int M_InOut_ID = m_ids[i];
|
||||
ReportEngine re = ReportEngine.get (Env.getCtx(), ReportEngine.SHIPMENT, M_InOut_ID);
|
||||
pdfList.add(re.getPDF());
|
||||
}
|
||||
|
||||
if (pdfList.size() > 1) {
|
||||
try {
|
||||
File outFile = File.createTempFile("WInOutGen", ".pdf");
|
||||
AEnv.mergePdf(pdfList, outFile);
|
||||
|
||||
Clients.showBusy(null, false);
|
||||
Window win = new SimplePDFViewer(getFormName(), new FileInputStream(outFile));
|
||||
SessionManager.getAppDesktop().showWindow(win, "center");
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
}
|
||||
} else if (pdfList.size() > 0) {
|
||||
Clients.showBusy(null, false);
|
||||
try {
|
||||
Window win = new SimplePDFViewer(getFormName(), new FileInputStream(pdfList.get(0)));
|
||||
SessionManager.getAppDesktop().showWindow(win, "center");
|
||||
} catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* Lock User Interface.
|
||||
* Called from the Worker before processing
|
||||
* @param pi process info
|
||||
*/
|
||||
public void lockUI ()
|
||||
{
|
||||
Clients.showBusy("Processing...", true);
|
||||
} // lockUI
|
||||
|
||||
/**
|
||||
* Unlock User Interface.
|
||||
* Called from the Worker when processing is done
|
||||
* @param pi result of execute ASync call
|
||||
*/
|
||||
public void unlockUI ()
|
||||
{
|
||||
generateComplete();
|
||||
} // unlockUI
|
||||
|
||||
public void dispose() {
|
||||
SessionManager.getAppDesktop().closeActiveWindow();
|
||||
}
|
||||
|
||||
public Grid getParameterPanel()
|
||||
{
|
||||
return selNorthPanel;
|
||||
}
|
||||
|
||||
public WListbox getMiniTable()
|
||||
{
|
||||
return miniTable;
|
||||
}
|
||||
|
||||
public StatusBarPanel getStatusBar()
|
||||
{
|
||||
return statusBar;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* Copyright (C) 2009 Low Heng Sin *
|
||||
* Copyright (C) 2009 Idalica Corporation *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
|
@ -10,126 +10,69 @@
|
|||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
*****************************************************************************/
|
||||
package org.adempiere.webui.apps.form;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EventListener;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.webui.LayoutUtils;
|
||||
import org.adempiere.webui.apps.AEnv;
|
||||
import org.adempiere.webui.component.ConfirmPanel;
|
||||
import org.adempiere.webui.component.DesktopTabpanel;
|
||||
import org.adempiere.webui.component.Grid;
|
||||
import org.adempiere.webui.component.GridFactory;
|
||||
import org.adempiere.webui.component.Label;
|
||||
import org.adempiere.webui.component.Listbox;
|
||||
import org.adempiere.webui.component.ListboxFactory;
|
||||
import org.adempiere.webui.component.Row;
|
||||
import org.adempiere.webui.component.Tab;
|
||||
import org.adempiere.webui.component.Tabbox;
|
||||
import org.adempiere.webui.component.Tabpanels;
|
||||
import org.adempiere.webui.component.Tabs;
|
||||
import org.adempiere.webui.component.WListbox;
|
||||
import org.adempiere.webui.component.Window;
|
||||
import org.adempiere.webui.editor.WSearchEditor;
|
||||
import org.adempiere.webui.editor.WTableDirEditor;
|
||||
import org.adempiere.webui.event.ValueChangeEvent;
|
||||
import org.adempiere.webui.event.ValueChangeListener;
|
||||
import org.adempiere.webui.event.WTableModelEvent;
|
||||
import org.adempiere.webui.event.WTableModelListener;
|
||||
import org.adempiere.webui.panel.ADForm;
|
||||
import org.adempiere.webui.panel.StatusBarPanel;
|
||||
import org.adempiere.webui.session.SessionManager;
|
||||
import org.adempiere.webui.window.FDialog;
|
||||
import org.adempiere.webui.window.SimplePDFViewer;
|
||||
import org.compiere.apps.ProcessCtl;
|
||||
import org.compiere.minigrid.IDColumn;
|
||||
import org.compiere.apps.form.InOutGen;
|
||||
import org.compiere.model.MLookup;
|
||||
import org.compiere.model.MLookupFactory;
|
||||
import org.compiere.model.MOrder;
|
||||
import org.compiere.model.MPInstance;
|
||||
import org.compiere.model.MPInstancePara;
|
||||
import org.compiere.model.MPrivateAccess;
|
||||
import org.compiere.model.MRMA;
|
||||
import org.compiere.print.ReportEngine;
|
||||
import org.compiere.process.DocAction;
|
||||
import org.compiere.process.ProcessInfo;
|
||||
import org.compiere.process.ProcessInfoUtil;
|
||||
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.zkoss.zk.au.out.AuEcho;
|
||||
import org.zkoss.zk.ui.DesktopUnavailableException;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.Events;
|
||||
import org.zkoss.zk.ui.util.Clients;
|
||||
import org.zkoss.zkex.zul.Borderlayout;
|
||||
import org.zkoss.zkex.zul.Center;
|
||||
import org.zkoss.zkex.zul.North;
|
||||
import org.zkoss.zkex.zul.South;
|
||||
import org.zkoss.zul.Div;
|
||||
import org.zkoss.zul.Html;
|
||||
import org.zkoss.zul.Space;
|
||||
|
||||
/**
|
||||
* Manual Shipment Selection
|
||||
* Generate Shipment (manual) view class
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: VInOutGen.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
|
||||
*/
|
||||
public class WInOutGen extends ADForm implements EventListener, ValueChangeListener, WTableModelListener
|
||||
public class WInOutGen extends InOutGen implements EventListener, ValueChangeListener
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2522466013777853310L;
|
||||
private static WGenForm form;
|
||||
|
||||
@Override
|
||||
protected void initForm()
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(WInOutGen.class);
|
||||
//
|
||||
private Label lWarehouse = new Label();
|
||||
private WTableDirEditor fWarehouse;
|
||||
private Label lBPartner = new Label();
|
||||
private WSearchEditor fBPartner;
|
||||
private Label lDocType = new Label();
|
||||
private Listbox cmbDocType = ListboxFactory.newDropdownListbox();
|
||||
private Label lDocAction = new Label();
|
||||
private WTableDirEditor docAction;
|
||||
|
||||
public WInOutGen()
|
||||
{
|
||||
log.info("");
|
||||
Env.setContext(Env.getCtx(), m_WindowNo, "IsSOTrx", "Y");
|
||||
|
||||
form = new WGenForm(this);
|
||||
Env.setContext(Env.getCtx(), form.getWindowNo(), "IsSOTrx", "Y");
|
||||
|
||||
try
|
||||
{
|
||||
fillPicks();
|
||||
zkInit();
|
||||
dynInit();
|
||||
Borderlayout contentPane = new Borderlayout();
|
||||
this.appendChild(contentPane);
|
||||
contentPane.setWidth("99%");
|
||||
contentPane.setHeight("100%");
|
||||
Center center = new Center();
|
||||
center.setStyle("border: none");
|
||||
contentPane.appendChild(center);
|
||||
center.appendChild(tabbedPane);
|
||||
center.setFlex(true);
|
||||
South south = new South();
|
||||
south.setStyle("border: none");
|
||||
contentPane.appendChild(south);
|
||||
south.appendChild(statusBar);
|
||||
LayoutUtils.addSclass("status-border", statusBar);
|
||||
south.setHeight("22px");
|
||||
zkInit();
|
||||
|
||||
postQueryEvent();
|
||||
form.postQueryEvent();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
|
@ -137,38 +80,6 @@ public class WInOutGen extends ADForm implements EventListener, ValueChangeListe
|
|||
}
|
||||
} // init
|
||||
|
||||
private boolean m_selectionActive = true;
|
||||
private Object m_M_Warehouse_ID = null;
|
||||
private Object m_C_BPartner_ID = null;
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(WInOutGen.class);
|
||||
//
|
||||
private Tabbox tabbedPane = new Tabbox();
|
||||
private Borderlayout selPanel = new Borderlayout();
|
||||
private Grid selNorthPanel = GridFactory.newGridLayout();
|
||||
private Label lWarehouse = new Label();
|
||||
private WTableDirEditor fWarehouse;
|
||||
private Label lBPartner = new Label();
|
||||
private WSearchEditor fBPartner;
|
||||
// private FlowLayout northPanelLayout = new FlowLayout();
|
||||
private ConfirmPanel confirmPanelSel = new ConfirmPanel(true);
|
||||
private ConfirmPanel confirmPanelGen = new ConfirmPanel(false, true, false, false, false, false, false);
|
||||
private StatusBarPanel statusBar = new StatusBarPanel();
|
||||
private Borderlayout genPanel = new Borderlayout();
|
||||
private Html info = new Html();
|
||||
// private JScrollPane scrollPane = new JScrollPane();
|
||||
private WListbox miniTable = ListboxFactory.newDataTable();
|
||||
|
||||
private Label lDocType = new Label();
|
||||
private Listbox cmbDocType = ListboxFactory.newDropdownListbox();
|
||||
private Label lDocAction = new Label();
|
||||
private WTableDirEditor docAction;
|
||||
|
||||
/** User selection */
|
||||
private ArrayList<Integer> selection = null;
|
||||
private int[] m_ids;
|
||||
private ProcessInfo m_pi;
|
||||
|
||||
/**
|
||||
* Static Init.
|
||||
* <pre>
|
||||
|
@ -182,26 +93,9 @@ public class WInOutGen extends ADForm implements EventListener, ValueChangeListe
|
|||
*/
|
||||
void zkInit() throws Exception
|
||||
{
|
||||
//
|
||||
selPanel.setWidth("99%");
|
||||
selPanel.setHeight("90%");
|
||||
selPanel.setStyle("border: none; position: absolute");
|
||||
lBPartner.setText("BPartner");
|
||||
DesktopTabpanel tabpanel = new DesktopTabpanel();
|
||||
tabpanel.appendChild(selPanel);
|
||||
Tabpanels tabPanels = new Tabpanels();
|
||||
tabPanels.appendChild(tabpanel);
|
||||
tabbedPane.appendChild(tabPanels);
|
||||
Tabs tabs = new Tabs();
|
||||
tabbedPane.appendChild(tabs);
|
||||
Tab tab = new Tab(Msg.getMsg(Env.getCtx(), "Select"));
|
||||
tabs.appendChild(tab);
|
||||
tabbedPane.getTabpanels();
|
||||
|
||||
North north = new North();
|
||||
selPanel.appendChild(north);
|
||||
north.appendChild(selNorthPanel);
|
||||
Row row = selNorthPanel.newRows().newRow();
|
||||
Row row = form.getParameterPanel().newRows().newRow();
|
||||
row.appendChild(lWarehouse.rightAlign());
|
||||
row.appendChild(fWarehouse.getComponent());
|
||||
row.appendChild(new Space());
|
||||
|
@ -209,37 +103,8 @@ public class WInOutGen extends ADForm implements EventListener, ValueChangeListe
|
|||
row.appendChild(fBPartner.getComponent());
|
||||
row.appendChild(new Space());
|
||||
|
||||
South south = new South();
|
||||
selPanel.appendChild(south);
|
||||
south.appendChild(confirmPanelSel);
|
||||
|
||||
Center center = new Center();
|
||||
selPanel.appendChild(center);
|
||||
center.appendChild(miniTable);
|
||||
center.setFlex(true);
|
||||
miniTable.setHeight("99%");
|
||||
confirmPanelSel.addActionListener(this);
|
||||
//
|
||||
tabpanel = new DesktopTabpanel();
|
||||
tabPanels.appendChild(tabpanel);
|
||||
tabpanel.appendChild(genPanel);
|
||||
tab = new Tab(Msg.getMsg(Env.getCtx(), "Generate"));
|
||||
tabs.appendChild(tab);
|
||||
genPanel.setWidth("99%");
|
||||
genPanel.setHeight("90%");
|
||||
genPanel.setStyle("border: none; position: absolute");
|
||||
center = new Center();
|
||||
genPanel.appendChild(center);
|
||||
Div div = new Div();
|
||||
div.appendChild(info);
|
||||
center.appendChild(div);
|
||||
south = new South();
|
||||
genPanel.appendChild(south);
|
||||
south.appendChild(confirmPanelGen);
|
||||
confirmPanelGen.addActionListener(this);
|
||||
|
||||
row = new Row();
|
||||
selNorthPanel.getRows().appendChild(row);
|
||||
form.getParameterPanel().getRows().appendChild(row);
|
||||
row.appendChild(lDocType.rightAlign());
|
||||
row.appendChild(cmbDocType);
|
||||
row.appendChild(new Space());
|
||||
|
@ -253,10 +118,10 @@ public class WInOutGen extends ADForm implements EventListener, ValueChangeListe
|
|||
* Column_ID from C_Order
|
||||
* @throws Exception if Lookups cannot be initialized
|
||||
*/
|
||||
private void fillPicks() throws Exception
|
||||
public void dynInit() throws Exception
|
||||
{
|
||||
// C_OrderLine.M_Warehouse_ID
|
||||
MLookup orgL = MLookupFactory.get (Env.getCtx(), m_WindowNo, 0, 2223, DisplayType.TableDir);
|
||||
MLookup orgL = MLookupFactory.get (Env.getCtx(), form.getWindowNo(), 0, 2223, DisplayType.TableDir);
|
||||
fWarehouse = new WTableDirEditor ("M_Warehouse_ID", true, false, true, orgL);
|
||||
lWarehouse.setText(Msg.translate(Env.getCtx(), "M_Warehouse_ID"));
|
||||
fWarehouse.addValueChangeListener(this);
|
||||
|
@ -264,14 +129,14 @@ public class WInOutGen extends ADForm implements EventListener, ValueChangeListe
|
|||
m_M_Warehouse_ID = fWarehouse.getValue();
|
||||
// Document Action Prepared/ Completed
|
||||
lDocAction.setText(Msg.translate(Env.getCtx(), "DocAction"));
|
||||
MLookup docActionL = MLookupFactory.get(Env.getCtx(), m_WindowNo, 4324 /* M_InOut.DocAction */,
|
||||
MLookup docActionL = MLookupFactory.get(Env.getCtx(), form.getWindowNo(), 4324 /* M_InOut.DocAction */,
|
||||
DisplayType.List, Env.getLanguage(Env.getCtx()), "DocAction", 135 /* _Document Action */,
|
||||
false, "AD_Ref_List.Value IN ('CO','PR')");
|
||||
docAction = new WTableDirEditor("DocAction", true, false, true,docActionL);
|
||||
docAction.setValue(DocAction.ACTION_Complete);
|
||||
docAction.addValueChangeListener(this);
|
||||
// C_Order.C_BPartner_ID
|
||||
MLookup bpL = MLookupFactory.get (Env.getCtx(), m_WindowNo, 0, 2762, DisplayType.Search);
|
||||
MLookup bpL = MLookupFactory.get (Env.getCtx(), form.getWindowNo(), 0, 2762, DisplayType.Search);
|
||||
fBPartner = new WSearchEditor("C_BPartner_ID", false, false, true, bpL);
|
||||
lBPartner.setText(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
|
||||
fBPartner.addValueChangeListener(this);
|
||||
|
@ -279,202 +144,19 @@ public class WInOutGen extends ADForm implements EventListener, ValueChangeListe
|
|||
lDocType.setText(Msg.translate(Env.getCtx(), "C_DocType_ID"));
|
||||
cmbDocType.addItem(new KeyNamePair(MOrder.Table_ID, Msg.translate(Env.getCtx(), "Order")));
|
||||
cmbDocType.addItem(new KeyNamePair(MRMA.Table_ID, Msg.translate(Env.getCtx(), "VendorRMA")));
|
||||
cmbDocType.addActionListener(this);
|
||||
cmbDocType.addActionListener(form);
|
||||
cmbDocType.setSelectedIndex(0);
|
||||
} // fillPicks
|
||||
|
||||
/**
|
||||
* Dynamic Init.
|
||||
* - Create GridController & Panel
|
||||
* - AD_Column_ID from C_Order
|
||||
*/
|
||||
private void dynInit()
|
||||
{
|
||||
// create Columns
|
||||
miniTable.addColumn("C_Order_ID");
|
||||
miniTable.addColumn("AD_Org_ID");
|
||||
miniTable.addColumn("C_DocType_ID");
|
||||
miniTable.addColumn("DocumentNo");
|
||||
miniTable.addColumn("C_BPartner_ID");
|
||||
miniTable.addColumn("DateOrdered");
|
||||
miniTable.addColumn("TotalLines");
|
||||
//
|
||||
miniTable.setMultiSelection(true);
|
||||
// miniTable.setRowSelectionAllowed(true);
|
||||
// set details
|
||||
miniTable.setColumnClass(0, IDColumn.class, false, " ");
|
||||
miniTable.setColumnClass(1, String.class, true, Msg.translate(Env.getCtx(), "AD_Org_ID"));
|
||||
miniTable.setColumnClass(2, String.class, true, Msg.translate(Env.getCtx(), "C_DocType_ID"));
|
||||
miniTable.setColumnClass(3, String.class, true, Msg.translate(Env.getCtx(), "DocumentNo"));
|
||||
miniTable.setColumnClass(4, String.class, true, Msg.translate(Env.getCtx(), "C_BPartner_ID"));
|
||||
miniTable.setColumnClass(5, Timestamp.class, true, Msg.translate(Env.getCtx(), "DateOrdered"));
|
||||
miniTable.setColumnClass(6, BigDecimal.class, true, Msg.translate(Env.getCtx(), "TotalLines"));
|
||||
//
|
||||
miniTable.autoSize();
|
||||
miniTable.getModel().addTableModelListener(this);
|
||||
// Info
|
||||
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateSel"));//@@
|
||||
statusBar.setStatusDB(" ");
|
||||
// Tabbed Pane Listener
|
||||
tabbedPane.addEventListener(Events.ON_SELECT, this);
|
||||
} // dynInit
|
||||
|
||||
/**
|
||||
* Get SQL for Orders that needs to be shipped
|
||||
* @return sql
|
||||
*/
|
||||
private String getOrderSQL()
|
||||
{
|
||||
// Create SQL
|
||||
StringBuffer sql = new StringBuffer(
|
||||
"SELECT C_Order_ID, o.Name, dt.Name, DocumentNo, bp.Name, DateOrdered, TotalLines "
|
||||
+ "FROM M_InOut_Candidate_v ic, AD_Org o, C_BPartner bp, C_DocType dt "
|
||||
+ "WHERE ic.AD_Org_ID=o.AD_Org_ID"
|
||||
+ " AND ic.C_BPartner_ID=bp.C_BPartner_ID"
|
||||
+ " AND ic.C_DocType_ID=dt.C_DocType_ID"
|
||||
+ " AND ic.AD_Client_ID=?");
|
||||
|
||||
if (m_M_Warehouse_ID != null)
|
||||
sql.append(" AND ic.M_Warehouse_ID=").append(m_M_Warehouse_ID);
|
||||
if (m_C_BPartner_ID != null)
|
||||
sql.append(" AND ic.C_BPartner_ID=").append(m_C_BPartner_ID);
|
||||
|
||||
// bug - [ 1713317 ] Generate Shipments (manual) show locked records
|
||||
/* begin - Exclude locked records; @Trifon */
|
||||
int AD_User_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID");
|
||||
String lockedIDs = MPrivateAccess.getLockedRecordWhere(MOrder.Table_ID, AD_User_ID);
|
||||
if (lockedIDs != null)
|
||||
{
|
||||
if (sql.length() > 0)
|
||||
sql.append(" AND ");
|
||||
sql.append("C_Order_ID").append(lockedIDs);
|
||||
}
|
||||
/* eng - Exclude locked records; @Trifon */
|
||||
|
||||
//
|
||||
sql.append(" ORDER BY o.Name,bp.Name,DateOrdered");
|
||||
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SQL for Vendor RMA that need to be shipped
|
||||
* @return sql
|
||||
*/
|
||||
private String getRMASql()
|
||||
{
|
||||
StringBuffer sql = new StringBuffer();
|
||||
|
||||
sql.append("SELECT rma.M_RMA_ID, org.Name, dt.Name, rma.DocumentNo, bp.Name, rma.Created, rma.Amt ");
|
||||
sql.append("FROM M_RMA rma INNER JOIN AD_Org org ON rma.AD_Org_ID=org.AD_Org_ID ");
|
||||
sql.append("INNER JOIN C_DocType dt ON rma.C_DocType_ID=dt.C_DocType_ID ");
|
||||
sql.append("INNER JOIN C_BPartner bp ON rma.C_BPartner_ID=bp.C_BPartner_ID ");
|
||||
sql.append("INNER JOIN M_InOut io ON rma.InOut_ID=io.M_InOut_ID ");
|
||||
sql.append("WHERE rma.DocStatus='CO' ");
|
||||
sql.append("AND dt.DocBaseType = 'POO' ");
|
||||
sql.append("AND EXISTS (SELECT * FROM M_RMA r INNER JOIN M_RMALine rl ");
|
||||
sql.append("ON r.M_RMA_ID=rl.M_RMA_ID WHERE r.M_RMA_ID=rma.M_RMA_ID ");
|
||||
sql.append("AND rl.IsActive='Y' AND rl.M_InOutLine_ID > 0 AND rl.QtyDelivered < rl.Qty) ");
|
||||
sql.append("AND NOT EXISTS (SELECT * FROM M_InOut oio WHERE oio.M_RMA_ID=rma.M_RMA_ID ");
|
||||
sql.append("AND oio.DocStatus IN ('IP', 'CO', 'CL')) " );
|
||||
sql.append("AND rma.AD_Client_ID=?");
|
||||
|
||||
if (m_M_Warehouse_ID != null)
|
||||
sql.append(" AND io.M_Warehouse_ID=").append(m_M_Warehouse_ID);
|
||||
if (m_C_BPartner_ID != null)
|
||||
sql.append(" AND bp.C_BPartner_ID=").append(m_C_BPartner_ID);
|
||||
|
||||
int AD_User_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID");
|
||||
String lockedIDs = MPrivateAccess.getLockedRecordWhere(MRMA.Table_ID, AD_User_ID);
|
||||
if (lockedIDs != null)
|
||||
{
|
||||
sql.append(" AND rma.M_RMA_ID").append(lockedIDs);
|
||||
}
|
||||
|
||||
sql.append(" ORDER BY org.Name, bp.Name, rma.Created ");
|
||||
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
private void postQueryEvent()
|
||||
{
|
||||
Clients.showBusy(Msg.getMsg(Env.getCtx(), "Processing"), true);
|
||||
Events.echoEvent("onExecuteQuery", this, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dont call this directly, use internally to handle execute query event
|
||||
*/
|
||||
public void onExecuteQuery()
|
||||
{
|
||||
try
|
||||
{
|
||||
executeQuery();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Clients.showBusy(null, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Query Info
|
||||
*/
|
||||
private void executeQuery()
|
||||
public void executeQuery()
|
||||
{
|
||||
log.info("");
|
||||
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
|
||||
|
||||
String sql = "";
|
||||
|
||||
KeyNamePair docTypeKNPair = cmbDocType.getSelectedItem().toKeyNamePair();
|
||||
|
||||
if (docTypeKNPair.getKey() == MRMA.Table_ID)
|
||||
{
|
||||
sql = getRMASql();
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = getOrderSQL();
|
||||
}
|
||||
|
||||
log.fine(sql);
|
||||
// reset table
|
||||
int row = 0;
|
||||
miniTable.setRowCount(row);
|
||||
// Execute
|
||||
try
|
||||
{
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
|
||||
pstmt.setInt(1, AD_Client_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
//
|
||||
while (rs.next())
|
||||
{
|
||||
// extend table
|
||||
miniTable.setRowCount(row+1);
|
||||
// set values
|
||||
miniTable.setValueAt(new IDColumn(rs.getInt(1)), row, 0); // C_Order_ID
|
||||
miniTable.setValueAt(rs.getString(2), row, 1); // Org
|
||||
miniTable.setValueAt(rs.getString(3), row, 2); // DocType
|
||||
miniTable.setValueAt(rs.getString(4), row, 3); // Doc No
|
||||
miniTable.setValueAt(rs.getString(5), row, 4); // BPartner
|
||||
miniTable.setValueAt(rs.getTimestamp(6), row, 5); // DateOrdered
|
||||
miniTable.setValueAt(rs.getBigDecimal(7), row, 6); // TotalLines
|
||||
// prepare next
|
||||
row++;
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, sql.toString(), e);
|
||||
}
|
||||
//
|
||||
miniTable.repaint();
|
||||
this.invalidate();
|
||||
// statusBar.setStatusDB(String.valueOf(miniTable.getRowCount()));
|
||||
executeQuery(docTypeKNPair, form.getMiniTable());
|
||||
form.getMiniTable().repaint();
|
||||
form.invalidate();
|
||||
} // executeQuery
|
||||
|
||||
/**
|
||||
|
@ -485,37 +167,34 @@ public class WInOutGen extends ADForm implements EventListener, ValueChangeListe
|
|||
{
|
||||
log.info("Cmd=" + e.getTarget().getId());
|
||||
//
|
||||
if (e.getTarget().getId().equals(ConfirmPanel.A_CANCEL))
|
||||
if(cmbDocType.equals(e.getTarget()))
|
||||
{
|
||||
dispose();
|
||||
return;
|
||||
}
|
||||
else if (e.getTarget() instanceof Tab)
|
||||
{
|
||||
int index = tabbedPane.getSelectedIndex();
|
||||
m_selectionActive = (index == 0);
|
||||
return;
|
||||
}
|
||||
else if (cmbDocType.equals(e.getTarget()))
|
||||
{
|
||||
postQueryEvent();
|
||||
form.postQueryEvent();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_selectionActive &&
|
||||
(m_M_Warehouse_ID == null || (Integer)m_M_Warehouse_ID <= 0)) {
|
||||
throw new WrongValueException(fWarehouse.getComponent(), Msg.translate(Env.getCtx(), "FillMandatory"));
|
||||
}
|
||||
//
|
||||
saveSelection();
|
||||
validate();
|
||||
} // actionPerformed
|
||||
|
||||
public void validate()
|
||||
{
|
||||
if (isSelectionActive() &&
|
||||
(m_M_Warehouse_ID == null || (Integer)m_M_Warehouse_ID <= 0)) {
|
||||
throw new WrongValueException(fWarehouse.getComponent(), Msg.translate(Env.getCtx(), "FillMandatory"));
|
||||
}
|
||||
|
||||
form.saveSelection();
|
||||
|
||||
ArrayList<Integer> selection = getSelection();
|
||||
if (selection != null
|
||||
&& selection.size() > 0
|
||||
&& m_selectionActive // on selection tab
|
||||
&& isSelectionActive() // on selection tab
|
||||
&& m_M_Warehouse_ID != null)
|
||||
generateShipments ();
|
||||
form.generate();
|
||||
else
|
||||
dispose();
|
||||
} // actionPerformed
|
||||
form.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Value Change Listener - requery
|
||||
|
@ -531,302 +210,21 @@ public class WInOutGen extends ADForm implements EventListener, ValueChangeListe
|
|||
m_C_BPartner_ID = e.getNewValue();
|
||||
fBPartner.setValue(m_C_BPartner_ID); // display value
|
||||
}
|
||||
postQueryEvent();
|
||||
form.postQueryEvent();
|
||||
} // vetoableChange
|
||||
|
||||
|
||||
/**
|
||||
* Table Model Listener
|
||||
* @param e event
|
||||
*/
|
||||
public void tableChanged(WTableModelEvent e)
|
||||
{
|
||||
int rowsSelected = 0;
|
||||
int rows = miniTable.getRowCount();
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
IDColumn id = (IDColumn)miniTable.getValueAt(i, 0); // ID in column 0
|
||||
if (id != null && id.isSelected())
|
||||
rowsSelected++;
|
||||
}
|
||||
statusBar.setStatusDB(" " + rowsSelected + " ");
|
||||
} // tableChanged
|
||||
|
||||
/**
|
||||
* Save Selection & return selecion Query or ""
|
||||
* @return where clause like C_Order_ID IN (...)
|
||||
*/
|
||||
private void saveSelection()
|
||||
{
|
||||
log.info("");
|
||||
// ID selection may be pending
|
||||
// miniTable.editingStopped(new ChangeEvent(this));
|
||||
// Array of Integers
|
||||
ArrayList<Integer> results = new ArrayList<Integer>();
|
||||
selection = null;
|
||||
|
||||
// Get selected entries
|
||||
int rows = miniTable.getRowCount();
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
IDColumn id = (IDColumn)miniTable.getValueAt(i, 0); // ID in column 0
|
||||
// log.fine( "Row=" + i + " - " + id);
|
||||
if (id != null && id.isSelected())
|
||||
results.add(id.getRecord_ID());
|
||||
}
|
||||
|
||||
if (results.size() == 0)
|
||||
return;
|
||||
log.config("Selected #" + results.size());
|
||||
selection = results;
|
||||
} // saveSelection
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Generate Shipments
|
||||
*/
|
||||
private void generateShipments ()
|
||||
public String generate()
|
||||
{
|
||||
log.info("M_Warehouse_ID=" + m_M_Warehouse_ID);
|
||||
String trxName = Trx.createTrxName("IOG");
|
||||
Trx trx = Trx.get(trxName, true); //trx needs to be committed too
|
||||
// String trxName = null;
|
||||
// Trx trx = null;
|
||||
|
||||
m_selectionActive = false; // prevents from being called twice
|
||||
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateGen"));
|
||||
statusBar.setStatusDB(String.valueOf(selection.size()));
|
||||
|
||||
// Prepare Process
|
||||
int AD_Process_ID = 0;
|
||||
KeyNamePair docTypeKNPair = (KeyNamePair)cmbDocType.getSelectedItem().toKeyNamePair();
|
||||
|
||||
if (docTypeKNPair.getKey() == MRMA.Table_ID)
|
||||
{
|
||||
AD_Process_ID = 52001; // M_InOut_GenerateRMA - org.adempiere.process.InOutGenerateRMA
|
||||
}
|
||||
else
|
||||
{
|
||||
AD_Process_ID = 199; // M_InOut_Generate - org.compiere.process.InOutGenerate
|
||||
}
|
||||
|
||||
MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
|
||||
if (!instance.save())
|
||||
{
|
||||
info.setContent(Msg.getMsg(Env.getCtx(), "ProcessNoInstance"));
|
||||
return;
|
||||
}
|
||||
|
||||
//insert selection
|
||||
StringBuffer insert = new StringBuffer();
|
||||
insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
|
||||
int counter = 0;
|
||||
for(Integer selectedId : selection)
|
||||
{
|
||||
counter++;
|
||||
if (counter > 1)
|
||||
insert.append(" UNION ");
|
||||
insert.append("SELECT ");
|
||||
insert.append(instance.getAD_PInstance_ID());
|
||||
insert.append(", ");
|
||||
insert.append(selectedId);
|
||||
insert.append(" FROM DUAL ");
|
||||
|
||||
if (counter == 1000)
|
||||
{
|
||||
if ( DB.executeUpdate(insert.toString(), trxName) < 0 )
|
||||
{
|
||||
String msg = "No Shipments"; // not translated!
|
||||
log.config(msg);
|
||||
info.setContent(msg);
|
||||
trx.rollback();
|
||||
return;
|
||||
}
|
||||
insert = new StringBuffer();
|
||||
insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
|
||||
counter = 0;
|
||||
}
|
||||
}
|
||||
if (counter > 0)
|
||||
{
|
||||
if ( DB.executeUpdate(insert.toString(), trxName) < 0 )
|
||||
{
|
||||
String msg = "No Shipments"; // not translated!
|
||||
log.config(msg);
|
||||
info.setContent(msg);
|
||||
trx.rollback();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//call process
|
||||
m_pi = new ProcessInfo ("VInOutGen", AD_Process_ID);
|
||||
m_pi.setAD_PInstance_ID (instance.getAD_PInstance_ID());
|
||||
|
||||
// Add Parameter - Selection=Y
|
||||
MPInstancePara ip = new MPInstancePara(instance, 10);
|
||||
ip.setParameter("Selection","Y");
|
||||
if (!ip.save())
|
||||
{
|
||||
String msg = "No Parameter added"; // not translated
|
||||
info.setContent(msg);
|
||||
log.log(Level.SEVERE, msg);
|
||||
return;
|
||||
}
|
||||
//Add Document action parameter
|
||||
ip = new MPInstancePara(instance, 20);
|
||||
KeyNamePair docTypeKNPair = (KeyNamePair)cmbDocType.getSelectedItem().toKeyNamePair();
|
||||
String docActionSelected = (String)docAction.getValue();
|
||||
ip.setParameter("DocAction", docActionSelected);
|
||||
if(!ip.save())
|
||||
{
|
||||
String msg = "No DocAction Parameter added";
|
||||
info.setContent(msg);
|
||||
log.log(Level.SEVERE, msg);
|
||||
return;
|
||||
}
|
||||
// Add Parameter - M_Warehouse_ID=x
|
||||
ip = new MPInstancePara(instance, 30);
|
||||
ip.setParameter("M_Warehouse_ID", Integer.parseInt(m_M_Warehouse_ID.toString()));
|
||||
if (!ip.save())
|
||||
{
|
||||
String msg = "No Parameter added"; // not translated
|
||||
info.setContent(msg);
|
||||
log.log(Level.SEVERE, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
// Execute Process
|
||||
if (!getDesktop().isServerPushEnabled())
|
||||
getDesktop().enableServerPush(true);
|
||||
|
||||
this.lockUI();
|
||||
final ProcessCtl worker = new ProcessCtl(null, m_WindowNo, m_pi, trx);
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
//get full control of desktop
|
||||
org.zkoss.zk.ui.Desktop desktop = WInOutGen.this.getDesktop();
|
||||
try {
|
||||
Executions.activate(desktop);
|
||||
try {
|
||||
worker.run(); // complete tasks in unlockUI / generateShipments_complete
|
||||
} finally{
|
||||
unlockUI();
|
||||
//release full control of desktop
|
||||
Executions.deactivate(desktop);
|
||||
}
|
||||
} catch (DesktopUnavailableException e) {
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
} catch (InterruptedException e) {
|
||||
log.log(Level.WARNING, e.getLocalizedMessage(), e);
|
||||
}
|
||||
}
|
||||
};
|
||||
new Thread(runnable).start();
|
||||
//
|
||||
return generate(form.getStatusBar(), docTypeKNPair, docActionSelected);
|
||||
} // generateShipments
|
||||
|
||||
/**
|
||||
* Complete generating shipments.
|
||||
* Called from Unlock UI
|
||||
* @param pi process info
|
||||
*/
|
||||
private void generateShipments_complete ()
|
||||
public Object getForm()
|
||||
{
|
||||
Clients.showBusy(null, false);
|
||||
|
||||
// Switch Tabs
|
||||
tabbedPane.setSelectedIndex(1);
|
||||
//
|
||||
ProcessInfoUtil.setLogFromDB(m_pi);
|
||||
StringBuffer iText = new StringBuffer();
|
||||
iText.append("<b>").append(m_pi.getSummary())
|
||||
.append("</b><br>(")
|
||||
.append(Msg.getMsg(Env.getCtx(), "InOutGenerateInfo"))
|
||||
// Shipments are generated depending on the Delivery Rule selection in the Order
|
||||
.append(")<br>")
|
||||
.append(m_pi.getLogInfo(true));
|
||||
info.setContent(iText.toString());
|
||||
|
||||
// Get results
|
||||
int[] ids = m_pi.getIDs();
|
||||
if (ids == null || ids.length == 0)
|
||||
return;
|
||||
log.config("PrintItems=" + ids.length);
|
||||
|
||||
m_ids = ids;
|
||||
Clients.response(new AuEcho(this, "onAfterProcess", null));
|
||||
|
||||
} // generateShipments_complete
|
||||
|
||||
|
||||
public void onAfterProcess()
|
||||
{
|
||||
// OK to print shipments
|
||||
if (FDialog.ask(m_WindowNo, this, "PrintShipments"))
|
||||
{
|
||||
// info.append("\n\n" + Msg.getMsg(Env.getCtx(), "PrintShipments"));
|
||||
Clients.showBusy("Processing...", true);
|
||||
Clients.response(new AuEcho(this, "onPrintShipments", null));
|
||||
} // OK to print shipments
|
||||
return form;
|
||||
}
|
||||
|
||||
public void onPrintShipments()
|
||||
{
|
||||
// Loop through all items
|
||||
List<File> pdfList = new ArrayList<File>();
|
||||
for (int i = 0; i < m_ids.length; i++)
|
||||
{
|
||||
int M_InOut_ID = m_ids[i];
|
||||
ReportEngine re = ReportEngine.get (Env.getCtx(), ReportEngine.SHIPMENT, M_InOut_ID);
|
||||
pdfList.add(re.getPDF());
|
||||
}
|
||||
|
||||
if (pdfList.size() > 1) {
|
||||
try {
|
||||
File outFile = File.createTempFile("WInOutGen", ".pdf");
|
||||
AEnv.mergePdf(pdfList, outFile);
|
||||
|
||||
Clients.showBusy(null, false);
|
||||
Window win = new SimplePDFViewer(this.getFormName(), new FileInputStream(outFile));
|
||||
SessionManager.getAppDesktop().showWindow(win, "center");
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
}
|
||||
} else if (pdfList.size() > 0) {
|
||||
Clients.showBusy(null, false);
|
||||
try {
|
||||
Window win = new SimplePDFViewer(this.getFormName(), new FileInputStream(pdfList.get(0)));
|
||||
SessionManager.getAppDesktop().showWindow(win, "center");
|
||||
} catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* Lock User Interface.
|
||||
* Called from the Worker before processing
|
||||
* @param pi process info
|
||||
*/
|
||||
public void lockUI ()
|
||||
{
|
||||
Clients.showBusy("Processing...", true);
|
||||
} // lockUI
|
||||
|
||||
/**
|
||||
* Unlock User Interface.
|
||||
* Called from the Worker when processing is done
|
||||
* @param pi result of execute ASync call
|
||||
*/
|
||||
public void unlockUI ()
|
||||
{
|
||||
generateShipments_complete();
|
||||
} // unlockUI
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
SessionManager.getAppDesktop().closeActiveWindow();
|
||||
}
|
||||
|
||||
} // VInOutGen
|
||||
}
|
|
@ -25,6 +25,7 @@ import org.adempiere.webui.component.Window;
|
|||
import org.adempiere.webui.exception.ApplicationException;
|
||||
import org.adempiere.webui.session.SessionManager;
|
||||
import org.adempiere.webui.util.ADClassNameMap;
|
||||
import org.compiere.apps.form.GenForm;
|
||||
import org.compiere.model.MForm;
|
||||
import org.compiere.process.ProcessInfo;
|
||||
import org.compiere.util.CLogger;
|
||||
|
@ -79,7 +80,7 @@ public abstract class ADForm extends Window implements EventListener
|
|||
this.setContentSclass("adform-content");
|
||||
}
|
||||
|
||||
protected int getWindowNo()
|
||||
public int getWindowNo()
|
||||
{
|
||||
return m_WindowNo;
|
||||
}
|
||||
|
@ -220,6 +221,21 @@ public abstract class ADForm extends Window implements EventListener
|
|||
form.init(adFormID, name);
|
||||
return form;
|
||||
}
|
||||
else if (obj instanceof GenForm)
|
||||
{
|
||||
GenForm genForm = (GenForm)obj;
|
||||
Object o = genForm.getForm();
|
||||
if(o instanceof ADForm)
|
||||
{
|
||||
form = (ADForm)o;
|
||||
form.init(adFormID, name);
|
||||
return form;
|
||||
}
|
||||
else
|
||||
throw new ApplicationException("The web user interface custom form '" +
|
||||
webClassName +
|
||||
"' cannot be displayed in the web user interface.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ApplicationException("The web user interface custom form '" +
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.adempiere.webui.LayoutUtils;
|
|||
import org.adempiere.webui.component.Label;
|
||||
import org.adempiere.webui.component.Panel;
|
||||
import org.adempiere.webui.window.WRecordInfo;
|
||||
import org.compiere.apps.IStatusBar;
|
||||
import org.compiere.model.DataStatusEvent;
|
||||
import org.compiere.model.MRole;
|
||||
import org.compiere.util.Env;
|
||||
|
@ -41,7 +42,7 @@ import org.zkoss.zul.Vbox;
|
|||
* @date Mar 12, 2007
|
||||
* @version $Revision: 0.10 $
|
||||
*/
|
||||
public class StatusBarPanel extends Panel implements EventListener
|
||||
public class StatusBarPanel extends Panel implements IStatusBar, EventListener
|
||||
{
|
||||
/**
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue