KickJava   Java API By Example, From Geeks To Geeks.

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


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_Movement (323)
27  * Document Types: MMM
28  * </pre>
29  * @author Jorg Janke
30  * @version $Id: Doc_Movement.java,v 1.8 2003/07/22 06:28:03 jjanke Exp $
31  */

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

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

43     /**
44      * Get AD_Table_ID
45      * @return AD_Table_ID (323)
46      */

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

52     /**
53      * Table Name
54      * @return Table Name (M_Movement)
55      */

56     public String JavaDoc getTableName()
57     {
58         return "M_Movement";
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_MatMovement;
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.debug("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 document lines (DocLine_Material)
88      */

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

126     /**
127      * Get Balance
128      * @return balance (ZERO) - always balanced
129      */

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

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

147     public Fact createFact(AcctSchema as)
148     {
149         p_vo.C_Currency_ID = as.getC_Currency_ID();
150         // create Fact Header
151
Fact fact = new Fact(this, as, Fact.POST_Actual);
152
153         // Line pointers
154
FactLine dr = null;
155         FactLine cr = null;
156
157         for (int i = 0; i < p_lines.length; i++)
158         {
159             DocLine_Material line = (DocLine_Material)p_lines[i];
160             BigDecimal costs = line.getProductCosts(as);
161             // Inventory DR CR
162
dr = fact.createLine(line,
163                 line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as),
164                 as.getC_Currency_ID(), costs.negate()); // from (-) CR
165
dr.setM_Locator_ID(line.getM_Locator_ID());
166             // InventoryTo DR CR
167
cr = fact.createLine(line,
168                 line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as),
169                 as.getC_Currency_ID(), costs); // to (+) DR
170
cr.setM_Locator_ID(line.getM_LocatorTo_ID());
171         }
172
173         return fact;
174     } // createFact
175

176 } // Doc_Movement
177
Popular Tags