1 19 package org.openbravo.erpCommon.ad_callouts; 20 21 import org.openbravo.base.secureApp.HttpSecureAppServlet; 22 import org.openbravo.base.secureApp.VariablesSecureApp; 23 import org.openbravo.xmlEngine.XmlDocument; 24 import org.openbravo.utils.FormatUtilities; 25 import org.openbravo.erpCommon.utility.*; 26 import org.openbravo.data.FieldProvider; 27 import java.io.*; 28 import javax.servlet.*; 29 import javax.servlet.http.*; 30 31 public class SL_Movement_Product extends HttpSecureAppServlet { 32 33 34 public void init (ServletConfig config) { 35 super.init(config); 36 boolHist = false; 37 } 38 39 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 40 VariablesSecureApp vars = new VariablesSecureApp(request); 41 if (vars.commandIn("DEFAULT")) { 42 String strChanged = vars.getStringParameter("inpLastFieldChanged"); 43 if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged); 44 String strLocator = vars.getStringParameter("inpmProductId_LOC"); 45 String strQty = vars.getStringParameter("inpmProductId_QTY"); 46 String strUOM = vars.getStringParameter("inpmProductId_UOM"); 47 String strAttribute = vars.getStringParameter("inpmProductId_ATR"); 48 String strQtyOrder = vars.getStringParameter("inpmProductId_PQTY"); 49 String strPUOM = vars.getStringParameter("inpmProductId_PUOM"); 50 String strMProductID = vars.getStringParameter("inpmProductId"); 51 String strWindowId = vars.getStringParameter("inpwindowId"); 52 String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId); 53 String strWharehouse = Utility.getContext(this, vars, "#M_Warehouse_ID", strWindowId); 54 String strTabId = vars.getStringParameter("inpTabId"); 55 56 try { 57 printPage(response, vars, strChanged, strMProductID, strLocator, strQty, strUOM, strAttribute, strQtyOrder, strPUOM, strIsSOTrx, strWharehouse, strTabId); 58 } catch (ServletException ex) { 59 pageErrorCallOut(response); 60 } 61 } else pageError(response); 62 } 63 64 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strChanged, String strMProductID, String strLocator, String strQty, String strUOM, String strAttribute, String strQtyOrder, String strPUOM, String strIsSOTrx, String strWharehouse, String strTabId) throws IOException, ServletException { 65 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 66 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument(); 67 68 StringBuffer resultado = new StringBuffer (); 69 resultado.append("var calloutName='SL_Movement_Product';\n\n"); 70 resultado.append("var respuesta = new Array("); 71 if (strLocator.startsWith("\"")) strLocator=strLocator.substring(1,strLocator.length()-1); 72 resultado.append("new Array(\"inpmLocatorId\", \"" + strLocator + "\"),"); 73 resultado.append("new Array(\"inpmLocatorId_R\", \"" + FormatUtilities.replaceJS(SLInOutLineProductData.locator(this, strLocator, vars.getLanguage())) + "\"),"); 74 resultado.append("new Array(\"inpcUomId\", " + (strUOM.equals("")?"\"\"":strUOM) + "),"); 75 if (strAttribute.startsWith("\"")) strAttribute=strAttribute.substring(1,strAttribute.length()-1); 76 resultado.append("new Array(\"inpmAttributesetinstanceId\", \"" + strAttribute + "\"),"); 77 resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \"" + FormatUtilities.replaceJS(SLInOutLineProductData.attribute(this, strAttribute)) + "\"),"); 78 resultado.append("new Array(\"inpmovementqty\", " + (strQty.equals("")?"\"\"":strQty) + "),"); 79 resultado.append("new Array(\"inpquantityorder\", " + (strQtyOrder.equals("")?"\"\"":strQtyOrder) + "), \n"); 80 String strHasSecondaryUOM = SLOrderProductData.hasSecondaryUOM(this, strMProductID); 81 resultado.append("new Array(\"inphasseconduom\", " + strHasSecondaryUOM + "),\n"); 82 resultado.append("new Array(\"inpmProductUomId\", "); 83 if (strPUOM.startsWith("\"")) strPUOM=strPUOM.substring(1,strPUOM.length()-1); 84 if (vars.getLanguage().equals("en_US")) { 85 FieldProvider [] tld = null; 86 try { 87 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "M_Product_UOM", "", Utility.getContext(this, vars, "#User_Org", "SLMovementProduct"), Utility.getContext(this, vars, "#User_Client", "SLMovementProduct"), 0); 88 Utility.fillSQLParameters(this, vars, null, comboTableData, "SLMovementProduct", ""); 89 tld = comboTableData.select(false); 90 comboTableData = null; 91 } catch (Exception ex) { 92 throw new ServletException(ex); 93 } 94 95 if (tld!=null && tld.length>0) { 96 resultado.append("new Array("); 97 for (int i=0;i<tld.length;i++) { 98 resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (tld[i].getField("id").equalsIgnoreCase(strPUOM)?"true":"false") + "\")"); 99 if (i<tld.length-1) resultado.append(",\n"); 100 } 101 resultado.append("\n)"); 102 } else resultado.append("null"); 103 resultado.append("\n),"); 104 } else { 105 FieldProvider [] tld = null; 106 try { 107 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "M_Product_UOM", "", Utility.getContext(this, vars, "#User_Org", "SLMovementProduct"), Utility.getContext(this, vars, "#User_Client", "SLMovementProduct"), 0); 108 Utility.fillSQLParameters(this, vars, null, comboTableData, "SLMovementProduct", ""); 109 tld = comboTableData.select(false); 110 comboTableData = null; 111 } catch (Exception ex) { 112 throw new ServletException(ex); 113 } 114 115 if (tld!=null && tld.length>0) { 116 resultado.append("new Array("); 117 for (int i=0;i<tld.length;i++) { 118 resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (tld[i].getField("id").equalsIgnoreCase(strPUOM)?"true":"false") + "\")"); 119 if (i<tld.length-1) resultado.append(",\n"); 120 } 121 resultado.append("\n)"); 122 } else resultado.append("null"); 123 resultado.append("\n),"); 124 } 125 resultado.append("new Array(\"EXECUTE\", \"displayLogic();\")\n"); 126 resultado.append(");"); 127 xmlDocument.setParameter("array", resultado.toString()); 128 xmlDocument.setParameter("frameName", "frameAplicacion"); 129 response.setContentType("text/html; charset=UTF-8"); 130 PrintWriter out = response.getWriter(); 131 out.println(xmlDocument.print()); 132 out.close(); 133 } 134 } 135 | Popular Tags |