| 1 19 package org.openbravo.erpCommon.ad_actionButton; 20 21 import org.openbravo.erpCommon.utility.*; 22 import org.openbravo.utils.FormatUtilities; 23 import org.openbravo.base.secureApp.*; 24 import org.openbravo.xmlEngine.XmlDocument; 25 import java.io.*; 26 import javax.servlet.*; 27 import javax.servlet.http.*; 28 import java.math.BigDecimal ; 29 30 import java.sql.Connection ; 32 33 34 public class EditCCPMeasureValues extends HttpSecureAppServlet { 35 static final BigDecimal ZERO = new BigDecimal (0.0); 36 37 38 public void init (ServletConfig config) { 39 super.init(config); 40 boolHist = false; 41 } 42 43 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 44 VariablesSecureApp vars = new VariablesSecureApp(request); 45 if (vars.commandIn("DEFAULT")) { 46 String strKey = vars.getRequestGlobalVariable("inpmaMeasureShiftId", "EditCCPMeasureValues|inpmaMeasureShiftId"); 47 String strWindowId = vars.getGlobalVariable("inpwindowId", "EditCCPMeasureValues|windowId", ""); 48 String strTabName = vars.getGlobalVariable("inpTabId", "EditCCPMeasureValues|adTabId", ""); 49 String strMeasureDate = vars.getRequestGlobalVariable("inpmeasuredate", "EditCCPMeasureValues|inpmeasuredate"); 50 String strProduct = vars.getRequestGlobalVariable("inpproduct", "EditCCPMeasureValues|inpproduct"); 51 String strShift = vars.getRequestGlobalVariable("inpshift", "EditCCPMeasureValues|inpshift"); 52 53 vars.setSessionValue("EditCCPMeasureValues|adProcessId", "800062"); 54 55 printPage_FS(response, vars); 56 } else if (vars.commandIn("FRAME2")) { 57 printPage_F2(response, vars); 58 } else if (vars.commandIn("FRAME1")) { 59 String strWindowId = vars.getGlobalVariable("inpWindowId", "EditCCPMeasureValues|windowId"); 60 String strKey = vars.getGlobalVariable("inpmaMeasureShiftId", "EditCCPMeasureValues|inpmaMeasureShiftId"); 61 String strTabId = vars.getGlobalVariable("inpTabId", "EditCCPMeasureValues|adTabId"); 62 String strProcessId = vars.getGlobalVariable("inpadProcessId", "EditCCPMeasureValues|adProcessId"); 63 String strMeasureDate = vars.getGlobalVariable("inpmeasuredate", "EditCCPMeasureValues|inpmeasuredate", ""); 64 String strProduct = vars.getGlobalVariable("inpproduct", "EditCCPMeasureValues|inpproduct", ""); 65 String strShift = vars.getGlobalVariable("inpshift", "EditCCPMeasureValues|inpshift", ""); 66 vars.removeSessionValue("EditCCPMeasureValues|windowId"); 67 vars.removeSessionValue("EditCCPMeasureValues|adTabId"); 68 vars.removeSessionValue("EditCCPMeasureValues|adProcessId"); 69 70 printPageDataSheet(response, vars, strKey, strWindowId, strTabId, strProcessId, strMeasureDate, strProduct, strShift); 71 } else if (vars.commandIn("SAVE")) { 72 String strKey = vars.getStringParameter("inpmaMeasureShiftId"); 73 String strWindowId = vars.getStringParameter("inpWindowId"); 74 String strTabId = vars.getStringParameter("inpTabId"); 75 updateValues(response, request, vars, strKey, strWindowId, strTabId); 76 } else pageErrorPopUp(response); 77 } 78 79 80 void printPage_FS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 81 if (log4j.isDebugEnabled()) log4j.debug("Output: FrameSet"); 82 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/EditCCPMeasureValues_FS").createXmlDocument(); 83 response.setContentType("text/html; charset=UTF-8"); 84 PrintWriter out = response.getWriter(); 85 out.println(xmlDocument.print()); 86 out.close(); 87 if (log4j.isDebugEnabled()) log4j.debug("Output: FrameSet - out"); 88 } 89 90 void printPage_F2(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 91 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame2"); 92 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/EditCCPMeasureValues_F2").createXmlDocument(); 93 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 94 response.setContentType("text/html; charset=UTF-8"); 95 PrintWriter out = response.getWriter(); 96 out.println(xmlDocument.print()); 97 out.close(); 98 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame2 - Out"); 99 } 100 101 void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strKey, String strWindowId, String strTabId, String strProcessId, String strMeasureDate, String strProduct, String strShift) throws IOException, ServletException { 102 if (log4j.isDebugEnabled()) log4j.debug("Output: values "); 103 String [] discard = {""}; 104 EditCCPMeasureValuesData[] data = null; 105 data = EditCCPMeasureValuesData.select(this, strKey); 106 107 String shift = ""; 108 109 if (vars.getLanguage().equals("en_US")) shift = EditCCPMeasureValuesData.selectShift(this, strShift); 110 else shift = EditCCPMeasureValuesData.selectShiftTrl(this, strShift, vars.getLanguage()); 111 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/EditCCPMeasureValues_F1", discard).createXmlDocument(); 112 113 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 114 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 115 xmlDocument.setParameter("key", strKey); 116 xmlDocument.setParameter("windowId", strWindowId); 117 xmlDocument.setParameter("tabId", strTabId); 118 119 xmlDocument.setParameter("measureDate", strMeasureDate); 120 xmlDocument.setParameter("shift", shift); 121 if (strProduct == null) strProduct = ""; 122 xmlDocument.setParameter("product", strProduct); 123 124 if (log4j.isDebugEnabled()) log4j.debug("Param: " + vars.getLanguage() + " " + strReplaceWith + " " + strKey + " " + strWindowId + " " + strTabId + " " + strMeasureDate + " shift: " + shift + " " + strShift + " " + strProduct); 125 EditCCPMeasureValuesHoursData[][] dataHours = new EditCCPMeasureValuesHoursData[data.length][10]; 126 EditCCPMeasureValuesValuesData[][] dataValues = new EditCCPMeasureValuesValuesData[data.length][]; 127 128 for (int i=0; i<data.length; i++){ 129 dataHours[i] = EditCCPMeasureValuesHoursData.select(this, data[i].groupid); 130 if (dataHours[i] == null || dataHours[i].length == 0) dataHours[i] = new EditCCPMeasureValuesHoursData[0]; 131 132 dataValues[i] = EditCCPMeasureValuesValuesData.select(this, data[i].groupid); 133 if (dataValues[i] == null || dataValues[i].length == 0) dataValues[i] = new EditCCPMeasureValuesValuesData[0]; 134 } 135 136 OBError myMessage = vars.getMessage("EditCCPMeasureValues"); 137 vars.removeMessage("EditCCPMeasureValues"); 138 if (myMessage!=null) { 139 xmlDocument.setParameter("messageType", myMessage.getType()); 140 xmlDocument.setParameter("messageTitle", myMessage.getTitle()); 141 xmlDocument.setParameter("messageMessage", myMessage.getMessage()); 142 } 143 xmlDocument.setData("structure1", data); 144 xmlDocument.setDataArray("reportHours", "structureHours",dataHours); 145 xmlDocument.setDataArray("reportValues", "structureValues",dataValues); 146 response.setContentType("text/html; charset=UTF-8"); 147 PrintWriter out = response.getWriter(); 148 out.println(xmlDocument.print()); 149 out.close(); 150 if (log4j.isDebugEnabled()) log4j.debug("Output: values - out"); 151 } 152 153 void updateValues(HttpServletResponse response, HttpServletRequest request, VariablesSecureApp vars, String strKey, String strWindowId, String strTabId) throws IOException, ServletException { 154 String strMessage=""; 155 if (log4j.isDebugEnabled()) log4j.debug("Update: values"); 156 157 String [] strValueId = request.getParameterValues("strKey"); 158 String [] strGroupId = request.getParameterValues("strGroup"); 159 OBError myError = null; 160 int total = 0; 161 Boolean error = false; 162 163 if (log4j.isDebugEnabled()) log4j.debug("Update: values after strValueID"); 164 if (strValueId != null && strValueId.length > 0) { 165 Connection conn = null; 166 try { 167 conn = this.getTransactionConnection(); 168 for (int i=0; i<strValueId.length; i++) { 169 String numeric = ""; 170 String text = ""; 171 String check = "N"; 172 if (log4j.isDebugEnabled()) log4j.debug("*****strValueId[i]=" + strValueId[i]); 173 if (!strValueId[i].equals("0")) { 174 String type = EditCCPMeasureValuesData.selectType(this, strValueId[i]); 175 if (type.equals("N")) numeric = vars.getStringParameter("strValue"+strValueId[i]); 176 else if (type.equals("T")) text = vars.getStringParameter("strValue"+strValueId[i]); 177 else check = vars.getStringParameter("strValue"+strValueId[i]); 178 if (log4j.isDebugEnabled()) log4j.debug("Values to update: " + strValueId[i] + ", " + numeric + ", " + text + ", " + check); 179 total = EditCCPMeasureValuesData.update(conn, this, numeric, text, check.equals("Y")?"Y":"N", strValueId[i]); 180 if (total == 0) error =true; 181 } 182 } 183 for (int i=0; i<strGroupId.length; i++) { 184 if (log4j.isDebugEnabled()) log4j.debug("*****strGroupId[i]=" + strGroupId[i]); 185 if (!strGroupId[i].equals("0")) { 186 String secProduct = vars. getStringParameter("strProduct"+strGroupId[i]); 187 if (log4j.isDebugEnabled()) log4j.debug("Values to update: " + strGroupId[i] + ", " + secProduct); 188 total = EditCCPMeasureValuesData.updateSecProduct(conn, this, secProduct, strGroupId[i]); 189 if (total == 0) error = true; 190 } 191 } 192 releaseCommitConnection(conn); 193 } catch (Exception e) { 194 myError = Utility.translateError(this, vars, vars.getLanguage(), e.getMessage()); 195 try { 196 releaseRollbackConnection(conn); 197 } catch (Exception ignored) {} 198 e.printStackTrace(); 199 log4j.warn("Rollback in transaction"); 200 if (!myError.isConnectionAvailable()) { 201 bdErrorConnection(response); 202 return; 203 } 204 } 205 } 206 if (error){ 207 myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=DBExecuteError"); 208 } else if (myError == null) { 209 myError = new OBError(); 210 myError.setType("Info"); 211 myError.setMessage(Utility.messageBD(this, "Success", vars.getLanguage())); 212 myError.setTitle(""); 213 } 214 vars.setMessage(strTabId, myError); 215 ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTabId); 216 String strWindowPath="", strTabName=""; 217 if (tab!=null && tab.length!=0) { 218 strTabName = FormatUtilities.replace(tab[0].name); 219 strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html"; 220 } else strWindowPath = strDefaultServlet; 221 if (!strMessage.equals("")) vars.setSessionValue(strWindowId + "|" + strTabName + ".message", strMessage); 222 printPageClosePopUp(response, vars, strWindowPath); 223 } 224 225 226 public String getServletInfo() { 227 return "Servlet that presents the button of Create From Multiple"; 228 } } 230 | Popular Tags |