KickJava   Java API By Example, From Geeks To Geeks.

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


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-2001 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  * Post Invoice Documents.
25  * <pre>
26  * Table: M_Production (325)
27  * Document Types: MMP
28  * </pre>
29  * @author Jorg Janke
30  * @version $Id: Doc_Production.java,v 1.8 2003/08/25 02:35:10 jjanke Exp $
31  */

32 public class Doc_Production extends Doc
33 {
34     /**
35      * Constructor
36      * @param AD_Client_ID client
37      */

38     public Doc_Production (int AD_Client_ID)
39     {
40         super (AD_Client_ID);
41     } // Doc_Production
42

43     /**
44      * Get AD_Table_ID
45      * @return 325
46      */

47     public int getAD_Table_ID()
48     {
49         return 325;
50     } // get_Table_ID
51

52     /**
53      * Table Name
54      * @return M_Production
55      */

56     public String JavaDoc getTableName()
57     {
58         return "M_Production";
59     } // getTableName
60

61     /**
62      * Load Document Details
63      * @param rs result set
64      * @return true if loadDocumentType was set
65      */

66     protected boolean loadDocumentDetails(ResultSet rs)
67     {
68         p_vo.DocumentType = DocVO.DOCTYPE_MatProduction;
69         p_vo.C_Currency_ID = NO_CURRENCY;
70         try
71         {
72             p_vo.DateDoc = rs.getTimestamp("MovementDate");
73         }
74         catch (SQLException e)
75         {
76             log.error("loadDocumentDetails", e);
77         }
78         loadDocumentType(); // lines require doc type
79
// Contained Objects
80
p_lines = loadLines();
81         log.debug("Lines=" + p_lines.length);
82         return true;
83     } // loadDocumentDetails
84

85     /**
86      * Load Invoice Line
87      * @return DoaLine Array
88      */

89     private DocLine[] loadLines()
90     {
91         ArrayList list = new ArrayList();
92         String JavaDoc sql = "SELECT * FROM M_ProductionLine pl "
93             + "WHERE EXISTS (SELECT * FROM M_ProductionPlan pp"
94             + " WHERE pl.M_ProductionPlan_ID=pp.M_ProductionPlan_ID"
95             + " AND M_Production_ID=?) "
96             + "ORDER BY pl.M_ProductionPlan_ID, pl.Line";
97         try
98         {
99             PreparedStatement pstmt = DB.prepareStatement(sql);
100             pstmt.setInt(1, p_vo.Record_ID);
101             ResultSet rs = pstmt.executeQuery();
102             //
103
while (rs.next())
104             {
105                 int Line_ID = rs.getInt("M_ProductionLine_ID");
106                 DocLine_Material docLine = new DocLine_Material (p_vo.DocumentType, p_vo.Record_ID, Line_ID);
107                 docLine.loadAttributes(rs, p_vo);
108                 docLine.setQty (rs.getBigDecimal("MovementQty"));
109                 docLine.setM_Locator_ID (rs.getInt("M_Locator_ID"));
110                 //
111
log.debug(docLine.toString());
112                 list.add (docLine);
113             }
114             //
115
rs.close();
116             pstmt.close();
117         }
118         catch (SQLException e)
119         {
120             log.error ("loadLines", e);
121         }
122         // Return Array
123
DocLine[] dl = new DocLine[list.size()];
124         list.toArray(dl);
125         return dl;
126     } // loadLines
127

128     /**
129      * Get Balance
130      * @return Zero (always balanced)
131      */

132     public BigDecimal getBalance()
133     {
134         BigDecimal retValue = Env.ZERO;
135         return retValue;
136     } // getBalance
137

138     /**
139      * Create Facts (the accounting logic) for
140      * MMP.
141      * <pre>
142      * Production
143      * Inventory DR CR
144      * </pre>
145      * @param as account schema
146      * @return Fact
147      */

148     public Fact createFact(AcctSchema as)
149     {
150         p_vo.C_Currency_ID = as.getC_Currency_ID();
151         // create Fact Header
152
Fact fact = new Fact(this, as, Fact.POST_Actual);
153
154         // Line pointer
155
FactLine fl = null;
156
157         // Ger BOM Cost
158
BigDecimal bomCost = Env.ZERO;
159         for (int i = 0; i < p_lines.length; i++)
160         {
161             DocLine_Material line = (DocLine_Material)p_lines[i];
162             if (!line.isBOM())
163                 bomCost = bomCost.add(line.getProductCosts(as));
164         }
165
166         for (int i = 0; i < p_lines.length; i++)
167         {
168             DocLine_Material line = (DocLine_Material)p_lines[i];
169             BigDecimal costs = null;
170             if (line.isBOM())
171                 costs = bomCost.negate();
172             else
173                 costs = line.getProductCosts(as);
174             // Inventory DR CR
175
fl = fact.createLine(line,
176                 line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as),
177                 as.getC_Currency_ID(), costs);
178             fl.setM_Locator_ID(line.getM_Locator_ID());
179         }
180         return fact;
181     } // createFact
182

183 } // Doc_Production
184
Popular Tags