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 java.io.*; 27 import java.math.BigDecimal ; 28 import javax.servlet.*; 29 import javax.servlet.http.*; 30 31 public class SL_Order_Amt extends HttpSecureAppServlet { 32 33 static final BigDecimal ZERO = new BigDecimal (0.0); 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 strChanged = vars.getStringParameter("inpLastFieldChanged"); 44 if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged); 45 String strQtyOrdered = vars.getStringParameter("inpqtyordered"); 46 String strPriceActual = vars.getStringParameter("inppriceactual"); 47 String strDiscount = vars.getStringParameter("inpdiscount"); 48 String strPriceLimit = vars.getStringParameter("inppricelimit"); 49 String strPriceList = vars.getStringParameter("inppricelist"); 50 String strPriceStd = vars.getStringParameter("inppricestd"); 51 String strCOrderId = vars.getStringParameter("inpcOrderId"); 52 String strProduct = vars.getStringParameter("inpmProductId"); 53 String strUOM = vars.getStringParameter("inpcUomId"); 54 String strAttribute = vars.getStringParameter("inpmAttributesetinstanceId"); 55 String strTabId = vars.getStringParameter("inpTabId"); 56 String strQty = vars.getStringParameter("inpqtyordered"); 57 58 try { 59 printPage(response, vars, strChanged, strQtyOrdered, strPriceActual, strDiscount, strPriceLimit, strPriceList, strCOrderId, strProduct, strUOM, strAttribute, strTabId, strQty, strPriceStd); 60 } catch (ServletException ex) { 61 pageErrorCallOut(response); 62 } 63 } else pageError(response); 64 } 65 66 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strChanged, String strQtyOrdered, String strPriceActual, String strDiscount, String strPriceLimit, String strPriceList, String strCOrderId, String strProduct, String strUOM, String strAttribute, String strTabId, String strQty, String strPriceStd) throws IOException, ServletException { 67 if (log4j.isDebugEnabled()){ log4j.debug("Output: dataSheet"); log4j.debug("CHANGED:"+strChanged);} 68 69 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument(); 70 SLOrderAmtData[] data = SLOrderAmtData.select(this, strCOrderId); 71 SLOrderStockData[] data1 = SLOrderStockData.select(this, strProduct); 72 String strPrecision = "0", strPricePrecision="0"; 73 String strStockSecurity = "0"; 74 String strEnforceAttribute = "N"; 75 String Issotrx = SLOrderStockData.isSotrx(this, strCOrderId); 76 String strStockNoAttribute; 77 String strStockAttribute; 78 if (data1!=null && data1.length>0) { 79 strStockSecurity = data1[0].stock; 80 strEnforceAttribute = data1[0].enforceAttribute; 81 } 82 boolean enforcedLimit=false; 83 if (data!=null && data.length>0) { 85 strPrecision = data[0].stdprecision.equals("")?"0":data[0].stdprecision; 86 strPricePrecision = data[0].priceprecision.equals("")?"0":data[0].priceprecision; 87 enforcedLimit = (data[0].enforcepricelimit.equals("Y")?true:false); 88 } 89 int StdPrecision = Integer.valueOf(strPrecision).intValue(); 90 int PricePrecision = Integer.valueOf(strPricePrecision).intValue(); 91 92 BigDecimal qtyOrdered, priceActual, discount, priceLimit, priceList, stockSecurity, stockNoAttribute, stockAttribute, resultStock, priceStd; 93 94 stockSecurity = new BigDecimal (strStockSecurity); 95 qtyOrdered = (strQtyOrdered.equals("")?ZERO:new BigDecimal (strQtyOrdered)); 96 priceActual = (strPriceActual.equals("")?ZERO:(new BigDecimal (strPriceActual))).setScale(PricePrecision, BigDecimal.ROUND_HALF_UP); 97 discount = (strDiscount.equals("")?ZERO:new BigDecimal (strDiscount)); 98 priceLimit = (strPriceLimit.equals("")?ZERO:(new BigDecimal (strPriceLimit))).setScale(PricePrecision, BigDecimal.ROUND_HALF_UP); 99 priceList = (strPriceList.equals("")?ZERO:new BigDecimal (strPriceList)); 100 priceStd = (strPriceStd.equals("")?ZERO:new BigDecimal (strPriceStd)); 101 108 109 110 StringBuffer resultado = new StringBuffer (); 111 resultado.append("var calloutName='SL_Order_Amt';\n\n"); 112 resultado.append("var respuesta = new Array("); 113 114 SLOrderProductData[] dataOrder = SLOrderProductData.select(this, strCOrderId); 116 if (strChanged.equals("inppriceactual")) 117 { 118 if (log4j.isDebugEnabled()) log4j.debug("priceActual:" + Double.toString(priceActual.doubleValue())); 119 priceStd = new BigDecimal (SLOrderProductData.getOffersStdPrice(this, dataOrder[0].cBpartnerId, strPriceActual.replace("\"", ""), strProduct, dataOrder[0].dateordered, strQty, dataOrder[0].mPricelistId, dataOrder[0].id)); 120 resultado.append("new Array(\"inppricestd\", \"" + priceStd.toString() + "\"),"); 122 } 123 124 132 133 if (strChanged.equals("inppricelist")||strChanged.equals("inppriceactual")) { 135 if (priceList.doubleValue() == 0.0) discount = ZERO; 136 else { 137 if (log4j.isDebugEnabled()) log4j.debug("pricelist:" + Double.toString(priceList.doubleValue())); 138 if (log4j.isDebugEnabled()) log4j.debug("priceActual:" + Double.toString(priceActual.doubleValue())); 139 discount = new BigDecimal ((priceList.doubleValue()-priceStd.doubleValue()) / priceList.doubleValue() * 100.0); 140 } 141 if (log4j.isDebugEnabled()) log4j.debug("Discount: " + discount.toString()); 142 if (discount.scale() > StdPrecision) discount = discount.setScale(StdPrecision, BigDecimal.ROUND_HALF_UP); 143 if (log4j.isDebugEnabled()) log4j.debug("Discount rounded: " + discount.toString()); 144 resultado.append("new Array(\"inpdiscount\", \"" + discount.toString() + "\"),"); 145 } else if (strChanged.equals("inpqtyordered")) { priceActual = new BigDecimal (SLOrderProductData.getOffersPrice(this, dataOrder[0].dateordered, dataOrder[0].cBpartnerId, strProduct, priceStd.toString(), strQty, dataOrder[0].mPricelistId, dataOrder[0].id)); 147 if (priceActual.scale() > PricePrecision) priceActual = priceActual.setScale(PricePrecision, BigDecimal.ROUND_HALF_UP); 148 resultado.append("new Array(\"inppriceactual\", \"" + priceActual.toString() + "\"),"); 149 } else if (strChanged.equals("inpdiscount")){ BigDecimal discount1 = null; 151 if (priceList.doubleValue() != 0) discount1 = new BigDecimal ((priceList.doubleValue()-priceStd.doubleValue()) / priceList.doubleValue() * 100.0).setScale(StdPrecision, BigDecimal.ROUND_HALF_UP); 152 else discount1 = new BigDecimal (0); 153 BigDecimal discount2 = discount.setScale(StdPrecision, BigDecimal.ROUND_HALF_UP); 154 if (discount1.compareTo(discount2)!=0) { 156 priceStd = new BigDecimal (priceList.doubleValue()-(priceList.doubleValue()*discount.doubleValue()/100) ); 157 priceActual = new BigDecimal (SLOrderProductData.getOffersPrice(this, dataOrder[0].dateordered, dataOrder[0].cBpartnerId, strProduct, priceStd.toString(), strQty, dataOrder[0].mPricelistId, dataOrder[0].id)); 158 if (priceStd.scale() > PricePrecision) priceStd = priceStd.setScale(PricePrecision, BigDecimal.ROUND_HALF_UP); 159 if (priceActual.scale() > PricePrecision) priceActual = priceActual.setScale(PricePrecision, BigDecimal.ROUND_HALF_UP); 160 resultado.append("new Array(\"inppriceactual\", \"" + priceActual.toString() + "\"),"); 161 resultado.append("new Array(\"inppricestd\", \"" + priceStd.toString() + "\"),"); 162 } 163 } 164 165 166 if (Issotrx.equals("Y")) { 167 if (!strStockSecurity.equals("0")) { 168 if (qtyOrdered.doubleValue() != 0.0) { 169 if (strEnforceAttribute.equals("N")) { 170 strStockNoAttribute = SLOrderStockData.totalStockNoAttribute(this, strProduct, strUOM); 171 stockNoAttribute = new BigDecimal (strStockNoAttribute); 172 resultStock = new BigDecimal (stockNoAttribute.doubleValue() - qtyOrdered.doubleValue()); 173 if (stockSecurity.doubleValue() > resultStock.doubleValue()) { 174 resultado.append("new Array('MESSAGE', \"" + FormatUtilities.replaceJS(Utility.messageBD(this, "StockLimit", vars.getLanguage())) + "\"),"); 175 } 176 } else { 177 if (!strAttribute.equals("") && strAttribute != null) { 178 strStockAttribute = SLOrderStockData.totalStockAttribute(this, strProduct, strUOM, strAttribute); 179 stockAttribute = new BigDecimal (strStockAttribute); 180 resultStock = new BigDecimal (stockAttribute.doubleValue() - qtyOrdered.doubleValue()); 181 if (stockSecurity.doubleValue() > resultStock.doubleValue()) { 182 resultado.append("new Array('MESSAGE', \"" + FormatUtilities.replaceJS(Utility.messageBD(this, "StockLimit", vars.getLanguage())) + "\"),"); 183 } 184 } 185 } 186 } 187 } 188 } 189 if (log4j.isDebugEnabled()) log4j.debug(resultado.toString()); 190 if (!strChanged.equals("inpqtyordered")) { boolean enforced = SLOrderAmtData.listPriceType(this, strPriceList); 192 if (enforced && priceLimit.doubleValue() != 0.0 && priceActual.compareTo(priceLimit) < 0) resultado.append("new Array('MESSAGE', \"" + Utility.messageBD(this, "UnderLimitPrice", vars.getLanguage()) + "\")"); 194 } 195 196 BigDecimal lineNetAmt = qtyOrdered.multiply(priceActual); 198 if (lineNetAmt.scale() > StdPrecision) lineNetAmt = lineNetAmt.setScale(StdPrecision, BigDecimal.ROUND_HALF_UP); 199 resultado.append("new Array(\"inplinenetamt\", \"" + lineNetAmt.toString() + "\")"); 200 201 resultado.append(");"); 202 xmlDocument.setParameter("array", resultado.toString()); 203 xmlDocument.setParameter("frameName", "frameAplicacion"); 204 response.setContentType("text/html; charset=UTF-8"); 205 PrintWriter out = response.getWriter(); 206 out.println(xmlDocument.print()); 207 out.close(); 208 } 209 } 210 | Popular Tags |