KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

65 /**
66  * Load AmortizationLine Line.
67  * @return DocLine Array
68  */

69 private DocLine[] loadLines(ConnectionProvider conn){
70     ArrayList<Object JavaDoc> list = new ArrayList<Object JavaDoc>();
71     DocLineDPManagementData [] data = null;
72
73     try{
74         data = DocLineDPManagementData.select(conn, Record_ID);
75     }catch(ServletException e){
76         log4j.warn(e);
77     }
78
79     log4j.debug("LoadLines: data.len"+data.length+" record_ID "+Record_ID);
80         //
81
for (int i=0;data!=null && i<data.length;i++){
82         String JavaDoc Line_ID = data[i].getField("C_DP_MANAGEMENTLINE_ID");
83         DocLine_DPManagement docLine = new DocLine_DPManagement (DocumentType, Record_ID, Line_ID);
84         docLine.loadAttributes(data[i], this);
85         docLine.Amount = data[i].getField("AMOUNT");
86         docLine.m_Record_Id2 = data[i].getField("C_DEBT_PAYMENT_ID");
87         docLine.Isreceipt = data[i].getField("ISRECEIPT");
88         docLine.StatusTo = data[i].getField("STATUS_TO");
89         docLine.StatusFrom = data[i].getField("STATUS_FROM");
90         list.add(docLine);
91     }
92
93     // Return Array
94
DocLine[] dl = new DocLine[list.size()];
95     list.toArray(dl);
96     return dl;
97 } // loadLines
98

99 /**
100  * Get Source Currency Balance - always zero
101  * @return Zero (always balanced)
102  */

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

109
110 /**
111  * Create Facts (the accounting logic) for
112  * @param as accounting schema
113  * @return Fact
114  */

115 public Fact createFact (AcctSchema as,ConnectionProvider conn,Connection JavaDoc con,VariablesSecureApp vars) throws ServletException{
116     log4j.debug("createFact - Inicio");
117     // create Fact Header
118
Fact fact = null;
119     String JavaDoc Fact_Acct_Group_ID = SequenceIdData.getSequence(conn, "Fact_Acct_Group", vars.getClient());
120     log4j.debug("createFact - object created");
121     // Lines
122
fact = new Fact(this, as, Fact.POST_Actual);
123     for (int i = 0;p_lines != null && i < p_lines.length; i++){
124         DocLine_DPManagement line = (DocLine_DPManagement)p_lines[i];
125 // ProductInfo product = new ProductInfo(line.m_M_Product_ID,conn);
126
if (line.Isreceipt.equals("Y"))
127       {
128         fact.createLine(line,getAccount(line.Isreceipt, line.m_C_BPartner_ID, as, line.StatusTo, conn),line.m_C_Currency_ID, line.Amount, "", Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
129         fact.createLine(line,getAccount(line.Isreceipt, line.m_C_BPartner_ID, as, line.StatusFrom, conn),line.m_C_Currency_ID, "", line.Amount, Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
130          
131       } else {
132         fact.createLine(line,getAccount(line.Isreceipt, line.m_C_BPartner_ID, as, line.StatusTo, conn),line.m_C_Currency_ID, "", line.Amount, Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
133         fact.createLine(line,getAccount(line.Isreceipt, line.m_C_BPartner_ID, as, line.StatusFrom, conn),line.m_C_Currency_ID, line.Amount, "", Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
134       }
135     }
136     SeqNo = "0";
137     return fact;
138 } // createFact
139

140
141     public String JavaDoc nextSeqNo(String JavaDoc oldSeqNo){
142       log4j.debug("DocAmortization - oldSeqNo = " + oldSeqNo);
143       BigDecimal seqNo = new BigDecimal(oldSeqNo);
144       SeqNo = (seqNo.add(new BigDecimal("10"))).toString();
145       log4j.debug("DocAmortization - nextSeqNo = " + SeqNo);
146       return SeqNo;
147     }
148
149   /**
150    * Get Document Confirmation
151    * @not used
152    */

153   public boolean getDocumentConfirmation(ConnectionProvider conn, String JavaDoc strRecordId) {
154     return true;
155   }
156
157   /**
158    * Line Account from Asset
159    *
160    * @param AcctType see ACCTTYPE_* (1..8)
161    * @param as Accounting Schema
162    * @return Requested Asset Account
163    */

164   public Account getAccount(String JavaDoc Isreceipt, String JavaDoc partnerID, AcctSchema as, String JavaDoc status, ConnectionProvider conn){
165     /*if (Integer.parseInt(AcctType) < 1 || Integer.parseInt(AcctType) > 2)
166       return null;*/

167
168     // No Product - get Default from Product Category
169
/*if (A_Asset_ID.equals(""))
170       return getAccountDefault(AcctType, as, conn);*/

171     DocDPManagementData [] data = null;
172     Account acc =null;
173     try{
174       
175       String JavaDoc validCombination_ID = "";
176
177       if (Isreceipt.equals("Y"))
178       {
179            data = DocDPManagementData.selectReceiptAcct(conn, partnerID, as.getC_AcctSchema_ID(),status);
180           validCombination_ID = data[0].acct;
181       }else{
182         data = DocDPManagementData.selectNoReceiptAcct(conn, partnerID, as.getC_AcctSchema_ID(),status);
183             validCombination_ID = data[0].acct;
184       }
185
186       if(data==null || data.length == 0) return null;
187       
188
189       if (validCombination_ID.equals(""))
190         return null;
191       acc = Account.getAccount(conn,validCombination_ID);
192     }catch(ServletException e){
193       log4j.warn(e);
194     }
195     log4j.debug("DocAmortization - getAccount - " + acc.Account_ID);
196     return acc;
197   } // getAccount
198

199     public String JavaDoc getServletInfo() {
200     return "Servlet for the accounting";
201   } // end of getServletInfo() method
202
}
203
Popular Tags