View source | Discuss this page | Page history | Printable version   
Toolbox
Main Page
Upload file
What links here
Recent changes
Help

PDF Books
Show collection (0 pages)
Collections help

Search

ERP 2.50:Developers Guide/Code Snippets/Window and Tab

ERP 2.50:Developers Guide

Index

Warning.png   This document is still a work in progress. It may contain inaccuracies or errors.

Print Button

Create a process:

HEADER
Id: RptC_Tiquet
Name: RptC_Tiquet
Data access: Entity/Organization
Report checkbox: Checked

(Image IiP.png)

PROCESS CLASS
Action: Process
Default value checkbox: Checked
Java class name: org.openbravo.erpReports.RptC_Tiquet

(Image PC.png)

PROCESS MAPPING
Mapping name: /RptC_Tiquet
Default value checkbox: Checked

(Image PM.png)


Use as a model the following code in java.

package org.openbravo.erpReports;
import org.openbravo.erpCommon.utility.*;
import org.openbravo.erpCommon.businessUtility.Tree;
import org.openbravo.erpCommon.businessUtility.TreeData;
import org.openbravo.erpCommon.businessUtility.WindowTabs;
import org.openbravo.base.secureApp.HttpSecureAppServlet;
import org.openbravo.base.secureApp.VariablesSecureApp;
import org.openbravo.xmlEngine.XmlDocument;
import java.io.*;
import java.util.HashMap;
import java.util.Date;
import java.text.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.openbravo.utils.Replace;
import org.openbravo.erpCommon.ad_combos.OrganizationComboData;
import org.openbravo.erpCommon.utility.DateTimeData;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.design.JasperDesign;
import java.sql.Connection;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.export.JRHtmlExporter;
import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;
 
public class RptC_Tiquet extends HttpSecureAppServlet {  
 public void init (ServletConfig config) {
   super.init(config);
   boolHist = false;
 }
 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
   VariablesSecureApp vars = new VariablesSecureApp(request);
   if (vars.commandIn("DEFAULT")) {
     String strcOrderId = vars.getSessionValue("RptC_Tiquet.inpcOrderId_R");
     strcOrderId = vars.getStringParameter("inpcOrderId");
     if (strcOrderId.equals("")) strcOrderId = vars.getSessionValue("RptC_Tiquet.inpcOrderId");
     if (log4j.isDebugEnabled()) log4j.debug("strcOrderId: "+ strcOrderId);
     printPagePartePDF(response, vars, strcOrderId);
   } else pageError(response);
 }
  void printPagePartePDF(HttpServletResponse response, VariablesSecureApp vars, String strcOrderId) throws IOException,ServletException{
   if (log4j.isDebugEnabled()) log4j.debug("Output: RptC_TiquetJR - pdf");
   JasperPrint jasperPrint;    
   String strReportName = "@basedesign@/org/openbravo/erpReports/C_TiquetJR.jrxml";
   response.setHeader("Content-disposition", "inline; filename=SalesOrderJR.pdf");
 
   strcOrderId=strcOrderId.replace("(", "");
   strcOrderId=strcOrderId.replace(")", "");
   strcOrderId=strcOrderId.replace("\'", "");
 
   HashMap<String, Object> parameters = new HashMap<String, Object>();
   parameters.put("'''C_ORDER_ID'''", strcOrderId);    
   renderJR(vars, response, strReportName, "pdf", parameters, null, null );    
 }
 public String getServletInfo() {
   return "Servlet that presents the RptCOrders seeker";
 } // End of getServletInfo() method}


Copy it into /home/openbravo/OpenbravoERP/AppsOpenbravo/src/org/openbravo/erpReports


In your .jrxml file you get the parameter C_ORDER_ID from the .java writing your SQL so:

SELECT DOCUMENTNO FROM C_ORDER_ID WHERE C_ORDER_ID=$P{C_ORDER_ID}

