1 19 package org.openbravo.erpCommon.ad_process; 20 21 22 import org.openbravo.erpCommon.ad_actionButton.ActionButtonDefaultData; 23 import org.openbravo.erpCommon.utility.*; 24 import org.openbravo.utils.FormatUtilities; 25 import org.openbravo.base.secureApp.HttpSecureAppServlet; 26 import org.openbravo.base.secureApp.VariablesSecureApp; 27 import org.openbravo.xmlEngine.XmlDocument; 28 import java.io.*; 29 import javax.servlet.*; 30 import javax.servlet.http.*; 31 32 33 import java.sql.Connection ; 35 36 public class CopyFromGLJournal extends HttpSecureAppServlet { 37 38 39 public void init (ServletConfig config) { 40 super.init(config); 41 boolHist = false; 42 } 43 44 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 45 VariablesSecureApp vars = new VariablesSecureApp(request); 46 47 if (vars.commandIn("DEFAULT")) { 48 String strWindow = vars.getGlobalVariable("inpwindowId", "CopyFromGLJournal|windowId"); 49 String strTab = vars.getGlobalVariable("inpTabId", "CopyFromGLJournal|tabId"); 50 String strKey = vars.getGlobalVariable("inpglJournalbatchId", "CopyFromGLJournal|glJournalbatchId"); 51 printPageFS(response, vars); 52 } else if (vars.commandIn("FRAME1")) { 53 String strWindow = vars.getGlobalVariable("inpwindowId", "CopyFromGLJournal|windowId"); 54 String strTab = vars.getGlobalVariable("inpTabId", "CopyFromGLJournal|tabId"); 55 String strDescription = vars.getStringParameter("inpDescription", ""); 56 String strDocumentNo = vars.getStringParameter("inpDocumentNo", ""); 57 printPageFrame1(response, vars, strDescription, strDocumentNo, strWindow, strTab); 58 } else if (vars.commandIn("FRAME2")) { 59 String strWindow = vars.getGlobalVariable("inpwindowId", "CopyFromGLJournal|windowId"); 60 String strTab = vars.getGlobalVariable("inpTabId", "CopyFromGLJournal|tabId"); 61 String strDescription = vars.getStringParameter("inpDescription"); 62 String strDocumentNo = vars.getStringParameter("inpDocumentNo"); 63 String strKey = vars.getGlobalVariable("inpglJournalbatchId", "CopyFromGLJournal|glJournalbatchId"); 64 printPageFrame2(response, vars, strDescription, strDocumentNo, strWindow, strTab, strKey); 65 } else if (vars.commandIn("FIND")) { 66 String strWindow = vars.getGlobalVariable("inpwindowId", "CopyFromGLJournal|windowId"); 67 String strTab = vars.getGlobalVariable("inpTabId", "CopyFromGLJournal|tabId"); 68 String strDescription = vars.getStringParameter("inpDescription"); 69 String strDocumentNo = vars.getStringParameter("inpDocumentNo"); 70 String strKey = vars.getGlobalVariable("inpglJournalbatchId", "CopyFromGLJournal|glJournalbatchId"); 71 printPageFrame2(response, vars, strDescription, strDocumentNo, strWindow, strTab, strKey); 72 } else if (vars.commandIn("FRAME3")) { 73 printPageFrame3(response, vars); 74 } else if (vars.commandIn("SAVE")) { 75 String strWindow = vars.getStringParameter("inpwindowId"); 76 String strTab = vars.getStringParameter("inpTabId"); 77 ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTab); 78 String strWindowPath="", strTabName=""; 79 if (tab!=null && tab.length!=0) { 80 strTabName = FormatUtilities.replace(tab[0].name); 81 if (tab[0].help.equals("Y")) strWindowPath="../utility/WindowTree_FS.html?inpTabId=" + strTab; 82 else strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html"; 83 } else strWindowPath = strDefaultServlet; 84 String strKey = vars.getRequiredStringParameter("inpglJournalbatchId"); 85 String strGLJournalBatch = vars.getStringParameter("inpglJournalId"); 86 87 88 89 90 OBError myError = null; 91 try { 92 myError = processButton(vars, strKey, strGLJournalBatch, strWindow); 93 } catch(ServletException ex) { 94 myError = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage()); 95 if (!myError.isConnectionAvailable()) { 96 bdErrorConnection(response); 97 return; 98 } 99 } 100 101 vars.setMessage(strTab, myError); 102 103 printPageClosePopUp(response, vars, strWindowPath); 104 } else pageErrorPopUp(response); 105 } 106 107 void printPageFS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 108 if (log4j.isDebugEnabled()) log4j.debug("Output: GLJournalBatch seeker Frame Set"); 109 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_process/CopyFromGLJournal_FS").createXmlDocument(); 110 response.setContentType("text/html; charset=UTF-8"); 111 PrintWriter out = response.getWriter(); 112 out.println(xmlDocument.print()); 113 out.close(); 114 } 115 116 void printPageFrame1(HttpServletResponse response, VariablesSecureApp vars, String strDescription, String strDocumentNo, String strWindow, String strTab) throws IOException, ServletException { 117 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 1 of the GLJournalBatch seeker"); 118 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_process/CopyFromGLJournal_F1").createXmlDocument(); 119 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 120 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 121 xmlDocument.setParameter("window", strWindow); 122 xmlDocument.setParameter("tab", strTab); 123 response.setContentType("text/html; charset=UTF-8"); 124 PrintWriter out = response.getWriter(); 125 out.println(xmlDocument.print()); 126 out.close(); 127 } 128 129 130 OBError processButton(VariablesSecureApp vars, String strKey, String strGLJournalBatch, String windowId) throws ServletException { 131 if (log4j.isDebugEnabled()) log4j.debug("Save: GLJournal"); 132 if (strGLJournalBatch.equals("")) return new OBError();; 133 Connection conn = null; 134 135 OBError myError = null; 136 try { 137 conn = this.getTransactionConnection(); 138 CopyFromGLJournalData [] data = CopyFromGLJournalData.select(this, strKey,strGLJournalBatch); 139 for(int i=0;data != null && i<data.length;i++){ 140 String strSequence = SequenceIdData.getSequence(this, "GL_Journal", vars.getClient()); 141 String strDocumentNo = Utility.getDocumentNo(this, vars, windowId, "GL_Journal", Utility.getContext(this, vars, "C_DocTypeTarget_ID", "132"), Utility.getContext(this, vars, "C_DocType_ID", "132"), false, true); 142 if(CopyFromGLJournalData.insertGLJournal(conn,this,strSequence, vars.getClient(), vars.getOrg(), vars.getUser(), data[i].cAcctschemaId, data[i].cDoctypeId, "DR", "CO", data[i].isapproved, data[i].isprinted, data[i].description, data[i].postingtype, data[i].glBudgetId, data[i].glCategoryId, data[i].datedoc, data[i].dateacct, data[i].cPeriodId, data[i].cCurrencyId, data[i].currencyratetype, data[i].currencyrate,strKey, data[i].controlamt, strDocumentNo, "N", "N", "N")==0)log4j.warn("Save: GLJournal record " + i + " not inserted. Sequence = " + strSequence); 143 CopyFromGLJournalData [] dataLines = CopyFromGLJournalData.selectLines(this, data[i].glJournalId); 144 for(int j=0;dataLines!=null && j<dataLines.length;j++){ 145 String strLineSequence = SequenceIdData.getSequence(this, "GL_JournalLine", vars.getClient()); 146 if(CopyFromGLJournalData.insertGLJournalLine(conn, this, strLineSequence, vars.getClient(), vars.getOrg(), vars.getUser(), strSequence, dataLines[j].line, dataLines[j].isgenerated, dataLines[j].description, dataLines[j].amtsourcedr, dataLines[j].amtsourcecr, dataLines[j].cCurrencyId, dataLines[j].currencyratetype, dataLines[j].currencyrate, dataLines[j].amtacctdr, dataLines[j].amtacctcr, dataLines[j].cUomId, dataLines[j].qty, dataLines[j].cValidcombinationId)==0)log4j.warn("Save: GLJournalLine record " + j + " not inserted. Sequence = " + strLineSequence); 147 } 148 } 149 releaseCommitConnection(conn); 150 151 } catch (ServletException ex) { 152 try { 153 releaseRollbackConnection(conn); 154 } catch (Exception ignored) {} 155 throw ex; 156 } catch (Exception e) { 157 try { 158 releaseRollbackConnection(conn); 159 } catch (Exception ignored) {} 160 e.printStackTrace(); 161 log4j.warn("Rollback in transaction"); 162 myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=ProcessRunError"); 163 } 164 if (myError==null) { 165 myError = new OBError(); 166 myError.setType("Success"); 167 myError.setTitle(""); 168 myError.setMessage(Utility.messageBD(this, "Success", vars.getLanguage())); 169 } 170 return myError; 171 } 172 173 174 void printPageFrame2(HttpServletResponse response, VariablesSecureApp vars, String strDescription, String strDocumentNo, String strWindow,String strTab, String strKey) 175 throws IOException, ServletException { 176 if (log4j.isDebugEnabled()) log4j.debug("Output: Button process copy GLJournalBatch details"); 177 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_process/CopyFromGLJournal_F2").createXmlDocument(); 178 CopyFromGLJournalData [] data = CopyFromGLJournalData.selectFrom(this, strDescription, strDocumentNo, vars.getClient(), Utility.getContext(this, vars, "#User_Org", "CopyFromGLJournal")); 179 xmlDocument.setData("structure1", data); 180 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 181 xmlDocument.setParameter("window", strWindow); 182 xmlDocument.setParameter("tab", strTab); 183 xmlDocument.setParameter("key", strKey); 184 { 185 OBError myMessage = vars.getMessage(strTab); 186 vars.removeMessage(strTab); 187 if (myMessage!=null) { 188 xmlDocument.setParameter("messageType", myMessage.getType()); 189 xmlDocument.setParameter("messageTitle", myMessage.getTitle()); 190 xmlDocument.setParameter("messageMessage", myMessage.getMessage()); 191 } 192 } 193 response.setContentType("text/html; charset=UTF-8"); 194 PrintWriter out = response.getWriter(); 195 out.println(xmlDocument.print()); 196 out.close(); 197 } 198 199 void printPageFrame3(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 200 if (log4j.isDebugEnabled()) log4j.debug("Output:: Button process copy GLJournalBatch details"); 201 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_process/CopyFromGLJournal_F3").createXmlDocument(); 202 203 response.setContentType("text/html; charset=UTF-8"); 204 PrintWriter out = response.getWriter(); 205 out.println(xmlDocument.print()); 206 out.close(); 207 } 208 209 public String getServletInfo() { 210 return "Servlet Project set Type"; 211 } } 213 214
| Popular Tags
|