Fixes issue 36067: Improve callouts performance extending from SimpleCallout
authorMark <markmm82@gmail.com>
Fri, 04 Aug 2017 19:25:27 -0400
changeset 32538 2ab8016a2353
parent 32537 48d6a58b1b9d
child 32539 a686f7a45fa5
Fixes issue 36067: Improve callouts performance extending from SimpleCallout

Refactorized some old callouts extending HttpSecureAppServlet to use SimpleCallout and improve performance.
src/org/openbravo/erpCommon/ad_callouts/SE_Expense_Amount.java
src/org/openbravo/erpCommon/ad_callouts/SE_Expense_BP_Project.java
src/org/openbravo/erpCommon/ad_callouts/SE_Expense_Product.java
src/org/openbravo/erpCommon/ad_callouts/SE_ExternalPOS_BPartner.java
src/org/openbravo/erpCommon/ad_callouts/SE_FinancialAccount_BSAccounts.java
src/org/openbravo/erpCommon/ad_callouts/SE_InOut_DocType.java
src/org/openbravo/erpCommon/ad_callouts/SE_Invoice_BPartner.java
src/org/openbravo/erpCommon/ad_callouts/SE_Invoice_Project.java
src/org/openbravo/erpCommon/ad_callouts/SE_Order_Project.java
src/org/openbravo/erpCommon/ad_callouts/SE_PeriodNo.java
src/org/openbravo/erpCommon/ad_callouts/SE_Period_Control.java
src/org/openbravo/erpCommon/ad_callouts/SE_Pricelist_Active.java
src/org/openbravo/erpCommon/ad_callouts/SE_ProjectLine_Value.java
src/org/openbravo/erpCommon/ad_callouts/SE_Project_BPartner.java
src/org/openbravo/erpCommon/ad_callouts/SE_Proposal_BPartner.java
src/org/openbravo/erpCommon/ad_callouts/SE_Supplier_BPartner.java
src/org/openbravo/erpCommon/ad_callouts/SE_Taxes_Active.java
src/org/openbravo/erpCommon/ad_callouts/SL_Asset_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_Assets.java
src/org/openbravo/erpCommon/ad_callouts/SL_BankDebt_Amount.java
src/org/openbravo/erpCommon/ad_callouts/SL_BankStmt_Amount.java
src/org/openbravo/erpCommon/ad_callouts/SL_Budget_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_CCPMeasure_Group.java
src/org/openbravo/erpCommon/ad_callouts/SL_CashJournal_Amounts.java
src/org/openbravo/erpCommon/ad_callouts/SL_Charge.java
src/org/openbravo/erpCommon/ad_callouts/SL_Conversion_Rate.java
src/org/openbravo/erpCommon/ad_callouts/SL_CostcenterEmployee_SalaryCategory.java
src/org/openbravo/erpCommon/ad_callouts/SL_GlobalUse_Conversion.java
src/org/openbravo/erpCommon/ad_callouts/SL_GlobalUse_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_InOutLine_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_InOut_BPartner.java
src/org/openbravo/erpCommon/ad_callouts/SL_InOut_Conversion.java
src/org/openbravo/erpCommon/ad_callouts/SL_Internal_Consumption_Conversion.java
src/org/openbravo/erpCommon/ad_callouts/SL_Internal_Consumption_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_Inventory_Conversion.java
src/org/openbravo/erpCommon/ad_callouts/SL_Inventory_Locator.java
src/org/openbravo/erpCommon/ad_callouts/SL_Inventory_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_InvoiceTax_Amt.java
src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Amt.java
src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Charge_Tax.java
src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Conversion.java
src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_DocType.java
src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Glitem.java
src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_PriceList.java
src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_JournalLineAmt.java
src/org/openbravo/erpCommon/ad_callouts/SL_Journal_Period.java
src/org/openbravo/erpCommon/ad_callouts/SL_LegalEntity_Acct.java
src/org/openbravo/erpCommon/ad_callouts/SL_MachineCost.java
src/org/openbravo/erpCommon/ad_callouts/SL_Movement_Conversion.java
src/org/openbravo/erpCommon/ad_callouts/SL_Movement_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java
src/org/openbravo/erpCommon/ad_callouts/SL_Order_Charge_Tax.java
src/org/openbravo/erpCommon/ad_callouts/SL_Order_Conversion.java
src/org/openbravo/erpCommon/ad_callouts/SL_Order_DocType.java
src/org/openbravo/erpCommon/ad_callouts/SL_Order_PriceList.java
src/org/openbravo/erpCommon/ad_callouts/SL_Order_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_Order_Tax.java
src/org/openbravo/erpCommon/ad_callouts/SL_Organization_Info.java
src/org/openbravo/erpCommon/ad_callouts/SL_PC_Case_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_ProductPrice_PriceListVersion.java
src/org/openbravo/erpCommon/ad_callouts/SL_Product_Type.java
src/org/openbravo/erpCommon/ad_callouts/SL_ProductionPlan_Conversion.java
src/org/openbravo/erpCommon/ad_callouts/SL_ProductionPlan_WRPhase.java
src/org/openbravo/erpCommon/ad_callouts/SL_Production_Conversion.java
src/org/openbravo/erpCommon/ad_callouts/SL_Production_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_Project_Margin.java
src/org/openbravo/erpCommon/ad_callouts/SL_Project_Planned.java
src/org/openbravo/erpCommon/ad_callouts/SL_Project_PriceList.java
src/org/openbravo/erpCommon/ad_callouts/SL_Project_Type.java
src/org/openbravo/erpCommon/ad_callouts/SL_Proposal_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_RequisitionLine_Amt.java
src/org/openbravo/erpCommon/ad_callouts/SL_RequisitionLine_Conversion.java
src/org/openbravo/erpCommon/ad_callouts/SL_RequisitionLine_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_RequisitionOrder_Order.java
src/org/openbravo/erpCommon/ad_callouts/SL_Requisition_BPartner.java
src/org/openbravo/erpCommon/ad_callouts/SL_Requisition_BPartner_PriceList.java
src/org/openbravo/erpCommon/ad_callouts/SL_ScheduledMaintenance_Maintenance.java
src/org/openbravo/erpCommon/ad_callouts/SL_SequenceProduct_Conversion.java
src/org/openbravo/erpCommon/ad_callouts/SL_SequenceProduct_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_User_Name.java
src/org/openbravo/erpCommon/ad_callouts/SL_WRPhaseProduct_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_WRPhase_Sequence.java
src/org/openbravo/erpCommon/ad_callouts/SL_WorkRequirement_Conversion.java
src/org/openbravo/erpCommon/ad_callouts/SL_WorkRequirement_ProcessPlan.java
src/org/openbravo/erpCommon/ad_callouts/SL_WorkRequirement_StartDate.java
src/org/openbravo/erpCommon/ad_callouts/SL_Year_Validation.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Expense_Amount.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Expense_Amount.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,148 +11,102 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2013 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.dal.security.OrganizationStructureProvider;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.utility.DateTimeData;
-import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.model.common.enterprise.Organization;
-import org.openbravo.xmlEngine.XmlDocument;
+import org.openbravo.model.timeandexpense.Sheet;
 
