KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > manufacturing > mrp > InventoryEventPlannedServices


1 /*
2  * $Id: InventoryEventPlannedServices.java 7238 2006-04-08 07:30:54Z jacopo $
3  *
4  * Copyright (c) 2003, 2004 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.manufacturing.mrp;
26
27 import java.util.HashMap JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import org.ofbiz.base.util.Debug;
31 import org.ofbiz.base.util.UtilMisc;
32 import org.ofbiz.entity.GenericDelegator;
33 import org.ofbiz.entity.GenericEntityException;
34 import org.ofbiz.entity.GenericValue;
35 import org.ofbiz.service.DispatchContext;
36 import org.ofbiz.service.ServiceUtil;
37
38 /**
39  * InventoryEventPlannedServices - InventoryEventPlanned related Services
40  *
41  * @author <a HREF="mailto:olivier.heintz@nereide.biz">Olivier Heintz</a>
42  */

43 public class InventoryEventPlannedServices {
44     
45     public static final String JavaDoc module = InventoryEventPlannedServices.class.getName();
46    
47     /**
48      *
49      * Create an InventoryEventPlanned.
50      * Make an update if a record exist with same key, (adding the eventQuantity to the exiting record)
51      *
52      * @param ctx
53      * @param context: a map containing the parameters used to create an InventoryEventPlanned (see the servcie definition)
54      * @return result: a map with service status
55      */

56     public static Map JavaDoc createInventoryEventPlanned(DispatchContext ctx, Map JavaDoc context) {
57         GenericDelegator delegator = ctx.getDelegator();
58         // No permission checking because this services is call from other services/
59
Map JavaDoc parameters = UtilMisc.toMap("productId", context.get("productId"),
60                                         "eventDate", context.get("eventDate"),
61                                         "inventoryEventPlanTypeId",context.get("inventoryEventPlanTypeId"));
62         Double JavaDoc quantity = (Double JavaDoc)context.get("eventQuantity");
63         GenericValue inventoryEventPlanned = null;
64         try {
65             createOrUpdateInventoryEventPlanned(parameters, quantity, delegator);
66         } catch (GenericEntityException e) {
67             Debug.logError(e,"Error : delegator.findByPrimaryKey(\"InventoryEventPlanned\", parameters =)"+parameters, module);
68             return ServiceUtil.returnError("Problem, on database access, for more detail look at the log");
69         }
70         return ServiceUtil.returnSuccess();
71     }
72
73     public static void createOrUpdateInventoryEventPlanned(Map JavaDoc inventoryEventPlannedKeyMap, Double JavaDoc newQuantity, GenericDelegator delegator) throws GenericEntityException {
74         GenericValue inventoryEventPlanned = null;
75         inventoryEventPlanned = delegator.findByPrimaryKey("InventoryEventPlanned", inventoryEventPlannedKeyMap);
76         if (inventoryEventPlanned == null) {
77             inventoryEventPlanned = delegator.makeValue("InventoryEventPlanned", inventoryEventPlannedKeyMap);
78             inventoryEventPlanned.put("eventQuantity", newQuantity);
79             inventoryEventPlanned.create();
80         } else {
81             double qties = newQuantity.doubleValue() + ((Double JavaDoc)inventoryEventPlanned.get("eventQuantity")).doubleValue();
82             inventoryEventPlanned.put("eventQuantity", new Double JavaDoc(qties));
83             inventoryEventPlanned.store();
84         }
85     }
86
87 }
88
Popular Tags