📄 importreportline.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 Original Code is Compiere ERP & CRM Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.process;
import java.math.*;
import java.sql.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Import ReportLines from I_ReportLine
*
* @author Jorg Janke
* @version $Id: ImportReportLine.java,v 1.19 2005/10/28 00:59:28 jjanke Exp $
*/
public class ImportReportLine extends SvrProcess
{
/** Client to be imported to */
private int m_AD_Client_ID = 0;
/** Default Report Line Set */
private int m_PA_ReportLineSet_ID = 0;
/** Delete old Imported */
private boolean m_deleteOldImported = false;
/** Organization to be imported to */
private int m_AD_Org_ID = 0;
/** Effective */
private Timestamp m_DateValue = null;
/**
* 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("PA_ReportLineSet_ID"))
m_PA_ReportLineSet_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);
}
if (m_DateValue == null)
m_DateValue = new Timestamp (System.currentTimeMillis());
} // prepare
/**
* Perrform process.
* @return Message
* @throws Exception
*/
protected String doIt() throws java.lang.Exception
{
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_ReportLine "
+ "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_ReportLine "
+ "SET AD_Client_ID = COALESCE (AD_Client_ID, ").append(m_AD_Client_ID).append("),"
+ " AD_Org_ID = COALESCE (AD_Org_ID, 0),"
+ " 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.fine("Reset=" + no);
// ReportLineSetName (Default)
if (m_PA_ReportLineSet_ID != 0)
{
sql = new StringBuffer ("UPDATE I_ReportLine i "
+ "SET ReportLineSetName=(SELECT Name FROM PA_ReportLineSet r"
+ " WHERE PA_ReportLineSet_ID=").append(m_PA_ReportLineSet_ID).append(" AND i.AD_Client_ID=r.AD_Client_ID) "
+ "WHERE ReportLineSetName IS NULL AND PA_ReportLineSet_ID IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set ReportLineSetName Default=" + no);
}
// Set PA_ReportLineSet_ID
sql = new StringBuffer ("UPDATE I_ReportLine i "
+ "SET PA_ReportLineSet_ID=(SELECT PA_ReportLineSet_ID FROM PA_ReportLineSet r"
+ " WHERE i.ReportLineSetName=r.Name AND i.AD_Client_ID=r.AD_Client_ID) "
+ "WHERE PA_ReportLineSet_ID IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set PA_ReportLineSet_ID=" + no);
//
sql = new StringBuffer ("UPDATE I_ReportLine "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid ReportLineSet, ' "
+ "WHERE PA_ReportLineSet_ID IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.config("Invalid ReportLineSet=" + no);
// Ignore if there is no Report Line Name or ID
sql = new StringBuffer ("UPDATE I_ReportLine "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Ignored=NoLineName, ' "
+ "WHERE PA_ReportLine_ID IS NULL AND Name IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.config("Invalid LineName=" + no);
// Validate ElementValue
sql = new StringBuffer ("UPDATE I_ReportLine i "
+ "SET C_ElementValue_ID=(SELECT C_ElementValue_ID FROM C_ElementValue e"
+ " WHERE i.ElementValue=e.Value AND i.AD_Client_ID=e.AD_Client_ID) "
+ "WHERE C_ElementValue_ID IS NULL AND ElementValue IS NOT NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set C_ElementValue_ID=" + no);
// Validate C_ElementValue_ID
sql = new StringBuffer ("UPDATE I_ReportLine "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid ElementValue, ' "
+ "WHERE C_ElementValue_ID IS NULL AND LineType<>'C'" // MReportLine.LINETYPE_Calculation
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.config("Invalid AccountType=" + no);
// Set SeqNo
sql = new StringBuffer ("UPDATE I_ReportLine "
+ "SET SeqNo=I_ReportLine_ID "
+ "WHERE SeqNo IS NULL"
+ " AND I_IsImported='N'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set SeqNo Default=" + no);
// Copy/Sync from first Row of Line
sql = new StringBuffer ("UPDATE I_ReportLine i "
+ "SET (Description, SeqNo, IsSummary, IsPrinted, LineType, CalculationType, AmountType, PostingType)="
+ " (SELECT Description, SeqNo, IsSummary, IsPrinted, LineType, CalculationType, AmountType, PostingType"
+ " FROM I_ReportLine ii WHERE i.Name=ii.Name AND i.PA_ReportLineSet_ID=ii.PA_ReportLineSet_ID"
+ " AND ii.I_ReportLine_ID=(SELECT MIN(I_ReportLine_ID) FROM I_ReportLine iii"
+ " WHERE i.Name=iii.Name AND i.PA_ReportLineSet_ID=iii.PA_ReportLineSet_ID)) "
+ "WHERE EXISTS (SELECT *"
+ " FROM I_ReportLine ii WHERE i.Name=ii.Name AND i.PA_ReportLineSet_ID=ii.PA_ReportLineSet_ID"
+ " AND ii.I_ReportLine_ID=(SELECT MIN(I_ReportLine_ID) FROM I_ReportLine iii"
+ " WHERE i.Name=iii.Name AND i.PA_ReportLineSet_ID=iii.PA_ReportLineSet_ID))"
+ " AND I_IsImported='N'").append(clientCheck); // not if previous error
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Sync from first Row of Line=" + no);
// Validate IsSummary - (N) Y
sql = new StringBuffer ("UPDATE I_ReportLine "
+ "SET IsSummary='N' "
+ "WHERE IsSummary IS NULL OR IsSummary NOT IN ('Y','N')"
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set IsSummary Default=" + no);
// Validate IsPrinted - (Y) N
sql = new StringBuffer ("UPDATE I_ReportLine "
+ "SET IsPrinted='Y' "
+ "WHERE IsPrinted IS NULL OR IsPrinted NOT IN ('Y','N')"
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set IsPrinted Default=" + no);
// Validate Line Type - (S) C
sql = new StringBuffer ("UPDATE I_ReportLine "
+ "SET LineType='S' "
+ "WHERE LineType IS NULL OR LineType NOT IN ('S','C')"
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set LineType Default=" + no);
// Validate Optional Calculation Type - A P R S
sql = new StringBuffer ("UPDATE I_ReportLine "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid CalculationType, ' "
+ "WHERE CalculationType IS NOT NULL AND CalculationType NOT IN ('A','P','R','S')"
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.config("Invalid CalculationType=" + no);
// Validate Optional Amount Type -
sql = new StringBuffer ("UPDATE I_ReportLine "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid CalculationType, ' "
+ "WHERE AmountType IS NOT NULL AND UPPER(AmountType) NOT IN ('BP','CP','DP','QP', 'BY','CY','DY','QY', 'BT','CT','DT','QT')"
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.config("Invalid AmountType=" + no);
// Validate Optional Posting Type - A B E S R
sql = new StringBuffer ("UPDATE I_ReportLine "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid CalculationType, ' "
+ "WHERE PostingType IS NOT NULL AND PostingType NOT IN ('A','B','E','S','R')"
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.config("Invalid PostingType=" + no);
// Set PA_ReportLine_ID
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -