Refactor custom form - ID: 2787613
This commit is contained in:
parent
9957873396
commit
e1d00d9d96
|
@ -28,6 +28,7 @@ public abstract class GenForm
|
|||
private boolean m_selectionActive = true;
|
||||
private String title;
|
||||
private int reportEngineType;
|
||||
private String askPrintMsg;
|
||||
|
||||
private Trx trx;
|
||||
private ProcessInfo pi;
|
||||
|
@ -107,12 +108,11 @@ public abstract class GenForm
|
|||
this.reportEngineType = reportEngineType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by org.adempiere.webui.panel.ADForm.openForm(int)
|
||||
* @return
|
||||
*/
|
||||
public Object getForm()
|
||||
{
|
||||
return null;
|
||||
public String getAskPrintMsg() {
|
||||
return askPrintMsg;
|
||||
}
|
||||
|
||||
public void setAskPrintMsg(String askPrintMsg) {
|
||||
this.askPrintMsg = askPrintMsg;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ 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.ProcessInfo;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
|
@ -50,6 +51,13 @@ public class InOutGen extends GenForm
|
|||
public Object m_M_Warehouse_ID = null;
|
||||
public Object m_C_BPartner_ID = null;
|
||||
|
||||
public void dynInit() throws Exception
|
||||
{
|
||||
setTitle("InOutGenerateInfo");
|
||||
setReportEngineType(ReportEngine.SHIPMENT);
|
||||
setAskPrintMsg("PrintShipments");
|
||||
}
|
||||
|
||||
public void configureMiniTable(IMiniTable miniTable)
|
||||
{
|
||||
// create Columns
|
||||
|
|
|
@ -0,0 +1,353 @@
|
|||
/******************************************************************************
|
||||
* 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.print.ReportEngine;
|
||||
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 Invoice (manual) controller class
|
||||
*
|
||||
*/
|
||||
public class InvoiceGen extends GenForm
|
||||
{
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(InvoiceGen.class);
|
||||
//
|
||||
|
||||
public Object m_AD_Org_ID = null;
|
||||
public Object m_C_BPartner_ID = null;
|
||||
|
||||
public void dynInit() throws Exception
|
||||
{
|
||||
setTitle("InvGenerateInfo");
|
||||
setReportEngineType(ReportEngine.INVOICE);
|
||||
setAskPrintMsg("PrintInvoices");
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
StringBuffer sql = new StringBuffer(
|
||||
"SELECT C_Order_ID, o.Name, dt.Name, DocumentNo, bp.Name, DateOrdered, TotalLines "
|
||||
+ "FROM C_Invoice_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=?"
|
||||
+ " AND NOT EXISTS (SELECT * FROM C_Invoice i"
|
||||
+ " WHERE i.C_Order_ID=ic.C_Order_ID AND i.DocStatus IN ('IP', 'CO', 'CL')) ");
|
||||
|
||||
if (m_AD_Org_ID != null)
|
||||
sql.append(" AND ic.AD_Org_ID=").append(m_AD_Org_ID);
|
||||
if (m_C_BPartner_ID != null)
|
||||
sql.append(" AND ic.C_BPartner_ID=").append(m_C_BPartner_ID);
|
||||
|
||||
// bug - [ 1713337 ] "Generate Invoices (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 NOT EXISTS (SELECT * FROM C_Invoice i ");
|
||||
sql.append("WHERE i.M_RMA_ID=rma.M_RMA_ID AND i.DocStatus IN ('IP', 'CO', 'CL')) ");
|
||||
sql.append("AND EXISTS (SELECT * FROM C_InvoiceLine il INNER JOIN M_InOutLine iol ");
|
||||
sql.append("ON il.M_InOutLine_ID=iol.M_InOutLine_ID INNER JOIN C_Invoice i ");
|
||||
sql.append("ON i.C_Invoice_ID=il.C_Invoice_ID WHERE i.DocStatus IN ('CO', 'CL') ");
|
||||
sql.append("AND iol.M_InOutLine_ID IN ");
|
||||
sql.append("(SELECT M_InOutLine_ID FROM M_RMALine rl WHERE rl.M_RMA_ID=rma.M_RMA_ID ");
|
||||
sql.append("AND rl.M_InOutLine_ID IS NOT NULL)) ");
|
||||
sql.append("AND rma.AD_Client_ID=?");
|
||||
|
||||
if (m_AD_Org_ID != null)
|
||||
sql.append(" AND rma.AD_Org_ID=").append(m_AD_Org_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());
|
||||
// Create SQL
|
||||
|
||||
String sql = "";
|
||||
|
||||
if (docTypeKNPair.getKey() == MOrder.Table_ID)
|
||||
{
|
||||
sql = getOrderSQL();
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = getRMASql();
|
||||
}
|
||||
|
||||
// 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 Invoices
|
||||
*/
|
||||
public String generate(IStatusBar statusBar, KeyNamePair docTypeKNPair, String docActionSelected)
|
||||
{
|
||||
String info = "";
|
||||
String trxName = Trx.createTrxName("IVG");
|
||||
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(), "InvGenerateGen"));
|
||||
statusBar.setStatusDB(String.valueOf(getSelection().size()));
|
||||
|
||||
// Prepare Process
|
||||
int AD_Process_ID = 0;
|
||||
|
||||
if (docTypeKNPair.getKey() == MRMA.Table_ID)
|
||||
{
|
||||
AD_Process_ID = 52002; // C_Invoice_GenerateRMA - org.adempiere.process.InvoiceGenerateRMA
|
||||
}
|
||||
else
|
||||
{
|
||||
AD_Process_ID = 134; // HARDCODED C_InvoiceCreate
|
||||
}
|
||||
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 Invoices"; // not translated!
|
||||
info = msg;
|
||||
log.config(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 Invoices"; // not translated!
|
||||
info = msg;
|
||||
log.config(msg);
|
||||
trx.rollback();
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
ProcessInfo pi = new ProcessInfo ("", AD_Process_ID);
|
||||
pi.setAD_PInstance_ID (instance.getAD_PInstance_ID());
|
||||
|
||||
// Add Parameters
|
||||
MPInstancePara para = new MPInstancePara(instance, 10);
|
||||
para.setParameter("Selection", "Y");
|
||||
if (!para.save())
|
||||
{
|
||||
String msg = "No Selection Parameter added"; // not translated
|
||||
info = msg;
|
||||
log.log(Level.SEVERE, msg);
|
||||
return info;
|
||||
}
|
||||
|
||||
para = new MPInstancePara(instance, 20);
|
||||
para.setParameter("DocAction", docActionSelected);
|
||||
|
||||
if (!para.save())
|
||||
{
|
||||
String msg = "No DocAction Parameter added"; // not translated
|
||||
info = msg;
|
||||
log.log(Level.SEVERE, msg);
|
||||
return info;
|
||||
}
|
||||
|
||||
setTrx(trx);
|
||||
setProcessInfo(pi);
|
||||
|
||||
return info;
|
||||
} // generateInvoices
|
||||
}
|
|
@ -154,7 +154,6 @@ public class VGenPanel extends CPanel implements ActionListener, ChangeListener,
|
|||
|
||||
miniTable.getModel().addTableModelListener(this);
|
||||
// Info
|
||||
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateSel"));//@@
|
||||
statusBar.setStatusDB(" ");
|
||||
// Tabbed Pane Listener
|
||||
tabbedPane.addChangeListener(this);
|
||||
|
@ -271,10 +270,9 @@ public class VGenPanel extends CPanel implements ActionListener, ChangeListener,
|
|||
log.config("PrintItems=" + ids.length);
|
||||
|
||||
confirmPanelGen.getOKButton().setEnabled(false);
|
||||
// OK to print shipments
|
||||
if (ADialog.ask(m_WindowNo, this, "PrintShipments"))
|
||||
// OK to print
|
||||
if (ADialog.ask(m_WindowNo, this, genForm.getAskPrintMsg()))
|
||||
{
|
||||
// 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
|
||||
|
@ -293,7 +291,7 @@ public class VGenPanel extends CPanel implements ActionListener, ChangeListener,
|
|||
}
|
||||
while (retValue == ADialogDialog.A_CANCEL);
|
||||
this.setCursor(Cursor.getDefaultCursor());
|
||||
} // OK to print shipments
|
||||
} // OK to print
|
||||
|
||||
//
|
||||
confirmPanelGen.getOKButton().setEnabled(true);
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.compiere.model.MLookup;
|
|||
import org.compiere.model.MLookupFactory;
|
||||
import org.compiere.model.MOrder;
|
||||
import org.compiere.model.MRMA;
|
||||
import org.compiere.print.ReportEngine;
|
||||
import org.compiere.swing.CLabel;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DisplayType;
|
||||
|
@ -76,6 +75,7 @@ public class VInOutGen extends InOutGen implements FormPanel, ActionListener, Ve
|
|||
|
||||
try
|
||||
{
|
||||
super.dynInit();
|
||||
dynInit();
|
||||
jbInit();
|
||||
}
|
||||
|
@ -107,10 +107,7 @@ public class VInOutGen extends InOutGen implements FormPanel, ActionListener, Ve
|
|||
* @throws Exception
|
||||
*/
|
||||
void jbInit() throws Exception
|
||||
{
|
||||
setTitle("InOutGenerateInfo");
|
||||
setReportEngineType(ReportEngine.SHIPMENT);
|
||||
|
||||
{
|
||||
lWarehouse.setLabelFor(fWarehouse);
|
||||
lBPartner.setLabelFor(fBPartner);
|
||||
lBPartner.setText(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
|
||||
|
@ -157,6 +154,8 @@ public class VInOutGen extends InOutGen implements FormPanel, ActionListener, Ve
|
|||
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);
|
||||
|
||||
panel.getStatusBar().setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateSel"));//@@
|
||||
} // fillPicks
|
||||
|
||||
public void executeQuery()
|
||||
|
|
|
@ -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,84 +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 Invoice Selection
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: VInvoiceGen.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
|
||||
* Generate Invoice (manual) view class
|
||||
*
|
||||
*/
|
||||
public class VInvoiceGen extends CPanel
|
||||
implements FormPanel, ActionListener, VetoableChangeListener, ChangeListener, TableModelListener, ASyncProcess
|
||||
public class VInvoiceGen extends InvoiceGen implements FormPanel, ActionListener, VetoableChangeListener
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -8924864953968836883L;
|
||||
private VGenPanel panel;
|
||||
|
||||
/** Window No */
|
||||
private int m_WindowNo = 0;
|
||||
/** FormFrame */
|
||||
private FormFrame m_frame;
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(VInvoiceGen.class);
|
||||
//
|
||||
|
||||
private CLabel lOrg = new CLabel();
|
||||
private VLookup fOrg;
|
||||
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
|
||||
* @param WindowNo window
|
||||
|
@ -99,55 +70,30 @@ public class VInvoiceGen 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();
|
||||
super.dynInit();
|
||||
dynInit();
|
||||
frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
|
||||
frame.getContentPane().add(statusBar, BorderLayout.SOUTH);
|
||||
jbInit();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
log.log(Level.SEVERE, "init", ex);
|
||||
}
|
||||
} // init
|
||||
|
||||
/** Window No */
|
||||
private int m_WindowNo = 0;
|
||||
/** FormFrame */
|
||||
private FormFrame m_frame;
|
||||
|
||||
private boolean m_selectionActive = true;
|
||||
private Object m_AD_Org_ID = null;
|
||||
private Object m_C_BPartner_ID = null;
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(VInvoiceGen.class);
|
||||
//
|
||||
private CTabbedPane tabbedPane = new CTabbedPane();
|
||||
private CPanel selPanel = new CPanel();
|
||||
private CPanel selNorthPanel = new CPanel();
|
||||
private BorderLayout selPanelLayout = new BorderLayout();
|
||||
private CLabel lOrg = new CLabel();
|
||||
private VLookup fOrg;
|
||||
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 ArrayList<Integer> selections = null;
|
||||
|
||||
private CLabel lDocType = new CLabel();
|
||||
private VComboBox cmbDocType = new VComboBox();
|
||||
private CLabel lDocAction = new CLabel();
|
||||
private VLookup docAction;
|
||||
|
||||
/**
|
||||
* Dispose
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
if (m_frame != null)
|
||||
m_frame.dispose();
|
||||
m_frame = null;
|
||||
} // dispose
|
||||
|
||||
/**
|
||||
* Static Init.
|
||||
|
@ -162,52 +108,30 @@ public class VInvoiceGen extends CPanel
|
|||
*/
|
||||
void jbInit() throws Exception
|
||||
{
|
||||
CompiereColor.setBackground(this);
|
||||
//
|
||||
selPanel.setLayout(selPanelLayout);
|
||||
lOrg.setLabelFor(fOrg);
|
||||
lOrg.setText(Msg.translate(Env.getCtx(), "AD_Org_ID"));
|
||||
lDocAction.setLabelFor(docAction);
|
||||
lDocAction.setText(Msg.translate(Env.getCtx(), "DocAction"));
|
||||
lBPartner.setLabelFor(fBPartner);
|
||||
lBPartner.setText(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
|
||||
selNorthPanel.setLayout(northPanelLayout);
|
||||
northPanelLayout.setAlignment(FlowLayout.LEFT);
|
||||
tabbedPane.add(selPanel, Msg.getMsg(Env.getCtx(), "Select"));
|
||||
selPanel.add(selNorthPanel, BorderLayout.NORTH);
|
||||
selNorthPanel.add(lOrg, null);
|
||||
selNorthPanel.add(fOrg, 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);
|
||||
|
||||
lDocAction.setLabelFor(docAction);
|
||||
lDocAction.setText(Msg.translate(Env.getCtx(), "DocAction"));
|
||||
lDocType.setLabelFor(cmbDocType);
|
||||
selNorthPanel.add(lDocType, null);
|
||||
selNorthPanel.add(cmbDocType, null);
|
||||
selNorthPanel.add(lDocAction, null);
|
||||
selNorthPanel.add(docAction, null);
|
||||
|
||||
|
||||
panel.getParameterPanel().add(lOrg, null);
|
||||
panel.getParameterPanel().add(fOrg, 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
|
||||
|
||||
|
||||
/**
|
||||
* Fill Picks
|
||||
* Fill Picks.
|
||||
* Column_ID from C_Order
|
||||
* @throws Exception if Lookups cannot be initialized
|
||||
*/
|
||||
private void fillPicks() throws Exception
|
||||
public void dynInit() throws Exception
|
||||
{
|
||||
MLookup orgL = MLookupFactory.get (Env.getCtx(), m_WindowNo, 0, 2163, DisplayType.TableDir);
|
||||
fOrg = new VLookup ("AD_Org_ID", false, false, true, orgL);
|
||||
|
@ -232,210 +156,41 @@ public class VInvoiceGen extends CPanel
|
|||
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);
|
||||
|
||||
panel.getStatusBar().setStatusLine(Msg.getMsg(Env.getCtx(), "InvGenerateSel"));//@@
|
||||
} // 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(), "InvGenerateSel"));
|
||||
statusBar.setStatusDB(" ");
|
||||
// Tabbed Pane Listener
|
||||
tabbedPane.addChangeListener(this);
|
||||
} // dynInit
|
||||
|
||||
private String getOrderSQL()
|
||||
public void executeQuery()
|
||||
{
|
||||
StringBuffer sql = new StringBuffer(
|
||||
"SELECT C_Order_ID, o.Name, dt.Name, DocumentNo, bp.Name, DateOrdered, TotalLines "
|
||||
+ "FROM C_Invoice_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=?"
|
||||
+ " AND NOT EXISTS (SELECT * FROM C_Invoice i"
|
||||
+ " WHERE i.C_Order_ID=ic.C_Order_ID AND i.DocStatus IN ('IP', 'CO', 'CL')) ");
|
||||
|
||||
if (m_AD_Org_ID != null)
|
||||
sql.append(" AND ic.AD_Org_ID=").append(m_AD_Org_ID);
|
||||
if (m_C_BPartner_ID != null)
|
||||
sql.append(" AND ic.C_BPartner_ID=").append(m_C_BPartner_ID);
|
||||
|
||||
// bug - [ 1713337 ] "Generate Invoices (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();
|
||||
}
|
||||
|
||||
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 NOT EXISTS (SELECT * FROM C_Invoice i ");
|
||||
sql.append("WHERE i.M_RMA_ID=rma.M_RMA_ID AND i.DocStatus IN ('IP', 'CO', 'CL')) ");
|
||||
sql.append("AND EXISTS (SELECT * FROM C_InvoiceLine il INNER JOIN M_InOutLine iol ");
|
||||
sql.append("ON il.M_InOutLine_ID=iol.M_InOutLine_ID INNER JOIN C_Invoice i ");
|
||||
sql.append("ON i.C_Invoice_ID=il.C_Invoice_ID WHERE i.DocStatus IN ('CO', 'CL') ");
|
||||
sql.append("AND iol.M_InOutLine_ID IN ");
|
||||
sql.append("(SELECT M_InOutLine_ID FROM M_RMALine rl WHERE rl.M_RMA_ID=rma.M_RMA_ID ");
|
||||
sql.append("AND rl.M_InOutLine_ID IS NOT NULL)) ");
|
||||
sql.append("AND rma.AD_Client_ID=?");
|
||||
|
||||
if (m_AD_Org_ID != null)
|
||||
sql.append(" AND rma.AD_Org_ID=").append(m_AD_Org_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());
|
||||
// Create SQL
|
||||
|
||||
String sql = "";
|
||||
|
||||
KeyNamePair docTypeKNPair = (KeyNamePair)cmbDocType.getSelectedItem();
|
||||
|
||||
if (docTypeKNPair.getKey() == MOrder.Table_ID)
|
||||
{
|
||||
sql = getOrderSQL();
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = getRMASQL();
|
||||
}
|
||||
|
||||
// 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()));
|
||||
KeyNamePair docTypeKNPair = (KeyNamePair)cmbDocType.getSelectedItem();
|
||||
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();
|
||||
return;
|
||||
}
|
||||
//
|
||||
saveSelection();
|
||||
if (selections != null && selections.size() > 0 && m_selectionActive)
|
||||
generateInvoices ();
|
||||
else
|
||||
dispose();
|
||||
{
|
||||
executeQuery();
|
||||
return;
|
||||
}
|
||||
|
||||
validate();
|
||||
} // actionPerformed
|
||||
|
||||
public void validate()
|
||||
{
|
||||
panel.saveSelection();
|
||||
|
||||
ArrayList<Integer> selection = getSelection();
|
||||
if (selection != null && selection.size() > 0 && isSelectionActive())
|
||||
panel.generate();
|
||||
else
|
||||
panel.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Vetoable Change Listener - requery
|
||||
|
@ -453,270 +208,14 @@ public class VInvoiceGen 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
|
||||
*/
|
||||
private void saveSelection()
|
||||
{
|
||||
log.info("");
|
||||
// ID selection may be pending
|
||||
miniTable.editingStopped(new ChangeEvent(this));
|
||||
// Array of Integers
|
||||
ArrayList<Integer> results = new ArrayList<Integer>();
|
||||
selections = 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;
|
||||
|
||||
selections = results;
|
||||
} // saveSelection
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Generate Invoices
|
||||
* Generate Shipments
|
||||
*/
|
||||
private void generateInvoices ()
|
||||
public String generate()
|
||||
{
|
||||
String trxName = Trx.createTrxName("IVG");
|
||||
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(), "InvGenerateGen"));
|
||||
statusBar.setStatusDB(String.valueOf(selections.size()));
|
||||
|
||||
// Prepare Process
|
||||
int AD_Process_ID = 0;
|
||||
KeyNamePair docTypeKNPair = (KeyNamePair)cmbDocType.getSelectedItem();
|
||||
|
||||
if (docTypeKNPair.getKey() == MRMA.Table_ID)
|
||||
{
|
||||
AD_Process_ID = 52002; // C_Invoice_GenerateRMA - org.adempiere.process.InvoiceGenerateRMA
|
||||
}
|
||||
else
|
||||
{
|
||||
AD_Process_ID = 134; // HARDCODED C_InvoiceCreate
|
||||
}
|
||||
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 : selections)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
ProcessInfo pi = new ProcessInfo ("", AD_Process_ID);
|
||||
pi.setAD_PInstance_ID (instance.getAD_PInstance_ID());
|
||||
|
||||
// Add Parameters
|
||||
MPInstancePara para = new MPInstancePara(instance, 10);
|
||||
para.setParameter("Selection", "Y");
|
||||
if (!para.save())
|
||||
{
|
||||
String msg = "No Selection Parameter added"; // not translated
|
||||
info.setText(msg);
|
||||
log.log(Level.SEVERE, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
para = new MPInstancePara(instance, 20);
|
||||
String docActionSelected = (String)docAction.getValue();
|
||||
para.setParameter("DocAction", docActionSelected);
|
||||
|
||||
if (!para.save())
|
||||
{
|
||||
String msg = "No DocAction 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 / generateInvoice_complete
|
||||
} // generateInvoices
|
||||
|
||||
/**
|
||||
* Complete generating invoices.
|
||||
* Called from Unlock UI
|
||||
* @param pi process info
|
||||
*/
|
||||
private void generateInvoice_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(), "InvGenerateInfo"))
|
||||
//Invoices are generated depending on the Invoicing 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;
|
||||
|
||||
confirmPanelGen.getOKButton().setEnabled(false);
|
||||
// OK to print invoices
|
||||
if (ADialog.ask(m_WindowNo, this, "PrintInvoices"))
|
||||
{
|
||||
// info.append("\n\n" + Msg.getMsg(Env.getCtx(), "PrintInvoices"));
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
int retValue = ADialogDialog.A_CANCEL;
|
||||
do
|
||||
{
|
||||
// Loop through all items
|
||||
for (int i = 0; i < ids.length; i++)
|
||||
{
|
||||
int C_Invoice_ID = ids[i];
|
||||
ReportCtl.startDocumentPrint(ReportEngine.INVOICE, C_Invoice_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 invoices
|
||||
|
||||
//
|
||||
confirmPanelGen.getOKButton().setEnabled(true);
|
||||
} // generateInvoices_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());
|
||||
//
|
||||
generateInvoice_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
|
||||
|
||||
} // VInvoiceGen
|
||||
String docActionSelected = (String)docAction.getValue();
|
||||
return generate(panel.getStatusBar(), docTypeKNPair, docActionSelected);
|
||||
} // generateShipments
|
||||
}
|
||||
|
|
|
@ -0,0 +1,321 @@
|
|||
package org.compiere.grid;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Vector;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.minigrid.IMiniTable;
|
||||
import org.compiere.model.GridTab;
|
||||
import org.compiere.model.MBankAccount;
|
||||
import org.compiere.model.MBankStatement;
|
||||
import org.compiere.model.MBankStatementLine;
|
||||
import org.compiere.model.MPayment;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.KeyNamePair;
|
||||
import org.compiere.util.Msg;
|
||||
|
||||
/**
|
||||
* Create Transactions for Bank Statements
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: VCreateFromStatement.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
|
||||
* @author Victor Perez, e-Evolucion
|
||||
* <li> RF [1811114] http://sourceforge.net/tracker/index.php?func=detail&aid=1811114&group_id=176962&atid=879335
|
||||
* @author Teo Sarca, www.arhipac.ro
|
||||
* <li>BF [ 2007837 ] VCreateFrom.save() should run in trx
|
||||
*/
|
||||
public class CreateFromStatement extends CreateFrom
|
||||
{
|
||||
public MBankAccount bankAccount;
|
||||
|
||||
/**
|
||||
* Protected Constructor
|
||||
* @param mTab MTab
|
||||
*/
|
||||
public CreateFromStatement(GridTab mTab)
|
||||
{
|
||||
super(mTab);
|
||||
log.info(mTab.toString());
|
||||
} // VCreateFromInvoice
|
||||
|
||||
/**
|
||||
* Dynamic Init
|
||||
* @return true if initialized
|
||||
*/
|
||||
public boolean dynInit() throws Exception
|
||||
{
|
||||
log.config("");
|
||||
setTitle(Msg.translate(Env.getCtx(), "C_BankStatement_ID") + " .. " + Msg.translate(Env.getCtx(), "CreateFrom"));
|
||||
|
||||
return true;
|
||||
} // dynInit
|
||||
|
||||
/**************************************************************************
|
||||
* Construct SQL Where Clause and define parameters
|
||||
* (setParameters needs to set parameters)
|
||||
* Includes first AND
|
||||
* @return sql where clause
|
||||
*/
|
||||
public String getSQLWhere(String DocumentNo, Object BPartner, Object DateFrom, Object DateTo,
|
||||
Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode)
|
||||
{
|
||||
StringBuffer sql = new StringBuffer("WHERE p.Processed='Y' AND p.IsReconciled='N'"
|
||||
+ " AND p.DocStatus IN ('CO','CL','RE','VO') AND p.PayAmt<>0"
|
||||
+ " AND p.C_BankAccount_ID = ?");
|
||||
|
||||
sql.append( " AND NOT EXISTS (SELECT * FROM C_BankStatementLine l "
|
||||
// Voided Bank Statements have 0 StmtAmt
|
||||
+ "WHERE p.C_Payment_ID=l.C_Payment_ID AND l.StmtAmt <> 0)");
|
||||
|
||||
if (DocumentNo.length() > 0)
|
||||
sql.append(" AND UPPER(p.DocumentNo) LIKE ?");
|
||||
//
|
||||
if (BPartner != null)
|
||||
sql.append(" AND p.C_BPartner_ID=?");
|
||||
//
|
||||
if (DateFrom != null || DateTo != null)
|
||||
{
|
||||
Timestamp from = (Timestamp) DateFrom;
|
||||
Timestamp to = (Timestamp) DateTo;
|
||||
if (from == null && to != null)
|
||||
sql.append(" AND TRUNC(p.DateTrx) <= ?");
|
||||
else if (from != null && to == null)
|
||||
sql.append(" AND TRUNC(p.DateTrx) >= ?");
|
||||
else if (from != null && to != null)
|
||||
sql.append(" AND TRUNC(p.DateTrx) BETWEEN ? AND ?");
|
||||
}
|
||||
//
|
||||
if (AmtFrom != null || AmtTo != null)
|
||||
{
|
||||
BigDecimal from = (BigDecimal) AmtFrom;
|
||||
BigDecimal to = (BigDecimal) AmtTo;
|
||||
if (from == null && to != null)
|
||||
sql.append(" AND p.PayAmt <= ?");
|
||||
else if (from != null && to == null)
|
||||
sql.append(" AND p.PayAmt >= ?");
|
||||
else if (from != null && to != null)
|
||||
sql.append(" AND p.PayAmt BETWEEN ? AND ?");
|
||||
}
|
||||
|
||||
if(DocType!=null)
|
||||
sql.append(" AND p.C_DocType_ID=?");
|
||||
if(TenderType != null && TenderType.toString().length() > 0)
|
||||
sql.append(" AND p.TenderType=?");
|
||||
if(AuthCode.length() > 0 )
|
||||
sql.append(" AND p.R_AuthCode LIKE ?");
|
||||
|
||||
log.fine(sql.toString());
|
||||
return sql.toString();
|
||||
} // getSQLWhere
|
||||
|
||||
/**
|
||||
* Set Parameters for Query.
|
||||
* (as defined in getSQLWhere)
|
||||
* @param pstmt statement
|
||||
* @param forCount for counting records
|
||||
* @throws SQLException
|
||||
*/
|
||||
void setParameters(PreparedStatement pstmt, boolean forCount,
|
||||
String DocumentNo, Object BPartner, Object DateFrom, Object DateTo,
|
||||
Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode)
|
||||
throws SQLException
|
||||
{
|
||||
int index = 1;
|
||||
|
||||
pstmt.setInt(index++, bankAccount.getC_BankAccount_ID());
|
||||
|
||||
if (DocumentNo.length() > 0)
|
||||
pstmt.setString(index++, getSQLText(DocumentNo));
|
||||
//
|
||||
if (BPartner != null)
|
||||
{
|
||||
Integer bp = (Integer) BPartner;
|
||||
pstmt.setInt(index++, bp.intValue());
|
||||
log.fine("BPartner=" + bp);
|
||||
}
|
||||
//
|
||||
if (DateFrom != null || DateTo != null)
|
||||
{
|
||||
Timestamp from = (Timestamp) DateFrom;
|
||||
Timestamp to = (Timestamp) DateTo;
|
||||
log.fine("Date From=" + from + ", To=" + to);
|
||||
if (from == null && to != null)
|
||||
pstmt.setTimestamp(index++, to);
|
||||
else if (from != null && to == null)
|
||||
pstmt.setTimestamp(index++, from);
|
||||
else if (from != null && to != null)
|
||||
{
|
||||
pstmt.setTimestamp(index++, from);
|
||||
pstmt.setTimestamp(index++, to);
|
||||
}
|
||||
}
|
||||
//
|
||||
if (AmtFrom != null || AmtTo != null)
|
||||
{
|
||||
BigDecimal from = (BigDecimal) AmtFrom;
|
||||
BigDecimal to = (BigDecimal) AmtTo;
|
||||
log.fine("Amt From=" + from + ", To=" + to);
|
||||
if (from == null && to != null)
|
||||
pstmt.setBigDecimal(index++, to);
|
||||
else if (from != null && to == null)
|
||||
pstmt.setBigDecimal(index++, from);
|
||||
else if (from != null && to != null)
|
||||
{
|
||||
pstmt.setBigDecimal(index++, from);
|
||||
pstmt.setBigDecimal(index++, to);
|
||||
}
|
||||
}
|
||||
if(DocType!=null)
|
||||
pstmt.setInt(index++, (Integer) DocType);
|
||||
if(TenderType!=null && TenderType.toString().length() > 0 )
|
||||
pstmt.setString(index++, (String) TenderType);
|
||||
if(AuthCode.length() > 0 )
|
||||
pstmt.setString(index++, getSQLText(AuthCode));
|
||||
|
||||
} // setParameters
|
||||
|
||||
/**
|
||||
* Get SQL WHERE parameter
|
||||
* @param f field
|
||||
* @return Upper case text with % at the end
|
||||
*/
|
||||
private String getSQLText (String text)
|
||||
{
|
||||
String s = text.toUpperCase();
|
||||
if (!s.endsWith("%"))
|
||||
s += "%";
|
||||
log.fine( "String=" + s);
|
||||
return s;
|
||||
} // getSQLText
|
||||
|
||||
protected Vector<Vector<Object>> getBankData(String DocumentNo, Object BPartner, Object DateFrom, Object DateTo,
|
||||
Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode)
|
||||
{
|
||||
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
|
||||
|
||||
String sql = "SELECT p.DateTrx,p.C_Payment_ID,p.DocumentNo, p.C_Currency_ID,c.ISO_Code, p.PayAmt,"
|
||||
+ "currencyConvert(p.PayAmt,p.C_Currency_ID,ba.C_Currency_ID,pay.DateAcct,p.C_ConversionType_ID,p.AD_Client_ID,p.AD_Org_ID),"
|
||||
+ " bp.Name "
|
||||
+ "FROM C_BankAccount ba"
|
||||
+ " INNER JOIN C_Payment_v p ON (p.C_BankAccount_ID=ba.C_BankAccount_ID)"
|
||||
+ " INNER JOIN C_Payment pay ON (p.C_Payment_ID=pay.C_Payment_ID)"
|
||||
+ " INNER JOIN C_Currency c ON (p.C_Currency_ID=c.C_Currency_ID)"
|
||||
+ " LEFT OUTER JOIN C_BPartner bp ON (p.C_BPartner_ID=bp.C_BPartner_ID) ";
|
||||
|
||||
sql = sql + getSQLWhere(DocumentNo, BPartner, DateFrom, DateTo, AmtFrom, AmtTo, DocType, TenderType, AuthCode) + " ORDER BY p.DateTrx";
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql.toString(), null);
|
||||
setParameters(pstmt, false, DocumentNo, BPartner, DateFrom, DateTo, AmtFrom, AmtTo, DocType, TenderType, AuthCode);
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
Vector<Object> line = new Vector<Object>(6);
|
||||
line.add(new Boolean(false)); // 0-Selection
|
||||
line.add(rs.getTimestamp(1)); // 1-DateTrx
|
||||
KeyNamePair pp = new KeyNamePair(rs.getInt(2), rs.getString(3));
|
||||
line.add(pp); // 2-C_Payment_ID
|
||||
pp = new KeyNamePair(rs.getInt(4), rs.getString(5));
|
||||
line.add(pp); // 3-Currency
|
||||
line.add(rs.getBigDecimal(6)); // 4-PayAmt
|
||||
line.add(rs.getBigDecimal(7)); // 5-Conv Amt
|
||||
line.add(rs.getString(8)); // 6-BParner
|
||||
data.add(line);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public void info()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected void configureMiniTable (IMiniTable miniTable)
|
||||
{
|
||||
miniTable.setColumnClass(0, Boolean.class, false); // 0-Selection
|
||||
miniTable.setColumnClass(1, Timestamp.class, true); // 1-TrxDate
|
||||
miniTable.setColumnClass(2, String.class, true); // 2-Payment
|
||||
miniTable.setColumnClass(3, String.class, true); // 3-Currency
|
||||
miniTable.setColumnClass(4, BigDecimal.class, true); // 4-Amount
|
||||
miniTable.setColumnClass(5, BigDecimal.class, true); // 5-ConvAmount
|
||||
miniTable.setColumnClass(6, String.class, true); // 6-BPartner
|
||||
// Table UI
|
||||
miniTable.autoSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Statement - Insert Data
|
||||
* @return true if saved
|
||||
*/
|
||||
public boolean save(IMiniTable miniTable, String trxName)
|
||||
{
|
||||
// fixed values
|
||||
int C_BankStatement_ID = ((Integer)getGridTab().getValue("C_BankStatement_ID")).intValue();
|
||||
MBankStatement bs = new MBankStatement (Env.getCtx(), C_BankStatement_ID, trxName);
|
||||
log.config(bs.toString());
|
||||
|
||||
// Lines
|
||||
for (int i = 0; i < miniTable.getRowCount(); i++)
|
||||
{
|
||||
if (((Boolean)miniTable.getValueAt(i, 0)).booleanValue())
|
||||
{
|
||||
Timestamp trxDate = (Timestamp)miniTable.getValueAt(i, 1); // 1-DateTrx
|
||||
KeyNamePair pp = (KeyNamePair)miniTable.getValueAt(i, 2); // 2-C_Payment_ID
|
||||
int C_Payment_ID = pp.getKey();
|
||||
pp = (KeyNamePair)miniTable.getValueAt(i, 3); // 3-Currency
|
||||
int C_Currency_ID = pp.getKey();
|
||||
BigDecimal TrxAmt = (BigDecimal)miniTable.getValueAt(i, 5); // 5- Conv Amt
|
||||
|
||||
log.fine("Line Date=" + trxDate
|
||||
+ ", Payment=" + C_Payment_ID + ", Currency=" + C_Currency_ID + ", Amt=" + TrxAmt);
|
||||
//
|
||||
MBankStatementLine bsl = new MBankStatementLine (bs);
|
||||
bsl.setStatementLineDate(trxDate);
|
||||
bsl.setPayment(new MPayment(Env.getCtx(), C_Payment_ID, trxName));
|
||||
|
||||
bsl.setTrxAmt(TrxAmt);
|
||||
bsl.setStmtAmt(TrxAmt);
|
||||
bsl.setC_Currency_ID(bankAccount.getC_Currency_ID());
|
||||
|
||||
if (!bsl.save())
|
||||
log.log(Level.SEVERE, "Line not created #" + i);
|
||||
} // if selected
|
||||
} // for all rows
|
||||
return true;
|
||||
} // save
|
||||
|
||||
@Override
|
||||
protected Vector<String> getOISColumnNames()
|
||||
{
|
||||
// Header Info
|
||||
Vector<String> columnNames = new Vector<String>(6);
|
||||
columnNames.add(Msg.getMsg(Env.getCtx(), "Select"));
|
||||
columnNames.add(Msg.translate(Env.getCtx(), "Date"));
|
||||
columnNames.add(Msg.getElement(Env.getCtx(), "C_Payment_ID"));
|
||||
columnNames.add(Msg.translate(Env.getCtx(), "C_Currency_ID"));
|
||||
columnNames.add(Msg.translate(Env.getCtx(), "Amount"));
|
||||
columnNames.add(Msg.translate(Env.getCtx(), "ConvertedAmount"));
|
||||
columnNames.add(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
|
||||
|
||||
return columnNames;
|
||||
}
|
||||
}
|
|
@ -160,6 +160,8 @@ public class VCreateFromDialog extends CDialog implements ActionListener, TableM
|
|||
count++;
|
||||
}
|
||||
setStatusLine(count, null);
|
||||
|
||||
createFrom.info();
|
||||
}
|
||||
|
||||
protected void setStatusLine(int selectedRowCount, String text)
|
||||
|
@ -182,4 +184,9 @@ public class VCreateFromDialog extends CDialog implements ActionListener, TableM
|
|||
{
|
||||
return parameterPanel;
|
||||
}
|
||||
|
||||
public ConfirmPanel getConfirmPanel()
|
||||
{
|
||||
return confirmPanel;
|
||||
}
|
||||
}
|
|
@ -36,7 +36,7 @@ public class VCreateFromFactory
|
|||
s_registeredClasses = new HashMap<Integer, Class<? extends ICreateFrom>>();
|
||||
s_registeredClasses.put(I_C_Invoice.Table_ID, VCreateFromInvoiceUI.class);
|
||||
|
||||
s_registeredClasses.put(I_C_BankStatement.Table_ID, VCreateFromStatement.class);
|
||||
s_registeredClasses.put(I_C_BankStatement.Table_ID, VCreateFromStatementUI.class);
|
||||
s_registeredClasses.put(I_M_InOut.Table_ID, VCreateFromShipment.class);
|
||||
s_registeredClasses.put(I_M_RMA.Table_ID, VCreateFromRMA.class);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,328 @@
|
|||
package org.compiere.grid;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Vector;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import org.compiere.apps.ADialog;
|
||||
import org.compiere.apps.AEnv;
|
||||
import org.compiere.apps.ConfirmPanel;
|
||||
import org.compiere.grid.ed.VDate;
|
||||
import org.compiere.grid.ed.VLookup;
|
||||
import org.compiere.grid.ed.VNumber;
|
||||
import org.compiere.grid.ed.VString;
|
||||
import org.compiere.model.GridTab;
|
||||
import org.compiere.model.MBankAccount;
|
||||
import org.compiere.model.MBankStatement;
|
||||
import org.compiere.model.MColumn;
|
||||
import org.compiere.model.MLookup;
|
||||
import org.compiere.model.MLookupFactory;
|
||||
import org.compiere.model.MPayment;
|
||||
import org.compiere.swing.CButton;
|
||||
import org.compiere.swing.CLabel;
|
||||
import org.compiere.swing.CPanel;
|
||||
import org.compiere.swing.CTextField;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
|
||||
public class VCreateFromStatementUI extends CreateFromStatement implements ActionListener
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private VCreateFromDialog dialog;
|
||||
|
||||
public VCreateFromStatementUI(GridTab mTab)
|
||||
{
|
||||
super(mTab);
|
||||
log.info(getGridTab().toString());
|
||||
|
||||
dialog = new VCreateFromDialog(this, getGridTab().getWindowNo(), true);
|
||||
|
||||
p_WindowNo = getGridTab().getWindowNo();
|
||||
|
||||
try
|
||||
{
|
||||
if (!dynInit())
|
||||
return;
|
||||
jbInit();
|
||||
|
||||
setInitOK(true);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, "", e);
|
||||
setInitOK(false);
|
||||
}
|
||||
AEnv.positionCenterWindow(Env.getWindow(p_WindowNo), dialog);
|
||||
} // VCreateFrom
|
||||
|
||||
/** Window No */
|
||||
private int p_WindowNo;
|
||||
|
||||
/** Logger */
|
||||
private CLogger log = CLogger.getCLogger(getClass());
|
||||
|
||||
private JLabel bankAccountLabel = new JLabel();
|
||||
protected VLookup bankAccountField;
|
||||
|
||||
private CLabel documentNoLabel = new CLabel(Msg.translate(Env.getCtx(), "DocumentNo"));
|
||||
protected CTextField documentNoField = new CTextField(10);
|
||||
|
||||
private JLabel documentTypeLabel = new JLabel();
|
||||
protected VLookup documentTypeField;
|
||||
|
||||
private JLabel authorizationLabel = new JLabel();
|
||||
protected VString authorizationField = new VString();
|
||||
|
||||
private JLabel tenderTypeLabel = new JLabel();
|
||||
protected VLookup tenderTypeField;
|
||||
|
||||
private CLabel amtFromLabel = new CLabel(Msg.translate(Env.getCtx(), "PayAmt"));
|
||||
protected VNumber amtFromField = new VNumber("AmtFrom", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtFrom"));
|
||||
private CLabel amtToLabel = new CLabel("-");
|
||||
protected VNumber amtToField = new VNumber("AmtTo", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtTo"));
|
||||
|
||||
protected CLabel BPartner_idLabel = new CLabel(Msg.translate(Env.getCtx(), "BPartner"));
|
||||
protected VLookup bPartnerLookup;
|
||||
|
||||
private CLabel dateFromLabel = new CLabel(Msg.translate(Env.getCtx(), "DateTrx"));
|
||||
protected VDate dateFromField = new VDate("DateFrom", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateFrom"));
|
||||
private CLabel dateToLabel = new CLabel("-");
|
||||
protected VDate dateToField = new VDate("DateTo", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateTo"));
|
||||
|
||||
|
||||
/**
|
||||
* Dynamic Init
|
||||
* @throws Exception if Lookups cannot be initialized
|
||||
* @return true if initialized
|
||||
*/
|
||||
public boolean dynInit() throws Exception
|
||||
{
|
||||
log.config("");
|
||||
|
||||
super.dynInit();
|
||||
|
||||
//Refresh button
|
||||
CButton refreshButton = ConfirmPanel.createRefreshButton(false);
|
||||
refreshButton.setMargin(new Insets (1, 10, 0, 10));
|
||||
refreshButton.setDefaultCapable(true);
|
||||
refreshButton.addActionListener(this);
|
||||
dialog.getConfirmPanel().addButton(refreshButton);
|
||||
dialog.getRootPane().setDefaultButton(refreshButton);
|
||||
|
||||
if (getGridTab().getValue("C_BankStatement_ID") == null)
|
||||
{
|
||||
ADialog.error(0, dialog, "SaveErrorRowNotFound");
|
||||
return false;
|
||||
}
|
||||
|
||||
dialog.setTitle(getTitle());
|
||||
|
||||
int AD_Column_ID = 4917; // C_BankStatement.C_BankAccount_ID
|
||||
MLookup lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, AD_Column_ID, DisplayType.TableDir);
|
||||
bankAccountField = new VLookup ("C_BankAccount_ID", true, true, true, lookup);
|
||||
// Set Default
|
||||
int C_BankAccount_ID = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "C_BankAccount_ID");
|
||||
bankAccountField.setValue(new Integer(C_BankAccount_ID));
|
||||
// initial Loading
|
||||
authorizationField = new VString ("authorization", false, false, true, 10, 30, null, null);
|
||||
authorizationField.addActionListener(this);
|
||||
|
||||
MLookup lookupDocument = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPayment.Table_Name, MPayment.COLUMNNAME_C_DocType_ID), DisplayType.TableDir);
|
||||
documentTypeField = new VLookup (MPayment.COLUMNNAME_C_DocType_ID,false,false,true,lookupDocument);
|
||||
documentTypeField.addActionListener(this);
|
||||
|
||||
MLookup lookupTender = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPayment.Table_Name, MPayment.COLUMNNAME_TenderType), DisplayType.List);
|
||||
tenderTypeField = new VLookup (MPayment.COLUMNNAME_TenderType,false,false,true,lookupTender);
|
||||
tenderTypeField.addActionListener(this);
|
||||
|
||||
bPartnerLookup = new VLookup("C_BPartner_ID", false, false, true,
|
||||
MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, 3499, DisplayType.Search));
|
||||
BPartner_idLabel.setLabelFor(bPartnerLookup);
|
||||
|
||||
Timestamp date = Env.getContextAsDate(Env.getCtx(), p_WindowNo, MBankStatement.COLUMNNAME_StatementDate);
|
||||
dateToField.setValue(date);
|
||||
|
||||
bankAccount = new MBankAccount(Env.getCtx(), C_BankAccount_ID, null);
|
||||
|
||||
loadBankAccount();
|
||||
|
||||
return true;
|
||||
} // dynInit
|
||||
|
||||
/**
|
||||
* Static Init.
|
||||
* <pre>
|
||||
* parameterPanel
|
||||
* parameterBankPanel
|
||||
* parameterStdPanel
|
||||
* bPartner/order/invoice/shopment/licator Label/Field
|
||||
* dataPane
|
||||
* southPanel
|
||||
* confirmPanel
|
||||
* statusBar
|
||||
* </pre>
|
||||
* @throws Exception
|
||||
*/
|
||||
private void jbInit() throws Exception
|
||||
{
|
||||
bankAccountLabel.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID"));
|
||||
authorizationLabel.setText(Msg.translate(Env.getCtx(), "R_AuthCode"));
|
||||
|
||||
documentTypeLabel.setText(Msg.translate(Env.getCtx(), "C_DocType_ID"));
|
||||
tenderTypeLabel.setText(Msg.translate(Env.getCtx(), "TenderType"));
|
||||
|
||||
documentNoLabel.setLabelFor(documentNoField);
|
||||
dateFromLabel.setLabelFor(dateFromField);
|
||||
dateFromField.setToolTipText(Msg.translate(Env.getCtx(), "DateFrom"));
|
||||
dateToLabel.setLabelFor(dateToField);
|
||||
dateToField.setToolTipText(Msg.translate(Env.getCtx(), "DateTo"));
|
||||
amtFromLabel.setLabelFor(amtFromField);
|
||||
amtFromField.setToolTipText(Msg.translate(Env.getCtx(), "AmtFrom"));
|
||||
amtToLabel.setLabelFor(amtToField);
|
||||
amtToField.setToolTipText(Msg.translate(Env.getCtx(), "AmtTo"));
|
||||
|
||||
CPanel parameterPanel = dialog.getParameterPanel();
|
||||
parameterPanel.setLayout(new BorderLayout());
|
||||
|
||||
CPanel parameterBankPanel = new CPanel();
|
||||
parameterBankPanel.setLayout(new GridBagLayout());
|
||||
parameterPanel.add(parameterBankPanel, BorderLayout.CENTER);
|
||||
|
||||
parameterBankPanel.add(bankAccountLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
if (bankAccountField != null)
|
||||
parameterBankPanel.add(bankAccountField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
|
||||
|
||||
parameterBankPanel.add(documentTypeLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
if(documentTypeField!= null)
|
||||
parameterBankPanel.add(documentTypeField, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
|
||||
|
||||
parameterBankPanel.add(tenderTypeLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
if(tenderTypeField!=null)
|
||||
parameterBankPanel.add(tenderTypeField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
|
||||
|
||||
parameterBankPanel.add(BPartner_idLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
parameterBankPanel.add(bPartnerLookup, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
|
||||
|
||||
parameterBankPanel.add(documentNoLabel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
parameterBankPanel.add(documentNoField, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
|
||||
|
||||
parameterBankPanel.add(authorizationLabel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
parameterBankPanel.add(authorizationField, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
|
||||
|
||||
parameterBankPanel.add(amtFromLabel, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
parameterBankPanel.add(amtFromField, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
|
||||
parameterBankPanel.add(amtToLabel, new GridBagConstraints(4, 2, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
parameterBankPanel.add(amtToField, new GridBagConstraints(5, 2, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
|
||||
|
||||
parameterBankPanel.add(dateFromLabel, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
parameterBankPanel.add(dateFromField, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
|
||||
parameterBankPanel.add(dateToLabel, new GridBagConstraints(4, 3, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
parameterBankPanel.add(dateToField, new GridBagConstraints(5, 3, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
|
||||
|
||||
} // jbInit
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Action Listener
|
||||
* @param e event
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
log.config("Action=" + e.getActionCommand());
|
||||
// Object source = e.getSource();
|
||||
if ( e.getActionCommand().equals(ConfirmPanel.A_REFRESH) )
|
||||
{
|
||||
Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
|
||||
loadBankAccount();
|
||||
dialog.tableChanged(null);
|
||||
Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
|
||||
}
|
||||
} // actionPerformed
|
||||
|
||||
protected void loadBankAccount()
|
||||
{
|
||||
loadTableOIS(getBankData(documentNoField.getText(), bPartnerLookup.getValue(), dateFromField.getValue(), dateToField.getValue(),
|
||||
amtFromField.getValue(), amtToField.getValue(), documentTypeField.getValue(), tenderTypeField.getValue(),
|
||||
authorizationField.getText()));
|
||||
}
|
||||
|
||||
protected void loadTableOIS (Vector<?> data)
|
||||
{
|
||||
// Remove previous listeners
|
||||
dialog.getMiniTable().getModel().removeTableModelListener(dialog);
|
||||
// Set Model
|
||||
DefaultTableModel model = new DefaultTableModel(data, getOISColumnNames());
|
||||
model.addTableModelListener(dialog);
|
||||
dialog.getMiniTable().setModel(model);
|
||||
//
|
||||
|
||||
configureMiniTable(dialog.getMiniTable());
|
||||
}
|
||||
|
||||
/**
|
||||
* List total amount
|
||||
*/
|
||||
public void info()
|
||||
{
|
||||
DecimalFormat format = DisplayType.getNumberFormat(DisplayType.Amount);
|
||||
|
||||
BigDecimal total = new BigDecimal(0.0);
|
||||
int rows = dialog.getMiniTable().getRowCount();
|
||||
int count = 0;
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
if (((Boolean)dialog.getMiniTable().getValueAt(i, 0)).booleanValue())
|
||||
{
|
||||
total = total.add((BigDecimal)dialog.getMiniTable().getValueAt(i, 4));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
dialog.setStatusLine(count, Msg.getMsg(Env.getCtx(), "Sum") + " " + format.format(total));
|
||||
} // infoStatement
|
||||
|
||||
public void showWindow()
|
||||
{
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
|
||||
public void closeWindow()
|
||||
{
|
||||
dialog.dispose();
|
||||
}
|
||||
}
|
|
@ -40,7 +40,7 @@ public class WCreateFromFactory
|
|||
s_registeredClasses = new HashMap<Integer, Class<? extends ICreateFrom>>();
|
||||
s_registeredClasses.put(I_C_Invoice.Table_ID, WCreateFromInvoiceUI.class);
|
||||
|
||||
s_registeredClasses.put(I_C_BankStatement.Table_ID, WCreateFromStatement.class);
|
||||
s_registeredClasses.put(I_C_BankStatement.Table_ID, WCreateFromStatementUI.class);
|
||||
s_registeredClasses.put(I_M_InOut.Table_ID, WCreateFromShipment.class);
|
||||
s_registeredClasses.put(I_M_RMA.Table_ID, WCreateFromRMA.class);
|
||||
}
|
||||
|
|
|
@ -134,7 +134,6 @@ public class WCreateFromInvoiceUI extends CreateFromInvoice implements EventList
|
|||
parameterLayout.appendChild(center);
|
||||
center.appendChild(parameterStdPanel);
|
||||
|
||||
parameterStdPanel.appendChild(parameterStdLayout);
|
||||
Rows rows = (Rows) parameterStdLayout.newRows();
|
||||
Row row = rows.newRow();
|
||||
row.appendChild(bPartnerLabel.rightAlign());
|
||||
|
@ -347,10 +346,10 @@ public class WCreateFromInvoiceUI extends CreateFromInvoice implements EventList
|
|||
window.getWListbox().clear();
|
||||
|
||||
// Remove previous listeners
|
||||
window.getWListbox().getModel().removeTableModelListener(window.getWListbox());
|
||||
window.getWListbox().getModel().removeTableModelListener(window);
|
||||
// Set Model
|
||||
ListModelTable model = new ListModelTable(data);
|
||||
model.addTableModelListener(window.getWListbox());
|
||||
model.addTableModelListener(window);
|
||||
window.getWListbox().setData(model, getOISColumnNames());
|
||||
//
|
||||
|
||||
|
|
|
@ -0,0 +1,298 @@
|
|||
package org.adempiere.webui.apps.form;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Vector;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.webui.apps.AEnv;
|
||||
import org.adempiere.webui.component.Button;
|
||||
import org.adempiere.webui.component.ConfirmPanel;
|
||||
import org.adempiere.webui.component.Grid;
|
||||
import org.adempiere.webui.component.GridFactory;
|
||||
import org.adempiere.webui.component.Label;
|
||||
import org.adempiere.webui.component.ListModelTable;
|
||||
import org.adempiere.webui.component.Panel;
|
||||
import org.adempiere.webui.component.Row;
|
||||
import org.adempiere.webui.component.Rows;
|
||||
import org.adempiere.webui.editor.WDateEditor;
|
||||
import org.adempiere.webui.editor.WEditor;
|
||||
import org.adempiere.webui.editor.WNumberEditor;
|
||||
import org.adempiere.webui.editor.WSearchEditor;
|
||||
import org.adempiere.webui.editor.WStringEditor;
|
||||
import org.adempiere.webui.editor.WTableDirEditor;
|
||||
import org.adempiere.webui.window.FDialog;
|
||||
import org.compiere.grid.CreateFromStatement;
|
||||
import org.compiere.model.GridTab;
|
||||
import org.compiere.model.MBankAccount;
|
||||
import org.compiere.model.MBankStatement;
|
||||
import org.compiere.model.MColumn;
|
||||
import org.compiere.model.MLookup;
|
||||
import org.compiere.model.MLookupFactory;
|
||||
import org.compiere.model.MPayment;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zk.ui.event.Events;
|
||||
import org.zkoss.zkex.zul.Borderlayout;
|
||||
import org.zkoss.zkex.zul.Center;
|
||||
import org.zkoss.zul.Hbox;
|
||||
|
||||
public class WCreateFromStatementUI extends CreateFromStatement implements EventListener
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private WCreateFromWindow window;
|
||||
|
||||
public WCreateFromStatementUI(GridTab tab)
|
||||
{
|
||||
super(tab);
|
||||
log.info(getGridTab().toString());
|
||||
|
||||
window = new WCreateFromWindow(this, getGridTab().getWindowNo());
|
||||
|
||||
p_WindowNo = getGridTab().getWindowNo();
|
||||
|
||||
try
|
||||
{
|
||||
if (!dynInit())
|
||||
return;
|
||||
zkInit();
|
||||
setInitOK(true);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, "", e);
|
||||
setInitOK(false);
|
||||
}
|
||||
AEnv.showWindow(window);
|
||||
}
|
||||
|
||||
/** Window No */
|
||||
private int p_WindowNo;
|
||||
|
||||
/** Logger */
|
||||
private CLogger log = CLogger.getCLogger(getClass());
|
||||
|
||||
protected Label bankAccountLabel = new Label();
|
||||
protected WTableDirEditor bankAccountField;
|
||||
|
||||
protected Label documentNoLabel = new Label(Msg.translate(Env.getCtx(), "DocumentNo"));
|
||||
protected WStringEditor documentNoField = new WStringEditor();
|
||||
|
||||
protected Label documentTypeLabel = new Label();
|
||||
protected WTableDirEditor documentTypeField;
|
||||
|
||||
protected Label authorizationLabel = new Label();
|
||||
protected WStringEditor authorizationField = new WStringEditor();
|
||||
|
||||
protected Label tenderTypeLabel = new Label();
|
||||
protected WTableDirEditor tenderTypeField;
|
||||
|
||||
protected Label amtFromLabel = new Label(Msg.translate(Env.getCtx(), "PayAmt"));
|
||||
protected WNumberEditor amtFromField = new WNumberEditor("AmtFrom", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtFrom"));
|
||||
protected Label amtToLabel = new Label("-");
|
||||
protected WNumberEditor amtToField = new WNumberEditor("AmtTo", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtTo"));
|
||||
|
||||
protected Label BPartner_idLabel = new Label(Msg.translate(Env.getCtx(), "BPartner"));
|
||||
protected WEditor bPartnerLookup;
|
||||
|
||||
protected Label dateFromLabel = new Label(Msg.translate(Env.getCtx(), "DateTrx"));
|
||||
protected WDateEditor dateFromField = new WDateEditor("DateFrom", false, false, true, Msg.translate(Env.getCtx(), "DateFrom"));
|
||||
protected Label dateToLabel = new Label("-");
|
||||
protected WDateEditor dateToField = new WDateEditor("DateTo", false, false, true, Msg.translate(Env.getCtx(), "DateTo"));
|
||||
|
||||
/**
|
||||
* Dynamic Init
|
||||
* @throws Exception if Lookups cannot be initialized
|
||||
* @return true if initialized
|
||||
*/
|
||||
public boolean dynInit() throws Exception
|
||||
{
|
||||
log.config("");
|
||||
|
||||
super.dynInit();
|
||||
|
||||
//Refresh button
|
||||
Button refreshButton = window.getConfirmPanel().createButton(ConfirmPanel.A_REFRESH);
|
||||
refreshButton.addEventListener(Events.ON_CLICK, this);
|
||||
window.getConfirmPanel().addButton(refreshButton);
|
||||
|
||||
if (getGridTab().getValue("C_BankStatement_ID") == null)
|
||||
{
|
||||
FDialog.error(0, window, "SaveErrorRowNotFound");
|
||||
return false;
|
||||
}
|
||||
|
||||
window.setTitle(getTitle());
|
||||
|
||||
authorizationField = new WStringEditor ("authorization", false, false, true, 10, 30, null, null);
|
||||
authorizationField.getComponent().addEventListener(Events.ON_CHANGE, this);
|
||||
|
||||
int AD_Column_ID = 4917; // C_BankStatement.C_BankAccount_ID
|
||||
MLookup lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, AD_Column_ID, DisplayType.TableDir);
|
||||
bankAccountField = new WTableDirEditor ("C_BankAccount_ID", true, false, true, lookup);
|
||||
// Set Default
|
||||
int C_BankAccount_ID = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "C_BankAccount_ID");
|
||||
bankAccountField.setValue(new Integer(C_BankAccount_ID));
|
||||
// initial Loading
|
||||
authorizationField = new WStringEditor ("authorization", false, false, true, 10, 30, null, null);
|
||||
authorizationField.getComponent().addEventListener(Events.ON_CHANGE, this);
|
||||
|
||||
lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPayment.Table_Name, MPayment.COLUMNNAME_C_DocType_ID), DisplayType.TableDir);
|
||||
documentTypeField = new WTableDirEditor (MPayment.COLUMNNAME_C_DocType_ID,false,false,true,lookup);
|
||||
documentTypeField.getComponent().addEventListener(Events.ON_CHANGE, this);
|
||||
|
||||
lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPayment.Table_Name, MPayment.COLUMNNAME_TenderType), DisplayType.List);
|
||||
tenderTypeField = new WTableDirEditor (MPayment.COLUMNNAME_TenderType,false,false,true,lookup);
|
||||
tenderTypeField.getComponent().addEventListener(Events.ON_CHANGE, this);
|
||||
|
||||
lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, 3499, DisplayType.Search);
|
||||
bPartnerLookup = new WSearchEditor ("C_BPartner_ID", false, false, true, lookup);
|
||||
|
||||
Timestamp date = Env.getContextAsDate(Env.getCtx(), p_WindowNo, MBankStatement.COLUMNNAME_StatementDate);
|
||||
dateToField.setValue(date);
|
||||
|
||||
bankAccount = new MBankAccount(Env.getCtx(), C_BankAccount_ID, null);
|
||||
|
||||
loadBankAccount();
|
||||
|
||||
return true;
|
||||
} // dynInit
|
||||
|
||||
protected void zkInit() throws Exception
|
||||
{
|
||||
bankAccountLabel.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID"));
|
||||
authorizationLabel.setText(Msg.translate(Env.getCtx(), "R_AuthCode"));
|
||||
|
||||
documentTypeLabel.setText(Msg.translate(Env.getCtx(), "C_DocType_ID"));
|
||||
tenderTypeLabel.setText(Msg.translate(Env.getCtx(), "TenderType"));
|
||||
|
||||
dateFromField.getComponent().setTooltiptext(Msg.translate(Env.getCtx(), "DateFrom"));
|
||||
dateToField.getComponent().setTooltiptext(Msg.translate(Env.getCtx(), "DateTo"));
|
||||
|
||||
amtFromField.getComponent().setTooltiptext(Msg.translate(Env.getCtx(), "AmtFrom"));
|
||||
amtToField.getComponent().setTooltiptext(Msg.translate(Env.getCtx(), "AmtTo"));
|
||||
|
||||
Borderlayout parameterLayout = new Borderlayout();
|
||||
parameterLayout.setHeight("110px");
|
||||
parameterLayout.setWidth("100%");
|
||||
Panel parameterPanel = window.getParameterPanel();
|
||||
parameterPanel.appendChild(parameterLayout);
|
||||
|
||||
Grid parameterBankLayout = GridFactory.newGridLayout();
|
||||
Panel parameterBankPanel = new Panel();
|
||||
parameterBankPanel.appendChild(parameterBankLayout);
|
||||
|
||||
Center center = new Center();
|
||||
parameterLayout.appendChild(center);
|
||||
center.appendChild(parameterBankPanel);
|
||||
|
||||
Rows rows = (Rows) parameterBankLayout.newRows();
|
||||
Row row = rows.newRow();
|
||||
row.appendChild(bankAccountLabel.rightAlign());
|
||||
row.appendChild(bankAccountField.getComponent());
|
||||
row.appendChild(documentNoLabel.rightAlign());
|
||||
row.appendChild(documentNoField.getComponent());
|
||||
|
||||
row = rows.newRow();
|
||||
row.appendChild(documentTypeLabel.rightAlign());
|
||||
row.appendChild(documentTypeField.getComponent());
|
||||
row.appendChild(authorizationLabel.rightAlign());
|
||||
row.appendChild(authorizationField.getComponent());
|
||||
|
||||
row = rows.newRow();
|
||||
row.appendChild(tenderTypeLabel.rightAlign());
|
||||
row.appendChild(tenderTypeField.getComponent());
|
||||
|
||||
row.appendChild(amtFromLabel.rightAlign());
|
||||
Hbox hbox = new Hbox();
|
||||
hbox.appendChild(amtFromField.getComponent());
|
||||
hbox.appendChild(amtToLabel.rightAlign());
|
||||
hbox.appendChild(amtToField.getComponent());
|
||||
row.appendChild(hbox);
|
||||
|
||||
row = rows.newRow();
|
||||
row.appendChild(BPartner_idLabel.rightAlign());
|
||||
row.appendChild(bPartnerLookup.getComponent());
|
||||
row.appendChild(dateFromLabel.rightAlign());
|
||||
|
||||
hbox = new Hbox();
|
||||
hbox.appendChild(dateFromField.getComponent());
|
||||
hbox.appendChild(dateToLabel.rightAlign());
|
||||
hbox.appendChild(dateToField.getComponent());
|
||||
row.appendChild(hbox);
|
||||
}
|
||||
|
||||
/**
|
||||
* Action Listener
|
||||
* @param e event
|
||||
* @throws Exception
|
||||
*/
|
||||
public void onEvent(Event e) throws Exception
|
||||
{
|
||||
log.config("Action=" + e.getTarget().getId());
|
||||
if(e.getTarget().equals(window.getConfirmPanel().getButton(ConfirmPanel.A_REFRESH)))
|
||||
{
|
||||
loadBankAccount();
|
||||
window.tableChanged(null);
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadBankAccount()
|
||||
{
|
||||
loadTableOIS(getBankData(documentNoField.getValue().toString(), bPartnerLookup.getValue(), dateFromField.getValue(), dateToField.getValue(),
|
||||
amtFromField.getValue(), amtToField.getValue(), documentTypeField.getValue(), tenderTypeField.getValue(),
|
||||
authorizationField.getValue().toString()));
|
||||
}
|
||||
|
||||
protected void loadTableOIS (Vector<?> data)
|
||||
{
|
||||
window.getWListbox().clear();
|
||||
|
||||
// Remove previous listeners
|
||||
window.getWListbox().getModel().removeTableModelListener(window);
|
||||
// Set Model
|
||||
ListModelTable model = new ListModelTable(data);
|
||||
model.addTableModelListener(window);
|
||||
window.getWListbox().setData(model, getOISColumnNames());
|
||||
//
|
||||
|
||||
configureMiniTable(window.getWListbox());
|
||||
}
|
||||
|
||||
/**
|
||||
* List total amount
|
||||
*/
|
||||
public void info()
|
||||
{
|
||||
DecimalFormat format = DisplayType.getNumberFormat(DisplayType.Amount);
|
||||
|
||||
BigDecimal total = new BigDecimal(0.0);
|
||||
int rows = window.getWListbox().getRowCount();
|
||||
int count = 0;
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
if (((Boolean)window.getWListbox().getValueAt(i, 0)).booleanValue())
|
||||
{
|
||||
total = total.add((BigDecimal)window.getWListbox().getValueAt(i, 4));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
window.setStatusLine(count, Msg.getMsg(Env.getCtx(), "Sum") + " " + format.format(total));
|
||||
} // infoStatement
|
||||
|
||||
public void showWindow()
|
||||
{
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
public void closeWindow()
|
||||
{
|
||||
window.dispose();
|
||||
}
|
||||
}
|
|
@ -195,4 +195,9 @@ public class WCreateFromWindow extends Window implements EventListener, WTableMo
|
|||
{
|
||||
return parameterPanel;
|
||||
}
|
||||
|
||||
public ConfirmPanel getConfirmPanel()
|
||||
{
|
||||
return confirmPanel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -194,7 +194,6 @@ public class WGenForm extends ADForm implements EventListener, WTableModelListen
|
|||
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);
|
||||
|
@ -306,7 +305,7 @@ public class WGenForm extends ADForm implements EventListener, WTableModelListen
|
|||
};
|
||||
new Thread(runnable).start();
|
||||
//
|
||||
} // generateShipments
|
||||
} // generate
|
||||
|
||||
/**
|
||||
* Complete generating shipments.
|
||||
|
@ -324,7 +323,7 @@ public class WGenForm extends ADForm implements EventListener, WTableModelListen
|
|||
StringBuffer iText = new StringBuffer();
|
||||
iText.append("<b>").append(genForm.getProcessInfo().getSummary())
|
||||
.append("</b><br>(")
|
||||
.append(Msg.getMsg(Env.getCtx(), "InOutGenerateInfo"))
|
||||
.append(Msg.getMsg(Env.getCtx(), genForm.getTitle()))
|
||||
// Shipments are generated depending on the Delivery Rule selection in the Order
|
||||
.append(")<br>")
|
||||
.append(genForm.getProcessInfo().getLogInfo(true));
|
||||
|
@ -344,29 +343,28 @@ public class WGenForm extends ADForm implements EventListener, WTableModelListen
|
|||
|
||||
public void onAfterProcess()
|
||||
{
|
||||
// OK to print shipments
|
||||
if (FDialog.ask(getWindowNo(), this, "PrintShipments"))
|
||||
// OK to print
|
||||
if (FDialog.ask(getWindowNo(), this, genForm.getAskPrintMsg()))
|
||||
{
|
||||
// info.append("\n\n" + Msg.getMsg(Env.getCtx(), "PrintShipments"));
|
||||
Clients.showBusy("Processing...", true);
|
||||
Clients.response(new AuEcho(this, "onPrintShipments", null));
|
||||
} // OK to print shipments
|
||||
Clients.response(new AuEcho(this, "onPrint", null));
|
||||
} // OK to print
|
||||
}
|
||||
|
||||
public void onPrintShipments()
|
||||
public void onPrint()
|
||||
{
|
||||
// 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);
|
||||
int RecordID = m_ids[i];
|
||||
ReportEngine re = ReportEngine.get (Env.getCtx(), genForm.getReportEngineType(), RecordID);
|
||||
pdfList.add(re.getPDF());
|
||||
}
|
||||
|
||||
if (pdfList.size() > 1) {
|
||||
try {
|
||||
File outFile = File.createTempFile("WInOutGen", ".pdf");
|
||||
File outFile = File.createTempFile(genForm.getClass().getName(), ".pdf");
|
||||
AEnv.mergePdf(pdfList, outFile);
|
||||
|
||||
Clients.showBusy(null, false);
|
||||
|
|
|
@ -25,6 +25,8 @@ 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.panel.ADForm;
|
||||
import org.adempiere.webui.panel.ICustomForm;
|
||||
import org.compiere.apps.form.InOutGen;
|
||||
import org.compiere.model.MLookup;
|
||||
import org.compiere.model.MLookupFactory;
|
||||
|
@ -44,7 +46,7 @@ import org.zkoss.zul.Space;
|
|||
* Generate Shipment (manual) view class
|
||||
*
|
||||
*/
|
||||
public class WInOutGen extends InOutGen implements EventListener, ValueChangeListener
|
||||
public class WInOutGen extends InOutGen implements ICustomForm, EventListener, ValueChangeListener
|
||||
{
|
||||
private static WGenForm form;
|
||||
|
||||
|
@ -69,6 +71,7 @@ public class WInOutGen extends InOutGen implements EventListener, ValueChangeLis
|
|||
|
||||
try
|
||||
{
|
||||
super.dynInit();
|
||||
dynInit();
|
||||
zkInit();
|
||||
|
||||
|
@ -146,6 +149,8 @@ public class WInOutGen extends InOutGen implements EventListener, ValueChangeLis
|
|||
cmbDocType.addItem(new KeyNamePair(MRMA.Table_ID, Msg.translate(Env.getCtx(), "VendorRMA")));
|
||||
cmbDocType.addActionListener(form);
|
||||
cmbDocType.setSelectedIndex(0);
|
||||
|
||||
form.getStatusBar().setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateSel"));//@@
|
||||
} // fillPicks
|
||||
|
||||
/**
|
||||
|
@ -223,7 +228,7 @@ public class WInOutGen extends InOutGen implements EventListener, ValueChangeLis
|
|||
return generate(form.getStatusBar(), docTypeKNPair, docActionSelected);
|
||||
} // generateShipments
|
||||
|
||||
public Object getForm()
|
||||
public ADForm getForm()
|
||||
{
|
||||
return form;
|
||||
}
|
||||
|
|
|
@ -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,161 +10,77 @@
|
|||
* 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.List;
|
||||
import java.util.EventListener;
|
||||
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.adempiere.webui.panel.ICustomForm;
|
||||
import org.compiere.apps.form.InvoiceGen;
|
||||
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.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
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 Invoice Selection
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: VInvoiceGen.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
|
||||
* Generate Invoice (manual) view class
|
||||
*
|
||||
*/
|
||||
public class WInvoiceGen extends ADForm
|
||||
implements EventListener, ValueChangeListener, WTableModelListener
|
||||
public class WInvoiceGen extends InvoiceGen implements ICustomForm, EventListener, ValueChangeListener
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 8563031560168180223L;
|
||||
|
||||
/**
|
||||
* Initialize Panel
|
||||
*/
|
||||
protected void initForm()
|
||||
private static WGenForm form;
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(WInOutGen.class);
|
||||
//
|
||||
private Label lOrg = new Label();
|
||||
private WTableDirEditor fOrg;
|
||||
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 WInvoiceGen()
|
||||
{
|
||||
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();
|
||||
super.dynInit();
|
||||
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();
|
||||
|
||||
form.postQueryEvent();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
log.log(Level.SEVERE, "init", ex);
|
||||
}
|
||||
} // init
|
||||
|
||||
private boolean m_selectionActive = true;
|
||||
private Object m_AD_Org_ID = null;
|
||||
private Object m_C_BPartner_ID = null;
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(WInvoiceGen.class);
|
||||
//
|
||||
private Tabbox tabbedPane = new Tabbox();
|
||||
private Borderlayout selPanel = new Borderlayout();
|
||||
private Grid selNorthPanel = GridFactory.newGridLayout();
|
||||
private Label lOrg = new Label();
|
||||
private WTableDirEditor fOrg;
|
||||
private Label lBPartner = new Label();
|
||||
private WSearchEditor fBPartner;
|
||||
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 WListbox miniTable = ListboxFactory.newDataTable();
|
||||
private ArrayList<Integer> selections = null;
|
||||
|
||||
private Label lDocType = new Label();
|
||||
private Listbox cmbDocType = ListboxFactory.newDropdownListbox();
|
||||
private Label lDocAction = new Label();
|
||||
private WTableDirEditor docAction;
|
||||
private ProcessInfo m_pi;
|
||||
private int[] m_ids;
|
||||
|
||||
/**
|
||||
* Static Init.
|
||||
|
@ -179,26 +95,10 @@ public class WInvoiceGen extends ADForm
|
|||
*/
|
||||
void zkInit() throws Exception
|
||||
{
|
||||
//
|
||||
selPanel.setWidth("99%");
|
||||
selPanel.setHeight("90%");
|
||||
selPanel.setStyle("border: none; position: absolute");
|
||||
lOrg.setText(Msg.translate(Env.getCtx(), "AD_Org_ID"));
|
||||
lBPartner.setText(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
|
||||
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);
|
||||
lBPartner.setText("BPartner");
|
||||
|
||||
North north = new North();
|
||||
selPanel.appendChild(north);
|
||||
north.appendChild(selNorthPanel);
|
||||
Row row = selNorthPanel.newRows().newRow();
|
||||
Row row = form.getParameterPanel().newRows().newRow();
|
||||
row.appendChild(lOrg.rightAlign());
|
||||
row.appendChild(fOrg.getComponent());
|
||||
row.appendChild(new Space());
|
||||
|
@ -206,65 +106,35 @@ public class WInvoiceGen extends ADForm
|
|||
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);
|
||||
row.appendChild(lDocType.rightAlign());
|
||||
row.appendChild(cmbDocType);
|
||||
row.appendChild(new Space());
|
||||
row.appendChild(lDocAction.rightAlign());
|
||||
row.appendChild(docAction.getComponent());
|
||||
row.appendChild(new Space());
|
||||
form.getParameterPanel().getRows().appendChild(row);
|
||||
row.appendChild(lDocType.rightAlign());
|
||||
row.appendChild(cmbDocType);
|
||||
row.appendChild(new Space());
|
||||
row.appendChild(lDocAction.rightAlign());
|
||||
row.appendChild(docAction.getComponent());
|
||||
row.appendChild(new Space());
|
||||
} // jbInit
|
||||
|
||||
/**
|
||||
* Fill Picks
|
||||
* Fill Picks.
|
||||
* Column_ID from C_Order
|
||||
* @throws Exception if Lookups cannot be initialized
|
||||
*/
|
||||
private void fillPicks() throws Exception
|
||||
public void dynInit() throws Exception
|
||||
{
|
||||
MLookup orgL = MLookupFactory.get (Env.getCtx(), m_WindowNo, 0, 2163, DisplayType.TableDir);
|
||||
MLookup orgL = MLookupFactory.get (Env.getCtx(), form.getWindowNo(), 0, 2163, DisplayType.TableDir);
|
||||
fOrg = new WTableDirEditor ("AD_Org_ID", false, false, true, orgL);
|
||||
// lOrg.setText(Msg.translate(Env.getCtx(), "AD_Org_ID"));
|
||||
fOrg.addValueChangeListener(this);
|
||||
//
|
||||
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);
|
||||
// Document Action Prepared/ Completed
|
||||
lDocAction.setText(Msg.translate(Env.getCtx(), "DocAction"));
|
||||
MLookup docActionL = MLookupFactory.get(Env.getCtx(), m_WindowNo, 3495 /* C_Invoice.DocAction */,
|
||||
MLookup docActionL = MLookupFactory.get(Env.getCtx(), form.getWindowNo(), 3495 /* C_Invoice.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);
|
||||
|
@ -275,230 +145,54 @@ public class WInvoiceGen extends ADForm
|
|||
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);
|
||||
|
||||
form.getStatusBar().setStatusLine(Msg.getMsg(Env.getCtx(), "InvGenerateSel"));//@@
|
||||
} // 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);
|
||||
// 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(), "InvGenerateSel"));
|
||||
statusBar.setStatusDB(" ");
|
||||
// Tabbed Pane Listener
|
||||
tabbedPane.addEventListener(Events.ON_SELECT, this);
|
||||
} // dynInit
|
||||
|
||||
private String getOrderSQL()
|
||||
{
|
||||
StringBuffer sql = new StringBuffer(
|
||||
"SELECT C_Order_ID, o.Name, dt.Name, DocumentNo, bp.Name, DateOrdered, TotalLines "
|
||||
+ "FROM C_Invoice_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_AD_Org_ID != null)
|
||||
sql.append(" AND ic.AD_Org_ID=").append(m_AD_Org_ID);
|
||||
if (m_C_BPartner_ID != null)
|
||||
sql.append(" AND ic.C_BPartner_ID=").append(m_C_BPartner_ID);
|
||||
|
||||
// bug - [ 1713337 ] "Generate Invoices (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();
|
||||
}
|
||||
|
||||
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 NOT EXISTS (SELECT * FROM C_Invoice i ");
|
||||
sql.append("WHERE i.M_RMA_ID=rma.M_RMA_ID AND i.DocStatus IN ('IP', 'CO', 'CL')) ");
|
||||
sql.append("AND EXISTS (SELECT * FROM C_InvoiceLine il INNER JOIN M_InOutLine iol ");
|
||||
sql.append("ON il.M_InOutLine_ID=iol.M_InOutLine_ID INNER JOIN C_Invoice i ");
|
||||
sql.append("ON i.C_Invoice_ID=il.C_Invoice_ID WHERE i.DocStatus IN ('CO', 'CL') ");
|
||||
sql.append("AND iol.M_InOutLine_ID IN ");
|
||||
sql.append("(SELECT M_InOutLine_ID FROM M_RMALine rl WHERE rl.M_RMA_ID=rma.M_RMA_ID ");
|
||||
sql.append("AND rl.M_InOutLine_ID IS NOT NULL)) ");
|
||||
sql.append("AND rma.AD_Client_ID=?");
|
||||
|
||||
if (m_AD_Org_ID != null)
|
||||
sql.append(" AND rma.AD_Org_ID=").append(m_AD_Org_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());
|
||||
// Create SQL
|
||||
|
||||
String sql = "";
|
||||
|
||||
KeyNamePair docTypeKNPair = cmbDocType.getSelectedItem().toKeyNamePair();
|
||||
|
||||
if (docTypeKNPair.getKey() == MOrder.Table_ID)
|
||||
{
|
||||
sql = getOrderSQL();
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = getRMASql();
|
||||
}
|
||||
|
||||
// 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()));
|
||||
KeyNamePair docTypeKNPair = cmbDocType.getSelectedItem().toKeyNamePair();
|
||||
executeQuery(docTypeKNPair, form.getMiniTable());
|
||||
form.getMiniTable().repaint();
|
||||
form.invalidate();
|
||||
} // executeQuery
|
||||
|
||||
/**
|
||||
* Action Listener
|
||||
* @param e event
|
||||
*/
|
||||
public void onEvent (Event e)
|
||||
public void onEvent(Event e)
|
||||
{
|
||||
log.info("Cmd=" + e.getTarget().getId());
|
||||
//
|
||||
if (e.getTarget().getId().equals(ConfirmPanel.A_CANCEL))
|
||||
if(cmbDocType.equals(e.getTarget()))
|
||||
{
|
||||
dispose();
|
||||
return;
|
||||
form.postQueryEvent();
|
||||
return;
|
||||
}
|
||||
else if (e.getTarget() instanceof Tab)
|
||||
{
|
||||
int index = tabbedPane.getSelectedIndex();
|
||||
m_selectionActive = (index == 0);
|
||||
return;
|
||||
}
|
||||
else if (cmbDocType.equals(e.getTarget()))
|
||||
{
|
||||
postQueryEvent();
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
saveSelection();
|
||||
if (selections != null && selections.size() > 0 && m_selectionActive)
|
||||
generateInvoices ();
|
||||
else
|
||||
dispose();
|
||||
validate();
|
||||
} // actionPerformed
|
||||
|
||||
public void validate()
|
||||
{
|
||||
form.saveSelection();
|
||||
|
||||
ArrayList<Integer> selection = getSelection();
|
||||
if (selection != null && selection.size() > 0 && isSelectionActive())
|
||||
form.generate();
|
||||
else
|
||||
form.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Vetoable Change Listener - requery
|
||||
* Value Change Listener - requery
|
||||
* @param e event
|
||||
*/
|
||||
public void valueChange(ValueChangeEvent e)
|
||||
|
@ -511,289 +205,21 @@ public class WInvoiceGen extends ADForm
|
|||
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
|
||||
*/
|
||||
private void saveSelection()
|
||||
{
|
||||
log.info("");
|
||||
// Array of Integers
|
||||
ArrayList<Integer> results = new ArrayList<Integer>();
|
||||
selections = 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;
|
||||
|
||||
selections = results;
|
||||
} // saveSelection
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Generate Invoices
|
||||
* Generate Shipments
|
||||
*/
|
||||
private void generateInvoices ()
|
||||
{
|
||||
String trxName = Trx.createTrxName("IVG");
|
||||
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(), "InvGenerateGen"));
|
||||
statusBar.setStatusDB(String.valueOf(selections.size()));
|
||||
|
||||
// Prepare Process
|
||||
int AD_Process_ID = 0;
|
||||
KeyNamePair docTypeKNPair = cmbDocType.getSelectedItem().toKeyNamePair();
|
||||
|
||||
if (docTypeKNPair.getKey() == MRMA.Table_ID)
|
||||
{
|
||||
AD_Process_ID = 52002; // C_Invoice_GenerateRMA - org.adempiere.process.InvoiceGenerateRMA
|
||||
}
|
||||
else
|
||||
{
|
||||
AD_Process_ID = 134; // HARDCODED C_InvoiceCreate
|
||||
}
|
||||
|
||||
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 : selections)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
m_pi = new ProcessInfo ("", AD_Process_ID);
|
||||
m_pi.setAD_PInstance_ID (instance.getAD_PInstance_ID());
|
||||
|
||||
// Add Parameters
|
||||
MPInstancePara para = new MPInstancePara(instance, 10);
|
||||
para.setParameter("Selection", "Y");
|
||||
if (!para.save())
|
||||
{
|
||||
String msg = "No Selection Parameter added"; // not translated
|
||||
info.setContent(msg);
|
||||
log.log(Level.SEVERE, msg);
|
||||
return;
|
||||
}
|
||||
//Add Document action parameter
|
||||
para = new MPInstancePara(instance, 20);
|
||||
String docActionSelected = (String)docAction.getValue();
|
||||
para.setParameter("DocAction", docActionSelected);
|
||||
if (!para.save())
|
||||
{
|
||||
String msg = "No DocAction 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 = WInvoiceGen.this.getDesktop();
|
||||
try {
|
||||
Executions.activate(desktop);
|
||||
try {
|
||||
worker.run(); // complete tasks in unlockUI / generateInvoice_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();
|
||||
} // generateInvoices
|
||||
|
||||
/**
|
||||
* Complete generating invoices.
|
||||
* Called from Unlock UI
|
||||
*/
|
||||
private void generateInvoice_complete ()
|
||||
public String generate()
|
||||
{
|
||||
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(), "InvGenerateInfo"))
|
||||
//Invoices are generated depending on the Invoicing Rule selection in the Order
|
||||
.append(")<br>")
|
||||
.append(m_pi.getLogInfo(true));
|
||||
info.setContent(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 = m_pi.getIDs();
|
||||
if (ids == null || ids.length == 0)
|
||||
return;
|
||||
|
||||
m_ids = ids;
|
||||
Clients.response(new AuEcho(this, "onAfterProcess", null));
|
||||
|
||||
} // generateInvoices_complete
|
||||
KeyNamePair docTypeKNPair = (KeyNamePair)cmbDocType.getSelectedItem().toKeyNamePair();
|
||||
String docActionSelected = (String)docAction.getValue();
|
||||
return generate(form.getStatusBar(), docTypeKNPair, docActionSelected);
|
||||
} // generateShipments
|
||||
|
||||
public void onAfterProcess()
|
||||
public ADForm getForm()
|
||||
{
|
||||
// OK to print invoices
|
||||
if (FDialog.ask(m_WindowNo, this, "PrintInvoices"))
|
||||
{
|
||||
Clients.showBusy("Processing...", true);
|
||||
Clients.response(new AuEcho(this, "onPrintInvoices", null));
|
||||
} // OK to print invoices
|
||||
return form;
|
||||
}
|
||||
|
||||
public void onPrintInvoices()
|
||||
{
|
||||
// Loop through all items
|
||||
List<File> pdfList = new ArrayList<File>();
|
||||
for (int i = 0; i < m_ids.length; i++)
|
||||
{
|
||||
int C_Invoice_ID = m_ids[i];
|
||||
ReportEngine re = ReportEngine.get (Env.getCtx(), ReportEngine.INVOICE, C_Invoice_ID);
|
||||
pdfList.add(re.getPDF());
|
||||
}
|
||||
|
||||
if (pdfList.size() > 1) {
|
||||
try {
|
||||
File outFile = File.createTempFile("WInvoiceGen", ".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
|
||||
*/
|
||||
public void lockUI ()
|
||||
{
|
||||
Clients.showBusy("Processing...", true);
|
||||
} // lockUI
|
||||
|
||||
/**
|
||||
* Unlock User Interface.
|
||||
* Called from the Worker when processing is done
|
||||
*/
|
||||
public void unlockUI ()
|
||||
{
|
||||
//
|
||||
generateInvoice_complete();
|
||||
} // unlockUI
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
SessionManager.getAppDesktop().closeActiveWindow();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // VInvoiceGen
|
||||
}
|
|
@ -221,10 +221,10 @@ public abstract class ADForm extends Window implements EventListener
|
|||
form.init(adFormID, name);
|
||||
return form;
|
||||
}
|
||||
else if (obj instanceof GenForm)
|
||||
else if (obj instanceof ICustomForm)
|
||||
{
|
||||
GenForm genForm = (GenForm)obj;
|
||||
Object o = genForm.getForm();
|
||||
ICustomForm customForm = (ICustomForm)obj;
|
||||
Object o = customForm.getForm();
|
||||
if(o instanceof ADForm)
|
||||
{
|
||||
form = (ADForm)o;
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package org.adempiere.webui.panel;
|
||||
|
||||
public class CustomForm extends ADForm
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected void initForm()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.adempiere.webui.panel;
|
||||
|
||||
|
||||
public interface ICustomForm
|
||||
{
|
||||
/**
|
||||
* Called by org.adempiere.webui.panel.ADForm.openForm(int)
|
||||
* @return
|
||||
*/
|
||||
public ADForm getForm();
|
||||
}
|
Loading…
Reference in New Issue