Copy your jasper template (.jrxml file) into /home/openbravo/OpenbravoERP/AppsOpenbravo/src/org/openbravo/erpReports

Then compile the changes using:

ant compile.development -Dtab=xxx


Now, you should change the current process that the print button from (i.e.) Sales Order windows executes. Go to Windows, Tab and Fields. Then look for the windows Sales Order and in the Header tab, locate the Process field. Change the value for your newly created RptC_Tiquet.

Then, compile the windows

ant compile.development -Dtab="Sales Order"

If you want to see your changes, restart apache-tomcat.


Display Role in Menu

To display the rolename currently selected by the logged in user next to the username in the leftside menu, update the following two files:

<SqlMethod name="getRoleName" type="preparedStatement" return="String" default="">
 <SqlMethodComment></SqlMethodComment>
  <Sql>
    SELECT NAME
    FROM AD_ROLE
    WHERE AD_Role_ID = ?
  </Sql>
  <Parameter name="adRoleId"/>
</SqlMethod>
xmlDocument.setParameter("userName", MenuData.getUserName(this, vars.getUser()) + " (" + MenuData.getRoleName(this, vars.getRole()) + ")");

Then, compile the manual code from the commandline, positioned inside the OpenbravoERP/AppsOpenbravo:

ant compile.development -Dtab=XXX


Enjoy!

Adding a Callout

Modifying a Callout to show a Message to the user, for clients checked as debtors, always that they try to buy NOT in cash (in certain windows with periodical payments).


  1. Create a new column in the C_BPARTNER table called isdebtor as char. Don't forget to Synchronize. Add this field to the windows Partner.
  2. Create a new message in the AD called isdebtor, with the alert wanted to show to the user.
  3. Add the next Sqlmethod to the file SE_Order_BPartner_data.xsql located under ~/OpenbravoERP/AppsOpenbravo/src/org/openbravo/erpCommon/ad_callouts/ if you are using Linux. This method gets if the partner was checked as debtor.
<!-- Method to get if a partner has been marked as a debtor -->
  <SqlMethod name="'''partnerDebtor'''" type="preparedStatement" return="String" default="">
  <SqlMethodComment></SqlMethodComment>
    <Sql>
     <![CDATA[
      select '''isdebtor'''
      from c_bpartner
      where c_bpartner_id = ?
     ]]>
    </Sql>
    <Parameter name="cBpartnerId"/>
    <Field name="isdebtor" value=""/>
  </SqlMethod>

4.- At the end of SE_Order_BPartner.java file located in the same directory, add the following java code. Pay attention to the if-condition to see if it fulfil your requirements.

...
    //Modified BEGINS
    //Get if the partner was checked as debtor
    String debtor = SEOrderBPartnerData.'''partnerDebtor'''(this, strBPartner);
    char[] is_debtor = debtor.toCharArray();
 
    //Get windows_id
    int intWindowId = Integer.parseInt(strWindowId);
 
    //If Partner is Debtor and Windows isn't "Cash windows" and Windows isn't Ticket Windows  
    if('''is_debtor[0]=='Y' && intWindowId!=100001 && intWindowId!=100003''')
    {
       resultado.append(", new Array('MESSAGE', \"" + Utility.messageBD(this, "'''isdebtor'''", vars.getLanguage()) + "\")");
    }
    //Modified END
 
    resultado.append(");");
    xmlDocument.setParameter("array", resultado.toString());
    xmlDocument.setParameter("frameName", "frameAplicacion");
    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();
    out.println(xmlDocument.print());
    out.close();
    ...

5.- Compile



ERP 2.50:Developers Guide/Code Snippets/Report | ERP 2.50:Developers Guide/Code Snippets/Process

Retrieved from "http://wiki.openbravo.com/wiki/ERP_2.50:Developers_Guide/Code_Snippets/Window_and_Tab"

This page has been accessed 3,605 times. This page was last modified on 14 June 2011, at 11:03. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.