diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/Desktop.java b/zkwebui/WEB-INF/src/org/adempiere/webui/Desktop.java index ec5cd3623b..81c67d351d 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/Desktop.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/Desktop.java @@ -519,15 +519,9 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl "Notice : " + noOfNotice + ", Request : " + noOfRequest + ", Workflow Activities : " + noOfWorkflow); } - public void showWindowInTabPanel(Window window) - { - Tabpanel tabPanel = new Tabpanel(); - window.setParent(tabPanel); - String title = window.getTitle(); - window.setTitle(null); - windowContainer.addWindow(tabPanel, title, true); - } - + /** + * @param event + */ public void onEvent(Event event) { Component comp = event.getTarget(); @@ -720,50 +714,97 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl if(menu.getAction().equals(MMenu.ACTION_Window)) { - ADWindow adWindow = new ADWindow(Env.getCtx(), menu.getAD_Window_ID()); - - DesktopTabpanel tabPanel = new DesktopTabpanel(); - adWindow.createPart(tabPanel); - windowContainer.addWindow(tabPanel, adWindow.getTitle(), true); + openWindow(menu.getAD_Window_ID()); } else if(menu.getAction().equals(MMenu.ACTION_Process) || menu.getAction().equals(MMenu.ACTION_Report)) { - ProcessDialog pd = new ProcessDialog (menu.getAD_Process_ID(), menu.isSOTrx()); - if (pd.isValid()) { - pd.setPage(page); - pd.setClosable(true); - pd.setWidth("500px"); - pd.doHighlighted(); - } + openProcessDialog(menu.getAD_Process_ID(), menu.isSOTrx()); } else if(menu.getAction().equals(MMenu.ACTION_Form)) { - ADForm form = ADForm.openForm(menu.getAD_Form_ID()); - - DesktopTabpanel tabPanel = new DesktopTabpanel(); - form.setParent(tabPanel); - //do not show window title when open as tab - form.setTitle(null); - windowContainer.addWindow(tabPanel, form.getFormName(), true); + openForm(menu.getAD_Form_ID()); } else { throw new ApplicationException("Menu Action not yet implemented: " + menu.getAction()); } } + + /** + * + * @param processId + * @param soTrx + * @return ProcessDialog + */ + public ProcessDialog openProcessDialog(int processId, boolean soTrx) { + ProcessDialog pd = new ProcessDialog (processId, soTrx); + if (pd.isValid()) { + pd.setPage(page); + pd.setClosable(true); + pd.setWidth("500px"); + pd.doHighlighted(); + } + return pd; + } + + /** + * + * @param formId + * @return ADWindow + */ + public ADForm openForm(int formId) { + ADForm form = ADForm.openForm(formId); + + DesktopTabpanel tabPanel = new DesktopTabpanel(); + form.setParent(tabPanel); + //do not show window title when open as tab + form.setTitle(null); + windowContainer.addWindow(tabPanel, form.getFormName(), true); + + return form; + } + + /** + * + * @param windowId + * @return ADWindow + */ + public ADWindow openWindow(int windowId) { + ADWindow adWindow = new ADWindow(Env.getCtx(), windowId); + + DesktopTabpanel tabPanel = new DesktopTabpanel(); + adWindow.createPart(tabPanel); + windowContainer.addWindow(tabPanel, adWindow.getTitle(), true); + + return adWindow; + } + /** + * @param url + */ public void showURL(String url, boolean closeable) { showURL(url, url, closeable); } + /** + * + * @param url + * @param title + * @param closeable + */ public void showURL(String url, String title, boolean closeable) { Iframe iframe = new Iframe(url); addWin(iframe, title, closeable); } + /** + * @param webDoc + * @param title + * @param closeable + */ public void showURL(WebDoc webDoc, String title, boolean closeable) { Iframe iframe = new Iframe(); @@ -774,6 +815,12 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl addWin(iframe, title, closeable); } + /** + * + * @param fr + * @param title + * @param closeable + */ private void addWin(Iframe fr, String title, boolean closeable) { fr.setWidth("100%"); @@ -791,7 +838,10 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl windowContainer.addWindow(tabPanel, title, closeable); } - + /** + * @param AD_Window_ID + * @param query + */ public void showZoomWindow(int AD_Window_ID, MQuery query) { ADWindow wnd = new ADWindow(Env.getCtx(), AD_Window_ID, query); @@ -801,12 +851,19 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl windowContainer.addWindow(tabPanel, wnd.getTitle(), true); } + /** + * @param win + */ public void showWindow(Window win) { String pos = win.getPosition(); this.showWindow(win, pos); } + /** + * @param win + * @param pos + */ public void showWindow(Window win, String pos) { win.setPage(page); @@ -819,31 +876,33 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl mode = objMode.toString(); } - if ("modal".equals(mode)) + if (Window.MODE_MODAL.equals(mode)) { showModal(win); } - else if ("popup".equals(mode)) + else if (Window.MODE_POPUP.equals(mode)) { showPopup(win, pos); } - else if ("overlapped".equals(mode)) + else if (Window.MODE_OVERLAPPED.equals(mode)) { showOverlapped(win, pos); } - else if ("embedded".equals(mode)) + else if (Window.MODE_EMBEDDED.equals(mode)) { - showEmbedded(win, pos); + showEmbedded(win); } - else if ("highlighted".equals(mode)) + else if (Window.MODE_HIGHLIGHTED.equals(mode)) { showHighlighted(win, pos); - } - -// win.setVisible(true); + } } - public void showModal(Window win) + /** + * + * @param win + */ + private void showModal(Window win) { try { @@ -856,7 +915,12 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl } - public void showPopup(Window win, String position) + /** + * + * @param win + * @param position + */ + private void showPopup(Window win, String position) { if (position == null) win.setPosition("center"); @@ -866,7 +930,12 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl win.doPopup(); } - public void showOverlapped(Window win, String position) + /** + * + * @param win + * @param position + */ + private void showOverlapped(Window win, String position) { if (position == null) win.setPosition("center"); @@ -876,7 +945,12 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl win.doOverlapped(); } - public void showHighlighted(Window win, String position) + /** + * + * @param win + * @param position + */ + private void showHighlighted(Window win, String position) { if (position == null) win.setPosition("center"); @@ -886,36 +960,56 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl win.doHighlighted(); } - public void showEmbedded(Window win, String position) + /** + * + * @param window + */ + private void showEmbedded(Window window) { - if (position == null) - win.setPosition("center"); - else - win.setPosition(position); - - win.doEmbedded(); + Tabpanel tabPanel = new Tabpanel(); + window.setParent(tabPanel); + String title = window.getTitle(); + window.setTitle(null); + windowContainer.addWindow(tabPanel, title, true); } + /** + * @return clientInfo + */ public ClientInfo getClientInfo() { return clientInfo; } + /** + * + * @param clientInfo + */ public void setClientInfo(ClientInfo clientInfo) { this.clientInfo = clientInfo; } + /** + * @param win + */ public int registerWindow(Object win) { int retValue = windows.size(); windows.add(win); return retValue; } + /** + * @param WindowNo + */ public void unregisterWindow(int WindowNo) { if (WindowNo < windows.size()) windows.set(WindowNo, null); } - + /** + * + * @param WindowNo + * @return Object + */ public Object findWindow(int WindowNo) { if (WindowNo < windows.size()) return windows.get(WindowNo); @@ -923,11 +1017,18 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl return null; } + /** + * Close active tab + */ public void removeWindow() { windowContainer.removeWindow(); } + /** + * + * @param page + */ public void setPage(Page page) { if (this.page != page) { layout.setPage(page); @@ -935,6 +1036,10 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl } } + /** + * Get the root component + * @return Component + */ public Component getComponent() { return layout; } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/IDesktop.java b/zkwebui/WEB-INF/src/org/adempiere/webui/IDesktop.java index 826c34614d..fa1fd81293 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/IDesktop.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/IDesktop.java @@ -1,30 +1,98 @@ package org.adempiere.webui; +import org.adempiere.webui.apps.ProcessDialog; import org.adempiere.webui.component.Window; +import org.adempiere.webui.panel.ADForm; +import org.adempiere.webui.window.ADWindow; import org.compiere.model.MQuery; import org.compiere.util.WebDoc; public interface IDesktop { + /** + * + * @return ClientInfo + */ public ClientInfo getClientInfo(); + /** + * + * @param nodeId + */ public void onMenuSelected(int nodeId); + /** + * + * @param window + * @return windowNo + */ public int registerWindow(Object window); + /** + * close active window + */ public void removeWindow(); + /** + * + * @param url + * @param closeable + */ public void showURL(String url, boolean closeable); + /** + * + * @param doc + * @param string + * @param closeable + */ public void showURL(WebDoc doc, String string, boolean closeable); + /** + * + * @param win + */ public void showWindow(Window win); + /** + * + * @param win + * @param position + */ public void showWindow(Window win, String position); + /** + * + * @param window_ID + * @param query + */ public void showZoomWindow(int window_ID, MQuery query); + /** + * + * @param windowNo + */ public void unregisterWindow(int windowNo); - public void showWindowInTabPanel(Window win); // Elaine 2008/07/30 + /** + * + * @param processId + * @param soTrx + * @return ProcessDialog + */ + public ProcessDialog openProcessDialog(int processId, boolean soTrx); + + /** + * + * @param formId + * @return ADWindow + */ + public ADForm openForm(int formId); + + /** + * + * @param windowId + * @return ADWindow + */ + public ADWindow openWindow(int windowId); } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/WArchive.java b/zkwebui/WEB-INF/src/org/adempiere/webui/WArchive.java index f20721b52b..2d307d5ba4 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/WArchive.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/WArchive.java @@ -164,7 +164,8 @@ public class WArchive implements EventListener else // all Reports av.query(true, m_AD_Table_ID, 0); - SessionManager.getAppDesktop().showWindowInTabPanel(form); + form.setAttribute(Window.MODE_KEY, Window.MODE_EMBEDDED); + SessionManager.getAppDesktop().showWindow(form); } } } 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 9fad755e13..fd568aa4c3 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/AEnv.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/AEnv.java @@ -17,6 +17,10 @@ package org.adempiere.webui.apps; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; import java.io.InvalidClassException; import java.io.NotSerializableException; import java.net.URI; @@ -26,6 +30,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Enumeration; +import java.util.List; import java.util.logging.Level; import javax.servlet.ServletRequest; @@ -51,6 +56,13 @@ import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Execution; import org.zkoss.zk.ui.Executions; +import com.lowagie.text.Document; +import com.lowagie.text.DocumentException; +import com.lowagie.text.pdf.PdfContentByte; +import com.lowagie.text.pdf.PdfImportedPage; +import com.lowagie.text.pdf.PdfReader; +import com.lowagie.text.pdf.PdfWriter; + /** * Windows Application Environment and utilities * @@ -735,4 +747,36 @@ public final class AEnv return false; } + + /** + * + * @param pdfList + * @param outFile + * @throws IOException + * @throws DocumentException + * @throws FileNotFoundException + */ + public static void mergePdf(List pdfList, File outFile) throws IOException, + DocumentException, FileNotFoundException { + 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(); + } } // AEnv diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/ProcessModalDialog.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/ProcessModalDialog.java index 7bbc8395eb..a03b626ac7 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/ProcessModalDialog.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/ProcessModalDialog.java @@ -252,13 +252,16 @@ public class ProcessModalDialog extends Window implements EventListener m_autoStart = true; } if (m_autoStart) { + this.getFirstChild().setVisible(false); startProcess(); + return true; } } // Check if the process is a silent one if(isValid() && m_ShowHelp != null && m_ShowHelp.equals("S")) { + this.getFirstChild().setVisible(false); startProcess(); } return true; @@ -268,22 +271,24 @@ public class ProcessModalDialog extends Window implements EventListener * launch process */ private void startProcess() - { - m_processRunnable = new ProcessRunnable(Executions.getCurrent().getDesktop()); + { m_pi.setPrintPreview(true); if (m_ASyncProcess != null) { m_ASyncProcess.lockUI(m_pi); + } else { + Clients.showBusy(null, true); } + m_processRunnable = new ProcessRunnable(Executions.getCurrent().getDesktop()); //use echo, otherwise lock ui wouldn't work - Clients.response(new AuEcho(this, "runProcessBackground", null)); + Clients.response(new AuEcho(this, "runASyncProcess", null)); } /** * internal use, don't call this directly */ - public void runProcessBackground() { + public void runASyncProcess() { new Thread(m_processRunnable).start(); } @@ -302,6 +307,8 @@ public class ProcessModalDialog extends Window implements EventListener } finally { if (m_ASyncProcess != null) { m_ASyncProcess.unlockUI(m_pi); + } else { + Clients.showBusy(null, false); } //release full control of desktop Executions.deactivate(desktop); 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 c6812a49e6..28c396ac66 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 @@ -18,13 +18,13 @@ 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.apps.AEnv; import org.adempiere.webui.component.ConfirmPanel; import org.adempiere.webui.component.DesktopTabpanel; import org.adempiere.webui.component.Label; @@ -68,12 +68,6 @@ 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 * @@ -706,26 +700,7 @@ public class WInOutGen extends ADForm implements EventListener, ValueChangeListe 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(); + AEnv.mergePdf(pdfList, outFile); Clients.showBusy(null, false); Window win = new SimplePDFViewer(this.getFormName(), new FileInputStream(outFile)); @@ -745,7 +720,6 @@ public class WInOutGen extends ADForm implements EventListener, ValueChangeListe } } - /************************************************************************** * Lock User Interface. * Called from the Worker before processing 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 be726d4d33..d3e3a45840 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 @@ -18,7 +18,6 @@ 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; @@ -29,6 +28,7 @@ import java.util.List; import java.util.logging.Level; import org.adempiere.webui.LayoutUtils; +import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.component.ConfirmPanel; import org.adempiere.webui.component.DesktopTabpanel; import org.adempiere.webui.component.Label; @@ -86,11 +86,6 @@ 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 @@ -705,26 +700,7 @@ public class WInvoiceGen extends ADForm 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(); + AEnv.mergePdf(pdfList, outFile); Clients.showBusy(null, false); Window win = new SimplePDFViewer(this.getFormName(), new FileInputStream(outFile)); diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WMatch.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WMatch.java index 533d5946e1..915a205834 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WMatch.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WMatch.java @@ -162,8 +162,8 @@ public class WMatch extends ADForm private Label onlyProductLabel = new Label(); private Label dateFromLabel = new Label(); private Label dateToLabel = new Label(); - private WDateEditor dateFrom = new WDateEditor("DateFrom", false, false, true, DisplayType.Date, "DateFrom"); - private WDateEditor dateTo = new WDateEditor("DateTo", false, false, true, DisplayType.Date, "DateTo"); + private WDateEditor dateFrom = new WDateEditor("DateFrom", false, false, true, "DateFrom"); + private WDateEditor dateTo = new WDateEditor("DateTo", false, false, true, "DateTo"); private Button bSearch = new Button(); private Panel southPanel = new Panel(); private Grid southLayout = GridFactory.newGridLayout(); diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WPayPrint.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WPayPrint.java index cd5c0eb8a3..8c9ed77e83 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WPayPrint.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WPayPrint.java @@ -1,702 +1,614 @@ -/****************************************************************************** - * 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.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.logging.Level; - -import org.adempiere.webui.component.Button; -import org.adempiere.webui.component.Label; -import org.adempiere.webui.component.ListItem; -import org.adempiere.webui.component.Listbox; -import org.adempiere.webui.component.Textbox; -import org.adempiere.webui.component.VerticalBox; -import org.adempiere.webui.panel.ADForm; -import org.adempiere.webui.session.SessionManager; -import org.adempiere.webui.window.FDialog; -import org.compiere.model.MLookupFactory; -import org.compiere.model.MLookupInfo; -import org.compiere.model.MPaySelectionCheck; -import org.compiere.model.MPaymentBatch; -import org.compiere.print.ReportCtl; -import org.compiere.print.ReportEngine; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.Ini; -import org.compiere.util.KeyNamePair; -import org.compiere.util.Language; -import org.compiere.util.Msg; -import org.compiere.util.ValueNamePair; -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.Filedownload; -import org.zkoss.zul.Hbox; - -public class WPayPrint extends ADForm implements EventListener -{ - - /** Used Bank Account */ - private int m_C_BankAccount_ID = -1; - - /** Payment Information */ - private MPaySelectionCheck[] m_checks = null; - - /** Payment Batch */ - private MPaymentBatch m_batch = null; - - /** Logger */ - private static CLogger log = CLogger.getCLogger(WPayPrint.class); - - // Static Variables - private Hbox centerPanel = new Hbox(); - private Hbox southPanel = new Hbox(); - - private Button bPrint = new Button(); - private Button bExport = new Button(); - private Button bCancel = new Button(); - private Button bProcess = new Button();//(Msg.getMsg(Env.getCtx(), "VPayPrintProcess")); - private Label lPaySelect = new Label(); - private Listbox fPaySelect = new Listbox(); - private Label lBank = new Label(); - private Label fBank = new Label(); - private Label lPaymentRule = new Label(); - private Listbox fPaymentRule = new Listbox(); - private Label lDocumentNo = new Label(); - private Textbox fDocumentNo = new Textbox(); - private Label lNoPayments = new Label(); - private Label fNoPayments = new Label(); - private Label lBalance = new Label(); - private Textbox fBalance = new Textbox(); - private Label lCurrency = new Label(); - private Label fCurrency = new Label(); - - public WPayPrint() - { - } - - protected void initForm() - { - log.info(""); - - try - { - jbInit(); - dynInit(); - - this.appendChild(centerPanel); - this.appendChild(southPanel); - - fPaySelect.setSelectedIndex(0); - loadPaySelectInfo(); - } - catch(Exception e) - { - log.log(Level.SEVERE, "", e); - } - } // init - - /** - * Static Init - * @throws Exception - */ - private void jbInit() throws Exception - { - fPaySelect.setRows(1); - fPaySelect.setMold("select"); - - fPaymentRule.setRows(1); - fPaymentRule.setMold("select"); - - bCancel.setImage("/images/Cancel24.png"); - bPrint.setImage("/images/Print24.png"); - bExport.setImage("/images/ExportX24.png"); - - bPrint.addEventListener(Events.ON_CLICK, this); - bExport.addEventListener(Events.ON_CLICK, this); - bCancel.addEventListener(Events.ON_CLICK, this); - - bProcess.setLabel(Msg.getMsg(Env.getCtx(), "EFT")); - bProcess.setEnabled(false); - bProcess.addEventListener(Events.ON_CLICK, this); - - lPaySelect.setValue(Msg.translate(Env.getCtx(), "C_PaySelection_ID")); - fPaySelect.addEventListener(Events.ON_SELECT, this); - - lBank.setValue(Msg.translate(Env.getCtx(), "C_BankAccount_ID")); - - lPaymentRule.setValue(Msg.translate(Env.getCtx(), "PaymentRule")); - fPaymentRule.addEventListener(Events.ON_SELECT, this); - - lDocumentNo.setValue(Msg.translate(Env.getCtx(), "DocumentNo")); - lNoPayments.setValue(Msg.getMsg(Env.getCtx(), "NoOfPayments")); - fNoPayments.setValue("0"); - lBalance.setValue(Msg.translate(Env.getCtx(), "CurrentBalance")); - fBalance.setEnabled(false); - lCurrency.setValue(Msg.translate(Env.getCtx(), "C_Currency_ID")); - - Hbox boxPaySelect = new Hbox(); - - fPaySelect.setWidth("100%"); - - boxPaySelect.setWidth("100%"); - boxPaySelect.setWidths("40%, 60%"); - boxPaySelect.appendChild(lPaySelect); - boxPaySelect.appendChild(fPaySelect); - - Hbox boxBank = new Hbox(); - boxBank.setWidth("100%"); - boxBank.setWidths("40%, 60%"); - boxBank.appendChild(lBank); - boxBank.appendChild(fBank); - - Hbox boxPaymentRule = new Hbox(); - boxPaymentRule.setWidth("100%"); - boxPaymentRule.setWidths("40%, 60%"); - boxPaymentRule.appendChild(lPaymentRule); - boxPaymentRule.appendChild(fPaymentRule); - - Hbox boxDocNo = new Hbox(); - boxDocNo.setWidth("100%"); - boxDocNo.setWidths("40%, 60%"); - boxDocNo.appendChild(lDocumentNo); - boxDocNo.appendChild(fDocumentNo); - - Hbox boxNoPayments = new Hbox(); - boxNoPayments.setWidth("100%"); - boxNoPayments.setWidths("50%, 50%"); - boxNoPayments.appendChild(lNoPayments); - boxNoPayments.appendChild(fNoPayments); - - Hbox boxBalance = new Hbox(); - boxBalance.setWidth("100%"); - boxBalance.setWidths("50%, 50%"); - boxBalance.appendChild(lBalance); - boxBalance.appendChild(fBalance); - - Hbox boxCurrency = new Hbox(); - boxCurrency.setWidth("100%"); - boxCurrency.setWidths("50%, 50%"); - boxCurrency.appendChild(lCurrency); - boxCurrency.appendChild(fCurrency); - - centerPanel.setWidth("100%"); - centerPanel.setWidths("65%, 35%"); - - VerticalBox vBox1 = new VerticalBox(); - vBox1.setWidth("100%"); - vBox1.appendChild(boxPaySelect); - vBox1.appendChild(boxBank); - vBox1.appendChild(boxPaymentRule); - vBox1.appendChild(boxDocNo); - - VerticalBox vBox2 = new VerticalBox(); - vBox2.setWidth("100%"); - vBox2.appendChild(new Label("")); - vBox2.appendChild(boxBalance); - vBox2.appendChild(boxCurrency); - vBox2.appendChild(boxNoPayments); - - centerPanel.appendChild(vBox1); - centerPanel.appendChild(vBox2); - - southPanel.appendChild(bCancel); - southPanel.appendChild(bExport); - southPanel.appendChild(bPrint); - southPanel.appendChild(bProcess); - } // WPayPrint - - /** - * Dynamic Init - */ - - private void dynInit() - { - log.config(""); - int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx()); - - // Load PaySelect - String sql = "SELECT C_PaySelection_ID, Name || ' - ' || TotalAmt FROM C_PaySelection " - + "WHERE AD_Client_ID=? AND Processed='Y' AND IsActive='Y'" - + "ORDER BY PayDate DESC"; - - try - { - PreparedStatement pstmt = DB.prepareStatement(sql, null); - pstmt.setInt(1, AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); - - while (rs.next()) - { - KeyNamePair pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); - fPaySelect.appendItem(pp.getName(), pp); - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql, e); - } - - if (fPaySelect.getItemCount() == 0) - FDialog.info(m_WindowNo, this, "VPayPrintNoRecords"); - } // dynInit - - /** - * Set Payment Selection - * @param C_PaySelection_ID id - */ - public void setPaySelection (int C_PaySelection_ID) - { - if (C_PaySelection_ID == 0) - return; - // - for (int i = 0; i < fPaySelect.getItemCount(); i++) - { - ListItem listitem = fPaySelect.getItemAtIndex(i); - - KeyNamePair pp = null; - - if (listitem != null) - pp = (KeyNamePair)listitem.getValue(); - - if (pp.getKey() == C_PaySelection_ID) - { - fPaySelect.setSelectedIndex(i); - return; - } - } - } // setsetPaySelection - - - /************************************************************************** - * Action Listener - * @param e event - */ - - public void onEvent(Event e) - { - if (e.getTarget() == fPaySelect) - loadPaySelectInfo(); - else if (e.getTarget() == fPaymentRule) - loadPaymentRuleInfo(); - else if (e.getTarget() == bCancel) - SessionManager.getAppDesktop().removeWindow(); - else if (e.getTarget() == bExport) - cmd_export(); - else if (e.getTarget() == bProcess) - cmd_EFT(); - else if (e.getTarget() == bPrint) - cmd_print(); - } // actionPerformed - - /** - * PaySelect changed - load Bank - */ - - private void loadPaySelectInfo() - { - log.info( "VPayPrint.loadPaySelectInfo"); - if (fPaySelect.getSelectedIndex() == -1) - return; - - // load Banks from PaySelectLine - - ListItem listitem = fPaySelect.getSelectedItem(); - - KeyNamePair key = null; - - if (listitem != null) - key = (KeyNamePair)listitem.getValue(); - - int C_PaySelection_ID = key.getKey(); - m_C_BankAccount_ID = -1; - String sql = "SELECT ps.C_BankAccount_ID, b.Name || ' ' || ba.AccountNo," // 1..2 - + " c.ISO_Code, CurrentBalance " // 3..4 - + "FROM C_PaySelection ps" - + " INNER JOIN C_BankAccount ba ON (ps.C_BankAccount_ID=ba.C_BankAccount_ID)" - + " INNER JOIN C_Bank b ON (ba.C_Bank_ID=b.C_Bank_ID)" - + " INNER JOIN C_Currency c ON (ba.C_Currency_ID=c.C_Currency_ID) " - + "WHERE ps.C_PaySelection_ID=? AND ps.Processed='Y' AND ba.IsActive='Y'"; - - try - { - PreparedStatement pstmt = DB.prepareStatement(sql, null); - pstmt.setInt(1, C_PaySelection_ID); - ResultSet rs = pstmt.executeQuery(); - - if (rs.next()) - { - m_C_BankAccount_ID = rs.getInt(1); - fBank.setValue(rs.getString(2)); - fCurrency.setValue(rs.getString(3)); - fBalance.setValue(rs.getBigDecimal(4).toString()); - } - else - { - m_C_BankAccount_ID = -1; - fBank.setValue(""); - fCurrency.setValue(""); - fBalance.setValue("0"); - log.log(Level.SEVERE, "No active BankAccount for C_PaySelection_ID=" + C_PaySelection_ID); - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql, e); - } - - loadPaymentRule(); - } // loadPaySelectInfo - - /** - * Bank changed - load PaymentRule - */ - private void loadPaymentRule() - { - log.info(""); - - if (m_C_BankAccount_ID == -1) - return; - - // load PaymentRule for Bank - - ListItem listitem = fPaySelect.getSelectedItem(); - - KeyNamePair kp = null; - - if (listitem != null) - kp = (KeyNamePair)listitem.getValue(); - else - return; - - int C_PaySelection_ID = kp.getKey(); - fPaymentRule.getChildren().clear(); - int AD_Reference_ID = 195; // MLookupInfo.getAD_Reference_ID("All_Payment Rule"); - Language language = Language.getLanguage(Env.getAD_Language(Env.getCtx())); - MLookupInfo info = MLookupFactory.getLookup_List(language, AD_Reference_ID); - String sql = info.Query.substring(0, info.Query.indexOf(" ORDER BY")) - + " AND " + info.KeyColumn - + " IN (SELECT PaymentRule FROM C_PaySelectionCheck WHERE C_PaySelection_ID=?) " - + info.Query.substring(info.Query.indexOf(" ORDER BY")); - - try - { - PreparedStatement pstmt = DB.prepareStatement(sql, null); - pstmt.setInt(1, C_PaySelection_ID); - ResultSet rs = pstmt.executeQuery(); - - while (rs.next()) - { - ValueNamePair pp = new ValueNamePair(rs.getString(2), rs.getString(3)); - fPaymentRule.appendItem(pp.getName(), pp); - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql, e); - } - - if (fPaymentRule.getItemCount() == 0) - log.config("PaySel=" + C_PaySelection_ID + ", BAcct=" + m_C_BankAccount_ID + " - " + sql); - - fPaymentRule.setSelectedIndex(0); - - loadPaymentRuleInfo(); - } // loadPaymentRule - - /** - * PaymentRule changed - load DocumentNo, NoPayments, - * enable/disable EFT, Print - */ - - private void loadPaymentRuleInfo() - { - ListItem listitem = fPaymentRule.getSelectedItem(); - - ValueNamePair pp = null; - - if (listitem != null) - pp = (ValueNamePair)listitem.getValue(); - - if (pp == null) - return; - - String PaymentRule = pp.getValue(); - - log.info("PaymentRule=" + PaymentRule); - fNoPayments.setValue(" "); - - listitem = fPaySelect.getSelectedItem(); - - KeyNamePair kp = null; - - if (listitem != null) - kp = (KeyNamePair)listitem.getValue(); - - int C_PaySelection_ID = kp.getKey(); - - String sql = "SELECT COUNT(*) " - + "FROM C_PaySelectionCheck " - + "WHERE C_PaySelection_ID=?"; - try - { - PreparedStatement pstmt = DB.prepareStatement(sql, null); - pstmt.setInt(1, C_PaySelection_ID); - ResultSet rs = pstmt.executeQuery(); - - if (rs.next()) - fNoPayments.setValue(String.valueOf(rs.getInt(1))); - - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql, e); - } - - bProcess.setEnabled(PaymentRule.equals("T")); - - // DocumentNo - sql = "SELECT CurrentNext " - + "FROM C_BankAccountDoc " - + "WHERE C_BankAccount_ID=? AND PaymentRule=? AND IsActive='Y'"; - - try - { - PreparedStatement pstmt = DB.prepareStatement(sql, null); - pstmt.setInt(1, m_C_BankAccount_ID); - pstmt.setString(2, PaymentRule); - ResultSet rs = pstmt.executeQuery(); - - if (rs.next()) - fDocumentNo.setValue(new Integer(rs.getInt(1)).toString()); - else - { - log.log(Level.SEVERE, "VPayPrint.loadPaymentRuleInfo - No active BankAccountDoc for C_BankAccount_ID=" - + m_C_BankAccount_ID + " AND PaymentRule=" + PaymentRule); - FDialog.error(m_WindowNo, this, "VPayPrintNoDoc"); - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql, e); - } - } // loadPaymentRuleInfo - - /************************************************************************** - * Export payments to file - */ - - private void cmd_export() - { - ListItem listitem = fPaymentRule.getSelectedItem(); - - ValueNamePair vp = null; - - if (listitem != null) - vp = (ValueNamePair)listitem.getValue(); - - String PaymentRule = null; - - if (vp != null) - PaymentRule = vp.getValue(); - - log.info(PaymentRule); - - if (!getChecks(PaymentRule)) - return; - - File file = null; - FileInputStream fstream = null; - int no = -1; - - try - { - file = File.createTempFile("temp", "txt"); - no = MPaySelectionCheck.exportToFile(m_checks, file); - fstream = new FileInputStream(file); - } - catch (IOException e1) - { - e1.printStackTrace(); - } - - Filedownload.save(fstream, "", file.getAbsolutePath()); - - // Create File - - FDialog.info(m_WindowNo, this, "Saved", - file.getAbsolutePath() + "\n" - + Msg.getMsg(Env.getCtx(), "NoOfLines") + "=" + no); - - if (FDialog.ask(m_WindowNo, this, "VPayPrintSuccess?")) - { - // int lastDocumentNo = - MPaySelectionCheck.confirmPrint (m_checks, m_batch); - // document No not updated - } - - SessionManager.getAppDesktop().removeWindow(); - } // cmd_export - - /** - * Create EFT payment - */ - - private void cmd_EFT() - { - ListItem listitem = fPaymentRule.getSelectedItem(); - - ValueNamePair vp = null; - - if (listitem != null) - vp = (ValueNamePair)listitem.getValue(); - - String PaymentRule = vp.getValue(); - log.info(PaymentRule); - - if (!getChecks(PaymentRule)) - return; - - SessionManager.getAppDesktop().removeWindow(); - } // cmd_EFT - - /** - * Print Checks and/or Remittance - */ - - private void cmd_print() - { - ListItem listitem = fPaymentRule.getSelectedItem(); - - ValueNamePair vp = null; - - if (listitem != null) - vp = (ValueNamePair)listitem.getValue(); - - String PaymentRule = vp.getValue(); - log.info(PaymentRule); - - if (!getChecks(PaymentRule)) - return; - - boolean somethingPrinted = false; - boolean directPrint = !Ini.isPropertyBool(Ini.P_PRINTPREVIEW); - - // for all checks - for (int i = 0; i < m_checks.length; i++) - { - MPaySelectionCheck check = m_checks[i]; - // ReportCtrl will check BankAccountDoc for PrintFormat - boolean ok = ReportCtl.startDocumentPrint(ReportEngine.CHECK, check.get_ID(), null, m_WindowNo, directPrint); - if (!somethingPrinted && ok) - somethingPrinted = true; - } - - // Confirm Print and Update BankAccountDoc - if (somethingPrinted && FDialog.ask(m_WindowNo, this, "VPayPrintSuccess?")) - { - int lastDocumentNo = MPaySelectionCheck.confirmPrint (m_checks, m_batch); - if (lastDocumentNo != 0) - { - StringBuffer sb = new StringBuffer(); - sb.append("UPDATE C_BankAccountDoc SET CurrentNext=").append(++lastDocumentNo) - .append(" WHERE C_BankAccount_ID=").append(m_C_BankAccount_ID) - .append(" AND PaymentRule='").append(PaymentRule).append("'"); - DB.executeUpdate(sb.toString(), null); - } - } // confirm - - if (FDialog.ask(m_WindowNo, this, "VPayPrintPrintRemittance")) - { - for (int i = 0; i < m_checks.length; i++) - { - MPaySelectionCheck check = m_checks[i]; - ReportCtl.startDocumentPrint(ReportEngine.REMITTANCE, check.get_ID(), null, m_WindowNo, directPrint); - } - } // remittance - - SessionManager.getAppDesktop().removeWindow(); - } // cmd_print - - /************************************************************************** - * Get Checks - * @param PaymentRule Payment Rule - * @return true if payments were created - */ - - private boolean getChecks(String PaymentRule) - { - // do we have values - if (fPaySelect.getSelectedIndex() == -1 || m_C_BankAccount_ID == -1 - || fPaymentRule.getSelectedIndex() == -1 || fDocumentNo.getValue() == null) - { - FDialog.error(m_WindowNo, this, "VPayPrintNoRecords", - "(" + Msg.translate(Env.getCtx(), "C_PaySelectionLine_ID") + "=0)"); - - return false; - } - - // get data - - ListItem listitem = fPaySelect.getSelectedItem(); - - KeyNamePair kp = null; - - if (listitem != null) - kp = (KeyNamePair)listitem.getValue(); - - int C_PaySelection_ID = kp.getKey(); - - int startDocumentNo = new Integer(fDocumentNo.getValue()); - - log.config("C_PaySelection_ID=" + C_PaySelection_ID + ", PaymentRule=" + PaymentRule + ", DocumentNo=" + startDocumentNo); - - // get Selections - m_checks = MPaySelectionCheck.get(C_PaySelection_ID, PaymentRule, startDocumentNo, null); - - if (m_checks == null || m_checks.length == 0) - { - FDialog.error(m_WindowNo, this, "VPayPrintNoRecords", - "(" + Msg.translate(Env.getCtx(), "C_PaySelectionLine_ID") + " #0"); - return false; - } - m_batch = MPaymentBatch.getForPaySelection (Env.getCtx(), C_PaySelection_ID, null); - - return true; - } // getChecks -} +/****************************************************************************** + * 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.sql.*; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.*; + +import org.adempiere.webui.apps.AEnv; +import org.adempiere.webui.component.Button; +import org.adempiere.webui.component.ConfirmPanel; +import org.adempiere.webui.component.Grid; +import org.adempiere.webui.component.GridFactory; +import org.adempiere.webui.component.Label; +import org.adempiere.webui.component.Listbox; +import org.adempiere.webui.component.ListboxFactory; +import org.adempiere.webui.component.Panel; +import org.adempiere.webui.component.Row; +import org.adempiere.webui.component.Rows; +import org.adempiere.webui.component.Window; +import org.adempiere.webui.editor.WNumberEditor; +import org.adempiere.webui.panel.ADForm; +import org.adempiere.webui.session.SessionManager; +import org.adempiere.webui.window.FDialog; +import org.adempiere.webui.window.SimplePDFViewer; +import org.compiere.model.*; +import org.compiere.print.*; +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.South; +import org.zkoss.zul.Filedownload; + +/** + * Payment Print & Export + * + * @author Jorg Janke + * @version $Id: VPayPrint.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $ + */ +public class WPayPrint extends ADForm + implements EventListener +{ + /** + * Initialize Panel + */ + protected void initForm() + { + try + { + zkInit(); + dynInit(); + Borderlayout contentLayout = new Borderlayout(); + contentLayout.setWidth("100%"); + contentLayout.setHeight("100%"); + this.appendChild(contentLayout); + Center center = new Center(); + contentLayout.appendChild(center); + center.appendChild(centerPanel); + South south = new South(); + south.setStyle("border: none"); + contentLayout.appendChild(south); + south.appendChild(southPanel); + } + catch(Exception e) + { + log.log(Level.SEVERE, "", e); + } + } // init + + /** Used Bank Account */ + private int m_C_BankAccount_ID = -1; + + /** Payment Information */ + private MPaySelectionCheck[] m_checks = null; + /** Payment Batch */ + private MPaymentBatch m_batch = null; + /** Logger */ + private static CLogger log = CLogger.getCLogger(WPayPrint.class); + + // Static Variables + private Panel centerPanel = new Panel(); + private ConfirmPanel southPanel = new ConfirmPanel(true, false, false, false, false, false, false); + private Grid centerLayout = GridFactory.newGridLayout(); + private Button bPrint = southPanel.createButton(ConfirmPanel.A_PRINT); + private Button bExport = southPanel.createButton(ConfirmPanel.A_EXPORT); + private Button bCancel = southPanel.getButton(ConfirmPanel.A_CANCEL); + private Button bProcess = southPanel.createButton(ConfirmPanel.A_PROCESS); + private Label lPaySelect = new Label(); + private Listbox fPaySelect = ListboxFactory.newDropdownListbox(); + private Label lBank = new Label(); + private Label fBank = new Label(); + private Label lPaymentRule = new Label(); + private Listbox fPaymentRule = ListboxFactory.newDropdownListbox(); + private Label lDocumentNo = new Label(); + private WNumberEditor fDocumentNo = new WNumberEditor(); + private Label lNoPayments = new Label(); + private Label fNoPayments = new Label(); + private Label lBalance = new Label(); + private WNumberEditor fBalance = new WNumberEditor(); + private Label lCurrency = new Label(); + private Label fCurrency = new Label(); + + /** + * Static Init + * @throws Exception + */ + private void zkInit() throws Exception + { + // + centerPanel.appendChild(centerLayout); + // + bPrint.addActionListener(this); + bExport.addActionListener(this); + bCancel.addActionListener(this); + // + bProcess.setEnabled(false); + bProcess.addActionListener(this); + // + lPaySelect.setText(Msg.translate(Env.getCtx(), "C_PaySelection_ID")); + fPaySelect.addActionListener(this); + // + lBank.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID")); + // + lPaymentRule.setText(Msg.translate(Env.getCtx(), "PaymentRule")); + fPaymentRule.addActionListener(this); + // + lDocumentNo.setText(Msg.translate(Env.getCtx(), "DocumentNo")); + fDocumentNo.getComponent().setIntegral(true); + lNoPayments.setText(Msg.getMsg(Env.getCtx(), "NoOfPayments")); + fNoPayments.setText("0"); + lBalance.setText(Msg.translate(Env.getCtx(), "CurrentBalance")); + fBalance.setReadWrite(false); + fBalance.getComponent().setIntegral(false); + lCurrency.setText(Msg.translate(Env.getCtx(), "C_Currency_ID")); + // + southPanel.addButton(bExport); + southPanel.addButton(bPrint); + southPanel.addButton(bProcess); + // + Rows rows = centerLayout.newRows(); + Row row = rows.newRow(); + row.appendChild(lPaySelect.rightAlign()); + row.appendChild(fPaySelect); + + row = rows.newRow(); + row.appendChild(lBank.rightAlign()); + row.appendChild(fBank); + row.appendChild(lBalance.rightAlign()); + row.appendChild(fBalance.getComponent()); + + row = rows.newRow(); + row.appendChild(lPaymentRule.rightAlign()); + row.appendChild(fPaymentRule); + row.appendChild(lCurrency.rightAlign()); + row.appendChild(fCurrency); + + row = rows.newRow(); + row.appendChild(lDocumentNo.rightAlign()); + row.appendChild(fDocumentNo.getComponent()); + row.appendChild(lNoPayments.rightAlign()); + row.appendChild(fNoPayments); + + } // VPayPrint + + /** + * Dynamic Init + */ + private void dynInit() + { + log.config(""); + int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx()); + + // Load PaySelect + String sql = "SELECT C_PaySelection_ID, Name || ' - ' || TotalAmt FROM C_PaySelection " + + "WHERE AD_Client_ID=? AND Processed='Y' AND IsActive='Y'" + + "ORDER BY PayDate DESC"; + try + { + PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt.setInt(1, AD_Client_ID); + ResultSet rs = pstmt.executeQuery(); + // + while (rs.next()) + { + KeyNamePair pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); + fPaySelect.addItem(pp); + } + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql, e); + } + if (fPaySelect.getItemCount() == 0) + FDialog.info(m_WindowNo, this, "VPayPrintNoRecords"); + else + { + fPaySelect.setSelectedIndex(0); + loadPaySelectInfo(); + } + } // dynInit + + /** + * Dispose + */ + public void dispose() + { + SessionManager.getAppDesktop().removeWindow(); + } // dispose + + /** + * Set Payment Selection + * @param C_PaySelection_ID id + */ + public void setPaySelection (int C_PaySelection_ID) + { + if (C_PaySelection_ID == 0) + return; + // + for (int i = 0; i < fPaySelect.getItemCount(); i++) + { + KeyNamePair pp = fPaySelect.getItemAtIndex(i).toKeyNamePair(); + if (pp.getKey() == C_PaySelection_ID) + { + fPaySelect.setSelectedIndex(i); + loadPaySelectInfo(); + return; + } + } + } // setsetPaySelection + + + /************************************************************************** + * Action Listener + * @param e event + */ + public void onEvent(Event e) + { + // log.config( "VPayPrint.actionPerformed" + e.toString()); + if (e.getTarget() == fPaySelect) + loadPaySelectInfo(); + else if (e.getTarget() == fPaymentRule) + loadPaymentRuleInfo(); + // + else if (e.getTarget() == bCancel) + dispose(); + else if (e.getTarget() == bExport) + cmd_export(); + else if (e.getTarget() == bProcess) + cmd_EFT(); + else if (e.getTarget() == bPrint) + cmd_print(); + } // actionPerformed + + /** + * PaySelect changed - load Bank + */ + private void loadPaySelectInfo() + { + log.info( "VPayPrint.loadPaySelectInfo"); + if (fPaySelect.getSelectedIndex() == -1) + return; + + // load Banks from PaySelectLine + int C_PaySelection_ID = fPaySelect.getSelectedItem().toKeyNamePair().getKey(); + m_C_BankAccount_ID = -1; + String sql = "SELECT ps.C_BankAccount_ID, b.Name || ' ' || ba.AccountNo," // 1..2 + + " c.ISO_Code, CurrentBalance " // 3..4 + + "FROM C_PaySelection ps" + + " INNER JOIN C_BankAccount ba ON (ps.C_BankAccount_ID=ba.C_BankAccount_ID)" + + " INNER JOIN C_Bank b ON (ba.C_Bank_ID=b.C_Bank_ID)" + + " INNER JOIN C_Currency c ON (ba.C_Currency_ID=c.C_Currency_ID) " + + "WHERE ps.C_PaySelection_ID=? AND ps.Processed='Y' AND ba.IsActive='Y'"; + try + { + PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt.setInt(1, C_PaySelection_ID); + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) + { + m_C_BankAccount_ID = rs.getInt(1); + fBank.setText(rs.getString(2)); + fCurrency.setText(rs.getString(3)); + fBalance.setValue(rs.getBigDecimal(4)); + } + else + { + m_C_BankAccount_ID = -1; + fBank.setText(""); + fCurrency.setText(""); + fBalance.setValue(Env.ZERO); + log.log(Level.SEVERE, "No active BankAccount for C_PaySelection_ID=" + C_PaySelection_ID); + } + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql, e); + } + loadPaymentRule(); + } // loadPaySelectInfo + + /** + * Bank changed - load PaymentRule + */ + private void loadPaymentRule() + { + log.info(""); + if (m_C_BankAccount_ID == -1) + return; + + // load PaymentRule for Bank + int C_PaySelection_ID = fPaySelect.getSelectedItem().toKeyNamePair().getKey(); + fPaymentRule.removeAllItems(); + int AD_Reference_ID = 195; // MLookupInfo.getAD_Reference_ID("All_Payment Rule"); + Language language = Language.getLanguage(Env.getAD_Language(Env.getCtx())); + MLookupInfo info = MLookupFactory.getLookup_List(language, AD_Reference_ID); + String sql = info.Query.substring(0, info.Query.indexOf(" ORDER BY")) + + " AND " + info.KeyColumn + + " IN (SELECT PaymentRule FROM C_PaySelectionCheck WHERE C_PaySelection_ID=?) " + + info.Query.substring(info.Query.indexOf(" ORDER BY")); + try + { + PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt.setInt(1, C_PaySelection_ID); + ResultSet rs = pstmt.executeQuery(); + // + while (rs.next()) + { + ValueNamePair pp = new ValueNamePair(rs.getString(2), rs.getString(3)); + fPaymentRule.addItem(pp); + } + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql, e); + } + if (fPaymentRule.getItemCount() == 0) + log.config("PaySel=" + C_PaySelection_ID + ", BAcct=" + m_C_BankAccount_ID + " - " + sql); + else + fPaymentRule.setSelectedIndex(0); + loadPaymentRuleInfo(); + } // loadPaymentRule + + /** + * PaymentRule changed - load DocumentNo, NoPayments, + * enable/disable EFT, Print + */ + private void loadPaymentRuleInfo() + { + ValueNamePair pp = fPaymentRule.getSelectedItem().toValueNamePair(); + if (pp == null) + return; + String PaymentRule = pp.getValue(); + + log.info("PaymentRule=" + PaymentRule); + fNoPayments.setText(" "); + + int C_PaySelection_ID = fPaySelect.getSelectedItem().toKeyNamePair().getKey(); + String sql = "SELECT COUNT(*) " + + "FROM C_PaySelectionCheck " + + "WHERE C_PaySelection_ID=?"; + try + { + PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt.setInt(1, C_PaySelection_ID); + ResultSet rs = pstmt.executeQuery(); + // + if (rs.next()) + fNoPayments.setText(String.valueOf(rs.getInt(1))); + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql, e); + } + bProcess.setEnabled(PaymentRule.equals("T")); + + // DocumentNo + sql = "SELECT CurrentNext " + + "FROM C_BankAccountDoc " + + "WHERE C_BankAccount_ID=? AND PaymentRule=? AND IsActive='Y'"; + try + { + PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt.setInt(1, m_C_BankAccount_ID); + pstmt.setString(2, PaymentRule); + ResultSet rs = pstmt.executeQuery(); + // + if (rs.next()) + fDocumentNo.setValue(new Integer(rs.getInt(1))); + else + { + log.log(Level.SEVERE, "VPayPrint.loadPaymentRuleInfo - No active BankAccountDoc for C_BankAccount_ID=" + + m_C_BankAccount_ID + " AND PaymentRule=" + PaymentRule); + FDialog.error(m_WindowNo, this, "VPayPrintNoDoc"); + } + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql, e); + } + } // loadPaymentRuleInfo + + + /************************************************************************** + * Export payments to file + */ + private void cmd_export() + { + String PaymentRule = fPaymentRule.getSelectedItem().toValueNamePair().getValue(); + log.info(PaymentRule); + if (!getChecks(PaymentRule)) + return; + + try + { + // Get File Info + File tempFile = File.createTempFile("paymentExport", ".txt"); + + // Create File + MPaySelectionCheck.exportToFile(m_checks, tempFile); + Filedownload.save(new FileInputStream(tempFile), "plain/text", "paymentExport.txt"); + + if (FDialog.ask(m_WindowNo, this, "VPayPrintSuccess?")) + { + // int lastDocumentNo = + MPaySelectionCheck.confirmPrint (m_checks, m_batch); + // document No not updated + } + dispose(); + } + catch (Exception e) + { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + } + } // cmd_export + + /** + * Create EFT payment + */ + private void cmd_EFT() + { + String PaymentRule = fPaymentRule.getSelectedItem().toValueNamePair().getValue(); + log.info(PaymentRule); + if (!getChecks(PaymentRule)) + return; + dispose(); + } // cmd_EFT + + /** + * Print Checks and/or Remittance + */ + private void cmd_print() + { + String PaymentRule = fPaymentRule.getSelectedItem().toValueNamePair().getValue(); + log.info(PaymentRule); + if (!getChecks(PaymentRule)) + return; + + // for all checks + List pdfList = new ArrayList(); + for (int i = 0; i < m_checks.length; i++) + { + MPaySelectionCheck check = m_checks[i]; + // ReportCtrl will check BankAccountDoc for PrintFormat + ReportEngine re = ReportEngine.get(Env.getCtx(), ReportEngine.CHECK, check.get_ID()); + try + { + File file = File.createTempFile("WPayPrint", null); + re.getPDF(file); + pdfList.add(file); + } + catch (Exception e) + { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + return; + } + } + + SimplePDFViewer chequeViewer = null; + try + { + File outFile = File.createTempFile("WPayPrint", null); + AEnv.mergePdf(pdfList, outFile); + chequeViewer = new SimplePDFViewer(this.getFormName(), new FileInputStream(outFile)); + chequeViewer.setAttribute(Window.MODE_KEY, Window.MODE_EMBEDDED); + chequeViewer.setWidth("100%"); + } + catch (Exception e) + { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + return; + } + + // Update BankAccountDoc + int lastDocumentNo = MPaySelectionCheck.confirmPrint (m_checks, m_batch); + if (lastDocumentNo != 0) + { + StringBuffer sb = new StringBuffer(); + sb.append("UPDATE C_BankAccountDoc SET CurrentNext=").append(++lastDocumentNo) + .append(" WHERE C_BankAccount_ID=").append(m_C_BankAccount_ID) + .append(" AND PaymentRule='").append(PaymentRule).append("'"); + DB.executeUpdate(sb.toString(), null); + } + + SimplePDFViewer remitViewer = null; + if (FDialog.ask(m_WindowNo, this, "VPayPrintPrintRemittance")) + { + pdfList = new ArrayList(); + for (int i = 0; i < m_checks.length; i++) + { + MPaySelectionCheck check = m_checks[i]; + ReportEngine re = ReportEngine.get(Env.getCtx(), ReportEngine.REMITTANCE, check.get_ID()); + try + { + File file = File.createTempFile("WPayPrint", null); + re.getPDF(file); + pdfList.add(file); + } + catch (Exception e) + { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + } + } + + try + { + File outFile = File.createTempFile("WPayPrint", null); + AEnv.mergePdf(pdfList, outFile); + String name = Msg.translate(Env.getCtx(), "Remittance"); + remitViewer = new SimplePDFViewer(this.getFormName() + " - " + name, new FileInputStream(outFile)); + remitViewer.setAttribute(Window.MODE_KEY, Window.MODE_EMBEDDED); + remitViewer.setWidth("100%"); + } + catch (Exception e) + { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + } + } // remittance + + dispose(); + + if (chequeViewer != null) + SessionManager.getAppDesktop().showWindow(chequeViewer); + + if (remitViewer != null) + SessionManager.getAppDesktop().showWindow(remitViewer); + } // cmd_print + + + /************************************************************************** + * Get Checks + * @param PaymentRule Payment Rule + * @return true if payments were created + */ + private boolean getChecks(String PaymentRule) + { + // do we have values + if (fPaySelect.getSelectedIndex() == -1 || m_C_BankAccount_ID == -1 + || fPaymentRule.getSelectedIndex() == -1 || fDocumentNo.getValue() == null) + { + FDialog.error(m_WindowNo, this, "VPayPrintNoRecords", + "(" + Msg.translate(Env.getCtx(), "C_PaySelectionLine_ID") + "=0)"); + return false; + } + + // get data + int C_PaySelection_ID = fPaySelect.getSelectedItem().toKeyNamePair().getKey(); + int startDocumentNo = ((Number)fDocumentNo.getValue()).intValue(); + + log.config("C_PaySelection_ID=" + C_PaySelection_ID + ", PaymentRule=" + PaymentRule + ", DocumentNo=" + startDocumentNo); + // + // get Slecetions + m_checks = MPaySelectionCheck.get(C_PaySelection_ID, PaymentRule, startDocumentNo, null); + + // + if (m_checks == null || m_checks.length == 0) + { + FDialog.error(m_WindowNo, this, "VPayPrintNoRecords", + "(" + Msg.translate(Env.getCtx(), "C_PaySelectionLine_ID") + " #0"); + return false; + } + m_batch = MPaymentBatch.getForPaySelection (Env.getCtx(), C_PaySelection_ID, null); + return true; + } // getChecks + +} // PayPrint diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WPaySelect.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WPaySelect.java index 8e7397b77b..6ae7ba7f68 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WPaySelect.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WPaySelect.java @@ -1,839 +1,712 @@ -/****************************************************************************** - * 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.DecimalFormat; -import java.util.List; -import java.util.Properties; -import java.util.logging.Level; - -import org.adempiere.webui.apps.ProcessModalDialog; -import org.adempiere.webui.component.Button; -import org.adempiere.webui.component.Checkbox; -import org.adempiere.webui.component.Datebox; -import org.adempiere.webui.component.Grid; -import org.adempiere.webui.component.Label; -import org.adempiere.webui.component.ListItem; -import org.adempiere.webui.component.Listbox; -import org.adempiere.webui.component.Row; -import org.adempiere.webui.component.Rows; -import org.adempiere.webui.component.WListbox; -import org.adempiere.webui.event.WTableModelEvent; -import org.adempiere.webui.event.WTableModelListener; -import org.adempiere.webui.panel.ADForm; -import org.adempiere.webui.window.FDialog; - -import org.compiere.minigrid.ColumnInfo; -import org.compiere.minigrid.IDColumn; -import org.compiere.model.MLookupFactory; -import org.compiere.model.MLookupInfo; -import org.compiere.model.MPaySelection; -import org.compiere.model.MPaySelectionLine; -import org.compiere.model.MRole; -import org.compiere.model.X_C_Order; -import org.compiere.model.X_C_PaySelection; -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.Language; -import org.compiere.util.Msg; -import org.compiere.util.ValueNamePair; - -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; - -/** - * Pay Selection Manual Custom Form : Based on VPaySelect - * - * @author Niraj Sohun - * @date Jun 25, 2007 - */ -public class WPaySelect extends ADForm implements EventListener, WTableModelListener -{ - private static final long serialVersionUID = 1L; - - /** Logger */ - private static CLogger log = CLogger.getCLogger(WPaySelect.class); - - // Input Part of Form - - private Grid parameters; - private Rows rows; - private Row row1; - private Row row2; - private Row row3; - - // Labels - - private Label lblBalanceAmt; - private Label lblBottom; - - // Components - - private Listbox lstBankAccount; - private Listbox lstBusinessPartner; - private Checkbox dueInvoices; - private Datebox date; - private Listbox lstPaymentRule; - private Button refresh; - private Button btnProcess; - - // Data Grid - - private WListbox dataTable; - - private int m_AD_Client_ID = 0; - private String m_sql = ""; - private DecimalFormat m_format = DisplayType.getNumberFormat(DisplayType.Amount); - private Float currentBalance; - - /** - * - * - */ - public WPaySelect() - { - } - - /** - * - * - */ - protected void initForm() - { - dataTable = new WListbox(); - dataTable.setWidth("700px"); - dataTable.setMultiple(true); - - // Input Part of Form - - parameters = new Grid(); - parameters.setWidth("700px"); - parameters.setAlign("center"); - - rows = new Rows(); - row1 = new Row(); - row2 = new Row(); - row3 = new Row(); - - // Components - - lblBalanceAmt = new Label(); - lblBottom = new Label(); - - lstBankAccount = new Listbox(); - lstBankAccount.setWidth("150px"); - lstBankAccount.setRows(1); - lstBankAccount.setMold("select"); - lstBankAccount.addEventListener(Events.ON_SELECT, this); - - lstBusinessPartner = new Listbox(); - lstBusinessPartner.setWidth("150px"); - lstBusinessPartner.setRows(1); - lstBusinessPartner.setMold("select"); - lstBusinessPartner.addEventListener(Events.ON_SELECT, this); - - dueInvoices = new Checkbox(); - dueInvoices.setLabel(Msg.getMsg(Env.getCtx(), "OnlyDue")); - dueInvoices.addEventListener(Events.ON_SELECT, this); - - date = new Datebox(); - date.setWidth("150px"); - date.setValue(new Timestamp(System.currentTimeMillis())); - date.addEventListener(Events.ON_SELECT, this); - - lstPaymentRule = new Listbox(); - lstPaymentRule.setWidth("150px"); - lstPaymentRule.setWidth("150px"); - lstPaymentRule.setRows(1); - lstPaymentRule.setMold("select"); - lstPaymentRule.addEventListener(Events.ON_SELECT, this); - - refresh = new Button(); - refresh.setImage("/images/Refresh24.png"); - refresh.addEventListener(Events.ON_CLICK, this); - - btnProcess = new Button(); - btnProcess.setImage("/images/Process24.png"); - btnProcess.setEnabled(false); - btnProcess.addEventListener(Events.ON_CLICK, this); - - display(); - } - - /** - * - * - */ - - private void display() - { - row1.appendChild(new Label("Bank Account")); - row1.appendChild(lstBankAccount); - - row1.appendChild(new Label("Current Balance")); - row1.appendChild(lblBalanceAmt); - - row2.setSpans(",2,"); - row2.appendChild(new Label("Business Partner")); - row2.appendChild(lstBusinessPartner); - - row2.appendChild(dueInvoices); - - row3.appendChild(new Label("Payment Date")); - row3.appendChild(date); - row3.appendChild(new Label("Payment Rule")); - row3.appendChild(lstPaymentRule); - - rows.appendChild(row1); - rows.appendChild(row2); - rows.appendChild(row3); - parameters.appendChild(rows); - - Hbox mainBox = new Hbox(); - mainBox.setWidth("700px"); - - Hbox hboxButtons = new Hbox(); - hboxButtons.setWidth("80px"); - hboxButtons.appendChild(btnProcess); - hboxButtons.appendChild(refresh); - - Hbox hLbl = new Hbox(); - hLbl.appendChild(lblBottom); - - mainBox.appendChild(hboxButtons); - mainBox.appendChild(hLbl); - - this.setHeight("710px"); - this.setWidth("100%"); - this.setBorder("normal"); - this.appendChild(parameters); - this.appendChild(new Separator()); - this.appendChild(dataTable); - this.appendChild(new Separator()); - this.appendChild(mainBox); - - populateBankAccount(); - populateBusinessPartner(); - populateGrid(); - } - - /** - * - * - */ - private void process() - { - int adProcessId = 155; - String trxName = null; - - calculateSelection(); - - MPaySelection m_ps = new MPaySelection(Env.getCtx(), 0, trxName); - - ListItem payRule = lstPaymentRule.getSelectedItem(); - Timestamp payDate = (Timestamp)date.getValue(); - - m_ps.setName (Msg.getMsg(Env.getCtx(), "WPaySelect") - + " - " + ((ValueNamePair)payRule.getValue()).getName() - + " - " + payDate); - - m_ps.setPayDate (payDate); - - BankInfo bi = getSelectedBankAccount(); - m_ps.setC_BankAccount_ID(bi.C_BankAccount_ID); - m_ps.setIsApproved(true); - - if (!m_ps.save()) - { - FDialog.error(m_WindowNo, this, "SaveError", Msg.translate(Env.getCtx(), "C_PaySelection_ID")); - m_ps = null; - return; - } - - // Create Lines - - int rows = dataTable.getItemCount(); - int line = 0; - - ListItem pyRule = lstPaymentRule.getSelectedItem(); - String strPayRule = ((ValueNamePair)pyRule.getValue()).getValue(); - - for (int i = 0; i < rows; i++) - { - if (dataTable.getItemAtIndex(i).isSelected()) - { - line += 10; - - MPaySelectionLine psl = new MPaySelectionLine (m_ps, line, strPayRule); - -// List celllist = (List)(dataTable.getItemAtIndex(i).getChildren()); - -// ListCell invID = celllist.get(0); -// ListCell openAmt = celllist.get(8); -// ListCell payAmt = celllist.get(9); - IDColumn id = (IDColumn)dataTable.getValueAt(i, 0); - - Integer C_Invoice_ID = id.getRecord_ID(); - BigDecimal OpenAmt = new BigDecimal(dataTable.getValueAt(i, 8).toString()); - BigDecimal PayAmt = new BigDecimal(dataTable.getValueAt(i, 9).toString()); - - boolean isSOTrx = false; - - psl.setInvoice(C_Invoice_ID, isSOTrx, OpenAmt, PayAmt, OpenAmt.subtract(PayAmt)); - - if (!psl.save(trxName)) - { - FDialog.error(m_WindowNo, this, "SaveError", Msg.translate(Env.getCtx(), "C_PaySelectionLine_ID")); - return; - } - log.fine("C_Invoice_ID=" + C_Invoice_ID - + ", PayAmt=" + PayAmt); - } - } - - // Ask to Post it - - if (!FDialog.ask(m_WindowNo, this, "(" + m_ps.getName() + ")")) - { - return; - } - - ProcessModalDialog msg = new ProcessModalDialog( - this, "Payment Selection Manual", null, m_WindowNo, adProcessId, - X_C_PaySelection.Table_ID, m_ps.getC_PaySelection_ID(), true); - - if (msg.isValid()) - { - msg.setTitle("Payment Selection (Manual)"); - msg.setPage(this.getPage()); - msg.setClosable(true); - msg.setWidth("500px"); - - try - { - msg.doModal(); - } - catch (InterruptedException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - - private void calculateSelection() - { - int noSelected = 0; - BigDecimal invoiceAmt = new BigDecimal(0.0); - - int rows = dataTable.getRowCount(); - - for (int rowIndex = 0; rowIndex < rows; rowIndex++) - { - // TODO remove this magic number - IDColumn id = (IDColumn)dataTable.getValueAt(rowIndex, 0); - - if (id.isSelected()) - { - // TODO remove this magic number - BigDecimal amt = (BigDecimal)dataTable.getValueAt(rowIndex, 9); - invoiceAmt = invoiceAmt.add(amt); - noSelected++; - } - } - - // Information - - BankInfo bi = getSelectedBankAccount(); - BigDecimal remaining = bi.Balance.subtract(invoiceAmt); - - StringBuffer info = new StringBuffer(); - info.append(noSelected).append(" ").append(Msg.getMsg(Env.getCtx(), "Selected")).append(" - "); - info.append(m_format.format(invoiceAmt)).append(", "); - info.append(Msg.getMsg(Env.getCtx(), "Remaining")).append(" ").append(m_format.format(remaining)); - - lblBottom.setValue(info.toString()); - - if (noSelected == 0) - { - btnProcess.setEnabled(false); - } - else - { - btnProcess.setEnabled(true); - } - - return; - } - - /** - * Obtain details of the selected bank account - * - * @return the BankInfo of the selected account - */ - private BankInfo getSelectedBankAccount() - { - ListItem bankAccountItem = lstBankAccount.getSelectedItem(); - BankInfo bi = (BankInfo)bankAccountItem.getValue(); - - return bi; - } - - private void populateBankAccount() - { - String sql = MRole.getDefault().addAccessSQL( - "SELECT ba.C_BankAccount_ID," // 1 - + "b.Name || ' ' || ba.AccountNo AS Name," // 2 - + "ba.C_Currency_ID, c.ISO_Code," // 3..4 - + "ba.CurrentBalance " // 5 - + "FROM C_Bank b, C_BankAccount ba, C_Currency c " - + "WHERE b.C_Bank_ID=ba.C_Bank_ID" - + " AND ba.C_Currency_ID=c.C_Currency_ID " - + " AND EXISTS (SELECT * FROM C_BankAccountDoc d WHERE d.C_BankAccount_ID=ba.C_BankAccount_ID) " - + "ORDER BY 2", - "b", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RW); - - BankInfo bi = null; - - try - { - PreparedStatement pstmt = DB.prepareStatement(sql, null); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - boolean Transfers = false; - bi = new BankInfo (rs.getInt(1), rs.getInt(3), rs.getString(2), rs.getString(4), rs.getBigDecimal(5), Transfers); - lstBankAccount.appendItem(bi.Name, bi); - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql, e); - } - - if (lstBankAccount.getItemCount() == 0) - { - throw new IllegalStateException("No Bank Account has been found"); - } - else - { - // Selecting the first item - lstBankAccount.setSelectedIndex(0); - populatePaymentRule(); - - updateCurrentBalance(); - } - } - - private void updateCurrentBalance() - { - BankInfo bnkInf = getSelectedBankAccount(); - currentBalance = bnkInf.Balance.floatValue(); - lblBalanceAmt.setValue(currentBalance.toString() + " " + bnkInf.Currency); - - lblBottom.setValue(""); - } - - /** - * Query the database for Business Partners and populate the Business - * Partner combobox with the returned resultset - */ - private void populateBusinessPartner() - { - KeyNamePair pp = new KeyNamePair(0, ""); - lstBusinessPartner.appendItem(pp.getName(), pp); - - String sql = MRole.getDefault().addAccessSQL( - "SELECT bp.C_BPartner_ID, bp.Name FROM C_BPartner bp", "bp", - MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO) - + " AND EXISTS (SELECT * FROM C_Invoice i WHERE bp.C_BPartner_ID=i.C_BPartner_ID" - + " AND (i.IsSOTrx='N' OR (i.IsSOTrx='Y' AND i.PaymentRule='D'))" - + " AND i.IsPaid<>'Y') " - + "ORDER BY 2"; - - try - { - PreparedStatement pstmt = DB.prepareStatement(sql, null); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); - lstBusinessPartner.appendItem(pp.getName(), pp); - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - // TODO need to do something with this exception - log.log(Level.SEVERE, sql, e); - } - - lstBusinessPartner.setSelectedIndex(0); - } - - - /** - * Query the database for Payment Rules and populate the Payment - * Rules combobox with the returned resultset - */ - private void populatePaymentRule() - { - ListItem temp = lstBankAccount.getSelectedItem(); - BankInfo bankInfo = (BankInfo)temp.getValue(); - - if (bankInfo == null) - { - return; - } - - // PaymentRule - - lstPaymentRule.getChildren().clear(); - - int AD_Reference_ID = 195; //TODO: Find this reference in the models - Language language = Env.getLanguage(Env.getCtx()); - MLookupInfo info = MLookupFactory.getLookup_List(language, AD_Reference_ID); - String sql = info.Query.substring(0, info.Query.indexOf(" ORDER BY")) - + " AND " + info.KeyColumn - + " IN (SELECT PaymentRule FROM C_BankAccountDoc WHERE C_BankAccount_ID=?) " - + info.Query.substring(info.Query.indexOf(" ORDER BY")); - - try - { - PreparedStatement pstmt = DB.prepareStatement(sql, null); - pstmt.setInt(1, bankInfo.C_BankAccount_ID); - ResultSet rs = pstmt.executeQuery(); - ValueNamePair vp = null; - while (rs.next()) - { - vp = new ValueNamePair(rs.getString(2), rs.getString(3)); // returns also not active - lstPaymentRule.appendItem(vp.getName(), vp); - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql, e); - } - - lstPaymentRule.setSelectedIndex(0); - } - - /** - * Prepare the data table - * - */ - private void prepareGrid() - { - // FROM VPaySelect.dynInit - - // MiniTable Parameters - - Properties ctx = Env.getCtx(); - - ColumnInfo[] columnInfo = new ColumnInfo[10]; - columnInfo[0] = new ColumnInfo(" ", "i.C_Invoice_ID", IDColumn.class, false, false, null); - columnInfo[1] = new ColumnInfo(Msg.translate(ctx, "DueDate"), "paymentTermDueDate(i.C_PaymentTerm_ID, i.DateInvoiced) AS DateDue", Timestamp.class, true, true, null); - columnInfo[2] = new ColumnInfo(Msg.translate(ctx, "C_BPartner_ID"), "bp.Name", KeyNamePair.class, true, false, "i.C_BPartner_ID"); - columnInfo[3] = new ColumnInfo(Msg.translate(ctx, "DocumentNo"), "i.DocumentNo", String.class); - columnInfo[4] = new ColumnInfo(Msg.translate(ctx, "C_Currency_ID"), "c.ISO_Code", KeyNamePair.class, true, false, "i.C_Currency_ID"); - columnInfo[5] = new ColumnInfo(Msg.translate(ctx, "GrandTotal"), "i.GrandTotal", BigDecimal.class); - columnInfo[6] = new ColumnInfo(Msg.translate(ctx, "DiscountAmt"), "paymentTermDiscount(i.GrandTotal,i.C_Currency_ID,i.C_PaymentTerm_ID,i.DateInvoiced, ?)", BigDecimal.class); - columnInfo[7] = new ColumnInfo(Msg.getMsg(ctx, "DiscountDate"), "SysDate-paymentTermDueDays(i.C_PaymentTerm_ID,i.DateInvoiced,SysDate)", Timestamp.class); - columnInfo[8] = new ColumnInfo(Msg.getMsg(ctx, "AmountDue"), "currencyConvert(invoiceOpen(i.C_Invoice_ID,i.C_InvoicePaySchedule_ID),i.C_Currency_ID, ?,?,i.C_ConversionType_ID, i.AD_Client_ID,i.AD_Org_ID)", BigDecimal.class); - columnInfo[9] = new ColumnInfo(Msg.getMsg(ctx, "AmountPay"), "currencyConvert(invoiceOpen(i.C_Invoice_ID,i.C_InvoicePaySchedule_ID)-paymentTermDiscount(i.GrandTotal,i.C_Currency_ID,i.C_PaymentTerm_ID,i.DateInvoiced, ?),i.C_Currency_ID, ?,?,i.C_ConversionType_ID, i.AD_Client_ID,i.AD_Org_ID)", BigDecimal.class); - - String fromClause = "C_Invoice_v i" - + " INNER JOIN C_BPartner bp ON (i.C_BPartner_ID=bp.C_BPartner_ID)" - + " INNER JOIN C_Currency c ON (i.C_Currency_ID=c.C_Currency_ID)" - + " INNER JOIN C_PaymentTerm p ON (i.C_PaymentTerm_ID=p.C_PaymentTerm_ID)"; - - String whereClause = "i.IsSOTrx=? AND IsPaid='N'" - + " AND NOT EXISTS (SELECT * FROM C_PaySelectionLine psl" - + " WHERE i.C_Invoice_ID=psl.C_Invoice_ID AND psl.C_PaySelectionCheck_ID IS NOT NULL)" - + " AND i.DocStatus IN ('CO','CL')" - + " AND i.AD_Client_ID=?"; - - boolean multiSelect = true; - - String tableName = "i"; - - // Create MiniTable - - m_sql = dataTable.prepareTable(columnInfo, fromClause, whereClause, multiSelect,tableName); - - dataTable.getModel().addTableModelListener(this); - - //TODO - //fieldPayDate.setMandatory(true); - - m_AD_Client_ID = Env.getAD_Client_ID(Env.getCtx()); - } - - private void populateGrid() - { - prepareGrid(); - - // FROM VPaySelect.loadTableInfo - - if (m_sql == null) - { - return; - } - - String sql = m_sql; - - // Parameters - - Timestamp payDate = (Timestamp)date.getValue(); - dataTable.setColorCompare(payDate); - log.config("PayDate=" + payDate); - - // Bank Account - BankInfo bi = getSelectedBankAccount(); - - String isSOTrx = "N"; - - // Payment Rule - - ListItem selectedRule = lstPaymentRule.getSelectedItem(); - ValueNamePair vp = (ValueNamePair)selectedRule.getValue(); - - if (vp != null && X_C_Order.PAYMENTRULE_DirectDebit.equals(vp.getValue())) - { - isSOTrx = "Y"; - sql += " AND i.PaymentRule='" + X_C_Order.PAYMENTRULE_DirectDebit + "'"; - } - - if (dueInvoices.isChecked()) - { - sql += " AND paymentTermDueDate(i.C_PaymentTerm_ID, i.DateInvoiced) <= ?"; - } - - // Business Partner - - ListItem selectedBPartner = lstBusinessPartner.getSelectedItem(); - KeyNamePair pp = (KeyNamePair)selectedBPartner.getValue(); - - int C_BPartner_ID = pp.getKey(); - - if (C_BPartner_ID != 0) - sql += " AND i.C_BPartner_ID=?"; - - sql += " ORDER BY 2,3"; - - log.finest(sql + " - C_Currecny_ID=" + bi.C_Currency_ID + ", C_BPartner_ID=" + C_BPartner_ID); - - //int m_AD_Client_ID = Env.getAD_Client_ID(Env.getCtx()); - - // Get Open Invoices - - try - { - int columnIndex = 1; - PreparedStatement pstmt = DB.prepareStatement(sql, null); - pstmt.setTimestamp(columnIndex++, payDate); // DiscountAmt - pstmt.setInt(columnIndex++, bi.C_Currency_ID); // DueAmt - pstmt.setTimestamp(columnIndex++, payDate); - pstmt.setTimestamp(columnIndex++, payDate); // PayAmt - pstmt.setInt(columnIndex++, bi.C_Currency_ID); - pstmt.setTimestamp(columnIndex++, payDate); - pstmt.setString(columnIndex++, isSOTrx); // IsSOTrx - pstmt.setInt(columnIndex++, m_AD_Client_ID); // Client - - if (dueInvoices.isChecked()) - { - pstmt.setTimestamp(columnIndex++, payDate); - } - - if (C_BPartner_ID != 0) - { - pstmt.setInt(columnIndex++, C_BPartner_ID); - } - - ResultSet rs = pstmt.executeQuery(); - dataTable.loadTable(rs); - rs.close(); - pstmt.close(); - - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql, e); - } - } - - public void onEvent(Event evt) throws Exception - { - if (evt != null) - { - if (evt.getTarget() == lstBankAccount) - { - populatePaymentRule(); - updateCurrentBalance(); - dataTable.getItems().clear(); - populateGrid(); - } - - if (evt.getTarget() == lstBusinessPartner) - { - dataTable.getItems().clear(); - populateGrid(); - } - - if (evt.getTarget() == lstPaymentRule) - { - dataTable.getItems().clear(); - populateGrid(); - } - - if (evt.getTarget() == dueInvoices) - { - dataTable.getItems().clear(); - populateGrid(); - } - - if (evt.getTarget() == date) - { - dataTable.getItems().clear(); - populateGrid(); - } - - if (evt.getTarget() == refresh) - { - dataTable.clear(); - populateGrid(); - } - - if (evt.getTarget() == btnProcess) - { - if (dataTable.getSelectedCount() <= 0) - { - btnProcess.setEnabled(false); - throw new IllegalArgumentException("No records selected"); - } - - process(); - } - - if (evt.getTarget() instanceof ListItem) - { - btnProcess.setEnabled(true); - - ListItem lstitem = (ListItem)(evt.getTarget()); - - if (lstitem.isSelected()) - { - dataTable.addItemToSelection(lstitem); - } - Integer size = dataTable.getSelectedCount(); - - Float amt = calculateTotalAmount(); - Float remaining = currentBalance - amt; - - lblBottom.setValue(size.toString() + " Selected :: " + amt.toString() + ", Remaining " + remaining.toString()); - } - } - } - - private Float calculateTotalAmount() - { - Float amount = new Float(0); - - for (int i = 0; i < dataTable.getItemCount(); i++) - { - if (dataTable.getItemAtIndex(i).isSelected()) - { - List celllist = (List)(dataTable.getItemAtIndex(i).getChildren()); - Listcell payAmt = celllist.get(9); - amount += new Float(payAmt.getLabel()); - } - } - - return amount; - } - - /* (non-Javadoc) - * @see org.adempiere.webui.event.WTableModelListener#tableChanged(org.adempiere.webui.event.WTableModelEvent) - */ - public void tableChanged(WTableModelEvent event) - { - if (event.getColumn() == 0) - { - calculateSelection(); - } - } - - public class BankInfo - { - /** - * BankInfo - * @param newC_BankAccount_ID - * @param newC_Currency_ID - * @param newName - * @param newCurrency - * @param newBalance - * @param newTransfers - */ - public BankInfo (int newC_BankAccount_ID, int newC_Currency_ID, String newName, String newCurrency, BigDecimal newBalance, boolean newTransfers) - { - C_BankAccount_ID = newC_BankAccount_ID; - C_Currency_ID = newC_Currency_ID; - Name = newName; - Currency = newCurrency; - Balance = newBalance; - } - - int C_BankAccount_ID; - int C_Currency_ID; - String Name; - String Currency; - BigDecimal Balance; - boolean Transfers; - - /** - * to String - * @return info - */ - - public String toString() - { - return Name; - } - } -} +/****************************************************************************** + * 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 * + * Contributors: * + * Colin Rooney (croo) Patch 1605368 Fixed Payment Terms & Only due * + *****************************************************************************/ +package org.adempiere.webui.apps.form; + +import java.math.*; +import java.sql.*; +import java.text.*; +import java.util.Properties; +import java.util.logging.*; + +import org.adempiere.webui.apps.ProcessModalDialog; +import org.adempiere.webui.component.Button; +import org.adempiere.webui.component.Checkbox; +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.Listbox; +import org.adempiere.webui.component.ListboxFactory; +import org.adempiere.webui.component.Panel; +import org.adempiere.webui.component.Row; +import org.adempiere.webui.component.Rows; +import org.adempiere.webui.component.WListbox; +import org.adempiere.webui.editor.WDateEditor; +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.adempiere.webui.window.FDialog; +import org.compiere.apps.ProcessCtl; +import org.compiere.minigrid.ColumnInfo; +import org.compiere.minigrid.IDColumn; +import org.compiere.model.*; +import org.compiere.process.*; +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.SuspendNotAllowedException; +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.North; +import org.zkoss.zkex.zul.South; +import org.zkoss.zul.Separator; +import org.zkoss.zul.Space; + +/** + * Create Manual Payments From (AP) Invoices or (AR) Credit Memos. + * Allows user to select Invoices for payment. + * When Processed, PaySelection is created + * and optionally posted/generated and printed + * + * @author Jorg Janke + * @version $Id: VPaySelect.java,v 1.3 2006/07/30 00:51:28 jjanke Exp $ + */ +public class WPaySelect extends ADForm + implements EventListener, WTableModelListener, ASyncProcess +{ + /** @todo withholding */ + + /** + * Initialize Panel + */ + protected void initForm() + { + try + { + zkInit(); + dynInit(); + southPanel.appendChild(new Separator()); + southPanel.appendChild(commandPanel); + } + catch(Exception e) + { + log.log(Level.SEVERE, "", e); + } + } // init + + /** Format */ + private DecimalFormat m_format = DisplayType.getNumberFormat(DisplayType.Amount); + /** Bank Balance */ + private BigDecimal m_bankBalance = new BigDecimal(0.0); + /** SQL for Query */ + private String m_sql; + /** Number of selected rows */ + private int m_noSelected = 0; + /** Client ID */ + private int m_AD_Client_ID = 0; + /** Payment Selection */ + private MPaySelection m_ps = null; + /** Logger */ + private static CLogger log = CLogger.getCLogger(WPaySelect.class); + + // + private Panel mainPanel = new Panel(); + private Borderlayout mainLayout = new Borderlayout(); + private Panel parameterPanel = new Panel(); + private Label labelBankAccount = new Label(); + private Listbox fieldBankAccount = ListboxFactory.newDropdownListbox(); + private Grid parameterLayout = GridFactory.newGridLayout(); + private Label labelBankBalance = new Label(); + private Label labelCurrency = new Label(); + private Label labelBalance = new Label(); + private Checkbox onlyDue = new Checkbox(); + private Label labelBPartner = new Label(); + private Listbox fieldBPartner = ListboxFactory.newDropdownListbox(); + private Label dataStatus = new Label(); + private WListbox miniTable = ListboxFactory.newDataTable(); + private ConfirmPanel commandPanel = new ConfirmPanel(true, false, false, false, false, false, false); + private Button bCancel = commandPanel.getButton(ConfirmPanel.A_CANCEL); + private Button bGenerate = commandPanel.createButton(ConfirmPanel.A_PROCESS); + private Button bRefresh = commandPanel.createButton(ConfirmPanel.A_REFRESH); + private Label labelPayDate = new Label(); + private WDateEditor fieldPayDate = new WDateEditor(); + private Label labelPaymentRule = new Label(); + private Listbox fieldPaymentRule = ListboxFactory.newDropdownListbox(); + private Panel southPanel; + private ProcessInfo m_pi; + private boolean m_isLock; + + /** + * Static Init + * @throws Exception + */ + private void zkInit() throws Exception + { + // + this.appendChild(mainPanel); + mainPanel.appendChild(mainLayout); + mainPanel.setStyle("width: 100%; height: 100%; padding: 0; margin: 0"); + mainLayout.setHeight("100%"); + mainLayout.setWidth("99%"); + parameterPanel.appendChild(parameterLayout); + // + labelBankAccount.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID")); + fieldBankAccount.addActionListener(this); + labelBPartner.setText(Msg.translate(Env.getCtx(), "C_BPartner_ID")); + fieldBPartner.addActionListener(this); + bRefresh.addActionListener(this); + labelPayDate.setText(Msg.translate(Env.getCtx(), "PayDate")); + labelPaymentRule.setText(Msg.translate(Env.getCtx(), "PaymentRule")); + fieldPaymentRule.addActionListener(this); + // + labelBankBalance.setText(Msg.translate(Env.getCtx(), "CurrentBalance")); + labelBalance.setText("0"); + onlyDue.setText(Msg.getMsg(Env.getCtx(), "OnlyDue")); + dataStatus.setText(" "); + dataStatus.setPre(true); + // + bGenerate.addActionListener(this); + bCancel.addActionListener(this); + // + North north = new North(); + north.setStyle("border: none"); + mainLayout.appendChild(north); + north.appendChild(parameterPanel); + + Rows rows = parameterLayout.newRows(); + Row row = rows.newRow(); + row.appendChild(labelBankAccount.rightAlign()); + row.appendChild(fieldBankAccount); + row.appendChild(labelBankBalance.rightAlign()); + Panel balancePanel = new Panel(); + balancePanel.appendChild(labelCurrency); + balancePanel.appendChild(labelBalance); + row.appendChild(balancePanel); + row.appendChild(new Space()); + + row = rows.newRow(); + row.appendChild(labelBPartner.rightAlign()); + row.appendChild(fieldBPartner); + row.appendChild(new Space()); + row.appendChild(onlyDue); + row.appendChild(new Space()); + + row = rows.newRow(); + row.appendChild(labelPayDate.rightAlign()); + row.appendChild(fieldPayDate.getComponent()); + row.appendChild(labelPaymentRule.rightAlign()); + row.appendChild(fieldPaymentRule); + row.appendChild(bRefresh); + + South south = new South(); + south.setStyle("border: none"); + mainLayout.appendChild(south); + southPanel = new Panel(); + southPanel.appendChild(dataStatus); + south.appendChild(southPanel); + Center center = new Center(); + mainLayout.appendChild(center); + center.appendChild(miniTable); + // + commandPanel.addButton(bGenerate); + } // jbInit + + /** + * Dynamic Init. + * - Load Bank Info + * - Load BPartner + * - Init Table + */ + private void dynInit() + { + Properties ctx = Env.getCtx(); + + // Bank Account Info + String sql = MRole.getDefault().addAccessSQL( + "SELECT ba.C_BankAccount_ID," // 1 + + "b.Name || ' ' || ba.AccountNo AS Name," // 2 + + "ba.C_Currency_ID, c.ISO_Code," // 3..4 + + "ba.CurrentBalance " // 5 + + "FROM C_Bank b, C_BankAccount ba, C_Currency c " + + "WHERE b.C_Bank_ID=ba.C_Bank_ID" + + " AND ba.C_Currency_ID=c.C_Currency_ID " + + " AND EXISTS (SELECT * FROM C_BankAccountDoc d WHERE d.C_BankAccount_ID=ba.C_BankAccount_ID) " + + "ORDER BY 2", + "b", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RW); + try + { + PreparedStatement pstmt = DB.prepareStatement(sql, null); + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) + { + boolean transfers = false; + BankInfo bi = new BankInfo (rs.getInt(1), rs.getInt(3), + rs.getString(2), rs.getString(4), + rs.getBigDecimal(5), transfers); + fieldBankAccount.appendItem(bi.toString(), bi); + } + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql, e); + } + if (fieldBankAccount.getItemCount() == 0) + FDialog.error(m_WindowNo, this, "VPaySelectNoBank"); + else + fieldBankAccount.setSelectedIndex(0); + loadBankInfo(); + + // Optional BusinessPartner with unpaid AP Invoices + KeyNamePair pp = new KeyNamePair(0, ""); + fieldBPartner.addItem(pp); + sql = MRole.getDefault().addAccessSQL( + "SELECT bp.C_BPartner_ID, bp.Name FROM C_BPartner bp", "bp", + MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO) + + " AND EXISTS (SELECT * FROM C_Invoice i WHERE bp.C_BPartner_ID=i.C_BPartner_ID" + // X_C_Order.PAYMENTRULE_DirectDebit + + " AND (i.IsSOTrx='N' OR (i.IsSOTrx='Y' AND i.PaymentRule='D'))" + + " AND i.IsPaid<>'Y') " + + "ORDER BY 2"; + + try + { + PreparedStatement pstmt = DB.prepareStatement(sql, null); + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) + { + pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); + fieldBPartner.addItem(pp); + } + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql, e); + } + fieldBPartner.setSelectedIndex(0); + + /** prepare MiniTable + * + SELECT i.C_Invoice_ID, i.DateInvoiced+p.NetDays AS DateDue, + bp.Name, i.DocumentNo, c.ISO_Code, i.GrandTotal, + paymentTermDiscount(i.GrandTotal, i.C_PaymentTerm_ID, i.DateInvoiced, SysDate) AS Discount, + SysDate-paymentTermDueDays(i.C_PaymentTerm_ID,i.DateInvoiced) AS DiscountDate, + i.GrandTotal-paymentTermDiscount(i.GrandTotal,i.C_PaymentTerm_ID,i.DateInvoiced,SysDate) AS DueAmount, + currencyConvert(i.GrandTotal-paymentTermDiscount(i.GrandTotal,i.C_PaymentTerm_ID,i.DateInvoiced,SysDate,null), + i.C_Currency_ID,xx100,SysDate) AS PayAmt + FROM C_Invoice i, C_BPartner bp, C_Currency c, C_PaymentTerm p + WHERE i.IsSOTrx='N' + AND i.C_BPartner_ID=bp.C_BPartner_ID + AND i.C_Currency_ID=c.C_Currency_ID + AND i.C_PaymentTerm_ID=p.C_PaymentTerm_ID + AND i.DocStatus IN ('CO','CL') + ORDER BY 2,3 + */ + + m_sql = miniTable.prepareTable(new ColumnInfo[] { + // 0..4 + new ColumnInfo(" ", "i.C_Invoice_ID", IDColumn.class, false, false, null), + new ColumnInfo(Msg.translate(ctx, "DueDate"), "paymentTermDueDate(i.C_PaymentTerm_ID, i.DateInvoiced) AS DateDue", Timestamp.class, true, true, null), + new ColumnInfo(Msg.translate(ctx, "C_BPartner_ID"), "bp.Name", KeyNamePair.class, true, false, "i.C_BPartner_ID"), + new ColumnInfo(Msg.translate(ctx, "DocumentNo"), "i.DocumentNo", String.class), + new ColumnInfo(Msg.translate(ctx, "C_Currency_ID"), "c.ISO_Code", KeyNamePair.class, true, false, "i.C_Currency_ID"), + // 5..9 + new ColumnInfo(Msg.translate(ctx, "GrandTotal"), "i.GrandTotal", BigDecimal.class), + new ColumnInfo(Msg.translate(ctx, "DiscountAmt"), "paymentTermDiscount(i.GrandTotal,i.C_Currency_ID,i.C_PaymentTerm_ID,i.DateInvoiced, ?)", BigDecimal.class), + new ColumnInfo(Msg.getMsg(ctx, "DiscountDate"), "SysDate-paymentTermDueDays(i.C_PaymentTerm_ID,i.DateInvoiced,SysDate)", Timestamp.class), + new ColumnInfo(Msg.getMsg(ctx, "AmountDue"), "currencyConvert(invoiceOpen(i.C_Invoice_ID,i.C_InvoicePaySchedule_ID),i.C_Currency_ID, ?,?,i.C_ConversionType_ID, i.AD_Client_ID,i.AD_Org_ID)", BigDecimal.class), + new ColumnInfo(Msg.getMsg(ctx, "AmountPay"), "currencyConvert(invoiceOpen(i.C_Invoice_ID,i.C_InvoicePaySchedule_ID)-paymentTermDiscount(i.GrandTotal,i.C_Currency_ID,i.C_PaymentTerm_ID,i.DateInvoiced, ?),i.C_Currency_ID, ?,?,i.C_ConversionType_ID, i.AD_Client_ID,i.AD_Org_ID)", BigDecimal.class) + }, + // FROM + "C_Invoice_v i" + + " INNER JOIN C_BPartner bp ON (i.C_BPartner_ID=bp.C_BPartner_ID)" + + " INNER JOIN C_Currency c ON (i.C_Currency_ID=c.C_Currency_ID)" + + " INNER JOIN C_PaymentTerm p ON (i.C_PaymentTerm_ID=p.C_PaymentTerm_ID)", + // WHERE + "i.IsSOTrx=? AND IsPaid='N'" + // Different Payment Selection + + " AND NOT EXISTS (SELECT * FROM C_PaySelectionLine psl" + + " WHERE i.C_Invoice_ID=psl.C_Invoice_ID AND psl.C_PaySelectionCheck_ID IS NOT NULL)" + + " AND i.DocStatus IN ('CO','CL')" + + " AND i.AD_Client_ID=?", // additional where & order in loadTableInfo() + true, "i"); + // + miniTable.getModel().addTableModelListener(this); + // + fieldPayDate.setMandatory(true); + fieldPayDate.setValue(new Timestamp(System.currentTimeMillis())); + // + m_AD_Client_ID = Env.getAD_Client_ID(Env.getCtx()); + } // dynInit + + /** + * Load Bank Info - Load Info from Bank Account and valid Documents (PaymentRule) + */ + private void loadBankInfo() + { + BankInfo bi = (BankInfo)fieldBankAccount.getSelectedItem().getValue(); + if (bi == null) + return; + labelCurrency.setText(bi.Currency); + labelBalance.setText(m_format.format(bi.Balance)); + m_bankBalance = bi.Balance; + + // PaymentRule + fieldPaymentRule.removeAllItems(); + int AD_Reference_ID = 195; // MLookupInfo.getAD_Reference_ID("All_Payment Rule"); + Language language = Env.getLanguage(Env.getCtx()); + MLookupInfo info = MLookupFactory.getLookup_List(language, AD_Reference_ID); + String sql = info.Query.substring(0, info.Query.indexOf(" ORDER BY")) + + " AND " + info.KeyColumn + + " IN (SELECT PaymentRule FROM C_BankAccountDoc WHERE C_BankAccount_ID=?) " + + info.Query.substring(info.Query.indexOf(" ORDER BY")); + try + { + PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt.setInt(1, bi.C_BankAccount_ID); + ResultSet rs = pstmt.executeQuery(); + ValueNamePair vp = null; + while (rs.next()) + { + vp = new ValueNamePair(rs.getString(2), rs.getString(3)); // returns also not active + fieldPaymentRule.addItem(vp); + } + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql, e); + } + fieldPaymentRule.setSelectedIndex(0); + + } // loadBankInfo + + /** + * Query and create TableInfo + */ + private void loadTableInfo() + { + log.config(""); + // not yet initialized + if (m_sql == null) + return; + + String sql = m_sql; + // Parameters + Timestamp payDate = (Timestamp)fieldPayDate.getValue(); + miniTable.setColorCompare(payDate); + log.config("PayDate=" + payDate); + BankInfo bi = (BankInfo)fieldBankAccount.getSelectedItem().getValue(); + // + String isSOTrx = "N"; + ValueNamePair vp = (ValueNamePair)fieldPaymentRule.getSelectedItem().toValueNamePair(); + if (vp != null && X_C_Order.PAYMENTRULE_DirectDebit.equals(vp.getValue())) + { + isSOTrx = "Y"; + sql += " AND i.PaymentRule='" + X_C_Order.PAYMENTRULE_DirectDebit + "'"; + } + // + if (onlyDue.isSelected()) + sql += " AND paymentTermDueDate(i.C_PaymentTerm_ID, i.DateInvoiced) <= ?"; + // + KeyNamePair pp = (KeyNamePair)fieldBPartner.getSelectedItem().toKeyNamePair(); + int C_BPartner_ID = pp.getKey(); + if (C_BPartner_ID != 0) + sql += " AND i.C_BPartner_ID=?"; + sql += " ORDER BY 2,3"; + // + log.finest(sql + " - C_Currecny_ID=" + bi.C_Currency_ID + ", C_BPartner_ID=" + C_BPartner_ID); + + // Get Open Invoices + try + { + int index = 1; + PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt.setTimestamp(index++, payDate); // DiscountAmt + pstmt.setInt(index++, bi.C_Currency_ID); // DueAmt + pstmt.setTimestamp(index++, payDate); + pstmt.setTimestamp(index++, payDate); // PayAmt + pstmt.setInt(index++, bi.C_Currency_ID); + pstmt.setTimestamp(index++, payDate); + pstmt.setString(index++, isSOTrx); // IsSOTrx + pstmt.setInt(index++, m_AD_Client_ID); // Client + if (onlyDue.isSelected()) + pstmt.setTimestamp(index++, payDate); + if (C_BPartner_ID != 0) + pstmt.setInt(index++, C_BPartner_ID); + // + ResultSet rs = pstmt.executeQuery(); + miniTable.loadTable(rs); + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql, e); + } + calculateSelection(); + } // loadTableInfo + + /** + * Dispose + */ + public void dispose() + { + SessionManager.getAppDesktop().removeWindow(); + } // dispose + + + /************************************************************************** + * ActionListener + * @param e event + */ + public void onEvent (Event e) + { + // Update Bank Info + if (e.getTarget() == fieldBankAccount) + loadBankInfo(); + + // Generate PaySelection + else if (e.getTarget() == bGenerate) + { + generatePaySelect(); + } + + else if (e.getTarget() == bCancel) + dispose(); + + // Update Open Invoices + else if (e.getTarget() == fieldBPartner || e.getTarget() == bRefresh) + loadTableInfo(); + + } // actionPerformed + + /** + * Table Model Listener + * @param e event + */ + public void tableChanged(WTableModelEvent e) + { + if (e.getColumn() == 0) + calculateSelection(); + } // valueChanged + + /** + * Calculate selected rows. + * - add up selected rows + */ + public void calculateSelection() + { + m_noSelected = 0; + BigDecimal invoiceAmt = new BigDecimal(0.0); + + int rows = miniTable.getRowCount(); + for (int i = 0; i < rows; i++) + { + IDColumn id = (IDColumn)miniTable.getModel().getValueAt(i, 0); + if (id.isSelected()) + { + BigDecimal amt = (BigDecimal)miniTable.getModel().getValueAt(i, 9); + if (amt != null) + invoiceAmt = invoiceAmt.add(amt); + m_noSelected++; + } + } + + // Information + BigDecimal remaining = m_bankBalance.subtract(invoiceAmt); + StringBuffer info = new StringBuffer(); + info.append(m_noSelected).append(" ").append(Msg.getMsg(Env.getCtx(), "Selected")).append(" - "); + info.append(m_format.format(invoiceAmt)).append(", "); + info.append(Msg.getMsg(Env.getCtx(), "Remaining")).append(" ").append(m_format.format(remaining)); + dataStatus.setText(info.toString()); + // + bGenerate.setEnabled(m_noSelected != 0); + } // calculateSelection + + /** + * Generate PaySelection + */ + private void generatePaySelect() + { + log.info(""); + // String trxName Trx.createTrxName("PaySelect"); + // Trx trx = Trx.get(trxName, true); trx needs to be committed too + String trxName = null; + Trx trx = null; + // + if (miniTable.getRowCount() == 0) + return; + miniTable.setSelectedIndices(new int[]{0}); + calculateSelection(); + if (m_noSelected == 0) + return; + + String PaymentRule = ((ValueNamePair)fieldPaymentRule.getSelectedItem().toValueNamePair()).getValue(); + + // Create Header + m_ps = new MPaySelection(Env.getCtx(), 0, trxName); + m_ps.setName (Msg.getMsg(Env.getCtx(), "VPaySelect") + + " - " + ((ValueNamePair)fieldPaymentRule.getSelectedItem().toValueNamePair()).getName() + + " - " + fieldPayDate.getValue()); + m_ps.setPayDate (new Timestamp(fieldPayDate.getComponent().getValue().getTime())); + BankInfo bi = (BankInfo)fieldBankAccount.getSelectedItem().getValue(); + m_ps.setC_BankAccount_ID(bi.C_BankAccount_ID); + m_ps.setIsApproved(true); + if (!m_ps.save()) + { + FDialog.error(m_WindowNo, this, "SaveError", Msg.translate(Env.getCtx(), "C_PaySelection_ID")); + m_ps = null; + return; + } + log.config(m_ps.toString()); + + // Create Lines + int rows = miniTable.getRowCount(); + int line = 0; + for (int i = 0; i < rows; i++) + { + IDColumn id = (IDColumn)miniTable.getModel().getValueAt(i, 0); + if (id.isSelected()) + { + line += 10; + MPaySelectionLine psl = new MPaySelectionLine (m_ps, line, PaymentRule); + int C_Invoice_ID = id.getRecord_ID().intValue(); + BigDecimal OpenAmt = (BigDecimal)miniTable.getModel().getValueAt(i, 8); + BigDecimal PayAmt = (BigDecimal)miniTable.getModel().getValueAt(i, 9); + boolean isSOTrx = false; + // + psl.setInvoice(C_Invoice_ID, isSOTrx, + OpenAmt, PayAmt, OpenAmt.subtract(PayAmt)); + if (!psl.save(trxName)) + { + FDialog.error(m_WindowNo, this, "SaveError", Msg.translate(Env.getCtx(), "C_PaySelectionLine_ID")); + return; + } + log.fine("C_Invoice_ID=" + C_Invoice_ID + ", PayAmt=" + PayAmt); + } + } // for all rows in table + + + // Ask to Post it + if (!FDialog.ask(m_WindowNo, this, "VPaySelectGenerate?", "(" + m_ps.getName() + ")")) + return; + + // Prepare Process + int AD_Proces_ID = 155; // C_PaySelection_CreatePayment + + // Execute Process + ProcessModalDialog dialog = new ProcessModalDialog(null, getFormName(), this, m_WindowNo, + AD_Proces_ID, X_C_PaySelection.Table_ID, m_ps.getC_PaySelection_ID(), false); + if (dialog.isValid()) { + try { + dialog.setWidth("500px"); + dialog.setVisible(true); + dialog.setPage(this.getPage()); + dialog.doModal(); + } catch (SuspendNotAllowedException e) { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + } catch (InterruptedException e) { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + } + } + } // generatePaySelect + + /** + * Lock User Interface + * Called from the Worker before processing + */ + public void lockUI (ProcessInfo pi) + { + if (m_isLock) return; + m_isLock = true; + Clients.showBusy(null, true); + } // lockUI + + /** + * Unlock User Interface. + * Called from the Worker when processing is done + */ + public void unlockUI (ProcessInfo pi) + { + if (!m_isLock) return; + m_isLock = false; + m_pi = pi; + Clients.showBusy(null, false); + Clients.response(new AuEcho(this, "onAfterProcess", null)); + } // unlockUI + + public void onAfterProcess() + { + if (!FDialog.ask(0, this, "VPaySelectPrint?", "(" + m_pi.getSummary() + ")")) + { + dispose(); + return; + } + + this.dispose(); + + // Start PayPrint + int AD_Form_ID = 106; // Payment Print/Export + ADForm form = SessionManager.getAppDesktop().openForm(AD_Form_ID); + if (m_ps != null) + { + WPayPrint pp = (WPayPrint)form; + pp.setPaySelection(m_ps.getC_PaySelection_ID()); + } + } + + /************************************************************************** + * Bank Account Info + */ + public class BankInfo + { + /** + * BankInfo + * @param newC_BankAccount_ID + * @param newC_Currency_ID + * @param newName + * @param newCurrency + * @param newBalance + * @param newTransfers + */ + public BankInfo (int newC_BankAccount_ID, int newC_Currency_ID, + String newName, String newCurrency, BigDecimal newBalance, boolean newTransfers) + { + C_BankAccount_ID = newC_BankAccount_ID; + C_Currency_ID = newC_Currency_ID; + Name = newName; + Currency = newCurrency; + Balance = newBalance; + } + int C_BankAccount_ID; + int C_Currency_ID; + String Name; + String Currency; + BigDecimal Balance; + boolean Transfers; + + /** + * to String + * @return info + */ + public String toString() + { + return Name; + } + } // BankInfo + + public void executeASync(ProcessInfo pi) { + } + + public boolean isUILocked() { + return m_isLock; + } + +} // VPaySelect diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WPayment.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WPayment.java index 21350478f5..7aeea2dab4 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WPayment.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WPayment.java @@ -101,7 +101,7 @@ public class WPayment extends Window m_mTab = mTab; try { - bDateField = new WDateEditor("DateAcct", false, false, true, DisplayType.Date, "DateAcct"); + bDateField = new WDateEditor("DateAcct", false, false, true, "DateAcct"); zkInit(); m_initOK = dynInit(button); // Null Pointer if order/invoice not saved yet } 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 328a85189f..28c3102f04 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 @@ -184,8 +184,8 @@ public class WTrxMaterial extends ADForm 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")); + dateFField = new WDateEditor("DateFrom", false, false, true, Msg.getMsg(Env.getCtx(), "DateFrom")); + dateTField = new WDateEditor("DateTo", false, false, true, Msg.getMsg(Env.getCtx(), "DateTo")); // confirmPanel.addActionListener(this); statusBar.setStatusLine(""); diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WPerformanceDetail.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WPerformanceDetail.java index 4c615a5280..f0828615ed 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WPerformanceDetail.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WPerformanceDetail.java @@ -28,6 +28,7 @@ public class WPerformanceDetail extends Window WBarGraph barPanel = new WBarGraph(goal); appendChild(barPanel); - SessionManager.getAppDesktop().showWindowInTabPanel(this); + this.setAttribute(Window.MODE_KEY, Window.MODE_EMBEDDED); + SessionManager.getAppDesktop().showWindow(this); } // PerformanceDetail } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/NumberBox.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/NumberBox.java index 6ce1719493..85032552cb 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/NumberBox.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/NumberBox.java @@ -17,12 +17,14 @@ package org.adempiere.webui.component; +import java.math.BigDecimal; import java.text.NumberFormat; import java.text.ParseException; -import org.zkoss.zul.Bandpopup; -import org.zkoss.zul.Button; +import org.adempiere.webui.apps.AEnv; +import org.zkoss.zul.Decimalbox; import org.zkoss.zul.Hbox; +import org.zkoss.zul.Popup; import org.zkoss.zul.Vbox; /** @@ -31,7 +33,7 @@ import org.zkoss.zul.Vbox; * @date Mar 11, 2007 * @version $Revision: 0.10 $ */ -public class NumberBox extends Bandbox +public class NumberBox extends Panel { private static final long serialVersionUID = 1L; @@ -41,6 +43,9 @@ public class NumberBox extends Bandbox NumberFormat format = null; + private Decimalbox decimalBox = null; + private Button btn; + public NumberBox(boolean integral) { super(); @@ -50,10 +55,25 @@ public class NumberBox extends Bandbox private void init() { - this.setImage("/images/Calculator16.png"); + decimalBox = new Decimalbox(); + if (integral) + decimalBox.setScale(0); + + btn = new Button(); + btn.setImage("/images/Calculator16.png"); this.setAction("onKeyPress : return calc.validate('" + - this.getId() + "'," + integral + ", event);"); - this.appendChild(getBandPopup()); + decimalBox.getId() + "'," + integral + ", event);"); + + Popup popup = getCalculatorPopup(); + btn.setHeight("22px"); + btn.setWidth("26px"); + btn.setPopup(popup); + appendChild(decimalBox); + appendChild(btn); + appendChild(popup); + + String style = AEnv.isFirefox2() ? "display: inline" : "display: inline-block"; + this.setStyle(style); } public void setFormat(NumberFormat format) @@ -61,70 +81,64 @@ public class NumberBox extends Bandbox this.format = format; } - public void setValue(Number value) + public void setValue(Object value) { - if (format != null) - { - super.setValue(format.format(value)); - } + if (value == null) + decimalBox.setValue(null); + else if (value instanceof BigDecimal) + decimalBox.setValue((BigDecimal) value); + else if (value instanceof Number) + decimalBox.setValue(new BigDecimal(((Number)value).doubleValue())); else - { - super.setValue(value.toString()); - } + decimalBox.setValue(new BigDecimal(value.toString())); } - public void setRawValue(Object value) + public BigDecimal getValue() { - super.setRawValue(value); + return decimalBox.getValue(); } public String getText() { - return super.getText(); + BigDecimal value = decimalBox.getValue(); + if (value == null) return null; + + if (format != null) + return format.format(value); + else + return value.toPlainString(); } public void setValue(String value) { - String formattedValue = ""; Number numberValue = null; if (format != null) { try { - numberValue = format.parse(value); - formattedValue = format.format(numberValue); + numberValue = format.parse(value); + setValue(numberValue); } catch (ParseException e) { - formattedValue = value; } } else { - formattedValue = value; - } - - super.setValue(formattedValue); + decimalBox.setValue(new BigDecimal(value)); + } } - /* - public void setReadonly(boolean readonly) + private Popup getCalculatorPopup() { - // Due to bug in bandbox - once set readonly, setting to not readonly - // does not work - super.setDisabled(readonly); - }*/ - - private Bandpopup getBandPopup() - { - Bandpopup bandPopup = new Bandpopup(); + Popup popup = new Popup(); Vbox vbox = new Vbox(); txtCalc = new Textbox(); txtCalc.setAction("onKeyPress : return calc.validate('" + - this.getId() + "!real','" + txtCalc.getId() + decimalBox.getId() + "','" + txtCalc.getId() + "'," + integral + ", event);"); txtCalc.setMaxlength(250); txtCalc.setCols(30); @@ -252,7 +266,7 @@ public class NumberBox extends Bandbox Button btnEqual = new Button(); btnEqual.setWidth("30px"); btnEqual.setLabel("="); - btnEqual.setAction("onClick : calc.evaluate('" + this.getId() + "!real','" + btnEqual.setAction("onClick : calc.evaluate('" + decimalBox.getId() + "','" + txtCalcId + "')"); Button btnAdd = new Button(); @@ -271,7 +285,30 @@ public class NumberBox extends Bandbox vbox.appendChild(row3); vbox.appendChild(row4); - bandPopup.appendChild(vbox); - return bandPopup; + popup.appendChild(vbox); + return popup; } + + public boolean isIntegral() { + return integral; + } + + public void setIntegral(boolean integral) { + this.integral = integral; + if (integral) + decimalBox.setScale(0); + else + decimalBox.setScale(Decimalbox.AUTO); + } + + public void setEnabled(boolean enabled) + { + decimalBox.setReadonly(!enabled); + btn.setEnabled(enabled); + } + + public boolean isEnabled() + { + return decimalBox.isReadonly(); + } } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/WListItemRenderer.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/WListItemRenderer.java index 90489e4fcd..69f327de69 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/WListItemRenderer.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/WListItemRenderer.java @@ -287,8 +287,7 @@ public class WListItemRenderer implements ListitemRenderer, EventListener, Listi numberbox.setFormat(format); numberbox.setValue((BigDecimal)field); numberbox.setWidth("100px"); - numberbox.setButtonVisible(true); - numberbox.setReadonly(false); + numberbox.setEnabled(true); numberbox.setStyle("text-align:right; " + listcell.getStyle()); numberbox.addEventListener(Events.ON_CHANGE, this); @@ -578,7 +577,7 @@ public class WListItemRenderer implements ListitemRenderer, EventListener, Listi } else if (source instanceof NumberBox) { - value = new BigDecimal(((NumberBox)source).getValue()); + value = ((NumberBox)source).getValue(); } if(value != null) diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/Window.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/Window.java index 2ee0856d9c..4e4656cc11 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/Window.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/Window.java @@ -35,6 +35,10 @@ public class Window extends org.zkoss.zul.Window public static final String MODE_EMBEDDED = "embedded"; + public static final String MODE_HIGHLIGHTED = "highlighted"; + + public static final String MODE_KEY = "mode"; + public Window() { super(); diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WDateEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WDateEditor.java index 8d93db38f4..fd72002fbb 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WDateEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WDateEditor.java @@ -46,6 +46,10 @@ public class WDateEditor extends WEditor private Timestamp oldValue = new Timestamp(0); + /** + * + * @param gridField + */ public WDateEditor(GridField gridField) { super(new Datebox(), gridField); @@ -76,23 +80,21 @@ public class WDateEditor extends WEditor { this("Date", "Date", false, false, true); } // VDate - + /** * * @param columnName * @param mandatory * @param readonly * @param updateable - * @param displayType - * @param label + * @param title */ - public WDateEditor(String columnName, boolean mandatory, boolean readonly, boolean updateable, - int displayType, String label) { - //TODO: support for displayType - super(new Datebox(), columnName, label, null, mandatory, readonly, updateable); + public WDateEditor(String columnName, boolean mandatory, boolean readonly, boolean updateable, + String title) + { + super(new Datebox(), columnName, title, null, mandatory, readonly, updateable); } - - + public void onEvent(Event event) { Date date = getComponent().getValue(); diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WNumberEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WNumberEditor.java index fa5a43ec8e..67eb657f70 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WNumberEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WNumberEditor.java @@ -43,7 +43,7 @@ public class WNumberEditor extends WEditor public static final int MAX_DISPLAY_LENGTH = 20; - private String oldValue; + private BigDecimal oldValue; private boolean mandatory = false; @@ -95,11 +95,8 @@ public class WNumberEditor extends WEditor { if (gridField != null) { - getComponent().setMaxlength(gridField.getFieldLength()); getComponent().setTooltiptext(gridField.getDescription()); - } - - getComponent().setCols(MAX_DISPLAY_LENGTH); + } } /** @@ -108,14 +105,8 @@ public class WNumberEditor extends WEditor */ public void onEvent(Event event) { - String newValue = getComponent().getValue(); - BigDecimal oldNumber = null; - if (oldValue != null && oldValue.trim().length() > 0) - oldNumber = new BigDecimal(oldValue); - BigDecimal newNumber = null; - if (newValue != null && newValue.trim().length() > 0) - newNumber = new BigDecimal(newValue); - ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldNumber, newNumber); + BigDecimal newValue = getComponent().getValue(); + ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue); super.fireValueChange(changeEvent); oldValue = newValue; } @@ -138,7 +129,7 @@ public class WNumberEditor extends WEditor @Override public String getDisplay() { - return getComponent().getValue(); + return getComponent().getText(); } @Override @@ -162,14 +153,7 @@ public class WNumberEditor extends WEditor @Override public void setValue(Object value) { - if (value != null) - { - getComponent().setValue(value.toString()); - } - else - { - getComponent().setValue("0"); - } + getComponent().setValue(value); } @Override diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WTableDirEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WTableDirEditor.java index 9196991ed5..1647c25250 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WTableDirEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WTableDirEditor.java @@ -331,7 +331,7 @@ ContextMenuListener, IZoomableEditor @Override public void dynamicDisplay() { - if (isReadWrite() && (!lookup.isValidated() || !lookup.isLoaded())) + if (isReadWrite() && (lookup != null) && (!lookup.isValidated() || !lookup.isLoaded())) this.actionRefresh(); } } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WTimeEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WTimeEditor.java new file mode 100644 index 0000000000..a9cd98be4e --- /dev/null +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WTimeEditor.java @@ -0,0 +1,174 @@ +/****************************************************************************** + * Copyright (C) 2008 Low Heng Sin * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ + +package org.adempiere.webui.editor; + +import java.sql.Timestamp; +import java.util.Date; +import java.util.logging.Level; + +import org.adempiere.webui.event.ValueChangeEvent; +import org.compiere.model.GridField; +import org.compiere.util.CLogger; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.Events; +import org.zkoss.zul.Timebox; + +/** + * + * @author Low Heng Sin + */ +public class WTimeEditor extends WEditor +{ + private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE}; + private static final CLogger logger; + + static + { + logger = CLogger.getCLogger(WDateEditor.class); + } + + private Timestamp oldValue = new Timestamp(0); + + /** + * + * @param gridField + */ + public WTimeEditor(GridField gridField) + { + super(new Timebox(), gridField); + } + + /** + * + * @param columnName + * @param mandatory + * @param readonly + * @param updateable + * @param title + */ + public WTimeEditor(String columnName, boolean mandatory, boolean readonly, boolean updateable, + String title) + { + super(new Timebox(), columnName, title, null, mandatory, readonly, updateable); + } + + /** + * Constructor for use if a grid field is unavailable + * + * @param label + * column name (not displayed) + * @param description + * description of component + * @param mandatory + * whether a selection must be made + * @param readonly + * whether or not the editor is read only + * @param updateable + * whether the editor contents can be changed + */ + public WTimeEditor (String label, String description, boolean mandatory, boolean readonly, boolean updateable) + { + super(new Timebox(), label, description, mandatory, readonly, updateable); + setColumnName("Time"); + } + + public WTimeEditor() + { + this("Time", "Time", false, false, true); + } // VDate + + public void onEvent(Event event) + { + Date date = getComponent().getValue(); + Timestamp newValue = null; + + if (date != null) + { + newValue = new Timestamp(date.getTime()); + } + + ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue); + super.fireValueChange(changeEvent); + oldValue = newValue; + } + + @Override + public String getDisplay() + { + // Elaine 2008/07/29 + return getComponent().getText(); + // + } + + @Override + public Object getValue() + { + // Elaine 2008/07/25 + if(getComponent().getValue() == null) return null; + return new Timestamp(getComponent().getValue().getTime()); + // + } + + @Override + public boolean isMandatory() + { + return false; + } + + @Override + public void setMandatory(boolean mandatory) + { + } + + @Override + public void setValue(Object value) + { + if (value == null) + { + oldValue = null; + getComponent().setValue(null); + } + else if (value instanceof Timestamp) + { + getComponent().setValue((Timestamp)value); + oldValue = (Timestamp)value; + } + else + { + logger.log(Level.SEVERE, "New field value is not of type timestamp"); + } + } + + @Override + public Timebox getComponent() { + return (Timebox) component; + } + + @Override + public boolean isReadWrite() { + return !getComponent().isReadonly(); + } + + + @Override + public void setReadWrite(boolean readWrite) { + getComponent().setReadonly(!readWrite); + } + + public String[] getEvents() + { + return LISTENER_EVENTS; + } + +} diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WebEditorFactory.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WebEditorFactory.java index 43e702bfde..5c250a504d 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WebEditorFactory.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WebEditorFactory.java @@ -105,7 +105,10 @@ public class WebEditorFactory /** Date */ else if (DisplayType.isDate(displayType)) { - editor = new WDateEditor(gridField); + if (displayType == DisplayType.Time) + editor = new WTimeEditor(gridField); + else + editor = new WDateEditor(gridField); } /** Button */ diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/panel/AbstractADWindowPanel.java b/zkwebui/WEB-INF/src/org/adempiere/webui/panel/AbstractADWindowPanel.java index 5eb9e123c4..40ad83c4b9 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/panel/AbstractADWindowPanel.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/panel/AbstractADWindowPanel.java @@ -952,11 +952,10 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To if (dialog.isValid()) { dialog.setPosition("center"); try { + dialog.setPage(this.getComponent().getPage()); dialog.doModal(); } catch (InterruptedException e) { - - e.printStackTrace(); } } } @@ -1337,31 +1336,24 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To if (m_uiLocked) return; m_uiLocked = true; - boolean notPrint = pi != null - && pi.getAD_Process_ID() != curTab.getAD_Process_ID() - && pi.isReportingProcess() == false; - // - // Process Result - if (notPrint) // refresh if not print + + if (Executions.getCurrent() != null) + Clients.showBusy(null, true); + else { - if (Executions.getCurrent() != null) - Clients.showBusy("Processing...", true); - else - { - try { - //get full control of desktop - Executions.activate(getComponent().getDesktop()); - try { - Clients.showBusy("Processing...", true); - } catch(Error ex){ - throw ex; - } finally{ - //release full control of desktop - Executions.deactivate(getComponent().getDesktop()); - } - } catch (Exception e) { - logger.log(Level.WARNING, "Failed to lock UI.", e); - } + try { + //get full control of desktop + Executions.activate(getComponent().getDesktop()); + try { + Clients.showBusy(null, true); + } catch(Error ex){ + throw ex; + } finally{ + //release full control of desktop + Executions.deactivate(getComponent().getDesktop()); + } + } catch (Exception e) { + logger.log(Level.WARNING, "Failed to lock UI.", e); } } } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/session/SessionContextListener.java b/zkwebui/WEB-INF/src/org/adempiere/webui/session/SessionContextListener.java index 574f60f93b..3ca56c299d 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/session/SessionContextListener.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/session/SessionContextListener.java @@ -63,7 +63,7 @@ public class SessionContextListener implements ExecutionInit, if (parent == null) { exec.removeAttribute(SESSION_CTX); - ServerContext.dispose(); +// ServerContext.dispose(); } } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/window/WAssignmentDialog.java b/zkwebui/WEB-INF/src/org/adempiere/webui/window/WAssignmentDialog.java index 19263f45a4..ff8fa82e13 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/window/WAssignmentDialog.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/window/WAssignmentDialog.java @@ -239,7 +239,7 @@ public class WAssignmentDialog extends Window implements EventListener confirmPanel.getButton("Cancel").setVisible(readWrite); fResource.setEnabled(readWrite); fDateFrom.setReadonly(!readWrite); - fQty.setReadonly(!readWrite); + fQty.setEnabled(readWrite); m_setting = false; } // dynInit @@ -265,7 +265,7 @@ public class WAssignmentDialog extends Window implements EventListener Calendar date = new GregorianCalendar(); getDateAndTimeFrom(date); Timestamp assignDateFrom = new Timestamp(date.getTimeInMillis()); - BigDecimal qty = new BigDecimal(fQty.getValue()); + BigDecimal qty = fQty.getValue(); KeyNamePair uom = (KeyNamePair)m_lookup.get(fResource.getSelectedItem()); int minutes = MUOMConversion.convertToMinutes(Env.getCtx(), uom.getKey(), qty); Timestamp assignDateTo = TimeUtil.addMinutess(assignDateFrom, minutes); @@ -339,8 +339,8 @@ public class WAssignmentDialog extends Window implements EventListener Timestamp assignDateFrom = new Timestamp(date.getTimeInMillis()); if (assignDateFrom != null) m_mAssignment.setAssignDateFrom (assignDateFrom); - if (fQty.getValue() != null && fQty.getValue().trim().length() > 0) { - BigDecimal qty = new BigDecimal(fQty.getValue()); + if (fQty.getValue() != null) { + BigDecimal qty = fQty.getValue(); m_mAssignment.setQty(qty); } m_mAssignment.setName((String)fName.getValue()); diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/window/WPAttributeDialog.java b/zkwebui/WEB-INF/src/org/adempiere/webui/window/WPAttributeDialog.java index 23a42acd15..15b8968087 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/window/WPAttributeDialog.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/window/WPAttributeDialog.java @@ -486,7 +486,7 @@ public class WPAttributeDialog extends Window implements EventListener editor.setValue(Env.ZERO); row.appendChild(editor); if (readOnly) - editor.setReadonly(true); + editor.setEnabled(false); else m_editors.add (editor); } @@ -773,7 +773,7 @@ public class WPAttributeDialog extends Window implements EventListener else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributes[i].getAttributeValueType())) { NumberBox editor = (NumberBox)m_editors.get(i); - BigDecimal value = new BigDecimal(editor.getValue()); + BigDecimal value = editor.getValue(); log.fine(attributes[i].getName() + "=" + value); if (attributes[i].isMandatory() && value == null) mandatory += " - " + attributes[i].getName(); diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/window/ZkReportViewerProvider.java b/zkwebui/WEB-INF/src/org/adempiere/webui/window/ZkReportViewerProvider.java index 55f7cf0356..249195dbe2 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/window/ZkReportViewerProvider.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/window/ZkReportViewerProvider.java @@ -34,7 +34,7 @@ public class ZkReportViewerProvider implements ReportViewerProvider { viewer.setClosable(true); viewer.setWidth("95%"); - SessionManager.getAppDesktop().showWindowInTabPanel(viewer); -// AEnv.showWindow(viewer); + viewer.setAttribute(Window.MODE_KEY, Window.MODE_EMBEDDED); + SessionManager.getAppDesktop().showWindow(viewer); } } \ No newline at end of file