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.erpCommon.utility.*; 25 import org.openbravo.data.FieldProvider; 26 import org.openbravo.utils.FormatUtilities; 27 import java.io.*; 28 import javax.servlet.*; 29 import javax.servlet.http.*; 30 import java.math.BigDecimal ; 31 32 import org.openbravo.erpCommon.businessUtility.Tax; 33 import org.openbravo.erpCommon.businessUtility.PAttributeSet; 34 import org.openbravo.erpCommon.businessUtility.PAttributeSetData; 35 36 public class SL_Order_Product 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 if (vars.commandIn("DEFAULT")) { 47 String strChanged = vars.getStringParameter("inpLastFieldChanged"); 48 if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged); 49 String strUOM = vars.getStringParameter("inpmProductId_UOM"); 50 String strPriceList = vars.getStringParameter("inpmProductId_PLIST"); 51 String strPriceStd = vars.getStringParameter("inpmProductId_PSTD"); 52 String strPriceLimit = vars.getStringParameter("inpmProductId_PLIM"); 53 String strCurrency = vars.getStringParameter("inpmProductId_CURR"); 54 String strQty = vars.getStringParameter("inpqtyordered"); 55 56 String strCBpartnerID = vars.getStringParameter("inpcBpartnerId"); 57 String strMProductID = vars.getStringParameter("inpmProductId"); 58 String strCBPartnerLocationID = vars.getStringParameter("inpcBpartnerLocationId"); 59 String strDateOrdered = vars.getStringParameter("inpdateordered"); 60 String strADOrgID = vars.getStringParameter("inpadOrgId"); 61 String strMWarehouseID = vars.getStringParameter("inpmWarehouseId"); 62 String strCOrderId = vars.getStringParameter("inpcOrderId"); 63 String strWindowId = vars.getStringParameter("inpwindowId"); 64 String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId); 65 String strTabId = vars.getStringParameter("inpTabId"); 66 67 try { 68 printPage(response, vars, strUOM, strPriceList, strPriceStd, strPriceLimit, strCurrency, strMProductID, strCBPartnerLocationID, strDateOrdered, strADOrgID, strMWarehouseID, strCOrderId, strWindowId, strIsSOTrx, strCBpartnerID, strTabId, strQty); 69 } catch (ServletException ex) { 70 pageErrorCallOut(response); 71 } 72 } else pageError(response); 73 } 74 75 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strUOM, String strPriceList, String strPriceStd, String strPriceLimit, String strCurrency, String strMProductID, String strCBPartnerLocationID, String strDateOrdered, String strADOrgID, String strMWarehouseID, String strCOrderId, String strWindowId, String strIsSOTrx, String strCBpartnerID, String strTabId, String strQty) throws IOException, ServletException { 76 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 77 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument(); 78 79 String strLastPriceSO = ""; 80 String strPriceActual = ""; 81 82 if (!strMProductID.equals("")) { 83 strLastPriceSO = SLOrderProductData.lastPriceSo(this, strCBpartnerID, strMProductID); 84 SLOrderProductData[] dataOrder = SLOrderProductData.select(this, strCOrderId); 85 86 if (log4j.isDebugEnabled()) log4j.debug("get Offers date: "+dataOrder[0].dateordered+" partner:" +dataOrder[0].cBpartnerId+" prod:"+ strMProductID +" std:"+strPriceStd.replace("\"", "")); 87 strPriceActual = SLOrderProductData.getOffersPrice(this, dataOrder[0].dateordered, dataOrder[0].cBpartnerId, strMProductID, (strPriceStd.equals("undefined")?"0":strPriceStd.replace("\"", "")), strQty, dataOrder[0].mPricelistId, dataOrder[0].id); 88 if (log4j.isDebugEnabled()) log4j.debug("get Offers price:"+strPriceActual); 89 90 dataOrder = null; 91 } else { 92 strUOM = strPriceList = strPriceLimit = strPriceStd = ""; 93 } 94 StringBuffer resultado = new StringBuffer (); 95 96 if (strPriceActual.equals("")) strPriceActual = strPriceStd; 97 98 if (strPriceList.startsWith("\"")) strPriceList = strPriceList.substring(1, strPriceList.length() - 1); 100 if (strPriceStd.startsWith("\"")) strPriceStd = strPriceStd.substring(1, strPriceStd.length() - 1); 101 BigDecimal priceList = (strPriceList.equals("")?new BigDecimal (0.0):new BigDecimal (strPriceList)); 102 BigDecimal priceStd = (strPriceStd.equals("")?new BigDecimal (0.0):new BigDecimal (strPriceStd)); 103 BigDecimal discount = new BigDecimal (0.0); 104 if (priceList.doubleValue() != discount.doubleValue()) { 105 discount = new BigDecimal ((priceList.doubleValue()-priceStd.doubleValue()) / priceList.doubleValue() * 100.0).setScale(2, BigDecimal.ROUND_HALF_UP); 106 } 107 108 resultado.append("var calloutName='SL_Order_Product';\n\n"); 109 resultado.append("var respuesta = new Array("); 110 resultado.append("new Array(\"inpcUomId\", " + (strUOM.equals("")?"\"\"":strUOM) + "),"); 111 resultado.append("new Array(\"inppricelist\", " + (strPriceList.equals("")?"\"0\"":strPriceList) + "),"); 112 resultado.append("new Array(\"inppricelimit\", " + (strPriceLimit.equals("")?"\"0\"":strPriceLimit) + "),"); 113 resultado.append("new Array(\"inppricestd\", " + (strPriceStd.equals("")?"\"0\"":strPriceStd) + "),"); 114 resultado.append("new Array(\"inppriceactual\", " + (strPriceActual.equals("")?"\"0\"":strPriceActual) + "),"); 115 resultado.append("new Array(\"inplastpriceso\", \"" + strLastPriceSO + "\"),"); 116 resultado.append("new Array(\"inpcCurrencyId\", " + (strCurrency.equals("")?"\"\"":strCurrency) + "),"); 117 resultado.append("new Array(\"inpdiscount\", \"" + discount.toString() + "\"),"); 118 if (!strMProductID.equals("")) { 119 PAttributeSetData[] dataPAttr = PAttributeSetData.selectProductAttr(this, strMProductID); 120 if (dataPAttr != null && dataPAttr.length>0) { 121 PAttributeSetData[] data2 = PAttributeSetData.select(this, dataPAttr[0].mAttributesetId); 122 if (PAttributeSet.isInstanceAttributeSet(data2)) { 123 resultado.append("new Array(\"inpmAttributesetinstanceId\", \"\"),"); 124 resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \"\"),"); 125 } else { 126 resultado.append("new Array(\"inpmAttributesetinstanceId\", \"" + dataPAttr[0].mAttributesetinstanceId + "\"),"); 127 resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \"" + FormatUtilities.replaceJS(dataPAttr[0].description) + "\"),"); 128 } 129 } 130 } 131 String strHasSecondaryUOM = SLOrderProductData.hasSecondaryUOM(this, strMProductID); 132 resultado.append("new Array(\"inphasseconduom\", " + strHasSecondaryUOM + "),\n"); 133 134 SLOrderTaxData [] data = SLOrderTaxData.select(this, strCOrderId); 135 136 String strCTaxID = Tax.get(this, strMProductID, data[0].dateordered, strADOrgID, strMWarehouseID, (data[0].billtoId.equals("")?strCBPartnerLocationID:data[0].billtoId), strCBPartnerLocationID, data[0].cProjectId, strIsSOTrx.equals("Y")); 137 138 resultado.append("new Array(\"inpcTaxId\", \"" + (strCTaxID.equals("")?"0":strCTaxID) + "\"),\n"); 139 resultado.append("new Array(\"inpmProductUomId\", "); 140 if (vars.getLanguage().equals("en_US")) { 143 FieldProvider [] tld = null; 144 try { 145 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "M_Product_UOM", "", Utility.getContext(this, vars, "#User_Org", "SLOrderProduct"), Utility.getContext(this, vars, "#User_Client", "SLOrderProduct"), 0); 146 Utility.fillSQLParameters(this, vars, null, comboTableData, "SLOrderProduct", ""); 147 tld = comboTableData.select(false); 148 comboTableData = null; 149 } catch (Exception ex) { 150 throw new ServletException(ex); 151 } 152 153 if (tld!=null && tld.length>0) { 154 resultado.append("new Array("); 155 for (int i=0;i<tld.length;i++) { 156 resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (i==0?"true":"false") + "\")"); 157 if (i<tld.length-1) resultado.append(",\n"); 158 } 159 resultado.append("\n)"); 160 } else resultado.append("null"); 161 resultado.append("\n),"); 162 } else { 163 FieldProvider [] tld = null; 164 try { 165 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "M_Product_UOM", "", Utility.getContext(this, vars, "#User_Org", "SLOrderProduct"), Utility.getContext(this, vars, "#User_Client", "SLOrderProduct"), 0); 166 Utility.fillSQLParameters(this, vars, null, comboTableData, "SLOrderProduct", ""); 167 tld = comboTableData.select(false); 168 comboTableData = null; 169 } catch (Exception ex) { 170 throw new ServletException(ex); 171 } 172 173 if (tld!=null && tld.length>0) { 174 resultado.append("new Array("); 175 for (int i=0;i<tld.length;i++) { 176 resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (i==0?"true":"false") + "\")"); 177 if (i<tld.length-1) resultado.append(",\n"); 178 } 179 resultado.append("\n)"); 180 } else resultado.append("null"); 181 resultado.append("\n),"); 182 } 183 resultado.append("new Array(\"EXECUTE\", \"displayLogic();\"),\n"); 184 resultado.append("new Array(\"CURSOR_FIELD\", \"inpqtyordered\")\n"); 186 if (!strHasSecondaryUOM.equals("0")) resultado.append(", new Array(\"CURSOR_FIELD\", \"inpquantityorder\")\n"); 187 188 resultado.append(");"); 189 xmlDocument.setParameter("array", resultado.toString()); 190 xmlDocument.setParameter("frameName", "frameAplicacion"); 191 response.setContentType("text/html; charset=UTF-8"); 192 PrintWriter out = response.getWriter(); 193 out.println(xmlDocument.print()); 194 out.close(); 195 } 196 } 197 | Popular Tags |