KickJava   Java API By Example, From Geeks To Geeks.

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


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 DocAmortization extends AcctServer {
33     static Logger log4jDocAmortization = Logger.getLogger(DocAmortization.class);
34
35     private String JavaDoc SeqNo = "0";
36     /** Account Type - Asset */
37     public static final String JavaDoc ACCTTYPE_Depreciation = "1";
38     public static final String JavaDoc ACCTTYPE_AccumDepreciation = "2";
39
40     /**
41      * Constructor
42      * @param AD_Client_ID AD_Client_ID
43      */

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

57 public boolean loadDocumentDetails (FieldProvider [] data,ConnectionProvider conn){
58     DocumentType = AcctServer.DOCTYPE_Amortization;
59     DateDoc = data[0].getField("Dateacct");
60     loadDocumentType(); // lines require doc type
61
// Contained Objects
62
p_lines = loadLines(conn);
63     log4jDocAmortization.debug("Record_ID = " + Record_ID + " - Lines=" + p_lines.length);
64     return false;
65 } // loadDocumentDetails
66

67 /**
68  * Load AmortizationLine Line.
69  * @return DocLine Array
70  */

71 private DocLine[] loadLines(ConnectionProvider conn){
72     ArrayList<Object JavaDoc> list = new ArrayList<Object JavaDoc>();
73     DocLineAmortizationData [] data = null;
74     try{
75         data = DocLineAmortizationData.select(conn, Record_ID);
76     }catch(ServletException e){
77         log4jDocAmortization.warn(e);
78     }
79     log4jDocAmortization.debug("Record_ID = " + Record_ID + " - Lines=" + p_lines.length);
80         //
81
for (int i=0;data!=null && i<data.length;i++){
82         String JavaDoc Line_ID = data[i].getField("A_AMORTIZATIONLINE_ID");
83         DocLine_Amortization docLine = new DocLine_Amortization (DocumentType, Record_ID, Line_ID);
84         docLine.loadAttributes(data[i], this);
85         docLine.Amount = data[i].getField("AMORTIZATIONAMT");
86         list.add(docLine);
87     }
88
89     // Return Array
90
DocLine[] dl = new DocLine[list.size()];
91     list.toArray(dl);
92     return dl;
93 } // loadLines
94

95 /**
96  * Get Source Currency Balance - always zero
97  * @return Zero (always balanced)
98  */

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

105
106 /**
107  * Create Facts (the accounting logic) for
108  * @param as accounting schema
109  * @return Fact
110  */

111 public Fact createFact (AcctSchema as,ConnectionProvider conn,Connection JavaDoc con,VariablesSecureApp vars) throws ServletException{
112     log4jDocAmortization.debug("createFact - Inicio");
113     // create Fact Header
114
Fact fact = null;
115     String JavaDoc Fact_Acct_Group_ID = SequenceIdData.getSequence(conn, "Fact_Acct_Group", vars.getClient());
116     log4jDocAmortization.debug("createFact - object created");
117     log4jDocAmortization.debug("createFact - p_lines.length - " + p_lines.length);
118     // Lines
119
fact = new Fact(this, as, Fact.POST_Actual);
120     for (int i = 0;p_lines != null && i < p_lines.length; i++){
121         DocLine_Amortization line = (DocLine_Amortization)p_lines[i];
122         ProductInfo product = new ProductInfo(line.m_M_Product_ID,conn);
123         fact.createLine(line,getAccount(ACCTTYPE_Depreciation, line.m_A_Asset_ID, as, conn),line.m_C_Currency_ID, line.Amount, "", Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
124         fact.createLine(line,getAccount(ACCTTYPE_AccumDepreciation, line.m_A_Asset_ID, as, conn),line.m_C_Currency_ID, "", line.Amount, Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
125     }
126     SeqNo = "0";
127     return fact;
128 } // createFact
129

130
131     public String JavaDoc nextSeqNo(String JavaDoc oldSeqNo){
132       log4jDocAmortization.debug("DocAmortization - oldSeqNo = " + oldSeqNo);
133       BigDecimal seqNo = new BigDecimal(oldSeqNo);
134       SeqNo = (seqNo.add(new BigDecimal("10"))).toString();
135       log4jDocAmortization.debug("DocAmortization - nextSeqNo = " + SeqNo);
136       return SeqNo;
137     }
138
139   /**
140    * Get Document Confirmation
141    * @not used
142    */

143   public boolean getDocumentConfirmation(ConnectionProvider conn, String JavaDoc strRecordId) {
144     return true;
145   }
146
147   /**
148    * Line Account from Asset
149    *
150    * @param AcctType see ACCTTYPE_* (1..8)
151    * @param as Accounting Schema
152    * @return Requested Asset Account
153    */

154   public Account getAccount(String JavaDoc AcctType, String JavaDoc A_Asset_ID, AcctSchema as, ConnectionProvider conn){
155     if (Integer.parseInt(AcctType) < 1 || Integer.parseInt(AcctType) > 2)
156       return null;
157     // No Product - get Default from Product Category
158
/*if (A_Asset_ID.equals(""))
159       return getAccountDefault(AcctType, as, conn);*/

160     DocAmortizationData [] data = null;
161     Account acc =null;
162     try{
163       data = DocAmortizationData.selectAssetAcct(conn, A_Asset_ID, as.getC_AcctSchema_ID());
164       if(data==null || data.length == 0) return null;
165       String JavaDoc validCombination_ID = "";
166       switch (Integer.parseInt(AcctType)){
167         case 1: validCombination_ID = data[0].depreciation;
168             break;
169         case 2: validCombination_ID = data[0].accumdepreciation;
170             break;
171       }
172       if (validCombination_ID.equals(""))
173         return null;
174       acc = Account.getAccount(conn,validCombination_ID);
175     }catch(ServletException e){
176       log4jDocAmortization.warn(e);
177     }
178     log4jDocAmortization.debug("DocAmortization - getAccount - " + acc.Account_ID);
179     return acc;
180   } // getAccount
181

182     public String JavaDoc getServletInfo() {
183     return "Servlet for the accounting";
184   } // end of getServletInfo() method
185
}
186
Popular Tags