-public class SE_Expense_Amount extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SE_Expense_Amount extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strExpenseAmt = vars.getNumericParameter("inpexpenseamt");
-      String strDateexpense = vars.getStringParameter("inpdateexpense");
-      String strcCurrencyId = vars.getStringParameter("inpcCurrencyId");
-      String strTimeExpenseId = vars.getStringParameter("inpsTimeexpenseId");
-      String strTabId = vars.getStringParameter("inpTabId");
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-      try {
-        printPage(response, vars, strExpenseAmt, strDateexpense, strcCurrencyId, strTimeExpenseId,
-            strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // Parameters
+    BigDecimal amount = info.getBigDecimalParameter("inpexpenseamt");
+    String strDateexpense = info.getStringParameter("inpdateexpense");
+    String strcCurrencyId = info.getStringParameter("inpcCurrencyId", IsIDFilter.instance);
+    String strTimeExpenseId = info.getStringParameter("inpsTimeexpenseId", IsIDFilter.instance);
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars,
-      String strExpenseAmt, String strDateexpense, String strcCurrencyId, String strTimeExpenseId,
-      String strTabId) throws IOException, ServletException {
-    String localStrDateexpense = strDateexpense;
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    final Organization org = OBDal.getInstance()
-        .get(org.openbravo.model.timeandexpense.Sheet.class, strTimeExpenseId).getOrganization();
+    // Get the currency to from organization's currency, or from the client's currency if it doesn't
+    // exists
+    final Organization org = OBDal.getInstance().get(Sheet.class, strTimeExpenseId)
+        .getOrganization();
     String c_Currency_To_ID = getCurrency(org.getId());
     if (c_Currency_To_ID == null) {
-      c_Currency_To_ID = OBDal.getInstance()
-          .get(org.openbravo.model.timeandexpense.Sheet.class, strTimeExpenseId).getClient()
+      c_Currency_To_ID = OBDal.getInstance().get(Sheet.class, strTimeExpenseId).getClient()
           .getCurrency().getId();
     }
 
+    if (StringUtils.isEmpty(strDateexpense)) {
+      strDateexpense = StringUtils.isEmpty(SEExpenseAmountData.selectReportDate(this,
+          strTimeExpenseId)) ? DateTimeData.today(this) : SEExpenseAmountData.selectReportDate(
+          this, strTimeExpenseId);
+    }
+
+    // Amount expense
+    int stdPrecision = 0;
+    if (StringUtils.isNotEmpty(strcCurrencyId)) {
+      stdPrecision = Integer.valueOf(SEExpenseAmountData.selectPrecision(this, strcCurrencyId));
+    }
+    if (amount.scale() > stdPrecision) {
+      amount = amount.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
+    }
+
     // Checks if there is a conversion rate for each of the transactions of
     // the report
-    String strConvRateErrorMsg = "";
-    OBError myMessage = null;
-    myMessage = new OBError();
-
-    if (localStrDateexpense.equals("")) {
-      localStrDateexpense = SEExpenseAmountData.selectReportDate(this, strTimeExpenseId).equals("") ? DateTimeData
-          .today(this) : SEExpenseAmountData.selectReportDate(this, strTimeExpenseId);
+    BigDecimal convAmount = amount;
+    if (!StringUtils.equals(strcCurrencyId, c_Currency_To_ID)) {
+      String convertedAmount = amount.toPlainString();
+      try {
+        convertedAmount = SEExpenseProductData.selectConvertedAmt(this, amount.toPlainString(),
+            strcCurrencyId, c_Currency_To_ID, strDateexpense, info.vars.getClient(), org.getId());
+      } catch (Exception e) {
+        convertedAmount = "";
+        OBDal.getInstance().rollbackAndClose();
+        info.showMessage(Utility.translateError(this, info.vars, info.vars.getLanguage(),
+            e.getMessage()).getMessage());
+        log4j.warn("Currency does not exist. Exception:" + e);
+      }
+      convAmount = StringUtils.isNotEmpty(convertedAmount) ? new BigDecimal(convertedAmount)
+          : BigDecimal.ZERO;
+      int stdPrecisionConv = 0;
+      if (StringUtils.isNotEmpty(c_Currency_To_ID)) {
+        stdPrecisionConv = Integer.valueOf(SEExpenseAmountData.selectPrecision(this,
+            c_Currency_To_ID));
+      }
+      if (convAmount.scale() > stdPrecisionConv) {
+        convAmount = convAmount.setScale(stdPrecisionConv, BigDecimal.ROUND_HALF_UP);
+      }
     }
 
-    BigDecimal amount = null;
-    if (!strExpenseAmt.equals("")) {
-      amount = new BigDecimal(strExpenseAmt);
-    } else {
-      amount = new BigDecimal(0.0);
-    }
-    String strPrecision = "0";
-    if (!strcCurrencyId.equals("")) {
-      strPrecision = SEExpenseAmountData.selectPrecision(this, strcCurrencyId);
-    }
-    int stdPrecision = Integer.valueOf(strPrecision).intValue();
-    if (amount.scale() > stdPrecision)
-      amount = amount.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
-
-    String convertedAmount = strExpenseAmt;
-    BigDecimal convAmount = amount;
-
-    if (!strcCurrencyId.equals(c_Currency_To_ID)) {
-      String strPrecisionConv = "0";
-      if (!c_Currency_To_ID.equals("")) {
-        strPrecisionConv = SEExpenseAmountData.selectPrecision(this, c_Currency_To_ID);
-      }
-      int stdPrecisionConv = Integer.valueOf(strPrecisionConv).intValue();
-      try {
-        convertedAmount = SEExpenseAmountData.selectConvertedAmt(this, strExpenseAmt,
-            strcCurrencyId, c_Currency_To_ID, localStrDateexpense, vars.getClient(), org.getId());
-      } catch (ServletException e) {
-        convertedAmount = "";
-        myMessage = Utility.translateError(this, vars, vars.getLanguage(), e.getMessage());
-        strConvRateErrorMsg = myMessage.getMessage();
-        log4j.warn("Currency does not exist. Exception:" + e);
-      }
-      if (!convertedAmount.equals("")) {
-        convAmount = new BigDecimal(convertedAmount);
-      } else {
-        convAmount = BigDecimal.ZERO;
-      }
-      if (convAmount.scale() > stdPrecisionConv)
-        convAmount = convAmount.setScale(stdPrecisionConv, BigDecimal.ROUND_HALF_UP);
-    }
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SE_Expense_Amount';\n\n");
-    resultado.append("var respuesta = new Array(");
-    if (!strConvRateErrorMsg.equals("") && strConvRateErrorMsg != null) {
-      resultado.append("new Array('MESSAGE', \"" + strConvRateErrorMsg + "\"), ");
-    }
-    resultado.append("new Array(\"inpexpenseamt\", " + amount.toPlainString() + ")");
-    resultado.append(", new Array(\"inpconvertedamt\", "
-        + (convAmount.compareTo(BigDecimal.ZERO) == 0 ? "\"\"" : convAmount.toPlainString()) + ")");
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    // Update Expense Amount and Converted Amount
+    info.addResult("inpexpenseamt", amount);
+    info.addResult("inpconvertedamt", convAmount.compareTo(BigDecimal.ZERO) != 0 ? convAmount
+        : null);
   }
 
   private static String getCurrency(String org) {
-    if (org.equals("0")) {
+    if (StringUtils.equals(org, "0")) {
       return null;
     } else {
       Organization organization = OBDal.getInstance().get(Organization.class, org);
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Expense_BP_Project.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Expense_BP_Project.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,124 +11,72 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SE_Expense_BP_Project extends SimpleCallout {
 
-public class SE_Expense_BP_Project extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strBPartnerId = vars.getStringParameter("inpcBpartnerId");
-      String strProjectId = vars.getStringParameter("inpcProjectId");
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      String strWindowId = vars.getStringParameter("inpwindowId");
-      String strTabId = vars.getStringParameter("inpTabId");
+    // Parameters
+    String strProjectId = info.getStringParameter("inpcProjectId", IsIDFilter.instance);
+    String strBPartnerId = info.getStringParameter("inpcBpartnerId", IsIDFilter.instance);
 
-      try {
-        printPage(response, vars, strBPartnerId, strProjectId, strChanged, strTabId, strWindowId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // If project changed
+    if (StringUtils.equals(strChanged, "inpcProjectId")) {
+      // Reset Project Phase and Project Task fields
+      info.addResult("inpcProjectphaseId", null);
+      info.addResult("inpcProjecttaskId", null);
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars,
-      String strBPartnerId, String strProjectId, String strChanged, String strTabId,
-      String strWindowId) throws IOException, ServletException {
-    String localStrProjectId = strProjectId;
-    String localStrBPartnerId = strBPartnerId;
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SE_Expense_BP_Project';\n\n");
-    resultado.append("var respuesta = new Array(");
-
-    if (strChanged.equals("inpcProjectId")) {
-      // Reset Project Phase and Project Task fields
-      resultado.append("new Array(\"inpcProjectphaseId\", \"\"),\n");
-      resultado.append("new Array(\"inpcProjecttaskId\", \"\")\n");
       // If project changed, select project's business partner (if any).
-      if (localStrProjectId != null && !localStrProjectId.equals("")) {
-        String strBPartnerName = "";
-        String strBPartner = SEExpenseBPProjectData.selectBPId(this, localStrProjectId);
-        if (strBPartner != null && !strBPartner.equals("")) {
-          localStrBPartnerId = strBPartner;
-          strBPartnerName = SEExpenseBPProjectData.selectBPName(this, localStrProjectId);
-          resultado.append(", new Array(\"inpcBpartnerId\", \"" + localStrBPartnerId + "\")\n");
-          resultado.append(", new Array(\"inpcBpartnerId_R\", \"" + strBPartnerName + "\")\n");
-        }
-      }
-    } else if (strChanged.equals("inpcBpartnerId")) {
-      // If business partner changed...
-      String strReset = "0";
-      if (localStrBPartnerId != null && !localStrBPartnerId.equals("")) {
-        String strProject = "";
-        if (localStrProjectId != null && !localStrProjectId.equals("")) {
-          // ...if project is not null, check if it corresponds with
-          // the business partner
-          String strBPartnerProject = SEExpenseBPProjectData.selectBPProject(this,
-              localStrBPartnerId, localStrProjectId);
-          // ...if there is no relationship between project and
-          // business partner, take the last project of that business
-          // partner (if any).
-          if (strBPartnerProject == null || strBPartnerProject.equals("")) {
-            // strReset = "1";
-            strProject = SEExpenseBPProjectData.selectProjectId(this, localStrBPartnerId);
-            if (strProject != null && !strProject.equals("")) {
-              localStrProjectId = strProject;
-              resultado.append("new Array(\"inpcProjectId\", \"" + localStrProjectId + "\")\n");
-            } else {
-              localStrProjectId = "";
-            }
-          }
-        } else {
-          // ...if project is null, take the last project of that
-          // business partner (if any).
-          strReset = "1";
-          strProject = SEExpenseBPProjectData.selectProjectId(this, localStrBPartnerId);
-          resultado.append("new Array(\"inpcProjectId\", \"" + strProject + "\"),\n");
-        }
-        if (strReset.equals("1")) {
-          // Reset Project Phase and Project Task fields
-          resultado.append("new Array(\"inpcProjectphaseId\", \"\"),\n");
-          resultado.append("new Array(\"inpcProjecttaskId\", \"\")\n");
+      if (StringUtils.isNotEmpty(strProjectId)) {
+        String strBPartner = SEExpenseBPProjectData.selectBPId(this, strProjectId);
+        if (StringUtils.isNotEmpty(strBPartner)) {
+          strBPartnerId = strBPartner;
+          String strBPartnerName = SEExpenseBPProjectData.selectBPName(this, strProjectId);
+          info.addResult("inpcBpartnerId", strBPartnerId);
+          info.addResult("inpcBpartnerId_R", strBPartnerName);
         }
       }
     }
 
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    // If business partner changed
+    else if (StringUtils.equals(strChanged, "inpcBpartnerId")) {
+      if (StringUtils.isNotEmpty(strBPartnerId)) {
+        // If project is not null, check if it corresponds with the business partner
+        if (StringUtils.isNotEmpty(strProjectId)) {
+          String strBPartnerProject = SEExpenseBPProjectData.selectBPProject(this, strBPartnerId,
+              strProjectId);
+          // If there is no relationship between project and business partner, take the last project
+          // of that business partner
+          if (StringUtils.isEmpty(strBPartnerProject)) {
+            strProjectId = SEExpenseBPProjectData.selectProjectId(this, strBPartnerId);
+            info.addResult("inpcProjectId", strProjectId);
+          }
+        }
+        // If project is null, take the last project of that business partner (if any).
+        else {
+          strProjectId = SEExpenseBPProjectData.selectProjectId(this, strBPartnerId);
+          info.addResult("inpcProjectId", strProjectId);
+          info.addResult("inpcProjectphaseId", null);
+          info.addResult("inpcProjecttaskId", null);
+        }
+      }
+    }
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Expense_Product.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Expense_Product.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,118 +11,80 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2013 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.dal.security.OrganizationStructureProvider;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.utility.DateTimeData;
-import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.model.common.enterprise.Organization;
-import org.openbravo.xmlEngine.XmlDocument;
+import org.openbravo.model.timeandexpense.Sheet;
 
-public class SE_Expense_Product extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SE_Expense_Product extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strDateexpense = vars.getStringParameter("inpdateexpense");
-      String strmProductId = vars.getStringParameter("inpmProductId");
-      String strsTimeexpenseId = vars.getStringParameter("inpsTimeexpenseId");
-      String strcCurrencyId = vars.getStringParameter("inpcCurrencyId");
-      String strqty = vars.getNumericParameter("inpqty");
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      String strTabId = vars.getStringParameter("inpTabId");
-      String strInvPrice = vars.getNumericParameter("inpinvoiceprice");
-      String strWindowId = vars.getStringParameter("inpwindowId");
-      String strlastNetUnitPrice = vars.getNumericGlobalVariable("inplastNetUnitPrice", strWindowId
-          + "|lastNetUnitPrice", "0");
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-      if (strlastNetUnitPrice.equals("0")) {
-        strlastNetUnitPrice = strInvPrice;
-      }
-      try {
-        printPage(response, vars, strDateexpense, strmProductId, strsTimeexpenseId, strqty,
-            strcCurrencyId, strInvPrice, strChanged, strTabId, strWindowId, strlastNetUnitPrice);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // Parameters
+    String strDateexpense = info.getStringParameter("inpdateexpense");
+    String strmProductId = info.getStringParameter("inpmProductId", IsIDFilter.instance);
+    String strsTimeexpenseId = info.getStringParameter("inpsTimeexpenseId", IsIDFilter.instance);
+    String strcCurrencyId = info.getStringParameter("inpcCurrencyId", IsIDFilter.instance);
+    String strInvPrice = info.vars.getNumericParameter("inpinvoiceprice");
+    String strWindowId = info.vars.getStringParameter("inpwindowId", IsIDFilter.instance);
+    String strlastNetUnitPrice = info.vars.getNumericGlobalVariable("inplastNetUnitPrice",
+        strWindowId + "|lastNetUnitPrice", "0");
+    BigDecimal qty = info.getBigDecimalParameter("inpqty");
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars,
-      String strDateexpense, String strmProductId, String strsTimeexpenseId, String strqty,
-      String strcCurrencyId, String strInvPrice, String strChanged, String strTabId,
-      String strWindowId, String strlastNetUnitPrice) throws IOException, ServletException {
-    String localStrDateexpense = strDateexpense;
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
+    if (StringUtils.equals(strlastNetUnitPrice, "0")) {
+      strlastNetUnitPrice = strInvPrice;
+    }
+
+    BigDecimal invPrice = StringUtils.isNotEmpty(strInvPrice) ? new BigDecimal(strInvPrice)
+        : BigDecimal.ZERO;
+    BigDecimal lastNetUnitPrice = StringUtils.isNotEmpty(strlastNetUnitPrice) ? new BigDecimal(
+        strlastNetUnitPrice) : BigDecimal.ZERO;
     String strmPricelistId = SEExpenseProductData.priceList(this, strsTimeexpenseId);
     SEExpenseProductData[] data = SEExpenseProductData.select(this, strmProductId, strmPricelistId);
+    if (StringUtils.isEmpty(strDateexpense)) {
+      strDateexpense = StringUtils.isEmpty(SEExpenseProductData.selectReportDate(this,
+          strsTimeexpenseId)) ? DateTimeData.today(this) : SEExpenseProductData.selectReportDate(
+          this, strsTimeexpenseId);
+    }
 
-    String strUOM = SEExpenseProductData.selectUOM(this, strmProductId);
+    // Search for price
     boolean noPrice = true;
     String priceActual = "";
     String cCurrencyID = "";
-    BigDecimal qty = new BigDecimal(strqty);
-    BigDecimal amount = null;
-
-    final Organization org = OBDal.getInstance()
-        .get(org.openbravo.model.timeandexpense.Sheet.class, strsTimeexpenseId).getOrganization();
-
-    if (localStrDateexpense.equals("")) {
-      localStrDateexpense = SEExpenseProductData.selectReportDate(this, strsTimeexpenseId).equals(
-          "") ? DateTimeData.today(this) : SEExpenseProductData.selectReportDate(this,
-          strsTimeexpenseId);
-    }
-
-    BigDecimal invPrice = BigDecimal.ZERO;
-    BigDecimal lastNetUnitPrice = BigDecimal.ZERO;
-    if (!"".equals(strInvPrice)) {
-      invPrice = new BigDecimal(strInvPrice);
-    }
-    if (!"".equals(strlastNetUnitPrice)) {
-      lastNetUnitPrice = new BigDecimal(strlastNetUnitPrice);
-    }
-
-    if (strInvPrice.equals("")
-        || (strChanged.equals("inpmProductId") && invPrice.compareTo(lastNetUnitPrice) == 0)) {
+    if (StringUtils.isEmpty(strInvPrice)
+        || (StringUtils.equals(strChanged, "inpmProductId") && invPrice.compareTo(lastNetUnitPrice) == 0)) {
       for (int i = 0; data != null && i < data.length && noPrice; i++) {
-        if (data[i].validfrom == null || data[i].validfrom.equals("")
-            || !DateTimeData.compare(this, localStrDateexpense, data[i].validfrom).equals("-1")) {
+        if (StringUtils.isEmpty(data[i].validfrom)
+            || !StringUtils.equals(DateTimeData.compare(this, strDateexpense, data[i].validfrom),
+                "-1")) {
           noPrice = false;
           // Price
           priceActual = data[i].pricestd;
-          if (priceActual.equals(""))
-            priceActual = data[i].pricelist;
-          if (priceActual.equals(""))
-            priceActual = data[i].pricelimit;
+          if (StringUtils.isEmpty(priceActual)) {
+            priceActual = StringUtils.isNotEmpty(data[i].pricelist) ? data[i].pricelist
+                : data[i].pricelimit;
+          }
           // Currency
           cCurrencyID = data[i].cCurrencyId;
         }
@@ -130,111 +92,101 @@
       if (noPrice) {
         data = SEExpenseProductData.selectBasePriceList(this, strmProductId, strmPricelistId);
         for (int i = 0; data != null && i < data.length && noPrice; i++) {
-          if (data[i].validfrom == null || data[i].validfrom.equals("")
-              || !DateTimeData.compare(this, localStrDateexpense, data[i].validfrom).equals("-1")) {
+          if (StringUtils.isEmpty(data[i].validfrom)
+              || !StringUtils.equals(DateTimeData.compare(this, strDateexpense, data[i].validfrom),
+                  "-1")) {
             noPrice = false;
             // Price
             priceActual = data[i].pricestd;
-            if (priceActual.equals(""))
-              priceActual = data[i].pricelist;
-            if (priceActual.equals(""))
-              priceActual = data[i].pricelimit;
+            if (StringUtils.isEmpty(priceActual)) {
+              priceActual = StringUtils.isNotEmpty(data[i].pricelist) ? data[i].pricelist
+                  : data[i].pricelimit;
+            }
             // Currency
             cCurrencyID = data[i].cCurrencyId;
           }
         }
       }
-      vars.setSessionValue(strWindowId + "|lastNetUnitPrice", priceActual);
+      info.vars.setSessionValue(strWindowId + "|lastNetUnitPrice", priceActual);
     } else {
       priceActual = strInvPrice;
     }
 
-    if (strChanged.equals("inpqty") || cCurrencyID.equals("")) {
+    if (StringUtils.equals(strChanged, "inpqty") || StringUtils.isEmpty(cCurrencyID)) {
       cCurrencyID = strcCurrencyId;
     }
-    String strPrecision = "0";
-    if (!cCurrencyID.equals("")) {
-      strPrecision = SEExpenseProductData.selectPrecision(this, cCurrencyID);
+
+    int stdPrecision = 0;
+    if (StringUtils.isNotEmpty(cCurrencyID)) {
+      stdPrecision = Integer.valueOf(SEExpenseProductData.selectPrecision(this, cCurrencyID));
     }
-    int stdPrecision = Integer.valueOf(strPrecision).intValue();
 
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SE_Expense_Product';\n\n");
-    resultado.append("var respuesta = new Array(");
-    resultado.append("new Array(\"inpcUomId\", \"" + strUOM + "\")\n");
+    // Update the UOM
+    String strUOM = SEExpenseProductData.selectUOM(this, strmProductId);
+    info.addResult("inpcUomId", strUOM);
 
-    if (!priceActual.equals("")) {
-      amount = new BigDecimal(priceActual);
-      amount = amount.multiply(qty);
-    } else {
-      amount = BigDecimal.ZERO;
+    // Calculate the Price and Expense Amount
+    BigDecimal price = BigDecimal.ZERO;
+    BigDecimal amount = BigDecimal.ZERO;
+    if (StringUtils.isNotEmpty(priceActual)) {
+      price = new BigDecimal(priceActual);
+      amount = price.multiply(qty);
     }
-    if (amount.scale() > stdPrecision)
+    if (amount.scale() > stdPrecision) {
       amount = amount.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
-    resultado.append(", new Array(\"inpexpenseamt\", " + amount.toPlainString() + ")");
-    resultado.append(", new Array(\"inpinvoiceprice\", "
-        + (priceActual.equals("") ? "\"\"" : priceActual) + ")");
+    }
+    info.addResult("inpexpenseamt", amount);
+    info.addResult("inpinvoiceprice", price);
 
+    // Get currency to from org's currency or client's currency if it doesn't exists
+    final Organization org = OBDal.getInstance().get(Sheet.class, strsTimeexpenseId)
+        .getOrganization();
     String c_Currency_To_ID = getCurrency(org.getId());
     if (c_Currency_To_ID == null) {
-      c_Currency_To_ID = OBDal.getInstance()
-          .get(org.openbravo.model.timeandexpense.Sheet.class, strsTimeexpenseId).getClient()
+      c_Currency_To_ID = OBDal.getInstance().get(Sheet.class, strsTimeexpenseId).getClient()
           .getCurrency().getId();
     }
 
     // Checks if there is a conversion rate for each of the transactions of
     // the report
-    String strConvRateErrorMsg = "";
-    OBError myMessage = null;
-    myMessage = new OBError();
-    if (!cCurrencyID.equals("")) {
-      String convertedAmount = amount.toPlainString();
-      if (!cCurrencyID.equals(c_Currency_To_ID)) {
+    if (StringUtils.isNotEmpty(cCurrencyID)) {
+      BigDecimal convAmount = amount;
+      if (!StringUtils.equals(cCurrencyID, c_Currency_To_ID)) {
+        String convertedAmount = amount.toPlainString();
         try {
           convertedAmount = SEExpenseProductData.selectConvertedAmt(this, amount.toPlainString(),
-              cCurrencyID, c_Currency_To_ID, localStrDateexpense, vars.getClient(), org.getId());
-        } catch (ServletException e) {
+              cCurrencyID, c_Currency_To_ID, strDateexpense, info.vars.getClient(), org.getId());
+        } catch (Exception e) {
           convertedAmount = "";
-          myMessage = Utility.translateError(this, vars, vars.getLanguage(), e.getMessage());
-          strConvRateErrorMsg = myMessage.getMessage();
+          OBDal.getInstance().rollbackAndClose();
+          info.showMessage(Utility.translateError(this, info.vars, info.vars.getLanguage(),
+              e.getMessage()).getMessage());
           log4j.warn("Currency does not exist. Exception:" + e);
         }
+        convAmount = StringUtils.isNotEmpty(convertedAmount) ? new BigDecimal(convertedAmount)
+            : BigDecimal.ZERO;
+        int stdPrecisionConv = 0;
+        if (StringUtils.isNotEmpty(c_Currency_To_ID)) {
+          stdPrecisionConv = Integer.valueOf(SEExpenseProductData.selectPrecision(this,
+              c_Currency_To_ID));
+        }
+        if (convAmount.scale() > stdPrecisionConv) {
+          convAmount = convAmount.setScale(stdPrecisionConv, BigDecimal.ROUND_HALF_UP);
+        }
       }
-      String strPrecisionConv = "0";
-      if (!c_Currency_To_ID.equals("")) {
-        strPrecisionConv = SEExpenseProductData.selectPrecision(this, c_Currency_To_ID);
-      }
-      int stdPrecisionConv = Integer.valueOf(strPrecisionConv).intValue();
-      BigDecimal convAmount;
-      if (!convertedAmount.equals("")) {
-        convAmount = new BigDecimal(convertedAmount);
-      } else {
-        convAmount = BigDecimal.ZERO;
-      }
-      if (convAmount.scale() > stdPrecisionConv)
-        convAmount = convAmount.setScale(stdPrecisionConv, BigDecimal.ROUND_HALF_UP);
-      resultado.append(", new Array(\"inpconvertedamt\", "
-          + (convAmount.compareTo(BigDecimal.ZERO) == 0 ? "\"\"" : convAmount.toPlainString())
-          + ")");
-    }
-    if (strChanged.equals("inpmProductId") && !cCurrencyID.equals("")) {
-      resultado.append(", new Array(\"inpcCurrencyId\", \"" + cCurrencyID + "\")");
-    }
-    if (!strConvRateErrorMsg.equals("") && strConvRateErrorMsg != null) {
-      resultado.append(", new Array('MESSAGE', \"" + strConvRateErrorMsg + "\")");
+      // Update Converted Amount
+      info.addResult("inpconvertedamt", convAmount.compareTo(BigDecimal.ZERO) != 0 ? convAmount
+          : null);
     }
 
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    // If the product was changed, then update the currency
+    if (StringUtils.equals(strChanged, "inpmProductId") && StringUtils.isNotEmpty(cCurrencyID)) {
+      info.addResult("inpcCurrencyId", cCurrencyID);
+    }
   }
 
   private static String getCurrency(String org) {
-    if (org.equals("0")) {
+    if (StringUtils.equals(org, "0")) {
       return null;
     } else {
       Organization organization = OBDal.getInstance().get(Organization.class, org);
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_ExternalPOS_BPartner.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_ExternalPOS_BPartner.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,81 +11,47 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
+import org.openbravo.erpCommon.utility.Utility;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.erpCommon.utility.Utility;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SE_ExternalPOS_BPartner extends SimpleCallout {
 
-public class SE_ExternalPOS_BPartner extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
-
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strBPartner = vars.getStringParameter("inpcBpartnerId");
-      String strWindowId = vars.getStringParameter("inpwindowId");
-      String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
-      String strPriceList = vars.getStringParameter("inpmPricelistId");
-      try {
-        printPage(response, vars, strWindowId, strBPartner, strIsSOTrx, strPriceList);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strWindowId,
-      String strBPartner, String strIsSOTrx, String strPriceList0) throws IOException,
-      ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    SEExternalPOSBPartnerData[] data = SEExternalPOSBPartnerData.select(this, strBPartner);
-    String strPriceList = "";
-    if (data != null && data.length > 0) {
-      strPriceList = (strIsSOTrx.equals("Y") ? data[0].mPricelistId : data[0].poPricelistId);
-      strPriceList = strPriceList.equals("") ? strPriceList0 : strPriceList;
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
     }
 
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SE_ExternalPOS_BPartner';\n\n");
-    resultado.append("var respuesta = new Array(");
-    resultado.append("new Array(\"inpmPricelistId\", \""
-        + (strPriceList.equals("") ? Utility.getContext(this, vars, "#M_PriceList_ID", strWindowId)
-            : strPriceList) + "\")");
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "frameAplicacion");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    // Parameters
+    String strBPartner = info.getStringParameter("inpcBpartnerId", IsIDFilter.instance);
+    String strWindowId = info.getStringParameter("inpwindowId", IsIDFilter.instance);
+    String strPriceList = info.getStringParameter("inpmPricelistId", IsIDFilter.instance);
+    String strIsSOTrx = Utility.getContext(this, info.vars, "isSOTrx", strWindowId);
+
+    String strBPPriceList = "";
+    SEExternalPOSBPartnerData[] data = SEExternalPOSBPartnerData.select(this, strBPartner);
+    if (data != null && data.length > 0) {
+      strBPPriceList = (StringUtils.equals(strIsSOTrx, "Y") ? data[0].mPricelistId
+          : data[0].poPricelistId);
+      strBPPriceList = StringUtils.isEmpty(strBPPriceList) ? strPriceList : strBPPriceList;
+    }
+
+    // Update the price list
+    info.addResult(
+        "inpmPricelistId",
+        StringUtils.isEmpty(strBPPriceList) ? Utility.getContext(this, info.vars,
+            "#M_PriceList_ID", strWindowId) : strBPPriceList);
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_FinancialAccount_BSAccounts.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_FinancialAccount_BSAccounts.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,132 +11,65 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2010-2011 Openbravo SLU
+ * All portions are Copyright (C) 2010-2017 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
+import org.apache.commons.lang.StringUtils;
 import org.openbravo.base.filter.IsIDFilter;
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.utility.Utility;
-import org.openbravo.model.financialmgmt.accounting.coa.AccountingCombination;
 import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
 import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SE_FinancialAccount_BSAccounts extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SE_FinancialAccount_BSAccounts extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      final String strChanged = vars.getStringParameter("inpLastFieldChanged");
+    final String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
       log4j.debug("CHANGED: " + strChanged);
-      final String strfinFinancialAccountId = vars.getStringParameter("inpfinFinancialAccountId",
-          IsIDFilter.instance);
+    }
 
-      try {
-        printPage(response, vars, strChanged, strfinFinancialAccountId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
+    // Parameters
+    final String strfinFinancialAccountId = info.getStringParameter("inpfinFinancialAccountId",
+        IsIDFilter.instance);
+    final String strfinTransitoryAcct = info.getStringParameter("inpfinTransitoryAcct",
+        IsIDFilter.instance);
+    final String strOB3UIMode = info.vars.getStringParameter("inpOB3UIMode", "N");
+
+    if (info.vars.commandIn("EXECUTE")) {
+      updatePaymentMethodConfiguration(strfinFinancialAccountId);
+      info.addResult("inpfinInClearAcct", strfinTransitoryAcct);
+      info.addResult("inpfinOutClearAcct", strfinTransitoryAcct);
+    }
+
+    else {
+      if (StringUtils.equals(strChanged, "inpfinTransitoryAcct")
+          && StringUtils.isNotEmpty(strfinTransitoryAcct)) {
+        String strConfirmMessage = Utility.messageBD(this, "BankStatementAccountWarning",
+            info.vars.getLanguage());
+        if (StringUtils.equals(strOB3UIMode, "Y")) {
+          String strScript = "OB.APRM.bankTransitoryAccountCalloutResponse(this, '"
+              + strConfirmMessage.replaceAll("\\\\n", "<br>") + "', '" + strfinFinancialAccountId
+              + "')";
+          info.addResult("JSEXECUTE", strScript);
+        } else {
+          String strScript = "(function(){var confirmation = confirm(\'"
+              + strConfirmMessage.replaceAll("\\\\n", "\\\\\\\\n")
+              + "\'); if(confirmation){submitCommandFormParameter(\'EXECUTE\', frmMain.inpLastFieldChanged, \'"
+              + strChanged
+              + "\', false, null, \'../ad_callouts/SE_FinancialAccount_BSAccounts.html\', \'hiddenFrame\', null, null, true);}})();";
+          info.addResult("EXECUTE", strScript);
+        }
       }
-    } else if (vars.commandIn("EXECUTE")) {
-      final String strfinTransitoryAcct = vars.getStringParameter("inpfinTransitoryAcct",
-          IsIDFilter.instance);
-      final String strfinFinancialAccountId = vars.getStringParameter("inpfinFinancialAccountId",
-          IsIDFilter.instance);
-      try {
-        updatePaymentMethodConfiguration(strfinFinancialAccountId);
-        printPageResponse(response, strfinTransitoryAcct);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strChanged,
-      String strFinancialAccountId) throws IOException, ServletException {
-    log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    String strOB3UIMode = vars.getStringParameter("inpOB3UIMode", "N");
-    String strfinTransitoryAcct = vars.getStringParameter("inpfinTransitoryAcct",
-        IsIDFilter.instance);
-    StringBuffer resultado = new StringBuffer();
-
-    if ("inpfinTransitoryAcct".equals(strChanged) && !"".equals(strfinTransitoryAcct)) {
-      resultado.append("var calloutName='SE_FinancialAccount_BSAccounts';\n\n");
-      resultado.append("var respuesta = new Array(");
-
-      String strConfirmMessage = Utility.messageBD(this, "BankStatementAccountWarning",
-          vars.getLanguage());
-      if ("Y".equals(strOB3UIMode)) {
-        resultado.append("new Array(\"JSEXECUTE\","
-            + " \"OB.APRM.bankTransitoryAccountCalloutResponse(this, '"
-            + strConfirmMessage.replaceAll("\\\\n", "<br>") + "', '" + strFinancialAccountId
-            + "')\")");
-      } else {
-        String strScript = "(function(){var confirmation = confirm(\'"
-            + strConfirmMessage.replaceAll("\\\\n", "\\\\\\\\n")
-            + "\'); if(confirmation){submitCommandFormParameter(\'EXECUTE\', frmMain.inpLastFieldChanged, \'"
-            + strChanged
-            + "\', false, null, \'../ad_callouts/SE_FinancialAccount_BSAccounts.html\', \'hiddenFrame\', null, null, true);}})();";
-        resultado.append("new Array(\"EXECUTE\", \"" + strScript + "\")");
-      }
-      resultado.append(");");
-    } else {
-      resultado.append("var calloutName='SE_FinancialAccount_BSAccounts';\n\n");
-      resultado.append("var respuesta = null;");
     }
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
-  }
-
-  private void printPageResponse(HttpServletResponse response, String strfinTransitoryAcct)
-      throws IOException, ServletException {
-    log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    StringBuffer resultado = new StringBuffer();
-    AccountingCombination transitoryAccount = OBDal.getInstance().get(AccountingCombination.class,
-        strfinTransitoryAcct);
-    resultado.append("var calloutName='SE_FinancialAccount_BSAccounts';\n\n");
-    resultado.append("var respuesta = new Array(");
-    resultado.append("new Array(\"inpfinInClearAcct\", \"" + strfinTransitoryAcct + "\"),");
-    resultado.append("new Array(\"inpfinOutClearAcct\", \"" + strfinTransitoryAcct + "\"),");
-    resultado.append("new Array(\"inpfinOutClearAcct_R\", \"" + transitoryAccount.getCombination()
-        + "\"),");
-    resultado.append("new Array(\"inpfinInClearAcct_R\", \"" + transitoryAccount.getCombination()
-        + "\"));");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
 
   void updatePaymentMethodConfiguration(String strfinFinancialAccountId) {
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_InOut_DocType.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_InOut_DocType.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,85 +11,45 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SE_InOut_DocType extends SimpleCallout {
 
-public class SE_InOut_DocType extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
-
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strTabId = vars.getStringParameter("inpTabId");
-      String strDocType = vars.getStringParameter("inpcDoctypeId");
-
-      try {
-        printPage(response, vars, strDocType, strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strDocType,
-      String strTabId) throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
-    SEInOutDocTypeData[] data = SEInOutDocTypeData.select(this, strDocType);
-
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SE_InOut_DocType';\n\n");
-    if (data != null && data.length > 0) {
-      resultado.append("var respuesta = new Array(");
-      if (data[0].docbasetype.equals("MMS"))
-        resultado.append("new Array(\"inpmovementtype\", \"C-\")");
-      else if (data[0].docbasetype.equals("MMR"))
-        resultado.append("new Array(\"inpmovementtype\", \"V+\")");
-      else
-        resultado.append("new Array(\"inpmovementtype\", \"\")");
-      if (data[0].isdocnocontrolled.equals("Y"))
-        resultado.append(", new Array(\"inpdocumentno\", \"<" + data[0].currentnext + ">\")");
-      resultado.append("\n);");
-    } else {
-      resultado.append("var respuesta = new Array(");
-      resultado.append("new Array(\"inpmovementtype\", \"\")");
-      resultado.append(");");
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
     }
 
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    // Parameter
+    String strDocType = info.getStringParameter("inpcDoctypeId", IsIDFilter.instance);
+
+    // Movement Type and Document No.
+    SEInOutDocTypeData[] data = SEInOutDocTypeData.select(this, strDocType);
+    if (data != null && data.length > 0) {
+      if (StringUtils.equals(data[0].docbasetype, "MMS")) {
+        info.addResult("inpmovementtype", "C-");
+      } else if (StringUtils.equals(data[0].docbasetype, "MMR")) {
+        info.addResult("inpmovementtype", "V+");
+      } else {
+        info.addResult("inpmovementtype", null);
+      }
+      if (StringUtils.equals(data[0].isdocnocontrolled, "Y")) {
+        info.addResult("inpdocumentno", "<" + data[0].currentnext + ">");
+      }
+    }
+
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Invoice_BPartner.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Invoice_BPartner.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,26 +11,21 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2001-2016 Openbravo SLU
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.lang.StringUtils;
 import org.hibernate.criterion.Restrictions;
 import org.openbravo.advpaymentmngt.utility.FIN_Utility;
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
@@ -44,326 +39,180 @@
 import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
 import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
-import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SE_Invoice_BPartner extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SE_Invoice_BPartner extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strBPartner = vars.getStringParameter("inpcBpartnerId");
-      String strDocType = vars.getStringParameter("inpcDoctypetargetId");
-      String strLocation = vars.getStringParameter("inpcBpartnerId_LOC");
-      String strContact = vars.getStringParameter("inpcBpartnerId_CON");
-      String strWindowId = vars.getStringParameter("inpwindowId");
-      String strProjectId = vars.getStringParameter("inpcProjectId");
-      String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
-      String strTabId = vars.getStringParameter("inpTabId");
-      String strfinPaymentmethodId = vars.getStringParameter("inpfinPaymentmethodId");
-      String strOrgId = vars.getStringParameter("inpadOrgId");
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-      try {
-        if ("inpfinPaymentmethodId".equals(strChanged)) { // Payment Method changed
-          printPagePaymentMethod(response, vars, strBPartner, strIsSOTrx, strfinPaymentmethodId,
-              strOrgId);
-        } else {
-          printPage(response, vars, strBPartner, strDocType, strIsSOTrx, strWindowId, strLocation,
-              strContact, strProjectId, strTabId, strOrgId);
-        }
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // Parameters
+    String strBPartner = info.getStringParameter("inpcBpartnerId", IsIDFilter.instance);
+    String strDocType = info.getStringParameter("inpcDoctypetargetId", IsIDFilter.instance);
+    String strLocation = info.getStringParameter("inpcBpartnerId_LOC", IsIDFilter.instance);
+    String strContact = info.getStringParameter("inpcBpartnerId_CON", IsIDFilter.instance);
+    String strIsSOTrx = Utility.getContext(this, info.vars, "isSOTrx", info.getWindowId());
+    String strfinPaymentmethodId = info.getStringParameter("inpfinPaymentmethodId",
+        IsIDFilter.instance);
+    String strOrgId = info.getStringParameter("inpadOrgId", IsIDFilter.instance);
+    boolean isSales = StringUtils.equals(strIsSOTrx, "Y");
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strBPartner,
-      String strDocType, String strIsSOTrx, String strWindowId, String strLocation,
-      String strContact, String strProjectId, String strTabId, String strOrgId) throws IOException,
-      ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
-    if (strBPartner.equals(""))
-      vars.removeSessionValue(strWindowId + "|C_BPartner_ID");
-
-    BpartnerMiscData[] data = BpartnerMiscData.select(this, strBPartner);
-    String strUserRep;
-    String DocBaseType = SEInvoiceBPartnerData.docBaseType(this, strDocType);
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SE_Invoice_BPartner';\n\n");
-    if (data == null || data.length == 0)
-      resultado.append("var respuesta = new Array(new Array(\"inpcBpartnerLocationId\", null));");
+    // Payment Method changed
+    if (StringUtils.equals(strChanged, "inpfinPaymentmethodId")
+        && StringUtils.isNotEmpty(strBPartner)) {
+      String message = isAutomaticCombination(info.vars, strBPartner, isSales,
+          strfinPaymentmethodId, strOrgId);
+      info.addResult("MESSAGE", message);
+    }
 
     else {
-      resultado.append("var respuesta = new Array(");
-      strUserRep = SEOrderBPartnerData.userIdSalesRep(this, data[0].salesrepId);
-      if (StringUtils.isEmpty(strUserRep)) {
-        strUserRep = vars.getUser();
-      }
-      String strPriceList = (strIsSOTrx.equals("Y") ? data[0].mPricelistId : data[0].poPricelistId);
-      if (strPriceList.equalsIgnoreCase("")) {
-        strPriceList = SEOrderBPartnerData.defaultPriceList(this, strIsSOTrx, vars.getClient());
-      }
-      resultado.append("new Array(\"inpmPricelistId\", \""
-          + (strPriceList.equals("") ? Utility.getContext(this, vars, "#M_PriceList_ID",
-              strWindowId) : strPriceList) + "\"),");
-
-      String strPaymentRule = (strIsSOTrx.equals("Y") ? data[0].paymentrule : data[0].paymentrulepo);
-      if (strPaymentRule.equals("") && DocBaseType.endsWith("C"))
-        strPaymentRule = "P";
-      else if (strPaymentRule.equals("S") || strPaymentRule.equals("U") && strIsSOTrx.equals("Y"))
-        strPaymentRule = "P";
-      resultado.append("new Array(\"inppaymentrule\", \"" + strPaymentRule + "\"),");
-      String strFinPaymentMethodId = (strIsSOTrx.equals("Y") ? data[0].finPaymentmethodId
-          : data[0].poPaymentmethodId);
-      resultado.append("new Array(\"inpfinPaymentmethodId\", \"" + strFinPaymentMethodId + "\"),");
-      String PaymentTerm = (strIsSOTrx.equals("Y") ? data[0].cPaymenttermId
-          : data[0].poPaymenttermId);
-      if (PaymentTerm.equalsIgnoreCase("")) {
-        BpartnerMiscData[] paymentTerm = BpartnerMiscData.selectPaymentTerm(this, strOrgId,
-            vars.getClient());
-        if (paymentTerm.length != 0) {
-          PaymentTerm = PaymentTerm.equals("") ? paymentTerm[0].cPaymenttermId : PaymentTerm;
-        }
-      }
-      resultado.append("new Array(\"inpcPaymenttermId\", \"" + PaymentTerm + "\"),");
-      FieldProvider[] tdv = null;
-      try {
-        ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR",
-            "C_BPartner_Location_ID", "", "C_BPartner Location - Bill To", Utility.getContext(this,
-                vars, "#AccessibleOrgTree", strWindowId), Utility.getContext(this, vars,
-                "#User_Client", strWindowId), 0);
-        Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
-        tdv = comboTableData.select(false);
-        comboTableData = null;
-      } catch (Exception ex) {
-        throw new ServletException(ex);
+      if (StringUtils.isEmpty(strBPartner)) {
+        info.vars.removeSessionValue(info.getWindowId() + "|C_BPartner_ID");
       }
 
-      resultado.append("new Array(\"inpcBpartnerLocationId\", ");
+      BpartnerMiscData[] data = BpartnerMiscData.select(this, strBPartner);
+      if (data == null || data.length == 0) {
+        info.addResult("inpcBpartnerLocationId", null);
+      }
 
-      if (tdv != null && tdv.length > 0) {
-        resultado.append("new Array(");
-        if (strLocation.isEmpty()) {
-          // If no location is provided, the first one is selected
-          resultado.append("new Array(\"" + tdv[0].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tdv[0].getField("name")) + "\", \"" + "true" + "\")");
-          if (tdv.length > 1) {
-            resultado.append(",\n");
+      else {
+        // BPartner Location
+        if (StringUtils.isNotEmpty(strLocation)) {
+          info.addResult("inpcBpartnerLocationId", strLocation);
+        }
+
+        // Price List
+        String strPriceList = isSales ? data[0].mPricelistId : data[0].poPricelistId;
+        if (StringUtils.isEmpty(strPriceList)) {
+          strPriceList = SEOrderBPartnerData.defaultPriceList(this, strIsSOTrx,
+              info.vars.getClient());
+        }
+        info.addResult(
+            "inpmPricelistId",
+            StringUtils.isEmpty(strPriceList) ? Utility.getContext(this, info.vars,
+                "#M_PriceList_ID", info.getWindowId()) : strPriceList);
+
+        // Payment Rule
+        String strPaymentRule = isSales ? data[0].paymentrule : data[0].paymentrulepo;
+        String docBaseType = SEInvoiceBPartnerData.docBaseType(this, strDocType);
+        if (StringUtils.isEmpty(strPaymentRule) && StringUtils.endsWith(docBaseType, "C")) {
+          strPaymentRule = "P";
+        }
+        info.addResult("inppaymentrule", strPaymentRule);
+
+        // Payment Method
+        String strFinPaymentMethodId = isSales ? data[0].finPaymentmethodId
+            : data[0].poPaymentmethodId;
+        info.addResult("inpfinPaymentmethodId", strFinPaymentMethodId);
+
+        // Payment Terms
+        String paymentTerm = isSales ? data[0].cPaymenttermId : data[0].poPaymenttermId;
+        if (StringUtils.isEmpty(paymentTerm)) {
+          BpartnerMiscData[] term = BpartnerMiscData.selectPaymentTerm(this, strOrgId,
+              info.vars.getClient());
+          if (term.length != 0) {
+            paymentTerm = term[0].cPaymenttermId;
           }
-          for (int i = 1; i < tdv.length; i++) {
-            resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-                + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \"" + "false" + "\")");
-            if (i < tdv.length - 1)
-              resultado.append(",\n");
+        }
+        info.addResult("inpcPaymenttermId", paymentTerm);
+
+        // Sales Representative
+        FieldProvider[] tld = null;
+        try {
+          ComboTableData comboTableData = new ComboTableData(info.vars, this, "TABLE", "",
+              "AD_User SalesRep", "", Utility.getReferenceableOrg(info.vars, strOrgId),
+              Utility.getContext(this, info.vars, "#User_Client", info.getWindowId()), 0);
+          Utility.fillSQLParameters(this, info.vars, null, comboTableData, info.getWindowId(), "");
+          tld = comboTableData.select(false);
+          comboTableData = null;
+        } catch (Exception ex) {
+          throw new ServletException(ex);
+        }
+        if (tld != null && tld.length > 0) {
+          String strUserRep = SEOrderBPartnerData.userIdSalesRep(this, data[0].salesrepId);
+          if (StringUtils.isEmpty(strUserRep)) {
+            strUserRep = info.vars.getUser();
           }
+          info.addSelect("inpsalesrepId");
+          for (int i = 0; i < tld.length; i++) {
+            info.addSelectResult(tld[i].getField("id"), tld[i].getField("name"),
+                StringUtils.equalsIgnoreCase(tld[i].getField("id"), strUserRep));
+          }
+          info.endSelect();
         } else {
-          // If a location is provided, it is selected
-          for (int i = 0; i < tdv.length; i++) {
-            resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-                + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \""
-                + (tdv[i].getField("id").equalsIgnoreCase(strLocation) ? "true" : "false") + "\")");
-            if (i < tdv.length - 1) {
-              resultado.append(",\n");
+          info.addResult("inpsalesrepId", null);
+        }
+
+        // Business Partner Contact
+        FieldProvider[] tdv = null;
+        try {
+          ComboTableData comboTableData = new ComboTableData(info.vars, this, "TABLEDIR",
+              "AD_User_ID", "", "AD_User C_BPartner User/Contacts", Utility.getReferenceableOrg(
+                  info.vars, strOrgId), Utility.getContext(this, info.vars, "#User_Client",
+                  info.getWindowId()), 0);
+          Utility.fillSQLParameters(this, info.vars, null, comboTableData, info.getWindowId(), "");
+          tdv = comboTableData.select(false);
+          comboTableData = null;
+        } catch (Exception ex) {
+          throw new ServletException(ex);
+        }
+        if (tdv != null && tdv.length > 0) {
+          info.addSelect("inpadUserId");
+          if (StringUtils.isEmpty(strContact)) {
+            // If a contact has not been specified, the first one is selected
+            info.addSelectResult(tdv[0].getField("id"), tdv[0].getField("name"), true);
+            for (int i = 1; i < tdv.length; i++) {
+              info.addSelectResult(tdv[i].getField("id"), tdv[i].getField("name"), false);
+            }
+          } else {
+            for (int i = 0; i < tdv.length; i++) {
+              info.addSelectResult(tdv[i].getField("id"), tdv[i].getField("name"),
+                  StringUtils.equalsIgnoreCase(tdv[i].getField("id"), strContact));
             }
           }
-        }
-        resultado.append("\n)");
-      } else {
-        resultado.append("null");
-      }
-
-      resultado.append("\n),");
-      resultado.append("new Array(\"inpsalesrepId\", ");
-      FieldProvider[] tld = null;
-      try {
-        ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "",
-            "AD_User SalesRep", "", Utility.getContext(this, vars, "#AccessibleOrgTree",
-                "SEInvoiceBPartner"), Utility.getContext(this, vars, "#User_Client",
-                "SEInvoiceBPartner"), 0);
-        Utility.fillSQLParameters(this, vars, null, comboTableData, "SEInvoiceBPartner", "");
-        tld = comboTableData.select(false);
-        comboTableData = null;
-      } catch (Exception ex) {
-        throw new ServletException(ex);
-      }
-
-      if (tld != null && tld.length > 0) {
-        resultado.append("new Array(");
-        for (int i = 0; i < tld.length; i++) {
-          resultado.append("new Array(\"" + tld[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \""
-              + (tld[i].getField("id").equalsIgnoreCase(strUserRep) ? "true" : "false") + "\")");
-          if (i < tld.length - 1)
-            resultado.append(",\n");
-        }
-        resultado.append("\n)");
-      } else
-        resultado.append("null");
-      resultado.append("\n),");
-      resultado.append("new Array(\"inpcProjectId\", \"\"),");
-      resultado.append("new Array(\"inpcProjectId_R\", \"\"),");
-      try {
-        ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "AD_User_ID",
-            "", "AD_User C_BPartner User/Contacts", Utility.getContext(this, vars,
-                "#AccessibleOrgTree", strWindowId), Utility.getContext(this, vars, "#User_Client",
-                strWindowId), 0);
-        Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
-        tdv = comboTableData.select(false);
-        comboTableData = null;
-      } catch (Exception ex) {
-        throw new ServletException(ex);
-      }
-
-      resultado.append("new Array(\"inpcBpartnerContactId\", ");
-      if (tdv != null && tdv.length > 0) {
-        resultado.append("new Array(");
-        if (strContact.isEmpty()) {
-          // If a contactID has not been specified, the first one is selected
-          resultado.append("new Array(\"" + tdv[0].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tdv[0].getField("name")) + "\", \"" + "true" + "\")");
-          if (tdv.length > 1) {
-            resultado.append(",\n");
-          }
-          for (int i = 1; i < tdv.length; i++) {
-            resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-                + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \"" + "false" + "\")");
-            if (i < tdv.length - 1) {
-              resultado.append(",\n");
-            }
-          }
+          info.endSelect();
         } else {
-          for (int i = 0; i < tdv.length; i++) {
-            resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-                + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \""
-                + (tdv[i].getField("id").equalsIgnoreCase(strContact) ? "true" : "false") + "\")");
-            if (i < tdv.length - 1) {
-              resultado.append(",\n");
-            }
-          }
-        }
-        resultado.append("\n)");
-      } else
-        resultado.append("null");
-      resultado.append("\n),");
-
-      try {
-        ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "AD_User_ID",
-            "", "AD_User C_BPartner User/Contacts", Utility.getContext(this, vars,
-                "#AccessibleOrgTree", strWindowId), Utility.getContext(this, vars, "#User_Client",
-                strWindowId), 0);
-        Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
-        tdv = comboTableData.select(false);
-        comboTableData = null;
-      } catch (Exception ex) {
-        throw new ServletException(ex);
-      }
-
-      resultado.append("new Array(\"inpadUserId\", ");
-      if (tdv != null && tdv.length > 0) {
-        resultado.append("new Array(");
-
-        if (strContact.isEmpty()) {
-          resultado.append("new Array(\"" + tdv[0].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tdv[0].getField("name")) + "\", \"" + "true" + "\")");
-          if (tdv.length > 1) {
-            resultado.append(",\n");
-          }
-          for (int i = 1; i < tdv.length; i++) {
-            resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-                + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \"" + "false" + "\")");
-            if (i < tdv.length - 1) {
-              resultado.append(",\n");
-            }
-          }
-        } else {
-          for (int i = 0; i < tdv.length; i++) {
-            resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-                + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \""
-                + (tdv[i].getField("id").equalsIgnoreCase(strContact) ? "true" : "false") + "\")");
-            if (i < tdv.length - 1) {
-              resultado.append(",\n");
-            }
-          }
+          info.addResult("inpadUserId", null);
         }
 
-        resultado.append("\n)");
-      } else
-        resultado.append("null");
-      resultado.append("\n),");
-      String strWithHolding = SEInvoiceBPartnerData.WithHolding(this, strBPartner);
-      resultado.append("new Array(\"inpcWithholdingId\", \"" + strWithHolding + "\"),");
-      resultado
-          .append("new Array(\"inpisdiscountprinted\", \"" + data[0].isdiscountprinted + "\")");
-      String message = "";
-      if (FIN_Utility.isBlockedBusinessPartner(strBPartner, "Y".equals(strIsSOTrx), 3)) {
-        // If the Business Partner is blocked for this document, show an information message.
-        BusinessPartner bPartner = OBDal.getInstance().get(BusinessPartner.class, strBPartner);
-        if (message.length() > 0) {
-          message = message + "<br>";
+        // Withholding
+        String strWithHolding = SEInvoiceBPartnerData.WithHolding(this, strBPartner);
+        info.addResult("inpcWithholdingId", strWithHolding);
+
+        // Print Discount
+        info.addResult("inpisdiscountprinted", data[0].isdiscountprinted);
+
+        // Project
+        info.addResult("inpcProjectId", null);
+        info.addResult("inpcProjectId_R", null);
+
+        // If the Business Partner is blocked for this document, show an information message
+        String message = "";
+        if (FIN_Utility.isBlockedBusinessPartner(strBPartner, isSales, 3)) {
+          BusinessPartner bPartner = OBDal.getInstance().get(BusinessPartner.class, strBPartner);
+          message = message + OBMessageUtils.messageBD("ThebusinessPartner") + " "
+              + bPartner.getIdentifier() + " " + OBMessageUtils.messageBD("BusinessPartnerBlocked");
         }
-        message = message + OBMessageUtils.messageBD("ThebusinessPartner") + " "
-            + bPartner.getIdentifier() + " " + OBMessageUtils.messageBD("BusinessPartnerBlocked");
+
+        // If the Business Partner has negative credit available, show an information message
+        if (new BigDecimal(data[0].creditavailable).compareTo(BigDecimal.ZERO) < 0 && isSales) {
+          String creditLimitExceed = "" + Double.parseDouble(data[0].creditavailable) * -1;
+          String automationPaymentMethod = isAutomaticCombination(info.vars, strBPartner, isSales,
+              strFinPaymentMethodId, strOrgId);
+          if (StringUtils.isNotEmpty(message)) {
+            message = message + "<br>";
+          }
+          message = message + Utility.messageBD(this, "CreditLimitOver", info.vars.getLanguage())
+              + creditLimitExceed + "<br/>" + automationPaymentMethod;
+        }
+
+        info.addResult("MESSAGE", message);
       }
-      if (data != null && data.length > 0
-          && new BigDecimal(data[0].creditavailable).compareTo(BigDecimal.ZERO) < 0
-          && strIsSOTrx.equals("Y")) {
-        String creditLimitExceed = "" + Double.parseDouble(data[0].creditavailable) * -1;
-        String automationPaymentMethod = isAutomaticCombination(vars, strBPartner, strIsSOTrx,
-            strFinPaymentMethodId, strOrgId);
-        if (message.length() > 0) {
-          message = message + "<br>";
-        }
-        message = message + Utility.messageBD(this, "CreditLimitOver", vars.getLanguage())
-            + creditLimitExceed + "<br/>" + automationPaymentMethod;
-      }
-
-      resultado.append(", new Array('MESSAGE', \"" + message + "\")");
-
-      resultado.append(");");
     }
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
-  }
-
-  private void printPagePaymentMethod(HttpServletResponse response, VariablesSecureApp vars,
-      String strBPartnerId, String strIsSOTrx, String strfinPaymentmethodId, String strOrgId)
-      throws IOException, ServletException {
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    StringBuilder result = new StringBuilder();
-
-    String message = isAutomaticCombination(vars, strBPartnerId, strIsSOTrx, strfinPaymentmethodId,
-        strOrgId);
-
-    result.append("var calloutName='SE_Invoice_BPartner';\n\n");
-    result.append("var respuesta = new Array(new Array(\"MESSAGE\", ");
-    result.append("\"" + message + "\"));");
-
-    xmlDocument.setParameter("array", result.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
 
   /**
@@ -374,8 +223,8 @@
    *          VariablesSecureApp.
    * @param strBPartnerId
    *          Business Partner id.
-   * @param strIsSOTrx
-   *          Sales ('Y') or purchase ('N') transaction.
+   * @param isSales
+   *          Sales (true) or purchase (false) transaction.
    * @param strfinPaymentmethodId
    *          Payment Method id.
    * @return Message to be displayed in the application warning the user that automatic actions
@@ -383,17 +232,16 @@
    *         financial account of the given business partner.
    */
   private String isAutomaticCombination(VariablesSecureApp vars, String strBPartnerId,
-      String strIsSOTrx, String strfinPaymentmethodId, String strOrgId) {
+      boolean isSales, String strfinPaymentmethodId, String strOrgId) {
     BusinessPartner bpartner = OBDal.getInstance().get(BusinessPartner.class, strBPartnerId);
     FIN_PaymentMethod selectedPaymentMethod = OBDal.getInstance().get(FIN_PaymentMethod.class,
         strfinPaymentmethodId);
     OBContext.setAdminMode(true);
     try {
-      boolean isSales = "Y".equals(strIsSOTrx);
       FIN_FinancialAccount account = null;
       String message = "";
 
-      if (bpartner != null && selectedPaymentMethod != null && !"".equals(strOrgId)) {
+      if (bpartner != null && selectedPaymentMethod != null && StringUtils.isNotEmpty(strOrgId)) {
         account = (isSales) ? bpartner.getAccount() : bpartner.getPOFinancialAccount();
         if (account != null) {
           OBCriteria<FinAccPaymentMethod> obc = OBDal.getInstance().createCriteria(
@@ -420,5 +268,4 @@
       OBContext.restorePreviousMode();
     }
   }
-
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Invoice_Project.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Invoice_Project.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,95 +11,47 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
+import org.openbravo.erpCommon.utility.Utility;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.erpCommon.utility.Utility;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SE_Invoice_Project extends SimpleCallout {
 
-public class SE_Invoice_Project extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strWindowId = vars.getStringParameter("inpwindowId");
-      String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
-      String strProjectId = vars.getStringParameter("inpcProjectId");
-      String strTabId = vars.getStringParameter("inpTabId");
+    // Parameters
+    String strIsSOTrx = Utility.getContext(this, info.vars, "isSOTrx", info.getWindowId());
+    String strProjectId = info.getStringParameter("inpcProjectId", IsIDFilter.instance);
 
-      try {
-        printPage(response, vars, strProjectId, strWindowId, strIsSOTrx, strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
+    if (StringUtils.equals(strIsSOTrx, "Y")) {
+      SEInvoiceProjectData[] data = SEInvoiceProjectData.select(this, strProjectId);
+      if (data != null && data.length > 0) {
+        // Payment Method
+        String strFinPaymentmethodId = data[0].finPaymentmethodId;
+        if (StringUtils.isNotEmpty(strFinPaymentmethodId)) {
+          info.addResult("inpfinPaymentmethodId", strFinPaymentmethodId);
+        }
+        // Payment Term
+        String strPaymentTerm = data[0].paymentterm;
+        if (StringUtils.isNotEmpty(strPaymentTerm)) {
+          info.addResult("inpcPaymenttermId", strPaymentTerm);
+        }
       }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars,
-      String strProjectId, String strWindowId, String strIsSOTrx, String strTabId)
-      throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
-    SEInvoiceProjectData[] data = SEInvoiceProjectData.select(this, strProjectId);
-
-    StringBuffer resultado = new StringBuffer();
-
-    if (strIsSOTrx.equals("Y")) {
-      if (data == null || data.length == 0) {
-        resultado.append("var calloutName='SE_Invoice_Project';\n\n");
-        resultado.append("var respuesta = null;");
-      } else {
-        resultado.append("var calloutName='SE_Invoice_Project';\n\n");
-        resultado.append("var respuesta = new Array(");
-
-        String strFinPaymentmethodId = data[0].finPaymentmethodId;
-        if (strFinPaymentmethodId != null && !"".equals(strFinPaymentmethodId)) {
-          resultado.append("new Array(\"inpfinPaymentmethodId\", \"" + strFinPaymentmethodId
-              + "\"),");
-        }
-        String PaymentTerm = data[0].paymentterm;
-        if (PaymentTerm != null && !"".equals(PaymentTerm)) {
-          resultado.append("new Array(\"inpcPaymenttermId\", \"" + PaymentTerm + "\")");
-        }
-        resultado.append(");");
-      }
-    } else {
-      resultado.append("var calloutName='SE_Invoice_Project';\n\n");
-      resultado.append("var respuesta = null;");
     }
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Order_Project.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Order_Project.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,92 +11,47 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
+import org.openbravo.erpCommon.utility.Utility;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.erpCommon.utility.Utility;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SE_Order_Project extends SimpleCallout {
 
-public class SE_Order_Project extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strWindowId = vars.getStringParameter("inpwindowId");
-      String strProjectId = vars.getStringParameter("inpcProjectId");
-      String strTabId = vars.getStringParameter("inpTabId");
-      String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
+    // Parameters
+    String strProjectId = info.getStringParameter("inpcProjectId", IsIDFilter.instance);
+    String strIsSOTrx = Utility.getContext(this, info.vars, "isSOTrx", info.getWindowId());
 
-      try {
-        printPage(response, vars, strProjectId, strTabId, strIsSOTrx);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars,
-      String strProjectId, String strTabId, String strIsSOTrx) throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
-    SEOrderProjectData[] data = SEOrderProjectData.select(this, strProjectId);
-    boolean hasData = false;
-    StringBuffer resultado = new StringBuffer();
-
-    if (strIsSOTrx.equals("Y")) {
-      resultado.append("var calloutName='SE_Order_Project';\n\n");
-      resultado.append("var respuesta = new Array(");
+    if (StringUtils.equals(strIsSOTrx, "Y")) {
+      SEOrderProjectData[] data = SEOrderProjectData.select(this, strProjectId);
       if (data != null && data.length > 0) {
-        if (!data[0].paymentrule.equals("")) {
-          String strPaymentRule = data[0].paymentrule;
-          resultado.append("new Array(\"inppaymentrule\", \"" + strPaymentRule + "\")");
-          hasData = true;
+        // Payment Rule
+        String strPaymentRule = data[0].paymentrule;
+        if (StringUtils.isNotEmpty(strPaymentRule)) {
+          info.addResult("inppaymentrule", strPaymentRule);
         }
-        if (!data[0].paymentterm.equals("")) {
-          if (hasData)
-            resultado.append(",");
-          String PaymentTerm = data[0].paymentterm;
-          resultado.append("new Array(\"inpcPaymenttermId\", \"" + PaymentTerm + "\")");
+        // Payment Term
+        String strPaymentTerm = data[0].paymentterm;
+        if (StringUtils.isNotEmpty(strPaymentTerm)) {
+          info.addResult("inpcPaymenttermId", strPaymentTerm);
         }
       }
-      resultado.append(");");
-    } else {
-      resultado.append("var calloutName='SE_Order_Project';\n\n");
-      resultado.append("var respuesta = null;");
     }
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_PeriodNo.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_PeriodNo.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,161 +11,90 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SE_PeriodNo extends SimpleCallout {
 
-public class SE_PeriodNo extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strOrgId = vars.getStringParameter("inpadOrgId");
-      String strCalendarId = vars.getStringParameter("inpcCalendarId");
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      String strYearId = vars.getStringParameter("inpcYearId");
-      String strWindowId = vars.getStringParameter("inpwindowId");
-      try {
-        printPage(response, vars, strYearId, strWindowId, strOrgId, strCalendarId, strChanged);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // Parameters
+    String strOrgId = info.getStringParameter("inpadOrgId", IsIDFilter.instance);
+    String strCalendarId = info.getStringParameter("inpcCalendarId", IsIDFilter.instance);
+    String strYearId = info.getStringParameter("inpcYearId", IsIDFilter.instance);
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strYearId,
-      String strWindowId, String strOrgId, String strCalendarId, String strChanged)
-      throws IOException, ServletException {
-    String localStrCalendarId = strCalendarId;
+    try {
 
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SE_PeriodNo';\n\n");
-    resultado.append("var respuesta = new Array(");
-
-    if (strChanged.equals("inpcYearId") && !strYearId.equals("")) {
-      SEPeriodNoData[] tdv = null;
       // Update the Periods
-      try {
+      if (StringUtils.equals(strChanged, "inpcYearId") && StringUtils.isNotEmpty(strYearId)) {
+        SEPeriodNoData[] tdv = null;
         tdv = SEPeriodNoData.getPeriodNo(this, strYearId);
-      } catch (Exception ex) {
-        throw new ServletException(ex);
+        if (tdv != null && tdv.length > 0) {
+          info.addSelect("inpperiodno");
+          for (int i = 0; i < tdv.length; i++) {
+            info.addSelectResult(tdv[i].getField("id"), tdv[i].getField("Name"));
+          }
+          info.endSelect();
+        }
       }
 
-      resultado.append("new Array(\"inpperiodno\", ");
-      if (tdv != null && tdv.length > 0) {
-        resultado.append("new Array(");
-        for (int i = 0; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + tdv[i].getField("Name") + "\")");
-          if (i < tdv.length - 1)
-            resultado.append(",\n");
+      else if (StringUtils.isNotEmpty(strOrgId)) {
+
+        // Update the Calendar
+        SEPeriodNoData[] tdv = null;
+        tdv = SEPeriodNoData.getCalendar(this, strOrgId);
+        if (tdv != null && tdv.length > 0) {
+          info.addSelect("inpcCalendarId");
+          for (int i = 0; i < tdv.length; i++) {
+            info.addSelectResult(tdv[i].getField("id"), tdv[i].getField("Name"));
+            strCalendarId = tdv[i].getField("id");
+          }
+          info.endSelect();
         }
-        resultado.append("\n)");
-      } else
-        resultado.append("null");
-      resultado.append("\n)");
-    } else if (!strOrgId.equals("")) {
-      SEPeriodNoData[] tdv = null;
-      // Update the Calendar
-      try {
-        tdv = SEPeriodNoData.getCalendar(this, strOrgId);
-      } catch (Exception ex) {
-        throw new ServletException(ex);
+
+        // Update the years
+        tdv = SEPeriodNoData.getYears(this, strCalendarId);
+        String strLastYear = "";
+        if (tdv != null && tdv.length > 0) {
+          info.addSelect("inpcYearId");
+          for (int i = 0; i < tdv.length; i++) {
+            info.addSelectResult(tdv[i].getField("id"), tdv[i].getField("Name"), (i == 0));
+            if (i == 0) {
+              strLastYear = tdv[i].getField("id");
+            }
+          }
+          info.endSelect();
+        }
+
+        // Update the Periods
+        tdv = SEPeriodNoData.getPeriodNo(this, strLastYear);
+        if (tdv != null && tdv.length > 0) {
+          info.addSelect("inpperiodno");
+          for (int i = 0; i < tdv.length; i++) {
+            info.addSelectResult(tdv[i].getField("id"), tdv[i].getField("Name"));
+          }
+          info.endSelect();
+        }
+
       }
-      resultado.append("new Array(\"inpcCalendarId\", ");
-      if (tdv != null && tdv.length > 0) {
-        resultado.append("new Array(");
-        for (int i = 0; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + tdv[i].getField("Name") + "\")");
-          localStrCalendarId = tdv[i].getField("id");
-          if (i < tdv.length - 1)
-            resultado.append(",\n");
-        }
-        resultado.append("\n)");
-      } else
-        resultado.append("null");
-      resultado.append("\n),");
-
-      // Update the years
-      try {
-        tdv = SEPeriodNoData.getYears(this, localStrCalendarId);
-      } catch (Exception ex) {
-        throw new ServletException(ex);
-      }
-
-      String strLastYear = "";
-      resultado.append("new Array(\"inpcYearId\", ");
-      if (tdv != null && tdv.length > 0) {
-        resultado.append("new Array(");
-        for (int i = 0; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + tdv[i].getField("Name") + "\", \"" + (i == 0 ? "true" : "false") + "\")");
-          if (i == 0)
-            strLastYear = tdv[i].getField("id");
-          if (i < tdv.length - 1)
-            resultado.append(",\n");
-        }
-        resultado.append("\n)");
-      } else
-        resultado.append("null");
-      resultado.append("\n),");
-
-      // Update the Periods
-      try {
-        tdv = SEPeriodNoData.getPeriodNo(this, strLastYear);
-      } catch (Exception ex) {
-        throw new ServletException(ex);
-      }
-
-      resultado.append("new Array(\"inpperiodno\", ");
-      if (tdv != null && tdv.length > 0) {
-        resultado.append("new Array(");
-        for (int i = 0; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + tdv[i].getField("Name") + "\")");
-          if (i < tdv.length - 1)
-            resultado.append(",\n");
-        }
-        resultado.append("\n)");
-      } else
-        resultado.append("null");
-      resultado.append("\n)");
+    } catch (Exception ex) {
+      throw new ServletException(ex);
     }
-
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
 
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Period_Control.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Period_Control.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -19,73 +19,36 @@
 
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
+import org.openbravo.base.filter.ValueListFilter;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SE_Period_Control extends SimpleCallout {
 
-public class SE_Period_Control extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strAdOrgTypeID = vars.getStringParameter("inpadOrgtypeId");
-      String strIsReady = vars.getStringParameter("inpisready");
-      try {
-        printPage(response, vars, strAdOrgTypeID, strIsReady);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars,
-      String strAdOrgTypeID, String strIsReady) throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
+    // Parameters
+    String strAdOrgTypeID = info.getStringParameter("inpadOrgtypeId", IsIDFilter.instance);
+    String strIsReady = info.getStringParameter("inpisready", new ValueListFilter("Y", "N"));
 
     String strIsBULE = SEPeriodControlData.select(this, strAdOrgTypeID);
+    info.addResult("inpisperiodcontrolallowedAux", strIsBULE);
 
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SE_Period_Control';\n\n");
-    resultado.append("var respuesta = new Array(");
-    resultado.append("new Array(\"inpisperiodcontrolallowedAux\", \"" + strIsBULE + "\"),\n ");
+    if (StringUtils.isEmpty(strIsBULE) && StringUtils.equals(strIsReady, "N")) {
+      info.addResult("inpisperiodcontrolallowed", "N");
+    }
 
-    if (strIsBULE == null && strIsReady.equals("N")) {
-      resultado.append("new Array(\"inpisperiodcontrolallowed\", \"" + "N" + "\"),\n ");
-    }
     String strIsLegalEntity = SEPeriodControlData.selectIsLegalEntity(this, strAdOrgTypeID);
     String strIsBusinessUnit = SEPeriodControlData.selectIsBusinessUnit(this, strAdOrgTypeID);
-    resultado.append("new Array(\"inpisorglegalentiy\", \"" + strIsLegalEntity + "\"),\n ");
-    resultado.append("new Array(\"inpisorgbusinessunit\", \"" + strIsBusinessUnit + "\"),\n ");
-
-    resultado.append("new Array(\"EXECUTE\", \"displayLogic();\")\n");
-    resultado.append(");");
-
-    xmlDocument.setParameter("array", resultado.toString());
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    info.addResult("inpisorglegalentiy", strIsLegalEntity);
+    info.addResult("inpisorgbusinessunit", strIsBusinessUnit);
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Pricelist_Active.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Pricelist_Active.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,76 +11,43 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
+import org.openbravo.base.filter.ValueListFilter;
+import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.utils.FormatUtilities;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.erpCommon.utility.Utility;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SE_Pricelist_Active extends SimpleCallout {
 
-public class SE_Pricelist_Active extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    String strLastChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("Changed: " + strLastChanged);
+    }
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strIsActive = vars.getStringParameter("inpisactive");
-      String strPricelistId = vars.getStringParameter("inpmPricelistId");
-      try {
-        printPage(response, vars, strIsActive, strPricelistId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // Parameters
+    String strPricelistId = info.getStringParameter("inpmPricelistId", IsIDFilter.instance);
+    String strIsActive = info.getStringParameter("inpisactive", new ValueListFilter("Y", "N"));
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strIsActive,
-      String strPricelistId) throws IOException, ServletException {
-
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SE_Pricelist_Active';\n\n");
-    resultado.append("var respuesta = new Array(");
-
-    String msg = "";
-    if (strIsActive.equals("")) {
+    // Check whether there exists active versions for price list being set Active = No
+    if (StringUtils.equals(strIsActive, "N")) {
       SEPricelistActiveData[] pricelistVersion = SEPricelistActiveData.getActivePricelistVersion(
           this, strPricelistId);
-      if (pricelistVersion.length > 0) {
-        msg = Utility.messageBD(this, "PricelistVersionActive", vars.getLanguage());
+      if (pricelistVersion != null && pricelistVersion.length > 0) {
+        info.showMessage(FormatUtilities.replaceJS(Utility.messageBD(this,
+            "PricelistVersionActive", info.vars.getLanguage())));
       }
     }
-
-    resultado.append("new Array(\"MESSAGE\", \"" + msg + "\")");
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
-
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_ProjectLine_Value.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_ProjectLine_Value.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2013 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -19,136 +19,96 @@
 package org.openbravo.erpCommon.ad_callouts;
 
 import java.io.IOException;
-import java.io.PrintWriter;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.erpCommon.businessUtility.Tax;
 import org.openbravo.erpCommon.utility.DateTimeData;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SE_ProjectLine_Value extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SE_ProjectLine_Value extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strmProductId = vars.getStringParameter("inpmProductId");
-      String strTabId = vars.getStringParameter("inpTabId");
-      String strProjectId = vars.getStringParameter("inpcProjectId");
-      String strPhaseId = vars.getStringParameter("inpcProjectphaseId");
-      String strADOrgID = vars.getStringParameter("inpadOrgId");
-      String strPriceStd = vars.getNumericParameter("inpmProductId_PSTD");
-      String strCreatePL = vars.getStringParameter("inpcreatetemppricelist");
-      String strStatus = vars.getStringParameter("inpprojectstatus");
-      String strPriceListVersion = vars.getGlobalVariable("inpPriceListVersion",
-          "Product.priceListVersion", "");
-      try {
-        printPage(response, vars, strmProductId, strPriceListVersion, strTabId, strProjectId,
-            strPhaseId, strADOrgID, strPriceStd, strCreatePL, strStatus);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars,
-      String strmProductId, String strPriceListVersion, String strTabId, String strProjectId,
-      String strPhaseId, String strADOrgID, String strPriceStd, String strCreatePL, String strStatus)
-      throws IOException, ServletException {
-    String localStrProjectId = strProjectId;
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
+    // Parameters
+    String strmProductId = info.getStringParameter("inpmProductId", IsIDFilter.instance);
+    String strProjectId = info.getStringParameter("inpcProjectId", IsIDFilter.instance);
+    String strPhaseId = info.getStringParameter("inpcProjectphaseId", IsIDFilter.instance);
+    String strADOrgID = info.getStringParameter("inpadOrgId", IsIDFilter.instance);
+    String strPriceStd = info.vars.getNumericParameter("inpmProductId_PSTD");
+    String strCreatePL = info.getStringParameter("inpcreatetemppricelist");
+    String strStatus = info.getStringParameter("inpprojectstatus");
+    String strPriceListVersion = info.getStringParameter("inpmPricelistVersionId",
+        IsIDFilter.instance);
 
     String strMessage = "";
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SE_ProjectLine_Value';\n\n");
-    resultado.append("var respuesta = new Array(\n");
+    if (StringUtils.isNotEmpty(strmProductId)) {
+      // Project Data
+      if (StringUtils.isNotEmpty(strPhaseId) && StringUtils.isEmpty(strProjectId)) {
+        strProjectId = SEProjectLineValueData.selectPhaseProject(this, strPhaseId);
+      }
+      SEProjectLineValueData[] data1 = SEProjectLineValueData.selectProject(this, strProjectId);
+      String strProjCat = data1[0].projcat;
 
-    SEProjectLineValueData[] data = null;
-    SEProjectLineValueData[] data1 = null;
-
-    if (strmProductId != null && !strmProductId.equals("")) {
-      data = SEProjectLineValueData.select(this, strmProductId);
-      String strDate = DateTimeData.today(this);
-      if (strPhaseId != null && !strPhaseId.equals("")) {
-        if (localStrProjectId == null || localStrProjectId.equals("")) {
-          localStrProjectId = SEProjectLineValueData.selectPhaseProject(this, strPhaseId);
+      // Planned Price, Price Actual from Price List Version if any
+      if (StringUtils.isNotEmpty(strPriceListVersion)) {
+        String plannedprice = SEProjectLineValueData.selectPlannedPrice(this, strPriceListVersion,
+            strmProductId, strProjectId);
+        if (StringUtils.isNotEmpty(plannedprice)) {
+          if (!StringUtils.equals(strProjCat, "S")) {
+            info.addResult("inpplannedprice", plannedprice);
+          } else {
+            info.addResult("inppriceactual", plannedprice);
+          }
+        } else {
+          strMessage = "PriceNotFound";
         }
       }
-      data1 = SEProjectLineValueData.selectProject(this, localStrProjectId);
-      String strCBPartnerLocationID = data1[0].bplocation;
-      String strMWarehouseID = data1[0].warehouse;
-      String strProjCat = data1[0].projcat;
 
-      if (!strPriceListVersion.equals("")) {
-        String plannedprice = SEProjectLineValueData.selectPlannedPrice(this, strPriceListVersion,
-            strmProductId, localStrProjectId);
-        if (plannedprice != null && !plannedprice.equals("")) {
-          if (!strProjCat.equals("S")) {
-            resultado.append("new Array(\"inpplannedprice\", "
-                + (plannedprice.equals("") ? "\"\"" : plannedprice) + "),\n");
-          } else {
-            resultado.append("new Array(\"inppriceactual\", "
-                + (plannedprice.equals("") ? "\"\"" : plannedprice) + "),\n");
-          }
-        } else
-          strMessage = "PriceNotFound";
-      }
-      if ("OR".equalsIgnoreCase(strStatus) && "Y".equalsIgnoreCase(strCreatePL)) {
-        // Warning message: is not going to add in the pricelist.
+      // Price from Product Selector applies only in Service Project - Project Line
+      info.addResult("inpplannedprice", strPriceStd);
+
+      // Warning message: is not going to add in the pricelist.
+      if (StringUtils.equalsIgnoreCase(strStatus, "OR")
+          && StringUtils.equalsIgnoreCase(strCreatePL, "Y")) {
         strMessage = OBMessageUtils.messageBD("PriceListNotUpdated");
       }
-      resultado.append("new Array(\"inpplannedprice\", " + strPriceStd + " )\n");
-      if (!strProjCat.equals("S")) {
-        if (strCBPartnerLocationID != null && !strCBPartnerLocationID.equals("")
-            && strMWarehouseID != null && !strMWarehouseID.equals("")) {
-          String strIsSOTrx = "Y";
-          String strCTaxID = Tax.get(this, strmProductId, strDate, strADOrgID, strMWarehouseID,
-              strCBPartnerLocationID, strCBPartnerLocationID, localStrProjectId,
-              strIsSOTrx.equals("Y"));
-          if (strCTaxID != null && !strCTaxID.equals("")) {
-            resultado.append(", new Array(\"inpcTaxId\", \""
-                + (strCTaxID.equals("") ? "\"\"" : strCTaxID) + "\"),\n");
-          } else
+
+      // Tax: Service Project - Project Line
+      if (!StringUtils.equals(strProjCat, "S")) {
+        String strCBPartnerLocationID = data1[0].bplocation;
+        String strMWarehouseID = data1[0].warehouse;
+        if (StringUtils.isNotEmpty(strCBPartnerLocationID)
+            && StringUtils.isNotEmpty(strMWarehouseID)) {
+          try {
+            String strCTaxID = Tax
+                .get(this, strmProductId, DateTimeData.today(this), strADOrgID, strMWarehouseID,
+                    strCBPartnerLocationID, strCBPartnerLocationID, strProjectId, true);
+            if (StringUtils.isNotEmpty(strCTaxID)) {
+              info.addResult("inpcTaxId", strCTaxID);
+            } else {
+              strMessage = "TaxNotFound";
+            }
+          } catch (IOException e) {
             strMessage = "TaxNotFound";
+          }
         }
-        resultado.append("new Array(\"inpproductValue\", \"" + data[0].value + "\"),\n");
-        resultado.append("new Array(\"inpproductName\", \""
-            + FormatUtilities.replaceJS(data[0].name) + "\"),\n");
-        resultado.append("new Array(\"inpproductDescription\", \""
-            + FormatUtilities.replaceJS(data[0].description) + "\")\n");
+        SEProjectLineValueData[] data = SEProjectLineValueData.select(this, strmProductId);
+        info.addResult("inpproductValue", data[0].value);
+        info.addResult("inpproductName", FormatUtilities.replaceJS(data[0].name));
+        info.addResult("inpproductDescription", FormatUtilities.replaceJS(data[0].description));
       }
-    } else {
-      data = SEProjectLineValueData.set();
     }
-    if (!strMessage.equals(""))
-      resultado.append(", new Array('MESSAGE', \""
-          + FormatUtilities.replaceJS(Utility.messageBD(this, strMessage, vars.getLanguage()))
-          + "\")\n");
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+
+    // Show message if any
+    if (StringUtils.isNotEmpty(strMessage)) {
+      info.showMessage(FormatUtilities.replaceJS(Utility.messageBD(this, strMessage,
+          info.vars.getLanguage())));
+    }
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Project_BPartner.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Project_BPartner.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,270 +11,166 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2013 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.data.FieldProvider;
 import org.openbravo.erpCommon.businessUtility.BpartnerMiscData;
 import org.openbravo.erpCommon.utility.ComboTableData;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SE_Project_BPartner extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SE_Project_BPartner extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strBPartner = vars.getStringParameter("inpcBpartnerId");
-      String strLocation = vars.getStringParameter("inpcBpartnerId_LOC");
-      String strContact = vars.getStringParameter("inpcBpartnerId_CON");
-      String strWindowId = vars.getStringParameter("inpwindowId");
-      String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
-
-      try {
-        printPage(response, vars, strBPartner, strIsSOTrx, strWindowId, strLocation, strContact);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strBPartner,
-      String strIsSOTrx, String strWindowId, String strLocation, String strContact)
-      throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    String strPaymentrule, strPaymentterm, strPricelist, strPaymentMethod, strUserRep;
-    strPaymentrule = strPaymentterm = strPricelist = strPaymentMethod = strUserRep = "";
-    BpartnerMiscData[] data = BpartnerMiscData.select(this, strBPartner);
-    if (data != null && data.length > 0) {
-      strPaymentrule = (strIsSOTrx.equals("Y") ? data[0].paymentrule : data[0].paymentrulepo);
-      strPaymentterm = (strIsSOTrx.equals("Y") ? data[0].cPaymenttermId : data[0].poPaymenttermId);
-      strPricelist = (strIsSOTrx.equals("Y") ? data[0].mPricelistId : data[0].poPricelistId);
-      strPaymentMethod = (strIsSOTrx.equals("Y") ? data[0].finPaymentmethodId
-          : data[0].poPaymentmethodId);
-      strUserRep = SEOrderBPartnerData.userIdSalesRep(this, data[0].salesrepId);
-      strUserRep = strUserRep.equals("") ? vars.getStringParameter("inpsalesrepId") : strUserRep;
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
     }
 
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SE_Project_BPartner';\n\n");
-    resultado.append("var respuesta = new Array(");
+    // Parameters
+    String strBPartner = info.getStringParameter("inpcBpartnerId", IsIDFilter.instance);
+    String strLocation = info.getStringParameter("inpcBpartnerId_LOC", IsIDFilter.instance);
+    String strContact = info.getStringParameter("inpcBpartnerId_CON", IsIDFilter.instance);
+    String strSalesRep = info.getStringParameter("inpsalesrepId", IsIDFilter.instance);
+    String strOrgId = info.getStringParameter("inpadOrgId", IsIDFilter.instance);
+    String strIsSOTrx = Utility.getContext(this, info.vars, "isSOTrx", info.getWindowId());
+    boolean isSales = StringUtils.equals(strIsSOTrx, "Y");
+
+    // Business Partner Data
+    BpartnerMiscData[] data = BpartnerMiscData.select(this, strBPartner);
+    String strPaymentrule = "", strPaymentterm = "", strPricelist = "", strPaymentMethod = "", strUserRep = "";
+    if (data != null && data.length > 0) {
+      strPaymentrule = isSales ? data[0].paymentrule : data[0].paymentrulepo;
+      strPaymentterm = isSales ? data[0].cPaymenttermId : data[0].poPaymenttermId;
+      strPricelist = isSales ? data[0].mPricelistId : data[0].poPricelistId;
+      strPaymentMethod = isSales ? data[0].finPaymentmethodId : data[0].poPaymentmethodId;
+      strUserRep = SEOrderBPartnerData.userIdSalesRep(this, data[0].salesrepId);
+      strUserRep = StringUtils.isEmpty(strUserRep) ? strSalesRep : strUserRep;
+    }
+
+    // Business Partner - Ship To Address
     FieldProvider[] tdv = null;
     try {
-      ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "M_PriceList_ID",
-          "", "", Utility.getContext(this, vars, "#AccessibleOrgTree", strWindowId),
-          Utility.getContext(this, vars, "#User_Client", strWindowId), 0);
-      Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
+      ComboTableData comboTableData = new ComboTableData(info.vars, this, "TABLEDIR",
+          "C_BPartner_Location_ID", "", "C_BPartner Location - Ship To", Utility.getContext(this,
+              info.vars, "#AccessibleOrgTree", info.getWindowId()), Utility.getContext(this,
+              info.vars, "#User_Client", info.getWindowId()), 0);
+      Utility.fillSQLParameters(this, info.vars, null, comboTableData, info.getWindowId(), "");
       tdv = comboTableData.select(false);
       comboTableData = null;
     } catch (Exception ex) {
       throw new ServletException(ex);
     }
+    if (tdv != null && tdv.length > 0) {
+      info.addSelect("inpcBpartnerLocationId");
+      // If location is provided it is selected, else the first one is selected
+      for (int i = 0; i < tdv.length; i++) {
+        info.addSelectResult(
+            tdv[i].getField("id"),
+            FormatUtilities.replaceJS(tdv[i].getField("name")),
+            (StringUtils.isEmpty(strLocation) && i == 0)
+                || (StringUtils.isNotEmpty(strLocation) && StringUtils.equalsIgnoreCase(
+                    tdv[i].getField("id"), strLocation)));
+      }
+      info.endSelect();
+    } else {
+      info.addResult("inpcBpartnerLocationId", null);
+    }
 
+    // Sales Representative
     try {
-      ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR",
-          "C_BPartner_Location_ID", "", "C_BPartner Location - Ship To", Utility.getContext(this,
-              vars, "#AccessibleOrgTree", strWindowId), Utility.getContext(this, vars,
-              "#User_Client", strWindowId), 0);
-      Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
+      ComboTableData comboTableData = new ComboTableData(info.vars, this, "TABLE", "",
+          "AD_User SalesRep", "", Utility.getReferenceableOrg(info.vars, strOrgId),
+          Utility.getContext(this, info.vars, "#User_Client", info.getWindowId()), 0);
+      Utility.fillSQLParameters(this, info.vars, null, comboTableData, info.getWindowId(), "");
       tdv = comboTableData.select(false);
       comboTableData = null;
     } catch (Exception ex) {
       throw new ServletException(ex);
     }
+    if (tdv != null && tdv.length > 0) {
+      info.addSelect("inpsalesrepId");
+      for (int i = 0; i < tdv.length; i++) {
+        info.addSelectResult(tdv[i].getField("id"),
+            FormatUtilities.replaceJS(tdv[i].getField("name")),
+            StringUtils.equalsIgnoreCase(tdv[i].getField("id"), strUserRep));
+      }
+      info.endSelect();
+    } else {
+      info.addResult("inpsalesrepId", null);
+    }
 
-    resultado.append("new Array(\"inpcBpartnerLocationId\", ");
-    if (tdv != null && tdv.length > 0) {
-      resultado.append("new Array(");
-      if (strLocation.isEmpty()) {
-        // If no location is provided, the first one is selected
-        if (tdv.length > 0) {
-          resultado.append("new Array(\"" + tdv[0].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tdv[0].getField("name")) + "\", \"" + "true" + "\")");
-          if (tdv.length > 1) {
-            resultado.append(",\n");
-          }
-        }
-        for (int i = 1; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \"" + "false" + "\")");
-          if (i < tdv.length - 1) {
-            resultado.append(",\n");
-          }
-        }
-      } else {
-        // If a location is provided, it is selected
-        for (int i = 0; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \""
-              + (tdv[i].getField("id").equalsIgnoreCase(strLocation) ? "true" : "false") + "\")");
-          if (i < tdv.length - 1) {
-            resultado.append(",\n");
-          }
-        }
-      }
-      resultado.append("\n)");
-
-    } else {
-      resultado.append("null");
-    }
-    resultado.append("\n),");
-
-    // Sales Representative
+    // Business Partner - User/Contacts
     try {
-      ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "",
-          "AD_User SalesRep", "",
-          Utility.getContext(this, vars, "#AccessibleOrgTree", strWindowId), Utility.getContext(
-              this, vars, "#User_Client", strWindowId), 0);
-      Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
+      ComboTableData comboTableData = new ComboTableData(info.vars, this, "TABLEDIR", "AD_User_ID",
+          "", "AD_User C_BPartner User/Contacts", Utility.getReferenceableOrg(info.vars, strOrgId),
+          Utility.getContext(this, info.vars, "#User_Client", info.getWindowId()), 0);
+      Utility.fillSQLParameters(this, info.vars, null, comboTableData, info.getWindowId(), "");
       tdv = comboTableData.select(false);
       comboTableData = null;
     } catch (Exception ex) {
       throw new ServletException(ex);
     }
-
-    resultado.append("new Array(\"inpsalesrepId\", ");
     if (tdv != null && tdv.length > 0) {
-      resultado.append("new Array(");
+      info.addSelect("inpadUserId");
+      // If contact is provided it is selected, else the first one is selected
       for (int i = 0; i < tdv.length; i++) {
-        resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-            + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \""
-            + (tdv[i].getField("id").equalsIgnoreCase(strUserRep) ? "true" : "false") + "\")");
-        if (i < tdv.length - 1) {
-          resultado.append(",\n");
-        }
+        info.addSelectResult(
+            tdv[i].getField("id"),
+            FormatUtilities.replaceJS(tdv[i].getField("name")),
+            (StringUtils.isEmpty(strContact) && i == 0)
+                || (StringUtils.isNotEmpty(strContact) && StringUtils.equalsIgnoreCase(
+                    tdv[i].getField("id"), strContact)));
       }
-      resultado.append("\n)");
+      info.endSelect();
     } else {
-      resultado.append("null");
-    }
-    resultado.append("\n),");
-
-    try {
-      ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "AD_User_ID", "",
-          "AD_User C_BPartner User/Contacts", Utility.getContext(this, vars, "#AccessibleOrgTree",
-              strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0);
-      Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
-      tdv = comboTableData.select(false);
-      comboTableData = null;
-    } catch (Exception ex) {
-      throw new ServletException(ex);
+      info.addResult("inpadUserId", null);
     }
 
-    resultado.append("new Array(\"inpadUserId\", ");
-    if (tdv != null && tdv.length > 0) {
-      resultado.append("new Array(");
-
-      if (strContact.isEmpty()) {
-        resultado.append("new Array(\"" + tdv[0].getField("id") + "\", \""
-            + FormatUtilities.replaceJS(tdv[0].getField("name")) + "\", \"" + "true" + "\")");
-        if (tdv.length > 1) {
-          resultado.append(",\n");
-        }
-        for (int i = 1; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \"" + "false" + "\")");
-          if (i < tdv.length - 1) {
-            resultado.append(",\n");
-          }
-        }
-      } else {
-        for (int i = 0; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \""
-              + (tdv[i].getField("id").equalsIgnoreCase(strContact) ? "true" : "false") + "\")");
-          if (i < tdv.length - 1) {
-            resultado.append(",\n");
-          }
-        }
-      }
-
-      resultado.append("\n)");
-    } else
-      resultado.append("null");
-    resultado.append("\n),");
+    // Business Partner - Bill To Address
     FieldProvider[] tlv = null;
     try {
-      ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "",
-          "C_BPartner Location", "C_BPartner Location - Bill To", Utility.getContext(this, vars,
-              "#AccessibleOrgTree", strWindowId), Utility.getContext(this, vars, "#User_Client",
-              strWindowId), 0);
-      Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
+      ComboTableData comboTableData = new ComboTableData(info.vars, this, "TABLE", "",
+          "C_BPartner Location", "C_BPartner Location - Bill To", Utility.getContext(this,
+              info.vars, "#AccessibleOrgTree", info.getWindowId()), Utility.getContext(this,
+              info.vars, "#User_Client", info.getWindowId()), 0);
+      Utility.fillSQLParameters(this, info.vars, null, comboTableData, info.getWindowId(), "");
       tlv = comboTableData.select(false);
       comboTableData = null;
     } catch (Exception ex) {
       throw new ServletException(ex);
     }
+    if (tlv != null && tlv.length > 0) {
+      info.addSelect("inpbilltoId");
+      // If location is provided it is selected, else the first one is selected
+      for (int i = 0; i < tlv.length; i++) {
+        info.addSelectResult(
+            tlv[i].getField("id"),
+            FormatUtilities.replaceJS(tlv[i].getField("name")),
+            (StringUtils.isEmpty(strLocation) && i == 0)
+                || (StringUtils.isNotEmpty(strLocation) && StringUtils.equalsIgnoreCase(
+                    tdv[i].getField("id"), strLocation)));
+      }
+      info.endSelect();
+    } else {
+      info.addResult("inpbilltoId", null);
+    }
 
-    resultado.append("new Array(\"inpbilltoId\", ");
-    if (tlv != null && tlv.length > 0) {
-      resultado.append("new Array(");
-
-      if (strLocation.isEmpty()) {
-        if (tlv.length > 0) {
-          resultado.append("new Array(\"" + tlv[0].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tlv[0].getField("name")) + "\", \"" + "true" + "\")");
-          if (tlv.length > 1) {
-            resultado.append(",\n");
-          }
-        }
-        for (int i = 1; i < tlv.length; i++) {
-          resultado.append("new Array(\"" + tlv[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tlv[i].getField("name")) + "\", \"" + "false" + "\")");
-          if (i < tlv.length - 1)
-            resultado.append(",\n");
-        }
-      } else {
-        for (int i = 0; i < tlv.length; i++) {
-          resultado.append("new Array(\"" + tlv[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tlv[i].getField("name")) + "\", \""
-              + (tlv[i].getField("id").equalsIgnoreCase(strLocation) ? "true" : "false") + "\")");
-          if (i < tlv.length - 1)
-            resultado.append(",\n");
-        }
-      }
-      resultado.append("\n)");
-    } else
-      resultado.append("null");
-    resultado.append("\n),");
-    resultado.append("new Array(\"inppaymentrule\", \"" + strPaymentrule + "\"),");
-    resultado.append("new Array(\"inpcPaymenttermId\", \"" + strPaymentterm + "\"),");
-    resultado.append("new Array(\"inpmPricelistId\", \"" + strPricelist + "\"),");
-    resultado.append("new Array(\"inpfinPaymentmethodId\", \"" + strPaymentMethod + "\")");
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    // Payment Rule, Payment Term, Price List, Payment Method
+    info.addResult("inppaymentrule", strPaymentrule);
+    info.addResult("inpcPaymenttermId", strPaymentterm);
+    info.addResult("inpmPricelistId", strPricelist);
+    info.addResult("inpfinPaymentmethodId", strPaymentMethod);
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Proposal_BPartner.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Proposal_BPartner.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,172 +11,93 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.data.FieldProvider;
 import org.openbravo.erpCommon.utility.ComboTableData;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SE_Proposal_BPartner extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SE_Proposal_BPartner extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strBPartner = vars.getStringParameter("inpcBpartnerId");
-      String strLocation = vars.getStringParameter("inpcBpartnerId_LOC");
-      String strContact = vars.getStringParameter("inpcBpartnerId_CON");
-      String strWindowId = vars.getStringParameter("inpwindowId");
-      String strTabId = vars.getStringParameter("inpTabId");
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-      try {
-        printPage(response, vars, strBPartner, strWindowId, strLocation, strContact, strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // Parameters
+    String strBPartner = info.getStringParameter("inpcBpartnerId", IsIDFilter.instance);
+    String strLocation = info.getStringParameter("inpcBpartnerLocationId", IsIDFilter.instance);
+    String strContact = info.getStringParameter("inpadUserId", IsIDFilter.instance);
+    String strWindowId = info.getWindowId();
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strBPartner,
-      String strWindowId, String strLocation, String strContact, String strTabId)
-      throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
+    // Update payment rule
+    String strPaymentRule = SEProposalBPartnerData.selectPaymentRule(this, strBPartner);
+    info.addResult("inppaymentrule", strPaymentRule);
 
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SE_Order_BPartner';\n\n");
-    resultado.append("var respuesta = new Array(");
-    String strPaymentRule = SEProposalBPartnerData.selectPaymentRule(this, strBPartner);
-    resultado.append("new Array(\"inppaymentrule\", \"" + strPaymentRule + "\"),");
+    // Update payment term
     String strPaymentTerm = SEProposalBPartnerData.selectPaymentTerm(this, strBPartner);
-    resultado.append("new Array(\"inpcPaymenttermId\", \"" + strPaymentTerm + "\"),");
+    info.addResult("inpcPaymenttermId", strPaymentTerm);
+
+    // If a Location ID has not been specified, the first one is selected. Else if Location ID is
+    // provided, it is selected.
     FieldProvider[] tdv = null;
     try {
-      ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR",
+      ComboTableData comboTableData = new ComboTableData(info.vars, this, "TABLEDIR",
           "C_BPartner_Location_ID", "", "C_BPartner Location - Ship To", Utility.getContext(this,
-              vars, "#AccessibleOrgTree", strWindowId), Utility.getContext(this, vars,
+              info.vars, "#AccessibleOrgTree", strWindowId), Utility.getContext(this, info.vars,
               "#User_Client", strWindowId), 0);
-      Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
+      Utility.fillSQLParameters(this, info.vars, null, comboTableData, strWindowId, "");
       tdv = comboTableData.select(false);
       comboTableData = null;
     } catch (Exception ex) {
       throw new ServletException(ex);
     }
+    if (tdv != null && tdv.length > 0) {
+      info.addSelect("inpcBpartnerLocationId");
+      for (int i = 0; i < tdv.length; i++) {
+        boolean selected = (StringUtils.isEmpty(strLocation) && i == 0)
+            || StringUtils.equalsIgnoreCase(tdv[i].getField("id"), strLocation);
+        info.addSelectResult(tdv[i].getField("id"),
+            FormatUtilities.replaceJS(tdv[i].getField("name")), selected);
+      }
+      info.endSelect();
+    }
 
-    resultado.append("new Array(\"inpcBpartnerLocationId\", ");
-    if (tdv != null && tdv.length > 0) {
-      resultado.append("new Array(");
-
-      if (strLocation.isEmpty()) {
-        // If no location is provided, the first one is selected
-        resultado.append("new Array(\"" + tdv[0].getField("id") + "\", \""
-            + FormatUtilities.replaceJS(tdv[0].getField("name")) + "\", \"" + "true" + "\")");
-        if (tdv.length > 1) {
-          resultado.append(",\n");
-        }
-        for (int i = 1; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \"" + "false" + "\")");
-          if (i < tdv.length - 1) {
-            resultado.append(",\n");
-          }
-        }
-      } else {
-        // If a location is provided, it is selected
-        for (int i = 0; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \""
-              + (tdv[i].getField("id").equalsIgnoreCase(strLocation) ? "true" : "false") + "\")");
-          if (i < tdv.length - 1) {
-            resultado.append(",\n");
-          }
-        }
-      }
-      resultado.append("\n)");
-    } else {
-      resultado.append("null");
-    }
-    resultado.append("\n),");
+    // If a contactID has not been specified, the first one is selected. Else if contact ID is
+    // provided, it is selected.
     try {
-      ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "AD_User_ID", "",
-          "AD_User C_BPartner User/Contacts", Utility.getContext(this, vars, "#AccessibleOrgTree",
-              strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0);
-      Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
+      ComboTableData comboTableData = new ComboTableData(info.vars, this, "TABLEDIR", "AD_User_ID",
+          "", "AD_User C_BPartner User/Contacts", Utility.getContext(this, info.vars,
+              "#AccessibleOrgTree", strWindowId), Utility.getContext(this, info.vars,
+              "#User_Client", strWindowId), 0);
+      Utility.fillSQLParameters(this, info.vars, null, comboTableData, strWindowId, "");
       tdv = comboTableData.select(false);
       comboTableData = null;
     } catch (Exception ex) {
       throw new ServletException(ex);
     }
-
-    resultado.append("new Array(\"inpadUserId\", ");
     if (tdv != null && tdv.length > 0) {
-      resultado.append("new Array(");
-
-      if (strContact.isEmpty()) {
-        // If a contactID has not been specified, the first one is selected
-        resultado.append("new Array(\"" + tdv[0].getField("id") + "\", \""
-            + FormatUtilities.replaceJS(tdv[0].getField("name")) + "\", \"" + "true" + "\")");
-        if (tdv.length > 1) {
-          resultado.append(",\n");
-        }
-        for (int i = 1; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \"" + "false" + "\")");
-          if (i < tdv.length - 1) {
-            resultado.append(",\n");
-          }
-        }
-      } else {
-        for (int i = 0; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \""
-              + (tdv[i].getField("id").equalsIgnoreCase(strContact) ? "true" : "false") + "\")");
-          if (i < tdv.length - 1) {
-            resultado.append(",\n");
-          }
-        }
+      info.addSelect("inpadUserId");
+      for (int i = 0; i < tdv.length; i++) {
+        boolean selected = (StringUtils.isEmpty(strContact) && i == 0)
+            || StringUtils.equalsIgnoreCase(tdv[i].getField("id"), strContact);
+        info.addSelectResult(tdv[i].getField("id"),
+            FormatUtilities.replaceJS(tdv[i].getField("name")), selected);
       }
-
-      resultado.append("\n)");
-    } else
-      resultado.append("null");
-    resultado.append("\n)");
-
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+      info.endSelect();
+    }
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Supplier_BPartner.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Supplier_BPartner.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,73 +11,39 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SE_Supplier_BPartner extends SimpleCallout {
 
-public class SE_Supplier_BPartner extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strBPartner = vars.getStringParameter("inpcBpartnerId");
-      String strWindowId = vars.getStringParameter("inpwindowId");
-      try {
-        printPage(response, vars, strBPartner, strWindowId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // Parameter
+    String strBPartner = info.getStringParameter("inpcBpartnerId", IsIDFilter.instance);
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strBPartner,
-      String strWindowId) throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
+    // Remove C_BPartner_ID from session when input parameter strBPartner is empty
+    if (StringUtils.isEmpty(strBPartner)) {
+      info.vars.removeSessionValue(info.getWindowId() + "|C_BPartner_ID");
+    } else {
+      // Price List
+      String strPriceList = SLRequisitionBPartnerData.select(this, strBPartner)[0].poPricelistId;
+      info.addResult("inpmPricelistId", strPriceList);
+    }
 
-    if (strBPartner.equals(""))
-      vars.removeSessionValue(strWindowId + "|C_BPartner_ID");
-
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    String strPriceList = SLRequisitionBPartnerData.select(this, strBPartner)[0].poPricelistId;
-
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_Supplier_BPartner';\n\n");
-    resultado.append("var respuesta = new Array(");
-    resultado.append("new Array(\"inpmPricelistId\", \"" + strPriceList + "\")");
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Taxes_Active.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Taxes_Active.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,74 +11,40 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
+import org.openbravo.base.filter.ValueListFilter;
+import org.openbravo.erpCommon.utility.Utility;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.erpCommon.utility.Utility;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SE_Taxes_Active extends SimpleCallout {
 
-public class SE_Taxes_Active extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    String strLastChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("Last Field Changed: " + strLastChanged);
+    }
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strIsActive = vars.getStringParameter("inpisactive");
-      String strParentTaxId = vars.getStringParameter("inpcTaxId");
-      try {
-        printPage(response, vars, strIsActive, strParentTaxId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // Parameter
+    String strIsActive = info.getStringParameter("inpisactive", new ValueListFilter("Y", "N"));
+    String strParentTaxId = info.getStringParameter("inpcTaxId", IsIDFilter.instance);
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strIsActive,
-      String strParentTaxId) throws IOException, ServletException {
-
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SE_Taxes_Active';\n\n");
-    resultado.append("var respuesta = new Array(");
-
-    String msg = "";
-    if (strIsActive.equals("")) {
+    // Check whether Active child taxes exists for the Tax Rate being set as Active = No.
+    if (StringUtils.equals(strIsActive, "N")) {
       SETaxesActiveData[] children = SETaxesActiveData.getActiveChildrenTaxes(this, strParentTaxId);
-      if (children.length > 0) {
-        msg = Utility.messageBD(this, "ChildrenTaxRateActive", vars.getLanguage());
+      if (children != null && children.length > 0) {
+        info.showMessage(Utility.messageBD(this, "ChildrenTaxRateActive", info.vars.getLanguage()));
       }
     }
-
-    resultado.append("new Array(\"MESSAGE\", \"" + msg + "\")");
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Asset_Product.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Asset_Product.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,90 +11,59 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2010 Openbravo SLU 
+ * All portions are Copyright (C) 2010-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.erpCommon.businessUtility.PAttributeSet;
 import org.openbravo.erpCommon.businessUtility.PAttributeSetData;
 import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_Asset_Product extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_Asset_Product extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strTabId = vars.getStringParameter("inpTabId");
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-      String strMProductID = vars.getStringParameter("inpmProductId");
-      String strPAttr = vars.getStringParameter("inpmProductId_ATR");
+    // Parameters
+    String strMProductID = info.getStringParameter("inpmProductId", IsIDFilter.instance);
 
-      try {
-        printPage(response, vars, strTabId, strMProductID, strPAttr);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // Get the product attribute data
+    PAttributeSetData[] dataPAttr = PAttributeSetData.selectProductAttr(this, strMProductID);
+    if (dataPAttr != null && dataPAttr.length > 0
+        && StringUtils.equals(dataPAttr[0].attrsetvaluetype, "D")) {
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strTabId,
-      String strMProductID, String strPAttr) throws IOException, ServletException {
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
+      // If the attribute value type is "D"
+      PAttributeSetData[] data2 = PAttributeSetData.select(this, dataPAttr[0].mAttributesetId);
 
-    StringBuffer result = new StringBuffer();
-    result.append("var calloutName='SL_Asset_Product';\n\n");
-    result.append("var respuesta = new Array(");
-    PAttributeSetData[] dataPAttr = PAttributeSetData.selectProductAttr(this, strMProductID);
-    if (dataPAttr != null && dataPAttr.length > 0 && dataPAttr[0].attrsetvaluetype.equals("D")) {
-      PAttributeSetData[] data2 = PAttributeSetData.select(this, dataPAttr[0].mAttributesetId);
+      // If it is an Instance Attribute, clean value of Attribute set instance, else fill it with
+      // the attribute set instance
       if (PAttributeSet.isInstanceAttributeSet(data2)) {
-        result.append("new Array(\"inpmAttributesetinstanceId\", \"\"),");
-        result.append("new Array(\"inpmAttributesetinstanceId_R\", \"\"),");
+        info.addResult("inpmAttributesetinstanceId", "");
+        info.addResult("inpmAttributesetinstanceId_R", "");
       } else {
-        result.append("new Array(\"inpmAttributesetinstanceId\", \""
-            + dataPAttr[0].mAttributesetinstanceId + "\"),");
-        result.append("new Array(\"inpmAttributesetinstanceId_R\", \""
-            + FormatUtilities.replaceJS(dataPAttr[0].description) + "\"),");
+        info.addResult("inpmAttributesetinstanceId", dataPAttr[0].mAttributesetinstanceId);
+        info.addResult("inpmAttributesetinstanceId_R",
+            FormatUtilities.replaceJS(dataPAttr[0].description));
       }
     } else {
-      result.append("new Array(\"inpmAttributesetinstanceId\", \"\"),");
-      result.append("new Array(\"inpmAttributesetinstanceId_R\", \"\"),");
+      info.addResult("inpmAttributesetinstanceId", "");
+      info.addResult("inpmAttributesetinstanceId_R", "");
     }
-    result.append("new Array(\"inpattributeset\", \""
-        + FormatUtilities.replaceJS(dataPAttr[0].mAttributesetId) + "\"),\n");
-    result.append("new Array(\"inpattrsetvaluetype\", \""
-        + FormatUtilities.replaceJS(dataPAttr[0].attrsetvaluetype) + "\"),\n");
-    result.append("new Array(\"EXECUTE\", \"displayLogic();\")\n");
-    result.append(");\n");
 
-    xmlDocument.setParameter("array", result.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    // Update the attribute set and attribute set value type according the product attribute.
+    info.addResult("inpattributeset", FormatUtilities.replaceJS(dataPAttr[0].mAttributesetId));
+    info.addResult("inpattrsetvaluetype", FormatUtilities.replaceJS(dataPAttr[0].attrsetvaluetype));
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Assets.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Assets.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,115 +11,55 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.xmlEngine.XmlDocument;
+import org.apache.commons.lang.StringUtils;
 
-public class SL_Assets extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_Assets extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
+    String strLastChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strLastChanged);
+    }
 
-      String strAssetvalue = vars.getNumericParameter("inpassetvalueamt");
-      String strResidualvalue = vars.getNumericParameter("inpresidualassetvalueamt");
-      String strAmortizationvalue = vars.getNumericParameter("inpamortizationvalueamt");
-      String strLastChanged = vars.getStringParameter("inpLastFieldChanged");
-      String strTabId = vars.getStringParameter("inpTabId");
+    // Parameters
+    BigDecimal fAssetvalue = info.getBigDecimalParameter("inpassetvalueamt");
+    BigDecimal fResidualvalue = info.getBigDecimalParameter("inpresidualassetvalueamt");
+    BigDecimal fAmortizationvalue = info.getBigDecimalParameter("inpamortizationvalueamt");
 
-      try {
-        printPage(response, vars, strTabId, strAssetvalue, strResidualvalue, strAmortizationvalue,
-            strLastChanged);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
+    // If Asset Value changes recalculate Residual Asset Value using current Depreciation amount
+    if (StringUtils.equals(strLastChanged, "inpassetvalueamt")) {
+      if (fAmortizationvalue.compareTo(BigDecimal.ZERO) != 0) {
+        fResidualvalue = fAssetvalue.subtract(fAmortizationvalue);
       }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strTabId,
-      String strAssetvalue, String strResidualvalue, String strAmortizationvalue,
-      String strLastChanged) throws IOException, ServletException {
-    String localStrResidualvalue = strResidualvalue;
-    String localStrAssetvalue = strAssetvalue;
-    String localStrAmortizationvalue = strAmortizationvalue;
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
-    if (localStrAssetvalue.equals(""))
-      localStrAssetvalue = "0";
-    if (localStrResidualvalue.equals(""))
-      localStrResidualvalue = "0";
-    if (localStrAmortizationvalue.equals(""))
-      localStrAmortizationvalue = "0";
-
-    BigDecimal fAssetvalue = new BigDecimal(localStrAssetvalue);
-    BigDecimal fResidualvalue = new BigDecimal(localStrResidualvalue);
-    BigDecimal fAmortizationvalue = new BigDecimal(localStrAmortizationvalue);
-    // Float fAssetvalue = Float.valueOf(strAssetvalue);
-    // Float fResidualvalue = Float.valueOf(strResidualvalue);
-    // Float fAmortizationvalue = Float.valueOf(strAmortizationvalue);
-
-    if (strLastChanged.equals("inpassetvalueamt")) {
-      if (!fAmortizationvalue.equals(BigDecimal.ZERO))
-        fResidualvalue = fAssetvalue.subtract(fAmortizationvalue);
       fAmortizationvalue = fAssetvalue.subtract(fResidualvalue);
     }
 
-    if (strLastChanged.equals("inpresidualassetvalueamt")) {
-      // if (fAmortizationvalue != 0) fAssetvalue = fResidualvalue +
-      // fAmortizationvalue;
+    // If Residual Asset Value changes recalculate Asset Value using new residual value
+    if (StringUtils.equals(strLastChanged, "inpresidualassetvalueamt")) {
       fAmortizationvalue = fAssetvalue.subtract(fResidualvalue);
     }
 
-    if (strLastChanged.equals("inpamortizationvalueamt")) {
-      // if (fResidualvalue != 0 ) fAssetvalue = fResidualvalue +
-      // fAmortizationvalue;
+    // If Depreciation amount changes recalculate Residual Asset Value using current Asset and
+    // Depreciation values
+    if (StringUtils.equals(strLastChanged, "inpamortizationvalueamt")) {
       fResidualvalue = fAssetvalue.subtract(fAmortizationvalue);
     }
 
-    localStrAssetvalue = fAssetvalue.toString();
-    localStrResidualvalue = fResidualvalue.toString();
-    localStrAmortizationvalue = fAmortizationvalue.toString();
-
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_Assets';\n\n");
-    resultado.append("var respuesta = new Array(new Array(\"inpassetvalueamt\","
-        + fAssetvalue.toString() + "), new Array(\"inpresidualassetvalueamt\","
-        + fResidualvalue.toString() + "), new Array(\"inpamortizationvalueamt\","
-        + fAmortizationvalue.toString() + "));");
-    resultado.append("\n\n//" + strLastChanged);
-
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    info.addResult("inpassetvalueamt", fAssetvalue);
+    info.addResult("inpresidualassetvalueamt", fResidualvalue);
+    info.addResult("inpamortizationvalueamt", fAmortizationvalue);
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_BankDebt_Amount.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_BankDebt_Amount.java	Fri Aug 04 19:25:27 2017 -0400
@@ -1,4 +1,4 @@
-/*ALO
+/*
  *************************************************************************
  * The contents of this file are subject to the Openbravo  Public  License
  * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
@@ -11,100 +11,55 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_BankDebt_Amount extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_BankDebt_Amount extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strDebtPayment = vars.getStringParameter("inpcDebtPaymentId");
-      String strBankStatement = vars.getStringParameter("inpcBankstatementId");
-      String strTabId = vars.getStringParameter("inpTabId");
-      String strCurrency = vars.getStringParameter("inpcCurrencyId");
-      String strDescription = vars.getStringParameter("inpdescription");
-
-      try {
-        printPage(response, vars, strChanged, strDebtPayment, strTabId, strBankStatement,
-            strCurrency, strDescription);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strChanged,
-      String strDebtPayment, String strTabId, String strBankStatement, String strCurrency,
-      String strDescription) throws IOException, ServletException {
-    String localStrDescription = strDescription;
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    String Amount = null;
-    String ConvChargeAmt = "0";
-    String conv = null;
-
-    if (!strDebtPayment.equals("")) {
-      Amount = SLCashJournalAmountsData.amountDebtPaymentBank(this, strBankStatement,
-          strDebtPayment);
-      if (!localStrDescription.equals("")) {
-        localStrDescription = localStrDescription + " - ";
-      }
-      localStrDescription = localStrDescription
-          + SLCashJournalAmountsData.debtPaymentDescription(this, strDebtPayment);
-      conv = SLBankStmtAmountData.isConversion(this, strCurrency, strDebtPayment);
-    } else {
-      Amount = "0";
-      // strDescription="";
-      conv = "N";
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
     }
 
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_BankDebt_Amount';\n\n");
-    resultado.append("var respuesta = new Array(");
-    resultado.append("new Array(\"inpdescription\", \""
-        + FormatUtilities.replaceJS(localStrDescription) + "\"),");
-    resultado.append("new Array(\"inptrxamt\", " + Amount + "),");
-    resultado.append("new Array(\"inpcurrconv\", \"" + conv + "\"),");
-    resultado.append("new Array(\"inpconvertchargeamt\", " + ConvChargeAmt + "),");
-    resultado.append("new Array(\"inpstmtamt\", " + Amount + ")");
+    // Parameters
+    String strDebtPayment = info.getStringParameter("inpcDebtPaymentId", IsIDFilter.instance);
+    String strBankStatement = info.getStringParameter("inpcBankstatementId", IsIDFilter.instance);
+    String strCurrency = info.getStringParameter("inpcCurrencyId", IsIDFilter.instance);
+    String strDesc = info.getStringParameter("inpdescription");
 
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    String conv = "N";
+    BigDecimal amount = BigDecimal.ZERO;
+    if (StringUtils.isNotEmpty(strDebtPayment)) {
+      String strAmt = SLCashJournalAmountsData.amountDebtPaymentBank(this, strBankStatement,
+          strDebtPayment);
+      amount = StringUtils.isEmpty(strAmt) ? BigDecimal.ZERO : new BigDecimal(strAmt);
+
+      if (StringUtils.isNotEmpty(strDesc)) {
+        strDesc = strDesc + " - ";
+      }
+      strDesc = strDesc + SLCashJournalAmountsData.debtPaymentDescription(this, strDebtPayment);
+      conv = SLBankStmtAmountData.isConversion(this, strCurrency, strDebtPayment);
+    }
+
+    info.addResult("inpdescription", FormatUtilities.replaceJS(strDesc));
+    info.addResult("inptrxamt", amount);
+    info.addResult("inpcurrconv", conv);
+    info.addResult("inpconvertchargeamt", BigDecimal.ZERO);
+    info.addResult("inpstmtamt", amount);
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_BankStmt_Amount.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_BankStmt_Amount.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,109 +11,61 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.xmlEngine.XmlDocument;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 
-public class SL_BankStmt_Amount extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_BankStmt_Amount extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strStmAmount = vars.getNumericParameter("inpstmtamt");
-      String strChgAmount = vars.getNumericParameter("inpchargeamt");
-      String strTrxAmount = vars.getNumericParameter("inptrxamt");
-      String strConvChgAmount = vars.getNumericParameter("inpconvertchargeamt");
-      String strTabId = vars.getStringParameter("inpTabId");
-      String strBankStmtLine = vars.getStringParameter("inpcBankstatementlineId");
-      String strCurrencyId = vars.getStringParameter("inpcCurrencyId");
-      String strDP = vars.getStringParameter("inpcDebtPaymentId");
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-      try {
-        printPage(response, vars, strChanged, strStmAmount, strTrxAmount, strChgAmount, strTabId,
-            strConvChgAmount, strBankStmtLine, strCurrencyId, strDP);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // Parameters
+    BigDecimal stmAmount = info.getBigDecimalParameter("inpstmtamt");
+    BigDecimal trxAmount = info.getBigDecimalParameter("inptrxamt");
+    BigDecimal chgAmount = info.getBigDecimalParameter("inpchargeamt");
+    BigDecimal convChgAmount = info.getBigDecimalParameter("inpconvertchargeamt");
+    String strCurrencyId = info.getStringParameter("inpcCurrencyId", IsIDFilter.instance);
+    String strDP = info.getStringParameter("inpcDebtPaymentId", IsIDFilter.instance);
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strChanged,
-      String strStmAmount, String strTrxAmount, String strChgAmount, String strTabId,
-      String strConChgAmount, String strBankStmtLine, String strCurrencyId, String strDP)
-      throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
+    boolean isConversion = false;
+    if (StringUtils.isNotEmpty(strDP)) {
+      isConversion = StringUtils.equals(
+          SLBankStmtAmountData.isConversion(this, strCurrencyId, strDP), "Y");
+    }
 
-    BigDecimal StmAmount = new BigDecimal(strStmAmount.equals("") ? "0" : strStmAmount);
-    BigDecimal TrxAmount = new BigDecimal(strTrxAmount.equals("") ? "0" : strTrxAmount);
-    BigDecimal ChgAmount = new BigDecimal(strChgAmount.equals("") ? "0" : strChgAmount);
-    BigDecimal ConvChgAmount = new BigDecimal(strConChgAmount.equals("") ? "0" : strConChgAmount);
-
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_BankStmt_Amount';\n\n");
-    resultado.append("var respuesta = new Array(");
-    boolean isConversion = false;
-
-    if (!strDP.equals(""))
-      isConversion = SLBankStmtAmountData.isConversion(this, strCurrencyId, strDP).equals("Y");
-
-    if (strChanged.equals("inpstmtamt")) {
+    if (StringUtils.equals(strChanged, "inpstmtamt")) {
       if (isConversion) {
-        if (log4j.isDebugEnabled())
-          log4j.debug("trx: " + TrxAmount.toString() + "chg" + ChgAmount.toString());
-        // ConvChgAmount =
-        // StmAmount.subtract(TrxAmount).subtract(ChgAmount);
-        ConvChgAmount = TrxAmount.subtract(ChgAmount).subtract(StmAmount);
-        resultado.append("new Array(\"inpconvertchargeamt\", " + ConvChgAmount.toString() + ")");
-        resultado.append(");");
+        if (log4j.isDebugEnabled()) {
+          log4j.debug("trx: " + trxAmount.toString() + "chg" + chgAmount.toString());
+        }
+        convChgAmount = trxAmount.subtract(chgAmount).subtract(stmAmount);
+        info.addResult("inpconvertchargeamt", convChgAmount);
       } else {
-        TrxAmount = StmAmount.subtract(ChgAmount);
-        resultado.append("new Array(\"inptrxamt\", " + TrxAmount.toString() + ")");
-        resultado.append(");");
+        trxAmount = stmAmount.subtract(chgAmount);
+        info.addResult("inptrxamt", trxAmount);
       }
     }
-    if (strChanged.equals("inpchargeamt") || (strChanged.equals("inpconvertchargeamt"))) {
-      // StmAmount = TrxAmount.add(ChgAmount).add(ConvChgAmount);
-      StmAmount = TrxAmount.subtract(ChgAmount).subtract(ConvChgAmount);
-      resultado.append("new Array(\"inpstmtamt\", " + StmAmount.toString() + ")");
-      resultado.append(");");
+
+    if (StringUtils.equals(strChanged, "inpchargeamt")
+        || (StringUtils.equals(strChanged, "inpconvertchargeamt"))) {
+      stmAmount = trxAmount.subtract(chgAmount).subtract(convChgAmount);
+      info.addResult("inpstmtamt", stmAmount);
     }
-
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Budget_Product.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Budget_Product.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,73 +11,31 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.openbravo.base.filter.IsIDFilter;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SL_Budget_Product extends SimpleCallout {
 
-public class SL_Budget_Product extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strUOM = vars.getStringParameter("inpmProductId_UOM");
-      String strTabId = vars.getStringParameter("inpTabId");
+    // Parameters
+    String strUOM = info.getStringParameter("inpmProductId_UOM", IsIDFilter.instance);
 
-      try {
-        printPage(response, vars, strUOM, strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strUOM,
-      String strTabId) throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
-    StringBuffer resultado = new StringBuffer();
-
-    resultado.append("var calloutName='SL_Budget_Product';\n");
-    resultado.append("var respuesta = new Array(");
-    resultado.append("new Array(\"inpcUomId\", \"" + strUOM + "\")");
-    resultado.append(");");
-
-    if (log4j.isDebugEnabled())
-      log4j.debug("Array: " + resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    xmlDocument.setParameter("array", resultado.toString());
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    // Update UOM field with the Product's UOM defined
+    info.addResult("inpcUomId", strUOM);
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_CCPMeasure_Group.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_CCPMeasure_Group.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,75 +11,32 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.openbravo.base.filter.IsIDFilter;
+import org.openbravo.utils.FormatUtilities;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SL_CCPMeasure_Group extends SimpleCallout {
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-public class SL_CCPMeasure_Group extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    // Parameter
+    String strMACCPGroupID = info.getStringParameter("inpmaCcpGroupId", IsIDFilter.instance);
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strTabId = vars.getStringParameter("inpTabId");
-
-      String strMACCPGroupID = vars.getStringParameter("inpmaCcpGroupId");
-
-      try {
-        printPage(response, vars, strTabId, strMACCPGroupID);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strTabId,
-      String strMACCPGroupID) throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
+    // Sequence No.
     SLCCPMeasureGroupData[] data = SLCCPMeasureGroupData.select(this, strMACCPGroupID);
-
-    String strSeqNo = data[0].seqno;
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_CCPMeasure_Group';\n\n");
-    resultado.append("var respuesta = new Array(");
-    resultado.append("new Array(\"inpseqno\", \""
-        + FormatUtilities.replaceJS((strSeqNo.equals("") ? "\"\"" : strSeqNo)) + "\")");
-    resultado.append(");\n");
-
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    info.addResult("inpseqno", FormatUtilities.replaceJS(data[0].seqno));
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_CashJournal_Amounts.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_CashJournal_Amounts.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,96 +11,50 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_CashJournal_Amounts extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_CashJournal_Amounts extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strOrder = vars.getStringParameter("inpcOrderId");
-      String strDebtPayment = vars.getStringParameter("inpcDebtPaymentId");
-      String strAmount = vars.getNumericParameter("inpamount");
-      String strDiscount = vars.getNumericParameter("inpdiscountamt");
-      String strwriteoff = vars.getNumericParameter("inpwriteoffamt");
-      String strTabId = vars.getStringParameter("inpTabId");
-      String strCashId = vars.getStringParameter("inpcCashId");
-      String strDesc = vars.getStringParameter("inpdescription");
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-      try {
-        printPage(response, vars, strChanged, strOrder, strDebtPayment, strAmount, strDiscount,
-            strwriteoff, strTabId, strCashId, strDesc);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // Parameters
+    String strOrder = info.getStringParameter("inpcOrderId", IsIDFilter.instance);
+    String strDebtPayment = info.getStringParameter("inpcDebtPaymentId", IsIDFilter.instance);
+    BigDecimal amount = info.getBigDecimalParameter("inpamount");
+    String strCashId = info.getStringParameter("inpcCashId", IsIDFilter.instance);
+    String strDesc = info.getStringParameter("inpdescription");
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strChanged,
-      String strOrder, String strDebtPayment, String strAmount, String strDiscount,
-      String strwriteoff, String strTabId, String strCashId, String strDesc) throws IOException,
-      ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    String amount = null;
-    String strDescription = null;
+    if (StringUtils.equals(strChanged, "inpcOrderId")) {
+      amount = new BigDecimal(SLCashJournalAmountsData.amountOrder(this, strOrder));
+    } else if (StringUtils.equals(strChanged, "inpcDebtPaymentId")) {
+      amount = new BigDecimal(SLCashJournalAmountsData.amountDebtPayment(this, strCashId,
+          strDebtPayment));
+    }
 
-    if (strChanged.equals("inpcOrderId"))
-      amount = SLCashJournalAmountsData.amountOrder(this, strOrder);
-    else if (strChanged.equals("inpcDebtPaymentId"))
-      amount = SLCashJournalAmountsData.amountDebtPayment(this, strCashId, strDebtPayment);
-    else
-      amount = strAmount;
+    if (StringUtils.isNotEmpty(strDebtPayment)) {
+      strDesc = SLCashJournalAmountsData.debtPaymentDescription(this, strDebtPayment);
+    }
 
-    if (!strDebtPayment.equals(""))
-      strDescription = SLCashJournalAmountsData.debtPaymentDescription(this, strDebtPayment);
-    else
-      strDescription = strDesc;
-
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_CashJournal_Amounts';\n\n");
-    resultado.append("var respuesta = new Array(");
-    resultado.append("new Array(\"inpdescription\", \"" + FormatUtilities.replaceJS(strDescription)
-        + "\"),");
-    resultado.append("new Array(\"inpamount\", " + amount + ")");
-
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    info.addResult("inpdescription", FormatUtilities.replaceJS(strDesc));
+    info.addResult("inpamount", amount);
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Charge.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Charge.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,76 +11,34 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SL_Charge extends SimpleCallout {
 
-public class SL_Charge extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strCChargeID = vars.getStringParameter("inpcChargeId");
-      String strTabId = vars.getStringParameter("inpTabId");
+    // Parameter
+    String strCChargeID = info.getStringParameter("inpcChargeId", IsIDFilter.instance);
 
-      try {
-        printPage(response, vars, strCChargeID, strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars,
-      String strCChargeID, String strTabId) throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
-    String chargeAmt;
-    if (strCChargeID.equals(""))
-      chargeAmt = "0";
-    else
-      chargeAmt = SLChargeData.chargeAmt(this, strCChargeID);
-
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_Charge';\n\n");
-    resultado.append("var respuesta = new Array(");
-    resultado.append("new Array(\"inpchargeamt\", " + chargeAmt + ")\n");
-    resultado.append(");");
-
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    // Charge Amount
+    String chargeAmt = StringUtils.isEmpty(strCChargeID) ? "0" : SLChargeData.chargeAmt(this,
+        strCChargeID);
+    info.addResult("inpchargeamt", chargeAmt);
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Conversion_Rate.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Conversion_Rate.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,91 +11,49 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.xmlEngine.XmlDocument;
+import org.apache.commons.lang.StringUtils;
 
-public class SL_Conversion_Rate extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
-  private static final BigDecimal ZERO = new BigDecimal(0.0);
-  private static final BigDecimal ONE = new BigDecimal(1.0);
+public class SL_Conversion_Rate extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strMultiplyRate = vars.getNumericParameter("inpmultiplyrate");
-      String strDivideRate = vars.getNumericParameter("inpdividerate");
-      String strTabId = vars.getStringParameter("inpTabId");
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-      try {
-        printPage(response, vars, strChanged, strMultiplyRate, strDivideRate, strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
+    // Parameters
+    BigDecimal multiplyRate = info.getBigDecimalParameter("inpmultiplyrate");
+    BigDecimal divideRate = info.getBigDecimalParameter("inpdividerate");
+
+    // Calculate Divide Rate By based on Multiple Rate By
+    if (StringUtils.equals(strChanged, "inpmultiplyrate")) {
+      BigDecimal rate = BigDecimal.ZERO;
+      if (multiplyRate.compareTo(BigDecimal.ZERO) != 0) {
+        rate = BigDecimal.ONE.divide(multiplyRate, 12, 4);
       }
-    } else
-      pageError(response);
-  }
+      info.addResult("inpdividerate", rate);
+    }
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strChanged,
-      String strMultiplyRate, String strDivideRate, String strTabId) throws IOException,
-      ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
-    BigDecimal divideRate, multiplyRate, rate, one;
-
-    multiplyRate = new BigDecimal(strMultiplyRate);
-    divideRate = new BigDecimal(strDivideRate);
-    rate = ZERO;
-    one = ONE;
-
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_Conversion_Rate';\n\n");
-    resultado.append("var respuesta = new Array(");
-
-    if (strChanged.equals("inpmultiplyrate")) {
-      if (multiplyRate.compareTo(BigDecimal.ZERO) != 0)
-        rate = one.divide(multiplyRate, 12, 4);
-      resultado.append("new Array(\"inpdividerate\", " + rate.toString() + ")");
-
-    } else {
-      if (divideRate.compareTo(BigDecimal.ZERO) != 0)
-        rate = one.divide(divideRate, 12, 4);
-      resultado.append("new Array(\"inpmultiplyrate\", " + rate.toString() + ")");
+    // Calculate Multiple Rate By based on Divide Rate By
+    else if (StringUtils.equals(strChanged, "inpdividerate")) {
+      BigDecimal rate = BigDecimal.ZERO;
+      if (divideRate.compareTo(BigDecimal.ZERO) != 0) {
+        rate = BigDecimal.ONE.divide(divideRate, 12, 4);
+      }
+      info.addResult("inpmultiplyrate", rate);
     }
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_CostcenterEmployee_SalaryCategory.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_CostcenterEmployee_SalaryCategory.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,70 +11,33 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.openbravo.base.filter.IsIDFilter;
+import org.openbravo.utils.FormatUtilities;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SL_CostcenterEmployee_SalaryCategory extends SimpleCallout {
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-public class SL_CostcenterEmployee_SalaryCategory extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    // Parameter
+    String srtcSalaryCategoryId = info.getStringParameter("inpcSalaryCategoryId",
+        IsIDFilter.instance);
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String srtcSalaryCategoryId = vars.getStringParameter("inpcSalaryCategoryId");
-
-      try {
-        printPage(response, vars, srtcSalaryCategoryId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars,
-      String srtcSalaryCategoryId) throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
+    // Cost UOM
     String strCostUom = SLCostcenterEmployeeSalaryCategoryData.select(this, srtcSalaryCategoryId);
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_CostcenterEmployee_SalaryCategory';\n\n");
-    resultado.append("var respuesta = new Array(");
-    resultado
-        .append("new Array(\"inpcostuom\", \"" + FormatUtilities.replaceJS(strCostUom) + "\")");
-    resultado.append(");");
-
-    xmlDocument.setParameter("array", resultado.toString());
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    info.addResult("inpcostuom", FormatUtilities.replaceJS(strCostUom));
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_GlobalUse_Conversion.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_GlobalUse_Conversion.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,111 +11,64 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_GlobalUse_Conversion extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_GlobalUse_Conversion extends SimpleCallout {
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
-
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strUOM = vars.getStringParameter("inpcUomId");
-      String strMProductUOMID = vars.getStringParameter("inpmProductUomId");
-      String strQuantityOrder = vars.getNumericParameter("inpquantityorder");
-      String strTabId = vars.getStringParameter("inpTabId");
-      try {
-        printPage(response, vars, strUOM, strMProductUOMID, strQuantityOrder, strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strUOM,
-      String strMProductUOMID, String strQuantityOrder, String strTabId) throws IOException,
-      ServletException {
-    String localStrUOM = strUOM;
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    if (localStrUOM.startsWith("\""))
-      localStrUOM = localStrUOM.substring(1, localStrUOM.length() - 1);
-    int stdPrecision = Integer.valueOf(SLInvoiceConversionData.stdPrecision(this, localStrUOM))
-        .intValue();
-    String strInitUOM = SLInvoiceConversionData.initUOMId(this, strMProductUOMID);
-    String strMultiplyRate;
-    boolean check = false;
-
-    strMultiplyRate = SLInvoiceConversionData.multiplyRate(this, strInitUOM, localStrUOM);
-    if (strInitUOM.equals(localStrUOM))
-      strMultiplyRate = "1";
-    if (strMultiplyRate.equals(""))
-      strMultiplyRate = SLInvoiceConversionData.divideRate(this, localStrUOM, strInitUOM);
-    if (strMultiplyRate.equals("")) {
-      strMultiplyRate = "1";
-      if (!strMProductUOMID.equals(""))
-        check = true;
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
     }
 
-    BigDecimal quantityOrder, qtyOrdered, multiplyRate;
+    // Parameters
+    String strUOM = info.getStringParameter("inpcUomId", IsIDFilter.instance);
+    String strMProductUOMID = info.getStringParameter("inpmProductUomId", IsIDFilter.instance);
+    String strQuantityOrder = info.vars.getNumericParameter("inpquantityorder");
 
-    multiplyRate = new BigDecimal(strMultiplyRate);
+    // Multiple Rate for UOM Conversion if any
+    String strInitUOM = SLInvoiceConversionData.initUOMId(this, strMProductUOMID);
+    String strMultiplyRate = StringUtils.equals(strInitUOM, strUOM) ? "1" : "";
+    if (StringUtils.isEmpty(strMultiplyRate)) {
+      strMultiplyRate = SLInvoiceConversionData.multiplyRate(this, strInitUOM, strUOM);
+    }
+    if (StringUtils.isEmpty(strMultiplyRate)) {
+      strMultiplyRate = SLInvoiceConversionData.divideRate(this, strUOM, strInitUOM);
+    }
+    if (StringUtils.isEmpty(strMultiplyRate)) {
+      strMultiplyRate = "1";
+      if (StringUtils.isNotEmpty(strMProductUOMID)) {
+        // Show message when no UOM Conversion exists
+        info.showMessage(FormatUtilities.replaceJS(Utility.messageBD(this, "NoUOMConversion",
+            info.vars.getLanguage())));
+      }
+    }
 
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_GlobalUse_Conversion';\n\n");
-    resultado.append("var respuesta = new Array(");
-    if (!strQuantityOrder.equals("")) {
-      quantityOrder = new BigDecimal(strQuantityOrder);
-      qtyOrdered = quantityOrder.multiply(multiplyRate);
-      if (qtyOrdered.scale() > stdPrecision)
+    // Calculate Quantity based in UOM Conversion
+    if (StringUtils.isNotEmpty(strQuantityOrder)) {
+      int stdPrecision = Integer.valueOf(SLInvoiceConversionData.stdPrecision(this, strUOM));
+      BigDecimal multiplyRate = new BigDecimal(strMultiplyRate);
+      BigDecimal qtyOrdered = new BigDecimal(strQuantityOrder).multiply(multiplyRate);
+      if (qtyOrdered.scale() > stdPrecision) {
         qtyOrdered = qtyOrdered.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
-      resultado.append("new Array(\"inpquantity\", " + qtyOrdered.toString() + ")");
+      }
+      info.addResult("inpmovementqty", qtyOrdered);
     }
-    if (check) {
-      if (!strQuantityOrder.equals(""))
-        resultado.append(",");
-      resultado
-          .append("new Array('MESSAGE', \""
-              + FormatUtilities.replaceJS(Utility.messageBD(this, "NoUOMConversion",
-                  vars.getLanguage())) + "\")");
-    }
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_GlobalUse_Product.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_GlobalUse_Product.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,179 +11,86 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.FieldProvider;
 import org.openbravo.erpCommon.utility.ComboTableData;
 import org.openbravo.erpCommon.utility.Utility;
-import org.openbravo.model.common.plm.AttributeSet;
 import org.openbravo.model.common.plm.Product;
 import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_GlobalUse_Product extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_GlobalUse_Product extends SimpleCallout {
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strTabId = vars.getStringParameter("inpTabId");
+    // Parameters
+    String strMProductID = info.getStringParameter("inpmProductId", IsIDFilter.instance);
+    String strPAttr = info.getStringParameter("inpmProductId_ATR", IsIDFilter.instance);
 
-      String strMProductID = vars.getStringParameter("inpmProductId");
-      String strPAttr = vars.getStringParameter("inpmProductId_ATR");
+    // UOM
+    String strProductUom = SLWRPhaseProductProductData.selectProductUom(this, strMProductID);
+    info.addResult("inpcUomId", FormatUtilities.replaceJS(strProductUom));
 
-      try {
-        printPage(response, vars, strTabId, strMProductID, strPAttr);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // HasSecondUOM
+    String strHasSecondaryUOM = SLGlobalUseProductData.hasSecondaryUOM(this, strMProductID);
+    info.addResult("inphasseconduom", Integer.parseInt(strHasSecondaryUOM));
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strTabId,
-      String strMProductID, String strPAttr) throws IOException, ServletException {
-    String localStrPAttr = strPAttr;
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
-    String strProductUom = SLWRPhaseProductProductData.selectProductUom(this, strMProductID);
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_GlobalUse_Product';\n\n");
-    resultado.append("var respuesta = new Array(");
-    resultado
-        .append("new Array(\"inpcUomId\", \""
-            + FormatUtilities.replaceJS((strProductUom.equals("") ? "\"\"" : strProductUom))
-            + "\"),\n");
-    String strHasSecondaryUOM = SLGlobalUseProductData.hasSecondaryUOM(this, strMProductID);
-    resultado.append("new Array(\"inphasseconduom\", \"" + strHasSecondaryUOM + "\"),\n");
-    if (localStrPAttr.startsWith("\""))
-      localStrPAttr = localStrPAttr.substring(1, localStrPAttr.length() - 1);
-    resultado.append("new Array(\"inpmAttributesetinstanceId\", \"" + localStrPAttr + "\"),\n");
-    resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \""
-        + FormatUtilities.replaceJS(SLInOutLineProductData.attribute(this, localStrPAttr))
-        + "\"),\n");
-    String strAttrSet, strAttrSetValueType;
-    strAttrSet = strAttrSetValueType = "";
+    // AttributeSetInstance, AttributeSet, AttributeSetValueType
+    info.addResult("inpmAttributesetinstanceId", strPAttr);
     OBContext.setAdminMode();
     try {
       final Product product = OBDal.getInstance().get(Product.class, strMProductID);
       if (product != null) {
-        AttributeSet attributeset = product.getAttributeSet();
-        if (attributeset != null)
-          strAttrSet = product.getAttributeSet().toString();
-        strAttrSetValueType = product.getUseAttributeSetValueAs();
+        info.addResult("inpattributeset", product.getAttributeSet() != null ? product
+            .getAttributeSet().getId() : "");
+        info.addResult("inpattrsetvaluetype",
+            FormatUtilities.replaceJS(product.getUseAttributeSetValueAs()));
       }
     } finally {
       OBContext.restorePreviousMode();
     }
-    resultado.append("new Array(\"inpattributeset\", \"" + FormatUtilities.replaceJS(strAttrSet)
-        + "\"),\n");
-    resultado.append("new Array(\"inpattrsetvaluetype\", \""
-        + FormatUtilities.replaceJS(strAttrSetValueType) + "\"),\n");
-    // String strProductUomId = SLGlobalUseProduct.selectProductUomId(this,
-    // strMProductID);
 
-    resultado.append("new Array(\"inpmProductUomId\", ");
+    // Product UOM
     String strmProductUOMId = SLGlobalUseProductData.strMProductUOMID(this, strMProductID,
         strProductUom);
-    if (vars.getLanguage().equals("en_US")) {
-      FieldProvider[] tld = null;
-      try {
-        ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "",
-            "M_Product_UOM", "", Utility.getContext(this, vars, "#AccessibleOrgTree",
-                "SLGlobalUseProduct"), Utility.getContext(this, vars, "#User_Client",
-                "SLGlobalUseProduct"), 0);
-        Utility.fillSQLParameters(this, vars, null, comboTableData, "SLGlobalUseProduct", "");
-        tld = comboTableData.select(false);
-        comboTableData = null;
-      } catch (Exception ex) {
-        throw new ServletException(ex);
+    FieldProvider[] tld = null;
+    try {
+      ComboTableData comboTableData = new ComboTableData(info.vars, this, "TABLE", "",
+          "M_Product_UOM", "", Utility.getContext(this, info.vars, "#AccessibleOrgTree",
+              "SLGlobalUseProduct"), Utility.getContext(this, info.vars, "#User_Client",
+              "SLGlobalUseProduct"), 0);
+      Utility.fillSQLParameters(this, info.vars, null, comboTableData, "SLGlobalUseProduct", "");
+      tld = comboTableData.select(false);
+      comboTableData = null;
+    } catch (Exception ex) {
+      throw new ServletException(ex);
+    }
+    if (tld != null && tld.length > 0) {
+      info.addSelect("inpmProductUomId");
+      for (int i = 0; i < tld.length; i++) {
+        info.addSelectResult(tld[i].getField("id"),
+            FormatUtilities.replaceJS(tld[i].getField("name")),
+            StringUtils.equalsIgnoreCase(tld[i].getField("id"), strmProductUOMId));
       }
-
-      if (tld != null && tld.length > 0) {
-        resultado.append("new Array(");
-        for (int i = 0; i < tld.length; i++) {
-          resultado.append("new Array(\"" + tld[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \""
-              + (tld[i].getField("id").equalsIgnoreCase(strmProductUOMId) ? "true" : "false")
-              + "\")");
-          if (i < tld.length - 1)
-            resultado.append(",\n");
-        }
-        resultado.append("\n)");
-      } else
-        resultado.append("null");
-      resultado.append("\n),");
+      info.endSelect();
     } else {
-      FieldProvider[] tld = null;
-      try {
-        ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "",
-            "M_Product_UOM", "", Utility.getContext(this, vars, "#AccessibleOrgTree",
-                "SLGlobalUseProduct"), Utility.getContext(this, vars, "#User_Client",
-                "SLGlobalUseProduct"), 0);
-        Utility.fillSQLParameters(this, vars, null, comboTableData, "SLGlobalUseProduct", "");
-        tld = comboTableData.select(false);
-        comboTableData = null;
-      } catch (Exception ex) {
-        throw new ServletException(ex);
-      }
-
-      if (tld != null && tld.length > 0) {
-        resultado.append("new Array(");
-        for (int i = 0; i < tld.length; i++) {
-          resultado.append("new Array(\"" + tld[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \""
-              + (tld[i].getField("id").equalsIgnoreCase(strmProductUOMId) ? "true" : "false")
-              + "\")");
-          if (i < tld.length - 1)
-            resultado.append(",\n");
-        }
-        resultado.append("\n)");
-      } else
-        resultado.append("null");
-      resultado.append("\n),");
+      info.addResult("inpmProductUomId", null);
     }
-    resultado.append("new Array(\"EXECUTE\", \"displayLogic();\")\n");
-    // To place the cursor in the quantity field
-    // resultado.append("new Array(\"CURSOR_FIELD\", \"inpqtyordered\")\n");
-    // if (!strHasSecondaryUOM.equals("0"))
-    // resultado.append(", new Array(\"CURSOR_FIELD\", \"inpquantityorder\")\n");
-    resultado.append(");\n");
-
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_InOutLine_Product.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_InOutLine_Product.java	Fri Aug 04 19:25:27 2017 -0400
@@ -169,9 +169,5 @@
     // UOM
 
     info.addResult("inpcUomId", info.vars.getStringParameter("inpmProductId_UOM"));
-
-    // displayLogic
-
-    info.addResult("EXECUTE", "displayLogic();");
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_InOut_BPartner.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_InOut_BPartner.java	Fri Aug 04 19:25:27 2017 -0400
@@ -18,19 +18,13 @@
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.lang.StringUtils;
 import org.openbravo.advpaymentmngt.utility.FIN_Utility;
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.FieldProvider;
 import org.openbravo.erpCommon.businessUtility.BpartnerMiscData;
@@ -40,236 +34,159 @@
 import org.openbravo.model.common.businesspartner.BusinessPartner;
 import org.openbravo.utils.FormatUtilities;
 import org.openbravo.utils.Replace;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_InOut_BPartner extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_InOut_BPartner extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strBPartner = vars.getStringParameter("inpcBpartnerId");
-      String strLocation = vars.getStringParameter("inpcBpartnerId_LOC");
-      String strContact = vars.getStringParameter("inpcBpartnerId_CON");
-      String strWindowId = vars.getStringParameter("inpwindowId");
-      String strProjectId = vars.getStringParameter("inpcProjectId");
-      String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
-      String strTabId = vars.getStringParameter("inpTabId");
-      String strDeliveryTerms = vars.getStringParameter("inpdeliveryrule");
-      String strDeliveryMethod = vars.getStringParameter("inpdeliveryviarule");
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-      try {
-        printPage(response, vars, strBPartner, strLocation, strDeliveryTerms, strDeliveryMethod,
-            strContact, strWindowId, strProjectId, strIsSOTrx, strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strBPartner,
-      String strLocation, String strDeliveryTerms, String strDeliveryMethod, String strContact,
-      String strWindowId, String strProjectId, String strIsSOTrx, String strTabId)
-      throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
+    // Parameters
+    String strBPartner = info.getStringParameter("inpcBpartnerId", IsIDFilter.instance);
+    String strLocation = info.getStringParameter("inpcBpartnerId_LOC", IsIDFilter.instance);
+    String strContact = info.getStringParameter("inpcBpartnerId_CON", IsIDFilter.instance);
+    String strOrgId = info.getStringParameter("inpadOrgId", IsIDFilter.instance);
+    String strDeliveryTerms = info.getStringParameter("inpdeliveryrule");
+    String strDeliveryMethod = info.getStringParameter("inpdeliveryviarule");
+    String strIsSOTrx = Utility.getContext(this, info.vars, "isSOTrx", info.getWindowId());
 
     BpartnerMiscData[] data = BpartnerMiscData.select(this, strBPartner);
-
     String strUserRep = "";
     if (data != null && data.length > 0) {
       strUserRep = SEOrderBPartnerData.userIdSalesRep(this, data[0].salesrepId);
-    }
-    if (StringUtils.isEmpty(strUserRep)) {
-      strUserRep = vars.getUser();
+      if (StringUtils.isEmpty(strUserRep)) {
+        strUserRep = info.vars.getUser();
+      }
     }
 
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_InOut_BPartner';\n\n");
-    resultado.append("var respuesta = new Array(");
-
+    // Business Partner Location
     FieldProvider[] tdv = null;
     try {
-      ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR",
+      ComboTableData comboTableData = new ComboTableData(info.vars, this, "TABLEDIR",
           "C_BPartner_Location_ID", "", "C_BPartner Location - Ship To", Utility.getContext(this,
-              vars, "#AccessibleOrgTree", strWindowId), Utility.getContext(this, vars,
-              "#User_Client", strWindowId), 0);
-      Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
+              info.vars, "#AccessibleOrgTree", info.getWindowId()), Utility.getContext(this,
+              info.vars, "#User_Client", info.getWindowId()), 0);
+      Utility.fillSQLParameters(this, info.vars, null, comboTableData, info.getWindowId(), "");
       tdv = comboTableData.select(false);
       comboTableData = null;
     } catch (Exception ex) {
       throw new ServletException(ex);
     }
+    if (tdv != null && tdv.length > 0) {
+      info.addSelect("inpcBpartnerLocationId");
+      for (int i = 0; i < tdv.length; i++) {
+        // If a location is provided it is selected, else the first one is selected
+        boolean selected = (StringUtils.isEmpty(strLocation) && i == 0)
+            || (StringUtils.isNotEmpty(strLocation) && StringUtils.equalsIgnoreCase(
+                tdv[i].getField("id"), strLocation));
+        info.addSelectResult(tdv[i].getField("id"),
+            FormatUtilities.replaceJS(Replace.replace(tdv[i].getField("name"), "\"", "\\\"")),
+            selected);
+      }
+      info.endSelect();
+    } else {
+      info.addResult("inpcBpartnerLocationId", null);
+    }
 
-    resultado.append("new Array(\"inpcBpartnerLocationId\", ");
-    if (tdv != null && tdv.length > 0) {
-      resultado.append("new Array(");
-
-      if (strLocation.isEmpty()) {
-        // If no location is provided, the first one is selected
-        resultado.append("new Array(\"" + tdv[0].getField("id") + "\", \""
-            + FormatUtilities.replaceJS(Replace.replace(tdv[0].getField("name"), "\"", "\\\""))
-            + "\", \"" + "true" + "\")");
-        if (tdv.length > 1) {
-          resultado.append(",\n");
-        }
-        for (int i = 1; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(Replace.replace(tdv[i].getField("name"), "\"", "\\\""))
-              + "\", \"" + "false" + "\")");
-          if (i < tdv.length - 1) {
-            resultado.append(",\n");
-          }
-        }
-      } else {
-        // If a location is provided, it is selected
-        for (int i = 0; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(Replace.replace(tdv[i].getField("name"), "\"", "\\\""))
-              + "\", \"" + (tdv[i].getField("id").equalsIgnoreCase(strLocation) ? "true" : "false")
-              + "\")");
-          if (i < tdv.length - 1) {
-            resultado.append(",\n");
-          }
-        }
-      }
-      resultado.append("\n)");
-    } else {
-      resultado.append("null");
-    }
-    resultado.append("\n),");
-    resultado.append("new Array(\"inpsalesrepId\", ");
+    // Sales Representative
     FieldProvider[] tld = null;
     try {
-      ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "SalesRep_ID",
-          "AD_User SalesRep", "", Utility.getContext(this, vars, "#AccessibleOrgTree",
-              "SEOrderBPartner"),
-          Utility.getContext(this, vars, "#User_Client", "SEOrderBPartner"), 0);
-      Utility.fillSQLParameters(this, vars, null, comboTableData, "SEOrderBPartner", "");
+      ComboTableData comboTableData = new ComboTableData(info.vars, this, "TABLE", "SalesRep_ID",
+          "AD_User SalesRep", "", Utility.getReferenceableOrg(info.vars, strOrgId),
+          Utility.getContext(this, info.vars, "#User_Client", info.getWindowId()), 0);
+      Utility.fillSQLParameters(this, info.vars, null, comboTableData, info.getWindowId(), "");
       tld = comboTableData.select(false);
       comboTableData = null;
     } catch (Exception ex) {
       throw new ServletException(ex);
     }
+    if (tld != null && tld.length > 0) {
+      info.addSelect("inpsalesrepId");
+      for (int i = 0; i < tld.length; i++) {
+        info.addSelectResult(tld[i].getField("id"),
+            FormatUtilities.replaceJS(tld[i].getField("name")),
+            StringUtils.equalsIgnoreCase(tld[i].getField("id"), strUserRep));
+      }
+      info.endSelect();
+    } else {
+      info.addResult("inpsalesrepId", null);
+    }
 
-    if (tld != null && tld.length > 0) {
-      resultado.append("new Array(");
-      for (int i = 0; i < tld.length; i++) {
-        resultado.append("new Array(\"" + tld[i].getField("id") + "\", \""
-            + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \""
-            + (tld[i].getField("id").equalsIgnoreCase(strUserRep) ? "true" : "false") + "\")");
-        if (i < tld.length - 1)
-          resultado.append(",\n");
-      }
-      resultado.append("\n)");
-    } else
-      resultado.append("null");
-    resultado.append("\n),");
-    resultado.append("new Array(\"inpcProjectId\", \"\"),");
-    resultado.append("new Array(\"inpcProjectId_R\", \"\"),");
+    // Project
+    info.addResult("inpcProjectId", null);
+
+    // Business Partner Contact
     try {
-      ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "AD_User_ID", "",
-          "AD_User C_BPartner User/Contacts", Utility.getContext(this, vars, "#AccessibleOrgTree",
-              strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0);
-      Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
+      ComboTableData comboTableData = new ComboTableData(info.vars, this, "TABLEDIR", "AD_User_ID",
+          "", "AD_User C_BPartner User/Contacts", Utility.getReferenceableOrg(info.vars, strOrgId),
+          Utility.getContext(this, info.vars, "#User_Client", info.getWindowId()), 0);
+      Utility.fillSQLParameters(this, info.vars, null, comboTableData, info.getWindowId(), "");
       tdv = comboTableData.select(false);
       comboTableData = null;
     } catch (Exception ex) {
       throw new ServletException(ex);
     }
+    if (tdv != null && tdv.length > 0) {
+      info.addSelect("inpadUserId");
+      for (int i = 0; i < tdv.length; i++) {
+        // If no contact is provided it is selected, else the first one is selected
+        boolean selected = (StringUtils.isEmpty(strContact) && i == 0)
+            || (StringUtils.isNotEmpty(strContact) && StringUtils.equalsIgnoreCase(
+                tdv[i].getField("id"), strContact));
+        info.addSelectResult(tdv[i].getField("id"),
+            FormatUtilities.replaceJS(Replace.replace(tdv[i].getField("name"), "\"", "\\\"")),
+            selected);
+      }
+      info.endSelect();
+    } else {
+      info.addResult("inpadUserId", null);
+    }
 
-    resultado.append("new Array(\"inpadUserId\", ");
-    if (tdv != null && tdv.length > 0) {
-      resultado.append("new Array(");
-
-      if (strContact.isEmpty()) {
-        resultado.append("new Array(\"" + tdv[0].getField("id") + "\", \""
-            + FormatUtilities.replaceJS(Replace.replace(tdv[0].getField("name"), "\"", "\\\""))
-            + "\", \"" + "true" + "\")");
-        if (tdv.length > 1) {
-          resultado.append(",\n");
-        }
-        for (int i = 1; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(Replace.replace(tdv[i].getField("name"), "\"", "\\\""))
-              + "\", \"" + "false" + "\")");
-          if (i < tdv.length - 1) {
-            resultado.append(",\n");
-          }
-        }
-      } else {
-        for (int i = 0; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(Replace.replace(tdv[i].getField("name"), "\"", "\\\""))
-              + "\", \"" + (tdv[i].getField("id").equalsIgnoreCase(strContact) ? "true" : "false")
-              + "\")");
-          if (i < tdv.length - 1) {
-            resultado.append(",\n");
-          }
-        }
+    // Delivery Rule
+    BusinessPartner bpartner = OBDal.getInstance().get(BusinessPartner.class, strBPartner);
+    if (bpartner != null) {
+      if (StringUtils.isNotEmpty(bpartner.getDeliveryTerms())
+          && !StringUtils.equals(strDeliveryTerms, bpartner.getDeliveryTerms())) {
+        info.addResult("inpdeliveryrule", bpartner.getDeliveryTerms());
       }
 
-      resultado.append("\n)");
-    } else {
-      resultado.append("null");
+      // Delivery Via Rule
+      if (StringUtils.isNotEmpty(bpartner.getDeliveryMethod())
+          && !StringUtils.equals(strDeliveryMethod, bpartner.getDeliveryMethod())) {
+        info.addResult("inpdeliveryviarule", bpartner.getDeliveryMethod());
+      }
+
+      // If the Business Partner is blocked for this document, show an information message
+      final String rtvendorship = "273673D2ED914C399A6C51DB758BE0F9";
+      final String rMatReceipt = "123271B9AD60469BAE8A924841456B63";
+      final boolean isSOTrx = StringUtils.equals(strIsSOTrx, "Y");
+      String message = "";
+      if (!StringUtils.equals(info.getWindowId(), rtvendorship)
+          && !StringUtils.equals(info.getWindowId(), rMatReceipt)
+          && FIN_Utility.isBlockedBusinessPartner(strBPartner, isSOTrx, 2)) {
+        message = OBMessageUtils.messageBD("ThebusinessPartner") + " " + bpartner.getIdentifier()
+            + " " + OBMessageUtils.messageBD("BusinessPartnerBlocked");
+      }
+
+      // If the Business Partner has negative credit available, show an information message
+      if (data != null && data.length > 0 && isSOTrx
+          && new BigDecimal(data[0].creditavailable).compareTo(BigDecimal.ZERO) < 0) {
+        String creditLimitExceed = String.valueOf(Double.parseDouble(data[0].creditavailable) * -1);
+        if (StringUtils.isNotEmpty(message)) {
+          message = message + "<br>";
+        }
+        message = message + Utility.messageBD(this, "CreditLimitOver", info.vars.getLanguage())
+            + creditLimitExceed;
+      }
+
+      if (StringUtils.isNotEmpty(message)) {
+        info.showMessage(message);
+      }
     }
-    resultado.append("\n)");
-    BusinessPartner bpartner = OBDal.getInstance().get(BusinessPartner.class, strBPartner);
-    if (StringUtils.isNotEmpty(bpartner.getDeliveryTerms())
-        && !StringUtils.equals(strDeliveryTerms, bpartner.getDeliveryTerms())) {
-      resultado.append(", new Array(\"inpdeliveryrule\", \"" + bpartner.getDeliveryTerms() + "\")");
-    }
-    if (StringUtils.isNotEmpty(bpartner.getDeliveryMethod())
-        && !StringUtils.equals(strDeliveryMethod, bpartner.getDeliveryMethod())) {
-      resultado.append(", new Array(\"inpdeliveryviarule\", \"" + bpartner.getDeliveryMethod()
-          + "\")");
-    }
-    final String rtvendorship = "273673D2ED914C399A6C51DB758BE0F9";
-    final String rMatReceipt = "123271B9AD60469BAE8A924841456B63";
-    String strwindow = vars.getStringParameter("inpwindowId");
-    String message = "";
-    if (!StringUtils.equals(strwindow, rtvendorship)
-        && !StringUtils.equals(strwindow, rMatReceipt)
-        && bpartner != null
-        && FIN_Utility.isBlockedBusinessPartner(bpartner.getId(),
-            StringUtils.equals(strIsSOTrx, "Y"), 2)) {
-      // If the Business Partner is blocked for this document, show an information message.
-      if (message.length() > 0) {
-        message = message + "<br>";
-      }
-      message = message + OBMessageUtils.messageBD("ThebusinessPartner") + " "
-          + bpartner.getIdentifier() + " " + OBMessageUtils.messageBD("BusinessPartnerBlocked");
-    }
-    if (data != null && data.length > 0
-        && new BigDecimal(data[0].creditavailable).compareTo(BigDecimal.ZERO) < 0
-        && strIsSOTrx.equals("Y")) {
-      String creditLimitExceed = "" + Double.parseDouble(data[0].creditavailable) * -1;
-      if (message.length() > 0) {
-        message = message + "<br>";
-      }
-      message = message + Utility.messageBD(this, "CreditLimitOver", vars.getLanguage())
-          + creditLimitExceed;
-    }
-    resultado.append(", new Array('MESSAGE', \"" + message + "\")");
 
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_InOut_Conversion.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_InOut_Conversion.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,115 +11,68 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_InOut_Conversion extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_InOut_Conversion extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strUOM = vars.getStringParameter("inpcUomId");
-      String strMProductUOMID = vars.getStringParameter("inpmProductUomId");
-      String strQuantityOrder = vars.getNumericParameter("inpquantityorder");
-      String strTabId = vars.getStringParameter("inpTabId");
-
-      try {
-        printPage(response, vars, strUOM, strMProductUOMID, strQuantityOrder, strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strUOM,
-      String strMProductUOMID, String strQuantityOrder, String strTabId) throws IOException,
-      ServletException {
-    String localStrUOM = strUOM;
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    if (localStrUOM.startsWith("\""))
-      localStrUOM = localStrUOM.substring(1, localStrUOM.length() - 1);
-    int stdPrecision = Integer.valueOf(SLInvoiceConversionData.stdPrecision(this, localStrUOM))
-        .intValue();
-    String strInitUOM = SLInvoiceConversionData.initUOMId(this, strMProductUOMID);
-    String strMultiplyRate;
-    boolean check = false;
-
-    strMultiplyRate = SLInvoiceConversionData.multiplyRate(this, strInitUOM, localStrUOM);
-    if (strInitUOM.equals(localStrUOM))
-      strMultiplyRate = "1";
-    if (strMultiplyRate.equals(""))
-      strMultiplyRate = SLInvoiceConversionData.divideRate(this, localStrUOM, strInitUOM);
-    if (strMultiplyRate.equals("")) {
-      strMultiplyRate = "1";
-      if (!strMProductUOMID.equals(""))
-        check = true;
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
     }
 
+    // Parameters
+    String strUOM = info.getStringParameter("inpcUomId", IsIDFilter.instance);
+    String strMProductUOMID = info.getStringParameter("inpmProductUomId", IsIDFilter.instance);
+    String strQuantityOrder = info.vars.getNumericParameter("inpquantityorder");
+
+    // Multiply Rate for UOM Conversion if any
+    String strInitUOM = SLInvoiceConversionData.initUOMId(this, strMProductUOMID);
+    String strMultiplyRate = StringUtils.equals(strInitUOM, strUOM) ? "1" : "";
+    if (StringUtils.isEmpty(strMultiplyRate)) {
+      strMultiplyRate = SLInvoiceConversionData.multiplyRate(this, strInitUOM, strUOM);
+    }
+    if (StringUtils.isEmpty(strMultiplyRate)) {
+      strMultiplyRate = SLInvoiceConversionData.divideRate(this, strUOM, strInitUOM);
+    }
+    // Set message when no UOM Conversion exists
+    if (StringUtils.isEmpty(strMultiplyRate)) {
+      strMultiplyRate = "1";
+      if (StringUtils.isNotEmpty(strMProductUOMID)) {
+        info.showMessage(FormatUtilities.replaceJS(Utility.messageBD(this, "NoUOMConversion",
+            info.vars.getLanguage())));
+      }
+    }
+    // Calculate Movement Qty based on UOM Conversion
     BigDecimal quantityOrder, movementQty, multiplyRate;
-
     multiplyRate = new BigDecimal(strMultiplyRate);
 
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_InOut_Conversion';\n\n");
-    if (strMultiplyRate.equals("0")) {
-      resultado.append("var respuesta = null");
-    } else {
-      resultado.append("var respuesta = new Array(");
-      if (!strQuantityOrder.equals("")) {
-        quantityOrder = new BigDecimal(strQuantityOrder);
-        movementQty = quantityOrder.multiply(multiplyRate);
-        if (movementQty.scale() > stdPrecision)
-          movementQty = movementQty.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
-        resultado.append("new Array(\"inpmovementqty\", " + movementQty.toString() + ")");
+    if (StringUtils.isNotEmpty(strQuantityOrder)) {
+      quantityOrder = new BigDecimal(strQuantityOrder);
+      movementQty = quantityOrder.multiply(multiplyRate);
+      int stdPrecision = Integer.valueOf(SLInvoiceConversionData.stdPrecision(this, strUOM))
+          .intValue();
+      if (movementQty.scale() > stdPrecision) {
+        movementQty = movementQty.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
       }
-      if (check) {
-        if (!strQuantityOrder.equals(""))
-          resultado.append(",");
-        resultado.append("new Array('MESSAGE', \""
-            + FormatUtilities.replaceJS(Utility.messageBD(this, "NoUOMConversion",
-                vars.getLanguage())) + "\")");
-      }
-      resultado.append(");");
+      info.addResult("inpmovementqty", movementQty);
     }
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Internal_Consumption_Conversion.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Internal_Consumption_Conversion.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,122 +11,78 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_Internal_Consumption_Conversion extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_Internal_Consumption_Conversion extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strUOM = vars.getStringParameter("inpcUomId");
-      String strMProductUOMID = vars.getStringParameter("inpmProductUomId");
-      String strQuantityOrder = vars.getNumericParameter("inpquantityorder");
-      String strTabId = vars.getStringParameter("inpTabId");
-      try {
-        printPage(response, vars, strChanged, strUOM, strMProductUOMID, strQuantityOrder, strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strChanged,
-      String strUOM, String strMProductUOMID, String strQuantityOrder, String strTabId)
-      throws IOException, ServletException {
-    String localStrUOM = strUOM;
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    if (localStrUOM.startsWith("\""))
-      localStrUOM = localStrUOM.substring(1, localStrUOM.length() - 1);
-    int stdPrecision = Integer.valueOf(SLInvoiceConversionData.stdPrecision(this, localStrUOM))
-        .intValue();
-    String strInitUOM = SLInvoiceConversionData.initUOMId(this, strMProductUOMID);
-    String strMultiplyRate;
-    boolean check = false;
-
-    strMultiplyRate = SLInvoiceConversionData.multiplyRate(this, strInitUOM, localStrUOM);
-    if (strInitUOM.equals(localStrUOM))
-      strMultiplyRate = "1";
-    if (strMultiplyRate.equals(""))
-      strMultiplyRate = SLInvoiceConversionData.divideRate(this, localStrUOM, strInitUOM);
-    if (strMultiplyRate.equals("")) {
-      strMultiplyRate = "1";
-      if (!strMProductUOMID.equals(""))
-        check = true;
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
     }
 
-    BigDecimal quantityOrder, qtyOrdered, multiplyRate;
+    // Parameters
+    String strUOM = info.getStringParameter("inpcUomId", IsIDFilter.instance);
+    String strMProductUOMID = info.getStringParameter("inpmProductUomId", IsIDFilter.instance);
+    String strQuantityOrder = info.vars.getNumericParameter("inpquantityorder");
 
-    multiplyRate = new BigDecimal(strMultiplyRate);
-
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_Internal_Consumption_Conversion';\n\n");
-    resultado.append("var respuesta = new Array(");
-
-    if (!strQuantityOrder.equals("")) {
-      quantityOrder = new BigDecimal(strQuantityOrder);
-      qtyOrdered = quantityOrder.multiply(multiplyRate);
-      if (qtyOrdered.scale() > stdPrecision)
-        qtyOrdered = qtyOrdered.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
-      resultado.append("new Array(\"inpmovementqty\", " + qtyOrdered.toString() + ")");
+    // Multiple Rate for UOM Conversion if any
+    String strInitUOM = SLInvoiceConversionData.initUOMId(this, strMProductUOMID);
+    String strMultiplyRate = StringUtils.equals(strInitUOM, strUOM) ? "1" : "";
+    if (StringUtils.isEmpty(strMultiplyRate)) {
+      strMultiplyRate = SLInvoiceConversionData.multiplyRate(this, strInitUOM, strUOM);
     }
-    if (check) {
-      if (!strQuantityOrder.equals(""))
-        resultado.append(",");
-      resultado
-          .append("new Array('MESSAGE', \""
-              + FormatUtilities.replaceJS(Utility.messageBD(this, "NoUOMConversion",
-                  vars.getLanguage())) + "\")");
+    if (StringUtils.isEmpty(strMultiplyRate)) {
+      strMultiplyRate = SLInvoiceConversionData.divideRate(this, strUOM, strInitUOM);
     }
-    if (strMProductUOMID.equals("") && !strChanged.equals("inpquantityorder")) {
-      if (!strQuantityOrder.equals(""))
-        resultado.append(",");
-      resultado.append("new Array(\"inpquantityorder\", \"\")");
-    }
-    if (strQuantityOrder.equals("") && strChanged.equals("inpquantityorder")
-        && !strMProductUOMID.equals("")) {
-      resultado.append("new Array(\"inpmProductUomId\", \"\")");
+    if (StringUtils.isEmpty(strMultiplyRate)) {
+      strMultiplyRate = "1";
+      if (StringUtils.isNotEmpty(strMProductUOMID)) {
+        // Set message when no UOM Conversion exists
+        info.showMessage(FormatUtilities.replaceJS(Utility.messageBD(this, "NoUOMConversion",
+            info.vars.getLanguage())));
+      }
     }
 
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    // Calculate MovementQty based on UOM Conversion
+    if (StringUtils.isNotEmpty(strQuantityOrder)) {
+      BigDecimal multiplyRate = new BigDecimal(strMultiplyRate);
+      BigDecimal quantityOrder = new BigDecimal(strQuantityOrder);
+      BigDecimal movementQty = quantityOrder.multiply(multiplyRate);
+      int stdPrecision = Integer.valueOf(SLInvoiceConversionData.stdPrecision(this, strUOM));
+      if (movementQty.scale() > stdPrecision) {
+        movementQty = movementQty.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
+      }
+      info.addResult("inpmovementqty", movementQty);
+    }
+
+    // Set Quantity Order blank when Product UOM is blank
+    if (!StringUtils.equals(strChanged, "inpquantityorder")
+        && StringUtils.isEmpty(strMProductUOMID)) {
+      info.addResult("inpquantityorder", null);
+    }
+
+    // Set Product UOM blank when Quantity Order is blank
+    if (StringUtils.equals(strChanged, "inpquantityorder") && StringUtils.isEmpty(strQuantityOrder)
+        && StringUtils.isNotEmpty(strMProductUOMID)) {
+      info.addResult("inpmProductUomId", null);
+    }
+
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Internal_Consumption_Product.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Internal_Consumption_Product.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,189 +11,96 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.FieldProvider;
 import org.openbravo.erpCommon.utility.ComboTableData;
 import org.openbravo.erpCommon.utility.Utility;
-import org.openbravo.model.common.plm.AttributeSet;
 import org.openbravo.model.common.plm.Product;
 import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_Internal_Consumption_Product extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_Internal_Consumption_Product extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strProduct = vars.getStringParameter("inpmProductId");
-      // String strLocator = vars.getStringParameter("inpmLocatorId");
-      String strPLocator = vars.getStringParameter("inpmProductId_LOC");
-      String strPAttr = vars.getStringParameter("inpmProductId_ATR");
-      String strPQty = vars.getNumericParameter("inpmProductId_PQTY");
-      String strPUOM = vars.getStringParameter("inpmProductId_PUOM");
-      String strQty = vars.getNumericParameter("inpmProductId_QTY");
-      String strUOM = vars.getStringParameter("inpmProductId_UOM");
-      String strTabId = vars.getStringParameter("inpTabId");
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-      try {
-        printPage(response, vars, strChanged, strProduct, strPLocator, strPAttr, strPQty, strPUOM,
-            strQty, strUOM, strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // Parameters
+    String strProduct = info.getStringParameter("inpmProductId", IsIDFilter.instance);
+    String strPLocator = info.getStringParameter("inpmProductId_LOC", IsIDFilter.instance);
+    String strPAttr = info.getStringParameter("inpmProductId_ATR", IsIDFilter.instance);
+    String strPQty = info.vars.getNumericParameter("inpmProductId_PQTY");
+    String strPUOM = info.getStringParameter("inpmProductId_PUOM", IsIDFilter.instance);
+    String strQty = info.vars.getNumericParameter("inpmProductId_QTY");
+    String strUOM = info.getStringParameter("inpmProductId_UOM", IsIDFilter.instance);
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strChanged,
-      String strProduct, String strPLocator, String strPAttr, String strPQty, String strPUOM,
-      String strQty, String strUOM, String strTabId) throws IOException, ServletException {
-    String localStrPUOM = strPUOM;
-    String localStrPLocator = strPLocator;
-    String localStrPAttr = strPAttr;
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
+    // UOM, Locator
+    info.addResult("inpcUomId", strUOM);
+    info.addResult("inpmLocatorId", strPLocator);
 
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_Internal_Consumption_Product';\n\n");
-    resultado.append("var respuesta = new Array(");
-    resultado.append("new Array(\"inpcUomId\", \"" + strUOM + "\"),\n");
-    if (localStrPLocator.startsWith("\""))
-      localStrPLocator = localStrPLocator.substring(1, localStrPLocator.length() - 1);
-    resultado.append("new Array(\"inpmLocatorId\", \"" + localStrPLocator + "\"),\n");
-    resultado.append("new Array(\"inpmLocatorId_R\", \""
-        + FormatUtilities.replaceJS(SLInternalConsumptionProductData.selectLocator(this,
-            localStrPLocator)) + "\"),\n");
+    // Has Second UOM
     String strHasSecondaryUOM = SLOrderProductData.hasSecondaryUOM(this, strProduct);
-    resultado.append("new Array(\"inphasseconduom\", " + strHasSecondaryUOM + "),\n");
-    if (localStrPAttr.startsWith("\""))
-      localStrPAttr = localStrPAttr.substring(1, localStrPAttr.length() - 1);
-    resultado.append("new Array(\"inpmAttributesetinstanceId\", \"" + localStrPAttr + "\"),\n");
-    resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \""
-        + FormatUtilities.replaceJS(SLInOutLineProductData.attribute(this, localStrPAttr))
-        + "\"),\n");
-    String strAttrSet, strAttrSetValueType;
-    strAttrSet = strAttrSetValueType = "";
+    info.addResult("inphasseconduom", Integer.parseInt(strHasSecondaryUOM));
+
+    // AttributeSetInstance, AttributeSet, AttributeSetValueType
+    info.addResult("inpmAttributesetinstanceId", strPAttr);
     OBContext.setAdminMode();
     try {
       final Product product = OBDal.getInstance().get(Product.class, strProduct);
       if (product != null) {
-        AttributeSet attributeset = product.getAttributeSet();
-        if (attributeset != null)
-          strAttrSet = product.getAttributeSet().toString();
-        strAttrSetValueType = product.getUseAttributeSetValueAs();
+        info.addResult("inpattributeset", product.getAttributeSet() != null ? product
+            .getAttributeSet().getId() : "");
+        info.addResult("inpattrsetvaluetype",
+            FormatUtilities.replaceJS(product.getUseAttributeSetValueAs()));
       }
     } finally {
       OBContext.restorePreviousMode();
     }
-    resultado
-        .append("new Array(\"inpattributeset\", \""
-            + (strAttrSet == null || strAttrSet.equals("") ? "" : FormatUtilities
-                .replaceJS(strAttrSet)) + "\"),\n");
-    resultado.append("new Array(\"inpattrsetvaluetype\", \""
-        + (strAttrSetValueType == null || strAttrSetValueType.equals("") ? "" : FormatUtilities
-            .replaceJS(strAttrSetValueType)) + "\"),\n");
-    resultado.append("new Array(\"inpmovementqty\", " + (strQty.equals("") ? "\"\"" : strQty)
-        + "),\n");
-    resultado.append("new Array(\"inpquantityorder\", " + (strPQty.equals("") ? "\"\"" : strPQty)
-        + "),\n");
-    if (localStrPUOM.startsWith("\""))
-      localStrPUOM = localStrPUOM.substring(1, localStrPUOM.length() - 1);
-    resultado.append("new Array(\"inpmProductUomId\", ");
-    if (vars.getLanguage().equals("en_US")) {
-      FieldProvider[] tld = null;
-      try {
-        ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "",
-            "M_Product_UOM", "", Utility.getContext(this, vars, "#AccessibleOrgTree",
-                "SLInternalConsumptionProduct"), Utility.getContext(this, vars, "#User_Client",
-                "SLInternalConsumptionProduct"), 0);
-        Utility.fillSQLParameters(this, vars, null, comboTableData, "SLInternalConsumptionProduct",
-            "");
-        tld = comboTableData.select(false);
-        comboTableData = null;
-      } catch (Exception ex) {
-        throw new ServletException(ex);
+
+    // MovementQty, Quantity Order
+    info.addResult("inpmovementqty", strQty);
+    info.addResult("inpquantityorder", strPQty);
+
+    // Product UOM List
+    FieldProvider[] tld = null;
+    try {
+      ComboTableData comboTableData = new ComboTableData(info.vars, this, "TABLE", "",
+          "M_Product_UOM", "", Utility.getContext(this, info.vars, "#AccessibleOrgTree",
+              "SLInternalConsumptionProduct"), Utility.getContext(this, info.vars, "#User_Client",
+              "SLInternalConsumptionProduct"), 0);
+      Utility.fillSQLParameters(this, info.vars, null, comboTableData,
+          "SLInternalConsumptionProduct", "");
+      tld = comboTableData.select(false);
+      comboTableData = null;
+    } catch (Exception ex) {
+      throw new ServletException(ex);
+    }
+    if (tld != null && tld.length > 0) {
+      info.addSelect("inpmProductUomId");
+      for (int i = 0; i < tld.length; i++) {
+        info.addSelectResult(tld[i].getField("id"),
+            FormatUtilities.replaceJS(tld[i].getField("name")),
+            StringUtils.equals(tld[i].getField("id"), strPUOM));
       }
+      info.endSelect();
+    } else {
+      info.addResult("inpmProductUomId", null);
+    }
 
-      if (tld != null && tld.length > 0) {
-        resultado.append("new Array(");
-        for (int i = 0; i < tld.length; i++) {
-          resultado.append("new Array(\"" + tld[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \""
-              + ((tld[i].getField("id").equals(localStrPUOM)) ? "true" : "false") + "\")");
-          if (i < tld.length - 1)
-            resultado.append(",\n");
-        }
-        resultado.append("\n)");
-      } else
-        resultado.append("null");
-      resultado.append("\n),");
-    } else {
-      FieldProvider[] tld = null;
-      try {
-        ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "",
-            "M_Product_UOM", "", Utility.getContext(this, vars, "#AccessibleOrgTree",
-                "SLInternalConsumptionProduct"), Utility.getContext(this, vars, "#User_Client",
-                "SLInternalConsumptionProduct"), 0);
-        Utility.fillSQLParameters(this, vars, null, comboTableData, "SLInternalConsumptionProduct",
-            "");
-        tld = comboTableData.select(false);
-        comboTableData = null;
-      } catch (Exception ex) {
-        throw new ServletException(ex);
-      }
-
-      if (tld != null && tld.length > 0) {
-        resultado.append("new Array(");
-        for (int i = 0; i < tld.length; i++) {
-          resultado.append("new Array(\"" + tld[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \""
-              + ((tld[i].getField("id").equals(localStrPUOM)) ? "true" : "false") + "\")");
-          if (i < tld.length - 1)
-            resultado.append(",\n");
-        }
-        resultado.append("\n)");
-      } else
-        resultado.append("null");
-      resultado.append("\n),");
-    }
-    resultado.append("new Array(\"EXECUTE\", \"displayLogic();\")\n");
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Inventory_Conversion.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Inventory_Conversion.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,115 +11,66 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_Inventory_Conversion extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_Inventory_Conversion extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strUOM = vars.getStringParameter("inpcUomId");
-      String strMProductUOMID = vars.getStringParameter("inpmProductUomId");
-      String strQuantityOrder = vars.getNumericParameter("inpquantityorder");
-      String strTabId = vars.getStringParameter("inpTabId");
-
-      try {
-        printPage(response, vars, strUOM, strMProductUOMID, strQuantityOrder, strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strUOM,
-      String strMProductUOMID, String strQuantityOrder, String strTabId) throws IOException,
-      ServletException {
-    String localStrUOM = strUOM;
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    if (localStrUOM.startsWith("\""))
-      localStrUOM = localStrUOM.substring(1, localStrUOM.length() - 1);
-    int stdPrecision = Integer.valueOf(SLInvoiceConversionData.stdPrecision(this, localStrUOM))
-        .intValue();
-    String strInitUOM = SLInvoiceConversionData.initUOMId(this, strMProductUOMID);
-    String strMultiplyRate;
-    boolean check = false;
-
-    strMultiplyRate = SLInvoiceConversionData.multiplyRate(this, strInitUOM, localStrUOM);
-    if (strInitUOM.equals(localStrUOM))
-      strMultiplyRate = "1";
-    if (strMultiplyRate.equals(""))
-      strMultiplyRate = SLInvoiceConversionData.divideRate(this, localStrUOM, strInitUOM);
-    if (strMultiplyRate.equals("")) {
-      strMultiplyRate = "1";
-      if (!strMProductUOMID.equals(""))
-        check = true;
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
     }
 
-    BigDecimal quantityOrder, qtyOrdered, multiplyRate;
+    // Parameters
+    String strUOM = info.getStringParameter("inpcUomId", IsIDFilter.instance);
+    String strMProductUOMID = info.getStringParameter("inpmProductUomId", IsIDFilter.instance);
+    String strQuantityOrder = info.vars.getNumericParameter("inpquantityorder");
 
-    multiplyRate = new BigDecimal(strMultiplyRate);
+    // Multiply Rate for UOM Conversion if any
+    String strInitUOM = SLInvoiceConversionData.initUOMId(this, strMProductUOMID);
+    String strMultiplyRate = StringUtils.equals(strInitUOM, strUOM) ? "1" : "";
+    if (StringUtils.isEmpty(strMultiplyRate)) {
+      strMultiplyRate = SLInvoiceConversionData.multiplyRate(this, strInitUOM, strUOM);
+    }
+    if (StringUtils.isEmpty(strMultiplyRate)) {
+      strMultiplyRate = SLInvoiceConversionData.divideRate(this, strUOM, strInitUOM);
+    }
+    if (StringUtils.isEmpty(strMultiplyRate)) {
+      strMultiplyRate = "1";
 
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_Inventory_Conversion';\n\n");
-    if (strMultiplyRate.equals("0")) {
-      resultado.append("var respuesta = null");
-    } else {
-      resultado.append("var respuesta = new Array(");
-      if (!strQuantityOrder.equals("")) {
-        quantityOrder = new BigDecimal(strQuantityOrder);
-        qtyOrdered = quantityOrder.multiply(multiplyRate);
-        if (qtyOrdered.scale() > stdPrecision)
-          qtyOrdered = qtyOrdered.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
-        resultado.append("new Array(\"inpqtycount\", " + qtyOrdered.toString() + ")");
+      // Set message when no UOM Conversion exists
+      if (StringUtils.isNotEmpty(strMProductUOMID)) {
+        info.showMessage(FormatUtilities.replaceJS(Utility.messageBD(this, "NoUOMConversion",
+            info.vars.getLanguage())));
       }
-      if (check) {
-        if (!strQuantityOrder.equals(""))
-          resultado.append(",");
-        resultado.append("new Array('MESSAGE', \""
-            + FormatUtilities.replaceJS(Utility.messageBD(this, "NoUOMConversion",
-                vars.getLanguage())) + "\")");
+    }
+
+    // Calculate Quantity Count based on UOM Conversion
+    if (StringUtils.isNotEmpty(strQuantityOrder)) {
+      BigDecimal multiplyRate = new BigDecimal(strMultiplyRate);
+      BigDecimal quantityOrder = new BigDecimal(strQuantityOrder);
+      BigDecimal movementQty = quantityOrder.multiply(multiplyRate);
+      int stdPrecision = Integer.valueOf(SLInvoiceConversionData.stdPrecision(this, strUOM));
+      if (movementQty.scale() > stdPrecision) {
+        movementQty = movementQty.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
       }
-      resultado.append(");");
+      info.addResult("inpqtycount", movementQty);
     }
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Inventory_Locator.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Inventory_Locator.java	Fri Aug 04 19:25:27 2017 -0400
@@ -53,8 +53,6 @@
       info.addResult("inpquantityorderbook", qtyOrder);
       info.addResult("inpqtycount", qty);
       info.addResult("inpqtybook", qty);
-
-      info.addResult("EXECUTE", "displayLogic();");
     }
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Inventory_Product.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Inventory_Product.java	Fri Aug 04 19:25:27 2017 -0400
@@ -139,9 +139,5 @@
       info.addResult("inpmProductUomId", null);
     }
 
-    // displaylogic
-
-    info.addResult("EXECUTE", "displayLogic();");
-
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_InvoiceTax_Amt.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_InvoiceTax_Amt.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,108 +11,51 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.xmlEngine.XmlDocument;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 
-public class SL_InvoiceTax_Amt extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_InvoiceTax_Amt extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strTaxAmt = vars.getNumericParameter("inptaxamt");
-      String strTaxBaseAmt = vars.getNumericParameter("inptaxbaseamt");
-      String strTaxId = vars.getStringParameter("inpcTaxId");
-      String strInvoiceId = vars.getStringParameter("inpcInvoiceId");
+    String fieldChanged = info.getLastFieldChanged();
+    log4j.debug("CHANGED: " + fieldChanged);
 
-      try {
-        printPage(response, vars, strChanged, strTaxAmt, strTaxBaseAmt, strTaxId, strInvoiceId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // Parameters
+    String taxId = info.getStringParameter("inpcTaxId", IsIDFilter.instance);
+    String invoiceId = info.getStringParameter("inpcInvoiceId", IsIDFilter.instance);
+    BigDecimal taxAmt = info.getBigDecimalParameter("inptaxamt");
+    BigDecimal taxBaseAmt = info.getBigDecimalParameter("inptaxbaseamt");
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strChanged,
-      String strTaxAmt, String strTaxBaseAmt, String strTaxId, String strInvoiceId)
-      throws IOException, ServletException {
-    String localStrTaxId = strTaxId;
-    String localStrTaxBaseAmt = strTaxBaseAmt;
-    String localStrTaxAmt = strTaxAmt;
-    String localStrInvoiceId = strInvoiceId;
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
+    // Update Tax Amount and Tax Base Amount
+    SLInvoiceTaxAmtData[] data = SLInvoiceTaxAmtData.select(this, taxId, invoiceId);
+    BigDecimal taxRate = StringUtils.isEmpty(data[0].rate) ? BigDecimal.ONE : new BigDecimal(
+        data[0].rate);
+    Integer taxScale = Integer.valueOf(data[0].priceprecision);
 
-    StringBuffer resultado = new StringBuffer();
-
-    // Discount...
-    if (localStrTaxAmt.startsWith("\""))
-      localStrTaxAmt = localStrTaxAmt.substring(1, localStrTaxAmt.length() - 1);
-    if (localStrTaxBaseAmt.startsWith("\""))
-      localStrTaxBaseAmt = localStrTaxBaseAmt.substring(1, localStrTaxBaseAmt.length() - 1);
-    if (localStrTaxId.startsWith("\""))
-      localStrTaxId = localStrTaxId.substring(1, localStrTaxId.length() - 1);
-    if (localStrInvoiceId.startsWith("\""))
-      localStrInvoiceId = localStrInvoiceId.substring(1, localStrTaxId.length() - 1);
-
-    SLInvoiceTaxAmtData[] data = SLInvoiceTaxAmtData.select(this, localStrTaxId, localStrInvoiceId);
-
-    BigDecimal taxAmt = (localStrTaxAmt.equals("") ? new BigDecimal(0.0) : new BigDecimal(
-        localStrTaxAmt));
-    BigDecimal taxBaseAmt = (localStrTaxBaseAmt.equals("") ? new BigDecimal(0.0) : new BigDecimal(
-        localStrTaxBaseAmt));
-    BigDecimal taxRate = (data[0].rate.equals("") ? new BigDecimal(1)
-        : new BigDecimal(data[0].rate));
-    Integer taxScale = new Integer(data[0].priceprecision);
-
-    if (strChanged.equals("inptaxamt")) {
-      if (taxRate.compareTo(BigDecimal.ZERO) != 0)
+    if (StringUtils.equals(fieldChanged, "inptaxamt")) {
+      if (taxRate.compareTo(BigDecimal.ZERO) != 0) {
         taxBaseAmt = ((taxAmt.divide(taxRate, 12, BigDecimal.ROUND_HALF_EVEN))
             .multiply(new BigDecimal("100"))).setScale(taxScale, BigDecimal.ROUND_HALF_UP);
+      }
     } else {
       taxAmt = ((taxBaseAmt.multiply(taxRate)).divide(new BigDecimal("100"), 12,
           BigDecimal.ROUND_HALF_EVEN)).setScale(taxScale, BigDecimal.ROUND_HALF_UP);
     }
 
-    resultado.append("var calloutName='SL_InvoiceTax_Amt';\n\n");
-    resultado.append("var respuesta = new Array(");
-    resultado.append("new Array(\"inptaxamt\", " + taxAmt.toPlainString() + "),");
-    resultado.append("new Array(\"inptaxbaseamt\", " + taxBaseAmt.toPlainString() + "));");
-
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    info.addResult("inptaxamt", taxAmt);
+    info.addResult("inptaxbaseamt", taxBaseAmt);
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Amt.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Amt.java	Fri Aug 04 19:25:27 2017 -0400
@@ -18,19 +18,13 @@
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.text.DecimalFormat;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.businessUtility.PriceAdjustment;
 import org.openbravo.erpCommon.utility.Utility;
@@ -38,202 +32,160 @@
 import org.openbravo.model.common.invoice.Invoice;
 import org.openbravo.model.common.plm.Product;
 import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_Invoice_Amt extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_Invoice_Amt extends SimpleCallout {
 
-  private static final BigDecimal ZERO = new BigDecimal(0.0);
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strQtyInvoice = vars.getNumericParameter("inpqtyinvoiced");
-      String strPriceActual = vars.getNumericParameter("inppriceactual");
-      String strPriceLimit = vars.getNumericParameter("inppricelimit");
-      String strInvoiceId = vars.getStringParameter("inpcInvoiceId");
-      String strProduct = vars.getStringParameter("inpmProductId");
-      String strTabId = vars.getStringParameter("inpTabId");
-      String strPriceList = vars.getNumericParameter("inppricelist");
-      String strPriceStd = vars.getNumericParameter("inppricestd");
-      String strLineNetAmt = vars.getNumericParameter("inplinenetamt");
-      String strTaxId = vars.getStringParameter("inpcTaxId");
-      String strGrossUnitPrice = vars.getNumericParameter("inpgrossUnitPrice");
-      String strBaseGrossUnitPrice = vars.getNumericParameter("inpgrosspricestd");
-      String strtaxbaseamt = vars.getNumericParameter("inptaxbaseamt");
-      String strInvoicelineId = vars.getStringParameter("inpcInvoicelineId");
+    // Parameters
+    BigDecimal qtyInvoice = info.getBigDecimalParameter("inpqtyinvoiced");
+    BigDecimal priceActual = info.getBigDecimalParameter("inppriceactual");
+    BigDecimal priceLimit = info.getBigDecimalParameter("inppricelimit");
+    String strInvoiceId = info.getStringParameter("inpcInvoiceId", IsIDFilter.instance);
+    String strProduct = info.getStringParameter("inpmProductId", IsIDFilter.instance);
+    BigDecimal priceList = info.getBigDecimalParameter("inppricelist");
+    BigDecimal priceStd = info.getBigDecimalParameter("inppricestd");
+    BigDecimal lineNetAmt = info.getBigDecimalParameter("inplinenetamt");
+    String strTaxId = info.getStringParameter("inpcTaxId", IsIDFilter.instance);
+    BigDecimal grossUnitPrice = info.getBigDecimalParameter("inpgrossUnitPrice");
+    BigDecimal baseGrossUnitPrice = info.getBigDecimalParameter("inpgrosspricestd");
+    BigDecimal taxBaseAmt = info.getBigDecimalParameter("inptaxbaseamt");
+    String strInvoicelineId = info.getStringParameter("inpcInvoicelineId", IsIDFilter.instance);
 
-      try {
-        printPage(response, vars, strChanged, strQtyInvoice, strPriceActual, strInvoiceId,
-            strProduct, strPriceLimit, strTabId, strPriceList, strPriceStd, strLineNetAmt,
-            strTaxId, strGrossUnitPrice, strBaseGrossUnitPrice, strtaxbaseamt, strInvoicelineId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  void printPage(HttpServletResponse response, VariablesSecureApp vars, String strChanged,
-      String strQtyInvoice, String strPriceActual, String strInvoiceId, String strProduct,
-      String strPriceLimit, String strTabId, String strPriceList, String strPriceStd,
-      String strLineNetAmt, String strTaxId, String strGrossUnitPrice,
-      String strBaseGrossUnitPrice, String strTaxBaseAmt, String strInvoicelineId)
-      throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
+    // Standard Precision and Price Precision
     SLInvoiceAmtData[] data = SLInvoiceAmtData.select(this, strInvoiceId);
     String strPrecision = "0", strPricePrecision = "0";
     boolean enforcedLimit = false;
+    if (data != null && data.length > 0) {
+      strPrecision = StringUtils.isEmpty(data[0].stdprecision) ? "0" : data[0].stdprecision;
+      strPricePrecision = StringUtils.isEmpty(data[0].priceprecision) ? "0"
+          : data[0].priceprecision;
+      enforcedLimit = StringUtils.equals(data[0].enforcepricelimit, "Y");
+    }
+    int stdPrecision = Integer.valueOf(strPrecision).intValue();
+    int pricePrecision = Integer.valueOf(strPricePrecision).intValue();
 
-    if (data != null && data.length > 0) {
-      strPrecision = data[0].stdprecision.equals("") ? "0" : data[0].stdprecision;
-      strPricePrecision = data[0].priceprecision.equals("") ? "0" : data[0].priceprecision;
-      enforcedLimit = (data[0].enforcepricelimit.equals("Y") ? true : false);
-    }
-    int StdPrecision = Integer.valueOf(strPrecision).intValue();
-    int PricePrecision = Integer.valueOf(strPricePrecision).intValue();
-
+    // Tax Rate and Tax Precision
     SLInvoiceTaxAmtData[] dataTax = SLInvoiceTaxAmtData.select(this, strTaxId, strInvoiceId);
     BigDecimal taxRate = BigDecimal.ZERO;
-    Integer taxScale = new Integer(0);
-    if (dataTax.length > 0) {
-      taxRate = (dataTax[0].rate.equals("") ? new BigDecimal(1) : new BigDecimal(dataTax[0].rate));
+    int taxScale = 0;
+    if (dataTax != null && dataTax.length > 0) {
+      taxRate = StringUtils.isEmpty(dataTax[0].rate) ? BigDecimal.ONE : new BigDecimal(
+          dataTax[0].rate);
       taxScale = new Integer(dataTax[0].priceprecision);
     }
-    if (log4j.isDebugEnabled())
-      log4j.debug("strPriceActual: " + strPriceActual);
-    if (log4j.isDebugEnabled())
-      log4j.debug("strPriceLimit: " + strPriceLimit);
-    if (log4j.isDebugEnabled())
-      log4j.debug("strLineNetAmt: " + strLineNetAmt);
-    if (log4j.isDebugEnabled())
-      log4j.debug("taxRate: " + taxRate);
 
-    BigDecimal qtyInvoice, priceActual, lineNetAmt, priceLimit, priceStd, taxBaseAmt;
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("PriceActual: " + priceActual);
+      log4j.debug("PriceLimit: " + priceLimit);
+      log4j.debug("LineNetAmt: " + lineNetAmt);
+      log4j.debug("TaxRate: " + taxRate);
+    }
 
-    qtyInvoice = (!Utility.isBigDecimal(strQtyInvoice) ? ZERO : new BigDecimal(strQtyInvoice));
-    priceStd = (!Utility.isBigDecimal(strPriceStd) ? ZERO : new BigDecimal(strPriceStd));
-    priceActual = (!Utility.isBigDecimal(strPriceActual) ? ZERO : (new BigDecimal(strPriceActual)))
-        .setScale(PricePrecision, BigDecimal.ROUND_HALF_UP);
-    priceLimit = (!Utility.isBigDecimal(strPriceLimit) ? ZERO : (new BigDecimal(strPriceLimit)))
-        .setScale(PricePrecision, BigDecimal.ROUND_HALF_UP);
-    lineNetAmt = (!Utility.isBigDecimal(strLineNetAmt) ? ZERO : new BigDecimal(strLineNetAmt));
-    taxBaseAmt = (strTaxBaseAmt.equals("") ? ZERO : (new BigDecimal(strTaxBaseAmt))).setScale(
-        PricePrecision, BigDecimal.ROUND_HALF_UP);
+    priceActual = priceActual.setScale(pricePrecision, BigDecimal.ROUND_HALF_UP);
+    priceLimit = priceLimit.setScale(pricePrecision, BigDecimal.ROUND_HALF_UP);
+    taxBaseAmt = taxBaseAmt.setScale(pricePrecision, BigDecimal.ROUND_HALF_UP);
+
+    // Show warning if Invoiced Qty is higher than Delivered Qty
+    SLInvoiceAmtData[] qtydata = SLInvoiceAmtData.selectDeliverQty(this, strInvoicelineId);
+    if (qtydata != null && qtydata.length > 0
+        && qtyInvoice.compareTo(new BigDecimal(qtydata[0].deliverqty)) > 0
+        && StringUtils.equals(qtydata[0].invoicerule, "D")) {
+      String msg = Utility.messageBD(this, "QtyInvoicedHigherDelivered", info.vars.getLanguage());
+      info.showWarning(msg);
+    }
+
+    // Calculate Price Actual if Line Net Amount is edited
+    if (StringUtils.equals(strChanged, "inplinenetamt")) {
+      if (qtyInvoice.compareTo(BigDecimal.ZERO) == 0) {
+        priceActual = BigDecimal.ZERO;
+      } else {
+        priceActual = lineNetAmt.divide(qtyInvoice, pricePrecision, BigDecimal.ROUND_HALF_UP);
+      }
+    }
+    if (priceActual.compareTo(BigDecimal.ZERO) == 0) {
+      lineNetAmt = BigDecimal.ZERO;
+    }
 
     Invoice invoice = OBDal.getInstance().get(Invoice.class, strInvoiceId);
     Product product = OBDal.getInstance().get(Product.class, strProduct);
     boolean priceIncludeTaxes = invoice.getPriceList().isPriceIncludesTax();
 
-    StringBuffer resultado = new StringBuffer();
-
-    resultado.append("var calloutName='SL_Invoice_Amt';\n\n");
-    resultado.append("var respuesta = new Array(");
-
-    SLInvoiceAmtData[] qtydata = SLInvoiceAmtData.selectDeliverQty(this, strInvoicelineId);
-
-    if (qtydata != null && qtydata.length > 0) {
-      if ((new BigDecimal(strQtyInvoice).compareTo(new BigDecimal(qtydata[0].deliverqty)) > 0)
-          && qtydata[0].invoicerule.equals("D")) {
-        StringBuffer strMessage = new StringBuffer(Utility.messageBD(this,
-            "QtyInvoicedHigherDelivered", vars.getLanguage()));
-        resultado.append("new Array('WARNING', \"" + strMessage.toString() + "\"),");
-      }
-    }
-
-    if (strChanged.equals("inplinenetamt")) {
-      if (qtyInvoice.compareTo(BigDecimal.ZERO) == 0) {
-        priceActual = BigDecimal.ZERO;
-      } else {
-        priceActual = lineNetAmt.divide(qtyInvoice, PricePrecision, BigDecimal.ROUND_HALF_UP);
-      }
-    }
-    if (priceActual.compareTo(BigDecimal.ZERO) == 0) {
-      lineNetAmt = BigDecimal.ZERO;
-    }
     // If unit price (actual price) changes, recalculates standard price
     // (std price) applying price adjustments (offers) if any
-    if (strChanged.equals("inppriceactual") || strChanged.equals("inplinenetamt")) {
-      if (log4j.isDebugEnabled())
+    if (StringUtils.equals(strChanged, "inppriceactual")
+        || StringUtils.equals(strChanged, "inplinenetamt")) {
+      if (log4j.isDebugEnabled()) {
         log4j.debug("priceActual:" + Double.toString(priceActual.doubleValue()));
-
+      }
       priceStd = PriceAdjustment.calculatePriceStd(invoice, product, qtyInvoice, priceActual);
-      resultado.append("new Array(\"inppricestd\", " + priceStd.toString() + "),");
-      resultado.append("new Array(\"inptaxbaseamt\", " + priceActual.multiply(qtyInvoice) + "),");
+      info.addResult("inppricestd", priceStd);
+      info.addResult("inptaxbaseamt", priceActual.multiply(qtyInvoice));
     }
 
     // If quantity changes, recalculates unit price (actual price) applying
     // price adjustments (offers) if any
-    if (strChanged.equals("inpqtyinvoiced")) {
-      if (log4j.isDebugEnabled())
-        log4j.debug("strPriceList: " + strPriceList.replace("\"", "") + " product:" + strProduct
-            + " qty:" + qtyInvoice.toString());
-
+    if (StringUtils.equals(strChanged, "inpqtyinvoiced")) {
+      if (log4j.isDebugEnabled()) {
+        log4j.debug("PriceList: " + priceList + " product:" + strProduct + " qty:"
+            + qtyInvoice.toString());
+      }
       if (priceIncludeTaxes) {
-        BigDecimal baseGrossUnitPrice = new BigDecimal(strBaseGrossUnitPrice.trim());
-        BigDecimal grossUnitPrice = PriceAdjustment.calculatePriceActual(invoice, product,
-            qtyInvoice, baseGrossUnitPrice);
-        BigDecimal grossAmount = grossUnitPrice.multiply(new BigDecimal(strQtyInvoice.trim()));
+        grossUnitPrice = PriceAdjustment.calculatePriceActual(invoice, product, qtyInvoice,
+            baseGrossUnitPrice);
+        BigDecimal grossAmount = grossUnitPrice.multiply(qtyInvoice);
         BigDecimal netAmount = FinancialUtils.calculateNetAmtFromGross(strTaxId, grossAmount,
-            StdPrecision, taxBaseAmt);
+            stdPrecision, taxBaseAmt);
         priceActual = BigDecimal.ZERO;
         if (qtyInvoice.compareTo(BigDecimal.ZERO) != 0) {
-          priceActual = netAmount.divide(qtyInvoice, PricePrecision, RoundingMode.HALF_UP);
+          priceActual = netAmount.divide(qtyInvoice, pricePrecision, RoundingMode.HALF_UP);
         }
-        resultado.append("new Array(\"inpgrossUnitPrice\", " + grossUnitPrice.toString() + "),");
-        resultado.append("new Array(\"inplineGrossAmount\", " + grossAmount.toString() + "),");
+        info.addResult("inpgrossUnitPrice", grossUnitPrice);
+        info.addResult("inplineGrossAmount", grossAmount);
       } else {
         priceActual = PriceAdjustment.calculatePriceActual(invoice, product, qtyInvoice, priceStd);
       }
     }
-    // if taxRate field is changed
-    if (strChanged.equals("inpgrossUnitPrice")
-        || (strChanged.equals("inpcTaxId") && priceIncludeTaxes)) {
-      BigDecimal grossUnitPrice = new BigDecimal(strGrossUnitPrice.trim());
-      BigDecimal baseGrossUnitPrice = PriceAdjustment.calculatePriceStd(invoice, product,
-          qtyInvoice, grossUnitPrice);
+
+    // If Gross Unit Price or Tax field is changed when price Includes Tax = Yes
+    if (StringUtils.equals(strChanged, "inpgrossUnitPrice")
+        || StringUtils.equals(strChanged, "inpcTaxId") && priceIncludeTaxes) {
+      baseGrossUnitPrice = PriceAdjustment.calculatePriceStd(invoice, product, qtyInvoice,
+          grossUnitPrice);
       BigDecimal grossAmount = grossUnitPrice.multiply(qtyInvoice);
       BigDecimal netAmount = FinancialUtils.calculateNetAmtFromGross(strTaxId, grossAmount,
-          StdPrecision, taxBaseAmt);
+          stdPrecision, taxBaseAmt);
       BigDecimal netUnitPrice = BigDecimal.ZERO;
       if (qtyInvoice.compareTo(BigDecimal.ZERO) != 0) {
-        netUnitPrice = netAmount.divide(qtyInvoice, PricePrecision, RoundingMode.HALF_UP);
+        netUnitPrice = netAmount.divide(qtyInvoice, pricePrecision, RoundingMode.HALF_UP);
       }
       priceActual = netUnitPrice;
       priceStd = netUnitPrice;
 
-      resultado.append("new Array(\"inpgrosspricestd\", " + baseGrossUnitPrice.toString() + "),");
+      info.addResult("inpgrosspricestd", baseGrossUnitPrice);
+      info.addResult("inppriceactual", netUnitPrice);
+      info.addResult("inppricelimit", netUnitPrice);
+      info.addResult("inppricestd", netUnitPrice);
 
-      resultado.append("new Array(\"inppriceactual\"," + netUnitPrice.toString() + "),");
-      resultado.append("new Array(\"inppricelimit\", " + netUnitPrice.toString() + "),");
-      resultado.append("new Array(\"inppricestd\", " + netUnitPrice.toString() + "),");
-
-      // if taxinclusive field is changed then modify net unit price and gross price
-      if (strChanged.equals("inpgrossUnitPrice")) {
-        resultado.append("new Array(\"inplineGrossAmount\"," + grossAmount.toString() + "),");
+      // If Gross Unit Price field is changed then modify Line Gross Amount
+      if (StringUtils.equals(strChanged, "inpgrossUnitPrice")) {
+        info.addResult("inplineGrossAmount", grossAmount);
       }
     }
 
-    if (!strChanged.equals("inplinenetamt")) {
+    if (!StringUtils.equals(strChanged, "inplinenetamt")) {
       if (priceIncludeTaxes) {
         // In price including taxes we get the net amount from the gross amount
-        BigDecimal baseGrossUnitPrice = new BigDecimal(strBaseGrossUnitPrice.trim());
-        BigDecimal grossUnitPrice = PriceAdjustment.calculatePriceActual(invoice, product,
-            qtyInvoice, baseGrossUnitPrice);
-        BigDecimal grossAmount = grossUnitPrice.multiply(new BigDecimal(strQtyInvoice.trim()));
-        lineNetAmt = FinancialUtils.calculateNetAmtFromGross(strTaxId, grossAmount, StdPrecision,
+        grossUnitPrice = PriceAdjustment.calculatePriceActual(invoice, product, qtyInvoice,
+            baseGrossUnitPrice);
+        BigDecimal grossAmount = grossUnitPrice.multiply(qtyInvoice);
+        lineNetAmt = FinancialUtils.calculateNetAmtFromGross(strTaxId, grossAmount, stdPrecision,
             taxBaseAmt);
       } else {
         // Net amount of a line equals quantity x unit price (actual price)
@@ -241,53 +193,54 @@
       }
     }
 
-    if (strChanged.equals("inplinenetamt")) {
-      DecimalFormat priceEditionFmt = Utility.getFormat(vars, "priceEdition");
-      DecimalFormat euroEditionFmt = Utility.getFormat(vars, "euroEdition");
-      BigDecimal CalculatedLineNetAmt = qtyInvoice
-          .multiply(
-              priceActual.setScale(priceEditionFmt.getMaximumFractionDigits(),
-                  BigDecimal.ROUND_HALF_UP)).setScale(euroEditionFmt.getMaximumFractionDigits(),
-              BigDecimal.ROUND_HALF_UP);
-      if (!lineNetAmt
-          .setScale(priceEditionFmt.getMaximumFractionDigits(), BigDecimal.ROUND_HALF_UP).equals(
-              CalculatedLineNetAmt)) {
+    // If edited Line Net Amount is not equals calculated Line Net Amount show informative
+    // message to consider setting calculated Line Net Amount
+    if (StringUtils.equals(strChanged, "inplinenetamt")) {
+      int priceEditionScale = Utility.getFormat(info.vars, "priceEdition")
+          .getMaximumFractionDigits();
+      int euroEditionScale = Utility.getFormat(info.vars, "euroEdition").getMaximumFractionDigits();
+
+      BigDecimal calculatedLineNetAmt = qtyInvoice.multiply(
+          priceActual.setScale(priceEditionScale, BigDecimal.ROUND_HALF_UP)).setScale(
+          euroEditionScale, BigDecimal.ROUND_HALF_UP);
+      if (!lineNetAmt.setScale(priceEditionScale, BigDecimal.ROUND_HALF_UP).equals(
+          calculatedLineNetAmt)) {
         StringBuffer strMessage = new StringBuffer(Utility.messageBD(this,
-            "NotCorrectAmountProvided", vars.getLanguage()));
+            "NotCorrectAmountProvided", info.vars.getLanguage()));
         strMessage.append(": ");
-        strMessage.append((strLineNetAmt.equals("") ? BigDecimal.ZERO : new BigDecimal(
-            strLineNetAmt)));
+        strMessage.append(lineNetAmt);
         strMessage.append(". ");
-        strMessage.append(Utility.messageBD(this, "CosiderUsing", vars.getLanguage()));
-        strMessage.append(" " + CalculatedLineNetAmt);
-        resultado.append("new Array('MESSAGE', \"" + strMessage.toString() + "\"),");
+        strMessage.append(Utility.messageBD(this, "CosiderUsing", info.vars.getLanguage()));
+        strMessage.append(" " + calculatedLineNetAmt);
+        info.showMessage(strMessage.toString());
       }
     }
 
-    if (lineNetAmt.scale() > StdPrecision)
-      lineNetAmt = lineNetAmt.setScale(StdPrecision, BigDecimal.ROUND_HALF_UP);
+    // Apply Price Precision to Line Net Amount
+    if (lineNetAmt.scale() > stdPrecision) {
+      lineNetAmt = lineNetAmt.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
+    }
 
     // Check price limit
     if (enforcedLimit) {
       if (priceLimit.compareTo(BigDecimal.ZERO) != 0 && priceActual.compareTo(priceLimit) < 0)
-        resultado.append("new Array('MESSAGE', \""
-            + FormatUtilities.replaceJS(Utility.messageBD(this, "UnderLimitPrice",
-                vars.getLanguage())) + "\"), ");
+        info.showMessage(FormatUtilities.replaceJS(Utility.messageBD(this, "UnderLimitPrice",
+            info.vars.getLanguage())));
     }
+
+    // Calculate Tax Amount
     BigDecimal taxAmt = ((lineNetAmt.multiply(taxRate)).divide(new BigDecimal("100"), 12,
         BigDecimal.ROUND_HALF_EVEN)).setScale(taxScale, BigDecimal.ROUND_HALF_UP);
 
-    if (!strChanged.equals("inplinenetamt") || lineNetAmt.compareTo(BigDecimal.ZERO) == 0)
-      resultado.append("new Array(\"inplinenetamt\", " + lineNetAmt.toString() + "),");
-    resultado.append("new Array(\"inptaxbaseamt\", " + lineNetAmt.toString() + "),");
-    resultado.append("new Array(\"inptaxamt\", " + taxAmt.toPlainString() + "),");
-    resultado.append("new Array(\"inppriceactual\", " + priceActual.toString() + ")");
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    // Set Line Net Amount
+    if (!StringUtils.equals(strChanged, "inplinenetamt")
+        || lineNetAmt.compareTo(BigDecimal.ZERO) == 0) {
+      info.addResult("inplinenetamt", lineNetAmt);
+    }
+
+    // Set TaxbaseAmt, Tax Amount, Price Actual
+    info.addResult("inptaxbaseamt", lineNetAmt);
+    info.addResult("inptaxamt", taxAmt);
+    info.addResult("inppriceactual", priceActual);
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Charge_Tax.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Charge_Tax.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -19,87 +19,49 @@
 package org.openbravo.erpCommon.ad_callouts;
 
 import java.io.IOException;
-import java.io.PrintWriter;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.erpCommon.businessUtility.Tax;
 import org.openbravo.erpCommon.utility.Utility;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_Invoice_Charge_Tax extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_Invoice_Charge_Tax extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strMProductID = vars.getStringParameter("inpmProductId");
-      String strADOrgID = vars.getStringParameter("inpadOrgId");
-      String strCInvoiceID = vars.getStringParameter("inpcInvoiceId");
-      String strWindowId = vars.getStringParameter("inpwindowId");
-      String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
-      String strWharehouse = Utility.getContext(this, vars, "#M_Warehouse_ID", strWindowId);
-      String strCChargeID = vars.getStringParameter("inpcChargeId");
-      String strTabId = vars.getStringParameter("inpTabId");
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
+    // Parameters
+    String strMProductID = info.getStringParameter("inpmProductId", IsIDFilter.instance);
+    String strADOrgID = info.getStringParameter("inpadOrgId", IsIDFilter.instance);
+    String strCInvoiceID = info.getStringParameter("inpcInvoiceId", IsIDFilter.instance);
+    String strIsSOTrx = Utility.getContext(this, info.vars, "isSOTrx", info.getWindowId());
+    String strWarehouse = Utility
+        .getContext(this, info.vars, "#M_Warehouse_ID", info.getWindowId());
+    String strCChargeID = info.getStringParameter("inpcChargeId", IsIDFilter.instance);
+
+    // Tax
+    SLInvoiceTaxData[] data = SLInvoiceTaxData.select(this, strCInvoiceID);
+    if (data != null && data.length > 0) {
       try {
-        printPage(response, vars, strMProductID, strADOrgID, strCInvoiceID, strIsSOTrx,
-            strWharehouse, strCChargeID, strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
+        String strCTaxID = Tax.get(this, strMProductID, data[0].dateinvoiced, strADOrgID,
+            strWarehouse, data[0].cBpartnerLocationId, data[0].cBpartnerLocationId,
+            data[0].cProjectId, StringUtils.equals(strIsSOTrx, "Y"));
+        info.addResult("inpcTaxId", strCTaxID);
+      } catch (IOException e) {
+        log4j.error(e.getMessage());
       }
-    } else
-      pageError(response);
-  }
+    }
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars,
-      String strMProductID, String strADOrgID, String strCInvoiceID, String strIsSOTrx,
-      String strWharehouse, String strCChargeID, String strTabId) throws IOException,
-      ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
-    String chargeAmt;
-    if (strCChargeID.equals(""))
-      chargeAmt = "0";
-    else
-      chargeAmt = SLChargeData.chargeAmt(this, strCChargeID);
-
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_Invoice_Charge_Tax';\n\n");
-    resultado.append("var respuesta = new Array(");
-
-    SLInvoiceTaxData[] data = SLInvoiceTaxData.select(this, strCInvoiceID);
-
-    String strCTaxID = Tax.get(this, strMProductID, data[0].dateinvoiced, strADOrgID,
-        strWharehouse, data[0].cBpartnerLocationId, data[0].cBpartnerLocationId,
-        data[0].cProjectId, strIsSOTrx.equals("Y"));
-
-    resultado.append("new Array(\"inpcTaxId\", \"" + strCTaxID + "\"),");
-    resultado.append("new Array(\"inpchargeamt\", " + chargeAmt + ")\n");
-
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    // Charge Amount
+    String chargeAmt = StringUtils.isEmpty(strCChargeID) ? "0" : SLChargeData.chargeAmt(this,
+        strCChargeID);
+    info.addResult("inpchargeamt", chargeAmt);
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Conversion.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Conversion.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,112 +11,67 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_Invoice_Conversion extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_Invoice_Conversion extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strUOM = vars.getStringParameter("inpcUomId");
-      String strMProductUOMID = vars.getStringParameter("inpmProductUomId");
-      String strQuantityOrder = vars.getNumericParameter("inpquantityorder");
-      String strTabId = vars.getStringParameter("inpTabId");
-
-      try {
-        printPage(response, vars, strUOM, strMProductUOMID, strQuantityOrder, strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strUOM,
-      String strMProductUOMID, String strQuantityOrder, String strTabId) throws IOException,
-      ServletException {
-    String localStrUOM = strUOM;
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    if (localStrUOM.startsWith("\""))
-      localStrUOM = localStrUOM.substring(1, localStrUOM.length() - 1);
-    int stdPrecision = Integer.valueOf(SLInvoiceConversionData.stdPrecision(this, localStrUOM))
-        .intValue();
-    String strInitUOM = SLInvoiceConversionData.initUOMId(this, strMProductUOMID);
-    String strMultiplyRate;
-    boolean check = false;
-
-    strMultiplyRate = SLInvoiceConversionData.multiplyRate(this, strInitUOM, localStrUOM);
-    if (strInitUOM.equals(localStrUOM))
-      strMultiplyRate = "1";
-    if (strMultiplyRate.equals(""))
-      strMultiplyRate = SLInvoiceConversionData.divideRate(this, localStrUOM, strInitUOM);
-    if (strMultiplyRate.equals("")) {
-      strMultiplyRate = "1";
-      if (!strMProductUOMID.equals(""))
-        check = true;
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
     }
 
-    BigDecimal quantityOrder, qtyInvoiced, multiplyRate;
+    // Parameters
+    String strUOM = info.getStringParameter("inpcUomId", IsIDFilter.instance);
+    String strMProductUOMID = info.getStringParameter("inpmProductUomId", IsIDFilter.instance);
+    String strQuantityOrder = info.vars.getNumericParameter("inpquantityorder");
 
-    multiplyRate = new BigDecimal(strMultiplyRate);
+    // Multiple Rate for UOM Conversion if any
+    String strInitUOM = SLInvoiceConversionData.initUOMId(this, strMProductUOMID);
+    String strMultiplyRate = StringUtils.equals(strInitUOM, strUOM) ? "1" : "";
+    if (StringUtils.isEmpty(strMultiplyRate)) {
+      strMultiplyRate = SLInvoiceConversionData.multiplyRate(this, strInitUOM, strUOM);
+    }
+    if (StringUtils.isEmpty(strMultiplyRate)) {
+      strMultiplyRate = SLInvoiceConversionData.divideRate(this, strUOM, strInitUOM);
+    }
+    if (StringUtils.isEmpty(strMultiplyRate)) {
+      strMultiplyRate = "1";
+      if (StringUtils.isNotEmpty(strMProductUOMID)) {
+        // Set message when no UOM Conversion exists
+        info.showMessage(FormatUtilities.replaceJS(Utility.messageBD(this, "NoUOMConversion",
+            info.vars.getLanguage())));
+      }
+    }
 
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_Invoice_Conversion';\n\n");
-    resultado.append("var respuesta = new Array(");
-    if (!strQuantityOrder.equals("")) {
-      quantityOrder = new BigDecimal(strQuantityOrder);
-      qtyInvoiced = quantityOrder.multiply(multiplyRate);
-      if (qtyInvoiced.scale() > stdPrecision)
+    // Calculate QtyInvoiced based on UOM Conversion
+    if (StringUtils.isNotEmpty(strQuantityOrder)) {
+      BigDecimal multiplyRate = new BigDecimal(strMultiplyRate);
+      BigDecimal quantityOrder = new BigDecimal(strQuantityOrder);
+      BigDecimal qtyInvoiced = quantityOrder.multiply(multiplyRate);
+      int stdPrecision = Integer.valueOf(SLInvoiceConversionData.stdPrecision(this, strUOM))
+          .intValue();
+      if (qtyInvoiced.scale() > stdPrecision) {
         qtyInvoiced = qtyInvoiced.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
-      resultado.append("new Array(\"inpqtyinvoiced\", " + qtyInvoiced.toString() + ")");
+      }
+      info.addResult("inpqtyinvoiced", qtyInvoiced);
     }
-    if (check) {
-      if (!strQuantityOrder.equals(""))
-        resultado.append(",");
-      resultado
-          .append("new Array('MESSAGE', \""
-              + FormatUtilities.replaceJS(Utility.messageBD(this, "NoUOMConversion",
-                  vars.getLanguage())) + "\")");
-    }
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_DocType.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_DocType.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,101 +11,63 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
+import org.openbravo.erpCommon.utility.Utility;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.erpCommon.reference.ListData;
-import org.openbravo.erpCommon.utility.Utility;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SL_Invoice_DocType extends SimpleCallout {
 
-public class SL_Invoice_DocType extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strDocTypeTarget = vars.getStringParameter("inpcDoctypetargetId");
-      String strTabId = vars.getStringParameter("inpTabId");
-      String strCInvoiceId = vars.getStringParameter("inpcInvoiceId");
-
-      try {
-        printPage(response, vars, strDocTypeTarget, strTabId, strCInvoiceId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars,
-      String strDocTypeTarget, String strTabId, String strCInvoiceId) throws IOException,
-      ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
+    // Parameters
+    String strDocTypeTarget = info.getStringParameter("inpcDoctypetargetId", IsIDFilter.instance);
+    String strCInvoiceId = info.getStringParameter("inpcInvoiceId", IsIDFilter.instance);
 
     SEInOutDocTypeData[] data = SEInOutDocTypeData.select(this, strDocTypeTarget);
+    if (data != null && data.length > 0) {
 
-    StringBuffer resultado = new StringBuffer();
-    if (data == null || data.length == 0)
-      resultado.append("var respuesta = null;");
-    else {
-      resultado.append("var calloutName='SL_Invoice_DocType';\n\n");
-      resultado.append("var respuesta = new Array(");
-
-      // check if doc type target is different, in this case assing new
-      // documentno otherwise matain the previous one
+      // Documentno
+      // check if doc type target is different, in this case assign new
+      // documentno otherwise maintain the previous one
       String strDoctypetargetinvoice = SEInOutDocTypeData.selectDoctypetargetinvoice(this,
           strCInvoiceId);
+      if (StringUtils.isEmpty(strDoctypetargetinvoice)
+          || !StringUtils.equals(strDoctypetargetinvoice, strDocTypeTarget)) {
+        String strDocumentNo = StringUtils.equals(data[0].isdocnocontrolled, "Y") ? data[0].currentnext
+            : Utility.getDocumentNo(this, info.vars.getClient(), "C_Invoice", false);
+        info.addResult("inpdocumentno", "<" + strDocumentNo + ">");
+      } else if (StringUtils.isNotEmpty(strDoctypetargetinvoice)
+          && StringUtils.equals(strDoctypetargetinvoice, strDocTypeTarget)) {
+        info.addResult("inpdocumentno",
+            SEInOutDocTypeData.selectActualinvoicedocumentno(this, strCInvoiceId));
+      }
 
-      if (strDoctypetargetinvoice == null || strDoctypetargetinvoice.equals("")
-          || !strDoctypetargetinvoice.equals(strDocTypeTarget)) {
-        String strDocumentNo = Utility.getDocumentNo(this, vars.getClient(), "C_Invoice", false);
-        if (data[0].isdocnocontrolled.equals("Y"))
-          strDocumentNo = data[0].currentnext;
-        resultado.append("new Array(\"inpdocumentno\", \"<" + strDocumentNo + ">\"),");
-      } else if (strDoctypetargetinvoice != null && !strDoctypetargetinvoice.equals("")
-          && strDoctypetargetinvoice.equals(strDocTypeTarget))
-        resultado.append("new Array(\"inpdocumentno\", \""
-            + SEInOutDocTypeData.selectActualinvoicedocumentno(this, strCInvoiceId) + "\"),");
-      // ------
+      // DocBaseType
+      info.addResult("inpdocbasetype", data[0].docbasetype);
 
-      resultado.append("new Array(\"inpdocbasetype\", \"" + data[0].docbasetype + "\")");
-      String strPaymentRule = "";
-      if (data[0].docbasetype.endsWith("C")) {
-        strPaymentRule = "P";
-        resultado.append(", new Array(\"inppaymentrule\", \"" + strPaymentRule + "\"),");
-        String strNamePaymentRule = ListData.selectName(this, "195", "P");
-        resultado.append("new Array(\"PaymentRule_BTN\", \"" + strNamePaymentRule + "\")");
+      // Payment Rule
+      if (StringUtils.endsWith(data[0].docbasetype, "C")) {
+        // Payment Rule - Form Of Payment On Credit for Credit Memos Document Type
+        info.addResult("inppaymentrule", "P");
+      } else {
+        // Payment Rule - No Form of Payment for non Credit Memos Document type.
+        info.addResult("inppaymentrule", null);
       }
-      resultado.append(");");
     }
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Glitem.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Glitem.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2010-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2010-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -19,75 +19,45 @@
 package org.openbravo.erpCommon.ad_callouts;
 
 import java.io.IOException;
-import java.io.PrintWriter;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.erpCommon.businessUtility.Tax;
 import org.openbravo.erpCommon.utility.Utility;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_Invoice_Glitem extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_Invoice_Glitem extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      String strAccountID = vars.getStringParameter("inpaccountId");
-      String strADOrgID = vars.getStringParameter("inpadOrgId");
-      String strCInvoiceID = vars.getStringParameter("inpcInvoiceId");
-      String strWindowId = vars.getStringParameter("inpwindowId");
-      String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
-      String strWharehouse = Utility.getContext(this, vars, "#M_Warehouse_ID", strWindowId);
-      try {
-        printPage(response, vars, strChanged, strAccountID, strADOrgID, strCInvoiceID, strIsSOTrx,
-            strWharehouse);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strChanged,
-      String strAccountID, String strADOrgID, String strCInvoiceID, String strIsSOTrx,
-      String strWharehouse) throws IOException, ServletException {
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    if (strChanged.equalsIgnoreCase("inpaccountId")) {
-      StringBuilder result = new StringBuilder();
+    // Parameters
+    String strAccountID = info.getStringParameter("inpaccountId", IsIDFilter.instance);
+    String strADOrgID = info.getStringParameter("inpadOrgId", IsIDFilter.instance);
+    String strCInvoiceID = info.getStringParameter("inpcInvoiceId", IsIDFilter.instance);
+    String strIsSOTrx = Utility.getContext(this, info.vars, "isSOTrx", info.getWindowId());
+    String strWarehouse = Utility
+        .getContext(this, info.vars, "#M_Warehouse_ID", info.getWindowId());
 
-      result.append("var calloutName='SL_Invoice_Glitem';\n\n");
-      result.append("var respuesta = new Array(");
+    if (StringUtils.equalsIgnoreCase(strChanged, "inpaccountId")) {
+      // Tax
       SLInvoiceTaxData[] data = SLInvoiceTaxData.select(this, strCInvoiceID);
       if (data != null && data.length > 0) {
-        String strCTaxID = Tax.get(this, null, data[0].dateinvoiced, strADOrgID, strWharehouse,
-            data[0].cBpartnerLocationId, data[0].cBpartnerLocationId, data[0].cProjectId,
-            strIsSOTrx, strAccountID);
-
-        result.append("new Array(\"inpcTaxId\", \"" + strCTaxID + "\")");
+        try {
+          String strCTaxID = Tax.get(this, null, data[0].dateinvoiced, strADOrgID, strWarehouse,
+              data[0].cBpartnerLocationId, data[0].cBpartnerLocationId, data[0].cProjectId,
+              strIsSOTrx, strAccountID);
+          info.addResult("inpcTaxId", strCTaxID);
+        } catch (IOException e) {
+          log4j.error(e.getMessage());
+        }
       }
-      result.append(",\n");
-      result.append("new Array(\"EXECUTE\", \"displayLogic();\")\n");
-      result.append(");");
-      xmlDocument.setParameter("array", result.toString());
     }
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_PriceList.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_PriceList.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,73 +11,35 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.openbravo.base.filter.IsIDFilter;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SL_Invoice_PriceList extends SimpleCallout {
 
-public class SL_Invoice_PriceList extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strMPriceListID = vars.getStringParameter("inpmPricelistId");
-      String strTabId = vars.getStringParameter("inpTabId");
+    // Parameter
+    String strMPriceListID = info.getStringParameter("inpmPricelistId", IsIDFilter.instance);
 
-      try {
-        printPage(response, vars, strMPriceListID, strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars,
-      String strMPriceListID, String strTabId) throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
+    // IsTaxIncluded and Currency
     SLOrderPriceListData[] data = SLOrderPriceListData.select(this, strMPriceListID);
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_Invoice_PriceList';\n\n");
-    resultado.append("var respuesta = new Array(");
     if (data != null && data.length > 0) {
-      resultado.append("new Array(\"inpistaxincluded\", \"" + data[0].istaxincluded + "\"),\n");
-      resultado.append("new Array(\"inpcCurrencyId\", \"" + data[0].cCurrencyId + "\")\n");
+      info.addResult("inpistaxincluded", data[0].istaxincluded);
+      info.addResult("inpcCurrencyId", data[0].cCurrencyId);
     }
-    resultado.append(");\n");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Product.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Product.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2016 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -19,16 +19,12 @@
 package org.openbravo.erpCommon.ad_callouts;
 
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.security.OrganizationStructureProvider;
 import org.openbravo.dal.service.OBDal;
@@ -45,147 +41,119 @@
 import org.openbravo.model.common.invoice.Invoice;
 import org.openbravo.model.common.plm.Product;
 import org.openbravo.utils.FormatUtilities;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_Invoice_Product extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_Invoice_Product extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strUOM = vars.getStringParameter("inpmProductId_UOM");
-      String strPriceList = vars.getNumericParameter("inpmProductId_PLIST");
-      String strPriceStd = vars.getNumericParameter("inpmProductId_PSTD");
-      String strPriceLimit = vars.getStringParameter("inpmProductId_PLIM");
-      String strCurrency = vars.getStringParameter("inpmProductId_CURR");
-      String strQty = vars.getNumericParameter("inpqtyinvoiced");
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-      String strMProductID = vars.getStringParameter("inpmProductId");
-      String strADOrgID = vars.getStringParameter("inpadOrgId");
-      String strCInvoiceID = vars.getStringParameter("inpcInvoiceId");
-      String strWindowId = vars.getStringParameter("inpwindowId");
-      String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
-      String strWharehouse = Utility.getContext(this, vars, "#M_Warehouse_ID", strWindowId);
-      String strUOMProduct = vars.getStringParameter("inpmProductUomId");
-      String strWarehouseOrg = SLOrderProductData.getWarehouseOrg(this, strWharehouse);
-      String strWarehouseForOrg = "";
-      final OrganizationStructureProvider osp = OBContext.getOBContext()
-          .getOrganizationStructureProvider(vars.getClient());
-      if (!strADOrgID.equals(strWarehouseOrg)) {
-        Organization org = OBDal.getInstance().get(Organization.class, strADOrgID);
-        if (strWarehouseOrg != null) {
-          Organization warehouseOrg = OBDal.getInstance().get(Organization.class, strWarehouseOrg);
-          if (!osp.isInNaturalTree(org, warehouseOrg) && !osp.isInNaturalTree(warehouseOrg, org))
-            strWarehouseForOrg = SLOrderProductData.getWarehouseOfOrg(this, vars.getClient(),
-                strADOrgID);
-          if (!strWarehouseForOrg.equals(""))
-            strWharehouse = strWarehouseForOrg;
+    // Parameters
+    String strUOM = info.getStringParameter("inpmProductId_UOM", IsIDFilter.instance);
+    BigDecimal priceList = info.getBigDecimalParameter("inpmProductId_PLIST");
+    BigDecimal priceStd = info.getBigDecimalParameter("inpmProductId_PSTD");
+    BigDecimal priceLimit = info.getBigDecimalParameter("inpmProductId_PLIM");
+    String strCurrency = info.getStringParameter("inpmProductId_CURR", IsIDFilter.instance);
+    BigDecimal qty = info.getBigDecimalParameter("inpqtyinvoiced");
+    String strMProductID = info.getStringParameter("inpmProductId", IsIDFilter.instance);
+    String strADOrgID = info.getStringParameter("inpadOrgId", IsIDFilter.instance);
+    String strCInvoiceID = info.getStringParameter("inpcInvoiceId", IsIDFilter.instance);
+    String strIsSOTrx = Utility.getContext(this, info.vars, "isSOTrx", info.getWindowId());
+    String strWarehouse = Utility
+        .getContext(this, info.vars, "#M_Warehouse_ID", info.getWindowId());
+    String strUOMProduct = info.getStringParameter("inpmProductUomId", IsIDFilter.instance);
+
+    // Warehouse
+    String strWarehouseOrg = SLOrderProductData.getWarehouseOrg(this, strWarehouse);
+    String strWarehouseForOrg = "";
+    final OrganizationStructureProvider osp = OBContext.getOBContext()
+        .getOrganizationStructureProvider(info.vars.getClient());
+    if (!StringUtils.equals(strADOrgID, strWarehouseOrg)) {
+      Organization org = OBDal.getInstance().get(Organization.class, strADOrgID);
+      if (strWarehouseOrg != null) {
+        Organization warehouseOrg = OBDal.getInstance().get(Organization.class, strWarehouseOrg);
+        if (!osp.isInNaturalTree(org, warehouseOrg) && !osp.isInNaturalTree(warehouseOrg, org)) {
+          strWarehouseForOrg = SLOrderProductData.getWarehouseOfOrg(this, info.vars.getClient(),
+              strADOrgID);
+        }
+        if (StringUtils.isNotEmpty(strWarehouseForOrg)) {
+          strWarehouse = strWarehouseForOrg;
         }
       }
-      String strTabId = vars.getStringParameter("inpTabId");
+    }
 
-      try {
-        printPage(response, vars, strUOM, strPriceList, strPriceStd, strPriceLimit, strCurrency,
-            strMProductID, strADOrgID, strCInvoiceID, strIsSOTrx, strWharehouse, strTabId, strQty,
-            strUOMProduct);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // Unit Of Measure
+    info.addResult("inpcUomId", strUOM);
 
-  private 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, String strUOMProduct)
-      throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
-    String strPriceActual = "";
+    // Prices
+    BigDecimal priceActual = BigDecimal.ZERO;
     Invoice invoice = OBDal.getInstance().get(Invoice.class, strCInvoiceID);
     boolean priceIncludeTaxes = invoice.getPriceList().isPriceIncludesTax();
-    if (!strMProductID.equals("")) {
+    if (StringUtils.isNotEmpty(strMProductID)) {
       Product product = OBDal.getInstance().get(Product.class, strMProductID);
-      strPriceActual = PriceAdjustment.calculatePriceActual(invoice, product,
-          new BigDecimal(strQty), new BigDecimal((strPriceStd.equals("") ? "0" : strPriceStd)))
-          .toString();
+      priceActual = PriceAdjustment.calculatePriceActual(invoice, product, qty, priceStd);
     }
-    StringBuffer resultado = new StringBuffer();
+    if (priceIncludeTaxes) {
+      info.addResult("inpgrossUnitPrice", priceActual);
+      info.addResult("inpgrosspricestd", priceStd);
+      info.addResult("inpgrosspricelist", priceList);
+    } else {
+      info.addResult("inppricestd", priceStd);
+      info.addResult("inppriceactual", priceActual);
+    }
+    info.addResult("inppricelist", priceList);
+    info.addResult("inppricelimit", priceLimit);
 
-    resultado.append("var calloutName='SL_Invoice_Product';\n\n");
-    resultado.append("var respuesta = new Array(");
-    resultado.append("new Array(\"inpcUomId\", \"" + strUOM + "\"),");
-    if (priceIncludeTaxes) {
-      resultado.append("new Array(\"inpgrossUnitPrice\", "
-          + (strPriceActual.equals("") ? "0" : strPriceActual) + "),");
-      resultado.append("new Array(\"inpgrosspricestd\", "
-          + (strPriceStd.equals("") ? "0" : strPriceStd) + "),");
-      resultado.append("new Array(\"inpgrosspricelist\", "
-          + (strPriceList.equals("") ? "\"\"" : strPriceList) + "),");
-
-    } else {
-      resultado.append("new Array(\"inppricestd\", "
-          + (strPriceStd.equals("") ? "\"\"" : strPriceStd) + "),");
-      resultado.append("new Array(\"inppriceactual\", "
-          + (strPriceActual.equals("") ? "\"\"" : strPriceActual) + "),");
-
+    // Attribute Set Instance
+    if (StringUtils.isNotEmpty(strMProductID)) {
+      PAttributeSetData[] dataPAttr = PAttributeSetData.selectProductAttr(this, strMProductID);
+      if (dataPAttr != null && dataPAttr.length > 0
+          && StringUtils.equals(dataPAttr[0].attrsetvaluetype, "D")) {
+        PAttributeSetData[] data2 = PAttributeSetData.select(this, dataPAttr[0].mAttributesetId);
+        if (PAttributeSet.isInstanceAttributeSet(data2)) {
+          info.addResult("inpmAttributesetinstanceId", "");
+        } else {
+          info.addResult("inpmAttributesetinstanceId", dataPAttr[0].mAttributesetinstanceId);
+        }
+        info.addResult("inpattributeset", FormatUtilities.replaceJS(dataPAttr[0].mAttributesetId));
+        info.addResult("inpattrsetvaluetype",
+            FormatUtilities.replaceJS(dataPAttr[0].attrsetvaluetype));
+      } else {
+        info.addResult("inpmAttributesetinstanceId", "");
+        info.addResult("inpattributeset", "");
+        info.addResult("inpattrsetvaluetype", "");
+      }
     }
 
-    resultado.append("new Array(\"inppricelist\", "
-        + (strPriceList.equals("") ? "\"\"" : strPriceList) + "),");
-    resultado.append("new Array(\"inppricelimit\", "
-        + (strPriceLimit.equals("") ? "\"\"" : strPriceLimit) + "),");
-    PAttributeSetData[] dataPAttr = PAttributeSetData.selectProductAttr(this, strMProductID);
-    if (dataPAttr != null && dataPAttr.length > 0 && dataPAttr[0].attrsetvaluetype.equals("D")) {
-      PAttributeSetData[] data2 = PAttributeSetData.select(this, dataPAttr[0].mAttributesetId);
-      if (PAttributeSet.isInstanceAttributeSet(data2)) {
-        resultado.append("new Array(\"inpmAttributesetinstanceId\", \"\"),");
-        resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \"\"),");
-      } else {
-        resultado.append("new Array(\"inpmAttributesetinstanceId\", \""
-            + dataPAttr[0].mAttributesetinstanceId + "\"),");
-        resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \""
-            + FormatUtilities.replaceJS(dataPAttr[0].description) + "\"),");
-      }
-      resultado.append("new Array(\"inpattributeset\", \""
-          + FormatUtilities.replaceJS(dataPAttr[0].mAttributesetId) + "\"),\n");
-      resultado.append("new Array(\"inpattrsetvaluetype\", \""
-          + FormatUtilities.replaceJS(dataPAttr[0].attrsetvaluetype) + "\"),\n");
-    } else {
-      resultado.append("new Array(\"inpmAttributesetinstanceId\", \"\"),");
-      resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \"\"),");
-      resultado.append("new Array(\"inpattributeset\", \"\"),\n");
-      resultado.append("new Array(\"inpattrsetvaluetype\", \"\"),\n");
-    }
+    // Second Unit Of Measure
     String strHasSecondaryUOM = SLOrderProductData.hasSecondaryUOM(this, strMProductID);
-    resultado.append("new Array(\"inphasseconduom\", " + strHasSecondaryUOM + ")");
-    if (!"".equals(strCurrency)) {
-      resultado.append(",\n new Array(\"inpcCurrencyId\", " + strCurrency + ")");
+    info.addResult("inphasseconduom", Integer.parseInt(strHasSecondaryUOM));
+
+    // Currency
+    if (StringUtils.isNotEmpty(strCurrency)) {
+      info.addResult("inpcCurrencyId", strCurrency);
     }
 
+    // Tax
     SLInvoiceTaxData[] data = SLInvoiceTaxData.select(this, strCInvoiceID);
     if (data != null && data.length > 0) {
-      String strCTaxID = Tax.get(this, strMProductID, data[0].dateinvoiced, strADOrgID,
-          strWharehouse, data[0].cBpartnerLocationId, data[0].cBpartnerLocationId,
-          data[0].cProjectId, strIsSOTrx.equals("Y"), "Y".equals(data[0].iscashvat));
+      try {
+        String strCTaxID = Tax.get(this, strMProductID, data[0].dateinvoiced, strADOrgID,
+            strWarehouse, data[0].cBpartnerLocationId, data[0].cBpartnerLocationId,
+            data[0].cProjectId, StringUtils.equals(strIsSOTrx, "Y"),
+            StringUtils.equals(data[0].iscashvat, "Y"));
+        info.addResult("inpcTaxId", strCTaxID);
+      } catch (IOException e) {
+        log4j.error(e.getMessage());
+      }
+    }
 
-      resultado.append(", new Array(\"inpcTaxId\", \"" + strCTaxID + "\")");
-    }
-    if (!"".equals(strCInvoiceID)) {
-      Invoice inv = OBDal.getInstance().get(Invoice.class, strCInvoiceID);
+    // Isdeferred, defplantype, periodno, periodId
+    if (StringUtils.isNotEmpty(strCInvoiceID)) {
       final String CURRENT_MONTH = "C";
       final String NEXT_MONTH = "N";
       // Set empty values
@@ -194,34 +162,34 @@
       String periodnumber = "";
       String cPeriodId = "";
       try {
-        if (inv.isSalesTransaction() && !"".equals(strMProductID)) {
+        if (invoice.isSalesTransaction() && StringUtils.isNotEmpty(strMProductID)) {
           Product product = OBDal.getInstance().get(Product.class, strMProductID);
           if (product.isDeferredRevenue()) {
             isdeferred = "Y";
             defplantype = product.getRevenuePlanType();
             periodnumber = product.getPeriodNumber().toString();
-            if (CURRENT_MONTH.equals(product.getDefaultPeriod())) {
-              cPeriodId = AccDefUtility.getCurrentPeriod(inv.getAccountingDate(),
-                  AccDefUtility.getCalendar(inv.getOrganization())).getId();
-            } else if (NEXT_MONTH.equals(product.getDefaultPeriod())) {
+            if (StringUtils.equals(product.getDefaultPeriod(), CURRENT_MONTH)) {
+              cPeriodId = AccDefUtility.getCurrentPeriod(invoice.getAccountingDate(),
+                  AccDefUtility.getCalendar(invoice.getOrganization())).getId();
+            } else if (StringUtils.equals(product.getDefaultPeriod(), NEXT_MONTH)) {
               cPeriodId = AccDefUtility.getNextPeriod(
-                  AccDefUtility.getCurrentPeriod(inv.getAccountingDate(),
-                      AccDefUtility.getCalendar(inv.getOrganization()))).getId();
+                  AccDefUtility.getCurrentPeriod(invoice.getAccountingDate(),
+                      AccDefUtility.getCalendar(invoice.getOrganization()))).getId();
             }
           }
-        } else if (!inv.isSalesTransaction() && !"".equals(strMProductID)) {
+        } else if (!invoice.isSalesTransaction() && StringUtils.isNotEmpty(strMProductID)) {
           Product product = OBDal.getInstance().get(Product.class, strMProductID);
           if (product.isDeferredexpense()) {
             isdeferred = "Y";
             defplantype = product.getExpplantype();
             periodnumber = product.getPeriodnumberExp().toString();
-            if (CURRENT_MONTH.equals(product.getDefaultPeriodExpense())) {
-              cPeriodId = AccDefUtility.getCurrentPeriod(inv.getAccountingDate(),
-                  AccDefUtility.getCalendar(inv.getOrganization())).getId();
-            } else if (NEXT_MONTH.equals(product.getDefaultPeriodExpense())) {
+            if (StringUtils.equals(product.getDefaultPeriodExpense(), CURRENT_MONTH)) {
+              cPeriodId = AccDefUtility.getCurrentPeriod(invoice.getAccountingDate(),
+                  AccDefUtility.getCalendar(invoice.getOrganization())).getId();
+            } else if (StringUtils.equals(product.getDefaultPeriodExpense(), NEXT_MONTH)) {
               cPeriodId = AccDefUtility.getNextPeriod(
-                  AccDefUtility.getCurrentPeriod(inv.getAccountingDate(),
-                      AccDefUtility.getCalendar(inv.getOrganization()))).getId();
+                  AccDefUtility.getCurrentPeriod(invoice.getAccountingDate(),
+                      AccDefUtility.getCalendar(invoice.getOrganization()))).getId();
             }
           }
         }
@@ -232,64 +200,47 @@
         cPeriodId = "";
         log4j.error("Error calculating Accruals and Deferrals Plan");
       }
-      // Set values
-      resultado.append(", new Array(\"inpisdeferred\", \"" + isdeferred + "\")");
-      resultado.append(", new Array(\"inpdefplantype\", \"" + defplantype + "\")");
-      resultado.append(", new Array(\"inpperiodnumber\", \"" + periodnumber + "\")");
-      resultado.append(", new Array(\"inpcPeriodId\", \"" + cPeriodId + "\")");
-
+      info.addResult("inpisdeferred", isdeferred);
+      info.addResult("inpdefplantype", defplantype);
+      info.addResult("inpperiodnumber", periodnumber);
+      info.addResult("inpcPeriodId", cPeriodId);
     }
 
-    if (UOMUtil.isUomManagementEnabled() && "".equals(strUOMProduct)) {
-      // Set AUM based on default
+    // Set AUM based on default
+    if (UOMUtil.isUomManagementEnabled() && StringUtils.isEmpty(strUOMProduct)) {
       String finalAUM = UOMUtil.getDefaultAUMForDocument(strMProductID, invoice
           .getTransactionDocument().getId());
       if (finalAUM != null) {
-        resultado.append(", new Array(\"inpcAum\", \"" + finalAUM + "\")");
+        info.addResult("inpcAum", finalAUM);
       }
     }
-    if (strHasSecondaryUOM.equals("1")
-        && (!UOMUtil.isUomManagementEnabled() || (UOMUtil.isUomManagementEnabled() && !""
-            .equals(strUOMProduct)))) {
-      resultado.append(", new Array(\"inpmProductUomId\", ");
 
+    // Load Product UOM in case Second UOM exists for product
+    if (StringUtils.equals(strHasSecondaryUOM, "1")
+        && (!UOMUtil.isUomManagementEnabled() || (UOMUtil.isUomManagementEnabled() && StringUtils
+            .isNotEmpty(strUOMProduct)))) {
       FieldProvider[] tld = null;
       try {
-        ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "",
-            "M_Product_UOM", "", Utility.getContext(this, vars, "#AccessibleOrgTree",
-                "SLOrderProduct"),
-            Utility.getContext(this, vars, "#User_Client", "SLOrderProduct"), 0);
-        Utility.fillSQLParameters(this, vars, null, comboTableData, "SLOrderProduct", "");
+        ComboTableData comboTableData = new ComboTableData(info.vars, this, "TABLE", "",
+            "M_Product_UOM", "", Utility.getContext(this, info.vars, "#AccessibleOrgTree",
+                "SLOrderProduct"), Utility.getContext(this, info.vars, "#User_Client",
+                "SLOrderProduct"), 0);
+        Utility.fillSQLParameters(this, info.vars, null, comboTableData, "SLOrderProduct", "");
         tld = comboTableData.select(false);
         comboTableData = null;
       } catch (Exception ex) {
         throw new ServletException(ex);
       }
-
       if (tld != null && tld.length > 0) {
-        resultado.append("new Array(");
+        info.addSelect("inpmProductUomId");
         for (int i = 0; i < tld.length; i++) {
-          resultado.append("new Array(\"" + tld[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"false\")");
-          if (i < tld.length - 1) {
-            resultado.append(",\n");
-          }
+          info.addSelectResult(tld[i].getField("id"),
+              FormatUtilities.replaceJS(tld[i].getField("name")), false);
         }
-        resultado.append("\n)");
-      } else
-        resultado.append("null");
-      resultado.append("\n)");
+        info.endSelect();
+      } else {
+        info.addResult("inpmProductUomId", null);
+      }
     }
-
-    resultado.append(", new Array(\"EXECUTE\", \"displayLogic();\")\n");
-
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
   }
-
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_JournalLineAmt.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_JournalLineAmt.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,117 +11,65 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
 import org.openbravo.dal.service.OBDal;
-import org.openbravo.erpCommon.utility.DateTimeData;
 import org.openbravo.model.financialmgmt.gl.GLJournal;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_JournalLineAmt extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_JournalLineAmt extends SimpleCallout {
 
-  static final BigDecimal ZERO = new BigDecimal(0.0);
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      String strWindowId = vars.getStringParameter("inpWindowId");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strGLJournal = vars.getRequiredStringParameter("inpglJournalId");
-      String strCurrencyRate = vars.getNumericParameter("inpcurrencyrate", "1");
-      String strCurrency = vars.getStringParameter("inpcCurrencyId");
-      String strDateAcct = vars.getStringParameter("inpdateacct", DateTimeData.today(this));
-      String strCurrencyRateType = vars.getStringParameter("inpcurrencyratetype", "S");
-      String strAmtSourceDr = vars.getNumericParameter("inpamtsourcedr", "0");
-      String strAmtSourceCr = vars.getNumericParameter("inpamtsourcecr", "0");
-      String strTabId = vars.getStringParameter("inpTabId");
-      if (!(strAmtSourceDr.equals("0")) && (strChanged.equals("inpamtsourcedr"))) {
-        strAmtSourceCr = "0";
-      }
-      if ((!strAmtSourceCr.equals("0")) && (strChanged.equals("inpamtsourcecr"))) {
-        strAmtSourceDr = "0";
-      }
-      try {
-        printPage(response, vars, strGLJournal, strCurrencyRate, strCurrency, strDateAcct,
-            strCurrencyRateType, strWindowId, strAmtSourceDr, strAmtSourceCr, strTabId);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    // Parameters
+    String strGLJournal = info.vars.getRequiredStringParameter("inpglJournalId");
+    String strCurrencyRateType = info.vars.getStringParameter("inpcurrencyratetype", "S");
+    BigDecimal amtSourceDr = info.getBigDecimalParameter("inpamtsourcedr");
+    BigDecimal amtSourceCr = info.getBigDecimalParameter("inpamtsourcecr");
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars,
-      String strGLJournal, String strCurrencyRate, String strCurrency, String strDateAcct,
-      String strCurrencyRateType, String strWindowId, String strAmtSourceDr, String strAmtSourceCr,
-      String strTabId) throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
     String strAcctSchema = SLJournalLineAmtData.selectGeneralLedger(this, strGLJournal);
     SLJournalLineAmtData[] data = SLJournalLineAmtData.select(this, strAcctSchema);
-    String strPrecision = "2";
+    int stdPrecision = 2;
     if (data != null && data.length > 0) {
-      strPrecision = data[0].stdprecision.equals("") ? "2" : data[0].stdprecision;
+      stdPrecision = Integer.valueOf(data[0].stdprecision);
     }
+
+    if (StringUtils.equals(strChanged, "inpamtsourcedr")
+        && amtSourceDr.compareTo(BigDecimal.ZERO) != 0) {
+      amtSourceCr = BigDecimal.ZERO;
+    }
+    if (StringUtils.equals(strChanged, "inpamtsourcecr")
+        && amtSourceCr.compareTo(BigDecimal.ZERO) != 0) {
+      amtSourceDr = BigDecimal.ZERO;
+    }
+
     GLJournal gLJournal = OBDal.getInstance().get(GLJournal.class, strGLJournal);
-    BigDecimal CurrencyRateValue = gLJournal.getRate();
-    String CurrencyRate = CurrencyRateValue.toString();
-    int StdPrecision = Integer.valueOf(strPrecision).intValue();
+    BigDecimal currencyRate = gLJournal.getRate().setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
+    BigDecimal amtAcctDr = amtSourceDr.multiply(currencyRate).setScale(stdPrecision,
+        BigDecimal.ROUND_HALF_UP);
+    BigDecimal amtAcctCr = amtSourceCr.multiply(currencyRate).setScale(stdPrecision,
+        BigDecimal.ROUND_HALF_UP);
 
-    BigDecimal AmtSourceDr = new BigDecimal(strAmtSourceDr);
-    BigDecimal AmtSourceCr = new BigDecimal(strAmtSourceCr);
-
-    CurrencyRateValue = CurrencyRateValue.setScale(StdPrecision, BigDecimal.ROUND_HALF_UP);
-    BigDecimal AmtAcctDr, AmtAcctCr;
-
-    AmtAcctDr = (strAmtSourceDr.equals("") ? ZERO : AmtSourceDr.multiply(new BigDecimal(
-        CurrencyRate))).setScale(StdPrecision, BigDecimal.ROUND_HALF_UP);
-    AmtAcctCr = (strAmtSourceCr.equals("") ? ZERO : AmtSourceCr.multiply(new BigDecimal(
-        CurrencyRate))).setScale(StdPrecision, BigDecimal.ROUND_HALF_UP);
-
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_JournalLineAmt';\n\n");
-    resultado.append("var respuesta = new Array(");
-    resultado.append("new Array(\"inpamtacctdr\", " + AmtAcctDr.toString() + "),");
-    resultado.append("new Array(\"inpamtacctcr\", " + AmtAcctCr.toString() + "),");
-    resultado.append("new Array(\"inpamtsourcedr\", " + strAmtSourceDr + "),");
-    resultado.append("new Array(\"inpamtsourcecr\", " + strAmtSourceCr + "),");
-    resultado.append("new Array(\"inpcurrencyrate\", " + CurrencyRateValue.toString() + "),");
-    resultado.append("new Array(\"inpcurrencyratetype\", \"" + strCurrencyRateType + "\")");
-
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    info.addResult("inpamtacctdr", amtAcctDr);
+    info.addResult("inpamtacctcr", amtAcctCr);
+    info.addResult("inpamtsourcedr", amtAcctDr);
+    info.addResult("inpamtsourcecr", amtAcctCr);
+    info.addResult("inpcurrencyrate", currencyRate);
+    info.addResult("inpcurrencyratetype", strCurrencyRateType);
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Journal_Period.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Journal_Period.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,166 +11,118 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2016 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.utility.DateTimeData;
 import org.openbravo.erpCommon.utility.OBCurrencyUtils;
-import org.openbravo.erpCommon.utility.OBError;
-import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.erpCommon.utility.OBMessageUtils;
 import org.openbravo.model.financialmgmt.accounting.coa.AcctSchema;
-import org.openbravo.xmlEngine.XmlDocument;
 
-public class SL_Journal_Period extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_Journal_Period extends SimpleCallout {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      String strWindowId = vars.getStringParameter("inpWindowId");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strOrgId = vars.getStringParameter("inpadOrgId");
-      String strDateAcct = vars.getStringParameter("inpdateacct");
-      String strDateDoc = vars.getStringParameter("inpdatedoc");
-      String strcPeriodId = vars.getStringParameter("inpcPeriodId");
-      String strTabId = vars.getStringParameter("inpTabId");
-      String strCurrencyId = vars.getStringParameter("inpcCurrencyId");
-      String strAcctSchemaId = vars.getStringParameter("inpcAcctschemaId");
-      String strCurrencyRateType = vars.getStringParameter("inpcurrencyratetype", "S");
-      try {
-        printPage(response, vars, strOrgId, strDateAcct, strDateDoc, strcPeriodId, strWindowId,
-            strChanged, strTabId, strCurrencyId, strAcctSchemaId, strCurrencyRateType);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
+    }
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strOrgId,
-      String strDateAcctNew, String strDateDocNew, String strcPeriodIdNew, String strWindowId,
-      String strChanged, String strTabId, String strCurrencyId, String strAcctSchemaId,
-      String strCurrencyRateType) throws IOException, ServletException {
-    String localStrChanged = strChanged;
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-    String stradClientId = vars.getClient();
+    // Parameters
+    String strOrgId = info.getStringParameter("inpadOrgId", IsIDFilter.instance);
+    String strDateAcct = info.getStringParameter("inpdateacct");
+    String strDateDoc = info.getStringParameter("inpdatedoc");
+    String strcPeriodId = info.getStringParameter("inpcPeriodId", IsIDFilter.instance);
+    String strCurrencyId = info.getStringParameter("inpcCurrencyId", IsIDFilter.instance);
+    String strAcctSchemaId = info.getStringParameter("inpcAcctschemaId", IsIDFilter.instance);
+    String strCurrencyRateType = info.vars.getStringParameter("inpcurrencyratetype", "S");
+    String stradClientId = info.vars.getClient();
 
     // When organization is changed, update currency
     String currency = null;
-    if (localStrChanged.equals("inpadOrgId")) {
+    if (StringUtils.equals(strChanged, "inpadOrgId")) {
       currency = OBCurrencyUtils.getOrgCurrency(strOrgId);
     }
 
-    OBError myMessage = null;
-    String currencyRate = null;
-    if (strAcctSchemaId != null && !strAcctSchemaId.isEmpty()) {
-      AcctSchema acctSchema = OBDal.getInstance().get(AcctSchema.class, strAcctSchemaId);
-      try {
-        currencyRate = SLJournalPeriodData.getCurrencyRate(this, strCurrencyId, acctSchema
-            .getCurrency().getId(), strDateAcctNew, strCurrencyRateType, stradClientId, strOrgId,
-            strAcctSchemaId);
-      } catch (Exception e) {
-        myMessage = Utility.translateError(this, vars, vars.getLanguage(), e.getMessage());
-        log4j.warn("Currency does not exist. Exception:" + e);
+    // When DateDoc is changed, update DateAcct
+    if (StringUtils.equals(strChanged, "inpdatedoc")) {
+      strDateAcct = strDateDoc;
+      strChanged = "inpdateacct";
+    }
+
+    // When DateAcct is changed, set C_Period_ID
+    if (StringUtils.equals(strChanged, "inpdateacct")) {
+      strcPeriodId = SLJournalPeriodData.period(this, stradClientId, strOrgId, strDateAcct);
+      if (StringUtils.isEmpty(strcPeriodId)) {
+        info.showError(OBMessageUtils.messageBD(this, "PeriodNotValid", info.vars.getLanguage()));
       }
     }
 
-    String strDateAcct = strDateAcctNew;
-    String strcPeriodId = strcPeriodIdNew;
-    // When DateDoc is changed, update DateAcct
-    if (localStrChanged.equals("inpdatedoc")) {
-      strDateAcct = strDateDocNew;
-      localStrChanged = "inpdateacct";
-    }
-    // When DateAcct is changed, set C_Period_ID
-    if (localStrChanged.equals("inpdateacct")) {
-      strcPeriodId = SLJournalPeriodData.period(this, stradClientId, strOrgId, strDateAcct);
-      if (strcPeriodId.equals("")) {
-        StringBuffer resultado = new StringBuffer();
-        resultado.append("var calloutName='SL_Journal_Period';\n\n");
-        resultado.append("var respuesta = new Array(");
-        resultado.append("new Array(\"ERROR\", \""
-            + Utility.messageBD(this, "PeriodNotValid", vars.getLanguage()) + "\")");
-        resultado.append(");");
-        xmlDocument.setParameter("array", resultado.toString());
-        xmlDocument.setParameter("frameName", "appFrame");
-        response.setContentType("text/html; charset=UTF-8");
-        PrintWriter out = response.getWriter();
-        out.println(xmlDocument.print());
-        out.close();
-        return;
-      }
-
-    }
+    // When C_Period_ID is changed, check if in DateAcct range and set to end date if not
     boolean isStandardPeriod = true;
-    if (localStrChanged.equals("inpcPeriodId") && !strcPeriodId.equals("")) {
-      // When C_Period_ID is changed, check if in DateAcct range and set
-      // to end date if not
+    if (StringUtils.equals(strChanged, "inpcPeriodId") && StringUtils.isNotEmpty(strcPeriodId)) {
       SLJournalPeriodData[] data = SLJournalPeriodData.select(this, strcPeriodId);
-      String PeriodType = data[0].periodtype;
-      String StartDate = data[0].startdate;
-      String EndDate = data[0].enddate;
-      if (PeriodType.equals("S")) { // Standard Periods
-        // out of range - set to last day
-        if (DateTimeData.compare(this, StartDate, strDateAcct).equals("1")
-            || DateTimeData.compare(this, EndDate, strDateAcct).equals("-1"))
-          strDateAcct = EndDate;
+      String periodType = data[0].periodtype;
+      String startDate = data[0].startdate;
+      String endDate = data[0].enddate;
+      // Standard Periods
+      if (StringUtils.equals(periodType, "S")) {
+        // Out of range, set to last day
+        if (StringUtils.equals(DateTimeData.compare(this, startDate, strDateAcct), "1")
+            || StringUtils.equals(DateTimeData.compare(this, endDate, strDateAcct), "-1")) {
+          strDateAcct = endDate;
+        }
       } else {
         isStandardPeriod = false;
-        strDateAcct = EndDate;
+        strDateAcct = endDate;
       }
     }
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_Journal_Period';\n\n");
-    resultado.append("var respuesta = new Array(");
-    resultado.append("new Array(\"inpdateacct\", \"" + strDateAcct + "\"),");
+
+    // Update Date acct
+    info.addResult("inpdateacct", strDateAcct);
+
+    // Update currency
     if (currency != null) {
-      resultado.append("new Array(\"inpcCurrencyId\", \"" + currency + "\"),");
+      info.addResult("inpcCurrencyId", currency);
     }
+
+    // Update date doc
     if (!isStandardPeriod) {
-      resultado.append("new Array(\"inpdatedoc\", \"" + strDateAcct + "\"),");
+      info.addResult("inpdatedoc", strDateAcct);
     }
-    resultado.append("new Array(\"inpcPeriodId\", \"" + strcPeriodId + "\"),");
-    if (myMessage != null) {
-      resultado.append("new Array('MESSAGE', \"" + myMessage.getMessage() + "\"),");
+
+    // Update period
+    info.addResult("inpcPeriodId", strcPeriodId);
+
+    // Update currency rate
+    if (StringUtils.isNotEmpty(strAcctSchemaId)) {
+      AcctSchema acctSchema = OBDal.getInstance().get(AcctSchema.class, strAcctSchemaId);
+      String currencyRate = null;
+      try {
+        currencyRate = SLJournalPeriodData.getCurrencyRate(this, strCurrencyId, acctSchema
+            .getCurrency().getId(), strDateAcct, strCurrencyRateType, stradClientId, strOrgId,
+            strAcctSchemaId);
+      } catch (Exception e) {
+        OBDal.getInstance().rollbackAndClose();
+        log4j.warn("No currency conversion exists.");
+        info.showMessage(OBMessageUtils.messageBD(this, "NoCurrencyConversion",
+            info.vars.getLanguage()));
+      }
+      info.addResult("inpcurrencyrate", StringUtils.isNotEmpty(currencyRate) ? new BigDecimal(
+          currencyRate) : BigDecimal.ONE);
     }
-    if (currencyRate == null) {
-      resultado.append("new Array(\"inpcurrencyrate\", \"" + "1" + "\")");
-    } else {
-      resultado.append("new Array(\"inpcurrencyrate\", \"" + currencyRate.toString() + "\")");
-    }
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_LegalEntity_Acct.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_LegalEntity_Acct.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,75 +11,37 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2009-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
+import javax.servlet.ServletException;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringUtils;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.xmlEngine.XmlDocument;
+public class SL_LegalEntity_Acct extends SimpleCallout {
 
-public class SL_LegalEntity_Acct extends HttpSecureAppServlet {
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  private static final long serialVersionUID = 1L;
-
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
-
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strIsLE = vars.getStringParameter("inpislegalentity");
-      try {
-        printPage(response, vars, strIsLE);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-
-    } else
-      pageError(response);
-
-  }
-
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strIsAcctLE)
-      throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
-    StringBuffer resultado = new StringBuffer();
-    resultado.append("var calloutName='SL_LegalEntity_Acct';\n\n");
-    resultado.append("var respuesta = new Array(");
-
-    if (strIsAcctLE.equals("Y")) {
-      resultado.append("new Array(\"inpacctleAux\", \"" + "N" + "\"),\n ");
-    } else {
-      resultado.append("new Array(\"inpacctleAux\", \"" + "Y" + "\"),\n ");
-      resultado.append("new Array(\"inpisacctlegalentity\", \"" + "N" + "\"),\n ");
+    String strChanged = info.getLastFieldChanged();
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("CHANGED: " + strChanged);
     }
 
-    resultado.append("new Array(\"EXECUTE\", \"displayLogic();\")\n");
-    resultado.append(");");
-    xmlDocument.setParameter("array", resultado.toString());
-    xmlDocument.setParameter("frameName", "appFrame");
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    // Parameters
+    String strIsAcctLE = info.getStringParameter("inpislegalentity");
+
+    // If the organization type is marked as Legal Entity then "Legal Entity with accounting" field
+    // must be available, in other case it will be hidden.
+    if (StringUtils.equals(strIsAcctLE, "Y")) {
+      info.addResult("inpacctleAux", "N");
+    } else {
+      info.addResult("inpacctleAux", "Y");
+      info.addResult("inpisacctlegalentity", "N");
+    }
   }
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_MachineCost.java	Fri Aug 04 14:41:10 2017 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_MachineCost.java	Fri Aug 04 19:25:27 2017 -0400
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -19,196 +19,82 @@
 
 package org.openbravo.erpCommon.ad_callouts;
 
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.openbravo.base.secureApp.HttpSecureAppServlet;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.xmlEngine.XmlDocument;
+import org.apache.commons.lang.StringUtils;
 
-public class SL_MachineCost extends HttpSecureAppServlet {
-  private static final long serialVersionUID = 1L;
+public class SL_MachineCost extends SimpleCallout {
+  @Override
+  protected void execute(CalloutInfo info) throws ServletException {
 
-  public void init(ServletConfig config) {
-    super.init(config);
-    boolHist = false;
-  }
-
-  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
-      ServletException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
-    if (vars.commandIn("DEFAULT")) {
-      String strChanged = vars.getStringParameter("inpLastFieldChanged");
-      if (log4j.isDebugEnabled())
-        log4j.debug("CHANGED: " + strChanged);
-      String strPurchaseAmt = vars.getNumericParameter("inppurchaseamt");
-      String strToolsetAmt = vars.getNumericParameter("inptoolsetamt");
-      String strYearValue = vars.getNumericParameter("inpyearvalue");
-      String strAmortization = vars.getNumericParameter("inpamortization");
-      String strDaysYear = vars.getNumericParameter("inpdaysyear");
-      String strDayHours = vars.getNumericParameter("inpdayhours");
-      String strImproductiveHoursYear = vars.getNumericParameter("inpimproductivehoursyear");
-      String strCostUomYear = vars.getNumericParameter("inpcostuomyear");
-      String strCost = vars.getNumericParameter("inpcost");
-      String strCostUom = vars.getStringParameter("inpcostuom");
-      try {
-        printPage(response, vars, strChanged, strPurchaseAmt, strToolsetAmt, strYearValue,
-            strAmortization, strDaysYear, strDayHours, strImproductiveHoursYear, strCostUomYear,
-            strCost, strCostUom);
-      } catch (ServletException ex) {
-        pageErrorCallOut(response);
-      }
-    } else
-      pageError(response);
-  }
-
-  private 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 {
-    String localStrYearValue = strYearValue;
-    String localStrImproductiveHoursYear = strImproductiveHoursYear;
-    String localStrCostUomYear = strCostUomYear;
-    String localStrCost = strCost;
-    String localStrAmortization = strAmortization;
-    if (log4j.isDebugEnabled())
-      log4j.debug("Output: dataSheet");
-    XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-        "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
-    if (strChanged.equals("inppurchaseamt") || strChanged.equals("inptoolsetamt")
-        || strChanged.equals("inpyearvalue")) {
-      if (strPurchaseAmt != null && !strPurchaseAmt.equals("") && strToolsetAmt != null
-          && !strToolsetAmt.equals("") && localStrYearValue != null
-          && !localStrYearValue.equals("")) {
-        BigDecimal fPurchaseAmt = new BigDecimal(strPurchaseAmt);
-        BigDecimal fToolsetAmt = new BigDecimal(strToolsetAmt);
-        BigDecimal fYearValue = new BigDecimal(localStrYearValue);
-        BigDecimal fAmortization = (fPurchaseAmt.add(fToolsetAmt)).divide(fYearValue, 12,
-            BigDecimal.ROUND_HALF_EVEN);
-        localStrAmortization = fAmortization.toString();
-
-        if (localStrCostUomYear != null && !localStrCostUomYear.equals("")) {
-          BigDecimal fCostUomYear = new BigDecimal(localStrCostUomYear);
-          BigDecimal fCost = fYearValue.divide(fCostUomYear, 12, BigDecimal.ROUND_HALF_EVEN);
-          localStrCost = fCost.toPlainString();
-        }
-      }
-    } else if (strChanged.equals("inpamortization")) {
-      if (strPurchaseAmt != null && !strPurchaseAmt.equals("") && strToolsetAmt != null
-          && !strToolsetAmt.equals("") && localStrAmortization != null
-          && !localStrAmortization.equals("")) {
-        BigDecimal fPurchaseAmt = new BigDecimal(strPurchaseAmt);
-        BigDecimal fToolsetAmt = new BigDecimal(strToolsetAmt);
-        BigDecimal fAmortization = new BigDecimal(localStrAmortization);
-        BigDecimal fYearValue = (fPurchaseAmt.add(fToolsetAmt)).divide(fAmortization, 12,
-            BigDecimal.ROUND_HALF_EVEN);
-        localStrYearValue = fYearValue.toPlainString();
-
-        if (localStrCostUomYear != null && !localStrCostUomYear.equals("")) {
-          BigDecimal fCostUomYear = new BigDecimal(localStrCostUomYear);
-          BigDecimal fCost = fYearValue.divide(fCostUomYear, 12, BigDecimal.ROUND_HALF_EVEN);
-          localStrCost = fCost.toPlainString();
-        }
-      }
-    } else if (strChanged.equals("inpdaysyear") || strChanged.equals("inpdayhours")
-        || strChanged.equals("inpimproductivehoursyear")) {
-      if (strDaysYear != null && !strDaysYear.equals("") && strDayHours != null
-          && !strDayHours.equals("") && localStrImproductiveHoursYear != null
-          && !localStrImproductiveHoursYear.equals("")) {
-        BigDecimal fDaysYear = new BigDecimal(strDaysYear);
-        BigDecimal fDayHours = new BigDecimal(strDayHours);
-        BigDecimal fImproductiveHoursYear = new BigDecimal(localStrImproductiveHoursYear);
-        BigDecimal fCostUomYear = (fDaysYear.multiply(fDayHours)).subtract(fImproductiveHoursYear);
-        localStrCostUomYear = fCostUomYear.toPlainString();
-
-        if (localStrYearValue != null && !localStrYearValue.equals("")) {
-          BigDecimal fYearValue = new BigDecimal(localStrYearValue);
-          BigDecimal fCost = fYearValue.divide(fCostUomYear, 12, BigDecimal.ROUND_HALF_EVEN);
-          localStrCost = fCost.toPlainString();
-        }
-      }
-    } else if (strChanged.equals("inpcostuomyear")) {
-      if (strCostUom.equals("H"))
-        if (strDaysYear != null && !strDaysYear.equals("") && strDayHours != null
-            && !strDayHours.equals("") && localStrCostUomYear != null
-            && !localStrCostUomYear.equals("")) {
-          BigDecimal fDaysYear = new BigDecimal(strDaysYear);
-          BigDecimal fDayHours = new BigDecimal(strDayHours);
-          BigDecimal fCostUomYear = new BigDecimal(localStrCostUomYear);
-          BigDecimal fImproductiveHoursYear = (fDaysYear.multiply(fDayHours))
-              .subtract(fCostUomYear);
-          localStrImproductiveHoursYear = fImproductiveHoursYear