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 import org.openbravo.erpCommon.utility.DateTimeData; 32 import org.openbravo.erpCommon.ad_combos.PriceListVersionComboData; 33 34 public class SL_Invoice_Amt extends HttpSecureAppServlet { 35 36 static final BigDecimal ZERO = new BigDecimal (0.0); 37 38 public void init (ServletConfig config) { 39 super.init(config); 40 boolHist = false; 41 } 42 43 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 44 VariablesSecureApp vars = new VariablesSecureApp(request); 45 if (vars.commandIn("DEFAULT")) { 46 String strChanged = vars.getStringParameter("inpLastFieldChanged"); 47 if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged); 48 String strQtyInvoice = vars.getStringParameter("inpqtyinvoiced"); 49 String strPriceActual = vars.getStringParameter("inppriceactual"); 50 String strPriceLimit = vars.getStringParameter("inppricelimit"); 51 String strInvoiceId = vars.getStringParameter("inpcInvoiceId"); 52 String strProduct = vars.getStringParameter("inpmProductId"); 53 String strTabId = vars.getStringParameter("inpTabId"); 54 String strPriceList = vars.getStringParameter("inppricelist"); 55 56 try { 57 printPage(response, vars, strChanged, strQtyInvoice, strPriceActual, strInvoiceId, strProduct, strPriceLimit, strTabId, strPriceList); 58 } catch (ServletException ex) { 59 pageErrorCallOut(response); 60 } 61 } else pageError(response); 62 } 63 64 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strChanged, String strQtyInvoice, String strPriceActual, String strInvoiceId, String strProduct, String strPriceLimit, String strTabId, String strPriceList) throws IOException, ServletException { 65 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 66 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument(); 67 SLInvoiceAmtData[] data = SLInvoiceAmtData.select(this, strInvoiceId); 68 String strPrecision = "0", strPricePrecision="0"; 69 boolean enforcedLimit=false; 70 if (data!=null && data.length>0) { 71 strPrecision = data[0].stdprecision; 72 strPricePrecision = data[0].priceprecision; 73 enforcedLimit = (data[0].enforcepricelimit.equals("Y")?true:false); 74 } 75 int StdPrecision = Integer.valueOf(strPrecision).intValue(); 76 int PricePrecision = Integer.valueOf(strPricePrecision).intValue(); 77 78 BigDecimal qtyInvoice, priceActual, LineNetAmt, priceLimit; 79 80 if (strQtyInvoice.equals("")) qtyInvoice=ZERO; 81 else qtyInvoice = new BigDecimal (strQtyInvoice); 82 if (strChanged.equals("inpqtyinvoiced")||strChanged.equals("inppricelist")) 83 { 84 if (log4j.isDebugEnabled()) log4j.debug("strPriceList: "+strPriceList.replace("\"", "")+" product:"+strProduct+" qty:"+strQtyInvoice); 85 strPriceActual = SLOrderProductData.getOffersPriceInvoice(this, data[0].dateinvoiced, data[0].cBpartnerId, strProduct, strPriceList.replace("\"", ""), strQtyInvoice, data[0].mPricelistId, data[0].id); 86 } 87 88 89 if (strPriceActual.equals("")) strPriceActual = "0"; 90 if (strPriceLimit.equals("")) strPriceLimit = "0"; 91 92 if (log4j.isDebugEnabled()) log4j.debug("strPriceActual: "+strPriceActual); 93 if (log4j.isDebugEnabled()) log4j.debug("strPriceLimit: "+strPriceLimit); 94 priceActual = (new BigDecimal (strPriceActual)).setScale(PricePrecision, BigDecimal.ROUND_HALF_UP); 95 priceLimit = (new BigDecimal (strPriceLimit)).setScale(PricePrecision, BigDecimal.ROUND_HALF_UP); 96 97 98 LineNetAmt = qtyInvoice.multiply(priceActual); 99 100 if (LineNetAmt.scale() > StdPrecision) 101 LineNetAmt = LineNetAmt.setScale(StdPrecision, BigDecimal.ROUND_HALF_UP); 102 103 104 StringBuffer resultado = new StringBuffer (); 105 106 resultado.append("var calloutName='SL_Invoice_Amt';\n\n"); 107 resultado.append("var respuesta = new Array("); 108 if (enforcedLimit) { 109 String strPriceVersion = ""; 110 PriceListVersionComboData[] data1 = PriceListVersionComboData.selectActual(this, data[0].mPricelistId, DateTimeData.today(this), Utility.getContext(this, vars, "#User_Client", "SLInvoiceAmt")); 111 if (data1!=null && data1.length>0) strPriceVersion = data1[0].mPricelistVersionId; 112 BigDecimal lineLimit = new BigDecimal (SLInvoiceAmtData.selectPriceLimit(this, strPriceVersion, strProduct)); 113 if (priceLimit.doubleValue() != 0.0 && priceActual.compareTo(priceLimit) < 0) resultado.append("new Array('MESSAGE', \"" + FormatUtilities.replaceJS(Utility.messageBD(this, "UnderLimitPrice", vars.getLanguage())) + "\"), "); 114 } 115 resultado.append("new Array(\"inplinenetamt\", \"" + LineNetAmt.toString() + "\"),"); 116 resultado.append("new Array(\"inppriceactual\", \"" + priceActual.toString() + "\")"); 117 resultado.append(");"); 118 xmlDocument.setParameter("array", resultado.toString()); 119 xmlDocument.setParameter("frameName", "frameAplicacion"); 120 response.setContentType("text/html; charset=UTF-8"); 121 PrintWriter out = response.getWriter(); 122 out.println(xmlDocument.print()); 123 124 125 out.close(); 126 } 127 } 128 | Popular Tags |