diff --git a/specialpurpose/hhfacility/src/org/ofbiz/hhfacility/FacilitySession.java b/specialpurpose/hhfacility/src/org/ofbiz/hhfacility/FacilitySession.java
new file mode 100644
index 0000000000..214959186c
--- /dev/null
+++ b/specialpurpose/hhfacility/src/org/ofbiz/hhfacility/FacilitySession.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2001-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.ofbiz.hhfacility;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+import java.io.IOException;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.GeneralRuntimeException;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.webapp.control.RequestHandler;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.service.ServiceUtil;
+
+public class FacilitySession {
+
+ public static final String module = FacilitySession.class.getName();
+
+ public static final String findProductsById(HttpServletRequest request, HttpServletResponse response) {
+ HttpSession session = request.getSession();
+ String idValueStr = request.getParameter("idValue");
+ String facilityIdStr = request.getParameter("facilityId");
+ LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
+
+ if (UtilValidate.isEmpty(idValueStr)) {
+ return "success";
+ }
+
+ Map productsMap = null;
+ try {
+ productsMap = dispatcher.runSync("findProductsById", UtilMisc.toMap("idValue", idValueStr, "facilityId", facilityIdStr));
+ } catch (GenericServiceException e) {
+ Debug.logError(e, "Problem in findProductsById", module);
+ return "error";
+ }
+
+ if (ServiceUtil.isError(productsMap)) {
+ return "error";
+ }
+
+ List productList = (List)productsMap.get("productList");
+ if (productList != null && productList.size() == 1) {
+ // Found only one product so go get it and redirect to the edit page
+ ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
+ RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
+ GenericValue product = EntityUtil.getFirst(productList);
+ String requestName = "/productstocktake?facilityId=" + facilityIdStr + "&productId=" + product.getString("productId");;
+ String target = rh.makeLink(request, response, requestName, false, false, false);
+ try {
+ response.sendRedirect(target);
+ return "none";
+ } catch (IOException e) {
+ Debug.logError(e, "Could not send redirect to: " + target, module);
+ }
+ }
+ request.setAttribute("productList", productList);
+ return "success";
+ }
+}
diff --git a/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/facilities.bsh b/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/facilities.bsh
new file mode 100644
index 0000000000..47670705a6
--- /dev/null
+++ b/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/facilities.bsh
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2001-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.ofbiz.entity.*;
+
+delegator = request.getAttribute("delegator");
+
+facilities = delegator.findAll("Facility");
+
+context.put("facilities", facilities);
\ No newline at end of file
diff --git a/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/productlist.bsh b/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/productlist.bsh
new file mode 100644
index 0000000000..e808953f26
--- /dev/null
+++ b/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/productlist.bsh
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2001-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.ofbiz.entity.*;
+
+delegator = request.getAttribute("delegator");
+
+productList = request.getAttribute("productList");
+if ( productList != null ) {
+ context.put("productList", productList);
+}
+
diff --git a/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/productstocktake.bsh b/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/productstocktake.bsh
new file mode 100644
index 0000000000..182e629785
--- /dev/null
+++ b/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/productstocktake.bsh
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2001-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.ofbiz.entity.*;
+import org.ofbiz.base.util.*;
+import org.ofbiz.entity.util.EntityUtil;
+
+import javolution.util.FastMap;
+
+delegator = request.getAttribute("delegator");
+
+productId = request.getParameter("productId");
+if ( productId == null ) {
+ productId = session.getAttribute("productId");
+}
+
+if ( productId != null ) {
+ product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId));
+ context.put("product", product);
+
+ facilityId = request.getParameter("facilityId");
+ contextInput = UtilMisc.toMap("productId",productId, "facilityId", facilityId);
+ resultOutput = dispatcher.runSync("getInventoryAvailableByFacility",contextInput);
+ quantitySummary = new HashMap();
+ quantitySummary.put("facilityId", facilityId);
+ quantitySummary.put("atp_qoh", ((Double)resultOutput.get("availableToPromiseTotal")).intValue() + " / " +
+ ((Double)resultOutput.get("quantityOnHandTotal")).intValue());
+ context.put("quantitySummary", quantitySummary);
+
+ // For now this just generates a visual list of locations set against the product for this facility.
+ // todo: Will need to be able to edit and change these values at some point in the future.
+ productFacilityLocList = delegator.findByAnd("ProductFacilityLocation", UtilMisc.toMap("productId", productId, "facilityId", facilityId));
+ productFacilityLocListIter = productFacilityLocList.iterator();
+ facStr = null;
+
+ while (productFacilityLocListIter.hasNext()) {
+ facilityLoc = productFacilityLocListIter.next();
+ if ( UtilValidate.isEmpty(facStr) ) {
+ facStr = facilityLoc.get("locationSeqId");
+ } else {
+ facStr = facStr + ", " + facilityLoc.get("locationSeqId");
+ }
+ }
+ context.put("productFacilityLocations", facStr);
+
+
+ // Now we build a list of locations for inventory items against the facility.
+ // todo: change this to a select from inv_items where productId and facilityId matches distinct (locationSeqId).
+ invItemList = delegator.findByAnd("InventoryItem",
+ UtilMisc.toMap("productId", productId, "facilityId", facilityId));
+
+ Map locations = new HashMap();
+
+ boolean negativeQOH = false;
+ invItemListIter = invItemList.iterator();
+ while (invItemListIter.hasNext()) {
+ invItem = invItemListIter.next();
+ int qoh = ((Double)invItem.get("quantityOnHandTotal")).intValue();
+ if ( qoh < 0 )
+ negativeQOH = true;
+ locationFound = (String)invItem.get("locationSeqId");
+ if ( locationFound == null ) {
+ locationFound = "nullField";
+ }
+ if ( locations.get(locationFound) == null ) {
+ locations.put(locationFound, locationFound);
+ }
+ }
+
+ // Go through and build the list of atp/qoh against each location
+ productFacilityLocations = new ArrayList();
+ locationsIter = locations.keySet().iterator();
+ while (locationsIter.hasNext()) {
+ location = locationsIter.next();
+ contextInput = UtilMisc.toMap("productId",productId, "facilityId", facilityId, "locationSeqId", location);
+ resultOutput = dispatcher.runSync("getInventoryAvailableByLocation",contextInput);
+ quantitySummary = new HashMap();
+ quantitySummary.put("productId", productId);
+ quantitySummary.put("facilityId", facilityId);
+ if ( "nullField".equals( location ) == true ) {
+ quantitySummary.put("locationSeqId", "");
+ } else {
+ quantitySummary.put("locationSeqId", location);
+ }
+ quantitySummary.put("atp_qoh", ((Double)resultOutput.get("availableToPromiseTotal")).intValue() + " / " +
+ ((Double)resultOutput.get("quantityOnHandTotal")).intValue());
+ productFacilityLocations.add(quantitySummary);
+ }
+
+ context.put("productQtyByLocations", productFacilityLocations);
+ if ( negativeQOH == true ) {
+ context.put("negativeQOH", "true");
+ }
+
+
+}
+
+
diff --git a/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/web.xml b/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/web.xml
new file mode 100644
index 0000000000..f09a2b7c4d
--- /dev/null
+++ b/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/web.xml
@@ -0,0 +1,91 @@
+
+
+
+
+