KickJava   Java API By Example, From Geeks To Geeks.

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


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

40 public DocInventory(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(DocInventoryData.select(conn, AD_Client_ID, Id));
46 }
47
48 /**
49  * Load Document Details
50  * @param rs result
51  * @return true if loadDocumentType was set
52  */

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

64 /**
65  * Load Invoice Line
66  * @return DocLine Array
67  */

68 private DocLine[] loadLines(ConnectionProvider conn){
69   ArrayList<Object JavaDoc> list = new ArrayList<Object JavaDoc>();
70   DocLineInventoryData [] data = null;
71   try{
72     data = DocLineInventoryData.select(conn,Record_ID);
73   }
74   catch (ServletException e){
75     log4jDocInventory.warn(e);
76   }
77   for(int i =0; i<data.length;i++){
78     String JavaDoc Line_ID = data[i].getField("mInventorylineId");
79     DocLine_Material docLine = new DocLine_Material (DocumentType, Record_ID, Line_ID);
80     docLine.loadAttributes(data[i], this);
81     log4jDocInventory.debug("QtyBook = " + data[i].getField("qtybook") + " - QtyCount = " + data[i].getField("qtycount"));
82     BigDecimal QtyBook = new BigDecimal(data[i].getField("qtybook"));
83     BigDecimal QtyCount = new BigDecimal(data[i].getField("qtycount"));
84     docLine.setQty ((QtyCount.subtract(QtyBook)).toString(),conn);
85     docLine.m_M_Locator_ID = data[i].getField("mLocatorId");
86       DocInventoryData [] data1 = null;
87     try{
88         data1= DocInventoryData.selectWarehouse(conn, docLine.m_M_Locator_ID);
89     }catch(ServletException e){
90       log4jDocInventory.warn(e);
91     }
92     if(data1!=null && data1.length>0) this.M_Warehouse_ID = data1[0].mWarehouseId;
93     // Set Charge ID only when Inventory Type = Charge
94
if (!"C".equals(data[i].getField("inventorytype")))
95       docLine.m_C_Charge_ID = "";
96     //
97
list.add (docLine);
98   }
99   // Return Array
100
DocLine[] dl = new DocLine[list.size()];
101   list.toArray(dl);
102   return dl;
103 } // loadLines
104

105
106 /**
107  * Get Balance
108  * @return Zero (always balanced)
109  */

110 public BigDecimal getBalance(){
111   BigDecimal retValue = ZERO;
112   return retValue;
113 } // getBalance
114

115 /**
116  * Create Facts (the accounting logic) for
117  * MMI.
118  * <pre>
119  * Inventory
120  * Inventory DR CR
121  * InventoryDiff DR CR (or Charge)
122  * </pre>
123  * @param as account schema
124  * @return Fact
125  */

126 public Fact createFact(AcctSchema as,ConnectionProvider conn,Connection JavaDoc con,VariablesSecureApp vars) throws ServletException{
127 // Log.trace(Log.l4_Data, "Doc.Inventory.createFact");
128
C_Currency_ID = as.getC_Currency_ID();
129   // create Fact Header
130
Fact fact = new Fact(this, as, Fact.POST_Actual);
131   String JavaDoc Fact_Acct_Group_ID = SequenceIdData.getSequence(conn, "Fact_Acct_Group", vars.getClient());
132   // Line pointers
133
FactLine dr = null;
134   FactLine cr = null;
135   log4jDocInventory.debug("CreateFact - before loop");
136   for (int i = 0; i < p_lines.length; i++){
137     DocLine_Material line = (DocLine_Material)p_lines[i];
138     String JavaDoc costs = line.getProductCosts(as, conn, con);
139     log4jDocInventory.debug("CreateFact - before DR - Costs: " + costs);
140     // Inventory DR CR
141
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);
142     // may be zero difference - no line created.
143
if (dr == null)
144       continue;
145     dr.setM_Locator_ID(line.m_M_Locator_ID);
146     log4jDocInventory.debug("CreateFact - before CR");
147     // InventoryDiff DR CR
148
BigDecimal b_Costs = new BigDecimal(costs);
149     // or Charge
150
Account invDiff = line.getChargeAccount(as, b_Costs.negate(), conn);
151     log4jDocInventory.debug("CreateFact - after getChargeAccount");
152     if (invDiff == null)
153       invDiff = getAccount(AcctServer.ACCTTYPE_InvDifferences, as, conn);
154     log4jDocInventory.debug("CreateFact - after getAccount - invDiff; " + invDiff);
155     cr = fact.createLine(line, invDiff,as.getC_Currency_ID(), (b_Costs.negate()).toString(), Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
156     cr.setM_Locator_ID(line.m_M_Locator_ID);
157   }
158   log4jDocInventory.debug("CreateFact - after loop");
159   SeqNo = "0";
160   return fact;
161 } // createFact
162

163     public String JavaDoc nextSeqNo(String JavaDoc oldSeqNo){
164       log4jDocInventory.debug("DocInventory - oldSeqNo = " + oldSeqNo);
165       BigDecimal seqNo = new BigDecimal(oldSeqNo);
166       SeqNo = (seqNo.add(new BigDecimal("10"))).toString();
167       log4jDocInventory.debug("DocInventory - nextSeqNo = " + SeqNo);
168       return SeqNo;
169     }
170
171   /**
172    * Get Document Confirmation
173    * @not used
174    */

175   public boolean getDocumentConfirmation(ConnectionProvider conn, String JavaDoc strRecordId) {
176     return true;
177   }
178
179   public String JavaDoc getServletInfo() {
180     return "Servlet for the accounting";
181   } // end of getServletInfo() method
182
}
183
Popular Tags