use of org.compiere.print.ReportEngine in project adempiere by adempiere.
the class MWFActivity method performWork.
// run
/**
* Perform Work.
* Set Text Msg.
* @param trx transaction
* @return true if completed, false otherwise
* @throws Exception if error
*/
private boolean performWork(Trx trx) throws Exception {
log.info(m_node + " [" + trx.getTrxName() + "]");
m_docStatus = null;
if (// overwrite priority if defined
m_node.getPriority() != 0)
setPriority(m_node.getPriority());
String action = m_node.getAction();
/****** Sleep (Start/End) ******/
if (MWFNode.ACTION_WaitSleep.equals(action)) {
log.fine("Sleep:WaitTime=" + m_node.getWaitTime());
if (m_node.getWaitingTime() == 0)
// done
return true;
Calendar cal = Calendar.getInstance();
cal.add(m_node.getDurationCalendarField(), m_node.getWaitTime());
setEndWaitTime(new Timestamp(cal.getTimeInMillis()));
// not done
return false;
} else /****** Document Action ******/
if (MWFNode.ACTION_DocumentAction.equals(action)) {
log.fine("DocumentAction=" + m_node.getDocAction());
getPO(trx);
if (m_po == null)
throw new Exception("Persistent Object not found - AD_Table_ID=" + getAD_Table_ID() + ", Record_ID=" + getRecord_ID());
boolean success = false;
String processMsg = null;
DocAction doc = null;
if (m_po instanceof DocAction) {
doc = (DocAction) m_po;
//
try {
// ** Do the work
success = doc.processIt(m_node.getDocAction());
setTextMsg(doc.getSummary());
processMsg = doc.getProcessMsg();
// the rest of methods return boolean, so doc status must not be taken into account when not successful
if (DocAction.ACTION_Prepare.equals(m_node.getDocAction()) || DocAction.ACTION_Complete.equals(m_node.getDocAction()) || success)
m_docStatus = doc.getDocStatus();
} catch (Exception e) {
if (m_process != null)
m_process.setProcessMsg(e.getLocalizedMessage());
throw e;
}
if (m_process != null)
m_process.setProcessMsg(processMsg);
} else
throw new IllegalStateException("Persistent Object not DocAction - " + m_po.getClass().getName() + " - AD_Table_ID=" + getAD_Table_ID() + ", Record_ID=" + getRecord_ID());
//
if (!m_po.save()) {
success = false;
processMsg = "SaveError";
}
if (!success) {
if (processMsg == null || processMsg.length() == 0) {
processMsg = "PerformWork Error - " + m_node.toStringX();
if (// problem: status will be rolled back
doc != null)
processMsg += " - DocStatus=" + doc.getDocStatus();
}
throw new Exception(processMsg);
}
return success;
} else /****** Report ******/
if (MWFNode.ACTION_AppsReport.equals(action)) {
log.fine("Report:AD_Process_ID=" + m_node.getAD_Process_ID());
// Process
MProcess process = MProcess.get(getCtx(), m_node.getAD_Process_ID());
process.set_TrxName(trx != null ? trx.getTrxName() : null);
if (!process.isReport() || process.getAD_ReportView_ID() == 0)
throw new IllegalStateException("Not a Report AD_Process_ID=" + m_node.getAD_Process_ID());
//
ProcessInfo pi = new ProcessInfo(m_node.getName(true), m_node.getAD_Process_ID(), getAD_Table_ID(), getRecord_ID());
pi.setAD_User_ID(getAD_User_ID());
pi.setAD_Client_ID(getAD_Client_ID());
MPInstance pInstance = new MPInstance(process, getRecord_ID());
pInstance.set_TrxName(trx != null ? trx.getTrxName() : null);
fillParameter(pInstance, trx);
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
// Report
ReportEngine re = ReportEngine.get(getCtx(), pi);
if (re == null)
throw new IllegalStateException("Cannot create Report AD_Process_ID=" + m_node.getAD_Process_ID());
File report = re.getPDF();
// Notice
// HARDCODED WorkflowResult
int AD_Message_ID = 753;
MNote note = new MNote(getCtx(), AD_Message_ID, getAD_User_ID(), trx.getTrxName());
note.setTextMsg(m_node.getName(true));
note.setDescription(m_node.getDescription(true));
note.setRecord(getAD_Table_ID(), getRecord_ID());
note.saveEx();
// Attachment
MAttachment attachment = new MAttachment(getCtx(), MNote.Table_ID, note.getAD_Note_ID(), get_TrxName());
attachment.addEntry(report);
attachment.setTextMsg(m_node.getName(true));
attachment.saveEx();
return true;
} else /****** Process ******/
if (MWFNode.ACTION_AppsProcess.equals(action)) {
log.fine("Process:AD_Process_ID=" + m_node.getAD_Process_ID());
// Process
MProcess process = MProcess.get(getCtx(), m_node.getAD_Process_ID());
MPInstance pInstance = new MPInstance(process, getRecord_ID());
fillParameter(pInstance, trx);
//
ProcessInfo pi = new ProcessInfo(m_node.getName(true), m_node.getAD_Process_ID(), getAD_Table_ID(), getRecord_ID());
pi.setAD_User_ID(getAD_User_ID());
pi.setAD_Client_ID(getAD_Client_ID());
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
return process.processItWithoutTrxClose(pi, trx);
} else /****** EMail ******/
if (MWFNode.ACTION_EMail.equals(action)) {
log.fine("EMail:EMailRecipient=" + m_node.getEMailRecipient());
getPO(trx);
if (m_po == null)
throw new Exception("Persistent Object not found - AD_Table_ID=" + getAD_Table_ID() + ", Record_ID=" + getRecord_ID());
if (m_po instanceof DocAction) {
m_emails = new ArrayList<String>();
sendEMail();
setTextMsg(m_emails.toString());
} else {
MClient client = MClient.get(getCtx(), getAD_Client_ID());
MMailText mailtext = new MMailText(getCtx(), getNode().getR_MailText_ID(), null);
String subject = getNode().getDescription() + ": " + mailtext.getMailHeader();
String message = mailtext.getMailText(true) + "\n-----\n" + getNodeHelp();
String to = getNode().getEMail();
client.sendEMail(to, subject, message, null);
}
// done
return true;
} else /****** Set Variable ******/
if (MWFNode.ACTION_SetVariable.equals(action)) {
String value = m_node.getAttributeValue();
log.fine("SetVariable:AD_Column_ID=" + m_node.getAD_Column_ID() + " to " + value);
MColumn column = m_node.getColumn();
int dt = column.getAD_Reference_ID();
return setVariable(value, dt, null, trx);
} else /****** TODO Start WF Instance ******/
if (MWFNode.ACTION_SubWorkflow.equals(action)) {
log.warning("Workflow:AD_Workflow_ID=" + m_node.getAD_Workflow_ID());
log.warning("Start WF Instance is not implemented yet");
} else /****** User Choice ******/
if (MWFNode.ACTION_UserChoice.equals(action)) {
log.fine("UserChoice:AD_Column_ID=" + m_node.getAD_Column_ID());
// Approval
if (m_node.isUserApproval() && getPO(trx) instanceof DocAction) {
DocAction doc = (DocAction) m_po;
boolean autoApproval = false;
// Approval Hierarchy
if (isInvoker()) {
// Set Approver
int startAD_User_ID = Env.getAD_User_ID(getCtx());
if (startAD_User_ID == 0)
startAD_User_ID = doc.getDoc_User_ID();
int nextAD_User_ID = getApprovalUser(startAD_User_ID, doc.getC_Currency_ID(), doc.getApprovalAmt(), doc.getAD_Org_ID(), // own doc
startAD_User_ID == doc.getDoc_User_ID());
// same user = approved
autoApproval = startAD_User_ID == nextAD_User_ID;
if (!autoApproval)
setAD_User_ID(nextAD_User_ID);
} else // fixed Approver
{
MWFResponsible resp = getResponsible();
// [ 1742751 ] Workflow: User Choice is not working
if (resp.isHuman()) {
autoApproval = resp.getAD_User_ID() == Env.getAD_User_ID(getCtx());
if (!autoApproval && resp.getAD_User_ID() != 0)
setAD_User_ID(resp.getAD_User_ID());
} else if (resp.isRole()) {
MUserRoles[] urs = MUserRoles.getOfRole(getCtx(), resp.getAD_Role_ID());
for (int i = 0; i < urs.length; i++) {
if (urs[i].getAD_User_ID() == Env.getAD_User_ID(getCtx())) {
autoApproval = true;
break;
}
}
} else if (resp.isOrganization()) {
throw new AdempiereException("Support not implemented for " + resp);
} else {
throw new AdempiereException("@NotSupported@ " + resp);
}
// end MZ
}
if (autoApproval && doc.processIt(DocAction.ACTION_Approve) && doc.save())
// done
return true;
}
// wait for user
return false;
} else /****** User Form ******/
if (MWFNode.ACTION_UserForm.equals(action)) {
log.fine("Form:AD_Form_ID=" + m_node.getAD_Form_ID());
return false;
} else if (MWFNode.ACTION_SmartBrowse.equals(action)) {
log.fine("Form:AD_Browse_ID=" + m_node.getAD_Browse_ID());
return false;
} else /****** User Window ******/
if (MWFNode.ACTION_UserWindow.equals(action)) {
log.fine("Window:AD_Window_ID=" + m_node.getAD_Window_ID());
return false;
}
//
throw new IllegalArgumentException("Invalid Action (Not Implemented) =" + action);
}
use of org.compiere.print.ReportEngine in project adempiere by adempiere.
the class WCollect method printTicketWeb.
/**
* Print Ticket for Web
* @return void
*/
public void printTicketWeb() {
try {
if (posPanel.isToPrint() && posPanel.hasOrder()) {
ReportCtl.startDocumentPrint(0, posPanel.getC_Order_ID(), false);
ReportEngine m_reportEngine = ReportEngine.get(p_ctx, ReportEngine.ORDER, posPanel.getC_Order_ID());
StringWriter sw = new StringWriter();
m_reportEngine.createCSV(sw, '\t', m_reportEngine.getPrintFormat().getLanguage());
byte[] data = sw.getBuffer().toString().getBytes();
AMedia media = new AMedia(m_reportEngine.getPrintFormat().getName() + ".txt", null, "application/octet-stream", data);
posPanel.printFile(media.getByteData(), posPanel.getC_Order_ID());
}
} catch (Exception e) {
log.severe("PrintTicket - Error Printing Ticket");
}
}
use of org.compiere.print.ReportEngine in project adempiere by adempiere.
the class VGenPanel method generateComplete.
/**
* Complete generating shipments/invoices.
* Called from Unlock UI
* @param pi process info
*/
public void generateComplete(ProcessInfo pi) {
// Switch Tabs
tabbedPane.setSelectedIndex(1);
//
ProcessInfoUtil.setLogFromDB(pi);
StringBuffer iText = new StringBuffer();
iText.append("<b>").append(pi.getSummary()).append("</b><br>(").append(Msg.getMsg(Env.getCtx(), genForm.getTitle())).append(")<br>").append(pi.getLogInfo(true));
info.setText(iText.toString());
// Reset Selection
/*
String sql = "UPDATE C_Order SET IsSelected='N' WHERE " + m_whereClause;
int no = DB.executeUpdate(sql, null);
log.config("Reset=" + no);*/
// Get results
int[] ids = pi.getIDs();
if (ids == null || ids.length == 0)
return;
log.config("PrintItems=" + ids.length);
confirmPanelGen.getOKButton().setEnabled(false);
// OK to print
if (ADialog.ask(m_WindowNo, this, genForm.getAskPrintMsg())) {
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// see also ProcessDialog.printShipments/Invoices
int retValue = ADialogDialog.A_CANCEL;
do {
// Loop through all items
for (int i = 0; i < ids.length; i++) {
int Record_ID = ids[i];
if (genForm.getPrintFormat() != null) {
MPrintFormat format = genForm.getPrintFormat();
MTable table = MTable.get(Env.getCtx(), format.getAD_Table_ID());
MQuery query = new MQuery(table.getTableName());
query.addRestriction(table.getTableName() + "_ID", MQuery.EQUAL, Record_ID);
// Engine
PrintInfo info = new PrintInfo(table.getTableName(), table.get_Table_ID(), Record_ID);
ReportEngine re = new ReportEngine(Env.getCtx(), format, query, info);
re.print();
new Viewer(m_frame.getGraphicsConfiguration(), re);
} else
ReportCtl.startDocumentPrint(genForm.getReportEngineType(), Record_ID, this, Env.getWindowNo(this), true);
}
// Yamel Senih 2015-11-23 FR [ 114 ] Add Supoort to dynamic create from
ADialogDialog d = new ADialogDialog(m_frame.getCFrame(), Env.getHeader(Env.getCtx(), m_WindowNo), Msg.getMsg(Env.getCtx(), "PrintoutOK?"), JOptionPane.QUESTION_MESSAGE);
// End Yamel Senih
retValue = d.getReturnCode();
} while (retValue == ADialogDialog.A_CANCEL);
this.setCursor(Cursor.getDefaultCursor());
}
// OK to print
//
confirmPanelGen.getOKButton().setEnabled(true);
}
use of org.compiere.print.ReportEngine in project adempiere by adempiere.
the class WProcess method createProcessPage.
// createParameterPage
//Modified by Rob klein 4/29/07
/**************************************************************************
* Create Parocess Page
* @param request request
* @param AD_Process_ID Process
* @return Page
*/
public void createProcessPage(HttpServletRequest request, HttpServletResponse response, int AD_Process_ID, int AD_Window_ID) {
MobileSessionCtx wsc = MobileSessionCtx.get(request);
MProcess process = MProcess.get(wsc.ctx, AD_Process_ID);
log.info("PI table id " + process.get_Table_ID());
log.info("PI table name id " + process.get_TableName());
log.info("PI table client id " + process.getAD_Client_ID());
log.info("PI table process id " + process.getAD_Process_ID());
log.info("PI process class name " + process.getClassname());
// need to check if Role can access
MobileDoc doc = null;
if (process == null) {
doc = MobileDoc.createWindow("Process Not Found");
} else {
doc = MobileDoc.createWindow(process.getName());
fieldset center = new fieldset();
doc.getBody().addElement(center);
if (process.getDescription() != null)
center.addElement(new p(new i(process.getDescription())));
if (process.getHelp() != null)
center.addElement(new p(process.getHelp(), AlignType.LEFT));
// Create Process Instance
MPInstance pInstance = fillParameter(request, process);
//
int AD_Table_ID = MobileUtil.getParameterAsInt(request, "AD_Table_ID");
int AD_Record_ID = MobileUtil.getParameterAsInt(request, "AD_Record_ID");
ProcessInfo pi = new ProcessInfo(process.getName(), process.getAD_Process_ID(), AD_Table_ID, AD_Record_ID);
pi.setAD_User_ID(Env.getAD_User_ID(wsc.ctx));
pi.setAD_Client_ID(Env.getAD_Client_ID(wsc.ctx));
pi.setClassName(process.getClassname());
log.info("PI client id " + pi.getAD_Client_ID());
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
// Info
p p = new p();
p.addElement(Msg.translate(wsc.ctx, "AD_PInstance_ID") + ": " + pInstance.getAD_PInstance_ID());
center.addElement(p);
// Start
boolean processOK = false;
if (process.isWorkflow()) {
Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
try {
WProcessCtl.process(this, AD_Window_ID, pi, trx, request);
//processOK = process.processIt(pi, trx);
trx.commit();
trx.close();
} catch (Throwable t) {
trx.rollback();
trx.close();
}
if (pi.isError()) {
center.addElement(new p("Error:" + pi.getSummary(), AlignType.LEFT).setClass("Cerror"));
processOK = false;
} else {
center.addElement(new p("OK: Workflow Started", AlignType.LEFT));
processOK = true;
}
center.addElement(new p().addElement(pi.getSummary()));
center.addElement(pi.getLogInfo(true));
}
String jasper = process.getJasperReport();
if (process.isJavaProcess()) {
if (jasper != null) {
pi.setPrintPreview(false);
pi.setIsBatch(true);
}
Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
try {
processOK = process.processIt(pi, trx);
trx.commit();
trx.close();
} catch (Throwable t) {
trx.rollback();
trx.close();
}
if (!processOK || pi.isError()) {
center.addElement(new p("Error:" + pi.getSummary(), AlignType.LEFT).setClass("Cerror"));
processOK = false;
} else {
if (jasper != null) {
String error = MobileUtil.streamFile(response, pi.getPDFReport());
//String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file);
if (error == null)
return;
doc = MobileDoc.create(error);
wsc.ctx.put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
} else {
center.addElement(new p().addElement(pi.getSummary()));
center.addElement(pi.getLogInfo(true));
}
}
}
// Report
if (process.isReport()) //if (processOK && process.isReport())
{
if (jasper == null) {
log.info(response.toString());
ReportEngine re = ReportEngine.get(wsc.ctx, pi);
if (re == null) {
center.addElement(new p("Could not start ReportEngine", AlignType.LEFT).setClass("Cerror"));
} else {
try {
File file = File.createTempFile("WProcess", ".pdf");
boolean ok = re.createPDF(file);
if (ok) {
String error = MobileUtil.streamFile(response, file);
//String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file);
if (error == null)
return;
doc = MobileDoc.create(error);
//Modified by Rob Klein 6/1/07
/**
String url = "WProcess?AD_PInstance_ID="
+ pInstance.getAD_PInstance_ID()
+ "&File="
+ URLEncoder.encode(file.getAbsolutePath(), WebEnv.ENCODING);
a link = new a (url, null, a.TARGET_BLANK, process.getName());
center
.addElement(new p()
.addElement("Report created: ")
.addElement(link));
// Marker that Process is OK
* */
wsc.ctx.put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
} else
center.addElement(new p("Could not create Report", AlignType.LEFT).setClass("Cerror"));
} catch (Exception e) {
center.addElement(new p("Could not create Report:", AlignType.LEFT).setClass("Cerror"));
center.addElement(e.toString());
}
}
}
}
}
try {
MobileUtil.createResponse(request, response, this, null, doc, false);
} catch (IOException e) {
log.info(e.toString());
}
}
use of org.compiere.print.ReportEngine in project adempiere by adempiere.
the class CompletePrintOrder method doIt.
// prepare
/**
* Perform process.
*
* @return Message (clear text)
* @throws Exception
* if not successful
*/
protected String doIt() throws Exception {
if (p_PP_Order_ID == 0) {
throw new FillMandatoryException(MPPOrder.COLUMNNAME_PP_Order_ID);
}
if (p_IsComplete) {
MPPOrder order = new MPPOrder(getCtx(), p_PP_Order_ID, get_TrxName());
if (!order.isAvailable()) {
throw new AdempiereException("@NoQtyAvailable@");
}
//
// Process document
boolean ok = order.processIt(MPPOrder.DOCACTION_Complete);
order.saveEx();
if (!ok) {
throw new AdempiereException(order.getProcessMsg());
}
// Document Status should be completed
if (!MPPOrder.DOCSTATUS_Completed.equals(order.getDocStatus())) {
throw new AdempiereException(order.getProcessMsg());
}
}
if (p_IsPrintPickList) {
// Get Format & Data
ReportEngine re = this.getReportEngine("Manufacturing_Order_BOM_Header ** TEMPLATE **", "PP_Order_BOM_Header_v");
if (re == null) {
return "";
}
ReportCtl.preview(re);
// prints only original
re.print();
}
if (p_IsPrintPackList) {
// Get Format & Data
ReportEngine re = this.getReportEngine("Manufacturing_Order_BOM_Header_Packing ** TEMPLATE **", "PP_Order_BOM_Header_v");
if (re == null) {
return "";
}
ReportCtl.preview(re);
// prints only original
re.print();
}
if (p_IsPrintWorkflow) {
// Get Format & Data
ReportEngine re = this.getReportEngine("Manufacturing_Order_Workflow_Header ** TEMPLATE **", "PP_Order_Workflow_Header_v");
if (re == null) {
return "";
}
ReportCtl.preview(re);
// prints only original
re.print();
}
return "@OK@";
}
Aggregations