details:   https://code.openbravo.com/erp/devel/pi/rev/c978371677b2
changeset: 21332:c978371677b2
user:      David Miguelez <david.miguelez <at> openbravo.com>
date:      Mon Oct 21 10:55:56 2013 +0200
summary:   Adds new Hooks to ProcessInvoice and GenerateInvoicesManual 
processes.
Contribution done by Daniel Martins: [email protected]

diffstat:

 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ProcessInvoiceHook.java
             |   39 +++
 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/ProcessInvoice.java
 |   61 +++++-
 src/org/openbravo/erpCommon/ad_forms/GenerateInvoicesHook.java                 
                           |   38 +++
 src/org/openbravo/erpCommon/ad_forms/GenerateInvoicesmanual.java               
                           |  110 +++++++++-
 src/org/openbravo/erpCommon/ad_forms/GenerateInvoicesmanual_data.xsql          
                           |   13 +-
 src/org/openbravo/erpCommon/reference/PInstanceProcess_data.xsql               
                           |   10 +
 6 files changed, 259 insertions(+), 12 deletions(-)

diffs (truncated from 432 to 300 lines):

diff -r cf31b113f28f -r c978371677b2 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ProcessInvoiceHook.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ProcessInvoiceHook.java
     Mon Oct 21 10:55:56 2013 +0200
@@ -0,0 +1,39 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2013 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  
+ *************************************************************************
+ */
+package org.openbravo.advpaymentmngt;
+
+import org.openbravo.erpCommon.utility.OBError;
+import org.openbravo.model.common.invoice.Invoice;
+
+/**
+ * @author <a href="mailto:[email protected]";>Daniel Martins</a>
+ * 
+ */
+public interface ProcessInvoiceHook {
+
+  /*
+   * Returns an OBError when an error occurred and null if it succeed
+   */
+  public OBError preProcess(Invoice invoice, String strDocAction);
+
+  /*
+   * Returns an OBError when an error occurred and null if it succeed
+   */
+  public OBError postProcess(Invoice invoice, String strDocAction);
+}
diff -r cf31b113f28f -r c978371677b2 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/ProcessInvoice.java
--- 
a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/ProcessInvoice.java
 Mon Oct 21 09:54:38 2013 +0200
+++ 
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/ProcessInvoice.java
 Mon Oct 21 10:55:56 2013 +0200
@@ -29,11 +29,15 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.hibernate.criterion.Restrictions;
+import org.openbravo.advpaymentmngt.ProcessInvoiceHook;
 import org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao;
 import org.openbravo.advpaymentmngt.process.FIN_AddPayment;
 import org.openbravo.advpaymentmngt.process.FIN_PaymentProcess;
@@ -75,6 +79,10 @@
   private final AdvPaymentMngtDao dao = new AdvPaymentMngtDao();
   private static final String Purchase_Invoice_Window = "183";
 
