KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > model > CalloutInventory


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.model;
15
16 import java.util.*;
17 import java.math.*;
18 import java.sql.*;
19
20 import org.compiere.util.*;
21
22 /**
23  * Physical Inventory Callouts
24  *
25  * @author Jorg Janke
26  * @version $Id: CalloutInventory.java,v 1.2 2003/10/17 06:15:20 jjanke Exp $
27  */

28 public class CalloutInventory extends CalloutEngine
29 {
30     /**
31      * Product modified.
32      * Set Attribute Set Instance
33      *
34      * @param ctx Context
35      * @param WindowNo current Window No
36      * @param mTab Model Tab
37      * @param mField Model Field
38      * @param value The new value
39      * @return Error message or ""
40      */

41     public String JavaDoc product (Properties ctx, int WindowNo, MTab mTab, MField mField, Object JavaDoc value)
42     {
43         Integer JavaDoc M_Product_ID = (Integer JavaDoc)value;
44         if (M_Product_ID == null || M_Product_ID.intValue() == 0)
45             return "";
46         // Set Attribute
47
if (Env.getContextAsInt(ctx, Env.WINDOW_INFO, Env.TAB_INFO, "M_Product_ID") == M_Product_ID.intValue()
48             && Env.getContextAsInt(ctx, Env.WINDOW_INFO, Env.TAB_INFO, "M_AttributeSetInstance_ID") != 0)
49             mTab.setValue("M_AttributeSetInstance_ID", new Integer JavaDoc(Env.getContextAsInt(ctx, Env.WINDOW_INFO, Env.TAB_INFO, "M_AttributeSetInstance_ID")));
50         else
51             mTab.setValue("M_AttributeSetInstance_ID", null);
52             
53             
54         Integer JavaDoc ID = (Integer JavaDoc)mTab.getValue("M_InventoryLine_ID");
55         // New Line - Get Book Value
56
if (ID != null && ID.intValue() == 0)
57         {
58             // Set QtyBook from first storage location (not correct)
59
int M_Locator_ID = Env.getContextAsInt(ctx, WindowNo, "M_Locator_ID");
60             String JavaDoc sql = "SELECT QtyOnHand FROM M_Storage "
61                 + "WHERE M_Product_ID=?" // 1
62
+ " AND M_Locator_ID=?"; // 2
63
try
64             {
65                 PreparedStatement pstmt = DB.prepareStatement(sql);
66                 pstmt.setInt(1, M_Product_ID.intValue());
67                 pstmt.setInt(2, M_Locator_ID);
68                 ResultSet rs = pstmt.executeQuery();
69                 if (rs.next())
70                 {
71                     BigDecimal bd = rs.getBigDecimal(1);
72                     if (!rs.wasNull())
73                         mTab.setValue("QtyBook", bd);
74                 }
75                 rs.close();
76                 pstmt.close();
77             }
78             catch (SQLException e)
79             {
80                 log.error("product", e);
81                 return e.getLocalizedMessage();
82             }
83         }
84         
85         return "";
86     } // product
87

88 } // CalloutInventory
89
Popular Tags