KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_forms > DocMovement


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

17 package org.openbravo.erpCommon.ad_forms;
18
19 import org.openbravo.erpCommon.utility.SequenceIdData;
20 import org.openbravo.base.secureApp.VariablesSecureApp;
21 import java.math.*;
22 import java.util.*;
23 import javax.servlet.*;
24 import org.apache.log4j.Logger ;
25 // imports for transactions
26
import org.openbravo.database.ConnectionProvider;
27 import java.sql.Connection JavaDoc;
28 import org.openbravo.data.FieldProvider;
29
30
31 public class DocMovement extends AcctServer {
32   static Logger log4jDocMovement = Logger.getLogger(DocMovement.class);
33
34   private String JavaDoc SeqNo = "0";
35
36 /**
37  * Constructor
38  * @param AD_Client_ID client
39  */

40 public DocMovement(String JavaDoc AD_Client_ID){
41   super(AD_Client_ID);
42 }
43
44 public void loadObjectFieldProvider(ConnectionProvider conn, String JavaDoc AD_Client_ID, String JavaDoc Id) throws ServletException{
45     setObjectFieldProvider(DocMovementData.select(conn, AD_Client_ID, Id));
46 }
47
48 /**
49  * Load Document Details
50  * @param rs result set
51  * @return true if loadDocumentType was set
52  */

53 public boolean loadDocumentDetails(FieldProvider [] data,ConnectionProvider conn){
54   DocumentType = AcctServer.DOCTYPE_MatMovement;
55   C_Currency_ID = NO_CURRENCY;
56   DateDoc = data[0].getField("MovementDate");
57
58   loadDocumentType(); // lines require doc type
59
// Contained Objects
60
p_lines = loadLines(conn);
61   log4jDocMovement.debug("Lines=" + p_lines.length);
62   return true;
63 } // loadDocumentDetails
64

65 /**
66  * Load Invoice Line
67  * @return document lines (DocLine_Material)
68  */

69 public DocLine[] loadLines(ConnectionProvider conn){
70   ArrayList<Object JavaDoc> list = new ArrayList<Object JavaDoc>();
71   DocLineMovementData [] data = null;
72   try{
73     data = DocLineMovementData.select(conn, Record_ID);
74   }
75   catch (ServletException e){
76     log4jDocMovement.warn(e);
77   }
78     //
79
for(int i=0; i<data.length;i++){
80     String JavaDoc Line_ID = data[i].getField("mMovementlineId");
81     DocLine_Material docLine = new DocLine_Material (DocumentType, Record_ID, Line_ID);
82     docLine.loadAttributes(data[i], this);
83     docLine.setQty(data[i].getField("MovementQty"),conn);
84     docLine.m_M_Locator_ID = data[i].getField("M_Locator_ID");
85     docLine.m_M_LocatorTo_ID = data[i].getField("M_LocatorTo_ID");
86     //
87
log4jDocMovement.debug("Movement line: " + Line_ID + " loaded.");
88     list.add (docLine);
89   }
90
91   // Return Array
92
DocLine[] dl = new DocLine[list.size()];
93   list.toArray(dl);
94   return dl;
95 } // loadLines
96

97 /**
98  * Get Balance
99  * @return balance (ZERO) - always balanced
100  */

101 public BigDecimal getBalance(){
102   BigDecimal retValue = ZERO;
103   return retValue;
104 } // getBalance
105

106 /**
107  * Create Facts (the accounting logic) for
108  * MMM.
109  * <pre>
110  * Movement
111  * Inventory DR CR
112  * InventoryTo DR CR
113  * </pre>
114  * @param as account schema
115  * @return Fact
116  */

117 public Fact createFact(AcctSchema as,ConnectionProvider conn,Connection JavaDoc con,VariablesSecureApp vars) throws ServletException{
118   C_Currency_ID = as.getC_Currency_ID();
119   // create Fact Header
120
Fact fact = new Fact(this, as, Fact.POST_Actual);
121   String JavaDoc Fact_Acct_Group_ID = SequenceIdData.getSequence(conn, "Fact_Acct_Group", vars.getClient());
122
123   // Line pointers
124
FactLine dr = null;
125   FactLine cr = null;
126   log4jDocMovement.debug("DocMovement - Before the loop");
127   for (int i=0; i < p_lines.length; i++){
128     DocLine_Material line = (DocLine_Material)p_lines[i];
129     log4jDocMovement.debug("DocMovement - Before calculating the costs for line i = " + i);
130     String JavaDoc costs = line.getProductCosts(as, conn, con);
131     BigDecimal b_Costs = new BigDecimal(costs);
132     // Inventory DR CR
133
dr = fact.createLine(line,line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn),as.getC_Currency_ID(), (b_Costs.negate()).toString(), Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn); // from (-) CR
134
dr.setM_Locator_ID(line.m_M_Locator_ID);
135     // InventoryTo DR CR
136
cr = fact.createLine(line,line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn),as.getC_Currency_ID(), costs, Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn); // to (+) DR
137
cr.setM_Locator_ID(line.m_M_LocatorTo_ID);
138   }
139   log4jDocMovement.debug("DocMovement - After the loop");
140   SeqNo = "0";
141   return fact;
142 } // createFact
143

144     public String JavaDoc nextSeqNo(String JavaDoc oldSeqNo){
145       log4jDocMovement.debug("DocMovement - oldSeqNo = " + oldSeqNo);
146       BigDecimal seqNo = new BigDecimal(oldSeqNo);
147       SeqNo = (seqNo.add(new BigDecimal("10"))).toString();
148       log4jDocMovement.debug("DocMovement - nextSeqNo = " + SeqNo);
149       return SeqNo;
150     }
151
152   /**
153    * Get Document Confirmation
154    * @not used
155    */

156   public boolean getDocumentConfirmation(ConnectionProvider conn, String JavaDoc strRecordId) {
157     return true;
158   }
159
160   public String JavaDoc getServletInfo() {
161     return "Servlet for accounting";
162   } // end of getServletInfo() method
163
}
164
Popular Tags