KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > process > ImportBankStatement


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 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.process;
15
16 import java.sql.*;
17 import java.math.*;
18
19 import org.compiere.model.*;
20 import org.compiere.util.DB;
21
22 /**
23  * Import Bank Statement from I_BankStatement
24  *
25  * @author Jorg Janke
26  * @version $Id: ImportBankStatement.java,v 1.1 2003/08/19 05:57:52 jjanke Exp $
27  */

28 public class ImportBankStatement extends SvrProcess
29 {
30     /** Client to be imported to */
31     private int m_AD_Client_ID = 0;
32     /** Organization to be imported to */
33     private int m_AD_Org_ID = 0;
34     /** Default Bank Account */
35     private int m_C_BankAccount_ID = 0;
36     /** Delete old Imported */
37     private boolean m_deleteOldImported = false;
38
39     /**
40      * Prepare - e.g., get Parameters.
41      */

42     protected void prepare()
43     {
44         ProcessInfoParameter[] para = getParameter();
45         for (int i = 0; i < para.length; i++)
46         {
47             String JavaDoc name = para[i].getParameterName();
48             if (para[i].getParameter() == null)
49                 ;
50             else if (name.equals("AD_Client_ID"))
51                 m_AD_Client_ID = ((BigDecimal)para[i].getParameter()).intValue();
52             else if (name.equals("AD_Org_ID"))
53                 m_AD_Org_ID = ((BigDecimal)para[i].getParameter()).intValue();
54             else if (name.equals("C_BankAccount_ID"))
55                 m_C_BankAccount_ID = ((BigDecimal)para[i].getParameter()).intValue();
56             else if (name.equals("DeleteOldImported"))
57                 m_deleteOldImported = "Y".equals(para[i].getParameter());
58             else
59                 log.error("prepare - Unknown Parameter: " + name);
60         }
61     } // prepare
62

63
64     /**
65      * Perrform process.
66      * @return Message
67      * @throws Exception
68      */

69     protected String JavaDoc doIt() throws java.lang.Exception JavaDoc
70     {
71         StringBuffer JavaDoc sql = null;
72         int no = 0;
73         String JavaDoc clientCheck = " AND AD_Client_ID=" + m_AD_Client_ID;
74
75         // **** Prepare ****
76

77         // Delete Old Imported
78
if (m_deleteOldImported)
79         {
80             sql = new StringBuffer JavaDoc ("DELETE I_BankStatement "
81                   + "WHERE I_IsImported='Y'").append (clientCheck);
82             no = DB.executeUpdate (sql.toString ());
83             log.debug ("doIt - Delete Old Impored =" + no);
84         }
85
86         // Set Client, Org, IsActive, Created/Updated
87
sql = new StringBuffer JavaDoc ("UPDATE I_BankStatement "
88               + "SET AD_Client_ID = COALESCE (AD_Client_ID,").append (m_AD_Client_ID).append ("),"
89               + " AD_Org_ID = COALESCE (AD_Org_ID,").append (m_AD_Org_ID).append ("),");
90         sql.append(" IsActive = COALESCE (IsActive, 'Y'),"
91               + " Created = COALESCE (Created, SysDate),"
92               + " CreatedBy = COALESCE (CreatedBy, 0),"
93               + " Updated = COALESCE (Updated, SysDate),"
94               + " UpdatedBy = COALESCE (UpdatedBy, 0),"
95               + " I_ErrorMsg = NULL,"
96               + " I_IsImported = 'N' "
97               + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL");
98         no = DB.executeUpdate (sql.toString ());
99         log.info ("doIt - Reset=" + no);
100
101         sql = new StringBuffer JavaDoc ("UPDATE I_BankStatement o "
102             + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '"
103             + "WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0"
104             + " OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))"
105             + " AND I_IsImported<>'Y'").append (clientCheck);
106         no = DB.executeUpdate (sql.toString ());
107         if (no != 0)
108             log.warn ("doIt - Invalid Org=" + no);
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123         throw new IllegalStateException JavaDoc("Not implemented yet");
124     } // doIt
125

126 } // ImportBankStatement
127
Popular Tags