KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > acct > Doc_ProjectIssue


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.acct;
15
16 import java.math.*;
17 import java.util.*;
18 import java.sql.*;
19
20 import org.compiere.util.*;
21 import org.compiere.model.*;
22
23 /**
24  * Project Issue.
25  * Note:
26  * Will load the default GL Category.
27  * Set up a document type to set the GL Category.
28  *
29  * @author Jorg Janke
30  * @version $Id: Doc_ProjectIssue.java,v 1.2 2003/10/10 06:35:58 jjanke Exp $
31  */

32 public class Doc_ProjectIssue extends Doc
33 {
34     /** AD_Table_ID */
35     public static final int AD_TABLE_ID = 623;
36     /** Document Type */
37     public static final String JavaDoc DOCUMENTTYPE = "PJI";
38
39     /**
40      * Constructor
41      * @param AD_Client_ID client
42      */

43     public Doc_ProjectIssue (int AD_Client_ID)
44     {
45         super (AD_Client_ID);
46         p_vo.DocumentType = DOCUMENTTYPE;
47     } // DocInOut
48

49     /** Is it an Asset Project - default WIP */
50     private boolean m_assetProject = false;
51     /** Pseudo Line */
52     private DocLine_Material m_line = null;
53     /** Expense Report */
54     private int m_S_TimeExpenseLine_ID = 0;
55     /** Material Receipt */
56     private int m_M_InOutLine_ID = 0;
57
58
59     /**
60      * Get AD_Table_ID
61      * @return 623
62      */

63     public int getAD_Table_ID()
64     {
65         return AD_TABLE_ID;
66     } // get_Table_ID
67

68     /**
69      * Table Name
70      * @return M_InOut
71      */

72     public String JavaDoc getTableName()
73     {
74         return "C_ProjectIssue";
75     } // getTableName
76

77     /**
78      * Load Document Details
79      * @param rs result set
80      * @return true if loadDocumentType was set
81      */

82     protected boolean loadDocumentDetails(ResultSet rs)
83     {
84         p_vo.C_Currency_ID = NO_CURRENCY;
85         try
86         {
87             p_vo.DateDoc = rs.getTimestamp("MovementDate");
88             m_M_InOutLine_ID = rs.getInt("M_InOutLine_ID");
89             m_S_TimeExpenseLine_ID = rs.getInt("S_TimeExpenseLine_ID");
90             
91             // Pseudo Line
92
m_line = new DocLine_Material (p_vo.DocumentType, p_vo.Record_ID, p_vo.Record_ID);
93             m_line.loadAttributes(rs, p_vo);
94             m_line.setQty (rs.getBigDecimal("MovementQty")); // sets Trx and Storage Qty
95
m_line.setM_Locator_ID (rs.getInt("M_Locator_ID"));
96         }
97         catch (SQLException e)
98         {
99             log.error("loadDocumentDetails", e);
100         }
101         
102         // Pseudo Line Check
103
if (m_line.getM_Product_ID() == 0)
104             log.warn(m_line.toString() + " - No Product");
105         log.debug(m_line.toString());
106         
107         // Default is WIP project
108
loadProjectCategory();
109         return true;
110     } // loadDocumentDetails
111

112     /**
113      * Load Project Catefory from Project Type
114      */

115     private void loadProjectCategory()
116     {
117         String JavaDoc sql = "SELECT pj.ProjectCategory FROM C_ProjectType pj"
118             + " INNER JOIN C_Project p ON (p.C_ProjectType_ID=pj.C_ProjectType_ID) "
119             + "WHERE C_Project_ID=?";
120         PreparedStatement pstmt = null;
121         try
122         {
123             pstmt = DB.prepareCall(sql);
124             pstmt.setInt(1, p_vo.C_Project_ID);
125             ResultSet rs = pstmt.executeQuery();
126             if (rs.next())
127             {
128                 String JavaDoc pc = rs.getString(1);
129                 if (MProjectType.PROJECTCATEGORY_AssetProject.equals(pc))
130                     m_assetProject = true;
131             }
132             else
133                 log.warn("loadProjectCategory - Not found for C_Project_ID=" + p_vo.C_Project_ID);
134             rs.close();
135             pstmt.close();
136             pstmt = null;
137         }
138         catch (Exception JavaDoc e)
139         {
140             log.error("loadProjectCategory", e);
141         }
142         try
143         {
144             if (pstmt != null)
145                 pstmt.close();
146             pstmt = null;
147         }
148         catch (Exception JavaDoc e)
149         {
150             pstmt = null;
151         }
152     } // loadProjectCategory
153

154     /**
155      * Get Balance
156      * @return Zero (always balanced)
157      */

158     public BigDecimal getBalance()
159     {
160         BigDecimal retValue = Env.ZERO;
161         return retValue;
162     } // getBalance
163

164     /**
165      * Create Facts (the accounting logic) for
166      * PJI
167      * <pre>
168      * Issue
169      * Project DR
170      * Inventory CR
171      * </pre>
172      * Project Account is either Asset or WIP depending on Project Type
173      * @param as accounting schema
174      * @return Fact
175      */

176     public Fact createFact(AcctSchema as)
177     {
178         p_vo.C_Currency_ID = as.getC_Currency_ID();
179         // create Fact Header
180
Fact fact = new Fact(this, as, Fact.POST_Actual);
181
182         // Line pointers
183
FactLine dr = null;
184         FactLine cr = null;
185
186         // Issue Cost
187
BigDecimal cost = null;
188         if (m_M_InOutLine_ID != 0)
189             cost = getPOCost(as);
190         else if (m_S_TimeExpenseLine_ID != 0)
191             cost = getLaborCost(as);
192         if (cost == null) // standard Product Costs
193
cost = m_line.getProductCosts(as);
194         // Project DR
195
dr = fact.createLine(m_line,
196         getAccount(m_assetProject ? ACCTTYPE_ProjectAsset : ACCTTYPE_ProjectWIP, as),
197             as.getC_Currency_ID(), cost, null);
198         // Inventory CR
199
cr = fact.createLine(m_line,
200             m_line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as),
201             as.getC_Currency_ID(), null, cost);
202         cr.setM_Locator_ID(m_line.getM_Locator_ID());
203         cr.setLocationFromLocator(m_line.getM_Locator_ID(), true); // from Loc
204
return fact;
205     } // createFact
206

