KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > report > FinBalance


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Smart Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.report;
15
16 import java.sql.*;
17 import java.util.*;
18 import java.math.*;
19
20 import org.compiere.process.*;
21 import org.compiere.model.*;
22 import org.compiere.util.*;
23
24 /**
25  * Financial Balance Maintenance Engine
26  *
27  * @author Jorg Janke
28  * @version $Id: FinBalance.java,v 1.5 2003/10/04 03:51:51 jjanke Exp $
29  */

30 public class FinBalance extends SvrProcess
31 {
32     /**
33      * Financial Report Constructor
34      */

35     public FinBalance()
36     {
37         super();
38         log.info(" ");
39     } // FinBalance
40

41     /** Logger */
42     protected static Logger s_log = Logger.getCLogger (FinBalance.class);
43
44     private int m_C_AcctSchema_ID = 0;
45     private int m_C_Calendar_ID = 0;
46     private boolean m_IsRecreate = false;
47
48     /**
49      * Prepare - e.g., get Parameters.
50      */

51     protected void prepare()
52     {
53         // Parameter
54
ProcessInfoParameter[] para = getParameter();
55         for (int i = 0; i < para.length; i++)
56         {
57             String JavaDoc name = para[i].getParameterName();
58             if (para[i].getParameter() == null)
59                 ;
60             else if (name.equals("C_AcctSchema_ID"))
61                 m_C_AcctSchema_ID = ((BigDecimal)para[i].getParameter()).intValue();
62             else if (name.equals("IsRecreate"))
63                 m_IsRecreate = "Y".equals(para[i].getParameter());
64             else
65                 log.error("prepare - Unknown Parameter: " + name);
66         }
67         log.debug("prepare - C_AcctSchema_ID=" + m_C_AcctSchema_ID
68             + ", C_Calendar_ID=" + m_C_Calendar_ID + ", IsRecreate=" + m_IsRecreate);
69     } // prepare
70

71
72     /**
73      * Perform process.
74      * @return Message to be translated
75      * @throws Exception
76      */

77     protected String JavaDoc doIt() throws java.lang.Exception JavaDoc
78     {
79         if (m_IsRecreate && m_C_AcctSchema_ID != 0)
80             deleteBalance (m_C_AcctSchema_ID);
81         if (m_IsRecreate && m_C_AcctSchema_ID == 0)
82             updateBalance(m_C_AcctSchema_ID, true); // Delete & Insert
83
else
84             updateBalance(m_C_AcctSchema_ID, false); // Update & Insert
85
return "";
86     } // doIt
87

88     /**
89      * Delete Balances
90      * @param C_AcctSchema_ID accounting schema
91      * @return Message to be translated
92      */

93     public static String JavaDoc deleteBalance (int C_AcctSchema_ID)
94     {
95         StringBuffer JavaDoc sql = new StringBuffer JavaDoc ("DELETE FROM Fact_Acct_Balance WHERE ");
96         if (C_AcctSchema_ID != 0)
97             sql.append ("C_AcctSchema_ID=").append (C_AcctSchema_ID);
98         //
99
int no = DB.executeUpdate(sql.toString());
100         String JavaDoc msg = "@Deleted@=" + no;
101         s_log.debug("deleteBalance - C_AcctSchema_ID=" + C_AcctSchema_ID + " #=" + no);
102         //
103
return msg;
104     } // deleteBalance
105

106     /**
107      * Update / Create Balances
108      * @param C_AcctSchema_ID accounting schema (ignored)
109      * @param deleteFirst delete (all) balances first
110      * @return Message to be translated
111      */

112     public static String JavaDoc updateBalance (int C_AcctSchema_ID, boolean deleteFirst)
113     {
114         s_log.info("updateBalance - C_AcctSchema_ID=" + C_AcctSchema_ID + " - DeleteFirst=" + deleteFirst);
115         long start = System.currentTimeMillis();
116         try
117         {
118             String JavaDoc sql = "{CALL Fact_Acct_Balance_Update(?)}";
119             CallableStatement cstmt = DB.prepareCall(sql);
120             cstmt.setString(1, deleteFirst ? "Y" : "N");
121             cstmt.executeUpdate();
122             cstmt.close();
123         }
124         catch(SQLException e)
125         {
126             s_log.error("FinBalance.updateBalance", e);
127             return e.getLocalizedMessage();
128         }
129         //
130
start = System.currentTimeMillis() - start;
131         s_log.info("updateBalance - " + (start/1000) + " sec");
132         return "";
133     } // updateBalance
134

135
136     /*************************************************************************/
137
138     /**
139      * Test
140      * @param args ignored
141      */

142     public static void main(String JavaDoc[] args)
143     {
144         FinBalance finBalance1 = new FinBalance();
145     } // main
146

147 } // FinBalance
148
Popular Tags