KickJava   Java API By Example, From Geeks To Geeks.

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


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
32 public class DocInOut extends AcctServer {
33     static Logger log4jDocInOut = Logger.getLogger(DocInOut.class);
34
35     /** AD_Table_ID */
36     private String JavaDoc SeqNo = "0";
37
38
39 /**
40  * Constructor
41  * @param AD_Client_ID AD_Client_ID
42  */

43 public DocInOut(String JavaDoc AD_Client_ID){
44     super(AD_Client_ID);
45 }
46
47 public void loadObjectFieldProvider(ConnectionProvider conn, String JavaDoc AD_Client_ID, String JavaDoc Id) throws ServletException{
48     setObjectFieldProvider(DocInOutData.selectRegistro(conn, AD_Client_ID, Id));
49 }
50
51 /**
52  * Load Document Details
53  * @param rs result set
54  * @return true if loadDocumentType was set
55  */

56 public boolean loadDocumentDetails(FieldProvider [] data,ConnectionProvider conn){
57     C_Currency_ID = NO_CURRENCY;
58     log4jDocInOut.debug("loadDocumentDetails - C_Currency_ID : " + C_Currency_ID);
59     DateDoc = data[0].getField("MovementDate");
60     C_BPartner_Location_ID = data[0].getField("C_BPartner_Location_ID");
61
62
63     loadDocumentType(); // lines require doc type
64
// Contained Objects
65
p_lines = loadLines(conn);
66     log4jDocInOut.debug("Lines=" + p_lines.length);
67     return true;
68 } // loadDocumentDetails
69

70 /**
71  * Load Invoice Line
72  * @return DocLine Array
73  */

74 public DocLine[] loadLines(ConnectionProvider conn){
75     ArrayList<Object JavaDoc> list = new ArrayList<Object JavaDoc>();
76     DocLineInOutData [] data = null;
77     try{
78         data = DocLineInOutData.select(conn, Record_ID);
79     }catch(ServletException e){
80         log4jDocInOut.warn(e);
81     }
82     //
83
for(int i=0;data!=null && i<data.length;i++){
84         String JavaDoc Line_ID = data[i].getField("M_INOUTLINE_ID");
85         DocLine_Material docLine = new DocLine_Material (DocumentType, Record_ID, Line_ID);
86         docLine.loadAttributes(data[i], this);
87         docLine.setQty (data[i].getField("MOVEMENTQTY"), conn); // sets Trx and Storage Qty
88
docLine.m_M_Locator_ID = data[i].getField("M_LOCATOR_ID");
89         //
90
if (docLine.m_M_Product_ID.equals("")) log4jDocInOut.debug(" - No Product - ignored");
91         else list.add (docLine);
92     }
93     // Return Array
94
DocLine[] dl = new DocLine[list.size()];
95     list.toArray(dl);
96     return dl;
97 } // loadLines
98

99 /**
100  * Get Balance
101  * @return Zero (always balanced)
102  */

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

108 /**
109  * Create Facts (the accounting logic) for
110  * MMS, MMR.
111  * <pre>
112  * Shipment
113  * CoGS DR
114  * Inventory CR
115  * Shipment of Project Issue
116  * CoGS DR
117  * Project CR
118  * Receipt
119  * Inventory DR
120  * NotInvoicedReceipt CR
121  * </pre>
122  * @param as accounting schema
123  * @return Fact
124  */

125 public Fact createFact(AcctSchema as,ConnectionProvider conn,Connection JavaDoc con,VariablesSecureApp vars) throws ServletException{
126     C_Currency_ID = as.getC_Currency_ID();
127     // create Fact Header
128
Fact fact = new Fact(this, as, Fact.POST_Actual);
129     String JavaDoc Fact_Acct_Group_ID = SequenceIdData.getSequence(conn, "Fact_Acct_Group", vars.getClient());
130     // Line pointers
131
FactLine dr = null;
132     FactLine cr = null;
133
134     // Sales
135
if (DocumentType.equals(AcctServer.DOCTYPE_MatShipment)){
136         for (int i = 0;p_lines != null && i < p_lines.length; i++){
137             DocLine_Material line = (DocLine_Material)p_lines[i];
138             String JavaDoc costs = line.getProductCosts(as, conn, con);
139             log4jDocInOut.debug("(MatShipment) - DR account: " + line.getAccount(ProductInfo.ACCTTYPE_P_Cogs, as, conn));
140             log4jDocInOut.debug("(MatShipment) - DR costs: " + costs);
141             // CoGS DR
142
dr = fact.createLine(line,line.getAccount(ProductInfo.ACCTTYPE_P_Cogs, as, conn),as.getC_Currency_ID(), costs, "",Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
143             dr.setM_Locator_ID(line.m_M_Locator_ID);
144             dr.setLocationFromLocator(line.m_M_Locator_ID, true, conn); // from Loc
145
dr.setLocationFromBPartner(C_BPartner_Location_ID, false, conn); // to Loc
146
log4jDocInOut.debug("(MatShipment) - CR account: " + getAccount(AcctServer.ACCTTYPE_NotInvoicedReceipts, as, conn));
147             log4jDocInOut.debug("(MatShipment) - CR costs: " + costs);
148             // Inventory CR
149
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);
150             cr.setM_Locator_ID(line.m_M_Locator_ID);
151             cr.setLocationFromLocator(line.m_M_Locator_ID, true, conn); // from Loc
152
cr.setLocationFromBPartner(C_BPartner_Location_ID, false, conn); // to Loc
153
}
154         updateProductInfo(as.getC_AcctSchema_ID(), conn, con); // only for SO!
155
}
156     // Purchasing
157
else if (DocumentType.equals(AcctServer.DOCTYPE_MatReceipt)){
158         for (int i = 0;p_lines != null && i < p_lines.length; i++){
159             DocLine_Material line = (DocLine_Material)p_lines[i];
160             String JavaDoc costs = line.getProductCosts(as, conn, con);
161             log4jDocInOut.debug("(matReceipt) - DR account: " + line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn));
162             log4jDocInOut.debug("(matReceipt) - DR costs: " + costs);
163             // Inventory DR
164
dr = fact.createLine(line,line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn),as.getC_Currency_ID(), costs, "",Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
165             dr.setM_Locator_ID(line.m_M_Locator_ID);
166             dr.setLocationFromBPartner(C_BPartner_Location_ID, true, conn); // from Loc
167
dr.setLocationFromLocator(line.m_M_Locator_ID, false, conn); // to Loc
168
log4jDocInOut.debug("(matReceipt) - CR account: " + getAccount(AcctServer.ACCTTYPE_NotInvoicedReceipts, as, conn));
169             log4jDocInOut.debug("(matReceipt) - CR costs: " + costs);
170             // NotInvoicedReceipt CR
171
cr = fact.createLine(line,getAccount(AcctServer.ACCTTYPE_NotInvoicedReceipts, as, conn),as.getC_Currency_ID(), "", costs,Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
172             cr.setM_Locator_ID(line.m_M_Locator_ID);
173             cr.setLocationFromBPartner(C_BPartner_Location_ID, true, conn); // from Loc
174
cr.setLocationFromLocator(line.m_M_Locator_ID, false, conn); // to Loc
175
}
176     }else{
177         log4jDocInOut.warn("createFact - " + "DocumentType unknown: " + DocumentType);
178         return null;
179     }
180     //
181
SeqNo = "0";
182     return fact;
183 } // createFact
184

185 /**
186  * Update Sales Order Costing Product Info.
187  * Purchase side handeled in Invoice Matching.
188  * <br>
189  * decrease average cumulatives
190  *
191  * @param C_AcctSchema_ID accounting schema
192  */

193 private void updateProductInfo (String JavaDoc C_AcctSchema_ID,ConnectionProvider conn,Connection JavaDoc con){
194     log4jDocInOut.debug("updateProductInfo - M_InOut_ID=" + Record_ID);
195
196     int no = 0;
197     try{
198         no = DocInOutData.updateProductCosting(con, conn, Record_ID);
199     }catch(ServletException e){
200         log4jDocInOut.warn(e);
201     }
202     log4jDocInOut.debug("M_Product_Costing - Updated=" + no);
203 } // updateProductInfo
204

205     public String JavaDoc nextSeqNo(String JavaDoc oldSeqNo){
206       log4jDocInOut.debug("DocInOut - oldSeqNo = " + oldSeqNo);
207       BigDecimal seqNo = new BigDecimal(oldSeqNo);
208       SeqNo = (seqNo.add(new BigDecimal("10"))).toString();
209       log4jDocInOut.debug("DocInOut - nextSeqNo = " + SeqNo);
210       return SeqNo;
211     }
212
213   /**
214    * Get Document Confirmation
215    * @not used
216    */

217   public boolean getDocumentConfirmation(ConnectionProvider conn, String JavaDoc strRecordId) {
218     return true;
219   }
220
221     public String JavaDoc getServletInfo() {
222     return "Servlet for the accounting";
223   } // end of getServletInfo() method
224
}
225
Popular Tags