diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/Desktop.java b/zkwebui/WEB-INF/src/org/adempiere/webui/Desktop.java
index 2c39fd0d0d..ec5cd3623b 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/Desktop.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/Desktop.java
@@ -734,10 +734,7 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl
pd.setPage(page);
pd.setClosable(true);
pd.setWidth("500px");
- try {
- pd.doModal();
- } catch (InterruptedException e) {
- }
+ pd.doHighlighted();
}
}
else if(menu.getAction().equals(MMenu.ACTION_Form))
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/ServerContextCallback.java b/zkwebui/WEB-INF/src/org/adempiere/webui/ServerContextCallback.java
index 4605a5819f..c1323ffb46 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/ServerContextCallback.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/ServerContextCallback.java
@@ -12,6 +12,7 @@
*****************************************************************************/
package org.adempiere.webui;
+import java.io.Serializable;
import java.lang.reflect.Method;
import org.adempiere.webui.session.ServerContext;
@@ -23,7 +24,7 @@ import net.sf.cglib.proxy.InvocationHandler;
* @author Low Heng Sin
*
*/
-public class ServerContextCallback implements InvocationHandler {
+public class ServerContextCallback implements InvocationHandler, Serializable {
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/AEnv.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/AEnv.java
index 5ad99dd567..caa4f676a4 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/AEnv.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/AEnv.java
@@ -28,6 +28,9 @@ import java.sql.SQLException;
import java.util.Enumeration;
import java.util.logging.Level;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+
import org.adempiere.webui.component.Window;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.window.FDialog;
@@ -44,6 +47,9 @@ import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Ini;
+import org.zkoss.web.servlet.Servlets;
+import org.zkoss.zk.ui.Execution;
+import org.zkoss.zk.ui.Executions;
/**
* Windows Application Environment and utilities
@@ -691,4 +697,22 @@ public final class AEnv
}
return uri;
} // getImageIcon
+
+ /**
+ *
+ * @return boolean
+ */
+ public static boolean isFirefox2() {
+ Execution execution = Executions.getCurrent();
+ if (execution == null)
+ return false;
+
+ Object n = execution.getNativeRequest();
+ if (n instanceof ServletRequest) {
+ String userAgent = Servlets.getUserAgent((ServletRequest) n);
+ return userAgent.indexOf("Firefox/2") >= 0;
+ } else {
+ return false;
+ }
+ }
} // AEnv
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/ProcessDialog.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/ProcessDialog.java
index 328af59faf..904bf326c1 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/ProcessDialog.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/ProcessDialog.java
@@ -1,8 +1,13 @@
package org.adempiere.webui.apps;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
@@ -11,13 +16,17 @@ import org.adempiere.webui.component.Panel;
import org.adempiere.webui.component.VerticalBox;
import org.adempiere.webui.component.Window;
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.print.ReportEngine;
import org.compiere.process.ProcessInfo;
import org.compiere.process.ProcessInfoUtil;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
+import org.zkoss.zk.au.out.AuEcho;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.DesktopUnavailableException;
import org.zkoss.zk.ui.Executions;
@@ -29,6 +38,13 @@ import org.zkoss.zul.Div;
import org.zkoss.zul.Hbox;
import org.zkoss.zul.Html;
+import com.lowagie.text.Document;
+import com.lowagie.text.pdf.PdfContentByte;
+import com.lowagie.text.pdf.PdfCopy;
+import com.lowagie.text.pdf.PdfImportedPage;
+import com.lowagie.text.pdf.PdfReader;
+import com.lowagie.text.pdf.PdfWriter;
+
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2007 Low Heng Sin *
@@ -334,8 +350,8 @@ public class ProcessDialog extends Window implements EventListener//, ASyncProce
m_isLocked = false;
if (Executions.getCurrent() != null)
{
- updateUI(pi);
Clients.showBusy(null, false);
+ updateUI(pi);
}
else
{
@@ -366,22 +382,25 @@ public class ProcessDialog extends Window implements EventListener//, ASyncProce
message.setContent(m_messageText.toString());
//message.setCaretPosition(message.getDocument().getLength()); // scroll down
m_ids = pi.getIDs();
- //
- bOK.setEnabled(true);
//no longer needed, hide to give more space to display log
centerPanel.detach();
invalidate();
+ Clients.response(new AuEcho(this, "onAfterProcess", null));
+ }
+
+ public void onAfterProcess()
+ {
//
afterProcessTask();
// Close automatically
- if (m_IsReport && !pi.isError())
+ if (m_IsReport && !m_pi.isError())
this.dispose();
// If the process is a silent one and no errors occured, close the dialog
if(m_ShowHelp != null && m_ShowHelp.equals("S"))
- this.dispose();
+ this.dispose();
}
/**************************************************************************
@@ -406,63 +425,139 @@ public class ProcessDialog extends Window implements EventListener//, ASyncProce
* Print Shipments
*/
private void printShipments()
- {
- /*
+ {
if (m_ids == null)
return;
- if (!ADialog.ask(m_WindowNo, this, "PrintShipments"))
+ if (!FDialog.ask(m_WindowNo, this, "PrintShipments"))
return;
+
m_messageText.append("
").append(Msg.getMsg(Env.getCtx(), "PrintShipments")).append("
");
- message.setText(m_messageText.toString());
- int retValue = ADialogDialog.A_CANCEL;
- do
- {
- // Loop through all items
- for (int i = 0; i < m_ids.length; i++)
- {
- int M_InOut_ID = m_ids[i];
- ReportCtl.startDocumentPrint(ReportEngine.SHIPMENT, M_InOut_ID, this, Env.getWindowNo(this), true);
- }
- ADialogDialog d = new ADialogDialog (this,
- Env.getHeader(Env.getCtx(), m_WindowNo),
- Msg.getMsg(Env.getCtx(), "PrintoutOK?"),
- JOptionPane.QUESTION_MESSAGE);
- retValue = d.getReturnCode();
- }
- while (retValue == ADialogDialog.A_CANCEL);
- */
+ message.setContent(m_messageText.toString());
+ Clients.showBusy("Processing...", true);
+ Clients.response(new AuEcho(this, "onPrintShipments", null));
} // printInvoices
+
+ public void onPrintShipments()
+ {
+ // Loop through all items
+ List pdfList = new ArrayList();
+ for (int i = 0; i < m_ids.length; i++)
+ {
+ int M_InOut_ID = m_ids[i];
+ ReportEngine re = ReportEngine.get (Env.getCtx(), ReportEngine.SHIPMENT, M_InOut_ID);
+ pdfList.add(re.getPDF());
+ }
+
+ if (pdfList.size() > 1) {
+ try {
+ File outFile = File.createTempFile("PrintShipments", ".pdf");
+ Document document = null;
+ PdfWriter copy = null;
+ for (File f : pdfList)
+ {
+ String fileName = f.getAbsolutePath();
+ PdfReader reader = new PdfReader(fileName);
+ reader.consolidateNamedDestinations();
+ if (document == null)
+ {
+ document = new Document(reader.getPageSizeWithRotation(1));
+ copy = PdfWriter.getInstance(document, new FileOutputStream(outFile));
+ document.open();
+ }
+ int pages = reader.getNumberOfPages();
+ PdfContentByte cb = copy.getDirectContent();
+ for (int i = 1; i <= pages; i++) {
+ document.newPage();
+ PdfImportedPage page = copy.getImportedPage(reader, i);
+ cb.addTemplate(page, 0, 0);
+ }
+ }
+ document.close();
+
+ Clients.showBusy(null, false);
+ Window win = new SimplePDFViewer(this.getTitle(), 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.getTitle(), new FileInputStream(pdfList.get(0)));
+ SessionManager.getAppDesktop().showWindow(win, "center");
+ } catch (Exception e)
+ {
+ log.log(Level.SEVERE, e.getLocalizedMessage(), e);
+ }
+ }
+ }
/**
* Print Invoices
*/
private void printInvoices()
{
- /*
if (m_ids == null)
return;
- if (!ADialog.ask(m_WindowNo, this, "PrintInvoices"))
+ if (!FDialog.ask(m_WindowNo, this, "PrintInvoices"))
return;
m_messageText.append("").append(Msg.getMsg(Env.getCtx(), "PrintInvoices")).append("
");
- message.setText(m_messageText.toString());
- int retValue = ADialogDialog.A_CANCEL;
- do
- {
- // Loop through all items
- for (int i = 0; i < m_ids.length; i++)
- {
- int AD_Invoice_ID = m_ids[i];
- ReportCtl.startDocumentPrint(ReportEngine.INVOICE, AD_Invoice_ID, this, Env.getWindowNo(this), true);
- }
- ADialogDialog d = new ADialogDialog (this,
- Env.getHeader(Env.getCtx(), m_WindowNo),
- Msg.getMsg(Env.getCtx(), "PrintoutOK?"),
- JOptionPane.QUESTION_MESSAGE);
- retValue = d.getReturnCode();
- }
- while (retValue == ADialogDialog.A_CANCEL);
- */
+ message.setContent(m_messageText.toString());
+ Clients.showBusy("Processing...", true);
+ Clients.response(new AuEcho(this, "onPrintInvoices", null));
} // printInvoices
+
+ public void onPrintInvoices()
+ {
+ // Loop through all items
+ List pdfList = new ArrayList();
+ 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("PrintInvoices", ".pdf");
+ Document document = null;
+ PdfWriter copy = null;
+ for (File f : pdfList)
+ {
+ PdfReader reader = new PdfReader(f.getAbsolutePath());
+ if (document == null)
+ {
+ document = new Document(reader.getPageSizeWithRotation(1));
+ copy = PdfWriter.getInstance(document, new FileOutputStream(outFile));
+ document.open();
+ }
+ PdfContentByte cb = copy.getDirectContent(); // Holds the PDF
+ int pages = reader.getNumberOfPages();
+ for (int i = 1; i <= pages; i++) {
+ document.newPage();
+ PdfImportedPage page = copy.getImportedPage(reader, i);
+ cb.addTemplate(page, 0, 0);
+ }
+ }
+ document.close();
+
+ Clients.showBusy(null, false);
+ Window win = new SimplePDFViewer(this.getTitle(), new FileInputStream(outFile));
+ SessionManager.getAppDesktop().showWindow(win, "center");
+ } catch (Exception e) {
+ log.log(Level.SEVERE, e.getLocalizedMessage(), e);
+ }
+ } else if (pdfList.size() > 0) {
+ try {
+ Window win = new SimplePDFViewer(this.getTitle(), new FileInputStream(pdfList.get(0)));
+ SessionManager.getAppDesktop().showWindow(win, "center");
+ } catch (Exception e)
+ {
+ log.log(Level.SEVERE, e.getLocalizedMessage(), e);
+ }
+ }
+ }
public boolean isValid() {
return valid;
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WAllocation.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WAllocation.java
index 9d2b46f2b6..840a57158a 100755
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WAllocation.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WAllocation.java
@@ -34,7 +34,6 @@ import org.adempiere.webui.component.Row;
import org.adempiere.webui.component.Rows;
import org.adempiere.webui.component.Textbox;
import org.adempiere.webui.component.WListbox;
-import org.adempiere.webui.component.WStatusBar;
import org.adempiere.webui.editor.WDateEditor;
import org.adempiere.webui.editor.WSearchEditor;
import org.adempiere.webui.editor.WTableDirEditor;
@@ -43,6 +42,7 @@ 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.window.FDialog;
import org.compiere.model.*;
import org.compiere.process.*;
@@ -85,7 +85,6 @@ public class WAllocation extends ADForm
calculate();
southPanel.appendChild(new Separator());
southPanel.appendChild(statusBar);
- statusBar.setWidth("100%");
}
catch(Exception e)
{
@@ -140,7 +139,7 @@ public class WAllocation extends ADForm
private WTableDirEditor currencyPick = null;
private Checkbox multiCurrency = new Checkbox();
private Label allocCurrencyLabel = new Label();
- private WStatusBar statusBar = new WStatusBar();
+ private StatusBarPanel statusBar = new StatusBarPanel();
private Label dateLabel = new Label();
private WDateEditor dateField = new WDateEditor();
private Checkbox autoWriteOff = new Checkbox();
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFrom.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFrom.java
index 4511dd8c9c..8d49e9e580 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFrom.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFrom.java
@@ -36,7 +36,6 @@ import org.adempiere.webui.component.Row;
import org.adempiere.webui.component.Rows;
import org.adempiere.webui.component.WAppsAction;
import org.adempiere.webui.component.WListbox;
-import org.adempiere.webui.component.WStatusBar;
import org.adempiere.webui.component.Window;
import org.adempiere.webui.editor.WEditor;
import org.adempiere.webui.editor.WLocatorEditor;
@@ -44,6 +43,7 @@ import org.adempiere.webui.editor.WSearchEditor;
import org.adempiere.webui.editor.WStringEditor;
import org.adempiere.webui.event.WTableModelEvent;
import org.adempiere.webui.event.WTableModelListener;
+import org.adempiere.webui.panel.StatusBarPanel;
import org.compiere.model.*;
import org.compiere.util.*;
import org.zkoss.zk.ui.event.Event;
@@ -177,7 +177,7 @@ public abstract class WCreateFrom extends Window
private Panel southPanel = new Panel();
// private Borderlayout southLayout = new Borderlayout();
private ConfirmPanel confirmPanel = new ConfirmPanel(true);
- private WStatusBar statusBar = new WStatusBar();
+ private StatusBarPanel statusBar = new StatusBarPanel();
protected WListbox dataTable = ListboxFactory.newDataTable();
protected Label locatorLabel = new Label();
protected WLocatorEditor locatorField = new WLocatorEditor();
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WInOutGen.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WInOutGen.java
index 1500167b17..c6812a49e6 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WInOutGen.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WInOutGen.java
@@ -1,692 +1,774 @@
-/******************************************************************************
- * Product: Adempiere ERP & CRM Smart Business Solution *
- * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
- * 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. *
- * 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 *
- *****************************************************************************/
-
-/**
- * 2007, Modified by Posterita Ltd.
- */
-
-package org.adempiere.webui.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.adempiere.webui.component.Button;
-import org.adempiere.webui.component.Label;
-import org.adempiere.webui.component.ListHead;
-import org.adempiere.webui.component.ListHeader;
-import org.adempiere.webui.component.ListItem;
-import org.adempiere.webui.component.Listbox;
-import org.adempiere.webui.component.Panel;
-import org.adempiere.webui.component.Tab;
-import org.adempiere.webui.component.Tabbox;
-import org.adempiere.webui.component.Tabpanel;
-import org.adempiere.webui.component.Tabpanels;
-import org.adempiere.webui.component.Tabs;
-import org.adempiere.webui.component.WListbox;
-import org.adempiere.webui.editor.WEditor;
-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.session.SessionManager;
-import org.compiere.apps.ProcessCtl;
-import org.compiere.minigrid.IDColumn;
-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.process.ProcessInfo;
-import org.compiere.util.CLogger;
-import org.compiere.util.DB;
-import org.compiere.util.DisplayType;
-import org.compiere.util.Env;
-import org.compiere.util.Msg;
-import org.compiere.util.Trx;
-import org.zkoss.zk.ui.event.Event;
-import org.zkoss.zk.ui.event.EventListener;
-import org.zkoss.zk.ui.event.Events;
-import org.zkoss.zul.Hbox;
-import org.zkoss.zul.Listcell;
-import org.zkoss.zul.Separator;
-
-/**
- * Generate Shipments Manual : Based on VInOutGen
- *
- * @author Niraj Sohun
- * @date Jul 9, 2007
- */
-
-public class WInOutGen extends ADForm implements EventListener, ValueChangeListener, WTableModelListener
-{
- private static final long serialVersionUID = 1L;
-
- private Separator separator;
-
- private Tabbox tabbox;
-
- private Tabs tabs;
- private Tab tabSelect;
- private Tab tabGenerate;
-
- private Tabpanels tabpanels;
- private Tabpanel pnlSelect;
- private Tabpanel pnlGenerate;
-
- // Panel Select
-
- private WEditor warehouseSearch;
- private WEditor bPartnerSearch;
- private WListbox lstSelect;
-
- // Panel Generate
-
- private Label lblGenerate;
- private Label lblNote;
- private Listbox lstGenerate;
-
- private Button btnOk;
- private Button btnCancel;
-
- private Label lblStatus;
- private Label lblNumSelected;
-
- private boolean m_selectionActive = true;
- private ArrayList selections = null;
-
- @SuppressWarnings("unused")
- private Object m_C_BPartner_ID;
- private Object m_M_Warehouse_ID;
-
- private static CLogger log = CLogger.getCLogger(WInvoiceGen.class);
-
- public WInOutGen()
- {
- }
-
- protected void initForm()
- {
- separator = new Separator();
- separator.setHeight("5px");
-
- tabbox = new Tabbox();
- tabbox.setWidth("700px");
-
- tabs = new Tabs();
-
- tabSelect = new Tab();
- tabSelect.setLabel("Select");
- tabSelect.addEventListener(Events.ON_SELECT, this);
-
- tabGenerate = new Tab();
- tabGenerate.setLabel("Generate");
- tabGenerate.addEventListener(Events.ON_SELECT, this);
-
- tabpanels = new Tabpanels();
-
- pnlSelect = new Tabpanel();
- pnlGenerate = new Tabpanel();
-
- lstSelect = new WListbox();
- lstSelect.setWidth("690px");
- lstSelect.setHeight("250px");
- lstSelect.addEventListener(Events.ON_CLICK, this);
- lstSelect.getModel().addTableModelListener(this);
-
- btnCancel = new Button();
- btnCancel.setImage("/images/Cancel24.png");
- btnCancel.addEventListener(Events.ON_CLICK, this);
-
- btnOk = new Button();
- btnOk.setImage("/images/Ok24.png");
- btnOk.addEventListener(Events.ON_CLICK, this);
-
- lblGenerate = new Label();
- lblGenerate.setWidth("690px");
- lblGenerate.setMultiline(true);
-
- lblNote = new Label();
- lblNote.setWidth("690px");
- lblNote.setMultiline(true);
-
- lblStatus = new Label(" ");
- lblNumSelected = new Label("Number of Records Selected : 0");
-
- lstGenerate = new Listbox();
- lstGenerate.setWidth("300px");
-
- populateWarehouse();
- showBusinessPartner();
-
- initComponents();
- }
-
- private void initComponents()
- {
- this.setWidth("710px");
-
- tabs.appendChild(tabSelect);
- tabs.appendChild(tabGenerate);
-
- tabpanels.appendChild(pnlSelect);
- tabpanels.appendChild(pnlGenerate);
-
- tabbox.appendChild(tabs);
- tabbox.appendChild(tabpanels);
-
- Hbox mainBox = new Hbox();
- mainBox.setWidth("100%");
- mainBox.setStyle("text-align:center");
-
- Hbox hOrg = new Hbox();
- hOrg.setWidth("100%");
-
- Hbox hBP = new Hbox();
- hBP.setWidth("100%");
-
- mainBox.appendChild(hOrg);
- mainBox.appendChild(hBP);
-
- Panel pnl1 = new Panel();
- pnl1.appendChild(warehouseSearch.getLabel());
- pnl1.setStyle("text-align:right");
-
- Panel pnl2 = new Panel();
- pnl2.appendChild(warehouseSearch.getComponent());
- pnl2.setStyle("text-align:left");
-
- Panel pnl3 = new Panel();
- pnl3.appendChild(bPartnerSearch.getLabel());
- pnl3.setStyle("text-align:right");
-
- Panel pnl4 = new Panel();
- pnl4.appendChild(bPartnerSearch.getComponent());
- pnl4.setStyle("text-align:left");
-
- hOrg.appendChild(pnl1);
- hOrg.appendChild(pnl2);
-
- hBP.appendChild(pnl3);
- hBP.appendChild(pnl4);
-
- pnlSelect.setStyle("text-align:center");
- pnlSelect.appendChild(mainBox);
- pnlSelect.appendChild(new Separator());
- pnlSelect.appendChild(lstSelect);
- pnlSelect.appendChild(new Separator());
- pnlSelect.addEventListener(Events.ON_SELECT, this);
-
- pnlGenerate.appendChild(lblGenerate);
- pnlGenerate.appendChild(lblNote);
- pnlGenerate.appendChild(new Separator());
- pnlGenerate.appendChild(lstGenerate);
-
- this.appendChild(tabbox);
- this.appendChild(new Separator());
-
- Hbox hbox = new Hbox();
- hbox.setWidth("80px");
- hbox.appendChild(btnCancel);
- hbox.appendChild(btnOk);
-
- this.appendChild(hbox);
- this.appendChild(new Separator());
-
- hbox = new Hbox();
- hbox.setWidth("700px");
-
- Panel p = new Panel();
- p.setStyle("text-align:left");
- p.appendChild(lblStatus);
- hbox.appendChild(p);
-
- p = new Panel();
- p.setStyle("text-align:right");
- p.appendChild(lblNumSelected);
- hbox.appendChild(p);
-
- this.appendChild(hbox);
-
- prepareTable();
- }
-
- private void prepareTable()
- {
- // Create Columns
-
- ListHead listhead = new ListHead();
- listhead.setSizable(true);
-
- listhead.appendChild(new ListHeader(""));
- listhead.appendChild(new ListHeader("Organization"));
- listhead.appendChild(new ListHeader("Document Type"));
- listhead.appendChild(new ListHeader("Document No"));
- listhead.appendChild(new ListHeader("Business Partner"));
- listhead.appendChild(new ListHeader("Date Ordered"));
- listhead.appendChild(new ListHeader("Total Lines"));
-
- lstSelect.appendChild(listhead);
-
- lstSelect.addColumn("C_Order_ID");
- lstSelect.addColumn("AD_Org_ID");
- lstSelect.addColumn("C_DocType_ID");
- lstSelect.addColumn("DocumentNo");
- lstSelect.addColumn("C_BPartner_ID");
- lstSelect.addColumn("DateOrdered");
- lstSelect.addColumn("TotalLines");
-
- lstSelect.setMultiSelection(true);
-
- // Set Details
-
- lstSelect.setColumnClass(0, IDColumn.class, false, " ");
- lstSelect.setColumnClass(1, String.class, true, Msg.translate(Env.getCtx(), "AD_Org_ID"));
- lstSelect.setColumnClass(2, String.class, true, Msg.translate(Env.getCtx(), "C_DocType_ID"));
- lstSelect.setColumnClass(3, String.class, true, Msg.translate(Env.getCtx(), "DocumentNo"));
- lstSelect.setColumnClass(4, String.class, true, Msg.translate(Env.getCtx(), "C_BPartner_ID"));
- lstSelect.setColumnClass(5, Timestamp.class, true, Msg.translate(Env.getCtx(), "DateOrdered"));
- lstSelect.setColumnClass(6, BigDecimal.class, true, Msg.translate(Env.getCtx(), "TotalLines"));
-
- // Set Status
-
- lblStatus.setValue(Msg.getMsg(Env.getCtx(), "InvGenerateSel"));
- //statusBar.setStatusDB(" ");
- }
-
- private void populateWarehouse()
- {
- final int AD_Column_ID = 2223;
-
- MLookup lookupBP = MLookupFactory.get(Env.getCtx(), m_WindowNo,
- 0, AD_Column_ID, DisplayType.TableDir);
-
- warehouseSearch = new WTableDirEditor(lookupBP, Msg.translate(
- Env.getCtx(), "M_Warehouse_ID"), "", true, false, true);
-
- warehouseSearch.addValueChangeListener(this);
- }
-
- private void showBusinessPartner()
- {
- final int AD_BPartner_ID = 3499;
-
- MLookup lookupBP = MLookupFactory.get(Env.getCtx(), m_WindowNo,
- 0, AD_BPartner_ID, DisplayType.Search);
-
- bPartnerSearch = new WSearchEditor(lookupBP, Msg.translate(
- Env.getCtx(), "C_BPartner_ID"), "", true, false, true);
-
- bPartnerSearch.addValueChangeListener(this);
- }
-
-
- private void executeQuery()
- {
- log.info("");
-
- int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
-
- // Create SQL
-
- StringBuffer sql = new StringBuffer(
- "SELECT C_Order_ID, o.Name, dt.Name, DocumentNo, bp.Name, DateOrdered, TotalLines "
- + "FROM M_InOut_Candidate_v ic, AD_Org o, C_BPartner bp, C_DocType dt "
- + "WHERE ic.AD_Org_ID=o.AD_Org_ID"
- + " AND ic.C_BPartner_ID=bp.C_BPartner_ID"
- + " AND ic.C_DocType_ID=dt.C_DocType_ID"
- + " AND ic.AD_Client_ID=?");
-
- if (m_M_Warehouse_ID != null)
- sql.append(" AND ic.M_Warehouse_ID=").append(m_M_Warehouse_ID);
-
- if (m_C_BPartner_ID != null)
- sql.append(" AND ic.C_BPartner_ID=").append(m_C_BPartner_ID);
-
- // bug - [ 1713317 ] Generate Shipments (manual) show locked records
-
- /* begin - Exclude locked records; @Trifon */
-
- int AD_User_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID");
- String lockedIDs = MPrivateAccess.getLockedRecordWhere(MOrder.Table_ID, AD_User_ID);
-
- if (lockedIDs != null)
- {
- if (sql.length() > 0)
- sql.append(" AND ");
- sql.append("C_Order_ID").append(lockedIDs);
- }
-
- /* end - Exclude locked records; @Trifon */
-
- sql.append(" ORDER BY o.Name,bp.Name,DateOrdered");
- log.fine(sql.toString());
-
- // Reset table
-
- int row = 0;
-
- if (lstSelect != null)
- lstSelect.clearTable();
-
- // Execute
-
- try
- {
- PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
- pstmt.setInt(1, AD_Client_ID);
- ResultSet rs = pstmt.executeQuery();
-
- while (rs.next())
- {
- // Extend table
-
- lstSelect.setRowCount(row+1);
-
- // Set values
-
- lstSelect.setValueAt(new IDColumn(rs.getInt(1)), row, 0); // C_Order_ID
- lstSelect.setValueAt(rs.getString(2), row, 1); // Org
- lstSelect.setValueAt(rs.getString(3), row, 2); // DocType
- lstSelect.setValueAt(rs.getString(4), row, 3); // Doc No
- lstSelect.setValueAt(rs.getString(5), row, 4); // BPartner
- lstSelect.setValueAt(rs.getTimestamp(6), row, 5); // DateOrdered
- lstSelect.setValueAt(rs.getBigDecimal(7), row, 6); // TotalLines
-
- // Prepare next
- row++;
- }
- rs.close();
- pstmt.close();
- }
- catch (SQLException e)
- {
- log.log(Level.SEVERE, sql.toString(), e);
- }
- }
-
- private void saveSelection()
- {
- log.info("");
-
- // Array of Integers
-
- ArrayList results = new ArrayList();
-
- if (selections != null)
- selections.clear();
-
- // Get Selected Entries
-
- int rows = lstSelect.getItemCount();
-
- for (int i = 0; i < rows; i++)
- {
- // ID in Column 0
-
- IDColumn id = (IDColumn)lstSelect.getValueAt(i, 0);
-
- if (id != null && id.isSelected())
- results.add(id.getRecord_ID());
- }
-
- if (results.size() == 0)
- return;
-
- selections = results;
- }
-
- private void generateShipments()
- {
- log.info("M_Warehouse_ID=" + m_M_Warehouse_ID);
-
- // Trx needs to be committed too
- String trxName = Trx.createTrxName("IOG");
- Trx trx = Trx.get(trxName, true);
-
- // Prevents from being called twice
- m_selectionActive = false;
-
- //lblStatus.setValue(Msg.getMsg(Env.getCtx(), "InOutGenerateGen"));
- //statusBar.setStatusDB(String.valueOf(selection.size()));
-
- // Prepare Process
-
- // M_InOutCreate
-
- int AD_Process_ID = 199;
- 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;
- }
- }
-
- // Call process
-
- ProcessInfo pi = new ProcessInfo ("WInOutGen", AD_Process_ID);
- pi.setAD_PInstance_ID (instance.getAD_PInstance_ID());
-
- // Add Parameter - Selection = Y
-
- MPInstancePara ip = new MPInstancePara(instance, 10);
- ip.setParameter("Selection","Y");
-
- if (!ip.save())
- {
- String msg = "No Parameter added"; // not translated
- //info.setText(msg);
- log.log(Level.SEVERE, msg);
- return;
- }
-
- // Add Parameter - M_Warehouse_ID = x
-
- ip = new MPInstancePara(instance, 20);
- ip.setParameter("M_Warehouse_ID", Integer.parseInt(m_M_Warehouse_ID.toString()));
-
- if (!ip.save())
- {
- String msg = "No Parameter added"; // not translated
- //info.setText(msg);
- log.log(Level.SEVERE, msg);
- return;
- }
-
- // Execute Process
- ProcessCtl worker = new ProcessCtl(null, m_WindowNo, pi, trx);
- worker.start(); // complete tasks in unlockUI / generateShipments_complete
-
- lstSelect.clearTable();
-
- displayInfo();
- }
-
- private void displayInfo()
- {
- lblGenerate.setValue("Created = " + selections.size());
- lblNote.setValue("(Shipments are generated depending on the 'Delivery Rule' selection in the Order)");
-
- lstGenerate.getChildren().clear();
-
- for (int i = 0; i < selections.size(); i++)
- {
- ListItem listitem = new ListItem();
- Timestamp time = new Timestamp(System.currentTimeMillis());
- listitem.appendChild(new Listcell(time.toString()));
- listitem.appendChild(new Listcell(selections.get(i).toString()));
-
- lstGenerate.appendChild(listitem);
- }
-
- tabbox.setSelectedPanel(pnlGenerate);
- }
-
- private void generateInvoiceComplete (ProcessInfo pi)
- {
- }
-
-
-
- public void onEvent(Event evt)
- {
- if (evt != null)
- {
- if (evt.getTarget() == tabSelect)
- {
- m_selectionActive = true;
-
- executeQuery();
- }
-
- if ((evt.getTarget() == warehouseSearch) || (evt.getTarget() == bPartnerSearch))
- {
- if (evt.getTarget() == warehouseSearch)
- {
- m_M_Warehouse_ID = warehouseSearch.getValue();
- }
-
- if (evt.getTarget() == bPartnerSearch)
- {
- m_C_BPartner_ID = bPartnerSearch.getValue();
- }
-
- executeQuery();
- }
-
- if ((evt.getTarget() == btnOk) || (evt.getTarget() == btnCancel))
- {
- if (evt.getTarget() == btnCancel)
- {
- SessionManager.getAppDesktop().removeWindow();
- }
-
- saveSelection();
-
- if (selections != null && selections.size() > 0 && m_selectionActive)
- generateShipments();
- else
- SessionManager.getAppDesktop().removeWindow();
- }
- }
- }
-
- public void valueChange(ValueChangeEvent evt)
- {
- if (evt == null)
- return;
-
- if (evt.getSource() instanceof WEditor)
- {
- String name = evt.getPropertyName();
- Object value = evt.getNewValue() == null ? "" : evt.getNewValue();
-
- if (name.equals("C_BPartner_ID"))
- {
- bPartnerSearch.setValue(value);
- m_C_BPartner_ID = ((Integer) value).intValue();
-
- executeQuery();
- }
-
- if (name.equals("M_Warehouse_ID"))
- {
- warehouseSearch.setValue(value);
- m_M_Warehouse_ID = ((Integer) value).intValue();
-
- executeQuery();
- }
- }
- }
-
- public void tableChanged(WTableModelEvent event)
- {
- int rowsSelected = 0;
- int rows = lstSelect.getItemCount();
-
- for (int i = 0; i < rows; i++)
- {
- // ID in column 0
- IDColumn id = (IDColumn)lstSelect.getValueAt(i, 0);
-
- if (id != null && id.isSelected())
- rowsSelected++;
- }
-
- // Set Status
-
- Integer size = rowsSelected;
- lblNumSelected.setValue("Number of Records Selected : " + size.toString());
- }
-}
+/******************************************************************************
+ * Product: Adempiere ERP & CRM Smart Business Solution *
+ * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
+ * 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. *
+ * 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.io.FileOutputStream;
+import java.math.*;
+import java.sql.*;
+import java.util.*;
+import java.util.logging.*;
+
+import org.adempiere.webui.LayoutUtils;
+import org.adempiere.webui.component.ConfirmPanel;
+import org.adempiere.webui.component.DesktopTabpanel;
+import org.adempiere.webui.component.Label;
+import org.adempiere.webui.component.Listbox;
+import org.adempiere.webui.component.ListboxFactory;
+import org.adempiere.webui.component.Panel;
+import org.adempiere.webui.component.Tab;
+import org.adempiere.webui.component.Tabbox;
+import org.adempiere.webui.component.Tabpanels;
+import org.adempiere.webui.component.Tabs;
+import org.adempiere.webui.component.WListbox;
+import org.adempiere.webui.component.Window;
+import org.adempiere.webui.editor.WSearchEditor;
+import org.adempiere.webui.editor.WTableDirEditor;
+import org.adempiere.webui.event.ValueChangeEvent;
+import org.adempiere.webui.event.ValueChangeListener;
+import org.adempiere.webui.event.WTableModelEvent;
+import org.adempiere.webui.event.WTableModelListener;
+import org.adempiere.webui.panel.ADForm;
+import org.adempiere.webui.panel.StatusBarPanel;
+import org.adempiere.webui.session.SessionManager;
+import org.adempiere.webui.window.FDialog;
+import org.adempiere.webui.window.SimplePDFViewer;
+import org.compiere.apps.ProcessCtl;
+import org.compiere.minigrid.IDColumn;
+import org.compiere.model.*;
+import org.compiere.print.*;
+import org.compiere.process.*;
+import org.compiere.util.*;
+import org.zkoss.zk.au.out.AuEcho;
+import org.zkoss.zk.ui.DesktopUnavailableException;
+import org.zkoss.zk.ui.Executions;
+import org.zkoss.zk.ui.event.Event;
+import org.zkoss.zk.ui.event.Events;
+import org.zkoss.zk.ui.util.Clients;
+import org.zkoss.zkex.zul.Borderlayout;
+import org.zkoss.zkex.zul.Center;
+import org.zkoss.zkex.zul.North;
+import org.zkoss.zkex.zul.South;
+import org.zkoss.zul.Div;
+import org.zkoss.zul.Html;
+import org.zkoss.zul.Space;
+
+import com.lowagie.text.Document;
+import com.lowagie.text.pdf.PdfContentByte;
+import com.lowagie.text.pdf.PdfImportedPage;
+import com.lowagie.text.pdf.PdfReader;
+import com.lowagie.text.pdf.PdfWriter;
+
+/**
+ * Manual Shipment Selection
+ *
+ * @author Jorg Janke
+ * @version $Id: VInOutGen.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
+ */
+public class WInOutGen extends ADForm implements EventListener, ValueChangeListener, WTableModelListener
+{
+ @Override
+ protected void initForm()
+ {
+ log.info("");
+ Env.setContext(Env.getCtx(), m_WindowNo, "IsSOTrx", "Y");
+ try
+ {
+ fillPicks();
+ zkInit();
+ dynInit();
+ Borderlayout contentPane = new Borderlayout();
+ this.appendChild(contentPane);
+ contentPane.setWidth("99%");
+ contentPane.setHeight("100%");
+ Center center = new Center();
+ center.setStyle("border: none");
+ contentPane.appendChild(center);
+ center.appendChild(tabbedPane);
+ center.setFlex(true);
+ South south = new South();
+ south.setStyle("border: none");
+ contentPane.appendChild(south);
+ south.appendChild(statusBar);
+ LayoutUtils.addSclass("status-border", statusBar);
+ south.setHeight("22px");
+ }
+ catch(Exception ex)
+ {
+ log.log(Level.SEVERE, "init", ex);
+ }
+ } // init
+
+ private boolean m_selectionActive = true;
+ private Object m_M_Warehouse_ID = null;
+ private Object m_C_BPartner_ID = null;
+ /** Logger */
+ private static CLogger log = CLogger.getCLogger(WInOutGen.class);
+ //
+ private Tabbox tabbedPane = new Tabbox();
+ private Borderlayout selPanel = new Borderlayout();
+ private Panel selNorthPanel = new Panel();
+ private Label lWarehouse = new Label();
+ private WTableDirEditor fWarehouse;
+ private Label lBPartner = new Label();
+ private WSearchEditor fBPartner;
+// private FlowLayout northPanelLayout = new FlowLayout();
+ private ConfirmPanel confirmPanelSel = new ConfirmPanel(true);
+ private ConfirmPanel confirmPanelGen = new ConfirmPanel(false, true, false, false, false, false, false);
+ private StatusBarPanel statusBar = new StatusBarPanel();
+ private Borderlayout genPanel = new Borderlayout();
+ private Html info = new Html();
+// private JScrollPane scrollPane = new JScrollPane();
+ private WListbox miniTable = ListboxFactory.newDataTable();
+
+ private Label lDocType = new Label();
+ private Listbox cmbDocType = ListboxFactory.newDropdownListbox();
+
+ /** User selection */
+ private ArrayList selection = null;
+ private int[] m_ids;
+ private ProcessInfo m_pi;
+
+ /**
+ * Static Init.
+ *
+ * selPanel (tabbed)
+ * fOrg, fBPartner
+ * scrollPane & miniTable
+ * genPanel
+ * info
+ *
+ * @throws Exception
+ */
+ void zkInit() throws Exception
+ {
+ //
+ selPanel.setWidth("99%");
+ selPanel.setHeight("90%");
+ selPanel.setStyle("border: none; position: absolute");
+ lBPartner.setText("BPartner");
+ DesktopTabpanel tabpanel = new DesktopTabpanel();
+ tabpanel.appendChild(selPanel);
+ Tabpanels tabPanels = new Tabpanels();
+ tabPanels.appendChild(tabpanel);
+ tabbedPane.appendChild(tabPanels);
+ Tabs tabs = new Tabs();
+ tabbedPane.appendChild(tabs);
+ Tab tab = new Tab(Msg.getMsg(Env.getCtx(), "Select"));
+ tabs.appendChild(tab);
+ tabbedPane.getTabpanels();
+
+ North north = new North();
+ selPanel.appendChild(north);
+ north.appendChild(selNorthPanel);
+ selNorthPanel.appendChild(lWarehouse);
+ selNorthPanel.appendChild(fWarehouse.getComponent());
+ selNorthPanel.appendChild(new Space());
+ selNorthPanel.appendChild(lBPartner);
+ selNorthPanel.appendChild(fBPartner.getComponent());
+ selNorthPanel.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);
+
+ selNorthPanel.appendChild(lDocType);
+ selNorthPanel.appendChild(cmbDocType);
+ } // jbInit
+
+ /**
+ * Fill Picks.
+ * Column_ID from C_Order
+ * @throws Exception if Lookups cannot be initialized
+ */
+ private void fillPicks() throws Exception
+ {
+ // C_OrderLine.M_Warehouse_ID
+ MLookup orgL = MLookupFactory.get (Env.getCtx(), m_WindowNo, 0, 2223, DisplayType.TableDir);
+ fWarehouse = new WTableDirEditor ("M_Warehouse_ID", true, false, true, orgL);
+ lWarehouse.setText(Msg.translate(Env.getCtx(), "M_Warehouse_ID"));
+ fWarehouse.addValueChangeListener(this);
+ m_M_Warehouse_ID = fWarehouse.getValue();
+ // C_Order.C_BPartner_ID
+ MLookup bpL = MLookupFactory.get (Env.getCtx(), m_WindowNo, 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 Type Sales Order/Vendor RMA
+ 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.setSelectedIndex(0);
+ } // fillPicks
+
+ /**
+ * Dynamic Init.
+ * - Create GridController & Panel
+ * - AD_Column_ID from C_Order
+ */
+ private void dynInit()
+ {
+ // create Columns
+ miniTable.addColumn("C_Order_ID");
+ miniTable.addColumn("AD_Org_ID");
+ miniTable.addColumn("C_DocType_ID");
+ miniTable.addColumn("DocumentNo");
+ miniTable.addColumn("C_BPartner_ID");
+ miniTable.addColumn("DateOrdered");
+ miniTable.addColumn("TotalLines");
+ //
+ miniTable.setMultiSelection(true);
+// miniTable.setRowSelectionAllowed(true);
+ // set details
+ miniTable.setColumnClass(0, IDColumn.class, false, " ");
+ miniTable.setColumnClass(1, String.class, true, Msg.translate(Env.getCtx(), "AD_Org_ID"));
+ miniTable.setColumnClass(2, String.class, true, Msg.translate(Env.getCtx(), "C_DocType_ID"));
+ miniTable.setColumnClass(3, String.class, true, Msg.translate(Env.getCtx(), "DocumentNo"));
+ miniTable.setColumnClass(4, String.class, true, Msg.translate(Env.getCtx(), "C_BPartner_ID"));
+ miniTable.setColumnClass(5, Timestamp.class, true, Msg.translate(Env.getCtx(), "DateOrdered"));
+ miniTable.setColumnClass(6, BigDecimal.class, true, Msg.translate(Env.getCtx(), "TotalLines"));
+ //
+ miniTable.autoSize();
+ miniTable.getModel().addTableModelListener(this);
+ // Info
+ statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateSel"));//@@
+ statusBar.setStatusDB(" ");
+ // Tabbed Pane Listener
+ tabbedPane.addEventListener(Events.ON_SELECT, this);
+ } // dynInit
+
+ /**
+ * Get SQL for Orders that needs to be shipped
+ * @return sql
+ */
+ private String getOrderSQL()
+ {
+ // Create SQL
+ StringBuffer sql = new StringBuffer(
+ "SELECT C_Order_ID, o.Name, dt.Name, DocumentNo, bp.Name, DateOrdered, TotalLines "
+ + "FROM M_InOut_Candidate_v ic, AD_Org o, C_BPartner bp, C_DocType dt "
+ + "WHERE ic.AD_Org_ID=o.AD_Org_ID"
+ + " AND ic.C_BPartner_ID=bp.C_BPartner_ID"
+ + " AND ic.C_DocType_ID=dt.C_DocType_ID"
+ + " AND ic.AD_Client_ID=?");
+
+ if (m_M_Warehouse_ID != null)
+ sql.append(" AND ic.M_Warehouse_ID=").append(m_M_Warehouse_ID);
+ if (m_C_BPartner_ID != null)
+ sql.append(" AND ic.C_BPartner_ID=").append(m_C_BPartner_ID);
+
+ // bug - [ 1713317 ] Generate Shipments (manual) show locked records
+ /* begin - Exclude locked records; @Trifon */
+ int AD_User_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID");
+ String lockedIDs = MPrivateAccess.getLockedRecordWhere(MOrder.Table_ID, AD_User_ID);
+ if (lockedIDs != null)
+ {
+ if (sql.length() > 0)
+ sql.append(" AND ");
+ sql.append("C_Order_ID").append(lockedIDs);
+ }
+ /* eng - Exclude locked records; @Trifon */
+
+ //
+ sql.append(" ORDER BY o.Name,bp.Name,DateOrdered");
+
+ return sql.toString();
+ }
+
+ /**
+ * Get SQL for Vendor RMA that need to be shipped
+ * @return sql
+ */
+ private String getRMASql()
+ {
+ StringBuffer sql = new StringBuffer();
+
+ sql.append("SELECT rma.M_RMA_ID, org.Name, dt.Name, rma.DocumentNo, bp.Name, rma.Created, rma.Amt ");
+ sql.append("FROM M_RMA rma INNER JOIN AD_Org org ON rma.AD_Org_ID=org.AD_Org_ID ");
+ sql.append("INNER JOIN C_DocType dt ON rma.C_DocType_ID=dt.C_DocType_ID ");
+ sql.append("INNER JOIN C_BPartner bp ON rma.C_BPartner_ID=bp.C_BPartner_ID ");
+ sql.append("INNER JOIN M_InOut io ON rma.InOut_ID=io.M_InOut_ID ");
+ sql.append("WHERE rma.DocStatus='CO' ");
+ sql.append("AND dt.DocBaseType = 'POO' ");
+ sql.append("AND EXISTS (SELECT * FROM M_RMA r INNER JOIN M_RMALine rl ");
+ sql.append("ON r.M_RMA_ID=rl.M_RMA_ID WHERE r.M_RMA_ID=rma.M_RMA_ID ");
+ sql.append("AND rl.IsActive='Y' AND rl.M_InOutLine_ID > 0 AND rl.QtyDelivered < rl.Qty) ");
+ sql.append("AND NOT EXISTS (SELECT * FROM M_InOut oio WHERE oio.M_RMA_ID=rma.M_RMA_ID ");
+ sql.append("AND oio.DocStatus IN ('IP', 'CO', 'CL')) " );
+ sql.append("AND rma.AD_Client_ID=?");
+
+ if (m_M_Warehouse_ID != null)
+ sql.append(" AND io.M_Warehouse_ID=").append(m_M_Warehouse_ID);
+ if (m_C_BPartner_ID != null)
+ sql.append(" AND bp.C_BPartner_ID=").append(m_C_BPartner_ID);
+
+ int AD_User_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID");
+ String lockedIDs = MPrivateAccess.getLockedRecordWhere(MRMA.Table_ID, AD_User_ID);
+ if (lockedIDs != null)
+ {
+ sql.append(" AND rma.M_RMA_ID").append(lockedIDs);
+ }
+
+ sql.append(" ORDER BY org.Name, bp.Name, rma.Created ");
+
+ return sql.toString();
+ }
+
+ /**
+ * Query Info
+ */
+ private void executeQuery()
+ {
+ log.info("");
+ int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
+
+ String sql = "";
+
+ KeyNamePair docTypeKNPair = cmbDocType.getSelectedItem().toKeyNamePair();
+
+ if (docTypeKNPair.getKey() == MRMA.Table_ID)
+ {
+ sql = getRMASql();
+ }
+ else
+ {
+ sql = getOrderSQL();
+ }
+
+ log.fine(sql);
+ // reset table
+ int row = 0;
+ miniTable.setRowCount(row);
+ // Execute
+ try
+ {
+ PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
+ pstmt.setInt(1, AD_Client_ID);
+ ResultSet rs = pstmt.executeQuery();
+ //
+ while (rs.next())
+ {
+ // extend table
+ miniTable.setRowCount(row+1);
+ // set values
+ miniTable.setValueAt(new IDColumn(rs.getInt(1)), row, 0); // C_Order_ID
+ miniTable.setValueAt(rs.getString(2), row, 1); // Org
+ miniTable.setValueAt(rs.getString(3), row, 2); // DocType
+ miniTable.setValueAt(rs.getString(4), row, 3); // Doc No
+ miniTable.setValueAt(rs.getString(5), row, 4); // BPartner
+ miniTable.setValueAt(rs.getTimestamp(6), row, 5); // DateOrdered
+ miniTable.setValueAt(rs.getBigDecimal(7), row, 6); // TotalLines
+ // prepare next
+ row++;
+ }
+ rs.close();
+ pstmt.close();
+ }
+ catch (SQLException e)
+ {
+ log.log(Level.SEVERE, sql.toString(), e);
+ }
+ //
+ miniTable.repaint();
+ this.invalidate();
+ // statusBar.setStatusDB(String.valueOf(miniTable.getRowCount()));
+ } // executeQuery
+
+ /**
+ * Action Listener
+ * @param e event
+ */
+ public void onEvent(Event e)
+ {
+ log.info("Cmd=" + e.getTarget().getId());
+ //
+ if (e.getTarget().getId().equals(ConfirmPanel.A_CANCEL))
+ {
+ dispose();
+ return;
+ }
+ else if (e.getTarget() instanceof Tab)
+ {
+ int index = tabbedPane.getSelectedIndex();
+ m_selectionActive = (index == 0);
+ return;
+ }
+ else if (cmbDocType.equals(e.getTarget()))
+ {
+ executeQuery();
+ return;
+ }
+ //
+ saveSelection();
+ if (selection != null
+ && selection.size() > 0
+ && m_selectionActive // on selection tab
+ && m_M_Warehouse_ID != null)
+ generateShipments ();
+ else
+ dispose();
+ } // actionPerformed
+
+ /**
+ * Value Change Listener - requery
+ * @param e event
+ */
+ public void valueChange(ValueChangeEvent e)
+ {
+ log.info(e.getPropertyName() + "=" + e.getNewValue());
+ if (e.getPropertyName().equals("M_Warehouse_ID"))
+ m_M_Warehouse_ID = e.getNewValue();
+ if (e.getPropertyName().equals("C_BPartner_ID"))
+ {
+ m_C_BPartner_ID = e.getNewValue();
+ fBPartner.setValue(m_C_BPartner_ID); // display value
+ }
+ executeQuery();
+ } // vetoableChange
+
+
+ /**
+ * Table Model Listener
+ * @param e event
+ */
+ public void tableChanged(WTableModelEvent e)
+ {
+ int rowsSelected = 0;
+ int rows = miniTable.getRowCount();
+ for (int i = 0; i < rows; i++)
+ {
+ IDColumn id = (IDColumn)miniTable.getValueAt(i, 0); // ID in column 0
+ if (id != null && id.isSelected())
+ rowsSelected++;
+ }
+ statusBar.setStatusDB(" " + rowsSelected + " ");
+ } // tableChanged
+
+ /**
+ * Save Selection & return selecion Query or ""
+ * @return where clause like C_Order_ID IN (...)
+ */
+ private void saveSelection()
+ {
+ log.info("");
+ // ID selection may be pending
+// miniTable.editingStopped(new ChangeEvent(this));
+ // Array of Integers
+ ArrayList results = new ArrayList();
+ selection = null;
+
+ // Get selected entries
+ int rows = miniTable.getRowCount();
+ for (int i = 0; i < rows; i++)
+ {
+ IDColumn id = (IDColumn)miniTable.getValueAt(i, 0); // ID in column 0
+ // log.fine( "Row=" + i + " - " + id);
+ if (id != null && id.isSelected())
+ results.add(id.getRecord_ID());
+ }
+
+ if (results.size() == 0)
+ return;
+ log.config("Selected #" + results.size());
+ selection = results;
+ } // saveSelection
+
+
+ /**************************************************************************
+ * Generate Shipments
+ */
+ private void generateShipments ()
+ {
+ log.info("M_Warehouse_ID=" + m_M_Warehouse_ID);
+ String trxName = Trx.createTrxName("IOG");
+ Trx trx = Trx.get(trxName, true); //trx needs to be committed too
+// String trxName = null;
+// Trx trx = null;
+
+ m_selectionActive = false; // prevents from being called twice
+ statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateGen"));
+ statusBar.setStatusDB(String.valueOf(selection.size()));
+
+ // Prepare Process
+ int AD_Process_ID = 0;
+ KeyNamePair docTypeKNPair = (KeyNamePair)cmbDocType.getSelectedItem().toKeyNamePair();
+
+ if (docTypeKNPair.getKey() == MRMA.Table_ID)
+ {
+ AD_Process_ID = 52001; // M_InOut_GenerateRMA - org.adempiere.process.InOutGenerateRMA
+ }
+ else
+ {
+ AD_Process_ID = 199; // M_InOut_Generate - org.compiere.process.InOutGenerate
+ }
+
+ MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
+ if (!instance.save())
+ {
+ info.setContent(Msg.getMsg(Env.getCtx(), "ProcessNoInstance"));
+ return;
+ }
+
+ //insert selection
+ StringBuffer insert = new StringBuffer();
+ insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
+ int counter = 0;
+ for(Integer selectedId : selection)
+ {
+ counter++;
+ if (counter > 1)
+ insert.append(" UNION ");
+ insert.append("SELECT ");
+ insert.append(instance.getAD_PInstance_ID());
+ insert.append(", ");
+ insert.append(selectedId);
+ insert.append(" FROM DUAL ");
+
+ if (counter == 1000)
+ {
+ if ( DB.executeUpdate(insert.toString(), trxName) < 0 )
+ {
+ String msg = "No Shipments"; // not translated!
+ log.config(msg);
+ info.setContent(msg);
+ trx.rollback();
+ return;
+ }
+ insert = new StringBuffer();
+ insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
+ counter = 0;
+ }
+ }
+ if (counter > 0)
+ {
+ if ( DB.executeUpdate(insert.toString(), trxName) < 0 )
+ {
+ String msg = "No Shipments"; // not translated!
+ log.config(msg);
+ info.setContent(msg);
+ trx.rollback();
+ return;
+ }
+ }
+
+ //call process
+ m_pi = new ProcessInfo ("VInOutGen", AD_Process_ID);
+ m_pi.setAD_PInstance_ID (instance.getAD_PInstance_ID());
+
+ // Add Parameter - Selection=Y
+ MPInstancePara ip = new MPInstancePara(instance, 10);
+ ip.setParameter("Selection","Y");
+ if (!ip.save())
+ {
+ String msg = "No Parameter added"; // not translated
+ info.setContent(msg);
+ log.log(Level.SEVERE, msg);
+ return;
+ }
+ // Add Parameter - M_Warehouse_ID=x
+ ip = new MPInstancePara(instance, 20);
+ ip.setParameter("M_Warehouse_ID", Integer.parseInt(m_M_Warehouse_ID.toString()));
+ if (!ip.save())
+ {
+ String msg = "No Parameter added"; // not translated
+ info.setContent(msg);
+ log.log(Level.SEVERE, msg);
+ return;
+ }
+
+ // Execute Process
+ if (!getDesktop().isServerPushEnabled())
+ getDesktop().enableServerPush(true);
+
+ this.lockUI();
+ final ProcessCtl worker = new ProcessCtl(null, m_WindowNo, m_pi, trx);
+ Runnable runnable = new Runnable() {
+ public void run() {
+ //get full control of desktop
+ org.zkoss.zk.ui.Desktop desktop = WInOutGen.this.getDesktop();
+ try {
+ Executions.activate(desktop);
+ try {
+ worker.run(); // complete tasks in unlockUI / generateShipments_complete
+ } finally{
+ unlockUI();
+ //release full control of desktop
+ Executions.deactivate(desktop);
+ }
+ } catch (DesktopUnavailableException e) {
+ log.log(Level.SEVERE, e.getLocalizedMessage(), e);
+ } catch (InterruptedException e) {
+ log.log(Level.WARNING, e.getLocalizedMessage(), e);
+ }
+ }
+ };
+ new Thread(runnable).start();
+ //
+ } // generateShipments
+
+ /**
+ * Complete generating shipments.
+ * Called from Unlock UI
+ * @param pi process info
+ */
+ private void generateShipments_complete ()
+ {
+ Clients.showBusy(null, false);
+
+ // Switch Tabs
+ tabbedPane.setSelectedIndex(1);
+ //
+ ProcessInfoUtil.setLogFromDB(m_pi);
+ StringBuffer iText = new StringBuffer();
+ iText.append("").append(m_pi.getSummary())
+ .append("
(")
+ .append(Msg.getMsg(Env.getCtx(), "InOutGenerateInfo"))
+ // Shipments are generated depending on the Delivery Rule selection in the Order
+ .append(")
")
+ .append(m_pi.getLogInfo(true));
+ info.setContent(iText.toString());
+
+ // Get results
+ int[] ids = m_pi.getIDs();
+ if (ids == null || ids.length == 0)
+ return;
+ log.config("PrintItems=" + ids.length);
+
+ m_ids = ids;
+ Clients.response(new AuEcho(this, "onAfterProcess", null));
+
+ } // generateShipments_complete
+
+
+ public void onAfterProcess()
+ {
+ // OK to print shipments
+ if (FDialog.ask(m_WindowNo, this, "PrintShipments"))
+ {
+ // info.append("\n\n" + Msg.getMsg(Env.getCtx(), "PrintShipments"));
+ Clients.showBusy("Processing...", true);
+ Clients.response(new AuEcho(this, "onPrintShipments", null));
+ } // OK to print shipments
+ }
+
+ public void onPrintShipments()
+ {
+// Loop through all items
+ List pdfList = new ArrayList();
+ for (int i = 0; i < m_ids.length; i++)
+ {
+ int M_InOut_ID = m_ids[i];
+ ReportEngine re = ReportEngine.get (Env.getCtx(), ReportEngine.SHIPMENT, M_InOut_ID);
+ pdfList.add(re.getPDF());
+ }
+
+ if (pdfList.size() > 1) {
+ try {
+ File outFile = File.createTempFile("WInOutGen", ".pdf");
+ Document document = null;
+ PdfWriter copy = null;
+ for (File f : pdfList)
+ {
+ PdfReader reader = new PdfReader(f.getAbsolutePath());
+ if (document == null)
+ {
+ document = new Document(reader.getPageSizeWithRotation(1));
+ copy = PdfWriter.getInstance(document, new FileOutputStream(outFile));
+ document.open();
+ }
+ int pages = reader.getNumberOfPages();
+ PdfContentByte cb = copy.getDirectContent();
+ for (int i = 1; i <= pages; i++) {
+ document.newPage();
+ PdfImportedPage page = copy.getImportedPage(reader, i);
+ cb.addTemplate(page, 0, 0);
+ }
+ }
+ document.close();
+
+ Clients.showBusy(null, false);
+ Window win = new SimplePDFViewer(this.getFormName(), new FileInputStream(outFile));
+ SessionManager.getAppDesktop().showWindow(win, "center");
+ } catch (Exception e) {
+ log.log(Level.SEVERE, e.getLocalizedMessage(), e);
+ }
+ } else if (pdfList.size() > 0) {
+ Clients.showBusy(null, false);
+ try {
+ Window win = new SimplePDFViewer(this.getFormName(), new FileInputStream(pdfList.get(0)));
+ SessionManager.getAppDesktop().showWindow(win, "center");
+ } catch (Exception e)
+ {
+ log.log(Level.SEVERE, e.getLocalizedMessage(), e);
+ }
+ }
+ }
+
+
+ /**************************************************************************
+ * Lock User Interface.
+ * Called from the Worker before processing
+ * @param pi process info
+ */
+ public void lockUI ()
+ {
+ Clients.showBusy("Processing...", true);
+ } // lockUI
+
+ /**
+ * Unlock User Interface.
+ * Called from the Worker when processing is done
+ * @param pi result of execute ASync call
+ */
+ public void unlockUI ()
+ {
+ generateShipments_complete();
+ } // unlockUI
+
+ @Override
+ public void dispose() {
+ SessionManager.getAppDesktop().removeWindow();
+ }
+
+} // VInOutGen
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WInvoiceGen.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WInvoiceGen.java
index 49e64eac94..be726d4d33 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WInvoiceGen.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WInvoiceGen.java
@@ -1,724 +1,774 @@
-/******************************************************************************
- * Product: Adempiere ERP & CRM Smart Business Solution *
- * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
- * 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. *
- * 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 *
- *****************************************************************************/
-
-/**
- * 2007, Modified by Posterita Ltd.
- */
-
-package org.adempiere.webui.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.adempiere.webui.component.Button;
-import org.adempiere.webui.component.Label;
-import org.adempiere.webui.component.ListHead;
-import org.adempiere.webui.component.ListHeader;
-import org.adempiere.webui.component.ListItem;
-import org.adempiere.webui.component.Listbox;
-import org.adempiere.webui.component.Panel;
-import org.adempiere.webui.component.Tab;
-import org.adempiere.webui.component.Tabbox;
-import org.adempiere.webui.component.Tabpanel;
-import org.adempiere.webui.component.Tabpanels;
-import org.adempiere.webui.component.Tabs;
-import org.adempiere.webui.component.WListbox;
-import org.adempiere.webui.editor.WEditor;
-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.session.SessionManager;
-import org.compiere.apps.ProcessCtl;
-import org.compiere.minigrid.IDColumn;
-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.process.ProcessInfo;
-import org.compiere.util.CLogger;
-import org.compiere.util.DB;
-import org.compiere.util.DisplayType;
-import org.compiere.util.Env;
-import org.compiere.util.Msg;
-import org.compiere.util.Trx;
-import org.zkoss.zk.ui.event.Event;
-import org.zkoss.zk.ui.event.EventListener;
-import org.zkoss.zk.ui.event.Events;
-import org.zkoss.zul.Hbox;
-import org.zkoss.zul.Listcell;
-import org.zkoss.zul.Separator;
-
-/**
- * Generate Invoices Manual : Based on VInvoiceGen
- *
- * @author Niraj Sohun
- * @date Jul 5, 2007
- */
-
-public class WInvoiceGen extends ADForm implements EventListener, ValueChangeListener, WTableModelListener
-{
- private static final long serialVersionUID = 1L;
-
- private Separator separator;
-
- private Tabbox tabbox;
-
- private Tabs tabs;
- private Tab tabSelect;
- private Tab tabGenerate;
-
- private Tabpanels tabpanels;
- private Tabpanel pnlSelect;
- private Tabpanel pnlGenerate;
-
- // Panel Select
-
- private WEditor organizationSearch;
- private WEditor bPartnerSearch;
- private WListbox lstSelect;
-
- // Panel Generate
-
- private Label lblGenerate;
- private Label lblNote;
- private Listbox lstGenerate;
-
- private Button btnOk;
- private Button btnCancel;
-
- private Label lblStatus;
- private Label lblNumSelected;
-
- private boolean m_selectionActive = true;
- private ArrayList selections = null;
-
- @SuppressWarnings("unused")
- private Object m_AD_Org_ID;
-
- @SuppressWarnings("unused")
- private Object m_C_BPartner_ID;
-
- private static CLogger log = CLogger.getCLogger(WInvoiceGen.class);
-
- public WInvoiceGen()
- {
- }
-
- protected void initForm()
- {
- separator = new Separator();
- separator.setHeight("5px");
-
- tabbox = new Tabbox();
- tabbox.setWidth("700px");
-
- tabs = new Tabs();
-
- tabSelect = new Tab();
- tabSelect.setLabel("Select");
- tabSelect.addEventListener(Events.ON_SELECT, this);
-
- tabGenerate = new Tab();
- tabGenerate.setLabel("Generate");
- tabGenerate.addEventListener(Events.ON_SELECT, this);
-
- tabpanels = new Tabpanels();
-
- pnlSelect = new Tabpanel();
- pnlGenerate = new Tabpanel();
-
- lstSelect = new WListbox();
- lstSelect.setWidth("690px");
- lstSelect.setHeight("250px");
- lstSelect.addEventListener(Events.ON_SELECT, this);
- lstSelect.getModel().addTableModelListener(this);
-
- btnCancel = new Button();
- btnCancel.setImage("/images/Cancel24.png");
- btnCancel.addEventListener(Events.ON_CLICK, this);
-
- btnOk = new Button();
- btnOk.setImage("/images/Ok24.png");
- btnOk.addEventListener(Events.ON_CLICK, this);
-
- lblGenerate = new Label();
- lblGenerate.setWidth("450px");
- lblGenerate.setMultiline(true);
-
- lblNote = new Label();
- lblNote.setWidth("450px");
- lblNote.setMultiline(true);
-
- lblStatus = new Label(" ");
- lblNumSelected = new Label("Number of Records Selected : 0");
-
- lstGenerate = new Listbox();
- lstGenerate.setWidth("300px");
-
- populateOrganisation();
- showBusinessPartner();
-
- initComponents();
- }
-
- private void initComponents()
- {
- this.setWidth("710px");
-
- tabs.appendChild(tabSelect);
- tabs.appendChild(tabGenerate);
-
- tabpanels.appendChild(pnlSelect);
- tabpanels.appendChild(pnlGenerate);
-
- tabbox.appendChild(tabs);
- tabbox.appendChild(tabpanels);
-
- Hbox mainBox = new Hbox();
- mainBox.setWidth("100%");
- mainBox.setStyle("text-align:center");
-
- Hbox hOrg = new Hbox();
- hOrg.setWidth("100%");
-
- Hbox hBP = new Hbox();
- hBP.setWidth("100%");
-
- mainBox.appendChild(hOrg);
- mainBox.appendChild(hBP);
-
- Panel pnl1 = new Panel();
- pnl1.appendChild(organizationSearch.getLabel());
- pnl1.setStyle("text-align:right");
-
- Panel pnl2 = new Panel();
- pnl2.appendChild(organizationSearch.getComponent());
- pnl2.setStyle("text-align:left");
-
- Panel pnl3 = new Panel();
- pnl3.appendChild(bPartnerSearch.getLabel());
- pnl3.setStyle("text-align:right");
-
- Panel pnl4 = new Panel();
- pnl4.appendChild(bPartnerSearch.getComponent());
- pnl4.setStyle("text-align:left");
-
- hOrg.appendChild(pnl1);
- hOrg.appendChild(pnl2);
-
- hBP.appendChild(pnl3);
- hBP.appendChild(pnl4);
-
- pnlSelect.setStyle("text-align:center");
- pnlSelect.appendChild(mainBox);
- pnlSelect.appendChild(new Separator());
- pnlSelect.appendChild(lstSelect);
- pnlSelect.appendChild(new Separator());
-
- pnlSelect.addEventListener(Events.ON_SELECT, this);
-
- pnlGenerate.appendChild(lblGenerate);
- pnlGenerate.appendChild(lblNote);
- pnlGenerate.appendChild(new Separator());
- pnlGenerate.appendChild(lstGenerate);
-
- this.appendChild(tabbox);
- this.appendChild(new Separator());
-
- Hbox hbox = new Hbox();
- hbox.setWidth("80px");
- hbox.appendChild(btnCancel);
- hbox.appendChild(btnOk);
-
- //pnlSelect.appendChild(hbox);
- //pnlSelect.appendChild(new Separator());
-
- this.appendChild(hbox);
- this.appendChild(new Separator());
-
- hbox = new Hbox();
- hbox.setWidth("700px");
-
- Panel p = new Panel();
- p.setStyle("text-align:left");
- p.appendChild(lblStatus);
- hbox.appendChild(p);
-
- p = new Panel();
- p.setStyle("text-align:right");
- p.appendChild(lblNumSelected);
- hbox.appendChild(p);
-
- //pnlSelect.appendChild(hbox);
- this.appendChild(hbox);
-
- prepareTable();
- populateOrganisation();
- }
-
- private void prepareTable()
- {
- // Create Columns
-
- ListHead listhead = new ListHead();
- listhead.setSizable(true);
-
- listhead.appendChild(new ListHeader(""));
- listhead.appendChild(new ListHeader("Organization"));
- listhead.appendChild(new ListHeader("Document Type"));
- listhead.appendChild(new ListHeader("Document No"));
- listhead.appendChild(new ListHeader("Business Partner"));
- listhead.appendChild(new ListHeader("Date Ordered"));
- listhead.appendChild(new ListHeader("Total Lines"));
-
- lstSelect.appendChild(listhead);
-
- lstSelect.addColumn("C_Order_ID");
- lstSelect.addColumn("AD_Org_ID");
- lstSelect.addColumn("C_DocType_ID");
- lstSelect.addColumn("DocumentNo");
- lstSelect.addColumn("C_BPartner_ID");
- lstSelect.addColumn("DateOrdered");
- lstSelect.addColumn("TotalLines");
-
- lstSelect.setMultiSelection(true);
-
- // Set Details
-
- lstSelect.setColumnClass(0, IDColumn.class, false, " ");
- lstSelect.setColumnClass(1, String.class, true, Msg.translate(Env.getCtx(), "AD_Org_ID"));
- lstSelect.setColumnClass(2, String.class, true, Msg.translate(Env.getCtx(), "C_DocType_ID"));
- lstSelect.setColumnClass(3, String.class, true, Msg.translate(Env.getCtx(), "DocumentNo"));
- lstSelect.setColumnClass(4, String.class, true, Msg.translate(Env.getCtx(), "C_BPartner_ID"));
- lstSelect.setColumnClass(5, Timestamp.class, true, Msg.translate(Env.getCtx(), "DateOrdered"));
- lstSelect.setColumnClass(6, BigDecimal.class, true, Msg.translate(Env.getCtx(), "TotalLines"));
-
- // Set Status
-
- lblStatus.setValue(Msg.getMsg(Env.getCtx(), "InvGenerateSel"));
- //statusBar.setStatusDB(" ");
- }
-
- private void populateOrganisation()
- {
- final int AD_Column_ID = 2163;
-
- MLookup lookupBP = MLookupFactory.get(Env.getCtx(), m_WindowNo,
- 0, AD_Column_ID, DisplayType.TableDir);
-
- organizationSearch = new WTableDirEditor(lookupBP, Msg.translate(
- Env.getCtx(), "AD_Org_ID"), "", true, false, true);
-
- organizationSearch.addValueChangeListener(this);
- }
-
- private void showBusinessPartner()
- {
- final int AD_Column_ID = 3499;
-
- MLookup lookupBP = MLookupFactory.get(Env.getCtx(), m_WindowNo,
- 0, AD_Column_ID, DisplayType.Search);
-
- bPartnerSearch = new WSearchEditor(lookupBP, Msg.translate(
- Env.getCtx(), "C_BPartner_ID"), "", true, false, true);
-
- bPartnerSearch.addValueChangeListener(this);
- }
-
-
- private void executeQuery()
- {
- log.info("");
-
- int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
-
- // Create SQL
-
- 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 (organizationSearch.getValue() != null)
- {
- sql.append(" AND ic.AD_Org_ID=").append(organizationSearch.getValue().toString());
- }
-
- if (bPartnerSearch.getDisplay() != "")
- {
- sql.append(" AND ic.C_BPartner_ID=").append(bPartnerSearch.getValue().toString());
- }
-
- // 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);
- }
-
- /* end - Exclude locked records; @Trifon */
-
- sql.append(" ORDER BY o.Name,bp.Name,DateOrdered");
-
- // Reset Table
-
- int row = 0;
- lstSelect.clearTable();
-
- // Execute
-
- try
- {
- PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
- pstmt.setInt(1, AD_Client_ID);
- ResultSet rs = pstmt.executeQuery();
-
- while (rs.next())
- {
- // Extend table
-
- lstSelect.setRowCount(row+1);
-
- // Set values
-
- lstSelect.setValueAt(new IDColumn(rs.getInt(1)), row, 0); // C_Order_ID
- lstSelect.setValueAt(rs.getString(2), row, 1); // Org
- lstSelect.setValueAt(rs.getString(3), row, 2); // DocType
- lstSelect.setValueAt(rs.getString(4), row, 3); // Doc No
- lstSelect.setValueAt(rs.getString(5), row, 4); // BPartner
- lstSelect.setValueAt(rs.getTimestamp(6), row, 5); // DateOrdered
- lstSelect.setValueAt(rs.getBigDecimal(7), row, 6); // TotalLines
-
- // Prepare next
-
- row++;
- }
- rs.close();
- pstmt.close();
- }
- catch (SQLException e)
- {
- log.log(Level.SEVERE, sql.toString(), e);
- }
-
- // Set Status
-
- //statusBar.setStatusDB(String.valueOf(miniTable.getRowCount()));
- }
-
- private void saveSelection()
- {
- log.info("");
-
- // Array of Integers
-
- ArrayList results = new ArrayList();
-
- if (selections != null)
- selections.clear();
-
- // Get Selected Entries
-
- int rows = lstSelect.getItemCount();
-
- for (int i = 0; i < rows; i++)
- {
- // ID in Column 0
-
- IDColumn id = (IDColumn)lstSelect.getValueAt(i, 0);
-
- if (id != null && id.isSelected())
- results.add(id.getRecord_ID());
- }
-
- if (results.size() == 0)
- return;
-
- selections = results;
- }
-
- private void generateInvoices()
- {
- String trxName = Trx.createTrxName("IVG");
- Trx trx = Trx.get(trxName, true); // Trx needs to be committed too
-
- m_selectionActive = false; // Prevents from being called twice
-
- // Set Status
-
- //lblStatus.setValue(Msg.getMsg(Env.getCtx(), "InvGenerateGen"));
- //statusBar.setStatusDB(String.valueOf(selections.size()));
-
- // Prepare Process
-
- int AD_Process_ID = 134; // C_InvoiceCreate
-
- MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
-
- if (!instance.save())
- {
- 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);
-
- 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);
-
- 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
- log.log(Level.SEVERE, msg);
- return;
- }
-
- para = new MPInstancePara(instance, 20);
- para.setParameter("DocAction", "CO");
-
- if (!para.save())
- {
- String msg = "No DocAction Parameter added"; // Not translated
- log.log(Level.SEVERE, msg);
- return;
- }
-
- // Execute Process
-
- ProcessCtl worker = new ProcessCtl(null, m_WindowNo, pi, trx);
- worker.start();
-
- lstSelect.clearTable();
-
- displayInfo();
- }
-
- private void displayInfo()
- {
- lblGenerate.setValue("Created = " + selections.size());
- lblNote.setValue("(Invoices are generated depending on the 'Invoice Rule' selection in the Order)");
-
- lstGenerate.getChildren().clear();
-
- for (int i = 0; i < selections.size(); i++)
- {
- ListItem listitem = new ListItem();
- Timestamp time = new Timestamp(System.currentTimeMillis());
- listitem.appendChild(new Listcell(time.toString()));
- listitem.appendChild(new Listcell(selections.get(i).toString()));
-
- lstGenerate.appendChild(listitem);
- }
-
- tabbox.setSelectedPanel(pnlGenerate);
- }
-
- private void generateInvoiceComplete (ProcessInfo pi)
- {
- // Print invoices
-
- int AD_Process_ID = 134;
-
-/* for (int i = 0; i < selections.size(); i++)
- {
- ProcessModalDialog dialog = new ProcessModalDialog(
- null, this.getTitle(), null, 0, AD_Process_ID,
- table_ID, selections.get(i), true);
-
- if (dialog.isValid())
- {
- dialog.setPosition("center");
-
- try
- {
- dialog.doModal();
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- }
- }*/
- }
-
-
-
- public void onEvent(Event evt)
- {
- if (evt != null)
- {
- if (evt.getTarget() == tabSelect)
- {
- m_selectionActive = true;
-
- executeQuery();
- }
-
- if ((evt.getTarget() == organizationSearch) || (evt.getTarget() == bPartnerSearch))
- {
- if (evt.getTarget() == organizationSearch)
- {
- m_AD_Org_ID = organizationSearch.getValue();
- }
-
- if (evt.getTarget() == bPartnerSearch)
- {
- m_C_BPartner_ID = bPartnerSearch.getValue();
- }
-
- executeQuery();
- }
-
- if ((evt.getTarget() == btnOk) || (evt.getTarget() == btnCancel))
- {
- if (evt.getTarget() == btnCancel)
- {
- SessionManager.getAppDesktop().removeWindow();
- }
-
- saveSelection();
-
- if (selections != null && selections.size() > 0 && m_selectionActive)
- generateInvoices();
- else
- SessionManager.getAppDesktop().removeWindow();
- }
- }
- }
-
-
- public void valueChange(ValueChangeEvent evt)
- {
- if (evt == null)
- return;
-
- if (evt.getSource() instanceof WEditor)
- {
- String name = evt.getPropertyName();
- Object value = evt.getNewValue() == null ? "" : evt.getNewValue();
-
- if (name.equals("C_BPartner_ID"))
- {
- bPartnerSearch.setValue(value);
- m_C_BPartner_ID = ((Integer) value).intValue();
-
- executeQuery();
- }
-
- if (name.equals("AD_Org_ID"))
- {
- organizationSearch.setValue(value);
- m_AD_Org_ID = ((Integer) value).intValue();
-
- executeQuery();
- }
- }
- }
-
- public void tableChanged(WTableModelEvent event)
- {
- int rowsSelected = 0;
- int rows = lstSelect.getItemCount();
-
- for (int i = 0; i < rows; i++)
- {
- // ID in column 0
- IDColumn id = (IDColumn)lstSelect.getValueAt(i, 0);
-
- if (id != null && id.isSelected())
- rowsSelected++;
- }
-
- // Set Status
-
- Integer size = rowsSelected;
- lblNumSelected.setValue("Number of Records Selected : " + size.toString());
- }
-}
+/******************************************************************************
+ * Product: Adempiere ERP & CRM Smart Business Solution *
+ * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
+ * 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. *
+ * 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.io.FileOutputStream;
+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.logging.Level;
+
+import org.adempiere.webui.LayoutUtils;
+import org.adempiere.webui.component.ConfirmPanel;
+import org.adempiere.webui.component.DesktopTabpanel;
+import org.adempiere.webui.component.Label;
+import org.adempiere.webui.component.Listbox;
+import org.adempiere.webui.component.ListboxFactory;
+import org.adempiere.webui.component.Panel;
+import org.adempiere.webui.component.Tab;
+import org.adempiere.webui.component.Tabbox;
+import org.adempiere.webui.component.Tabpanels;
+import org.adempiere.webui.component.Tabs;
+import org.adempiere.webui.component.WListbox;
+import org.adempiere.webui.component.Window;
+import org.adempiere.webui.editor.WSearchEditor;
+import org.adempiere.webui.editor.WTableDirEditor;
+import org.adempiere.webui.event.ValueChangeEvent;
+import org.adempiere.webui.event.ValueChangeListener;
+import org.adempiere.webui.event.WTableModelEvent;
+import org.adempiere.webui.event.WTableModelListener;
+import org.adempiere.webui.panel.ADForm;
+import org.adempiere.webui.panel.StatusBarPanel;
+import org.adempiere.webui.session.SessionManager;
+import org.adempiere.webui.window.FDialog;
+import org.adempiere.webui.window.SimplePDFViewer;
+import org.compiere.apps.ProcessCtl;
+import org.compiere.minigrid.IDColumn;
+import org.compiere.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.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;
+
+import com.lowagie.text.Document;
+import com.lowagie.text.pdf.PdfContentByte;
+import com.lowagie.text.pdf.PdfImportedPage;
+import com.lowagie.text.pdf.PdfReader;
+import com.lowagie.text.pdf.PdfWriter;
+
+/**
+ * Manual Invoice Selection
+ *
+ * @author Jorg Janke
+ * @version $Id: VInvoiceGen.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
+ */
+public class WInvoiceGen extends ADForm
+ implements EventListener, ValueChangeListener, WTableModelListener
+{
+ /**
+ * Initialize Panel
+ */
+ protected void initForm()
+ {
+ log.info("");
+ Env.setContext(Env.getCtx(), m_WindowNo, "IsSOTrx", "Y");
+ try
+ {
+ fillPicks();
+ zkInit();
+ dynInit();
+ Borderlayout contentPane = new Borderlayout();
+ this.appendChild(contentPane);
+ contentPane.setWidth("99%");
+ contentPane.setHeight("100%");
+ Center center = new Center();
+ center.setStyle("border: none");
+ contentPane.appendChild(center);
+ center.appendChild(tabbedPane);
+ center.setFlex(true);
+ South south = new South();
+ south.setStyle("border: none");
+ contentPane.appendChild(south);
+ south.appendChild(statusBar);
+ LayoutUtils.addSclass("status-border", statusBar);
+ south.setHeight("22px");
+ }
+ 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 Panel selNorthPanel = new Panel();
+ 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 selections = null;
+
+ private Label lDocType = new Label();
+ private Listbox cmbDocType = ListboxFactory.newDropdownListbox();
+ private ProcessInfo m_pi;
+ private int[] m_ids;
+
+ /**
+ * Static Init.
+ *
+ * selPanel (tabbed)
+ * fOrg, fBPartner
+ * scrollPane & miniTable
+ * genPanel
+ * info
+ *
+ * @throws Exception
+ */
+ 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);
+
+ North north = new North();
+ selPanel.appendChild(north);
+ north.appendChild(selNorthPanel);
+ selNorthPanel.appendChild(lOrg);
+ selNorthPanel.appendChild(fOrg.getComponent());
+ selNorthPanel.appendChild(new Space());
+ selNorthPanel.appendChild(lBPartner);
+ selNorthPanel.appendChild(fBPartner.getComponent());
+ selNorthPanel.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);
+
+ selNorthPanel.appendChild(lDocType);
+ selNorthPanel.appendChild(cmbDocType);
+ } // jbInit
+
+ /**
+ * Fill Picks
+ * Column_ID from C_Order
+ * @throws Exception if Lookups cannot be initialized
+ */
+ private void fillPicks() throws Exception
+ {
+ MLookup orgL = MLookupFactory.get (Env.getCtx(), m_WindowNo, 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);
+ fBPartner = new WSearchEditor ("C_BPartner_ID", false, false, true, bpL);
+ // lBPartner.setText(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
+ fBPartner.addValueChangeListener(this);
+
+// Document Type Sales Order/Vendor RMA
+ 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.setSelectedIndex(0);
+ } // fillPicks
+
+ /**
+ * Dynamic Init.
+ * - Create GridController & Panel
+ * - AD_Column_ID from C_Order
+ */
+ private void dynInit()
+ {
+ // create Columns
+ miniTable.addColumn("C_Order_ID");
+ miniTable.addColumn("AD_Org_ID");
+ miniTable.addColumn("C_DocType_ID");
+ miniTable.addColumn("DocumentNo");
+ miniTable.addColumn("C_BPartner_ID");
+ miniTable.addColumn("DateOrdered");
+ miniTable.addColumn("TotalLines");
+ //
+ miniTable.setMultiSelection(true);
+ // 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();
+ }
+ /**
+ * Query Info
+ */
+ private 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()));
+ } // executeQuery
+
+ /**
+ * Action Listener
+ * @param e event
+ */
+ public void onEvent (Event e)
+ {
+ log.info("Cmd=" + e.getTarget().getId());
+ //
+ if (e.getTarget().getId().equals(ConfirmPanel.A_CANCEL))
+ {
+ dispose();
+ return;
+ }
+ else if (e.getTarget() instanceof Tab)
+ {
+ int index = tabbedPane.getSelectedIndex();
+ m_selectionActive = (index == 0);
+ return;
+ }
+ else if (cmbDocType.equals(e.getTarget()))
+ {
+ executeQuery();
+ return;
+ }
+ //
+ saveSelection();
+ if (selections != null && selections.size() > 0 && m_selectionActive)
+ generateInvoices ();
+ else
+ dispose();
+ } // actionPerformed
+
+ /**
+ * Vetoable Change Listener - requery
+ * @param e event
+ */
+ public void valueChange(ValueChangeEvent e)
+ {
+ log.info(e.getPropertyName() + "=" + e.getNewValue());
+ if (e.getPropertyName().equals("AD_Org_ID"))
+ m_AD_Org_ID = e.getNewValue();
+ if (e.getPropertyName().equals("C_BPartner_ID"))
+ {
+ m_C_BPartner_ID = e.getNewValue();
+ fBPartner.setValue(m_C_BPartner_ID); // display value
+ }
+ executeQuery();
+ } // 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 results = new ArrayList();
+ 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
+ */
+ 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;
+ }
+ para = new MPInstancePara(instance, 20);
+ para.setParameter("DocAction", "CO");
+ 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 ()
+ {
+ Clients.showBusy(null, false);
+
+ // Switch Tabs
+ tabbedPane.setSelectedIndex(1);
+ //
+ ProcessInfoUtil.setLogFromDB(m_pi);
+ StringBuffer iText = new StringBuffer();
+ iText.append("").append(m_pi.getSummary())
+ .append("
(")
+ .append(Msg.getMsg(Env.getCtx(), "InvGenerateInfo"))
+ //Invoices are generated depending on the Invoicing Rule selection in the Order
+ .append(")
")
+ .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
+
+ public void onAfterProcess()
+ {
+ // 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
+ }
+
+ public void onPrintInvoices()
+ {
+ // Loop through all items
+ List pdfList = new ArrayList();
+ 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");
+ Document document = null;
+ PdfWriter copy = null;
+ for (File f : pdfList)
+ {
+ PdfReader reader = new PdfReader(f.getAbsolutePath());
+ if (document == null)
+ {
+ document = new Document(reader.getPageSizeWithRotation(1));
+ copy = PdfWriter.getInstance(document, new FileOutputStream(outFile));
+ document.open();
+ }
+ int pages = reader.getNumberOfPages();
+ PdfContentByte cb = copy.getDirectContent();
+ for (int i = 1; i <= pages; i++) {
+ document.newPage();
+ PdfImportedPage page = copy.getImportedPage(reader, i);
+ cb.addTemplate(page, 0, 0);
+ }
+ }
+ document.close();
+
+ 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().removeWindow();
+ }
+
+
+
+} // VInvoiceGen
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WMerge.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WMerge.java
index 4544028022..09e2095dc7 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WMerge.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WMerge.java
@@ -1,571 +1,539 @@
-/******************************************************************************
- * Product: Adempiere ERP & CRM Smart Business Solution *
- * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
- * 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. *
- * 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 *
- *****************************************************************************/
-
-/**
- * 2007, Modified by Posterita Ltd.
- */
-
-package org.adempiere.webui.apps.form;
-
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-
-import org.adempiere.webui.component.Grid;
-import org.adempiere.webui.component.Label;
-import org.adempiere.webui.component.Row;
-import org.adempiere.webui.component.Rows;
-import org.adempiere.webui.component.ConfirmPanel;
-import org.adempiere.webui.editor.WEditor;
-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.session.SessionManager;
-import org.adempiere.webui.window.FDialog;
-import org.compiere.model.MBPartner;
-import org.compiere.model.MInvoice;
-import org.compiere.model.MLookup;
-import org.compiere.model.MLookupFactory;
-import org.compiere.model.MPayment;
-import org.compiere.model.X_M_Cost;
-import org.compiere.util.CLogger;
-import org.compiere.util.DB;
-import org.compiere.util.DisplayType;
-import org.compiere.util.Env;
-import org.compiere.util.Msg;
-import org.compiere.util.Trx;
-import org.zkoss.zk.ui.event.Event;
-import org.zkoss.zk.ui.event.EventListener;
-
-/**
- * Merge Entities : Based on VMerge
- *
- * @author Niraj Sohun
- * @date Jul 28, 2007
- */
-
-public class WMerge extends ADForm implements EventListener, ValueChangeListener
-{
- private static final long serialVersionUID = 1L;
-
- private static CLogger log = CLogger.getCLogger(WInvoiceGen.class);
-
- private Grid grdAll;
- private Rows rows;
- private Row row;
-
- /** Confirmation panel containing Ok and Cancel button. */
- private ConfirmPanel m_pnlConfirm;
-
- private WEditor[] from = new WEditor[4];
- private WEditor[] to = new WEditor[4];
-
- private int[] fromIDs = new int[4];
- private int[] toIDs = new int[4];
-
- private int[] AD_Column_ID = new int[] {2163, 2762, 971, 2221};
- private String[] text = new String[] {"AD_Org_ID", "C_BPartner_ID", "AD_User_ID", "M_Product_ID"};
-
- private int m_totalCount;
-
- private StringBuffer m_errorLog;
-
- private Trx m_trx;
-
- static private String AD_ORG_ID = "AD_Org_ID";
- static private String C_BPARTNER_ID = "C_BPartner_ID";
- static private String AD_USER_ID = "AD_User_ID";
- static private String M_PRODUCT_ID = "M_Product_ID";
-
- /** Tables to delete (not update) for AD_Org */
- static private String[] s_delete_Org = new String[] {"AD_OrgInfo"};
-
- /** Tables to delete (not update) for AD_User */
- static private String[] s_delete_User = new String[] {"AD_User_Roles"};
-
- /** Tables to delete (not update) for C_BPartner */
- static private String[] s_delete_BPartner = new String[] {"C_BP_Employee_Acct",
- "C_BP_Vendor_Acct", "C_BP_Customer_Acct", "T_Aging"};
-
- /** Tables to delete (not update) for M_Product */
- static private String[] s_delete_Product = new String[] {"M_Product_PO", "M_Replenish", "T_Replenish",
- "M_ProductPrice", "M_Product_Costing",
- "M_Cost", // teo_sarca [ 1704554 ]
- "M_Product_Trl", "M_Product_Acct"}; // M_Storage
-
- private String[] m_columnName = new String[]{"AD_Org_ID", "C_BPartner_ID", "AD_User_ID", "M_Product_ID"};
- private String[] m_deleteTables = null;
-
- public WMerge()
- {
- }
-
- protected void initForm()
- {
- grdAll = new Grid();
- grdAll.setWidth("700px");
-
- /*btnCancel = new Button();
- btnCancel.setImage("/images/Cancel24.png");
- btnCancel.addEventListener(Events.ON_CLICK, this);
-
- btnOk = new Button();
- btnOk.setImage("/images/Ok24.png");
- btnOk.addEventListener(Events.ON_CLICK, this);*/
-
- m_pnlConfirm = new ConfirmPanel(true);
- m_pnlConfirm.addActionListener(this);
-
- initComponents();
- }
-
- public void initComponents()
- {
- this.setWidth("710px");
- this.setBorder("normal");
-
- components();
-
- rows = new Rows();
-
- // Row 1
- row = new Row();
- row.appendChild(new Label(""));
- row.appendChild(new Label("Merge From (Deleted)"));
- row.appendChild(new Label("Merge To (Surviving)"));
- rows.appendChild(row);
-
- for (int i = 0; i < 4; i++)
- {
- row = new Row();
- row.appendChild(from[i].getLabel());
- row.appendChild(from[i].getComponent());
- row.appendChild(to[i].getComponent());
- rows.appendChild(row);
- }
-
- grdAll.appendChild(rows);
- this.appendChild(grdAll);
-
- // Row 6
- this.appendChild(m_pnlConfirm);
- }
-
- private void components()
- {
- MLookup lookup = MLookupFactory.get(Env.getCtx(), m_WindowNo,
- 0, AD_Column_ID[0], DisplayType.TableDir);
-
- from[0] = new WTableDirEditor(lookup, Msg.translate(
- Env.getCtx(), text[0]), "from", true, false, true);
-
- from[0].addValueChangeListener(this);
-
- to[0] = new WTableDirEditor(lookup, Msg.translate(
- Env.getCtx(), text[0]), "to", true, false, true);
-
- to[0].addValueChangeListener(this);
-
-
- // Search Editors
-
- for (int i = 1; i < AD_Column_ID.length; i++)
- {
- lookup = MLookupFactory.get(Env.getCtx(), m_WindowNo,
- 0, AD_Column_ID[i], DisplayType.Search);
-
- from[i] = new WSearchEditor(lookup, Msg.translate(
- Env.getCtx(), text[i]), "from", true, false, true);
-
- from[i].addValueChangeListener(this);
-
- to[i] = new WSearchEditor(lookup, Msg.translate(
- Env.getCtx(), text[i]), "to", true, false, true);
-
- to[i].addValueChangeListener(this);
- }
- }
-
- public void valueChange(ValueChangeEvent evt)
- {
- if (evt == null)
- {
- return;
- }
-
- WEditor edit = (WEditor)evt.getSource();
- String des = edit.getDescription();
-
- String name = evt.getPropertyName();
- Object value = evt.getNewValue();
-
-
- if (name.equals("AD_Org_ID"))
- {
- if (des.equals("from"))
- {
- from[0].setValue(value);
- fromIDs[0] = ((Integer)value).intValue();
- }
- else
- {
- to[0].setValue(value);
- toIDs[0] = ((Integer)value).intValue();
- }
- }
- else if (name.equals("C_BPartner_ID"))
- {
- if (des.equals("from"))
- {
- from[1].setValue(value);
- fromIDs[1] = ((Integer)value).intValue();
- }
- else
- {
- to[1].setValue(value);
- toIDs[1] = ((Integer)value).intValue();
- }
- }
- else if (name.equals("M_Product_ID"))
- {
- if (des.equals("from"))
- {
- from[3].setValue(value);
- fromIDs[3] = ((Integer)value).intValue();
- }
- else
- {
- to[3].setValue(value);
- toIDs[3] = ((Integer)value).intValue();
- }
- }
- else if (name.equals("AD_User_ID"))
- {
- if (des.equals("from"))
- {
- from[2].setValue(value);
- fromIDs[2] = ((Integer)value).intValue();
- }
- else
- {
- to[2].setValue(value);
- toIDs[2] = ((Integer)value).intValue();
- }
- }
- }
-
- private boolean merge (String ColumnName, int from_ID, int to_ID)
- {
- String TableName = ColumnName.substring(0, ColumnName.length()-3);
-
- //log.config(ColumnName + " - From=" + from_ID + ",To=" + to_ID);
-
- boolean success = true;
- m_totalCount = 0;
- m_errorLog = new StringBuffer();
-
- String sql = "SELECT t.TableName, c.ColumnName "
- + "FROM AD_Table t"
- + " INNER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID) "
- + "WHERE t.IsView='N'"
- + " AND t.TableName NOT IN ('C_TaxDeclarationAcct')"
- + " AND ("
- + "(c.ColumnName=? AND c.IsKey='N')" // #1 - direct
- + " OR "
- + "c.AD_Reference_Value_ID IN " // Table Reference
- + "(SELECT rt.AD_Reference_ID FROM AD_Ref_Table rt"
- + " INNER JOIN AD_Column cc ON (rt.AD_Table_ID=cc.AD_Table_ID AND rt.AD_Key=cc.AD_Column_ID) "
- + "WHERE cc.IsKey='Y' AND cc.ColumnName=?)" // #2
- + ") "
- + "ORDER BY t.LoadSeq DESC";
-
- PreparedStatement pstmt = null;
-
- try
- {
-
- m_trx = Trx.get(Trx.createTrxName("merge"), true);
-
- pstmt = DB.prepareStatement(sql, Trx.createTrxName());
- pstmt.setString(1, ColumnName);
- pstmt.setString(2, ColumnName);
- ResultSet rs = pstmt.executeQuery();
-
- while (rs.next())
- {
- String tName = rs.getString(1);
- String cName = rs.getString(2);
-
- if (!TableName.equals(tName)) // to be sure - sql should prevent it
- {
- int count = mergeTable (tName, cName, from_ID, to_ID);
-
- if (count < 0)
- success = false;
- else
- m_totalCount += count;
- }
- }
- rs.close();
- pstmt.close();
- pstmt = null;
-
- //log.config("Success=" + success + " - " + ColumnName + " - From=" + from_ID + ",To=" + to_ID);
-
- if (success)
- {
- sql = "DELETE " + TableName + " WHERE " + ColumnName + "=" + from_ID;
-
- if ( DB.executeUpdate(sql, m_trx.getTrxName()) < 0 )
- {
- m_errorLog.append(Env.NL).append("DELETE ").append(TableName).append(" - ");
- success = false;
- //log.config(m_errorLog.toString());
- m_trx.rollback();
- return false;
- }
-
- }
-
- if (success)
- m_trx.commit();
- else
- m_trx.rollback();
-
- m_trx.close();
-
- }
- catch (Exception ex)
- {
- // log.log(Level.SEVERE, ColumnName, ex);
- }
-
- // Cleanup
- try
- {
- if (pstmt != null)
- pstmt.close();
- }
- catch (Exception ex)
- {
- }
-
- pstmt = null;
- return success;
- }
-
- /**
- * Merge Table
- * @param TableName table
- * @param ColumnName column
- * @param from_ID from
- * @param to_ID to
- * @return -1 for error or number of changes
- */
-
- private int mergeTable (String TableName, String ColumnName, int from_ID, int to_ID)
- {
- // log.fine(TableName + "." + ColumnName + " - From=" + from_ID + ",To=" + to_ID);
-
- String sql = "UPDATE " + TableName
- + " SET " + ColumnName + "=" + to_ID
- + " WHERE " + ColumnName + "=" + from_ID;
-
- boolean delete = false;
-
- for (int i = 0; i < m_deleteTables.length; i++)
- {
- if (m_deleteTables[i].equals(TableName))
- {
- delete = true;
- sql = "DELETE " + TableName + " WHERE " + ColumnName + "=" + from_ID;
- }
- }
-
- // Delete newly created MCost records - teo_sarca [ 1704554 ]
- if (delete && X_M_Cost.Table_Name.equals(TableName) && M_PRODUCT_ID.equals(ColumnName))
- {
- sql += " AND " + X_M_Cost.COLUMNNAME_CurrentCostPrice + "=0"
- + " AND " + X_M_Cost.COLUMNNAME_CurrentQty + "=0"
- + " AND " + X_M_Cost.COLUMNNAME_CumulatedAmt + "=0"
- + " AND " + X_M_Cost.COLUMNNAME_CumulatedQty + "=0";
- }
-
- int count = DB.executeUpdate(sql, m_trx.getTrxName());
-
-
- if ( count < 0 )
- {
- count = -1;
- m_errorLog.append(Env.NL).append(delete ? "DELETE " : "UPDATE ").append(TableName).append(" - ").append(" - ").append(sql);
- //log.config(m_errorLog.toString());
- m_trx.rollback();
-
- }
- //log.fine(count + (delete ? " -Delete- " : " -Update- ") + TableName);
-
- return count;
- }
-
- /**
- * Post Merge
- * @param ColumnName column name
- * @param to_ID ID
- */
-
- private void postMerge (String ColumnName, int to_ID)
- {
- if (ColumnName.equals(AD_ORG_ID))
- {
-
- }
- else if (ColumnName.equals(AD_USER_ID))
- {
-
- }
- else if (ColumnName.equals(C_BPARTNER_ID))
- {
- MBPartner bp = new MBPartner (Env.getCtx(), to_ID, null);
- if (bp.get_ID() != 0)
- {
- MPayment[] payments = MPayment.getOfBPartner(Env.getCtx(), bp.getC_BPartner_ID(), null);
- for (int i = 0; i < payments.length; i++)
- {
- MPayment payment = payments[i];
- if (payment.testAllocation())
- payment.save();
- }
- MInvoice[] invoices = MInvoice.getOfBPartner(Env.getCtx(), bp.getC_BPartner_ID(), null);
- for (int i = 0; i < invoices.length; i++)
- {
- MInvoice invoice = invoices[i];
- if (invoice.testAllocation())
- invoice.save();
- }
- bp.setTotalOpenBalance();
- bp.setActualLifeTimeValue();
- bp.save();
- }
- }
- else if (ColumnName.equals(M_PRODUCT_ID))
- {
-
- }
- }
-
- private void process()
- {
- String columnName = null;
- String from_Info = null;
- String to_Info = null;
- int from_ID = 0;
- int to_ID = 0;
-
- for (int i = 0; (i < m_columnName.length && from_ID == 0 && to_ID == 0); i++)
- {
- Object value;
-
- value = from[i].getValue();
-
- if (value != null)
- {
- if (value instanceof Integer)
- from_ID = ((Integer)value).intValue();
- else
- continue;
-
- value = to[i].getValue();
-
- if (value != null && value instanceof Integer)
- to_ID = ((Integer)value).intValue();
- else
- from_ID = 0;
-
- if (from_ID != 0)
- {
- columnName = m_columnName[i];
-
- from_Info = from[i].getDisplay ();
- to_Info = to[i].getDisplay ();
- }
- }
- } // get first merge pair
-
- if (from_ID == 0 || from_ID == to_ID)
- return;
-
- String msg = Msg.getMsg(Env.getCtx(), "MergeFrom") + " = " + from_Info
- + "\n" + Msg.getMsg(Env.getCtx(), "MergeTo") + " = " + to_Info;
-
- //if (!FDialog.ask(super.m_windowNo, this, msg))
- // return;
-
- // ** Update **
-
- if (columnName.equals(AD_ORG_ID))
- m_deleteTables = s_delete_Org;
- else if (columnName.equals(AD_USER_ID))
- m_deleteTables = s_delete_User;
- else if (columnName.equals(C_BPARTNER_ID))
- m_deleteTables = s_delete_BPartner;
- else if (columnName.equals(M_PRODUCT_ID))
- m_deleteTables = s_delete_Product;
-
- //setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- //confirmPanel.getOKButton().setEnabled(false);
-
- boolean success = merge (columnName, from_ID, to_ID);
- postMerge(columnName, to_ID);
-
- //confirmPanel.getOKButton().setEnabled(true);
- //setCursor(Cursor.getDefaultCursor());
- //
-
- if (success)
- {
- FDialog.info (m_WindowNo, this, msg);
- }
- else
- {
- FDialog.error(m_WindowNo, this, "MergeError", m_errorLog.toString());
- return;
- }
- }
-
- /**
- * React to Ok and Cancel buttons being triggered.
- *
- * @param event the event to which to respond
- * @throws Exception if an exception occurred
- */
- public void onEvent(Event event) throws Exception
- {
- if (event != null)
- {
- if (event.getTarget().getId().equals(ConfirmPanel.A_CANCEL))
- {
- SessionManager.getAppDesktop().removeWindow();
- return;
- }
- else if (event.getTarget().getId().equals(ConfirmPanel.A_OK))
- {
- process();
- }
- }
- }
-}
+/******************************************************************************
+ * Product: Adempiere ERP & CRM Smart Business Solution *
+ * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
+ * 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. *
+ * 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.sql.*;
+import java.util.logging.*;
+
+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.Panel;
+import org.adempiere.webui.component.Row;
+import org.adempiere.webui.component.Rows;
+import org.adempiere.webui.editor.WEditor;
+import org.adempiere.webui.editor.WSearchEditor;
+import org.adempiere.webui.editor.WTableDirEditor;
+import org.adempiere.webui.panel.ADForm;
+import org.adempiere.webui.session.SessionManager;
+import org.adempiere.webui.window.FDialog;
+import org.compiere.model.*;
+import org.compiere.util.*;
+import org.zkoss.zk.au.out.AuEcho;
+import org.zkoss.zk.ui.Desktop;
+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.util.Clients;
+import org.zkoss.zkex.zul.Borderlayout;
+import org.zkoss.zkex.zul.Center;
+import org.zkoss.zkex.zul.South;
+
+/**
+ * Merge Dialog.
+ * Restriction - fails for Accounting
+ *
+ * @author Jorg Janke
+ * @version $Id: VMerge.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
+ */
+public class WMerge extends ADForm
+ implements EventListener
+{
+ private int m_totalCount = 0;
+ /** Error Log */
+ private StringBuffer m_errorLog = new StringBuffer();
+ /** Connection */
+ //private Connection m_con = null;
+ private Trx m_trx = null;
+ /** Logger */
+ private static CLogger log = CLogger.getCLogger(WMerge.class);
+
+ static private String AD_ORG_ID = "AD_Org_ID";
+ static private String C_BPARTNER_ID = "C_BPartner_ID";
+ static private String AD_USER_ID = "AD_User_ID";
+ static private String M_PRODUCT_ID = "M_Product_ID";
+
+ /** Tables to delete (not update) for AD_Org */
+ static private String[] s_delete_Org = new String[]
+ {"AD_OrgInfo"};
+ /** Tables to delete (not update) for AD_User */
+ static private String[] s_delete_User = new String[]
+ {"AD_User_Roles"};
+ /** Tables to delete (not update) for C_BPartner */
+ static private String[] s_delete_BPartner = new String[]
+ {"C_BP_Employee_Acct", "C_BP_Vendor_Acct", "C_BP_Customer_Acct",
+ "T_Aging"};
+ /** Tables to delete (not update) for M_Product */
+ static private String[] s_delete_Product = new String[]
+ {"M_Product_PO", "M_Replenish", "T_Replenish",
+ "M_ProductPrice", "M_Product_Costing",
+ "M_Cost", // teo_sarca [ 1704554 ]
+ "M_Product_Trl", "M_Product_Acct"}; // M_Storage
+
+ private String[] m_columnName = null;
+ private Label[] m_label = null;
+ private WEditor[] m_from = null;
+ private WEditor[] m_to = null;
+ private String[] m_deleteTables = null;
+
+
+ private Borderlayout mainLayout = new Borderlayout();
+ private Panel CenterPanel = new Panel();
+ private Grid centerLayout = GridFactory.newGridLayout();
+ private Label mergeFromLabel = new Label();
+ private Label mergeToLabel = new Label();
+ private ConfirmPanel confirmPanel = new ConfirmPanel(true);
+ private String m_msg;
+ private boolean m_success;
+
+ /**
+ * Initialize Panel
+ */
+ protected void initForm()
+ {
+ log.info( "VMerge.init - WinNo=" + m_WindowNo);
+ try
+ {
+ preInit();
+ jbInit ();
+ }
+ catch (Exception ex)
+ {
+ log.log(Level.SEVERE, "", ex);
+ }
+ } // init
+
+ /**
+ * Pre Init
+ */
+ private void preInit()
+ {
+ int count = 4; // ** Update **
+ m_columnName = new String[count];
+ m_label = new Label[count];
+ m_from = new WEditor[count];
+ m_to = new WEditor[count];
+
+ // ** Update **
+ preInit (0, 2163, DisplayType.TableDir, AD_ORG_ID); // C_Order.AD_Org_ID
+ preInit (1, 2762, DisplayType.Search, C_BPARTNER_ID); // C_Order.C_BPartner_ID
+ preInit (2, 971, DisplayType.Search, AD_USER_ID); // AD_User_Roles.AD_User_ID
+ preInit (3, 2221, DisplayType.Search, M_PRODUCT_ID); // C_OrderLine.M_Product_ID
+ } // preInit
+
+ /**
+ * Pre Init Line
+ * @param index index
+ * @param AD_Column_ID id
+ * @param displayType display type
+ * @param ColumnName column name
+ */
+ private void preInit (int index, int AD_Column_ID, int displayType, String ColumnName)
+ {
+ m_columnName[index] = ColumnName;
+ String what = Msg.translate(Env.getCtx(), ColumnName);
+ m_label[index] = new Label(what);
+ Lookup lookup = MLookupFactory.get (Env.getCtx(), m_WindowNo, 0, AD_Column_ID, displayType);
+ if (displayType == DisplayType.Search)
+ {
+ m_from[index] = new WSearchEditor(ColumnName, false, false, true, lookup);
+ m_to[index] = new WSearchEditor (ColumnName, false, false, true, lookup);
+ }
+ else
+ {
+ m_from[index] = new WTableDirEditor(ColumnName, false, false, true, lookup);
+ m_to[index] = new WTableDirEditor (ColumnName, false, false, true, lookup);
+ }
+
+ } // preInit
+
+ /**
+ * Static init
+ * @throws java.lang.Exception
+ */
+ void jbInit () throws Exception
+ {
+ this.appendChild (mainLayout);
+ mainLayout.setHeight("100%");
+ mainLayout.setWidth("100%");
+ //
+ South south = new South();
+ mainLayout.appendChild(south);
+ south.appendChild(confirmPanel);
+ confirmPanel.addActionListener(this);
+ //
+ Rows rows = centerLayout.newRows();
+
+ //
+ CenterPanel.appendChild(centerLayout);
+
+ Center center = new Center();
+ mainLayout.appendChild(center);
+ center.appendChild(CenterPanel);
+
+ Row row = rows.newRow();
+ row.appendChild(new Label());
+ row.appendChild(mergeFromLabel);
+ row.appendChild(mergeToLabel);
+ //
+ mergeFromLabel.setText (Msg.getMsg(Env.getCtx(), "MergeFrom"));
+ mergeFromLabel.setStyle("font-weight: bold");
+ mergeToLabel.setText (Msg.getMsg(Env.getCtx(), "MergeTo"));
+ mergeToLabel.setStyle("font-weight: bold");
+ //
+ for (int i = 0; i < m_label.length; i++)
+ {
+ row = rows.newRow();
+ row.appendChild(m_label[i]);
+ row.appendChild(m_from[i].getComponent());
+ row.appendChild(m_to[i].getComponent());
+ }
+ } // jbInit
+
+ /**
+ * Dispose
+ */
+ public void dispose()
+ {
+ SessionManager.getAppDesktop().removeWindow();
+ } // dispose
+
+ /**
+ * Action Listener
+ * @param e event
+ */
+ public void onEvent (Event e)
+ {
+ if (e.getTarget().getId().equals(ConfirmPanel.A_CANCEL))
+ {
+ dispose();
+ return;
+ }
+ //
+ String columnName = null;
+ String from_Info = null;
+ String to_Info = null;
+ int from_ID = 0;
+ int to_ID = 0;
+ // get first merge pair
+ for (int i = 0; (i < m_columnName.length && from_ID == 0 && to_ID == 0); i++)
+ {
+ Object value = m_from[i].getValue();
+ if (value != null)
+ {
+ if (value instanceof Integer)
+ from_ID = ((Integer)value).intValue();
+ else
+ continue;
+ value = m_to[i].getValue();
+ if (value != null && value instanceof Integer)
+ to_ID = ((Integer)value).intValue();
+ else
+ from_ID = 0;
+ if (from_ID != 0)
+ {
+ columnName = m_columnName[i];
+ from_Info = m_from[i].getDisplay ();
+ to_Info = m_to[i].getDisplay ();
+ }
+ }
+ } // get first merge pair
+
+ if (from_ID == 0 || from_ID == to_ID)
+ return;
+
+ m_msg = Msg.getMsg(Env.getCtx(), "MergeFrom") + " = " + from_Info
+ + "\n" + Msg.getMsg(Env.getCtx(), "MergeTo") + " = " + to_Info;
+ if (!FDialog.ask(m_WindowNo, this, "MergeQuestion", m_msg))
+ return;
+
+ // ** Update **
+ if (columnName.equals(AD_ORG_ID))
+ m_deleteTables = s_delete_Org;
+ else if (columnName.equals(AD_USER_ID))
+ m_deleteTables = s_delete_User;
+ else if (columnName.equals(C_BPARTNER_ID))
+ m_deleteTables = s_delete_BPartner;
+ else if (columnName.equals(M_PRODUCT_ID))
+ m_deleteTables = s_delete_Product;
+
+ Clients.showBusy("Processing...", true);
+
+ if (!getDesktop().isServerPushEnabled())
+ getDesktop().enableServerPush(true);
+
+ MergeRunnable runnable = new MergeRunnable(columnName, from_ID, to_ID, this.getDesktop());
+ new Thread(runnable).start();
+
+ } // actionPerformed
+
+ class MergeRunnable implements Runnable {
+ private int to_ID;
+ private int from_ID;
+ private String columnName;
+ private Desktop desktop;
+ private MergeRunnable(String columnName, int from_ID, int to_ID, Desktop desktop) {
+ this.columnName = columnName;
+ this.from_ID = from_ID;
+ this.to_ID = to_ID;
+ this.desktop = desktop;
+ }
+ public void run() {
+ //get full control of desktop
+ try {
+ Executions.activate(desktop);
+ try {
+ m_success = merge (columnName, from_ID, to_ID);
+ postMerge(columnName, to_ID);
+ } finally{
+ Clients.showBusy(null, false);
+ Clients.response(new AuEcho(WMerge.this, "onAfterProcess", null));
+ //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);
+ }
+ }
+ }
+
+ public void onAfterProcess()
+ {
+ if (m_success)
+ {
+ FDialog.info (m_WindowNo, this, "MergeSuccess",
+ m_msg + " #" + m_totalCount);
+ }
+ else
+ {
+ FDialog.error(m_WindowNo, this, "MergeError",
+ m_errorLog.toString());
+ return;
+ }
+ dispose();
+ }
+ /**
+ * Merge.
+ * @param ColumnName column
+ * @param from_ID from
+ * @param to_ID to
+ * @return true if merged
+ */
+ private boolean merge (String ColumnName, int from_ID, int to_ID)
+ {
+ String TableName = ColumnName.substring(0, ColumnName.length()-3);
+ log.config(ColumnName
+ + " - From=" + from_ID + ",To=" + to_ID);
+
+ boolean success = true;
+ m_totalCount = 0;
+ m_errorLog = new StringBuffer();
+ String sql = "SELECT t.TableName, c.ColumnName "
+ + "FROM AD_Table t"
+ + " INNER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID) "
+ + "WHERE t.IsView='N'"
+ + " AND t.TableName NOT IN ('C_TaxDeclarationAcct')"
+ + " AND ("
+ + "(c.ColumnName=? AND c.IsKey='N')" // #1 - direct
+ + " OR "
+ + "c.AD_Reference_Value_ID IN " // Table Reference
+ + "(SELECT rt.AD_Reference_ID FROM AD_Ref_Table rt"
+ + " INNER JOIN AD_Column cc ON (rt.AD_Table_ID=cc.AD_Table_ID AND rt.AD_Key=cc.AD_Column_ID) "
+ + "WHERE cc.IsKey='Y' AND cc.ColumnName=?)" // #2
+ + ") "
+ + "ORDER BY t.LoadSeq DESC";
+ PreparedStatement pstmt = null;
+
+ try
+ {
+
+ m_trx = Trx.get(Trx.createTrxName("merge"), true);
+ //
+ pstmt = DB.prepareStatement(sql, Trx.createTrxName());
+ pstmt.setString(1, ColumnName);
+ pstmt.setString(2, ColumnName);
+ ResultSet rs = pstmt.executeQuery();
+ while (rs.next())
+ {
+ String tName = rs.getString(1);
+ String cName = rs.getString(2);
+ if (!TableName.equals(tName)) // to be sure - sql should prevent it
+ {
+ int count = mergeTable (tName, cName, from_ID, to_ID);
+ if (count < 0)
+ success = false;
+ else
+ m_totalCount += count;
+ }
+ }
+ rs.close();
+ pstmt.close();
+ pstmt = null;
+ //
+ log.config("Success=" + success
+ + " - " + ColumnName + " - From=" + from_ID + ",To=" + to_ID);
+ if (success)
+ {
+ sql = "DELETE " + TableName + " WHERE " + ColumnName + "=" + from_ID;
+
+
+
+
+ if ( DB.executeUpdate(sql, m_trx.getTrxName()) < 0 )
+ {
+ m_errorLog.append(Env.NL).append("DELETE ").append(TableName)
+ .append(" - ");
+ success = false;
+ log.config(m_errorLog.toString());
+ m_trx.rollback();
+ return false;
+ }
+
+ }
+ //
+ if (success)
+ m_trx.commit();
+ else
+ m_trx.rollback();
+
+ m_trx.close();
+
+ }
+ catch (Exception ex)
+ {
+ log.log(Level.SEVERE, ColumnName, ex);
+ }
+ // Cleanup
+ try
+ {
+ if (pstmt != null)
+ pstmt.close();
+
+ }
+ catch (Exception ex)
+ {
+ }
+ pstmt = null;
+ return success;
+ } // merge
+
+
+ /**
+ * Merge Table
+ * @param TableName table
+ * @param ColumnName column
+ * @param from_ID from
+ * @param to_ID to
+ * @return -1 for error or number of changes
+ */
+ private int mergeTable (String TableName, String ColumnName, int from_ID, int to_ID)
+ {
+ log.fine(TableName + "." + ColumnName + " - From=" + from_ID + ",To=" + to_ID);
+ String sql = "UPDATE " + TableName
+ + " SET " + ColumnName + "=" + to_ID
+ + " WHERE " + ColumnName + "=" + from_ID;
+ boolean delete = false;
+ for (int i = 0; i < m_deleteTables.length; i++)
+ {
+ if (m_deleteTables[i].equals(TableName))
+ {
+ delete = true;
+ sql = "DELETE " + TableName + " WHERE " + ColumnName + "=" + from_ID;
+ }
+ }
+ // Delete newly created MCost records - teo_sarca [ 1704554 ]
+ if (delete && X_M_Cost.Table_Name.equals(TableName) && M_PRODUCT_ID.equals(ColumnName))
+ {
+ sql += " AND " + X_M_Cost.COLUMNNAME_CurrentCostPrice + "=0"
+ + " AND " + X_M_Cost.COLUMNNAME_CurrentQty + "=0"
+ + " AND " + X_M_Cost.COLUMNNAME_CumulatedAmt + "=0"
+ + " AND " + X_M_Cost.COLUMNNAME_CumulatedQty + "=0";
+ }
+
+ int count = DB.executeUpdate(sql, m_trx.getTrxName());
+
+
+ if ( count < 0 )
+ {
+
+ count = -1;
+ m_errorLog.append(Env.NL)
+ .append(delete ? "DELETE " : "UPDATE ")
+ .append(TableName).append(" - ")
+ .append(" - ").append(sql);
+ log.config(m_errorLog.toString());
+ m_trx.rollback();
+
+ }
+ log.fine(count
+ + (delete ? " -Delete- " : " -Update- ") + TableName);
+
+
+ return count;
+ } // mergeTable
+
+ /**
+ * Post Merge
+ * @param ColumnName column name
+ * @param to_ID ID
+ */
+ private void postMerge (String ColumnName, int to_ID)
+ {
+ if (ColumnName.equals(AD_ORG_ID))
+ {
+
+ }
+ else if (ColumnName.equals(AD_USER_ID))
+ {
+
+ }
+ else if (ColumnName.equals(C_BPARTNER_ID))
+ {
+ MBPartner bp = new MBPartner (Env.getCtx(), to_ID, null);
+ if (bp.get_ID() != 0)
+ {
+ MPayment[] payments = MPayment.getOfBPartner(Env.getCtx(), bp.getC_BPartner_ID(), null);
+ for (int i = 0; i < payments.length; i++)
+ {
+ MPayment payment = payments[i];
+ if (payment.testAllocation())
+ payment.save();
+ }
+ MInvoice[] invoices = MInvoice.getOfBPartner(Env.getCtx(), bp.getC_BPartner_ID(), null);
+ for (int i = 0; i < invoices.length; i++)
+ {
+ MInvoice invoice = invoices[i];
+ if (invoice.testAllocation())
+ invoice.save();
+ }
+ bp.setTotalOpenBalance();
+ bp.setActualLifeTimeValue();
+ bp.save();
+ }
+ }
+ else if (ColumnName.equals(M_PRODUCT_ID))
+ {
+
+ }
+ } // postMerge
+
+
+} // VMerge
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WTrxMaterial.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WTrxMaterial.java
index 395df6da42..328a85189f 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WTrxMaterial.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WTrxMaterial.java
@@ -1,623 +1,395 @@
-/******************************************************************************
- * Product: Adempiere ERP & CRM Smart Business Solution *
- * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
- * 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. *
- * 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 *
- *****************************************************************************/
-
-/**
- * 2007, Modified by Posterita Ltd.
- */
-
-package org.adempiere.webui.apps.form;
-
-import java.math.BigDecimal;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Timestamp;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Properties;
-import java.util.logging.Level;
-
-import javax.swing.table.AbstractTableModel;
-
-import org.adempiere.webui.apps.AEnv;
-import org.adempiere.webui.component.Column;
-import org.adempiere.webui.component.Columns;
-import org.adempiere.webui.component.ConfirmPanel;
-import org.adempiere.webui.component.Datebox;
-import org.adempiere.webui.component.Grid;
-import org.adempiere.webui.component.Label;
-import org.adempiere.webui.component.Panel;
-import org.adempiere.webui.component.Row;
-import org.adempiere.webui.component.Rows;
-import org.adempiere.webui.component.VerticalBox;
-import org.adempiere.webui.component.WStatusBar;
-import org.adempiere.webui.editor.WEditor;
-import org.adempiere.webui.editor.WLocatorEditor;
-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.compiere.model.GridField;
-import org.compiere.model.GridTab;
-import org.compiere.model.GridTable;
-import org.compiere.model.GridWindow;
-import org.compiere.model.GridWindowVO;
-import org.compiere.model.MLocatorLookup;
-import org.compiere.model.MLookup;
-import org.compiere.model.MLookupFactory;
-import org.compiere.model.MQuery;
-import org.compiere.util.CLogger;
-import org.compiere.util.DB;
-import org.compiere.util.DisplayType;
-import org.compiere.util.Env;
-import org.compiere.util.Msg;
-import org.compiere.util.NamePair;
-import org.zkoss.zk.ui.event.Event;
-import org.zkoss.zk.ui.event.EventListener;
-import org.zkoss.zk.ui.event.Events;
-import org.zkoss.zul.Hbox;
-import org.zkoss.zul.Separator;
-
-public class WTrxMaterial extends ADForm implements EventListener, ValueChangeListener
-{
- private static final long serialVersionUID = 1L;
-
- /** FormFrame */
- //private FormFrame m_frame;
-
- /** GridController */
- private Grid m_gridController = new Grid();
- private Columns columns = new Columns();
- private Rows rows = new Rows();
-
- /** MWindow */
- private GridWindow m_mWindow = null;
-
- /** MTab pointer */
- private GridTab m_mTab = null;
-
- private MQuery m_staticQuery = null;
-
- /** Logger */
- private static CLogger log = CLogger.getCLogger(WTrxMaterial.class);
-
- private VerticalBox mainPanel = new VerticalBox();
- private Hbox parameterPanel = new Hbox();
- private Label orgLabel = new Label();
- private WEditor orgField;
- private Label locatorLabel = new Label();
- private WLocatorEditor locatorField;
- private Label productLabel = new Label();
- private WEditor productField;
- private Label dateFLabel = new Label();
- private Datebox dateFField;
- private Label dateTLabel = new Label();
- private Datebox dateTField;
- private Label mtypeLabel = new Label();
- private WEditor mtypeField;
- private Panel southPanel = new Panel();
- private ConfirmPanel confirmPanel = new ConfirmPanel(true, true, false, false, false, true);
- private WStatusBar statusBar = new WStatusBar();
-
- public WTrxMaterial()
- {
- }
-
- /**
- * Initialize Panel
- * @param WindowNo window
- * @param frame frame
- */
-
- protected void initForm()
- {
- log.info("");
-
- try
- {
- dynParameter();
- jbInit();
- dynInit();
-
- this.appendChild(mainPanel);
- this.appendChild(statusBar);
- }
- catch(Exception ex)
- {
- log.log(Level.SEVERE, "", ex);
- }
- } // init
-
- /**
- * Static Init
- * @throws Exception
- */
-
- void jbInit() throws Exception
- {
- orgLabel.setValue(Msg.translate(Env.getCtx(), "AD_Org_ID"));
- locatorLabel.setValue(Msg.translate(Env.getCtx(), "M_Locator_ID"));
- productLabel.setValue(Msg.translate(Env.getCtx(), "Product"));
- dateFLabel.setValue(Msg.translate(Env.getCtx(), "DateFrom"));
- dateTLabel.setValue(Msg.translate(Env.getCtx(), "DateTo"));
- mtypeLabel.setValue(Msg.translate(Env.getCtx(), "MovementType"));
-
- m_gridController.setWidth("900px");
- m_gridController.setHeight("550px");
-
- mainPanel.setWidth("100%");
- mainPanel.appendChild(new Separator());
- mainPanel.appendChild(parameterPanel);
- mainPanel.appendChild(new Separator());
- mainPanel.appendChild(m_gridController);
- mainPanel.appendChild(new Separator());
-
- Hbox boxOrg = new Hbox();
- boxOrg.setWidth("100%");
- boxOrg.setWidth("35%, 75%");
- boxOrg.appendChild(orgLabel);
- boxOrg.appendChild(orgField.getComponent());
-
- Hbox boxMType = new Hbox();
- boxMType.setWidth("100%");
- boxMType.setWidth("35%, 75%");
- boxMType.appendChild(mtypeLabel);
- boxMType.appendChild(mtypeField.getComponent());
-
- Hbox boxDateF = new Hbox();
- boxDateF.setWidth("100%");
- boxDateF.setWidth("35%, 75%");
- boxDateF.appendChild(dateFLabel);
- boxDateF.appendChild(dateFField);
-
- Hbox boxLocator = new Hbox();
- boxLocator.setWidth("100%");
- boxLocator.setWidth("35%, 75%");
- boxLocator.appendChild(locatorLabel);
- boxLocator.appendChild(locatorField.getComponent());
-
- Hbox boxProduct = new Hbox();
- boxProduct.setWidth("100%");
- boxProduct.setWidth("35%, 75%");
- boxProduct.appendChild(productLabel);
- boxProduct.appendChild(productField.getComponent());
-
- Hbox boxDateT = new Hbox();
- boxDateT.setWidth("100%");
- boxDateT.setWidth("35%, 75%");
- boxDateT.appendChild(dateTLabel);
- boxDateT.appendChild(dateTField);
-
- VerticalBox boxCol1 = new VerticalBox();
- boxCol1.setWidth("100%");
- boxCol1.appendChild(boxOrg);
- boxCol1.appendChild(boxLocator);
-
- VerticalBox boxCol2 = new VerticalBox();
- boxCol2.setWidth("100%");
- boxCol2.appendChild(boxMType);
- boxCol2.appendChild(boxProduct);
-
- VerticalBox boxCol3 = new VerticalBox();
- boxCol3.setWidth("100%");
- boxCol3.appendChild(boxDateF);
- boxCol3.appendChild(boxDateT);
-
- parameterPanel.setWidth("100%");
- parameterPanel.setStyle("text-align:right");
- parameterPanel.appendChild(boxCol1);
- parameterPanel.appendChild(new Separator());
- parameterPanel.appendChild(boxCol2);
- parameterPanel.appendChild(new Separator());
- parameterPanel.appendChild(boxCol3);
-
- southPanel.appendChild(confirmPanel);
- southPanel.appendChild(new Separator());
- southPanel.appendChild(statusBar);
-
- mainPanel.appendChild(southPanel);
-
- this.setWidth("100%");
- this.appendChild(mainPanel);
- }
-
- /**
- * Initialize Parameter fields
- * @throws Exception if Lookups cannot be initialized
- */
-
- private void dynParameter() throws Exception
- {
- Properties ctx = Env.getCtx();
- // Organization
-
- MLookup orgLookup = MLookupFactory.get (ctx, m_WindowNo, 0, 3660, DisplayType.TableDir);
- orgField = new WTableDirEditor(orgLookup, "AD_Org_ID", "", false, false, true);
- orgField.addValueChangeListener(this);
-
- // Locator
- MLocatorLookup locatorLookup = new MLocatorLookup(ctx, m_WindowNo);
- locatorField = new WLocatorEditor ("M_Locator_ID", false, false, true, locatorLookup, m_WindowNo);
- locatorField.addValueChangeListener(this);
-
- // Product
- MLookup productLookup = MLookupFactory.get (ctx, m_WindowNo, 0, 3668, DisplayType.Search);
- productField = new WSearchEditor(productLookup, "M_Product_ID", "", false, false, true);
- productField.addValueChangeListener(this);
-
- // Movement Type
- MLookup mtypeLookup = MLookupFactory.get (ctx, m_WindowNo, 0, 3666, DisplayType.List);
- mtypeField = new WTableDirEditor(mtypeLookup, "MovementType", "", false, false, true);
- mtypeField.addValueChangeListener(this);
-
- // Dates
- dateFField = new Datebox();//"DateFrom", false, false, true, DisplayType.Date, Msg.getMsg(Env.getCtx(), "DateFrom"));
- dateTField = new Datebox();//"DateTo", false, false, true, DisplayType.Date, Msg.getMsg(Env.getCtx(), "DateTo"));
-
- confirmPanel.addActionListener(Events.ON_CLICK, this);
- statusBar.setStatusLine("");
- } // dynParameter
-
- /**
- * Dynamic Layout (Grid).
- * Based on AD_Window: Material Transactions
- */
- private void dynInit()
- {
- m_staticQuery = new MQuery();
- m_staticQuery.addRestriction("AD_Client_ID", MQuery.EQUAL, Env.getAD_Client_ID(Env.getCtx()));
- int AD_Window_ID = 223; // Hardcoded
- GridWindowVO wVO = AEnv.getMWindowVO (m_WindowNo, AD_Window_ID, 0);
-
- if (wVO == null)
- return;
-
- m_mWindow = new GridWindow (wVO);
- m_mTab = m_mWindow.getTab(0);
- m_mWindow.initTab(0);
-
- populateGrid();
-
- //m_gridController.initGrid(m_mTab, true, m_WindowNo, null, null);
- //mainPanel.add(m_gridController, BorderLayout.CENTER);
-
- m_mTab.setQuery(MQuery.getEqualQuery("1", "2"));
- m_mTab.query(false);
- statusBar.setStatusLine(" ", false);
- statusBar.setStatusDB(" ");
- } // dynInit
-
- private void populateGrid()
- {
- m_gridController.getChildren().clear();
- m_gridController.appendChild(columns);
- m_gridController.appendChild(rows);
-
- columns.getChildren().clear();
-
- Column column = new Column();
-
- AbstractTableModel tableModel = m_mTab.getTableModel();
- GridField[] gridfields = ((GridTable)tableModel).getFields();
-
- for (int i = 0; i < gridfields.length; i++)
- {
- if (gridfields[i].isDisplayed())
- {
- column = new Column(gridfields[i].getHeader());
- columns.appendChild(column);
- }
- }
-
- rows.getChildren().clear();
-
- for (int i = 0; i < tableModel.getRowCount(); i++)
- {
- Row row = new Row();
-
- for (int j = 0; j < tableModel.getColumnCount(); j++)
- {
- Label lab = new Label();
-
- Label label = new Label("");
-
- if (!gridfields[j].isDisplayed())
- break;
-
- Object obj = tableModel.getValueAt(i, j);
-
- if (obj != null)
- {
- if (tableModel.getColumnClass(j).equals(String.class))
- {
- label.setValue(obj.toString());
- }
- else if (tableModel.getColumnClass(j).equals(BigDecimal.class))
- {
- label.setValue(obj.toString());
- }
- else if (tableModel.getColumnClass(j).equals(Integer.class))
- {
- if (gridfields[j].isLookup())
- {
- MLookup lookup = MLookupFactory.get(Env.getCtx(), m_WindowNo,
- 0, gridfields[j].getAD_Column_ID(), gridfields[j].getDisplayType());
-
- NamePair namepair = lookup.get(obj);
-
- if (namepair != null)
- label.setValue(namepair.getName());
- else
- label.setValue("");
- }
- }
- else if (tableModel.getColumnClass(j).equals(Timestamp.class))
- {
- SimpleDateFormat dateFormat = DisplayType.getDateFormat(DisplayType.Date);
- label.setValue(dateFormat.format((Timestamp)obj));
- }
- else
- label.setValue("Missing Class");
- }
-
- lab = new Label(label.getValue());
- row.appendChild(lab);
- }
- rows.appendChild(row);
- }
- }
-
- /**
- * Dispose
- */
- public void dispose()
- {
- /*if (m_gridController != null)
- m_gridController.dispose();
- */
- m_gridController = null;
- m_mTab = null;
-
- if (m_mWindow != null)
- m_mWindow.dispose();
-
- m_mWindow = null;
-
- orgField = null;
- locatorField = null;
- productField = null;
- mtypeField = null;
- dateFField = null;
- dateTField = null;
- } // dispose
-
-
- /**************************************************************************
- * Action Listener
- * @param e event
- */
-
- public void onEvent(Event event) throws Exception
- {
- if (confirmPanel.getButton("Cancel").equals(event.getTarget()))
- dispose();
- else if (confirmPanel.getButton("Refresh").equals(event.getTarget())
- || confirmPanel.getButton("Ok").equals(event.getTarget()))
- refresh();
- else if (confirmPanel.getButton("Zoom").equals(event.getTarget()))
- zoom();
-
- }
-
- /**************************************************************************
- * Property Listener
- * @param e event
- */
-
- public void valueChange(ValueChangeEvent evt)
- {
- if (evt.getPropertyName().equals("M_Product_ID"))
- productField.setValue(evt.getNewValue());
- }
-
- /**************************************************************************
- * Refresh - Create Query and refresh grid
- */
-
- private void refresh()
- {
- /**
- * Create Where Clause
- */
-
- MQuery query = m_staticQuery.deepCopy();
-
- // Organization
- Object value = null;
- if (orgField.getDisplay() != "")
- value = orgField.getValue();
- if (value != null && value.toString().length() > 0)
- query.addRestriction("AD_Org_ID", MQuery.EQUAL, value);
-
- // Locator
- value = null;
- if (locatorField.getDisplay() != "")
- value = locatorField.getValue();
- if (value != null && value.toString().length() > 0)
- query.addRestriction("M_Locator_ID", MQuery.EQUAL, value);
-
- // Product
- value = null;
- if (productField.getDisplay() != "")
- value = productField.getValue();
- if (value != null && value.toString().length() > 0)
- query.addRestriction("M_Product_ID", MQuery.EQUAL, value);
-
- // MovementType
- value = null;
- if (mtypeField.getDisplay() != "")
- value = mtypeField.getValue();
- if (value != null && value.toString().length() > 0)
- query.addRestriction("MovementType", MQuery.EQUAL, value);
-
- // DateFrom
- Date f = null;
- Timestamp ts =null;
-
- if (dateFField.getValue() != null)
- {
- f = dateFField.getValue();
- ts = new Timestamp(f.getTime());
- }
-
- if (ts != null)
- query.addRestriction("TRUNC(MovementDate)", MQuery.GREATER_EQUAL, ts);
-
- // DateTO
- Date t = null;
- ts = null;
-
- if (dateTField.getValue() != null)
- {
- t = dateTField.getValue();
- ts = new Timestamp(t.getTime());
- }
-
- if (ts != null)
- query.addRestriction("TRUNC(MovementDate)", MQuery.LESS_EQUAL, ts);
- log.info( "VTrxMaterial.refresh query=" + query.toString());
-
- /**
- * Refresh/Requery
- */
-
- statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "StartSearch"), false);
-
- m_mTab.setQuery(query);
- m_mTab.query(false);
-
- int no = m_mTab.getRowCount();
- statusBar.setStatusLine(" ", false);
- statusBar.setStatusDB(Integer.toString(no));
-
- populateGrid();
- } // refresh
-
- /**
- * Zoom
- */
-
- private void zoom()
- {
- log.info("");
-
- int AD_Window_ID = 0;
- String ColumnName = null;
- String SQL = null;
-
- int lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_InOutLine_ID");
-
- if (lineID != 0)
- {
- log.fine("M_InOutLine_ID=" + lineID);
-
- if (Env.getContext(Env.getCtx(), m_WindowNo, "MovementType").startsWith("C"))
- AD_Window_ID = 169; // Customer
- else
- AD_Window_ID = 184; // Vendor
- ColumnName = "M_InOut_ID";
- SQL = "SELECT M_InOut_ID FROM M_InOutLine WHERE M_InOutLine_ID=?";
- }
- else
- {
- lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_InventoryLine_ID");
-
- if (lineID != 0)
- {
- log.fine("M_InventoryLine_ID=" + lineID);
- AD_Window_ID = 168;
- ColumnName = "M_Inventory_ID";
- SQL = "SELECT M_Inventory_ID FROM M_InventoryLine WHERE M_InventoryLine_ID=?";
- }
- else
- {
- lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_MovementLine_ID");
-
- if (lineID != 0)
- {
- log.fine("M_MovementLine_ID=" + lineID);
- AD_Window_ID = 170;
- ColumnName = "M_Movement_ID";
- SQL = "SELECT M_Movement_ID FROM M_MovementLine WHERE M_MovementLine_ID=?";
- }
- else
- {
- lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_ProductionLine_ID");
-
- if (lineID != 0)
- {
- log.fine("M_ProductionLine_ID=" + lineID);
- AD_Window_ID = 191;
- ColumnName = "M_Production_ID";
- SQL = "SELECT M_Production_ID FROM M_ProductionLine WHERE M_ProductionLine_ID=?";
- }
- else
- log.fine("Not found WindowNo=" + m_WindowNo);
- }
- }
- }
-
- if (AD_Window_ID == 0)
- return;
-
- // Get Parent ID
- int parentID = 0;
-
- try
- {
- PreparedStatement pstmt = DB.prepareStatement(SQL, null);
- pstmt.setInt(1, lineID);
- ResultSet rs = pstmt.executeQuery();
-
- if (rs.next())
- parentID = rs.getInt(1);
- rs.close();
- pstmt.close();
- }
- catch (SQLException e)
- {
- log.log(Level.SEVERE, SQL, e);
- }
-
- MQuery query = MQuery.getEqualQuery(ColumnName, parentID);
- log.config("AD_Window_ID=" + AD_Window_ID + " - " + query);
-
- if (parentID == 0)
- log.log(Level.SEVERE, "No ParentValue - " + SQL + " - " + lineID);
-
- // Zoom
- AEnv.zoom(AD_Window_ID, query);
-/* ADWindow frame = new ADWindow(Env.getCtx(), AD_Window_ID);
-
- if (frame == null)
- return;
-
- SessionManager.getAppDesktop().showWindow(frame);
- frame = null;
-*/ } // zoom
-}
+/******************************************************************************
+ * Product: Adempiere ERP & CRM Smart Business Solution *
+ * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
+ * 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. *
+ * 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.sql.*;
+import java.util.*;
+import java.util.logging.*;
+
+import org.adempiere.webui.LayoutUtils;
+import org.adempiere.webui.apps.AEnv;
+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.Panel;
+import org.adempiere.webui.component.Row;
+import org.adempiere.webui.component.Rows;
+import org.adempiere.webui.editor.WDateEditor;
+import org.adempiere.webui.editor.WLocatorEditor;
+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.ADTabpanel;
+import org.adempiere.webui.panel.StatusBarPanel;
+import org.adempiere.webui.session.SessionManager;
+import org.compiere.model.*;
+import org.compiere.util.*;
+import org.zkoss.zk.ui.event.Event;
+import org.zkoss.zk.ui.event.EventListener;
+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.Separator;
+
+/**
+ * Material Transaction History
+ *
+ * @author Jorg Janke
+ * @version $Id: VTrxMaterial.java,v 1.3 2006/07/30 00:51:28 jjanke Exp $
+ */
+public class WTrxMaterial extends ADForm
+ implements EventListener, ValueChangeListener
+{
+
+ /** GridController */
+ private ADTabpanel m_gridController = null;
+ /** MWindow */
+ private GridWindow m_mWindow = null;
+ /** MTab pointer */
+ private GridTab m_mTab = null;
+
+ private MQuery m_staticQuery = null;
+ /** Logger */
+ private static CLogger log = CLogger.getCLogger(WTrxMaterial.class);
+ //
+ private Panel mainPanel = new Panel();
+ private Borderlayout mainLayout = new Borderlayout();
+ private Panel parameterPanel = new Panel();
+ private Label orgLabel = new Label();
+ private WTableDirEditor orgField;
+ private Label locatorLabel = new Label();
+ private WLocatorEditor locatorField;
+ private Label productLabel = new Label();
+ private WSearchEditor productField;
+ private Label dateFLabel = new Label();
+ private WDateEditor dateFField;
+ private Label dateTLabel = new Label();
+ private WDateEditor dateTField;
+ private Label mtypeLabel = new Label();
+ private WTableDirEditor mtypeField;
+ private Grid parameterLayout = GridFactory.newGridLayout();
+ private Panel southPanel = new Panel();
+ private ConfirmPanel confirmPanel = new ConfirmPanel(true, true, false, false, false, true, false);
+ private StatusBarPanel statusBar = new StatusBarPanel();
+
+
+ /**
+ * Initialize Panel
+ */
+ protected void initForm()
+ {
+ log.info("");
+ try
+ {
+ dynParameter();
+ zkInit();
+ dynInit();
+ }
+ catch(Exception ex)
+ {
+ log.log(Level.SEVERE, "", ex);
+ }
+ } // init
+
+ /**
+ * Static Init
+ * @throws Exception
+ */
+ void zkInit() throws Exception
+ {
+ this.appendChild(mainPanel);
+ mainPanel.setStyle("width: 99%; height: 100%; border: none; padding: 0; margin: 0");
+ mainPanel.appendChild(mainLayout);
+ mainLayout.setWidth("100%");
+ mainLayout.setHeight("100%");
+ parameterPanel.appendChild(parameterLayout);
+ //
+ orgLabel.setText(Msg.translate(Env.getCtx(), "AD_Org_ID"));
+ locatorLabel.setText(Msg.translate(Env.getCtx(), "M_Locator_ID"));
+ productLabel.setText(Msg.translate(Env.getCtx(), "Product"));
+ dateFLabel.setText(Msg.translate(Env.getCtx(), "DateFrom"));
+ dateTLabel.setText(Msg.translate(Env.getCtx(), "DateTo"));
+ mtypeLabel.setText(Msg.translate(Env.getCtx(), "MovementType"));
+ //
+ North north = new North();
+ mainLayout.appendChild(north);
+ north.appendChild(parameterPanel);
+
+ Rows rows = parameterLayout.newRows();
+ Row row = rows.newRow();
+ row.appendChild(orgLabel.rightAlign());
+ row.appendChild(orgField.getComponent());
+ row.appendChild(mtypeLabel.rightAlign());
+ row.appendChild(mtypeField.getComponent());
+ row.appendChild(dateFLabel.rightAlign());
+ row.appendChild(dateFField.getComponent());
+
+ row = rows.newRow();
+ row.appendChild(locatorLabel.rightAlign());
+ row.appendChild(locatorField.getComponent());
+ row.appendChild(productLabel.rightAlign());
+ row.appendChild(productField.getComponent());
+ row.appendChild(dateTLabel.rightAlign());
+ row.appendChild(dateTField.getComponent());
+ //
+ southPanel.appendChild(confirmPanel);
+ southPanel.appendChild(new Separator());
+ southPanel.appendChild(statusBar);
+ South south = new South();
+ south.setStyle("border: none");
+ mainLayout.appendChild(south);
+ south.appendChild(southPanel);
+
+ LayoutUtils.addSclass("status-border", statusBar);
+ } // jbInit
+
+ /**
+ * Initialize Parameter fields
+ * @throws Exception if Lookups cannot be initialized
+ */
+ private void dynParameter() throws Exception
+ {
+ Properties ctx = Env.getCtx();
+ // Organization
+ MLookup orgLookup = MLookupFactory.get (ctx, m_WindowNo, 0, 3660, DisplayType.TableDir);
+ orgField = new WTableDirEditor("AD_Org_ID", false, false, true, orgLookup);
+ // orgField.addVetoableChangeListener(this);
+ // Locator
+ MLocatorLookup locatorLookup = new MLocatorLookup(ctx, m_WindowNo);
+ locatorField = new WLocatorEditor ("M_Locator_ID", false, false, true, locatorLookup, m_WindowNo);
+ // locatorField.addVetoableChangeListener(this);
+ // Product
+ MLookup productLookup = MLookupFactory.get (ctx, m_WindowNo, 0, 3668, DisplayType.Search);
+ productField = new WSearchEditor("M_Product_ID", false, false, true, productLookup);
+ productField.addValueChangeListener(this);
+ // Movement Type
+ MLookup mtypeLookup = MLookupFactory.get (ctx, m_WindowNo, 0, 3666, DisplayType.List);
+ mtypeField = new WTableDirEditor("MovementType", false, false, true, mtypeLookup);
+ // Dates
+ dateFField = new WDateEditor("DateFrom", false, false, true, DisplayType.Date, Msg.getMsg(Env.getCtx(), "DateFrom"));
+ dateTField = new WDateEditor("DateTo", false, false, true, DisplayType.Date, Msg.getMsg(Env.getCtx(), "DateTo"));
+ //
+ confirmPanel.addActionListener(this);
+ statusBar.setStatusLine("");
+ } // dynParameter
+
+ /**
+ * Dynamic Layout (Grid).
+ * Based on AD_Window: Material Transactions
+ */
+ private void dynInit()
+ {
+ m_staticQuery = new MQuery();
+ m_staticQuery.addRestriction("AD_Client_ID", MQuery.EQUAL, Env.getAD_Client_ID(Env.getCtx()));
+ int AD_Window_ID = 223; // Hardcoded
+ GridWindowVO wVO = AEnv.getMWindowVO (m_WindowNo, AD_Window_ID, 0);
+ if (wVO == null)
+ return;
+ m_mWindow = new GridWindow (wVO);
+ m_mTab = m_mWindow.getTab(0);
+ m_mWindow.initTab(0);
+ //
+ m_gridController = new ADTabpanel();
+ m_gridController.init(null, m_WindowNo, m_mTab, m_mWindow);
+ m_gridController.switchRowPresentation();
+ Center center = new Center();
+ mainLayout.appendChild(center);
+ center.setFlex(true);
+ center.appendChild(m_gridController);
+ //
+ m_mTab.setQuery(MQuery.getEqualQuery("1", "2"));
+ m_mTab.query(false);
+ statusBar.setStatusLine(" ", false);
+ statusBar.setStatusDB(" ");
+ } // dynInit
+
+
+ /**
+ * Dispose
+ */
+ public void dispose()
+ {
+ SessionManager.getAppDesktop().removeWindow();
+ } // dispose
+
+
+ /**************************************************************************
+ * Action Listener
+ * @param e event
+ */
+ public void onEvent (Event e)
+ {
+ if (e.getTarget().getId().equals(ConfirmPanel.A_CANCEL))
+ dispose();
+ else if (e.getTarget().getId().equals(ConfirmPanel.A_REFRESH)
+ || e.getTarget().getId().equals(ConfirmPanel.A_OK))
+ refresh();
+ else if (e.getTarget().getId().equals(ConfirmPanel.A_ZOOM))
+ zoom();
+ } // actionPerformed
+
+
+ /**************************************************************************
+ * Property Listener
+ * @param e event
+ */
+ public void valueChange (ValueChangeEvent e)
+ {
+ if (e.getPropertyName().equals("M_Product_ID"))
+ productField.setValue(e.getNewValue());
+ } // vetoableChange
+
+
+
+ /**************************************************************************
+ * Refresh - Create Query and refresh grid
+ */
+ private void refresh()
+ {
+ /**
+ * Create Where Clause
+ */
+ MQuery query = m_staticQuery.deepCopy();
+ // Organization
+ Object value = orgField.getValue();
+ if (value != null && value.toString().length() > 0)
+ query.addRestriction("AD_Org_ID", MQuery.EQUAL, value);
+ // Locator
+ value = locatorField.getValue();
+ if (value != null && value.toString().length() > 0)
+ query.addRestriction("M_Locator_ID", MQuery.EQUAL, value);
+ // Product
+ value = productField.getValue();
+ if (value != null && value.toString().length() > 0)
+ query.addRestriction("M_Product_ID", MQuery.EQUAL, value);
+ // MovementType
+ value = mtypeField.getValue();
+ if (value != null && value.toString().length() > 0)
+ query.addRestriction("MovementType", MQuery.EQUAL, value);
+ // DateFrom
+ Timestamp ts = (Timestamp)dateFField.getValue();
+ if (ts != null)
+ query.addRestriction("TRUNC(MovementDate)", MQuery.GREATER_EQUAL, ts);
+ // DateTO
+ ts = (Timestamp)dateTField.getValue();
+ if (ts != null)
+ query.addRestriction("TRUNC(MovementDate)", MQuery.LESS_EQUAL, ts);
+ log.info( "VTrxMaterial.refresh query=" + query.toString());
+
+ /**
+ * Refresh/Requery
+ */
+ statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "StartSearch"), false);
+ //
+ m_mTab.setQuery(query);
+ m_mTab.query(false);
+ //
+ int no = m_mTab.getRowCount();
+ statusBar.setStatusLine(" ", false);
+ statusBar.setStatusDB(Integer.toString(no));
+ } // refresh
+
+ /**
+ * Zoom
+ */
+ private void zoom()
+ {
+ log.info("");
+ //
+ int AD_Window_ID = 0;
+ String ColumnName = null;
+ String SQL = null;
+ //
+ int lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_InOutLine_ID");
+ if (lineID != 0)
+ {
+ log.fine("M_InOutLine_ID=" + lineID);
+ if (Env.getContext(Env.getCtx(), m_WindowNo, "MovementType").startsWith("C"))
+ AD_Window_ID = 169; // Customer
+ else
+ AD_Window_ID = 184; // Vendor
+ ColumnName = "M_InOut_ID";
+ SQL = "SELECT M_InOut_ID FROM M_InOutLine WHERE M_InOutLine_ID=?";
+ }
+ else
+ {
+ lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_InventoryLine_ID");
+ if (lineID != 0)
+ {
+ log.fine("M_InventoryLine_ID=" + lineID);
+ AD_Window_ID = 168;
+ ColumnName = "M_Inventory_ID";
+ SQL = "SELECT M_Inventory_ID FROM M_InventoryLine WHERE M_InventoryLine_ID=?";
+ }
+ else
+ {
+ lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_MovementLine_ID");
+ if (lineID != 0)
+ {
+ log.fine("M_MovementLine_ID=" + lineID);
+ AD_Window_ID = 170;
+ ColumnName = "M_Movement_ID";
+ SQL = "SELECT M_Movement_ID FROM M_MovementLine WHERE M_MovementLine_ID=?";
+ }
+ else
+ {
+ lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_ProductionLine_ID");
+ if (lineID != 0)
+ {
+ log.fine("M_ProductionLine_ID=" + lineID);
+ AD_Window_ID = 191;
+ ColumnName = "M_Production_ID";
+ SQL = "SELECT M_Production_ID FROM M_ProductionLine WHERE M_ProductionLine_ID=?";
+ }
+ else
+ log.fine("Not found WindowNo=" + m_WindowNo);
+ }
+ }
+ }
+ if (AD_Window_ID == 0)
+ return;
+
+ // Get Parent ID
+ int parentID = 0;
+ try
+ {
+ PreparedStatement pstmt = DB.prepareStatement(SQL, null);
+ pstmt.setInt(1, lineID);
+ ResultSet rs = pstmt.executeQuery();
+ if (rs.next())
+ parentID = rs.getInt(1);
+ rs.close();
+ pstmt.close();
+ }
+ catch (SQLException e)
+ {
+ log.log(Level.SEVERE, SQL, e);
+ }
+ MQuery query = MQuery.getEqualQuery(ColumnName, parentID);
+ log.config("AD_Window_ID=" + AD_Window_ID + " - " + query);
+ if (parentID == 0)
+ log.log(Level.SEVERE, "No ParentValue - " + SQL + " - " + lineID);
+
+ // Zoom
+ AEnv.zoom(AD_Window_ID, query);
+ } // zoom
+
+} // VTrxMaterial
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/wf/WWFActivity.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/wf/WWFActivity.java
index 975637e635..e542adfeac 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/wf/WWFActivity.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/wf/WWFActivity.java
@@ -14,10 +14,10 @@ import org.adempiere.webui.component.Listbox;
import org.adempiere.webui.component.Row;
import org.adempiere.webui.component.Rows;
import org.adempiere.webui.component.Textbox;
-import org.adempiere.webui.component.WStatusBar;
import org.adempiere.webui.component.Window;
import org.adempiere.webui.editor.WSearchEditor;
import org.adempiere.webui.panel.ADForm;
+import org.adempiere.webui.panel.StatusBarPanel;
import org.adempiere.webui.window.FDialog;
import org.compiere.model.MColumn;
import org.compiere.model.MLookup;
@@ -89,7 +89,7 @@ public class WWFActivity extends ADForm implements EventListener
private WSearchEditor fForward = null; // dynInit
private Label lForward = new Label(Msg.getMsg(Env.getCtx(), "Forward"));
private Label lOptional = new Label("(" + Msg.translate(Env.getCtx(), "Optional") + ")");
- private WStatusBar statusBar = new WStatusBar();
+ private StatusBarPanel statusBar = new StatusBarPanel();
public WWFActivity()
{
@@ -226,7 +226,6 @@ public class WWFActivity extends ADForm implements EventListener
South south = new South();
south.appendChild(statusBar);
- statusBar.setWidth("100%");
layout.appendChild(south);
south.setStyle("background-color: transparent");
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/ADButtonTabList.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/ADButtonTabList.java
index 6b18d72fb4..20f1584f98 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/ADButtonTabList.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/ADButtonTabList.java
@@ -18,6 +18,7 @@ import java.util.List;
import org.adempiere.webui.component.ADTabListModel.ADTabLabel;
import org.zkoss.zhtml.Button;
import org.zkoss.zhtml.Text;
+import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
@@ -38,10 +39,15 @@ public class ADButtonTabList extends Panel implements IADTabList, EventListener
this.setStyle("margin:0;padding:0");
}
- public void refresh() {
- this.getChildren().clear();
- int i = 0;
- for (ADTabLabel tabLabel : listItems) {
+ public synchronized void refresh() {
+ List childs = getChildren();
+ int childCount = childs.size();
+ for (int c = childCount - 1; c >=0; c--) {
+ removeChild((Component) childs.get(c));
+ }
+ Object[] items = listItems.toArray();
+ for (int i = 0; i < items.length; i++) {
+ ADTabLabel tabLabel = (ADTabLabel) items[i];
Button button = new Button();
Text text = new Text(tabLabel.label);
button.appendChild(text);
@@ -67,7 +73,6 @@ public class ADButtonTabList extends Panel implements IADTabList, EventListener
button.setParent(this);
button.addEventListener(Events.ON_CLICK, this);
- i++;
}
}
@@ -79,7 +84,7 @@ public class ADButtonTabList extends Panel implements IADTabList, EventListener
this.selectedIndex = index;
}
- public void setItems(List listItems) {
+ public synchronized void setItems(List listItems) {
this.listItems = listItems;
refresh();
}
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/CWindowToolbar.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/CWindowToolbar.java
index 2d5c36d982..1e88172233 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/CWindowToolbar.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/CWindowToolbar.java
@@ -441,7 +441,6 @@ public class CWindowToolbar extends FToolbar implements EventListener
public void enableChanges(boolean enabled)
{
this.btnNew.setDisabled(!enabled);
- this.btnIgnore.setDisabled(!enabled);
}
public void enableIgnore(boolean enabled)
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/Combinationbox.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/Combinationbox.java
index ecc1c31311..2013de2003 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/Combinationbox.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/Combinationbox.java
@@ -13,15 +13,15 @@
package org.adempiere.webui.component;
+import org.adempiere.webui.apps.AEnv;
import org.zkoss.zk.ui.event.EventListener;
-import org.zkoss.zul.Hbox;
/**
*
* @author Low Heng Sin
*
*/
-public class Combinationbox extends Hbox
+public class Combinationbox extends Panel
{
private static final long serialVersionUID = 1L;
@@ -49,11 +49,14 @@ public class Combinationbox extends Hbox
private void initComponents()
{
textbox = new Textbox();
- textbox.setWidth("100%");
button = new Button();
- button.setHeight("98%");
+ button.setHeight("22px");
+ button.setWidth("26px");
appendChild(textbox);
appendChild(button);
+
+ String style = AEnv.isFirefox2() ? "display: inline" : "display: inline-block";
+ this.setStyle(style);
}
public void setText(String value)
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/ConfirmPanel.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/ConfirmPanel.java
index 1ae259faf6..22bff1a8b6 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/ConfirmPanel.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/ConfirmPanel.java
@@ -23,6 +23,8 @@ import java.util.List;
import java.util.Map;
import org.adempiere.webui.LayoutUtils;
+import org.compiere.util.Env;
+import org.compiere.util.Msg;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Hbox;
@@ -68,6 +70,8 @@ public final class ConfirmPanel extends Hbox
/** Action String New. */
public static final String A_NEW = "New";
+ private boolean m_withText = false;
+
private Map buttonMap = new HashMap();
/**
@@ -98,15 +102,50 @@ public final class ConfirmPanel extends Hbox
Button button = new Button();
button.setName("btn"+name);
button.setId(name);
- button.setSrc("images/"+name+"24.png");
+ String text = Msg.translate(Env.getCtx(), name);
+ if (!name.equals(text))
+ text = text.replaceAll("[&]", "");
+ else
+ text = null;
- LayoutUtils.addSclass("action-button", button);
+ if (m_withText && text != null)
+ {
+ button.setSrc("images/"+name+"16.png");
+ button.setLabel(text);
+ LayoutUtils.addSclass("action-text-button", button);
+ }
+ else
+ {
+ button.setSrc("images/"+name+"24.png");
+ if (text != null)
+ button.setTooltiptext(text);
+ LayoutUtils.addSclass("action-button", button);
+ }
buttonMap.put(name, button);
return button;
}
+ /**
+ * create confirm panel with multiple options
+ * @param withCancelButton with cancel
+ * @param withRefreshButton with refresh
+ * @param withResetButton with reset
+ * @param withCustomizeButton with customize
+ * @param withHistoryButton with history
+ * @param withZoomButton with zoom
+ */
+ public ConfirmPanel(boolean withCancelButton,
+ boolean withRefreshButton,
+ boolean withResetButton,
+ boolean withCustomizeButton,
+ boolean withHistoryButton,
+ boolean withZoomButton)
+ {
+ this(withCancelButton, withRefreshButton, withResetButton, withCustomizeButton, withHistoryButton, withZoomButton, false);
+ }
+
/**
* create confirm panel with multiple options
* @param withCancelButton with cancel
@@ -121,8 +160,11 @@ public final class ConfirmPanel extends Hbox
boolean withResetButton,
boolean withCustomizeButton,
boolean withHistoryButton,
- boolean withZoomButton)
+ boolean withZoomButton,
+ boolean withText)
{
+ m_withText = withText;
+
init();
setVisible(A_CANCEL, withCancelButton);
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/EditorBox.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/EditorBox.java
index 1809a161cc..9b177e241a 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/EditorBox.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/EditorBox.java
@@ -20,6 +20,7 @@ package org.adempiere.webui.component;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
+import org.adempiere.webui.apps.AEnv;
import org.zkoss.zk.ui.event.EventListener;
/**
@@ -62,6 +63,12 @@ public class EditorBox extends Panel
this.appendChild(txt);
this.appendChild(btn);
+
+ btn.setHeight("22px");
+ btn.setWidth("26px");
+
+ String style = AEnv.isFirefox2() ? "display: inline" : "display: inline-block";
+ this.setStyle(style);
}
public Textbox getTextBox()
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/Label.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/Label.java
index 0a5cca6cf2..fe98c2e261 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/Label.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/Label.java
@@ -60,7 +60,8 @@ public class Label extends org.zkoss.zul.Label
@Override
public void setValue(String value) {
super.setValue(value != null ? value.replaceAll("[&]", "") : null);
- setupMandatoryDecorator();
+ if ((value == null || value.trim().length() == 0) && decorator != null)
+ decorator.setVisible(false);
}
@Override
@@ -75,15 +76,20 @@ public class Label extends org.zkoss.zul.Label
}
private void setupMandatoryDecorator() {
+ if (decorator == null)
+ createMandatoryDecorator();
String value = getValue();
- if (value != null && (value.trim().length() > 0) && mandatory) {
- if (decorator == null)
- decorator = new Label("*");
- ((Label)decorator).setStyle("text-decoration: none; font-size: xx-small; vertical-align: top;");
- } else if (decorator != null)
+ if (mandatory && value != null && value.trim().length() > 0) {
+ decorator.setVisible(true);
+ } else
decorator.setVisible(false);
}
+ private void createMandatoryDecorator() {
+ decorator = new Label("*");
+ ((Label)decorator).setStyle("text-decoration: none; font-size: xx-small; vertical-align: top;");
+ }
+
/**
* alias for setValue, added to ease porting of swing form
* @param translate
diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/ListModelTable.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/ListModelTable.java
index a12b3fee65..95582c129f 100644
--- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/ListModelTable.java
+++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/ListModelTable.java
@@ -257,13 +257,16 @@ public class ListModelTable extends ListModelList implements ListModelExt
if (vector)
{
newRow = new Vector