1 19 package org.openbravo.erpCommon.ad_actionButton; 20 21 import org.openbravo.erpCommon.utility.SequenceIdData; 22 import org.openbravo.erpCommon.utility.*; 23 import org.openbravo.utils.FormatUtilities; 24 import org.openbravo.utils.Replace; 25 import org.openbravo.base.secureApp.HttpSecureAppServlet; 26 import org.openbravo.base.secureApp.VariablesSecureApp; 27 import org.openbravo.xmlEngine.XmlDocument; 28 import org.openbravo.exception.*; 29 import java.io.*; 30 import javax.servlet.*; 31 import javax.servlet.http.*; 32 import java.sql.*; 33 34 35 import java.sql.Connection ; 37 38 39 public class CopyFromInvoice extends HttpSecureAppServlet { 40 41 42 public void init (ServletConfig config) { 43 super.init(config); 44 boolHist = false; 45 } 46 47 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 48 VariablesSecureApp vars = new VariablesSecureApp(request); 49 50 if (vars.commandIn("DEFAULT")) { 51 String strProcessId = vars.getStringParameter("inpProcessId"); 52 String strWindow = vars.getStringParameter("inpwindowId"); 53 String strTab = vars.getStringParameter("inpTabId"); 54 String strKey = vars.getStringParameter("inpcInvoiceId"); 55 printPage(response, vars, strKey, strWindow, strTab, strProcessId); 56 } else if (vars.commandIn("SAVE")) { 57 String strKey = vars.getStringParameter("inpcInvoiceId"); 58 String strInvoice = vars.getStringParameter("inpNewcInvoiceId"); 59 String strWindow = vars.getStringParameter("inpwindowId"); 60 String strTab = vars.getStringParameter("inpTabId"); 61 ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTab); 62 String strWindowPath="", strTabName=""; 63 if (tab!=null && tab.length!=0) { 64 strTabName = FormatUtilities.replace(tab[0].name); 65 strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html"; 66 } else strWindowPath = strDefaultServlet; 67 68 try { 69 Connection conn = getTransactionConnection(); 70 String strMessage = processButton(conn, vars, strKey, strInvoice, strWindow); 71 if (!strMessage.equals("") && !strTabName.equals("")) { 72 vars.setSessionValue(strWindow + "|" + strTabName + ".message", Replace.replace(strMessage, "'", "\\'")); 73 } 74 } catch (NoConnectionAvailableException ex) { 75 bdErrorConnection(response); 76 return; 77 } catch (SQLException ex2) { 78 OBError myError = Utility.translateError(this, vars, vars.getLanguage(), ex2.toString()); 79 if (!myError.isConnectionAvailable()) { 80 bdErrorConnection(response); 81 return; 82 } else vars.setMessage(strTab, myError); 83 } 84 printPageClosePopUp(response, vars, strWindowPath); 85 } else pageErrorPopUp(response); 87 } 88 89 String processButton(Connection conn, VariablesSecureApp vars, String strKey, String strInvoice, String windowId) { 90 int i=0; 91 try { 92 CopyFromInvoiceData[] data = CopyFromInvoiceData.select(conn, this, strInvoice, Utility.getContext(this, vars, "#User_Client", windowId), Utility.getContext(this, vars, "#User_Org", windowId)); 93 if (data!=null && data.length!=0) { 94 for (i=0;i<data.length;i++) { 95 String strSequence = SequenceIdData.getSequence(this, "C_InvoiceLine", vars.getClient()); 96 CopyFromInvoiceData.insert(conn, this, strSequence, strKey, vars.getClient(), vars.getOrg(), vars.getUser(), data[i].cInvoicelineId); 97 } 98 } 99 releaseCommitConnection(conn); 100 } catch (Exception e) { 101 try { 102 releaseRollbackConnection(conn); 103 } catch (Exception ignored) {} 104 e.printStackTrace(); 105 log4j.warn("Rollback in transaction"); 106 return Utility.messageBD(this, "ProcessRunError", vars.getLanguage()); 107 } 108 return (Utility.messageBD(this, "RecordsCopied", vars.getLanguage()) + i); 109 } 110 111 112 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strKey, String windowId, String strTab, String strProcessId) 113 throws IOException, ServletException { 114 if (log4j.isDebugEnabled()) log4j.debug("Output: Button process Copy from Invoice"); 115 116 ActionButtonDefaultData[] data = null; 117 String strHelp="", strDescription=""; 118 if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId); 119 else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId); 120 121 if (data!=null && data.length!=0) { 122 strDescription = data[0].description; 123 strHelp = data[0].help; 124 } 125 String [] discard = {""}; 126 if (strHelp.equals("")) discard[0] = new String ("helpDiscard"); 127 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/CopyFromInvoice", discard).createXmlDocument(); 128 xmlDocument.setParameter("key", strKey); 129 xmlDocument.setParameter("window", windowId); 130 xmlDocument.setParameter("tab", strTab); 131 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 132 xmlDocument.setParameter("question", Utility.messageBD(this, "StartProcess?", vars.getLanguage())); 133 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 134 xmlDocument.setParameter("description", strDescription); 135 xmlDocument.setParameter("help", strHelp); 136 137 138 response.setContentType("text/html; charset=UTF-8"); 139 PrintWriter out = response.getWriter(); 140 out.println(xmlDocument.print()); 141 out.close(); 142 } 143 144 public String getServletInfo() { 145 return "Servlet Copy from invoice"; 146 } } 148 149 | Popular Tags |