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 java.io.*; 25 import javax.servlet.*; 26 import javax.servlet.http.*; 27 28 import org.openbravo.erpCommon.utility.DateTimeData; 29 import java.math.BigDecimal ; 30 31 32 public class SE_Expense_Product extends HttpSecureAppServlet { 33 34 35 public void init (ServletConfig config) { 36 super.init(config); 37 boolHist = false; 38 } 39 40 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 41 VariablesSecureApp vars = new VariablesSecureApp(request); 42 if (vars.commandIn("DEFAULT")) { 43 String strDateexpense = vars.getStringParameter("inpdateexpense", DateTimeData.today(this)); 44 String strmProductId = vars.getStringParameter("inpmProductId"); 45 String strsTimeexpenseId = vars.getStringParameter("inpsTimeexpenseId"); 47 String strqty = vars.getStringParameter("inpqty"); 48 String strChanged = vars.getStringParameter("inpLastFieldChanged"); 49 String strTabId = vars.getStringParameter("inpTabId"); 50 51 try { 52 printPage(response, vars, strDateexpense, strmProductId, strsTimeexpenseId, strqty, strChanged, strTabId); 53 } catch (ServletException ex) { 54 pageErrorCallOut(response); 55 } 56 } else pageError(response); 57 } 58 59 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strDateexpense, String strmProductId, String strsTimeexpenseId, String strqty, String strChanged, String strTabId) throws IOException, ServletException { 60 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 61 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument(); 62 String strmPricelistId = SEExpenseProductData.priceList(this, strsTimeexpenseId); 63 SEExpenseProductData[] data = SEExpenseProductData.select(this, strmProductId, strmPricelistId); 64 String strUOM = SEExpenseProductData.selectUOM(this, strmProductId); 65 boolean noPrice = true; 66 String priceActual = ""; 67 String CCurrencyID = ""; 68 BigDecimal Qty = new BigDecimal (strqty); 69 BigDecimal Amount = null; 70 for (int i=0;data!=null && i<data.length && noPrice;i++){ 71 if (data[i].validfrom == null || data[i].validfrom.equals("") || !DateTimeData.compare(this, strDateexpense, data[i].validfrom).equals("-1")){ 72 noPrice = false; 73 priceActual = data[i].pricestd; 75 if (priceActual.equals("")) 76 priceActual = data[i].pricelist; 77 if (priceActual.equals("")) 78 priceActual = data[i].pricelimit; 79 CCurrencyID = data[i].cCurrencyId; 81 } 82 } 83 if (noPrice){ 84 data = SEExpenseProductData.selectBasePriceList(this, strmProductId, strmPricelistId); 85 for (int i=0;data!=null && i<data.length && noPrice;i++){ 86 if (data[i].validfrom == null || data[i].validfrom.equals("") || !DateTimeData.compare(this, strDateexpense, data[i].validfrom).equals("-1")){ 87 noPrice = false; 88 priceActual = data[i].pricestd; 90 if (priceActual.equals("")) 91 priceActual = data[i].pricelist; 92 if (priceActual.equals("")) 93 priceActual = data[i].pricelimit; 94 CCurrencyID = data[i].cCurrencyId; 96 } 97 } 98 } 99 StringBuffer resultado = new StringBuffer (); 100 resultado.append("var calloutName='SE_Expense_Product';\n\n"); 101 resultado.append("var respuesta = new Array("); 102 resultado.append("new Array(\"inpcUomId\", " + (strUOM.equals("")?"\"\"":strUOM) + ")\n"); 103 if (!priceActual.equals("") && !CCurrencyID.equals("")) { 104 if (!priceActual.equals("")) Amount = new BigDecimal (priceActual); 105 else Amount = new BigDecimal ("0.0"); 106 priceActual = Amount.multiply(Qty).toString(); 107 resultado.append(", new Array(\"inpexpenseamt\", \"" + priceActual + "\")"); 108 if (strChanged.equals("inpmProductId"))resultado.append(",new Array(\"inpcCurrencyId\", \"" + CCurrencyID + "\")"); 109 } 110 111 resultado.append(");"); 112 xmlDocument.setParameter("array", resultado.toString()); 113 xmlDocument.setParameter("frameName", "frameAplicacion"); 114 response.setContentType("text/html; charset=UTF-8"); 115 PrintWriter out = response.getWriter(); 116 out.println(xmlDocument.print()); 117 out.close(); 118 } 119 } 120 | Popular Tags |