1 19 package org.openbravo.erpCommon.ad_actionButton; 20 21 import org.openbravo.erpCommon.utility.SequenceIdData; 22 import org.openbravo.erpCommon.ad_forms.*; 23 import org.openbravo.erpCommon.reference.*; 24 import org.openbravo.erpCommon.utility.*; 25 import org.openbravo.utils.Replace; 26 import org.openbravo.utils.FormatUtilities; 27 import org.openbravo.base.secureApp.HttpSecureAppServlet; 28 import org.openbravo.base.secureApp.VariablesSecureApp; 29 import org.openbravo.xmlEngine.XmlDocument; 30 import java.io.*; 31 import javax.servlet.*; 32 import javax.servlet.http.*; 33 34 import java.sql.Connection ; 36 37 public class Posted extends HttpSecureAppServlet { 38 39 40 public void init (ServletConfig config) { 41 super.init(config); 42 boolHist = false; 43 } 44 45 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 46 if (log4j.isDebugEnabled()) log4j.debug("Posted: doPost"); 47 48 VariablesSecureApp vars = new VariablesSecureApp(request); 49 50 if (vars.commandIn("DEFAULT")) { 51 String strKey = vars.getGlobalVariable("inpKey", "Posted|key"); 52 String strTableId = vars.getGlobalVariable("inpTableId", "Posted|tableId"); 53 String strTabId = vars.getGlobalVariable("inpTabId", "Posted|tabId"); 54 String strPosted = vars.getGlobalVariable("inpPosted", "Posted|posted"); 55 String strProcessId = vars.getGlobalVariable("inpProcessId", "Posted|processId", ""); 56 String strPath = vars.getGlobalVariable("inpPath", "Posted|path", strDireccion + request.getServletPath()); 57 String strWindowId = vars.getGlobalVariable("inpWindowId", "Posted|windowId", ""); 58 String strTabName = vars.getGlobalVariable("inpTabName", "Posted|tabName", ""); 59 60 printPage(response, vars, strKey, strWindowId, strTabId, strProcessId, strTableId, strPath, strTabName, strPosted); 61 } else if (vars.commandIn("SAVE")) { 62 63 String strKey = vars.getRequiredGlobalVariable("inpKey", "Posted|key"); 64 String strTableId = vars.getRequiredGlobalVariable("inpTableId", "Posted|tableId"); 65 String strTabId = vars.getRequestGlobalVariable("inpTabId", "Posted|tabId"); 66 String strPosted = vars.getRequiredGlobalVariable("inpPosted", "Posted|posted"); 67 String strProcessId = vars.getRequestGlobalVariable("inpProcessId", "Posted|processId"); 68 String strPath = vars.getRequestGlobalVariable("inpPath", "Posted|path"); 69 String strWindowId = vars.getRequestGlobalVariable("inpWindowId", "Posted|windowId"); 70 String strTabName = vars.getRequestGlobalVariable("inpTabName", "Posted|tabName"); 71 String strEliminar = vars.getStringParameter("inpEliminar", "N"); 72 73 74 if (log4j.isDebugEnabled()) log4j.debug("SAVE, strPosted: " +strPosted+" Elim "+strEliminar); 75 76 ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTabId); 77 String strWindowPath=""; 78 if (tab!=null && tab.length!=0) { 79 strTabName = FormatUtilities.replace(tab[0].name); 80 strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html"; 81 } else strWindowPath = strDefaultServlet; 82 83 if (strPosted.equals("N")){ 84 OBError messageResult = processButton(vars, strKey, strTableId); 85 if (!messageResult.getType().equals("Success")){ 86 vars.setMessage(strTabId, messageResult); 87 printPageClosePopUp(response, vars); 88 } else { 89 PostedData [] data = PostedData.select(this, strKey, strTableId); 90 if (data==null || data.length==0 || data[0].id.equals("")) { 91 vars.setMessage(strTabId, messageResult); 93 printPageClosePopUp(response, vars); 94 } else { 95 printPageClosePopUp(response, vars, (strDireccion + "/ad_reports/ReportGeneralLedgerJournal.html?Command=DIRECT&inpTable=" + strTableId + "&inpRecord=" + strKey + "&inpOrg=" + data[0].org)); 96 } 97 } 98 } else { 99 if (strEliminar.equals("N")) { 100 PostedData [] data = PostedData.select(this, strKey, strTableId); 101 if (data==null || data.length==0 || data[0].id.equals("")) { 102 vars.setMessage(strTabId, Utility.translateError(this, vars, vars.getLanguage(), "NoFactAcct")); 105 printPageClosePopUp(response, vars); 106 } else { 107 printPageClosePopUp(response, vars, (strDireccion + "/ad_reports/ReportGeneralLedgerJournal.html?Command=DIRECT&inpTable=" + strTableId + "&inpRecord=" + strKey + "&inpOrg=" + data[0].org)); 108 } 109 } else { 110 if (log4j.isDebugEnabled()) log4j.debug("SAVE, delete"); 111 OBError myMessage = processButtonDelete(vars, strKey, strTableId); 112 vars.setMessage(strTabId, myMessage); 113 printPageClosePopUp(response, vars); 114 } 115 } 116 } else pageErrorPopUp(response); 117 } 118 119 120 OBError processButton(VariablesSecureApp vars, String strKey, String strTableId) { 121 if (log4j.isDebugEnabled()) log4j.debug("ProcessButton strKey: "+strKey+"strTableId: "+strTableId ); 122 Connection con = null; 123 OBError myMessage = null; 124 try { 125 con = getTransactionConnection(); 126 AcctServer acct = AcctServer.get(strTableId, vars.getClient()); 127 if (!acct.post(strKey,false, vars,this,con)) { 128 releaseRollbackConnection(con); 129 myMessage = Utility.translateError(this, vars, vars.getLanguage(), "ProcessRunError"+ "\\n" + acct.getInfo(vars)); 131 } 132 releaseCommitConnection(con); 135 } catch (Exception e) { 136 log4j.error(e); 137 myMessage = Utility.translateError(this, vars, vars.getLanguage(), e.getMessage()); 138 try { 139 releaseRollbackConnection(con); 140 } catch (Exception ignored) {} 141 } 142 143 if (myMessage==null) { 144 myMessage = new OBError(); 145 myMessage.setType("Success"); 146 myMessage.setTitle(""); 147 myMessage.setMessage(Utility.messageBD(this, "Success", vars.getLanguage())); 148 } 149 return myMessage; 150 } 151 152 OBError processButtonDelete(VariablesSecureApp vars, String strKey, String strTableId) throws ServletException { 153 OBError myMessage = null; 154 155 try { 156 157 String strClient = PostedData.selectClient(this, PostedData.selectTableName(this, strTableId), strKey); 158 String pinstance = SequenceIdData.getSequence(this, "AD_PInstance", vars.getClient()); 159 PInstanceProcessData.insertPInstance(this, pinstance, "176", strKey, "N", vars.getUser(), vars.getClient(), vars.getOrg()); 160 PInstanceProcessData.insertPInstanceParamNumber(this, pinstance, "10", "AD_Client_ID", strClient, vars.getClient(), vars.getOrg(), vars.getUser()); 161 PInstanceProcessData.insertPInstanceParamNumber(this, pinstance, "20", "AD_Table_ID", strTableId, vars.getClient(), vars.getOrg(), vars.getUser()); 162 PInstanceProcessData.insertPInstanceParam(this, pinstance, "30", "DeletePosting", "Y", vars.getClient(), vars.getOrg(), vars.getUser()); 163 if (log4j.isDebugEnabled()) log4j.debug("delete, pinstance " + pinstance); 164 ActionButtonData.process176(this, pinstance); 165 166 PInstanceProcessData[] pinstanceData = PInstanceProcessData.select(this, pinstance); 167 myMessage = Utility.getProcessInstanceMessage(this, vars, pinstanceData); 168 } catch (ServletException ex) { 169 myMessage = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage()); 170 } 171 if (myMessage==null) { 172 myMessage = new OBError(); 173 myMessage.setType("Success"); 174 myMessage.setTitle(""); 175 myMessage.setMessage(Utility.messageBD(this, "Success", vars.getLanguage())); 176 } 177 return myMessage; 178 } 179 180 181 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strKey, String windowId, String strTab, String strProcessId, String strTableId, String strPath, String strTabName, String strPosted) throws IOException, ServletException { 182 if (log4j.isDebugEnabled()) log4j.debug("Output: Button process Posted"); 183 184 ActionButtonDefaultData[] data = null; 185 String strHelp="", strDescription=""; 186 if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId); 187 else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId); 188 189 if (data!=null && data.length!=0) { 190 strDescription = data[0].description; 191 strHelp = data[0].help; 192 } 193 String [] discard ={"",""}; 194 if (strHelp.equals("")) discard[0] = new String ("helpDiscard"); 195 if (strPosted.equals("N")) discard[1] = new String ("selEliminar"); 196 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/Posted", discard).createXmlDocument(); 197 xmlDocument.setParameter("key", strKey); 198 xmlDocument.setParameter("window", windowId); 199 xmlDocument.setParameter("tab", strTab); 200 xmlDocument.setParameter("process", strProcessId); 201 xmlDocument.setParameter("table", strTableId); 202 xmlDocument.setParameter("posted", strPosted); 203 xmlDocument.setParameter("path", strPath); 204 xmlDocument.setParameter("tabname", strTabName); 205 206 String message = vars.getSessionValue("Posted|message"); 207 if (!message.equals("")) message = "alert('" + message + "');"; 208 vars.removeSessionValue("Posted|message"); 209 xmlDocument.setParameter("message", message); 210 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 211 xmlDocument.setParameter("question", Utility.messageBD(this, "StartProcess?", vars.getLanguage())); 212 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 213 xmlDocument.setParameter("description", strDescription); 214 xmlDocument.setParameter("help", strHelp); 215 216 response.setContentType("text/html; charset=UTF-8"); 217 PrintWriter out = response.getWriter(); 218 out.println(xmlDocument.print()); 219 out.close(); 220 } 221 222 public String getServletInfo() { 223 return "Servlet Posted"; 224 } } 226 227 | Popular Tags |