1 19 package org.openbravo.erpCommon.ad_actionButton; 20 21 import org.openbravo.erpCommon.utility.SequenceIdData; 22 import org.openbravo.erpCommon.utility.Utility; 23 import org.openbravo.erpCommon.utility.ComboTableData; 24 import org.openbravo.utils.FormatUtilities; 25 import org.openbravo.base.secureApp.*; 26 import org.openbravo.xmlEngine.XmlDocument; 27 import java.io.*; 28 import java.util.*; 29 import javax.servlet.*; 30 import javax.servlet.http.*; 31 import org.openbravo.utils.Replace; 32 33 import java.math.BigDecimal ; 34 import org.openbravo.erpCommon.ad_combos.WarehouseComboData; 35 36 import java.sql.Connection ; 38 39 40 public class CreateFromMultiple extends HttpSecureAppServlet { 41 42 static final BigDecimal ZERO = new BigDecimal (0.0); 43 44 45 public void init (ServletConfig config) { 46 super.init(config); 47 boolHist = false; 48 } 49 50 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 51 VariablesSecureApp vars = new VariablesSecureApp(request); 52 if (vars.commandIn("DEFAULT")) { 53 String strKey = vars.getGlobalVariable("inpmInoutId", "CreateFromMultiple|mInoutId"); 54 String strWindowId = vars.getGlobalVariable("inpwindowId", "CreateFromMultiple|windowId", ""); 55 String strTabName = vars.getGlobalVariable("inpTabId", "CreateFromMultiple|adTabId", ""); 56 String strBpartner = vars.getGlobalVariable("inpcBpartnerId", "CreateFromMultiple|bpartner", ""); 57 String strmWarehouseId = vars.getGlobalVariable("inpmWarehouseId", "CreateFromMultiple|mWarehouseId", ""); 58 vars.setSessionValue("CreateFromMultiple|adProcessId", "800062"); 59 60 printPage_FS(response, vars); 61 } else if (vars.commandIn("FRAME2")) { 62 printPage_F2(response, vars); 63 } else if (vars.commandIn("FRAME1")) { 64 String strWindowId = vars.getGlobalVariable("inpWindowId", "CreateFromMultiple|windowId"); 65 String strSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId); 66 String strKey = vars.getGlobalVariable("inpmInoutId", "CreateFromMultiple|mInoutId"); 67 String strTabId = vars.getGlobalVariable("inpTabId", "CreateFromMultiple|adTabId"); 68 String strProcessId = vars.getGlobalVariable("inpadProcessId", "CreateFromMultiple|adProcessId"); 69 String strBpartner = vars.getGlobalVariable("inpcBpartnerId", "CreateFromMultiple|bpartner", ""); 70 String strmWarehouseId = vars.getGlobalVariable("inpmWarehouseId", "CreateFromMultiple|mWarehouseId", ""); 71 vars.removeSessionValue("CreateFromMultiple|mInoutId"); 72 vars.removeSessionValue("CreateFromMultiple|windowId"); 73 vars.removeSessionValue("CreateFromMultiple|adTabId"); 74 vars.removeSessionValue("CreateFromMultiple|adProcessId"); 75 vars.removeSessionValue("CreateFromMultiple|bpartner"); 76 77 callPrintPage(response, vars, strKey, strWindowId, strSOTrx, strTabId, strProcessId, strBpartner, strmWarehouseId); 78 } else if (vars.commandIn("FIND")) { 79 String strKey = vars.getRequiredStringParameter("inpmInoutId"); 80 String strWindowId = vars.getStringParameter("inpWindowId"); 81 String strSOTrx = vars.getStringParameter("inpissotrx"); 82 String strTabId = vars.getStringParameter("inpTabId"); 83 String strBpartner = vars.getRequestGlobalVariable("inpcBpartnerId", "CreateFromMultiple|bpartner"); 84 String strmWarehouseId = vars.getRequestGlobalVariable("inpmWarehouseId", "CreateFromMultiple|mWarehouseId"); 85 callPrintPage(response, vars, strKey, strWindowId, strSOTrx, strTabId, "", strBpartner, strmWarehouseId); 86 } else if (vars.commandIn("SAVE")) { 87 String strKey = vars.getRequiredStringParameter("inpmInoutId"); 88 String strWindowId = vars.getStringParameter("inpWindowId"); 89 String strSOTrx = vars.getStringParameter("inpissotrx"); 90 String strTabId = vars.getStringParameter("inpTabId"); 91 String strMessage = saveMethod(vars, strKey, strWindowId, strSOTrx); 92 ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTabId); 93 String strWindowPath="", strTabName=""; 94 if (tab!=null && tab.length!=0) { 95 strTabName = FormatUtilities.replace(tab[0].name); 96 if (tab[0].help.equals("Y")) strWindowPath="../utility/WindowTree_FS.html?inpTabId=" + strTabId; 97 else strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html"; 98 } else strWindowPath = strDefaultServlet; 99 if (!strMessage.equals("")) vars.setSessionValue(strWindowId + "|" + strTabName + ".message", strMessage); 100 printPageClosePopUp(response, vars, strWindowPath); 101 } else pageErrorPopUp(response); 102 } 103 104 105 void printPage_FS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 106 if (log4j.isDebugEnabled()) log4j.debug("Output: FrameSet"); 107 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/CreateFromMultiple_FS").createXmlDocument(); 108 response.setContentType("text/html; charset=UTF-8"); 109 PrintWriter out = response.getWriter(); 110 out.println(xmlDocument.print()); 111 out.close(); 112 } 113 114 void printPage_F2(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 115 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame2"); 116 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/CreateFromMultiple_F2").createXmlDocument(); 117 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 118 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 119 response.setContentType("text/html; charset=UTF-8"); 120 PrintWriter out = response.getWriter(); 121 out.println(xmlDocument.print()); 122 out.close(); 123 } 124 125 126 void callPrintPage(HttpServletResponse response, VariablesSecureApp vars, String strKey, String strWindowId, String strSOTrx, String strTabId, String strProcessId, String strBpartner, String strmWarehouseId) throws IOException, ServletException { 127 if (strSOTrx.equals("Y")) { printPageShipment(response, vars, strKey, strWindowId, strTabId, strSOTrx, strProcessId, strBpartner, strmWarehouseId); 129 } else { printPageReceipt(response, vars, strKey, strWindowId, strTabId, strSOTrx, strProcessId, strBpartner, strmWarehouseId); 131 } 132 } 133 134 void printPageReceipt(HttpServletResponse response, VariablesSecureApp vars, String strKey, String strWindowId, String strTabId, String strSOTrx, String strProcessId, String strBpartner, String strmWarehouseId) throws IOException, ServletException { 135 if (log4j.isDebugEnabled()) log4j.debug("Output: Receipt"); 136 ActionButtonDefaultData[] data = null; 137 String strHelp="", strDescription=""; 138 if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId); 139 else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId); 140 if (data!=null && data.length!=0) { 141 strDescription = data[0].description; 142 strHelp = data[0].help; 143 } 144 String [] discard = {""}; 145 if (strHelp.equals("")) discard[0] = new String ("helpDiscard"); 146 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/CreateFromMultiple_Receipt", discard).createXmlDocument(); 147 148 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 149 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 150 xmlDocument.setParameter("help", strHelp); 151 xmlDocument.setParameter("description", strDescription); 152 xmlDocument.setParameter("key", strKey); 153 xmlDocument.setParameter("windowId", strWindowId); 154 xmlDocument.setParameter("tabId", strTabId); 155 xmlDocument.setParameter("sotrx", strSOTrx); 156 xmlDocument.setParameter("bpartner", strBpartner); 157 xmlDocument.setParameter("mWarehouseId", strmWarehouseId); 158 159 160 try { 161 ComboTableData comboTableData = new ComboTableData(this, "TABLEDIR", "C_UOM_ID", "", "", Utility.getContext(this, vars, "#User_Org", strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0); 162 Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, ""); 163 xmlDocument.setData("reportC_UOM_ID","liststructure", comboTableData.select(false)); 164 comboTableData = null; 165 } catch (Exception ex) { 166 throw new ServletException(ex); 167 } 168 169 170 171 try { 172 ComboTableData comboTableData = new ComboTableData(this, "TABLEDIR", "M_Warehouse_ID", "", "", Utility.getContext(this, vars, "#User_Org", strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0); 173 Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, strmWarehouseId); 174 xmlDocument.setData("reportM_WAREHOUSE_ID","liststructure", comboTableData.select(false)); 175 comboTableData = null; 176 } catch (Exception ex) { 177 throw new ServletException(ex); 178 } 179 180 WarehouseComboData[] dataW = WarehouseComboData.select(this,vars.getRole(), vars.getClient()); 181 if (strmWarehouseId.equals("") && dataW!=null && dataW.length>0) strmWarehouseId = dataW[0].mWarehouseId; 182 xmlDocument.setData("reportM_LOCATOR_X", "liststructure", CreateFromMultipleReceiptData.selectM_Locator_X(this,strmWarehouseId)); 183 184 185 if (vars.getLanguage().equals("en_US")) { 186 187 try { 188 ComboTableData comboTableData = new ComboTableData(this, "TABLEDIR", "M_Inoutline_Type_ID", "", "", Utility.getContext(this, vars, "#User_Org", strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0); 189 Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, ""); 190 xmlDocument.setData("reportM_INOUTLINETYPE_ID","liststructure", comboTableData.select(false)); 191 comboTableData = null; 192 } catch (Exception ex) { 193 throw new ServletException(ex); 194 } 195 196 } else { 197 198 try { 199 ComboTableData comboTableData = new ComboTableData(this, "TABLEDIR", "M_Inoutline_Type_ID", "", "", Utility.getContext(this, vars, "#User_Org", strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0); 200 Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, ""); 201 xmlDocument.setData("reportM_INOUTLINETYPE_ID","liststructure", comboTableData.select(false)); 202 comboTableData = null; 203 } catch (Exception ex) { 204 throw new ServletException(ex); 205 } 206 207 } 208 209 try { 210 ComboTableData comboTableData = new ComboTableData(this, "TABLEDIR", "M_Locator_Type_ID", "", "", Utility.getContext(this, vars, "#User_Org", strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0); 211 Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, ""); 212 xmlDocument.setData("reportM_LOCATOR_TYPE","liststructure", comboTableData.select(false)); 213 comboTableData = null; 214 } catch (Exception ex) { 215 throw new ServletException(ex); 216 } 217 218 219 response.setContentType("text/html; charset=UTF-8"); 220 PrintWriter out = response.getWriter(); 221 out.println(xmlDocument.print()); 222 out.close(); 223 } 224 225 void printPageShipment(HttpServletResponse response, VariablesSecureApp vars, String strKey, String strWindowId, String strTabId, String strSOTrx, String strProcessId, String strBpartner, String strmWarehouseId) throws IOException, ServletException { 226 if (log4j.isDebugEnabled()) log4j.debug("Output: Shipment"); 227 String [] discard = {""}; 228 String strProduct = vars.getStringParameter("inpmProductId"); 229 String strX = vars.getStringParameter("inpx"); 231 String strY = vars.getStringParameter("inpy"); 232 String strZ = vars.getStringParameter("inpz"); 233 CreateFromMultipleShipmentData[] data = null; 234 if (strProduct.equals("") && strmWarehouseId.equals("") && strX.equals("") && strY.equals("") && strZ.equals("")) { 235 discard[0] = new String ("sectionDetail"); 236 data = new CreateFromMultipleShipmentData[0]; 237 } else { 238 data = CreateFromMultipleShipmentData.select(this, strBpartner, strProduct, strmWarehouseId, strX, strY, strZ, Utility.getContext(this, vars, "#User_Client", strWindowId)); 239 } 240 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/CreateFromMultiple_Shipment", discard).createXmlDocument(); 241 242 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 243 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 244 xmlDocument.setParameter("key", strKey); 245 xmlDocument.setParameter("windowId", strWindowId); 246 xmlDocument.setParameter("tabId", strTabId); 247 xmlDocument.setParameter("sotrx", strSOTrx); 248 xmlDocument.setParameter("mWarehouseId", strmWarehouseId); xmlDocument.setParameter("bpartnerId", strBpartner); 250 xmlDocument.setParameter("bpartnerId_DES", CreateFromMultipleShipmentData.bpartnerDescription(this, strBpartner)); 251 xmlDocument.setParameter("productId", strProduct); 252 xmlDocument.setParameter("productId_DES", CreateFromMultipleShipmentData.productDescription(this, strProduct)); 253 xmlDocument.setParameter("x", strX); 254 xmlDocument.setParameter("y", strY); 255 xmlDocument.setParameter("z", strZ); 256 257 258 try { 259 ComboTableData comboTableData = new ComboTableData(this, "TABLEDIR", "M_Warehouse_ID", "", "", Utility.getContext(this, vars, "#User_Org", strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0); 260 Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, strmWarehouseId); 261 xmlDocument.setData("reportM_WAREHOUSE_ID","liststructure", comboTableData.select(false)); 262 comboTableData = null; 263 } catch (Exception ex) { 264 throw new ServletException(ex); 265 } 266 267 268 269 try { 270 ComboTableData comboTableData = new ComboTableData(this, "TABLEDIR", "M_Inoutline_Type_ID", "", "", Utility.getContext(this, vars, "#User_Org", strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0); 271 Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, ""); 272 xmlDocument.setData("reportM_INOUTLINETYPE_ID","liststructure", comboTableData.select(false)); 273 comboTableData = null; 274 } catch (Exception ex) { 275 throw new ServletException(ex); 276 } 277 278 xmlDocument.setData("structure1", data); 279 response.setContentType("text/html; charset=UTF-8"); 280 PrintWriter out = response.getWriter(); 281 out.println(xmlDocument.print()); 282 out.close(); 283 284 } 285 286 String saveMethod(VariablesSecureApp vars, String strKey, String strWindowId, String strSOTrx) throws IOException, ServletException { 287 if (strSOTrx.equals("Y")) return saveShipment(vars, strKey, strWindowId); 288 else return saveReceipt(vars, strKey, strWindowId); 289 } 290 291 String saveReceipt(VariablesSecureApp vars, String strKey, String strWindowId) throws IOException, ServletException { 292 if (log4j.isDebugEnabled()) log4j.debug("Save: Receipt"); 293 String strProduct = vars.getRequiredStringParameter("inpmProductId"); 294 String strAtributo = vars.getStringParameter("inpmAttributesetinstanceId"); 295 String strQty = vars.getStringParameter("inpmovementqty"); 296 String strUOM = vars.getStringParameter("inpcUomId"); 297 String strQuantityOrder = vars.getStringParameter("inpquantityorder"); 298 String strProductUOM = vars.getStringParameter("inpmProductUomId"); 299 String strWarehouse = vars.getRequiredStringParameter("inpmWarehouseId"); 300 String strInoutlineType = vars.getStringParameter("inpmInoutlineTypeId"); 301 String strLocator = vars.getStringParameter("inpmLocatorX"); 302 String strNumero = vars.getRequiredStringParameter("inpnumerolineas"); 303 String strLocatorType = vars.getStringParameter("inpmLocatorType"); 304 String strMessage = ""; 305 306 Connection conn = null; 307 try { 308 conn = this.getTransactionConnection(); 309 int total = Integer.valueOf(strNumero).intValue(); 310 CreateFromMultipleReceiptData[] locators = CreateFromMultipleReceiptData.select(conn, this, Utility.getContext(this, vars, "#User_Client", strWindowId), Utility.getContext(this, vars, "#User_Org", strWindowId), strWarehouse, strLocator, strLocatorType); 311 int count = 0; 312 if (locators!=null && locators.length>0) { 313 for (count=0;count<total;count++) { 314 String strM_Locator_ID = (count>locators.length-1)?"":locators[count].mLocatorId; 315 if (strM_Locator_ID.equals("")) break; 316 String strSequence = SequenceIdData.getSequence(this, "M_InOutLine", vars.getClient()); 317 CreateFromMultipleReceiptData.insert(conn, this, strSequence, vars.getClient(), vars.getOrg(), vars.getUser(), strKey, strM_Locator_ID, strProduct, strUOM, strQty, strAtributo, strQuantityOrder, strProductUOM, strInoutlineType); 318 } 319 } 320 strMessage = Utility.messageBD(this, "Success", vars.getLanguage()) + " - " + Utility.messageBD(this, "Created", vars.getLanguage()) + ": " + count; 321 322 releaseCommitConnection(conn); 323 } catch (Exception e) { 324 try { 325 releaseRollbackConnection(conn); 326 } catch (Exception ignored) {} 327 e.printStackTrace(); 328 log4j.warn("Rollback in transaction"); 329 return Utility.messageBD(this, "ProcessRunError", vars.getLanguage()); 330 } 331 return strMessage; 332 } 333 334 String saveShipment(VariablesSecureApp vars, String strKey, String strWindowId) throws IOException, ServletException { 335 if (log4j.isDebugEnabled()) log4j.debug("Save: Shipment"); 336 String strStorageDetail = vars.getInStringParameter("inpmStorageDetailId"); 337 String strInoutlineType = vars.getStringParameter("inpmInoutlineTypeId"); 338 if (strStorageDetail.equals("")) return ""; 339 Connection conn = null; 340 try { 341 conn = this.getTransactionConnection(); 342 if (strStorageDetail.startsWith("(")) strStorageDetail = strStorageDetail.substring(1, strStorageDetail.length()-1); 343 if (!strStorageDetail.equals("")) { 344 strStorageDetail = Replace.replace(strStorageDetail, "'", ""); 345 StringTokenizer st = new StringTokenizer(strStorageDetail, ",", false); 346 while (st.hasMoreTokens()) { 347 String strStorageDetailId = st.nextToken().trim(); 348 String strQty = vars.getStringParameter("inpmovementqty" + strStorageDetailId); 349 String strQtyOrder = vars.getStringParameter("inpquantityorder" + strStorageDetailId); 350 351 String strSequence = SequenceIdData.getSequence(this, "M_InOutLine", vars.getClient()); 352 CreateFromMultipleShipmentData.insert(conn, this, strSequence, vars.getClient(), vars.getOrg(), vars.getUser(), strKey, strQty, strQtyOrder, strInoutlineType, strStorageDetailId); 353 } 354 } 355 releaseCommitConnection(conn); 356 } catch (Exception e) { 357 try { 358 releaseRollbackConnection(conn); 359 } catch (Exception ignored) {} 360 e.printStackTrace(); 361 log4j.warn("Rollback in transaction"); 362 return Utility.messageBD(this, "ProcessRunError", vars.getLanguage()); 363 } 364 return Utility.messageBD(this, "Success", vars.getLanguage()); 365 } 366 367 368 public String getServletInfo() { 369 return "Servlet that presents the button of Create From Multiple"; 370 } } 372 | Popular Tags |