1 19 package org.openbravo.erpCommon.ad_actionButton; 20 21 import org.openbravo.erpCommon.utility.SequenceIdData; 22 import org.openbravo.erpCommon.utility.*; 23 import org.openbravo.utils.FormatUtilities; 24 import org.openbravo.erpCommon.ad_callouts.*; 25 import org.openbravo.erpCommon.businessUtility.*; 26 import org.openbravo.base.secureApp.HttpSecureAppServlet; 27 import org.openbravo.base.secureApp.VariablesSecureApp; 28 import org.openbravo.xmlEngine.XmlDocument; 29 import java.io.*; 30 import java.math.BigDecimal ; 31 import javax.servlet.*; 32 import javax.servlet.http.*; 33 34 import java.sql.Connection ; 37 38 import org.openbravo.erpCommon.utility.DateTimeData; 39 40 public class CopyFromPOOrder extends HttpSecureAppServlet { 41 static final BigDecimal ZERO = new BigDecimal (0.0); 42 43 public void init (ServletConfig config) { 44 super.init(config); 45 boolHist = false; 46 } 47 48 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 49 VariablesSecureApp vars = new VariablesSecureApp(request); 50 51 if (vars.commandIn("DEFAULT")) { 52 String strProcessId = vars.getStringParameter("inpProcessId"); 53 String strWindow = vars.getStringParameter("inpwindowId"); 54 String strTab = vars.getStringParameter("inpTabId"); 55 String strKey = vars.getRequiredGlobalVariable("inpcOrderId", strWindow + "|C_Order_ID"); 56 printPage(response, vars, strKey, strWindow, strTab, strProcessId); 57 } else if (vars.commandIn("SAVE")) { 58 String strWindow = vars.getStringParameter("inpwindowId"); 59 String strOrder = vars.getStringParameter("inpcOrderId"); 60 String strKey = vars.getRequestGlobalVariable("inpKey", strWindow + "|C_Order_ID"); 61 String strTab = vars.getStringParameter("inpTabId"); 62 ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTab); 63 String strWindowPath="", strTabName=""; 64 if (tab!=null && tab.length!=0) { 65 strTabName = FormatUtilities.replace(tab[0].name); 66 if (tab[0].help.equals("Y")) strWindowPath="../utility/WindowTree_FS.html?inpTabId=" + strTab; 67 else strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html"; 68 } else strWindowPath = strDefaultServlet; 69 String messageResult = processButton(vars, strKey, strOrder, strWindow); 70 vars.setSessionValue(strWindow + "|" + strTabName + ".message", messageResult); 71 printPageClosePopUp(response, vars, strWindowPath); 72 } else pageErrorPopUp(response); 73 } 74 75 76 String processButton(VariablesSecureApp vars, String strKey, String strOrder, String windowId) { 77 String priceactual = ""; 78 String pricelist = ""; 79 String pricelimit = ""; 80 String strPrecision = "0"; 81 String strPricePrecision="0"; 82 String strDiscount = ""; 83 Connection conn = null; 84 try { 85 conn = getTransactionConnection(); 86 CopyFromPOOrderData[] data = CopyFromPOOrderData.selectLines(this, strOrder); 87 CopyFromPOOrderData[] order = CopyFromPOOrderData.select(this, strKey); 88 for (int i=0;data!=null && i<data.length;i++){ 89 SEExpenseProductData[] data3 = SEExpenseProductData.select(this, data[i].mProductId, order[0].mPricelistId.equals("")?CopyFromPOOrderData.defaultPriceList(this):order[0].mPricelistId); 90 for (int j=0;data3!=null && j<data3.length;j++) { 91 if (data3[j].validfrom == null || data3[j].validfrom.equals("") || !DateTimeData.compare(this, DateTimeData.today(this), data3[j].validfrom).equals("-1")){ 92 priceactual = data3[j].pricestd; 93 pricelist = data3[j].pricelist; 94 pricelimit = data3[j].pricelimit; 95 SLOrderAmtData[] data4 = SLOrderAmtData.select(this, strKey); 96 if (data4!=null && data4.length>0) { 97 strPrecision = data4[0].stdprecision.equals("")?"0":data4[0].stdprecision; 98 strPricePrecision = data4[0].priceprecision.equals("")?"0":data4[0].priceprecision; 99 } 100 int StdPrecision = Integer.valueOf(strPrecision).intValue(); 101 int PricePrecision = Integer.valueOf(strPricePrecision).intValue(); 102 103 BigDecimal priceActual, priceList, discount; 104 105 priceActual = (priceactual.equals("")?ZERO:(new BigDecimal (priceactual))).setScale(PricePrecision, BigDecimal.ROUND_HALF_UP); 106 priceList = (pricelist.equals("")?ZERO:new BigDecimal (pricelist)); 107 if (priceList.doubleValue() == 0.0) discount = ZERO; 108 else discount = new BigDecimal ((priceList.doubleValue() - priceActual.doubleValue()) / priceList.doubleValue() * 100.0); 109 if (discount.scale() > StdPrecision) discount = discount.setScale(StdPrecision, BigDecimal.ROUND_HALF_UP); 110 strDiscount = discount.toString(); 111 priceactual = priceActual.toString(); 112 pricelist = priceList.toString(); 113 } 114 } 115 if (priceactual.equals("")) priceactual="0"; 116 if (pricelist.equals("")) pricelist="0"; 117 if (pricelimit.equals("")) pricelimit="0"; 118 int line = 0; 119 String strCTaxID = Tax.get(this, data[i].mProductId, DateTimeData.today(this), order[0].adOrgId, order[0].mWarehouseId.equals("")?vars.getWarehouse():order[0].mWarehouseId, CopyFromPOOrderData.cBPartnerLocationId(this, order[0].cBpartnerId), CopyFromPOOrderData.cBPartnerLocationId(this, order[0].cBpartnerId), order[0].cProjectId, true); 120 line = Integer.valueOf(order[0].line.equals("")?"0":order[0].line).intValue() + ((i+1) * 10); 121 String strCOrderlineID = SequenceIdData.getSequence(this, "C_OrderLine", vars.getClient()); 122 CopyFromPOOrderData.insertCOrderline(conn, this, strCOrderlineID, order[0].adClientId, order[0].adOrgId, vars.getUser(), 123 strKey, Integer.toString(line), order[0].cBpartnerId, 124 order[0].cBpartnerLocationId.equals("")?ExpenseSOrderData.cBPartnerLocationId(this, 125 order[0].cBpartnerId):order[0].cBpartnerLocationId, DateTimeData.today(this), DateTimeData.today(this), data[i].description, 126 data[i].mProductId, order[0].mWarehouseId.equals("")?vars.getWarehouse():order[0].mWarehouseId, data[i].cUomId, data[i].qtyordered, data[i].quantityorder, 127 data[i].cCurrencyId, pricelist, priceactual, pricelimit, strCTaxID, strDiscount, data[i].mProductUomId, data[i].orderline); 128 } 129 releaseCommitConnection(conn); 130 return Utility.messageBD(this, "ProcessOK", vars.getLanguage()); 131 } catch (Exception e) { 132 log4j.warn(e); 133 try { 134 releaseRollbackConnection(conn); 135 } catch (Exception ignored) {} 136 return Utility.messageBD(this, "ProcessRunError", vars.getLanguage()); 137 } 138 } 139 140 141 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strKey, String windowId, String strTab, String strProcessId) 142 throws IOException, ServletException { 143 if (log4j.isDebugEnabled()) log4j.debug("Output: Button process Copy lines"); 144 ActionButtonDefaultData[] data = null; 145 String strHelp="", strDescription=""; 146 if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId); 147 else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(),strProcessId); 148 if (data!=null && data.length!=0) { 149 strDescription = data[0].description; 150 strHelp = data[0].help; 151 } 152 String [] discard = {""}; 153 if (strHelp.equals("")) discard[0] = new String ("helpDiscard"); 154 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder", discard).createXmlDocument(); 155 xmlDocument.setParameter("key", strKey); 156 xmlDocument.setParameter("window", windowId); 157 xmlDocument.setParameter("tab", strTab); 158 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 159 xmlDocument.setParameter("question", Utility.messageBD(this, "StartProcess?", vars.getLanguage())); 160 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 161 xmlDocument.setParameter("description", strDescription); 162 xmlDocument.setParameter("help", strHelp); 163 response.setContentType("text/html"); 164 PrintWriter out = response.getWriter(); 165 out.println(xmlDocument.print()); 166 out.close(); 167 } 168 169 public String getServletInfo() { 170 return "Servlet Copy from order"; 171 } } 173 174 | Popular Tags |