IDEMPIERE-5356 - Add Printing Support to ProcessInfoDialog (#1412)

* IDEMPIERE-5356 - Add Printing Support to ProcessInfoDialog
This commit is contained in:
Peter Takács 2022-08-02 11:10:52 +02:00 committed by GitHub
parent 11962e1713
commit 5931f6ce8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 97 additions and 3 deletions

View File

@ -104,10 +104,12 @@ public class SystemIDs
public final static int PROCESS_RPT_C_PROJECT = 217; public final static int PROCESS_RPT_C_PROJECT = 217;
public final static int PROCESS_RPT_C_RFQRESPONSE = 276; public final static int PROCESS_RPT_C_RFQRESPONSE = 276;
public final static int PROCESS_RPT_C_DUNNING = 159; public final static int PROCESS_RPT_C_DUNNING = 159;
public final static int PROCESS_RPT_DD_ORDER = 53044;
public final static int PROCESS_RPT_FINREPORT = 202; public final static int PROCESS_RPT_FINREPORT = 202;
public final static int PROCESS_RPT_FINSTATEMENT = 204; public final static int PROCESS_RPT_FINSTATEMENT = 204;
public final static int PROCESS_RPT_M_INVENTORY = 291; public final static int PROCESS_RPT_M_INVENTORY = 291;
public final static int PROCESS_RPT_M_MOVEMENT = 290; public final static int PROCESS_RPT_M_MOVEMENT = 290;
public final static int PROCESS_RPT_PP_ORDER = 53028;
public final static int REFERENCE_DATATYPE_ACCOUNT = 25; public final static int REFERENCE_DATATYPE_ACCOUNT = 25;
public final static int REFERENCE_DATATYPE_AMOUNT = 12; public final static int REFERENCE_DATATYPE_AMOUNT = 12;

View File

@ -2401,7 +2401,21 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
public void setIsReplaceTabContent(boolean m_isReplaceTabContent) { public void setIsReplaceTabContent(boolean m_isReplaceTabContent) {
this.m_isReplaceTabContent = m_isReplaceTabContent; this.m_isReplaceTabContent = m_isReplaceTabContent;
} }
/**
* Get Report Engine Type from Table_ID
* @param tableID
* @return Report Engine Type
* -1 if Report Engine Type was not found
*/
public static int getReportEngineType(int tableID) {
for(int i = 0; i < DOC_TABLE_ID.length; i++) {
if(DOC_TABLE_ID[i] == tableID)
return i;
}
return -1;
}
/** /**
* build css for table from mapCssInfo * build css for table from mapCssInfo
* @param doc * @param doc

View File

@ -14,16 +14,25 @@
package org.adempiere.webui.component; package org.adempiere.webui.component;
import java.io.File;
import java.io.FileInputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import org.adempiere.webui.ISupportMask; import org.adempiere.webui.ISupportMask;
import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.LayoutUtils;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.event.DialogEvents; import org.adempiere.webui.event.DialogEvents;
import org.adempiere.webui.factory.ButtonFactory; import org.adempiere.webui.factory.ButtonFactory;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.util.ZKUpdateUtil; import org.adempiere.webui.util.ZKUpdateUtil;
import org.adempiere.webui.window.SimplePDFViewer;
import org.compiere.print.ReportEngine;
import org.compiere.process.ProcessInfo; import org.compiere.process.ProcessInfo;
import org.compiere.process.ProcessInfoLog; import org.compiere.process.ProcessInfoLog;
import org.compiere.process.ProcessInfoUtil; import org.compiere.process.ProcessInfoUtil;
import org.compiere.tools.FileUtil;
import org.compiere.util.DisplayType; import org.compiere.util.DisplayType;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Msg; import org.compiere.util.Msg;
@ -33,6 +42,7 @@ import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Hbox; import org.zkoss.zul.Hbox;
import org.zkoss.zul.Image; import org.zkoss.zul.Image;
import org.zkoss.zul.Separator; import org.zkoss.zul.Separator;
@ -50,10 +60,13 @@ public class ProcessInfoDialog extends Window implements EventListener<Event> {
private static final long serialVersionUID = -1712025652050086903L; private static final long serialVersionUID = -1712025652050086903L;
private static final String MESSAGE_PANEL_STYLE = "text-align:left; word-break: break-all; overflow: auto; max-height: 250pt; min-width: 230pt; max-width: 450pt;"; private static final String MESSAGE_PANEL_STYLE = "text-align:left; word-break: break-all; overflow: auto; max-height: 250pt; min-width: 230pt; max-width: 450pt;";
private Text lblMsg = new Text(); private Text lblMsg = new Text();
private Button btnOk = ButtonFactory.createNamedButton(ConfirmPanel.A_OK); private Button btnOk = ButtonFactory.createNamedButton(ConfirmPanel.A_OK);
private Button btnPrint = ButtonFactory.createNamedButton(ConfirmPanel.A_PRINT);
private Image img = new Image(); private Image img = new Image();
private ProcessInfoLog[] m_logs;
public static final String INFORMATION = "~./zul/img/msgbox/info-btn.png"; public static final String INFORMATION = "~./zul/img/msgbox/info-btn.png";
public static final String ERROR = "~./zul/img/msgbox/info-btn.png"; public static final String ERROR = "~./zul/img/msgbox/info-btn.png";
@ -113,6 +126,7 @@ public class ProcessInfoDialog extends Window implements EventListener<Event> {
lblMsg.setValue(header); lblMsg.setValue(header);
btnOk.addEventListener(Events.ON_CLICK, this); btnOk.addEventListener(Events.ON_CLICK, this);
btnPrint.addEventListener(Events.ON_CLICK, this);
Panel pnlMessage = new Panel(); Panel pnlMessage = new Panel();
pnlMessage.setStyle(MESSAGE_PANEL_STYLE); pnlMessage.setStyle(MESSAGE_PANEL_STYLE);
@ -142,6 +156,8 @@ public class ProcessInfoDialog extends Window implements EventListener<Event> {
ZKUpdateUtil.setHeight(pnlButtons, "52px"); ZKUpdateUtil.setHeight(pnlButtons, "52px");
pnlButtons.setAlign("center"); pnlButtons.setAlign("center");
pnlButtons.setPack("end"); pnlButtons.setPack("end");
btnPrint.setVisible(false);
pnlButtons.appendChild(btnPrint);
pnlButtons.appendChild(btnOk); pnlButtons.appendChild(btnOk);
Separator separator = new Separator(); Separator separator = new Separator();
@ -166,7 +182,12 @@ public class ProcessInfoDialog extends Window implements EventListener<Event> {
pnlMessage.appendChild(new Text(summary)); pnlMessage.appendChild(new Text(summary));
} }
} }
this.m_logs = m_logs;
if(isPrintable())
btnPrint.setVisible(true);
if (m_logs != null && m_logs.length > 0){ if (m_logs != null && m_logs.length > 0){
separator = new Separator(); separator = new Separator();
ZKUpdateUtil.setWidth(separator, "100%"); ZKUpdateUtil.setWidth(separator, "100%");
@ -216,6 +237,63 @@ public class ProcessInfoDialog extends Window implements EventListener<Event> {
if (event.getTarget() == btnOk) { if (event.getTarget() == btnOk) {
this.detach(); this.detach();
} }
if(event.getTarget() == btnPrint) {
Clients.showBusy(Msg.getMsg(Env.getCtx(), "Processing"));
Executions.schedule(this.getDesktop(), e -> onPrint(), new Event("onPrint"));
}
}
/**
* On Print
*/
private void onPrint() {
Clients.clearBusy();
// Loop through all items
List<File> pdfList = new ArrayList<File>();
for (int i = 0; i < m_logs.length; i++)
{
int recordID = m_logs[i].getRecord_ID();
int reportEngineType = ReportEngine.getReportEngineType(m_logs[i].getAD_Table_ID());
ReportEngine re = null;
if((reportEngineType >= 0) && (recordID > 0)) {
re = ReportEngine.get (Env.getCtx(), reportEngineType, recordID);
pdfList.add(re.getPDF());
}
}
if (pdfList.size() > 1) {
try {
File outFile = FileUtil.createTempFile(getTitle(), ".pdf");
AEnv.mergePdf(pdfList, outFile);
Window win = new SimplePDFViewer(getTitle(), new FileInputStream(outFile));
SessionManager.getAppDesktop().showWindow(win, "center");
} catch (Exception e) {
throw new RuntimeException(e.getLocalizedMessage(), e);
}
} else if (pdfList.size() > 0) {
try {
Window win = new SimplePDFViewer(getTitle(), new FileInputStream(pdfList.get(0)));
SessionManager.getAppDesktop().showWindow(win, "center");
} catch (Exception e)
{
throw new RuntimeException(e.getLocalizedMessage(), e);
}
}
this.detach();
}
/**
* Is Printable
* @return boolean
*/
public boolean isPrintable() {
for(ProcessInfoLog log : m_logs) {
if (ReportEngine.getReportEngineType(log.getAD_Table_ID()) >= 0)
return true;
}
return false;
} }
@Override @Override