KickJava   Java API By Example, From Geeks To Geeks.

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


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

40 public DocGLJournal(String JavaDoc AD_Client_ID){
41   super(AD_Client_ID);
42   log4jDocGLJournal.info("- DocGLJournal - OBJECT CREATED.");
43 }
44
45 public String JavaDoc m_PostingType = Fact.POST_Actual;
46
47 public void loadObjectFieldProvider(ConnectionProvider conn, String JavaDoc AD_Client_ID, String JavaDoc Id) throws ServletException{
48     setObjectFieldProvider(DocGLJournalData.select(conn, AD_Client_ID, Id));
49 }
50
51 /**
52  * Load Specific Document Details
53  * @param rs result set
54  * @return true if loadDocumentType was set
55  */

56 public boolean loadDocumentDetails (FieldProvider [] data,ConnectionProvider conn){
57   loadDocumentType(); // lines require doc type
58

59   m_PostingType = data[0].getField("PostingType");
60   m_IsOpening = data[0].getField("isopening");
61
62   // Contained Objects
63
p_lines = loadLines(conn);
64   log4jDocGLJournal.debug("Lines=" + p_lines.length);
65   return true;
66 } // loadDocumentDetails
67

68 /**
69  * Load Invoice Line
70  * @return DocLine Array
71  */

72 private DocLine[] loadLines(ConnectionProvider conn){
73   ArrayList<Object JavaDoc> list = new ArrayList<Object JavaDoc>();
74
75   DocLineGLJournalData [] data = null;
76   try{
77     data = DocLineGLJournalData.select(conn, Record_ID);
78   }
79   catch (ServletException e){
80     log4jDocGLJournal.warn(e);
81   }
82   //
83
for(int i=0; i<data.length;i++){
84     String JavaDoc Line_ID = data[i].glJournallineId;
85     DocLine docLine = new DocLine (DocumentType, Record_ID, Line_ID);
86     docLine.loadAttributes (data[i], this);
87     docLine.m_Record_Id2 = data[i].cDebtPaymentId;
88     // -- Source Amounts
89
String JavaDoc AmtSourceDr = data[i].amtsourcedr;
90     String JavaDoc AmtSourceCr = data[i].amtsourcecr;
91     docLine.setAmount (AmtSourceDr, AmtSourceCr);
92     // -- Converted Amounts
93
String JavaDoc C_AcctSchema_ID = data[i].cAcctschemaId;
94     String JavaDoc AmtAcctDr = data[i].amtacctdr;
95     String JavaDoc AmtAcctCr = data[i].amtacctcr;
96     docLine.setConvertedAmt (C_AcctSchema_ID, AmtAcctDr, AmtAcctCr);
97     docLine.m_DateAcct = this.DateAcct;
98     // -- Account
99
String JavaDoc C_ValidCombination_ID = data[i].cValidcombinationId;
100     Account acct = null;
101     try{
102       acct = new Account(conn,C_ValidCombination_ID);
103     }catch (ServletException e){
104       log4jDocGLJournal.warn(e);
105     }
106     docLine.setAccount (acct);
107     // -- Set Org from account (x-org)
108
docLine.setAD_Org_ID(acct.getAD_Org_ID());
109     //
110
list.add(docLine);
111   }
112   // Return Array
113
DocLine[] dl = new DocLine[list.size()];
114   list.toArray(dl);
115   return dl;
116 } // loadLines
117

118 /**
119  * Get Source Currency Balance - subtracts line and tax amounts from total - no rounding
120  * @return positive amount, if total invoice is bigger than lines
121  */

122 public BigDecimal getBalance(){
123   BigDecimal retValue = ZERO;
124   StringBuffer JavaDoc sb = new StringBuffer JavaDoc (" [");
125   // Lines
126
for (int i = 0; i < p_lines.length; i++){
127     retValue = retValue.add(new BigDecimal(p_lines[i].getAmount()));
128     sb.append("+").append(p_lines[i].getAmount());
129   }
130   sb.append("]");
131   //
132
log4jDocGLJournal.debug(toString() + " Balance=" + retValue + sb.toString());
133   return retValue;
134 } // getBalance
135

136 /**
137  * Create Facts (the accounting logic) for
138  * GLJ.
139  * (only for the accounting scheme, it was created)
140  * <pre>
141  * account DR CR
142  * </pre>
143  * @param as acct schema
144  * @return Fact
145  */

146 public Fact createFact (AcctSchema as,ConnectionProvider conn,Connection JavaDoc con,VariablesSecureApp vars) throws ServletException{
147   // create Fact Header
148
Fact fact = new Fact (this, as, m_PostingType);
149   String JavaDoc Fact_Acct_Group_ID = SequenceIdData.getSequence(conn, "Fact_Acct_Group", vars.getClient());
150   // GLJ
151
if (DocumentType.equals(AcctServer.DOCTYPE_GLJournal)){
152     // account DR CR
153
for (int i = 0; i < p_lines.length; i++){
154       if (p_lines[i].getC_AcctSchema_ID().equals(as.getC_AcctSchema_ID ())){
155         FactLine line = fact.createLine (p_lines[i],p_lines[i].getAccount(),C_Currency_ID,p_lines[i].getAmtSourceDr(),
156           p_lines[i].getAmtSourceCr (), Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
157       }
158     } // for all lines
159
}else{
160     log4jDocGLJournal.warn("createFact - " + "DocumentType unknown: " + DocumentType);
161     fact = null;
162   }
163   SeqNo = "0";
164   return fact;
165 } // createFact
166

167     public String JavaDoc nextSeqNo(String JavaDoc oldSeqNo){
168       log4jDocGLJournal.debug("DocGLJournal - oldSeqNo = " + oldSeqNo);
169       BigDecimal seqNo = new BigDecimal(oldSeqNo);
170       SeqNo = (seqNo.add(new BigDecimal("10"))).toString();
171       log4jDocGLJournal.debug("DocGLJournal - nextSeqNo = " + SeqNo);
172       return SeqNo;
173     }
174
175   /**
176    * Get Document Confirmation
177    * @not used
178    */

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