1 19 20 package org.openbravo.erpCommon.ad_callouts; 21 22 import org.openbravo.base.secureApp.HttpSecureAppServlet; 23 import org.openbravo.base.secureApp.VariablesSecureApp; 24 import org.openbravo.xmlEngine.XmlDocument; 25 import java.io.*; 26 import java.math.BigDecimal ; 27 import javax.servlet.*; 28 import javax.servlet.http.*; 29 30 31 32 public class SL_MachineCost extends HttpSecureAppServlet { 33 34 static final BigDecimal ZERO = new BigDecimal (0.0); 35 36 public void init (ServletConfig config) { 37 super.init(config); 38 boolHist = false; 39 } 40 41 42 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 43 VariablesSecureApp vars = new VariablesSecureApp(request); 44 if (vars.commandIn("DEFAULT")) { 45 String strChanged = vars.getStringParameter("inpLastFieldChanged"); 46 if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged); 47 String strPurchaseAmt = vars.getStringParameter("inppurchaseamt"); 48 String strToolsetAmt = vars.getStringParameter("inptoolsetamt"); 49 String strYearValue = vars.getStringParameter("inpyearvalue"); 50 String strAmortization = vars.getStringParameter("inpamortization"); 51 String strDaysYear = vars.getStringParameter("inpdaysyear"); 52 String strDayHours = vars.getStringParameter("inpdayhours"); 53 String strImproductiveHoursYear = vars.getStringParameter("inpimproductivehoursyear"); 54 String strCostUomYear = vars.getStringParameter("inpcostuomyear"); 55 String strCost = vars.getStringParameter("inpcost"); 56 String strCostUom = vars.getStringParameter("inpcostuom"); 57 try { 58 printPage(response, vars, strChanged, strPurchaseAmt, strToolsetAmt, strYearValue, strAmortization, strDaysYear, strDayHours, strImproductiveHoursYear, strCostUomYear, strCost, strCostUom); 59 } catch (ServletException ex) { 60 pageErrorCallOut(response); 61 } 62 } else pageError(response); 63 } 64 65 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strChanged, String strPurchaseAmt, String strToolsetAmt, String strYearValue, String strAmortization, String strDaysYear, String strDayHours, String strImproductiveHoursYear, String strCostUomYear, String strCost, String strCostUom) throws IOException, ServletException { 66 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 67 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument(); 68 69 if (strChanged.equals("inppurchaseamt") || strChanged.equals("inptoolsetamt") || strChanged.equals("inpyearvalue")){ 70 if (strPurchaseAmt!=null && !strPurchaseAmt.equals("") && 71 strToolsetAmt!=null && !strToolsetAmt.equals("") && 72 strYearValue!=null && !strYearValue.equals("")) { 73 Float fPurchaseAmt = Float.valueOf(strPurchaseAmt); 74 Float fToolsetAmt = Float.valueOf(strToolsetAmt); 75 Float fYearValue = Float.valueOf(strYearValue); 76 Float fAmortization = (fPurchaseAmt + fToolsetAmt) / fYearValue; 77 strAmortization = fAmortization.toString(); 78 79 if (strCostUomYear!=null && !strCostUomYear.equals("")) { 80 Float fCostUomYear = Float.valueOf(strCostUomYear); 81 Float fCost= fYearValue / fCostUomYear; 82 strCost = fCost.toString(); 83 } 84 } 85 } else if (strChanged.equals("inpamortization")){ 86 if (strPurchaseAmt!=null && !strPurchaseAmt.equals("") && 87 strToolsetAmt!=null && !strToolsetAmt.equals("") && 88 strAmortization!=null && !strAmortization.equals("")) { 89 Float fPurchaseAmt = Float.valueOf(strPurchaseAmt); 90 Float fToolsetAmt = Float.valueOf(strToolsetAmt); 91 Float fAmortization = Float.valueOf(strAmortization); 92 Float fYearValue = (fPurchaseAmt + fToolsetAmt) / fAmortization; 93 strYearValue = fYearValue.toString(); 94 95 if (strCostUomYear!=null && !strCostUomYear.equals("")) { 96 Float fCostUomYear = Float.valueOf(strCostUomYear); 97 Float fCost= fYearValue / fCostUomYear; 98 strCost = fCost.toString(); 99 } 100 } 101 } else if (strChanged.equals("inpdaysyear") || strChanged.equals("inpdayhours") || strChanged.equals("inpimproductivehoursyear")){ 102 if (strDaysYear!=null && !strDaysYear.equals("") && 103 strDayHours!=null && !strDayHours.equals("") && 104 strImproductiveHoursYear!=null && !strImproductiveHoursYear.equals("")) { 105 Float fDaysYear = Float.valueOf(strDaysYear); 106 Float fDayHours = Float.valueOf(strDayHours); 107 Float fImproductiveHoursYear = Float.valueOf(strImproductiveHoursYear); 108 Float fCostUomYear = (fDaysYear * fDayHours) - fImproductiveHoursYear; 109 strCostUomYear = fCostUomYear.toString(); 110 111 if (strYearValue!=null && !strYearValue.equals("")) { 112 Float fYearValue = Float.valueOf(strYearValue); 113 Float fCost= fYearValue / fCostUomYear; 114 strCost = fCost.toString(); 115 } 116 } 117 } else if (strChanged.equals("inpcostuomyear")){ 118 if (strCostUom.equals("H")) 119 if (strDaysYear!=null && !strDaysYear.equals("") && 120 strDayHours!=null && !strDayHours.equals("") && 121 strCostUomYear!=null && !strCostUomYear.equals("")) { 122 Float fDaysYear = Float.valueOf(strDaysYear); 123 Float fDayHours = Float.valueOf(strDayHours); 124 Float fCostUomYear = Float.valueOf(strCostUomYear); 125 Float fImproductiveHoursYear = (fDaysYear * fDayHours) - fCostUomYear; 126 strImproductiveHoursYear = fImproductiveHoursYear.toString(); 127 } 128 if (strYearValue!=null && !strYearValue.equals("") && 129 strCostUomYear!=null && !strCostUomYear.equals("")) { 130 Float fYearValue = Float.valueOf(strYearValue); 131 Float fCostUomYear = Float.valueOf(strCostUomYear); 132 Float fCost= fYearValue / fCostUomYear; 133 strCost = fCost.toString(); 134 } 135 } else if (strChanged.equals("inpcost")){ 136 if (strCost!=null && !strCost.equals("") && 137 strCostUomYear!=null && !strCostUomYear.equals("")) { 138 Float fCostUomYear = Float.valueOf(strCostUomYear); 139 Float fCost = Float.valueOf(strCost); 140 Float fYearValue = fCost * fCostUomYear; 141 strYearValue = fYearValue.toString(); 142 143 if (strPurchaseAmt!=null && !strPurchaseAmt.equals("") && 144 strToolsetAmt!=null && !strToolsetAmt.equals("")) { 145 Float fPurchaseAmt = Float.valueOf(strPurchaseAmt); 146 Float fToolsetAmt = Float.valueOf(strToolsetAmt); 147 Float fAmortization = (fPurchaseAmt + fToolsetAmt) / fYearValue; 148 strAmortization = fAmortization.toString(); 149 } 150 } 151 } 152 153 StringBuffer resultado = new StringBuffer (); 154 resultado.append("var calloutName='SL_MachineCost';\n\n"); 155 resultado.append("var respuesta = new Array("); 156 resultado.append("new Array(\"inppurchaseamt\", \"" + strPurchaseAmt + "\"),\n"); 157 resultado.append("new Array(\"inptoolsetamt\", \"" + strToolsetAmt + "\"),\n"); 158 resultado.append("new Array(\"inpyearvalue\", \"" + strYearValue + "\"),\n"); 159 resultado.append("new Array(\"inpamortization\", \"" + strAmortization + "\"), \n"); 160 resultado.append("new Array(\"inpdaysyear\", \"" + strDaysYear + "\"),\n"); 161 resultado.append("new Array(\"inpdayhours\", \"" + strDayHours + "\"),\n"); 162 resultado.append("new Array(\"inpimproductivehoursyear\", \"" + strImproductiveHoursYear + "\"),\n"); 163 resultado.append("new Array(\"inpcostuomyear\", \"" + strCostUomYear + "\"),\n"); 164 resultado.append("new Array(\"inpcost\", \"" + strCost + "\") \n"); 165 resultado.append(");\n"); 166 xmlDocument.setParameter("array", resultado.toString()); 167 response.setContentType("text/html; charset=UTF-8"); 168 PrintWriter out = response.getWriter(); 169 out.println(xmlDocument.print()); 170 out.close(); 171 } 172 } 173 | Popular Tags |