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 31 import org.openbravo.erpCommon.businessUtility.Tax; 32 import org.openbravo.erpCommon.businessUtility.PAttributeSet; 33 import org.openbravo.erpCommon.businessUtility.PAttributeSetData; 34 35 public class SL_Invoice_Product extends HttpSecureAppServlet { 36 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 strUOM = vars.getStringParameter("inpmProductId_UOM"); 49 String strPriceList = vars.getStringParameter("inpmProductId_PLIST"); 50 String strPriceStd = vars.getStringParameter("inpmProductId_PSTD"); 51 String strPriceLimit = vars.getStringParameter("inpmProductId_PLIM"); 52 String strCurrency = vars.getStringParameter("inpmProductId_CURR"); 53 String strQty = vars.getStringParameter("inpqtyinvoiced"); 54 55 String strMProductID = vars.getStringParameter("inpmProductId"); 56 String strADOrgID = vars.getStringParameter("inpadOrgId"); 57 String strCInvoiceID = vars.getStringParameter("inpcInvoiceId"); 58 String strWindowId = vars.getStringParameter("inpwindowId"); 59 String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId); 60 String strWharehouse = Utility.getContext(this, vars, "#M_Warehouse_ID", strWindowId); 61 String strTabId = vars.getStringParameter("inpTabId"); 62 63 try { 64 printPage(response, vars, strUOM, strPriceList, strPriceStd, strPriceLimit, strCurrency, strMProductID, strADOrgID, strCInvoiceID, strIsSOTrx, strWharehouse, strTabId, strQty); 65 } catch (ServletException ex) { 66 pageErrorCallOut(response); 67 } 68 } else pageError(response); 69 } 70 71 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strUOM, String strPriceList, String strPriceStd, String strPriceLimit, String strCurrency, String strMProductID, String strADOrgID, String strCInvoiceID, String strIsSOTrx, String strWharehouse, String strTabId, String strQty) throws IOException, ServletException { 72 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 73 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument(); 74 75 76 String strPriceActual=""; 77 if (!strMProductID.equals("")) { 78 SLOrderProductData[] dataInvoice = SLOrderProductData.selectInvoice(this, strCInvoiceID); 79 80 if (log4j.isDebugEnabled()) log4j.debug("get Offers date: "+dataInvoice[0].dateinvoiced+" partner:" +dataInvoice[0].cBpartnerId+" prod:"+ strMProductID +" std:"+strPriceStd.replace("\"", "")); 81 strPriceActual = SLOrderProductData.getOffersPriceInvoice(this, dataInvoice[0].dateinvoiced, dataInvoice[0].cBpartnerId, strMProductID, strPriceStd.replace("\"", ""), strQty, dataInvoice[0].mPricelistId, dataInvoice[0].id); 82 if (log4j.isDebugEnabled()) log4j.debug("get Offers price:"+strPriceActual); 83 84 dataInvoice=null; 85 } 86 StringBuffer resultado = new StringBuffer (); 87 88 if (strPriceActual.equals("")) strPriceActual = strPriceStd; 89 90 resultado.append("var calloutName='SL_Invoice_Product';\n\n"); 91 resultado.append("var respuesta = new Array("); 92 resultado.append("new Array(\"inpcUomId\", " + (strUOM.equals("")?"\"\"":strUOM) + "),"); 93 resultado.append("new Array(\"inppricelist\", " + (strPriceList.equals("")?"\"\"":strPriceList) + "),"); 94 resultado.append("new Array(\"inppricelimit\", " + (strPriceLimit.equals("")?"\"\"":strPriceLimit) + "),"); 95 resultado.append("new Array(\"inppricestd\", " + (strPriceStd.equals("")?"\"\"":strPriceStd) + "),"); 96 resultado.append("new Array(\"inppriceactual\", " + (strPriceActual.equals("")?"\"\"":strPriceActual) + "),"); 97 PAttributeSetData[] dataPAttr = PAttributeSetData.selectProductAttr(this, strMProductID); 98 if (dataPAttr!=null && dataPAttr.length>0){ 99 PAttributeSetData[] data2 = PAttributeSetData.select(this, dataPAttr[0].mAttributesetId); 100 if (PAttributeSet.isInstanceAttributeSet(data2)) { 101 resultado.append("new Array(\"inpmAttributesetinstanceId\", \"\"),"); 102 resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \"\"),"); 103 } else { 104 resultado.append("new Array(\"inpmAttributesetinstanceId\", \"" + dataPAttr[0].mAttributesetinstanceId + "\"),"); 105 resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \"" + FormatUtilities.replaceJS(dataPAttr[0].description) + "\"),"); 106 } 107 } 108 String strHasSecondaryUOM = SLOrderProductData.hasSecondaryUOM(this, strMProductID); 109 resultado.append("new Array(\"inphasseconduom\", " + strHasSecondaryUOM + "),\n"); 110 resultado.append("new Array(\"inpcCurrencyId\", " + (strCurrency.equals("")?"\"\"":strCurrency) + ")"); 111 112 SLInvoiceTaxData [] data = SLInvoiceTaxData.select(this, strCInvoiceID); 113 if (data!=null && data.length>0) { 114 String strCTaxID = Tax.get(this, strMProductID, data[0].dateinvoiced, strADOrgID, strWharehouse, data[0].cBpartnerLocationId, data[0].cBpartnerLocationId, data[0].cProjectId, strIsSOTrx.equals("Y")); 115 116 resultado.append(", new Array(\"inpcTaxId\", \"" + strCTaxID + "\")"); 117 } 118 119 resultado.append(", new Array(\"inpmProductUomId\", "); 120 123 FieldProvider [] tld = null; 124 try { 125 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); 126 Utility.fillSQLParameters(this, vars, null, comboTableData, "SLOrderProduct", ""); 127 tld = comboTableData.select(false); 128 comboTableData = null; 129 } catch (Exception ex) { 130 throw new ServletException(ex); 131 } 132 133 if (tld!=null && tld.length>0) { 134 resultado.append("new Array("); 135 for (int i=0;i<tld.length;i++) { 136 resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (i==0?"true":"false") + "\")"); 137 if (i<tld.length-1) resultado.append(",\n"); 138 } 139 resultado.append("\n)"); 140 } else resultado.append("null"); 141 resultado.append("\n),"); 142 resultado.append("new Array(\"EXECUTE\", \"displayLogic();\")\n"); 143 144 145 resultado.append(");"); 146 xmlDocument.setParameter("array", resultado.toString()); 147 xmlDocument.setParameter("frameName", "frameAplicacion"); 148 response.setContentType("text/html; charset=UTF-8"); 149 PrintWriter out = response.getWriter(); 150 out.println(xmlDocument.print()); 151 out.close(); 152 } 153 } 154 | Popular Tags |