1 19 20 package org.openbravo.erpCommon.ad_forms; 21 22 import org.openbravo.erpCommon.utility.SequenceIdData; 23 import org.openbravo.erpCommon.utility.Utility; 24 import org.openbravo.erpCommon.utility.ComboTableData; 25 import org.openbravo.base.secureApp.HttpSecureAppServlet; 26 import org.openbravo.base.secureApp.VariablesSecureApp; 27 import org.openbravo.xmlEngine.XmlDocument; 28 import java.io.*; 29 import javax.servlet.*; 30 import javax.servlet.http.*; 31 32 import org.openbravo.data.FieldProvider; 33 import org.openbravo.erpCommon.businessUtility.Tax; 34 35 import java.sql.Connection ; 37 38 public class InvoiceVendorMultiline_Lines extends HttpSecureAppServlet { 39 40 protected String windowId = ""; 41 protected String tabId = ""; 42 protected String tabName = ""; 43 protected String windowName = ""; 44 protected String windowNameEnUS = ""; 45 protected String tabNameEnUS = ""; 46 protected String tableId = ""; 47 private static final String formClassName = "org.openbravo.erpCommon.ad_forms.InvoiceVendorMultiline"; 48 49 public void init (ServletConfig config) { 50 super.init(config); 51 boolHist = false; 52 } 53 54 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 55 VariablesSecureApp vars = new VariablesSecureApp(request); 56 57 if (!Utility.hasFormAccess(this, vars, "", formClassName)) { 58 bdError(response, "AccessTableNoView", vars.getLanguage()); 59 return; 60 } 61 { 62 InvoiceVendorMultilineData[] data = InvoiceVendorMultilineData.selectWindowData(this, vars.getLanguage(), formClassName); 63 if (data==null || data.length==0) { 64 throw new ServletException(formClassName + ": Error on window data"); 65 } 66 windowId = data[0].adWindowId; 67 tabId = data[0].adTabId; 68 tableId = data[0].adTableId; 69 tabName = data[0].tabname; 70 windowName = data[0].windowname; 71 tabNameEnUS = data[0].tabnameEnUs; 72 windowNameEnUS = data[0].windownameEnUs; 73 } 74 75 if (vars.commandIn("DEFAULT")) { 76 String strInvoice = vars.getStringParameter("inpcInvoiceId"); 77 printPageDataSheet(response, vars, strInvoice); 78 } else if (vars.commandIn("HIDDEN", "SAVE_EDIT", "SAVE_NEW", "DELETE")) { 79 printPageHidden(response, vars); 80 } else if (vars.commandIn("PRODUCT_CALLOUT")) { 81 printPageCallOut(response, vars); 82 } else pageError(response); 83 } 84 85 void printPageCallOut(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 86 response.setContentType("text/plain"); 87 response.setHeader("Cache-Control", "no-cache"); 88 PrintWriter out = response.getWriter(); 89 String strMProductID = vars.getStringParameter("inpmProductId"); 90 String strcInvoiceId = vars.getStringParameter("inpcInvoiceId"); 91 String strWarehouse = Utility.getContext(this, vars, "#M_Warehouse_ID", windowId); 92 String strDateFormat = vars.getSessionValue("#AD_SqlDateFormat"); 93 InvoiceVendorMultilineData[] data = InvoiceVendorMultilineData.select(this, strDateFormat, vars.getLanguage(), strcInvoiceId); 94 if (data!=null && data.length>0) { 95 out.print(Tax.get(this, strMProductID, data[0].dateinvoiced, data[0].adOrgId, strWarehouse, data[0].cBpartnerLocationId, data[0].cBpartnerLocationId, data[0].cProjectId, data[0].issotrx.equals("Y"))); 96 } else { 97 out.print(""); 98 } 99 out.close(); 100 } 101 102 void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strInvoice) 103 throws IOException, ServletException { 104 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 105 InvoiceVendorMultilineLinesData[] data = InvoiceVendorMultilineLinesData.select(this, vars.getLanguage(), strInvoice); 106 if (!strInvoice.equals("") && (data==null || data.length==0)) data = InvoiceVendorMultilineLinesData.set(InvoiceVendorMultilineLinesData.selectNextLine(this, strInvoice)); 107 108 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_forms/InvoiceVendorMultiline_Lines").createXmlDocument(); 109 110 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 111 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 112 xmlDocument.setParameter("cInvoiceId",strInvoice); 113 String strTax = ""; 114 if (data!=null && data.length>0) strTax = data[0].cTaxId; 115 116 try { 117 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "C_Tax_ID", "C_Tax", "", Utility.getContext(this, vars, "#User_Org", windowId), Utility.getContext(this, vars, "#User_Client", windowId), 0); 118 Utility.fillSQLParameters(this, vars, null, comboTableData, windowId, strTax); 119 xmlDocument.setData("reportC_Tax_ID","liststructure", comboTableData.select(false)); 120 comboTableData = null; 121 } catch (Exception ex) { 122 throw new ServletException(ex); 123 } 124 125 xmlDocument.setData("structure1", data); 126 127 response.setContentType("text/html; charset=UTF-8"); 128 PrintWriter out = response.getWriter(); 129 out.println(xmlDocument.print()); 130 out.close(); 131 } 132 133 InvoiceVendorMultilineLinesData getEditVariables(VariablesSecureApp vars) throws IOException,ServletException { 134 InvoiceVendorMultilineLinesData data = new InvoiceVendorMultilineLinesData(); 135 136 data.cInvoicelineId = vars.getStringParameter("inpcInvoicelineId"); 137 data.cInvoiceId = vars.getRequestGlobalVariable("inpcInvoiceId", windowId + "|C_Invoice_ID"); 138 data.adClientId = vars.getGlobalVariable("inpadClientId", windowId + "|AD_Client_ID", vars.getClient()); 139 data.adOrgId = vars.getGlobalVariable("inpadOrgId", windowId + "|AD_Org_ID", vars.getOrg()); 140 data.isactive = vars.getStringParameter("inpisactive", "Y"); 141 data.cOrderlineId = vars.getStringParameter("inpcOrderlineId"); 142 data.mInoutlineId = vars.getStringParameter("inpmInoutlineId"); 143 data.line = vars.getStringParameter("inpline"); 144 data.description = vars.getStringParameter("inpdescription"); 145 data.mProductId = vars.getStringParameter("inpmProductId" + data.cInvoicelineId); 146 data.qtyinvoiced = vars.getStringParameter("inpqtyinvoiced"); 147 data.pricelist = vars.getStringParameter("inppricelist", "1"); 148 data.priceactual = vars.getStringParameter("inppriceactual", "1"); 149 data.pricelimit = vars.getStringParameter("inppricelimit", "1"); 150 data.pricestd = vars.getStringParameter("inppricestd", "1"); 151 data.cChargeId = vars.getStringParameter("inpcChargeId"); 152 data.chargeamt = vars.getStringParameter("inpchargeamt", "0"); 153 data.cUomId = vars.getStringParameter("inpcUomId"); 154 data.cTaxId = vars.getStringParameter("inpcTaxId"); 155 data.sResourceassignmentId = vars.getStringParameter("inpsResourceassignmentId"); 156 data.aAssetId = vars.getStringParameter("inpaAssetId"); 157 data.taxamt = vars.getStringParameter("inptaxamt", "0"); 158 data.mAttributesetinstanceId = vars.getStringParameter("inpmAttributesetinstanceId"); 159 data.isdescription = vars.getStringParameter("inpisdescription", "N"); 160 data.quantityorder = vars.getStringParameter("inpquantityorder"); 161 data.mProductUomId = vars.getStringParameter("inpmProductUomId"); 162 data.cInvoiceDiscountId = vars.getStringParameter("inpcInvoiceDiscountId"); 163 164 data.createdby = vars.getUser(); 165 data.updatedby = vars.getUser(); 166 167 if (data.cUomId.equals("") && !data.mProductId.equals("")) data.cUomId = InvoiceVendorMultilineLinesData.selectUOM(this, data.mProductId); 168 169 if (log4j.isDebugEnabled()) log4j.debug("C_InvoiceLine_ID: " + data.cInvoicelineId); 170 if (log4j.isDebugEnabled()) log4j.debug("C_Invoice_ID: " + data.cInvoiceId); 171 if (log4j.isDebugEnabled()) log4j.debug("AD_Client_ID: " + data.adClientId); 172 if (log4j.isDebugEnabled()) log4j.debug("AD_Org_ID: " + data.adOrgId); 173 if (log4j.isDebugEnabled()) log4j.debug("IsActive: " + data.isactive); 174 if (log4j.isDebugEnabled()) log4j.debug("C_OrderLine_ID: " + data.cOrderlineId); 175 if (log4j.isDebugEnabled()) log4j.debug("M_InoutLine_ID: " + data.mInoutlineId); 176 if (log4j.isDebugEnabled()) log4j.debug("Line: " + data.line); 177 if (log4j.isDebugEnabled()) log4j.debug("Description: " + data.description); 178 if (log4j.isDebugEnabled()) log4j.debug("M_Product_ID: " + data.mProductId); 179 if (log4j.isDebugEnabled()) log4j.debug("QtyInvoiced: " + data.qtyinvoiced); 180 if (log4j.isDebugEnabled()) log4j.debug("PriceList: " + data.pricelist); 181 if (log4j.isDebugEnabled()) log4j.debug("PriceActual: " + data.priceactual); 182 if (log4j.isDebugEnabled()) log4j.debug("PriceLimit: " + data.pricelimit); 183 if (log4j.isDebugEnabled()) log4j.debug("C_Charge_ID: " + data.cChargeId); 184 if (log4j.isDebugEnabled()) log4j.debug("ChargeAmt: " + data.chargeamt); 185 if (log4j.isDebugEnabled()) log4j.debug("C_UOM_ID: " + data.cUomId); 186 if (log4j.isDebugEnabled()) log4j.debug("C_Tax_ID: " + data.cTaxId); 187 if (log4j.isDebugEnabled()) log4j.debug("S_ResourceAssignment_ID: " + data.sResourceassignmentId); 188 if (log4j.isDebugEnabled()) log4j.debug("A_Asset_ID: " + data.aAssetId); 189 if (log4j.isDebugEnabled()) log4j.debug("TaxAmt: " + data.taxamt); 190 if (log4j.isDebugEnabled()) log4j.debug("M_AttributeSetInstance_ID: " + data.mAttributesetinstanceId); 191 if (log4j.isDebugEnabled()) log4j.debug("IsDescription: " + data.isdescription); 192 if (log4j.isDebugEnabled()) log4j.debug("QuantityOrder: " + data.quantityorder); 193 if (log4j.isDebugEnabled()) log4j.debug("M_Product_UOM_ID: " + data.mProductUomId); 194 if (log4j.isDebugEnabled()) log4j.debug("C_Invoice_Discount_ID: " + data.cInvoiceDiscountId); 195 196 return data; 197 } 198 199 void printPageHidden(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 200 if (log4j.isDebugEnabled()) log4j.debug("Output: hidden"); 201 InvoiceVendorMultilineLinesData data = getEditVariables(vars); 202 String strIDNew = ""; 203 String strMensaje = ""; 204 String strLineNo = ""; 205 206 try { 207 if (vars.commandIn("DELETE")) { 208 if (data.cInvoicelineId.equals("")) strMensaje = Utility.messageBD(this, "ProcessError", vars.getLanguage()); 209 else { 210 Connection conn = getTransactionConnection(); 211 try { 212 if (data.delete(conn, this)==0) strMensaje = Utility.messageBD(this, "ProcessError", vars.getLanguage()); 213 releaseCommitConnection(conn); 214 } catch (Exception ex1) { 215 try { 216 releaseRollbackConnection(conn); 217 } catch (Exception ignored) {} 218 ex1.printStackTrace(); 219 log4j.error("Failed delete on expense Invoice lines - ROLLBACK"); 220 strMensaje = Utility.messageBD(this, "ProcessError", vars.getLanguage()); 221 } 222 } 223 } else if (vars.commandIn("SAVE_NEW", "SAVE_EDIT")) { 224 if (data.cInvoicelineId.equals("")) { 225 strIDNew = SequenceIdData.getSequence(this, "C_InvoiceLine", vars.getClient()); 226 data.cInvoicelineId = strIDNew; 227 if (data.insert(this) == 0) strMensaje = Utility.messageBD(this, "ProcessError", vars.getLanguage()); 228 strLineNo = InvoiceVendorMultilineLinesData.selectLineNo(this, strIDNew); 229 data.cInvoicelineId = ""; 230 } else { 231 if (data.update(this)==0) strMensaje = Utility.messageBD(this, "ProcessError", vars.getLanguage()); 232 strLineNo = InvoiceVendorMultilineLinesData.selectLineNo(this, data.cInvoicelineId); 233 } 234 } 235 } catch (Exception ex) { 236 strMensaje = ex.getMessage(); 237 } 238 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/utility/FrameOcultoMultilinea").createXmlDocument(); 239 StringBuffer datos = new StringBuffer (); 240 datos.append("var respuesta = new Array(\n"); 241 if (!vars.commandIn("HIDDEN")) { 242 if (!strMensaje.equals("")) { 243 datos.append("new Array(\"Command\", \"ERROR\"),\n"); 244 datos.append("new Array(\"inpcInvoicelineId\", \"").append(data.cInvoicelineId).append("\"),\n"); 245 datos.append("new Array(\"MENSAJE_ERROR\", \"").append(Utility.messageBD(this, strMensaje, vars.getLanguage())).append("\"),\n"); 246 } else { 247 datos.append("new Array(\"Command\", \"").append(vars.getCommand()).append("\"),\n"); 248 datos.append("new Array(\"inpcInvoicelineId\", \"").append(data.cInvoicelineId).append("\"),\n"); 249 datos.append("new Array(\"inpmProductId\", \"").append(data.mProductId).append("\"),\n"); 250 datos.append("new Array(\"inplineno\", \"").append(strLineNo).append("\"),\n"); 251 datos.append("new Array(\"inppriceactual\", \"").append(data.priceactual).append("\"),\n"); 252 datos.append("new Array(\"inpqtyinvoiced\", \"").append(data.qtyinvoiced).append("\"),\n"); 253 datos.append("new Array(\"inpcTaxId\", \"").append(data.cTaxId).append("\"),\n"); 254 datos.append("new Array(\"inpcInvoicelineIdNew\", \"").append(data.cInvoicelineId.equals("")?strIDNew:data.cInvoicelineId).append("\"),\n"); 255 } 256 datos.append("new Array(\"Formulario\", \"document.frmMain\")"); 257 } 258 datos.append(");\n"); 259 datos.append("var respuestaNew = new Array(\n"); 260 if (strMensaje.equals("") && vars.commandIn("SAVE_NEW", "DELETE")) { 261 datos.append("new Array(\"LineNo\", \"").append(InvoiceVendorMultilineLinesData.selectNextLine(this, data.cInvoiceId)).append("\")\n"); 262 FieldProvider [] fp = null; 263 try { 264 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "C_Tax", "", Utility.getContext(this, vars, "#User_Org", windowId), Utility.getContext(this, vars, "#User_Client", windowId), 0); 265 Utility.fillSQLParameters(this, vars, null, comboTableData, windowId, ""); 266 fp = comboTableData.select(false); 267 comboTableData = null; 268 } catch (Exception ex) { 269 throw new ServletException(ex); 270 } 271 272 273 if (fp!=null && fp.length>0) { 274 datos.append(", new Array(\"inpcTaxId\", new Array(\n"); 275 for (int i=0;i<fp.length;i++) { 276 datos.append("new Array(\"").append(fp[i].getField("id")).append("\", \"").append(fp[i].getField("name")).append("\")\n"); 277 if (i<fp.length-1) datos.append(", "); 278 } 279 datos.append(")\n"); 280 datos.append(")\n"); 281 } 282 } 283 datos.append(");\n"); 284 xmlDocument.setParameter("array",datos.toString()); 285 xmlDocument.setParameter("targetFrame", vars.getStringParameter("target")); 286 287 response.setContentType("text/html; charset=UTF-8"); 288 PrintWriter out = response.getWriter(); 289 out.println(xmlDocument.print()); 290 out.close(); 291 } 292 293 public String getServletInfo() { 294 return "InvoiceVendorMultiline_Lines Servlet"; 295 } } 297 298 | Popular Tags |