From 53c1eff60c051f86f0970e514b4eb17e8b8f3431 Mon Sep 17 00:00:00 2001 From: Jacopo Cappellato Date: Tue, 5 Dec 2006 22:00:29 +0000 Subject: [PATCH] First commit of the "hhfacility" component a special purpose application for warehouse operations done using hand held devices. The application is still in a very initial stage, a lot of cleanups still need to be done, but it is a nice start. It has been contributed by Daniel Goodwin and Ray Barlow; see OFBIZ-226 for details. Daniel, Ray many thanks to both of you. git-svn-id: https://svn.apache.org/repos/asf/incubator/ofbiz/trunk@482801 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/ofbiz/hhfacility/FacilitySession.java | 88 ++++++ .../hhfacility/WEB-INF/actions/facilities.bsh | 23 ++ .../WEB-INF/actions/productlist.bsh | 25 ++ .../WEB-INF/actions/productstocktake.bsh | 111 +++++++ .../webapp/hhfacility/WEB-INF/web.xml | 91 ++++++ .../webapp/hhfacility/includes/footer.ftl | 32 ++ .../hhfacility/webapp/hhfacility/login.ftl | 93 ++++++ .../widget/hhfacility/FacilityScreens.xml | 289 ++++++++++++++++++ 8 files changed, 752 insertions(+) create mode 100644 specialpurpose/hhfacility/src/org/ofbiz/hhfacility/FacilitySession.java create mode 100644 specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/facilities.bsh create mode 100644 specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/productlist.bsh create mode 100644 specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/productstocktake.bsh create mode 100644 specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/web.xml create mode 100644 specialpurpose/hhfacility/webapp/hhfacility/includes/footer.ftl create mode 100644 specialpurpose/hhfacility/webapp/hhfacility/login.ftl create mode 100644 specialpurpose/hhfacility/widget/hhfacility/FacilityScreens.xml 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 @@ + + + + + + Facility Handheld Application + Facility Handheld Application + + + localDispatcherName + hhfacility + A unique name used to identify/recognize the local dispatcher for the Service Engine + + + serviceReaderUrls + /WEB-INF/services.xml + Configuration File(s) For The Service Dispatcher + + + entityDelegatorName + default + The Name of the Entity Delegator to use, defined in entityengine.xml + + + + ContextFilter + ContextFilter + org.ofbiz.webapp.control.ContextFilter + + disableContextSecurity + N + + + allowedPaths + /control:/select:/index.html:/index.jsp:/default.html:/default.jsp:/images:/includes/maincss.css + + + errorCode + 403 + + + redirectPath + /control/main + + + + ContextFilter + /* + + + org.ofbiz.webapp.control.ControlEventListener + org.ofbiz.webapp.control.LoginEventListener + + + + + ControlServlet + ControlServlet + Main Control Servlet + org.ofbiz.webapp.control.ControlServlet + 1 + + + ControlServlet + /control/* + + + + 60 + + + + index.jsp + index.html + index.htm + + diff --git a/specialpurpose/hhfacility/webapp/hhfacility/includes/footer.ftl b/specialpurpose/hhfacility/webapp/hhfacility/includes/footer.ftl new file mode 100644 index 0000000000..5c7a077b7c --- /dev/null +++ b/specialpurpose/hhfacility/webapp/hhfacility/includes/footer.ftl @@ -0,0 +1,32 @@ +<#-- +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. +--> + + + + + + + + + + +Hand Held Facility + + + + + + \ No newline at end of file diff --git a/specialpurpose/hhfacility/webapp/hhfacility/login.ftl b/specialpurpose/hhfacility/webapp/hhfacility/login.ftl new file mode 100644 index 0000000000..b5fa159609 --- /dev/null +++ b/specialpurpose/hhfacility/webapp/hhfacility/login.ftl @@ -0,0 +1,93 @@ +<#-- +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. +--> + +<#assign previousParams = sessionAttributes._PREVIOUS_PARAMS_?if_exists> +<#if previousParams?has_content> + <#assign previousParams = "?" + previousParams> + + +<#assign username = requestParameters.USERNAME?default((sessionAttributes.autoUserLogin.userLoginId)?default(""))> +<#if username != ""> + <#assign focusName = false> +<#else> + <#assign focusName = true> + + + + + + +
+ + + + + + + +
+ + + + +
+
Login
+
+
+ + + + +
+
+ + + + + + + + + + + + +
+ Username  + + +
+ Password  + + +
+ + +
+
+
+
+
+ + diff --git a/specialpurpose/hhfacility/widget/hhfacility/FacilityScreens.xml b/specialpurpose/hhfacility/widget/hhfacility/FacilityScreens.xml new file mode 100644 index 0000000000..7e1865932c --- /dev/null +++ b/specialpurpose/hhfacility/widget/hhfacility/FacilityScreens.xml @@ -0,0 +1,289 @@ + + + + + +
+ + + + + + +
+
+ + +
+ + + +
+
+ + +
+ + + + + + + + + + + + + + +
+
+ + +
+ + + + + + + + + +
+
+ + +
+ + + +
+ + + + +
+
+ + + + +
+
+
+
+
+
+ + +
+ + + + + + + +
+
+ + +
+ + + + + + + + + + +
+
+ + +
+ + + + + + + + + + +
+
+ + +
+ + + + + + + + + +
+
+ + +
+ + + + + + + + + + + + + + +
+
+ + +
+ + + + + + + + + + + + + +
+
+ + +
+ + + + + + + + + +
+
+ + +
+ + + + + + + + + +
+
+ + +
+ + + + + + + + + +
+
+ + +
+ + +