KickJava   Java API By Example, From Geeks To Geeks.

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


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 Smart 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.sql.*;
17 import java.util.*;
18 import java.math.*;
19
20 import org.compiere.util.*;
21
22 /**
23  * Project Issue Model
24  *
25  * @author Jorg Janke
26  * @version $Id: MProjectIssue.java,v 1.1 2003/09/05 04:59:48 jjanke Exp $
27  */

28 public class MProjectIssue extends X_C_ProjectIssue
29 {
30
31     /**
32      * Standard Constructor
33      * @param ctx context
34      * @param C_ProjectIssue_ID id
35      */

36     public MProjectIssue (Properties ctx, int C_ProjectIssue_ID)
37     {
38         super (ctx, C_ProjectIssue_ID);
39         /** if (C_ProjectIssue_ID == 0)
40         {
41         setC_ProjectIssue_ID (0);
42         setC_Project_ID (0);
43         setLine (0);
44         setM_Locator_ID (0);
45         setM_Product_ID (0);
46         setMovementDate (new Timestamp(System.currentTimeMillis()));
47         setMovementQty (Env.ZERO);
48         setPosted (false);
49         setProcessed (false);
50         }
51         **/

52     } // MProjectIssue
53

54     /**
55      * Load Constructor
56      * @param ctx context
57      * @param rs result set
58      */

59     public MProjectIssue (Properties ctx, ResultSet rs)
60     {
61         super (ctx, rs);
62     } // MProjectIssue
63

64     /**
65      * New Parent Constructor
66      * @param project parent
67      */

68     public MProjectIssue (MProject project)
69     {
70         super (project.getCtx(), 0);
71         setClientOrg(project.getAD_Client_ID(), project.getAD_Org_ID());
72         setC_Project_ID (project.getC_Project_ID()); // Parent
73
// setC_ProjectIssue_ID (0); // PK
74
setLine (getNextLine());
75         //
76
setM_Locator_ID (0);
77         setM_Product_ID (0);
78         //
79
setMovementDate (new Timestamp(System.currentTimeMillis()));
80         setMovementQty (Env.ZERO);
81         setPosted (false);
82         setProcessed (false);
83     } // MProjectIssue
84

85     /**
86      * Get the next Line No
87      * @return next line no
88      */

89     private int getNextLine()
90     {
91         return DB.getSQLValue("SELECT COALESCE(MAX(Line),0)+10 FROM C_ProjectIssue WHERE C_Project_ID=?", getC_Project_ID());
92     } // getLineFromProject
93

94     /**
95      * Set Mandatory Values
96      * @param M_Locator_ID locator
97      * @param M_Product_ID product
98      * @param MovementQty qty
99      */

100     public void setMandatory (int M_Locator_ID, int M_Product_ID, BigDecimal MovementQty)
101     {
102         setM_Locator_ID (M_Locator_ID);
103         setM_Product_ID (M_Product_ID);
104         setMovementQty (MovementQty);
105     } // setMandatory
106

107     /*************************************************************************/
108
109     /**
110      * Process Issue
111      * @return true if processed
112      */

113     public boolean process()
114     {
115         if (!save())
116             return false;
117         if (getM_Product_ID() == 0)
118         {
119             log.error("process - No Product");
120             return false;
121         }
122
123         MProduct product = new MProduct (getCtx(), getM_Product_ID());
124
125         // If not a stocked Item nothing to do
126
if (MProduct.PRODUCTTYPE_Item.equals(product.getProductType()) && product.isStocked())
127         {
128             setProcessed(true);
129             return save();
130         }
131
132         /** @todo Transaction */
133
134         // ** Create Material Transactions **
135
MTransaction trx = new MTransaction (getCtx(), MTransaction.MOVEMENTTYPE_WorkOrderPlus,
136             getM_Locator_ID(), getM_Product_ID(), getM_AttributeSetInstance_ID(),
137             getMovementQty().negate(), getMovementDate());
138         //
139
if (MStorage.add(getCtx(), getM_Locator_ID(), getM_Product_ID(), getM_AttributeSetInstance_ID(),
140                 getMovementQty().negate(), null, null))
141         {
142             if (trx.save())
143             {
144                 setProcessed (true);
145                 if (save())
146                     return true;
147                 else
148                     log.error("process - Issue not saved"); // requires trx !!
149
}
150             else
151                 log.error("process - Transaction not saved"); // requires trx !!
152
}
153         else
154             log.error("process - Storage not updated"); // OK
155
//
156
return false;
157     } // process
158

159 } // MProjectIssue
160
Popular Tags