📄 importbankstatement.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer is ActFact BV.
* Copyright (C) 2003-2004 ActFact BV and Compiere Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.process;
import java.sql.*;
import java.math.*;
import java.util.*;
//import org.compiere.process.*;
import org.compiere.model.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Import Bank Statement from I_BankStatement
*
* author Eldir Tomassen
* @version $Id: ImportBankStatement.java,v 1.8 2005/10/26 00:37:42 jjanke Exp $
*/
public class ImportBankStatement extends SvrProcess
{
/** Client to be imported to */
private int m_AD_Client_ID = 0;
/** Organization to be imported to */
private int m_AD_Org_ID = 0;
/** Default Bank Account */
private int m_C_BankAccount_ID = 0;
/** Delete old Imported */
private boolean m_deleteOldImported = false;
private Properties m_ctx;
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
{
String name = para[i].getParameterName();
if (para[i].getParameter() == null)
;
else if (name.equals("AD_Client_ID"))
m_AD_Client_ID = ((BigDecimal)para[i].getParameter()).intValue();
else if (name.equals("AD_Org_ID"))
m_AD_Org_ID = ((BigDecimal)para[i].getParameter()).intValue();
else if (name.equals("C_BankAccount_ID"))
m_C_BankAccount_ID = ((BigDecimal)para[i].getParameter()).intValue();
else if (name.equals("DeleteOldImported"))
m_deleteOldImported = "Y".equals(para[i].getParameter());
else
log.log(Level.SEVERE, "Unknown Parameter: " + name);
}
m_ctx = Env.getCtx();
} // prepare
/**
* Perform process.
* @return Message
* @throws Exception
*/
protected String doIt() throws java.lang.Exception
{
log.info("");
StringBuffer sql = null;
int no = 0;
String clientCheck = " AND AD_Client_ID=" + m_AD_Client_ID;
// **** Prepare ****
// Delete Old Imported
if (m_deleteOldImported)
{
sql = new StringBuffer ("DELETE I_BankStatement "
+ "WHERE I_IsImported='Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Delete Old Impored =" + no);
}
// Set Client, Org, IsActive, Created/Updated
sql = new StringBuffer ("UPDATE I_BankStatement "
+ "SET AD_Client_ID = COALESCE (AD_Client_ID,").append (m_AD_Client_ID).append ("),"
+ " AD_Org_ID = COALESCE (AD_Org_ID,").append (m_AD_Org_ID).append ("),");
sql.append(" IsActive = COALESCE (IsActive, 'Y'),"
+ " Created = COALESCE (Created, SysDate),"
+ " CreatedBy = COALESCE (CreatedBy, 0),"
+ " Updated = COALESCE (Updated, SysDate),"
+ " UpdatedBy = COALESCE (UpdatedBy, 0),"
+ " I_ErrorMsg = NULL,"
+ " I_IsImported = 'N' "
+ "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL");
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.info ("Reset=" + no);
sql = new StringBuffer ("UPDATE I_BankStatement o "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '"
+ "WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0"
+ " OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning ("Invalid Org=" + no);
// Set Bank Account
sql = new StringBuffer("UPDATE I_BankStatement i "
+ "SET C_BankAccount_ID="
+ "( "
+ " SELECT C_BankAccount_ID "
+ " FROM C_BankAccount a, C_Bank b "
+ " WHERE b.IsOwnBank='Y' "
+ " AND a.AD_Client_ID=i.AD_Client_ID "
+ " AND a.C_Bank_ID=b.C_Bank_ID "
+ " AND a.AccountNo=i.BankAccountNo "
+ " AND b.RoutingNo=i.RoutingNo "
+ " OR b.SwiftCode=i.RoutingNo "
+ ") "
+ "WHERE i.C_BankAccount_ID IS NULL "
+ "AND i.I_IsImported<>'Y' "
+ "OR i.I_IsImported IS NULL").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.info("Bank Account (With Routing No)=" + no);
//
sql = new StringBuffer("UPDATE I_BankStatement i "
+ "SET C_BankAccount_ID="
+ "( "
+ " SELECT C_BankAccount_ID "
+ " FROM C_BankAccount a, C_Bank b "
+ " WHERE b.IsOwnBank='Y' "
+ " AND a.C_Bank_ID=b.C_Bank_ID "
+ " AND a.AccountNo=i.BankAccountNo "
+ " AND a.AD_Client_ID=i.AD_Client_ID "
+ ") "
+ "WHERE i.C_BankAccount_ID IS NULL "
+ "AND i.I_isImported<>'Y' "
+ "OR i.I_isImported IS NULL").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.info("Bank Account (Without Routing No)=" + no);
//
sql = new StringBuffer("UPDATE I_BankStatement i "
+ "SET C_BankAccount_ID=(SELECT C_BankAccount_ID FROM C_BankAccount a WHERE a.C_BankAccount_ID=").append(m_C_BankAccount_ID);
sql.append(" and a.AD_Client_ID=i.AD_Client_ID) "
+ "WHERE i.C_BankAccount_ID IS NULL "
+ "AND i.BankAccountNo IS NULL "
+ "AND i.I_isImported<>'Y' "
+ "OR i.I_isImported IS NULL").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.info("Bank Account=" + no);
//
sql = new StringBuffer("UPDATE I_BankStatement "
+ "SET I_isImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Bank Account, ' "
+ "WHERE C_BankAccount_ID IS NULL "
+ "AND I_isImported<>'Y' "
+ "OR I_isImported IS NULL").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning("Invalid Bank Account=" + no);
// Set Currency
sql = new StringBuffer ("UPDATE I_BankStatement i "
+ "SET C_Currency_ID=(SELECT C_Currency_ID FROM C_Currency c"
+ " WHERE i.ISO_Code=c.ISO_Code AND c.AD_Client_ID IN (0,i.AD_Client_ID)) "
+ "WHERE C_Currency_ID IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.info("Set Currency=" + no);
//
sql = new StringBuffer("UPDATE I_BankStatement i "
+ "SET i.C_Currency_ID=(SELECT C_Currency_ID FROM C_BankAccount WHERE C_BankAccount_ID=i.C_BankAccount_ID) "
+ "WHERE i.C_Currency_ID IS NULL "
+ "AND i.ISO_Code IS NULL").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.info("Set Currency=" + no);
//
sql = new StringBuffer ("UPDATE I_BankStatement "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Currency,' "
+ "WHERE C_Currency_ID IS NULL "
+ "AND I_IsImported<>'E' "
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning("Invalid Currency=" + no);
// Set Amount
sql = new StringBuffer("UPDATE I_BankStatement "
+ "SET ChargeAmt=0 "
+ "WHERE ChargeAmt IS NULL "
+ "AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.info("Charge Amount=" + no);
//
sql = new StringBuffer("UPDATE I_BankStatement "
+ "SET InterestAmt=0 "
+ "WHERE InterestAmt IS NULL "
+ "AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.info("Interest Amount=" + no);
//
sql = new StringBuffer("UPDATE I_BankStatement "
+ "SET TrxAmt=StmtAmt - InterestAmt - ChargeAmt "
+ "WHERE TrxAmt IS NULL "
+ "AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.info("Transaction Amount=" + no);
//
sql = new StringBuffer("UPDATE I_BankStatement "
+ "SET I_isImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Amount, ' "
+ "WHERE TrxAmt + ChargeAmt + InterestAmt <> StmtAmt "
+ "AND I_isImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.info("Invaid Amount=" + no);
// Set Valuta Date
sql = new StringBuffer("UPDATE I_BankStatement "
+ "SET ValutaDate=StatementLineDate "
+ "WHERE ValutaDate IS NULL "
+ "AND I_isImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.info("Valuta Date=" + no);
// Check Payment<->Invoice combination
sql = new StringBuffer("UPDATE I_BankStatement "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Payment<->Invoive, ' "
+ "WHERE I_BankStatement_ID IN "
+ "( "
+ " SELECT I_BankStatement_ID "
+ " FROM I_BankStatement i, C_Payment p "
+ " WHERE i.C_Invoice_ID IS NOT NULL "
+ " AND i.C_Payment_ID IS NOT NULL "
+ " AND p.C_Invoice_ID IS NOT NULL "
+ " AND p.C_Invoice_ID<>i.C_Invoice_ID "
+ " GROUP BY I_BankStatement_ID "
+ ")").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.info("Payment<->Invoice Mismatch=" + no);
// Check Payment<->BPartner combination
sql = new StringBuffer("UPDATE I_BankStatement "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Payment<->BPartner, ' "
+ "WHERE I_BankStatement_ID IN "
+ "( "
+ " SELECT I_BankStatement_ID "
+ " FROM I_BankStatement i, C_Payment p "
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -