/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 java.util.*; import java.io.*; import org.ofbiz.entity.*; import org.ofbiz.base.util.*; import org.ofbiz.widget.html.*; delegator = request.getAttribute("delegator"); parameterMap = UtilHttp.getParameterMap(request); facilityId = request.getParameter("facilityId"); locationSeqId = request.getParameter("locationSeqId"); session.removeAttribute("inventoryItemId"); boolean tryEntity = true; if (request.getAttribute("_ERROR_MESSAGE_") != null) tryEntity = false; inventoryItemId = request.getParameter("inventoryItemId"); if (UtilValidate.isEmpty(inventoryItemId) && UtilValidate.isNotEmpty((String) request.getAttribute("inventoryItemId"))) { inventoryItemId = request.getAttribute("inventoryItemId"); } inventoryItem = delegator.findByPrimaryKey("InventoryItem", UtilMisc.toMap("inventoryItemId", inventoryItemId)); curStatusItem = null; inventoryItemType = null; facilityLocation = null; facility = null; if(inventoryItem == null) { tryEntity = false; } else { curStatusItem = inventoryItem.getRelatedOneCache("StatusItem"); inventoryItemType = inventoryItem.getRelatedOneCache("InventoryItemType"); facilityLocation = inventoryItem.getRelatedOne("FacilityLocation"); facility = inventoryItem.getRelatedOne("Facility"); if (facility != null && facilityId == null) { facilityId = facility.getString("facilityId"); parameters.put("facilityId", facilityId); } //statuses if ("NON_SERIAL_INV_ITEM".equals(inventoryItem.getString("inventoryItemTypeId"))) { //do nothing for non-serialized inventory } else if ("SERIALIZED_INV_ITEM".equals(inventoryItem.getString("inventoryItemTypeId"))) { if (UtilValidate.isNotEmpty(inventoryItem.getString("statusId"))) { statusChange = delegator.findByAnd("StatusValidChange", UtilMisc.toMap("statusId", inventoryItem.getString("statusId"))); statusItems = new ArrayList(); statusChangeIter = statusChange.iterator(); while (statusChangeIter.hasNext()) { iterStatusChange = statusChangeIter.next(); iterStatusItem = delegator.findByPrimaryKey("StatusItem", UtilMisc.toMap("statusId", iterStatusChange.get("statusIdTo"))); if (iterStatusItem != null) statusItems.add(iterStatusItem); } context.put("statusItems", statusItems); } else { //no status id, just get all statusItems statusItems = delegator.findByAnd("StatusItem", UtilMisc.toMap("statusTypeId", "INV_SERIALIZED_STTS"), UtilMisc.toList("sequenceId")); context.put("statusItems", statusItems); } } } //inv item types inventoryItemTypes = delegator.findAll("InventoryItemType", UtilMisc.toList("description")); //facilities facilities = delegator.findAll("Facility", UtilMisc.toList("facilityName")); //get physicalInventoryAndVarianceDatas if this is a NON_SERIAL_INV_ITEM if (inventoryItem != null && "NON_SERIAL_INV_ITEM".equals(inventoryItem.getString("inventoryItemTypeId"))) { physicalInventoryAndVariances = delegator.findByAnd("PhysicalInventoryAndVariance", UtilMisc.toMap("inventoryItemId", inventoryItemId), UtilMisc.toList("-physicalInventoryDate", "-physicalInventoryId")); physicalInventoryAndVarianceDatas = new ArrayList(physicalInventoryAndVariances.size()); physicalInventoryAndVarianceIter = physicalInventoryAndVariances.iterator(); while (physicalInventoryAndVarianceIter.hasNext()) { physicalInventoryAndVariance = physicalInventoryAndVarianceIter.next(); physicalInventoryAndVarianceData = new HashMap(); physicalInventoryAndVarianceDatas.add(physicalInventoryAndVarianceData); physicalInventoryAndVarianceData.put("physicalInventoryAndVariance", physicalInventoryAndVariance); physicalInventoryAndVarianceData.put("varianceReason", physicalInventoryAndVariance.getRelatedOneCache("VarianceReason")); physicalInventoryAndVarianceData.put("person", physicalInventoryAndVariance.getRelatedOne("Person")); physicalInventoryAndVarianceData.put("partyGroup", physicalInventoryAndVariance.getRelatedOne("PartyGroup")); } context.put("physicalInventoryAndVarianceDatas", physicalInventoryAndVarianceDatas); } nowTimestampString = UtilDateTime.nowTimestamp().toString(); context.put("inventoryItem", inventoryItem); context.put("inventoryItemId", inventoryItemId); context.put("inventoryItemType", inventoryItemType); context.put("curStatusItem", curStatusItem); context.put("facilityLocation", facilityLocation); context.put("facility", facility); context.put("facilityId", facilityId); context.put("locationSeqId", locationSeqId); context.put("inventoryItemTypes", inventoryItemTypes); context.put("facilities", facilities); context.put("nowTimestampString", nowTimestampString); context.put("tryEntity", tryEntity); if (tryEntity) { context.put("inventoryItemData", inventoryItem); } else { context.put("inventoryItemData", parameterMap); }