+  @Inject
+  @Any
+  private Instance<ProcessInvoiceHook> hooks;
+
   public void doPost(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {
     VariablesSecureApp vars = new VariablesSecureApp(request);
@@ -133,6 +141,19 @@
         OBDal.getInstance().save(invoice);
         OBDal.getInstance().flush();
 
+        OBError msg = null;
+        for (ProcessInvoiceHook hook : hooks) {
+          msg = hook.preProcess(invoice, strdocaction);
+          if (msg != null && "Error".equals(msg.getType())) {
+            vars.setMessage(strTabId, msg);
+            String strWindowPath = Utility.getTabURL(strTabId, "R", true);
+            if (strWindowPath.equals(""))
+              strWindowPath = strDefaultServlet;
+            printPageClosePopUp(response, vars, strWindowPath);
+            return;
+          }
+        }
+
         OBContext.setAdminMode(true);
         Process process = null;
         try {
@@ -186,16 +207,51 @@
         }
         OBDal.getInstance().save(invoice);
         OBDal.getInstance().flush();
+
+        OBContext.setAdminMode();
+        try {
+          // on error close popup
+          if (pinstance.getResult() == 0L) {
+            OBDal.getInstance().commitAndClose();
+            final PInstanceProcessData[] pinstanceData = 
PInstanceProcessData.select(this,
+                pinstance.getId());
+            myMessage = Utility.getProcessInstanceMessage(this, vars, 
pinstanceData);
+            log4j.debug(myMessage.getMessage());
+            vars.setMessage(strTabId, myMessage);
+
+            String strWindowPath = Utility.getTabURL(strTabId, "R", true);
+            if (strWindowPath.equals(""))
+              strWindowPath = strDefaultServlet;
+            printPageClosePopUp(response, vars, strWindowPath);
+            return;
+          }
+        } finally {
+          OBContext.restorePreviousMode();
+        }
+
+        for (ProcessInvoiceHook hook : hooks) {
+          msg = hook.postProcess(invoice, strdocaction);
+          if (msg != null && "Error".equals(msg.getType())) {
+            vars.setMessage(strTabId, msg);
+            String strWindowPath = Utility.getTabURL(strTabId, "R", true);
+            if (strWindowPath.equals(""))
+              strWindowPath = strDefaultServlet;
+            printPageClosePopUp(response, vars, strWindowPath);
+            OBDal.getInstance().rollbackAndClose();
+            return;
+          }
+        }
+
         OBDal.getInstance().commitAndClose();
         final PInstanceProcessData[] pinstanceData = 
PInstanceProcessData.select(this,
             pinstance.getId());
         myMessage = Utility.getProcessInstanceMessage(this, vars, 
pinstanceData);
         log4j.debug(myMessage.getMessage());
         vars.setMessage(strTabId, myMessage);
+
         OBContext.setAdminMode();
         try {
-          // on error close popup
-          if (pinstance.getResult() == 0L || !"CO".equals(strdocaction)) {
+          if (!"CO".equals(strdocaction)) {
             String strWindowPath = Utility.getTabURL(strTabId, "R", true);
             if (strWindowPath.equals(""))
               strWindowPath = strDefaultServlet;
@@ -625,3 +681,4 @@
     return "Servlet to Process Invoice";
   }
 }
+
diff -r cf31b113f28f -r c978371677b2 
src/org/openbravo/erpCommon/ad_forms/GenerateInvoicesHook.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/erpCommon/ad_forms/GenerateInvoicesHook.java    Mon Oct 
21 10:55:56 2013 +0200
@@ -0,0 +1,38 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2013 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  
+ *************************************************************************
+ */
+
+package org.openbravo.erpCommon.ad_forms;
+
+import java.sql.Connection;
+import java.util.List;
+
+import org.openbravo.erpCommon.utility.OBError;
+import org.openbravo.model.common.order.Order;
+
+/**
+ * @author <a href="mailto:[email protected]";>Daniel Martins</a>
+ * 
+ */
+public interface GenerateInvoicesHook {
+
+  /*
+   * Returns an OBError when an error occurred and null if it succeed
+   */
+  public OBError executeHook(Connection conn, List<Order> orders, OBError 
myMessage);
+}
diff -r cf31b113f28f -r c978371677b2 
src/org/openbravo/erpCommon/ad_forms/GenerateInvoicesmanual.java
--- a/src/org/openbravo/erpCommon/ad_forms/GenerateInvoicesmanual.java  Mon Oct 
21 09:54:38 2013 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/GenerateInvoicesmanual.java  Mon Oct 
21 10:55:56 2013 +0200
@@ -22,17 +22,26 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
 
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.hibernate.criterion.Restrictions;
 import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.dal.service.OBCriteria;
+import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.businessUtility.Tree;
 import org.openbravo.erpCommon.businessUtility.WindowTabs;
-import org.openbravo.erpCommon.reference.ActionButtonData;
 import org.openbravo.erpCommon.reference.PInstanceProcessData;
 import org.openbravo.erpCommon.utility.ComboTableData;
 import org.openbravo.erpCommon.utility.DateTimeData;
@@ -42,11 +51,17 @@
 import org.openbravo.erpCommon.utility.SequenceIdData;
 import org.openbravo.erpCommon.utility.ToolBar;
 import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.exception.NoConnectionAvailableException;
+import org.openbravo.model.common.order.Order;
 import org.openbravo.xmlEngine.XmlDocument;
 
 public class GenerateInvoicesmanual extends HttpSecureAppServlet {
   private static final long serialVersionUID = 1L;
 
+  @Inject
+  @Any
+  private Instance<GenerateInvoicesHook> hooks;
+
   public void doPost(HttpServletRequest request, HttpServletResponse response) 
throws IOException,
       ServletException {
     VariablesSecureApp vars = new VariablesSecureApp(request);
@@ -81,13 +96,33 @@
       printPageDataSheet(response, vars, strC_BPartner_ID, strAD_Org_ID, 
strDateFrom, strDateTo,
           strIncludeTaxes, strInvDate);
     } else if (vars.commandIn("GENERATE")) {
+      Connection conn = null;
+      OBError myMessage = null;
+      try {
+        conn = getTransactionConnection();
+        conn.setAutoCommit(false);
+      } catch (NoConnectionAvailableException e1) {
+        log4j.error(e1.getMessage(), e1);
+
+        myMessage = handleException("NoDBConnection", vars);
+      } catch (SQLException e) {
+        log4j.error(e.getMessage(), e);
+
+        myMessage = handleException("NoDBConnection", vars);
+      }
+      if (myMessage != null) {
+        vars.setMessage("GenerateInvoicesmanual", myMessage);
+        response.sendRedirect(strDireccion + request.getServletPath());
+        return;
+      }
+
       String strCOrderId = vars.getInStringParameter("inpOrder", 
IsIDFilter.instance);
       String strInvDate = vars.getRequestGlobalVariable("inpInvDate",
           "GenerateInvoicesmanual|invDate");
       if (strCOrderId.equals(""))
         strCOrderId = "('0')";
-      GenerateInvoicesmanualData.initUpdate(this);
-      GenerateInvoicesmanualData.updateSelection(this, strCOrderId);
+      GenerateInvoicesmanualData.initUpdate(conn, this);
+      GenerateInvoicesmanualData.updateSelection(conn, this, strCOrderId);
       String pinstance = SequenceIdData.getUUID();
       PInstanceProcessData.insertPInstance(this, pinstance, "134", "0", "N", 
vars.getUser(),
           vars.getClient(), vars.getOrg());
@@ -97,17 +132,50 @@
         PInstanceProcessData.insertPInstanceParamDate(this, pinstance, "2", 
"DateInvoiced",
             strInvDate, vars.getClient(), vars.getOrg(), vars.getUser());
       }
-      ActionButtonData.process134(this, pinstance);
-      PInstanceProcessData[] pinstanceData = PInstanceProcessData.select(this, 
pinstance);
-      OBError myMessage = new OBError();
+
+      GenerateInvoicesmanualData.process134(conn, this, pinstance);
+
+      PInstanceProcessData[] pinstanceData = PInstanceProcessData.select(conn, 
this, pinstance);
+      myMessage = new OBError();
       String message = "";
       myMessage.setTitle("");
       myMessage = Utility.getProcessInstanceMessage(this, vars, pinstanceData);
       vars.setMessage("GenerateInvoicesmanual", myMessage);
-      GenerateInvoicesmanualData.resetSelection(this, strCOrderId);
+      GenerateInvoicesmanualData.resetSelection(conn, this, strCOrderId);
       if (log4j.isDebugEnabled())
         log4j.debug(message);
+

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to