From f0dd2096d5226d8d3c2e6aff4c65d71d4e201dc9 Mon Sep 17 00:00:00 2001 From: Anil Patel Date: Thu, 20 Sep 2007 19:58:03 +0000 Subject: [PATCH] added two report to get value of stock Inventory git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@577898 13f79535-47bb-0310-9956-ffa450edef68 --- .../product/config/ProductUiLabels.properties | 3 + .../actions/inventory/InventoryItemTotals.bsh | 107 ++++++++++++++++++ .../webapp/facility/WEB-INF/controller.xml | 10 ++ .../facility/facility/FacilityForms.xml | 19 ++++ .../widget/facility/FacilityScreens.xml | 52 +++++++++ 5 files changed, 191 insertions(+) create mode 100644 applications/product/webapp/facility/WEB-INF/actions/inventory/InventoryItemTotals.bsh diff --git a/applications/product/config/ProductUiLabels.properties b/applications/product/config/ProductUiLabels.properties index 7792ae7c57..90cf23c36b 100644 --- a/applications/product/config/ProductUiLabels.properties +++ b/applications/product/config/ProductUiLabels.properties @@ -434,6 +434,7 @@ ProductContent_Id=Content [ID] ProductCopyProductCategoryMembersToAnotherCategory=Copy Product Category Members to Another Category ProductCostPrice=Cost Price ProductCosts=Costs +ProductCostPrice=Cost Price ProductCouldNotFindFacilityWithId=Could Not Find Facility with ID ProductCouldNotFindProduct=Could Not Find Product with ID ProductCouldNotFindProductCategoryWithId=Could not Find Product Category with Id @@ -705,6 +706,8 @@ ProductInventoryItemTypeId=InventoryItem Type ID ProductInventoryItems=Inventory Items ProductInventoryItemsFor=Inventory Items for ProductInventoryItemsToPick=Inventory Items to Pick +ProductInventoryItemTotals=Inventory Item Totals +ProductInventoryItemGrandTotals=Inventory Item Grand Totals ProductInventoryMessage=Inventory Message ProductInventoryReceive=Receive Inventory ProductInventoryRequiredProduct=Should inventory be required to purchase this product? If not specified defaults to the Catalog setting. diff --git a/applications/product/webapp/facility/WEB-INF/actions/inventory/InventoryItemTotals.bsh b/applications/product/webapp/facility/WEB-INF/actions/inventory/InventoryItemTotals.bsh new file mode 100644 index 0000000000..402b2f8e69 --- /dev/null +++ b/applications/product/webapp/facility/WEB-INF/actions/inventory/InventoryItemTotals.bsh @@ -0,0 +1,107 @@ +/* + * 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 javolution.util.FastList; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.entity.*; +import org.ofbiz.entity.condition.*; +import org.ofbiz.entity.transaction.*; + +delegator = request.getAttribute("delegator"); +dispatcher = request.getAttribute("dispatcher"); + +action = request.getParameter("action"); + +inventoryItemTotals = FastList.newInstance(); +qohGrandTotal = 0.0; +atpGrandTotal = 0.0; +costPriceGrandTotal = 0.0; +retailPriceGrandTotal = 0.0; +totalCostPriceGrandTotal = 0.0; +totalRetailPriceGrandTotal = 0.0; +boolean beganTransaction = false; +if (action != null) { + conditions = UtilMisc.toList(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "INV_DELIVERED")); + conditions.add(new EntityExpr("statusId", EntityOperator.EQUALS, null)); + conditionList = new EntityConditionList(conditions, EntityOperator.OR); + try { + beganTransaction = TransactionUtil.begin(); + invItemListItr = delegator.findListIteratorByCondition("InventoryItem", conditionList, null, UtilMisc.toList("productId")); + while ((inventoryItem = invItemListItr.next()) != null) { + productId = inventoryItem.getString("productId"); + product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId)); + productFacility = delegator.findByPrimaryKey("ProductFacility", UtilMisc.toMap("productId", productId, "facilityId", facilityId)); + if (productFacility != null) { + quantityOnHandTotal = inventoryItem.getDouble("quantityOnHandTotal"); + availableToPromiseTotal = inventoryItem.getDouble("availableToPromiseTotal"); + costPrice = inventoryItem.getDouble("unitCost"); + retailPrice = 0.0; + productPrices = product.getRelated("ProductPrice"); + if (productPrices != null) { + productPriceItr = productPrices.iterator(); + while (productPriceItr.hasNext()) { + productPrice = productPriceItr.next(); + if (("DEFAULT_PRICE").equals(productPrice.getString("productPriceTypeId"))) { + retailPrice = productPrice.getDouble("price"); + } + } + } + + totalCostPrice = costPrice * quantityOnHandTotal; + totalRetailPrice = retailPrice * availableToPromiseTotal; + qohGrandTotal += quantityOnHandTotal; + atpGrandTotal += availableToPromiseTotal; + costPriceGrandTotal += costPrice; + retailPriceGrandTotal += retailPrice; + totalCostPriceGrandTotal += totalCostPrice; + totalRetailPriceGrandTotal += totalRetailPrice; + + resultMap = UtilMisc.toMap("productId", product.getString("productId"), "quantityOnHand", quantityOnHandTotal, "availableToPromise", availableToPromiseTotal, + "costPrice", costPrice, "retailPrice", retailPrice); + resultMap.put("totalCostPrice", totalCostPrice); + resultMap.put("totalRetailPrice", totalRetailPrice); + inventoryItemTotals.add(resultMap); + } + } + invItemListItr.close(); + } catch (GenericEntityException e) { + String errMsg = "Failure in operation, rolling back transaction"; + Debug.logError(e, errMsg, "findInventoryItemsByLabels"); + try { + // only rollback the transaction if we started one... + TransactionUtil.rollback(beganTransaction, errMsg, e); + } catch (GenericEntityException e2) { + Debug.logError(e2, "Could not rollback transaction: " + e2.toString(), "findInventoryItemsByLabels"); + } + // after rolling back, rethrow the exception + throw e; + } finally { + // only commit the transaction if we started one... this will throw an exception if it fails + TransactionUtil.commit(beganTransaction); + } + +} + +inventoryItemGrandTotals = FastList.newInstance(); +inventoryItemGrandTotals.add(UtilMisc.toMap("qohGrandTotal", qohGrandTotal, "atpGrandTotal", atpGrandTotal, + "totalCostPriceGrandTotal", totalCostPriceGrandTotal, "totalRetailPriceGrandTotal", totalRetailPriceGrandTotal)); + +context.put("inventoryItemTotals", inventoryItemTotals); +context.put("inventoryItemGrandTotals", inventoryItemGrandTotals); diff --git a/applications/product/webapp/facility/WEB-INF/controller.xml b/applications/product/webapp/facility/WEB-INF/controller.xml index 0a5b7660b9..073d089877 100644 --- a/applications/product/webapp/facility/WEB-INF/controller.xml +++ b/applications/product/webapp/facility/WEB-INF/controller.xml @@ -1127,6 +1127,14 @@ under the License. + + + + + + + + @@ -1211,6 +1219,8 @@ under the License. + + diff --git a/applications/product/webapp/facility/facility/FacilityForms.xml b/applications/product/webapp/facility/facility/FacilityForms.xml index ec544d8217..9a10cfbb8f 100644 --- a/applications/product/webapp/facility/facility/FacilityForms.xml +++ b/applications/product/webapp/facility/facility/FacilityForms.xml @@ -343,4 +343,23 @@ under the License. +
+ + + + + + + + + +
+
+ + + + +
diff --git a/applications/product/widget/facility/FacilityScreens.xml b/applications/product/widget/facility/FacilityScreens.xml index 8d69791566..d37cb9a523 100644 --- a/applications/product/widget/facility/FacilityScreens.xml +++ b/applications/product/widget/facility/FacilityScreens.xml @@ -244,6 +244,8 @@ under the License. + + @@ -364,6 +366,56 @@ under the License. + +
+ + + + + + + + + +