207     /**
208      * Get PO Costs in Currency of AcctSchema
209      * @param as Account Schema
210      * @return Unit PO Cost
211      */

212     private BigDecimal getPOCost(AcctSchema as)
213     {
214         BigDecimal retValue = null;
215         // Uses PO Date
216
String JavaDoc sql = "SELECT C_Currency_Convert(ol.PriceActual, o.C_Currency_ID, ?, o.DateOrdered, 'S', ?, ?) "
217             + "FROM C_OrderLine ol"
218             + " INNER JOIN M_InOutLine iol ON (iol.C_OrderLine_ID=ol.C_OrderLine_ID)"
219             + " INNER JOIN C_Order o ON (o.C_Order_ID=ol.C_Order_ID) "
220             + "WHERE iol.M_InOutLine_ID=?";
221         PreparedStatement pstmt = null;
222         try
223         {
224             pstmt = DB.prepareCall(sql);
225             pstmt.setInt(1, as.getC_Currency_ID());
226             pstmt.setInt(2, p_vo.AD_Client_ID);
227             pstmt.setInt(3, p_vo.AD_Org_ID);
228             pstmt.setInt(4, m_M_InOutLine_ID);
229             ResultSet rs = pstmt.executeQuery();
230             if (rs.next())
231             {
232                 retValue = rs.getBigDecimal(1);
233                 log.debug("getPOCost = " + retValue);
234             }
235             else
236                 log.warn("getPOCost - Not found for M_InOutLine_ID=" + m_M_InOutLine_ID);
237             rs.close();
238             pstmt.close();
239             pstmt = null;
240         }
241         catch (Exception JavaDoc e)
242         {
243             log.error("getPOCost", e);
244         }
245         try
246         {
247             if (pstmt != null)
248                 pstmt.close();
249             pstmt = null;
250         }
251         catch (Exception JavaDoc e)
252         {
253             pstmt = null;
254         }
255         return retValue;
256     } // getPOCost();
257

258     /**
259      * Get Labor Cost from Expense Report
260      * @param as Account Schema
261      * @return Unit Labor Cost
262      */

263     private BigDecimal getLaborCost(AcctSchema as)
264     {
265         BigDecimal retValue = null;
266         /** TODO Labor Cost */
267         return retValue;
268     } // getLaborCost
269

270 } // DocProjectIssue
271

272
Popular Tags