Update of /cvsroot/compiere/base/src/org/compiere/process In directory sc8-pr-cvs1:/tmp/cvs-serv11957/src/org/compiere/process Modified Files: Tag: pbs_payment ReportLineSet_Copy.java InvoicePrint.java ImportInvoice.java ExpenseSOrder.java RequestAction.java AssetDelivery.java ImportBPartner.java ImportOrder.java InventoryValue.java PaymentProcess.java ImportAccount.java ImportProduct.java ImportReportLine.java ReportColumnSet_Copy.java ExpenseAPInvoice.java Added Files: Tag: pbs_payment ProjectLinePricing.java ReplicationLocal.java ImportBankStatement.java SendMailText.java ProjectClose.java ReplicationRemote.java ProjectSetType.java CopyFromJournal.java ImportInventory.java ProjectGenPO.java ProjectIssue.java RemoteSetupVO.java Recurring.java ProjectGenOrder.java RemoteUpdateVO.java RemoteMergeDataVO.java CopyFromInvoice.java CopyFromOrder.java ImportGLJournal.java CopyFromProject.java ProjectPhaseGenOrder.java Log Message: Aligning with CVS HEAD --- NEW FILE: ProjectLinePricing.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 and ComPiere, Inc. * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.process; import java.math.*; import java.util.*; import java.sql.*; import org.compiere.model.*; import org.compiere.util.*; /** * Price Project Line. * * @author Jorg Janke * @version $Id: ProjectLinePricing.java,v 1.1.2.1 2003/09/24 17:45:35 jpedersen Exp $ */ public class ProjectLinePricing extends SvrProcess { /** Project Line from Record */ private int m_C_ProjectLine_ID = 0; /** * 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 log.error("prepare - Unknown Parameter: " + name); } m_C_ProjectLine_ID = getRecord_ID(); } // prepare /** * Perrform process. * @return Message (clear text) * @throws Exception if not successful */ protected String doIt() throws Exception { if (m_C_ProjectLine_ID == 0) throw new IllegalArgumentException("No Project Line"); MProjectLine projectLine = new MProjectLine (getCtx(), m_C_ProjectLine_ID); log.info("doIt - " + projectLine); if (projectLine.getM_Product_ID() == 0) throw new IllegalArgumentException("No Product"); // MProject project = new MProject (getCtx(), projectLine.getC_Project_ID()); if (project.getM_PriceList_ID() == 0) throw new IllegalArgumentException("No PriceList"); // return "Not Implemented (yet)"; } // doIt } // ProjectLinePricing --- NEW FILE: ReplicationLocal.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 and ComPiere, Inc. * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.process; import java.util.*; import java.sql.*; import javax.naming.*; import javax.sql.*; import java.math.*; import org.apache.log4j.Logger; import org.compiere.db.*; import org.compiere.util.*; import org.compiere.process.*; import org.compiere.model.*; import org.compiere.interfaces.*; import java.rmi.*; /** * Local (Central) Data Replication. * Note: requires migration technology * * @author Jorg Janke * @version $Id: ReplicationLocal.java,v 1.5.2.1 2003/09/24 17:45:35 jpedersen Exp $ */ public class ReplicationLocal extends SvrProcess { /** * Replication */ public ReplicationLocal() { m_system = MSystem.get (getCtx()); } // Replication /** System Record */ private MSystem m_system = null; /** Replication Info */ private MReplication m_replication = null; /** Replication Run */ private MReplicationRun m_replicationRun = null; /** Test Flag */ private Boolean m_test = Boolean.FALSE; /** Replication Flag */ private boolean m_replicated = true; /** Remote Server */ private Server m_serverRemote = null; private long m_start = System.currentTimeMillis(); /** Date Run on Remote */ private Timestamp m_replicationStart = new Timestamp (m_start); /** Logger */ private static Logger s_log = Logger.getLogger(ReplicationLocal.class); /** Remote class */ private static String REMOTE = "org.compiere.process.ReplicationRemote"; protected static String START = "com.compiere.client.StartReplication"; /** * Prepare - e.g., get Parameters. */ public 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("IsTest")) m_test = Boolean.valueOf("Y".equals (para[i].getParameter())); else log.error("prepare - Unknown Parameter: " + name); } } // prepare /** * Perrform process. * @return Message * @throws Exception if not successful */ public String doIt() throws Exception { if (!m_system.isValid()) { log.error("System not setup correctly for Migration"); throw new Exception ("SystemNotSetup"); } log.info("doIt - Record_ID=" + getRecord_ID() + ", test=" + m_test); connectRemote(); // setupRemote(); mergeData(); sendUpdates(); // Save Info log.info("doIt - Replicated=" + m_replicated + " - " + m_replicationStart); m_replicationRun.setIsReplicated(m_replicated); double sec = (System.currentTimeMillis() - m_start); sec /= 1000; m_replicationRun.setDescription(sec + " s"); m_replicationRun.save(); if (m_replicated) { m_replication.setDateLastRun (m_replicationStart); m_replication.save(); } // exit(); return m_replicated ? "Replicated" : "Replication Error"; } // doIt /** * Connect to Remote Server * @throws java.lang.Exception */ private void connectRemote() throws Exception { // Replication Info m_replication = new MReplication (getCtx(), getRecord_ID()); // String AppsHost = m_replication.getHostAddress(); int AppsPort = m_replication.getHostPort(); boolean RMIoverHTTP = m_replication.isRMIoverHTTP(); log.info ("connectRemote - " + AppsHost + ":" + AppsPort + " - HTTP Tunnel=" + RMIoverHTTP); InitialContext ic = CConnection.getInitialContext( CConnection.getInitialEnvironment(AppsHost, AppsPort, RMIoverHTTP)); if (ic == null) throw new Exception ("NoInitialContext"); try { ServerHome serverHome = (ServerHome)ic.lookup (ServerHome.JNDI_NAME); // log.debug("- ServerHome: " + serverHome); if (serverHome == null) throw new Exception ("NoServer"); m_serverRemote = serverHome.create(); // log.debug("- Server: " + m_serverRemote); // log.debug("- Remote Status = " + m_serverRemote.getStatus()); } catch (Exception ex) { log.error("connectRemote", ex); throw new Exception (ex); } } // connectRemote /** * Setup Remote AD_System/AD_Table/AD_Sequence for Remote Management. * @throws Exception */ private void setupRemote() throws Exception { log.info("setupRemote"); // String sql = "SELECT rt.AD_Table_ID, rt.ReplicationType, t.TableName " + "FROM AD_ReplicationTable rt" + " INNER JOIN AD_Table t ON (rt.AD_Table_ID=t.AD_Table_ID) " + "WHERE rt.IsActive='Y' AND t.IsActive='Y'" + " AND AD_ReplicationStrategy_ID=? " // #1 + "ORDER BY t.LoadSeq"; RowSet rowset = getRowSet(sql, new Object[]{new Integer(m_replication.getAD_ReplicationStrategy_ID())}); if (rowset == null) throw new Exception("setupRemote - No RowSet Data"); // Data Info RemoteSetupVO data = new RemoteSetupVO(); data.Test = m_test; data.ReplicationTable = rowset; // RowSet data.IDRangeStart = m_replication.getIDRangeStart(); data.IDRangeEnd = m_replication.getIDRangeEnd(); data.AD_Client_ID = m_replication.getRemote_Client_ID(); data.AD_Org_ID = m_replication.getRemote_Org_ID(); data.Prefix = m_replication.getPrefix(); data.Suffix = m_replication.getSuffix(); // Process Info ProcessInfo pi = new ProcessInfo(data.toString(), 0, 0); pi.setClassName (REMOTE); pi.setSerializableObject(data); Object result = doIt(START, "init", new Object[]{m_system}); if (result == null || !Boolean.TRUE.equals(result)) throw new Exception("setupRemote - Init Error - " + result); // send it pi = m_serverRemote.process (new Properties (), pi); ProcessInfoLog[] logs = pi.getLogs(); Timestamp dateRun = null; if (logs != null && logs.length > 0) dateRun = logs[0].getP_Date(); // User Remote Timestamp! // log.info ("setupRemote - " + pi + " - Remote Timestamp = " + dateRun); if (dateRun != null) m_replicationStart = dateRun; m_replicationRun = new MReplicationRun (getCtx(), m_replication.getAD_Replication_ID(), m_replicationStart); m_replicationRun.save(); } // setupRemote /*************************************************************************/ /** * Receive new Data from Remote. * @throws Exception */ private void mergeData() throws Exception { log.info("receiveNewData"); // String sql = "SELECT rt.AD_Table_ID, rt.ReplicationType, t.TableName, rt.AD_ReplicationTable_ID " + "FROM AD_ReplicationTable rt" + " INNER JOIN AD_Table t ON (rt.AD_Table_ID=t.AD_Table_ID) " + "WHERE rt.IsActive='Y' AND t.IsActive='Y'" + " AND AD_ReplicationStrategy_ID=?" // #1 + " AND rt.ReplicationType='M' " // Merge + "ORDER BY t.LoadSeq"; RowSet rowset = getRowSet(sql, new Object[]{new Integer(m_replication.getAD_ReplicationStrategy_ID())}); try { while (rowset.next()) mergeDataTable (rowset.getInt(1), rowset.getString(3), rowset.getInt(4)); rowset.close(); rowset = null; } catch (SQLException ex) { log.error("mergeData", ex); m_replicated = false; } } // mergeData /** * Receive New Data from Remote (and send local updates) * @param AD_Table_ID table id * @param TableName table name * @param AD_ReplicationTable_ID id * @return true if success * @throws java.lang.Exception */ private boolean mergeDataTable (int AD_Table_ID, String TableName, int AD_ReplicationTable_ID) throws Exception { RemoteMergeDataVO data = new RemoteMergeDataVO(); data.Test = m_test; data.TableName = TableName; // Create SQL StringBuffer sql = new StringBuffer("SELECT * FROM ") .append(TableName) .append(" WHERE AD_Client_ID=").append(m_replication.getRemote_Client_ID()); if (m_replication.getRemote_Org_ID() != 0) sql.append(" AND AD_Org_ID IN (0,").append(m_replication.getRemote_Org_ID()).append(")"); if (m_replication.getDateLastRun() != null) sql.append(" AND Updated >= ").append(DB.TO_DATE(m_replication.getDateLastRun(), false)); sql.append(" ORDER BY "); data.KeyColumns = getKeyColumns(AD_Table_ID); if (data.KeyColumns == null || data.KeyColumns.length == 0) { log.error("mergeDataTable - No KeyColumns for " + TableName); m_replicated = false; return false; } for (int i = 0; i < data.KeyColumns.length; i++) { if (i > 0) sql.append(","); sql.append(data.KeyColumns[i]); } data.Sql = sql.toString(); // New Central Data data.CentralData = getRowSet(data.Sql, null); if (data.CentralData == null) { log.debug("mergeDataTable - CentralData is Null - " + TableName); m_replicated = false; return false; } // Process Info ProcessInfo pi = new ProcessInfo("MergeData", 0, 0); pi.setClassName (REMOTE); pi.setSerializableObject(data); // send it pi = m_serverRemote.process (new Properties (), pi); ProcessInfoLog[] logs = pi.getLogs(); String msg = "< "; if (logs != null && logs.length > 0) msg += logs[0].getP_Msg(); // Remote Message log.info("mergeDataTable - " + pi); // MReplicationLog rLog = new MReplicationLog (getCtx(), m_replicationRun.getAD_Replication_Run_ID(), AD_ReplicationTable_ID, msg); if (pi.isError()) { log.error ("mergeDataTable Error - " + pi); m_replicated = false; rLog.setIsReplicated(false); } else // import data fom remote { RowSet sourceRS = (RowSet)pi.getSerializableObject(); RowSet targetRS = getRowSet(data.Sql, null); Object result = doIt (START, "sync", new Object[] // Merge {data.TableName, data.KeyColumns, sourceRS, targetRS, m_test, Boolean.TRUE}); boolean replicated = isReplicated(result); if (replicated) log.debug ("mergeDataTable -> " + TableName + " - " + result); else { m_replicated = false; log.error ("mergeDataTable -> " + TableName + " - " + result); } rLog.setIsReplicated(replicated); if (result != null) rLog.setP_Msg("< " + result.toString()); sourceRS.close(); sourceRS = null; targetRS.close(); targetRS = null; } rLog.save(); return !pi.isError(); } // mergeDataTable /** * Get Key Columns (PK or FK) of Table * @param AD_Table_ID id * @return Key Columns */ public String[] getKeyColumns (int AD_Table_ID) { ArrayList list = new ArrayList(); PreparedStatement pstmt = null; try { // Get Keys String sql = "SELECT ColumnName FROM AD_Column " + "WHERE AD_Table_ID=?" + " AND IsKey='Y'"; pstmt = DB.prepareStatement(sql); pstmt.setInt(1, AD_Table_ID); ResultSet rs = pstmt.executeQuery(); while (rs.next()) list.add(rs.getString(1)); rs.close(); // no keys - search for parents if (list.size() == 0) { sql = "SELECT ColumnName FROM AD_Column " + "WHERE AD_Table_ID=?" + " AND IsParent='Y'"; pstmt = DB.prepareStatement(sql); pstmt.setInt(1, AD_Table_ID); rs = pstmt.executeQuery(); while (rs.next()) list.add(rs.getString(1)); rs.close(); } pstmt.close(); pstmt = null; } catch (Exception e) { log.error("getKeyColumns", e); } try { if (pstmt != null) pstmt.close(); } catch (Exception e) { } // Convert to Array String[] retValue = new String[list.size()]; list.toArray(retValue); return retValue; } // getKeyColumns /*************************************************************************/ /** * Send Updates to Remote (i.e. r/o on remote) * @throws Exception */ private void sendUpdates() throws Exception { log.info("sendUpdates"); // String sql = "SELECT rt.AD_Table_ID, rt.ReplicationType, t.TableName, rt.AD_ReplicationTable_ID " + "FROM AD_ReplicationTable rt" + " INNER JOIN AD_Table t ON (rt.AD_Table_ID=t.AD_Table_ID) " + "WHERE rt.IsActive='Y' AND t.IsActive='Y'" + " AND AD_ReplicationStrategy_ID=?" // #1 + " AND rt.ReplicationType='R' " // Reference + "ORDER BY t.LoadSeq"; RowSet rowset = getRowSet(sql, new Object[]{new Integer(m_replication.getAD_ReplicationStrategy_ID())}); try { while (rowset.next()) sendUpdatesTable (rowset.getInt(1), rowset.getString(3), rowset.getInt(4)); rowset.close(); } catch (SQLException ex) { log.error("sendUpdates", ex); m_replicated = false; } } // sendUpdates /** * Send UPdates to Remote * @param AD_Table_ID table id * @param TableName table * @param AD_ReplicationTable_ID id * @return true if success * @throws Exception */ private boolean sendUpdatesTable (int AD_Table_ID, String TableName, int AD_ReplicationTable_ID) throws Exception { RemoteUpdateVO data = new RemoteUpdateVO(); data.Test = m_test; data.TableName = TableName; // Create SQL StringBuffer sql = new StringBuffer ("SELECT * FROM ") .append(TableName) .append(" WHERE AD_Client_ID=").append(m_replication.getRemote_Client_ID()); if (m_replication.getRemote_Org_ID() != 0) sql.append(" AND AD_Org_ID IN (0,").append(m_replication.getRemote_Org_ID()).append(")"); if (m_replication.getDateLastRun() != null) sql.append(" AND Updated >= ").append(DB.TO_DATE(m_replication.getDateLastRun(), false)); sql.append(" ORDER BY "); data.KeyColumns = getKeyColumns(AD_Table_ID); if (data.KeyColumns == null || data.KeyColumns.length == 0) { log.error("sendUpdatesTable - No KeyColumns for " + TableName); m_replicated = false; return false; } for (int i = 0; i < data.KeyColumns.length; i++) { if (i > 0) sql.append(","); sql.append(data.KeyColumns[i]); } data.Sql = sql.toString(); // New Data data.CentralData = getRowSet(data.Sql, null); if (data.CentralData == null) { log.debug("sendUpdatesTable - Null - " + TableName); m_replicated = false; return false; } int rows = 0; try { if (data.CentralData.last()) rows = data.CentralData.getRow(); data.CentralData.beforeFirst(); // rewind } catch (SQLException ex) { log.debug("sendUpdatesTable - RowCheck", ex); m_replicated = false; return false; } if (rows == 0) { log.debug("sendUpdatesTable - No Rows - " + TableName); return true; } else log.debug("sendUpdatesTable - " + TableName + " #" + rows); // Process Info ProcessInfo pi = new ProcessInfo("SendUpdates", 0, 0); pi.setClassName (REMOTE); pi.setSerializableObject(data); // send it pi = m_serverRemote.process (new Properties (), pi); log.info("sendUpdatesTable - " + pi); ProcessInfoLog[] logs = pi.getLogs(); String msg = "> "; if (logs != null && logs.length > 0) msg += logs[0].getP_Msg(); // Remote Message // MReplicationLog rLog = new MReplicationLog (getCtx(), m_replicationRun.getAD_Replication_Run_ID(), AD_ReplicationTable_ID, msg); if (pi.isError()) m_replicated = false; rLog.setIsReplicated(!pi.isError()); rLog.save(); return !pi.isError(); } // sendUpdatesTable /** * Clean up resources (connections) */ private void exit() { log.info ("exit"); Object result = doIt(START, "exit", null); ProcessInfo pi = new ProcessInfo("Exit", 0, 0); pi.setClassName (REMOTE); pi.setSerializableObject(m_replicationStart); // send it try { m_serverRemote.process (new Properties (), pi); } catch (Exception ex) { } } // exit /*************************************************************************/ /** * Get RowSet of Local Connection * @param sql sql * @param args optional argument array - supported: Integer, Timestamp, BigDecimal - rest is concerted to String * @return row set */ public static RowSet getRowSet (String sql, Object[] args) { RowSet retValue = null; PreparedStatement pstmt = null; try { pstmt = DB.prepareStatement (sql); if (args != null) { for (int i = 0; i < args.length; i++) { if (args[i] == null) s_log.error("getRowSet - NULL Argument " + i); else if (args[i] instanceof Integer) pstmt.setInt(i+1, ((Integer)args[i]).intValue()); else if (args[i] instanceof Timestamp) pstmt.setTimestamp(i+1, (Timestamp)args[i]); else if (args[i] instanceof BigDecimal) pstmt.setBigDecimal(i+1, (BigDecimal)args[i]); else pstmt.setString(i+1, args[i].toString()); } } ResultSet rs = pstmt.executeQuery (); // retValue = DB.getDatabase().getRowSet(rs); // rs.close(); pstmt.close (); pstmt = null; } catch (SQLException ex) { s_log.error ("getRowSet - " + sql, ex); } try { if (pstmt != null) pstmt.close (); } catch (SQLException ex1) { } pstmt = null; return retValue; } // getRowSet /** * Is data successful replicated * @param result sync return value * @return true if replicated */ public static boolean isReplicated (Object result) { boolean replicated = result != null && !Boolean.FALSE.equals(result); if (replicated) replicated = result.toString().endsWith("Errors=0"); return replicated; } // isReplicated } // ReplicationLocal --- NEW FILE: 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 Original Code is Compiere ERP & CRM Business Solution * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc. * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.process; import java.sql.*; import java.math.*; import org.compiere.model.*; import org.compiere.util.DB; /** * Import Bank Statement from I_BankStatement * * @author Jorg Janke * @version $Id: ImportBankStatement.java,v 1.1.2.1 2003/09/24 17:45:35 jpedersen 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; /** * 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.error("prepare - Unknown Parameter: " + name); } } // 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_BankStatement " + "WHERE I_IsImported='Y'").append (clientCheck); no = DB.executeUpdate (sql.toString ()); log.debug ("doIt - 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 ()); log.info ("doIt - 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 ()); if (no != 0) log.warn ("doIt - Invalid Org=" + no); throw new IllegalStateException("Not implemented yet"); } // doIt } // ImportBankStatement --- NEW FILE: SendMailText.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 and ComPiere, Inc. * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.process; import java.sql.*; import java.math.*; import org.compiere.util.*; import org.compiere.model.*; /** * Send Mail to Interest Area Subscribers * * @author Jorg Janke * @version $Id: SendMailText.java,v 1.3.2.1 2003/09/24 17:45:35 jpedersen Exp $ */ public class SendMailText extends SvrProcess { /** * Constructor */ public SendMailText() { } // SendMailText private int m_R_MailText_ID = -1; private int m_R_InterestArea_ID = -1; private int m_C_BP_Group_ID = -1; private int m_AD_User_ID = -1; /** Mail Text */ private MMailText m_MailText = null; /** Client Info */ private MClient m_Client = null; /** User Info */ private MUser m_User = null; /** From */ private String m_from = null; private String m_fromID = null; private String m_fromPW = 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("R_InterestArea_ID")) m_R_InterestArea_ID = ((BigDecimal)para[i].getParameter()).intValue(); else if (name.equals("R_MailText_ID")) m_R_MailText_ID = ((BigDecimal)para[i].getParameter()).intValue(); else if (name.equals("C_BP_Group_ID")) m_C_BP_Group_ID = ((BigDecimal)para[i].getParameter()).intValue(); else if (name.equals("AD_User_ID")) m_AD_User_ID = ((BigDecimal)para[i].getParameter()).intValue(); else log.error("prepare - Unknown Parameter: " + name); } } // prepare /** * Perrform process. * @return Message * @throws Exception */ protected String doIt() throws Exception { log.info("doIt - R_MailText_ID=" + m_R_MailText_ID); // Mail Test m_MailText = new MMailText (getCtx(), m_R_MailText_ID); if (m_MailText.getR_MailText_ID() == 0) throw new Exception ("Not found @R_MailText_ID@=" + m_R_MailText_ID); // Client Info m_Client = MClient.get (getCtx()); if (m_Client.getAD_Client_ID() == 0) throw new Exception ("Not found @AD_Client_ID@"); if (m_Client.getSMTPHost() == null || m_Client.getSMTPHost().length() == 0) throw new Exception ("No SMTP Host found"); // if (m_AD_User_ID != -1) { m_User = new MUser (getCtx(), m_AD_User_ID); if (m_User.getAD_User_ID() == 0) throw new Exception ("No found @AD_User_ID@=" + m_AD_User_ID); } m_from = m_User == null ? m_Client.getRequestEMail() : m_User.getEmail(); m_fromID = m_User == null ? m_Client.getRequestUser() : m_User.getEmailUser(); m_fromPW = m_User == null ? m_Client.getRequestUserPW() : m_User.getEmailUserPW(); if (m_from == null || m_from.length() == 0 || m_fromID == null || m_fromID.length() == 0 || m_fromPW == null || m_fromPW.length() == 0) throw new Exception ("From EMail not complete - " + m_from + "(" + m_fromID + "/" + m_fromPW + ")"); log.debug("doIt - send from " + m_from + "(" + m_fromID + "/" + m_fromPW + ")"); long start = System.currentTimeMillis(); // Loop to Interest Area Subscribers ******************************* log.info("doIt - Send to R_InterestArea_ID=" + m_R_InterestArea_ID); String sql = "SELECT u.Name, u.EMail " + "FROM R_ContactInterest ci" + " INNER JOIN AD_User u ON (ci.AD_User_ID=u.AD_User_ID) " + "WHERE ci.IsActive='Y' AND u.IsActive='Y'" + " AND ci.OptOutDate IS NULL" + " AND u.EMail IS NOT NULL" + " AND ci.R_InterestArea_ID=?"; PreparedStatement pstmt = null; int counter = 0; int errors = 0; try { pstmt = DB.prepareStatement(sql); pstmt.setInt(1, m_R_InterestArea_ID); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { if (sendIndividualMail (rs.getString(1), rs.getString(2))) counter++; else errors++; } rs.close(); pstmt.close(); pstmt = null; } catch (SQLException ex) { log.error("doIt - InterestArea", ex); } // Loop to Interest Area Subscribers ******************************* log.info("doIt - Send to C_BP_Group_ID=" + m_C_BP_Group_ID); sql = "SELECT u.Name, u.EMail " + "FROM AD_User u" + " INNER JOIN C_BPartner bp ON (u.C_BPartner_ID=bp.C_BPartner_ID) " + "WHERE u.IsActive='Y' AND bp.IsActive='Y'" + " AND u.EMail IS NOT NULL" + " AND bp.C_BP_Group_ID=?"; try { pstmt = DB.prepareStatement(sql); pstmt.setInt(1, m_C_BP_Group_ID); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { if (sendIndividualMail (rs.getString(1), rs.getString(2))) counter++; else errors++; } rs.close(); pstmt.close(); pstmt = null; } catch (SQLException ex) { log.error("doIt - BP_Group", ex); } // Cleanup try { if (pstmt != null) pstmt.close(); } catch (SQLException ex1) { } pstmt = null; return "@Created@=" + counter + ", @Errors@=" + errors + " - " + (System.currentTimeMillis()-start) + "ms"; } // doIt /** * Send Individual Mail * @param Name name * @param EMailAddress email * @return true if mail has been sent */ private boolean sendIndividualMail (String Name, String EMailAddress) { String subject = m_MailText.getMailHeader(); String message = m_MailText.getMailText(); // EMail mail = new EMail (m_Client.getSMTPHost(), m_from, EMailAddress, subject, message); mail.setEMailUser(m_fromID, m_fromPW); boolean OK = EMail.SENT_OK.equals(mail.send()); if (OK) log.debug("sendIndividualMail - " + EMailAddress); else log.warn("sendIndividualMail FAILURE - " + EMailAddress); addLog(0, null, null, (OK ? "OK" : "ERROR") + " - " + EMailAddress); return OK; } // sendIndividualMail } // SendMailText --- NEW FILE: ProjectClose.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 and ComPiere, Inc. * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.process; import java.math.*; import java.util.*; import java.sql.*; import org.compiere.model.*; import org.compiere.util.*; /** * Close Project. * * @author Jorg Janke * @version $Id: ProjectClose.java,v 1.2.2.1 2003/09/24 17:45:36 jpedersen Exp $ */ public class ProjectClose extends SvrProcess { /** Project from Record */ private int m_C_Project_ID = 0; /** * 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 log.error("prepare - Unknown Parameter: " + name); } m_C_Project_ID = getRecord_ID(); } // prepare /** * Perrform process. * @return Message (clear text) * @throws Exception if not successful */ protected String doIt() throws Exception { MProject project = new MProject (getCtx(), m_C_Project_ID); log.info("doIt - " + project); MProjectLine[] projectLines = project.getLines(); if (MProject.PROJECTCATEGORY_WorkOrderJob.equals(project.getProjectCategory()) || MProject.PROJECTCATEGORY_AssetProject.equals(project.getProjectCategory())) { /** @todo Check if we should close it */ } // Close lines for (int line = 0; line < projectLines.length; line++) { projectLines[line].setProcessed(true); projectLines[line].save(); } project.setProcessed(true); project.save(); return ""; } // doIt } // ProjectClose --- NEW FILE: ReplicationRemote.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 and ComPiere, Inc. * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.process; import javax.sql.*; import java.math.BigDecimal; import java.io.*; import org.compiere.db.*; import org.compiere.util.*; import org.compiere.process.*; import org.compiere.model.*; import org.compiere.interfaces.*; import java.sql.*; /** * Remote Data Replication. * Note: requires migration technology * * @author Jorg Janke * @version $Id: ReplicationRemote.java,v 1.5.2.1 2003/09/24 17:45:36 jpedersen Exp $ */ public class ReplicationRemote extends SvrProcess { /** * Constructor */ public ReplicationRemote() { m_system = MSystem.get (getCtx()); } // ReplicationRemote /** System Record */ private MSystem m_system = null; /** Local Timestamp */ private Timestamp m_startDate = new Timestamp(System.currentTimeMillis()); /** * Prepare - e.g., get Parameters. */ public void prepare() { ProcessInfoParameter[] para = getParameter(); for (int i = 0; i < para.length; i++) { String name = para[i].getParameterName(); if (para[i].getParameter() == null) ; else log.error("prepare - Unknown Parameter: " + name); } } // prepare /** * Perrform process. * @return Message * @throws Exception if not successful */ public String doIt() throws Exception { ProcessInfo pi = getProcessInfo(); log.info("doIt - " + pi.getTitle()); if (pi.getSerializableObject() instanceof RemoteSetupVO) return setupRemote(); else if (pi.getSerializableObject() instanceof RemoteMergeDataVO) return mergeDataWithCentral(); else if (pi.getSerializableObject() instanceof RemoteUpdateVO) return receiveUpdateFromCentral(); else if (pi.getSerializableObject() instanceof Timestamp) return exit(); else throw new Exception ("ReplicationRemote - unknown VO - " + pi.getSerializableObject()); } // doIt /*************************************************************************/ /** * Setup Remote AD_System/AD_Table/AD_Sequence for Remote Management. * @return "" or error message * @throws Exception */ private String setupRemote() throws Exception { ProcessInfo pi = getProcessInfo(); RemoteSetupVO data = (RemoteSetupVO)pi.getSerializableObject(); log.info("setupRemote Start (" + pi + ") " + data); RowSet rs = data.ReplicationTable; try { // Update AD_System **** if (data.IDRangeStart == null || data.IDRangeEnd == null) throw new Exception ("setupRemote - IDRange cannot be null"); if (!data.Test.booleanValue()) { setupRemoteAD_System (data.IDRangeStart, data.IDRangeEnd); // Update AD_Sequence **** setupRemoteAD_Sequence (data.IDRangeStart); // Update DocNo Prefix/Suffix **** setupRemoteC_DocType (data.AD_Client_ID, data.Prefix, data.Suffix); } // Update Tables **** while (rs.next ()) { int AD_Table_ID = rs.getInt(1); String ReplicationType = rs.getString(2); String TableName = rs.getString(3); log.debug("setupRemote - " + TableName + " - " + ReplicationType); if (!data.Test.booleanValue()) setupRemoteAD_Table(TableName, ReplicationType); } pi.setSummary("OK - Test=" + data.Test, false); } catch (Exception ex) { log.error("setupRemote", ex); pi.setSummary(ex.toString(), true); } Object result = doIt(ReplicationLocal.START, "init", new Object[]{m_system}); if (result == null || !Boolean.TRUE.equals(result)) throw new Exception("setupRemote - Init Error - " + result); pi.setSerializableObject(null); pi.addLog(0,0, m_startDate, null, null); log.info("setupRemote End (" + pi + ") " + data); return "Remote SetupRemote OK"; } // setupRemote /** * Update Replication Type and ID Range of AD_System * @param IDRangeStart start * @param IDRangeEnd end * @throws Exception if sql error */ private void setupRemoteAD_System (BigDecimal IDRangeStart, BigDecimal IDRangeEnd) throws Exception { m_system.setIDRangeStart(IDRangeStart); m_system.setIDRangeEnd(IDRangeEnd); m_system.setReplicationType(MSystem.REPLICATIONTYPE_Merge); m_system.save(); } // setupRemoteAD_System /** * Update StartNo/CurrentNext/CurrentNextSys in AD_Sequence * @param IDRangeStart start * @throws Exception if sql error */ private void setupRemoteAD_Sequence (BigDecimal IDRangeStart) throws Exception { String sql = "UPDATE AD_Sequence SET StartNo = " + IDRangeStart + " WHERE IsTableID='Y' AND StartNo < " + IDRangeStart; int no = DB.executeUpdate(sql); if (no == -1) throw new Exception("setupRemoteAD_Sequence_Start"); // sql = "UPDATE AD_Sequence SET CurrentNext = " + IDRangeStart + " WHERE IsTableID='Y' AND CurrentNext < " + IDRangeStart; no = DB.executeUpdate(sql); if (no == -1) throw new Exception("setupRemoteAD_Sequence_Next"); // sql = "UPDATE AD_Sequence SET CurrentNextSys = -1" + " WHERE IsTableID='Y' AND CurrentNextSys <> -1"; no = DB.executeUpdate(sql); if (no == -1) throw new Exception("setupRemoteAD_Sequence_Sys"); } // setupRemoteAD_Sequence /** * Update Document Prefix/Suffix * @param AD_Client_ID client * @param Prefix prefix * @param Suffix suffix * @throws Exception if sql error */ private void setupRemoteC_DocType (int AD_Client_ID, String Prefix, String Suffix) throws Exception { if (Prefix == null) Prefix = ""; if (Suffix == null) Suffix = ""; // DocNoSequence_ID String sql = "UPDATE AD_Sequence SET Prefix=" + DB.TO_STRING(Prefix) + ", Suffix=" + DB.TO_STRING(Suffix) + " WHERE AD_Sequence_ID IN (SELECT DocNoSequence_ID FROM C_DocType" + " WHERE AD_Client_ID=" + AD_Client_ID + " AND DocNoSequence_ID IS NOT NULL)"; int no = DB.executeUpdate(sql); if (no == -1) throw new Exception("setupRemoteC_DocType_DocNo"); // BatchNoSequence_ID sql = "UPDATE AD_Sequence SET Prefix=" + DB.TO_STRING(Prefix) + ", Suffix=" + DB.TO_STRING(Suffix) + " WHERE AD_Sequence_ID IN (SELECT BatchNoSequence_ID FROM C_DocType" + " WHERE AD_Client_ID=" + AD_Client_ID + " AND BatchNoSequence_ID IS NOT NULL)"; no = DB.executeUpdate(sql); if (no == -1) throw new Exception("setupRemoteC_DocType_Batch"); } // setupRemoteC_DocType /** * Set ReplicationType of AD_Table * @param TableName table name * @param ReplicationType replication type * @throws Exception if sql error */ private void setupRemoteAD_Table(String TableName, String ReplicationType) throws Exception { String sql = "UPDATE AD_Table SET ReplicationType = '" + ReplicationType + "' WHERE TableName='" + TableName + "' AND ReplicationType <> '" + ReplicationType + "'"; int no = DB.executeUpdate(sql); if (no == -1) throw new Exception("setupRemoteAD_Table"); } // setupRemoteAD_Table /*************************************************************************/ /** * Send new Data from Remote. * Transcation Data changed * @return info * @throws Exception */ private String mergeDataWithCentral() throws Exception { ProcessInfo pi = getProcessInfo(); RemoteMergeDataVO data = (RemoteMergeDataVO)pi.getSerializableObject(); log.info("mergeDataWithCentral Start (" + pi + ") " + data); // Merge Data from Central RowSet sourceRS = data.CentralData; if (sourceRS == null) log.error("mergeDataWithCentral - No Data - " + data); else if (!data.Test.booleanValue()) { RowSet targetRS = ReplicationLocal.getRowSet(data.Sql, null); Object result = doIt (ReplicationLocal.START, "sync", new Object[] // Merge {data.TableName, data.KeyColumns, sourceRS, targetRS, data.Test, Boolean.TRUE}); log.debug("receiveUpdateFromCentral - " + data.TableName + " - " + result); pi.setSerializableObject(null); boolean replicated = ReplicationLocal.isReplicated(result); if (!replicated) pi.setError(true); if (result != null) pi.addLog(0,null,null, result.toString()); if (Boolean.FALSE.equals(result)) throw new Exception ("receiveUpdateFromCentral - " + data.TableName + " - " + result); } // Local Remote Data RowSet rowset = ReplicationLocal.getRowSet(data.Sql, null); // Result pi.setSerializableObject((Serializable)rowset); log.info("mergeDataWithCentral End (" + pi + ") " + data); return "Remote MergeDataWithCentral - " + data.TableName; } // sendNewDataToCentral /*************************************************************************/ /** * Receive Update from Central * @return info * @throws Exception */ private String receiveUpdateFromCentral() throws Exception { ProcessInfo pi = getProcessInfo(); RemoteUpdateVO data = (RemoteUpdateVO)pi.getSerializableObject(); log.info("receiveUpdateFromCentral Start (" + pi + ") - " + data); // RowSet sourceRS = data.CentralData; if (sourceRS == null) { log.error("receiveUpdateFromCentral - No Data - " + data); pi.setSummary("NoData", true); } else if (!data.Test.booleanValue()) { RowSet targetRS = ReplicationLocal.getRowSet(data.Sql, null); Object result = doIt (ReplicationLocal.START, "sync", new Object[] // Sync {data.TableName, data.KeyColumns, sourceRS, targetRS, data.Test, Boolean.FALSE}); log.debug("receiveUpdateFromCentral - " + data.TableName + " - " + result); pi.setSerializableObject(null); boolean replicated = ReplicationLocal.isReplicated(result); if (!replicated) pi.setError(true); if (result != null) pi.addLog(0,null,null, result.toString()); if (Boolean.FALSE.equals(result)) throw new Exception ("receiveUpdateFromCentral - " + data.TableName + " - " + result); } // pi.setSerializableObject(null); log.info("receiveUpdateFromCentral End (" + pi + ") - " + data); return "Remote Receive Update from Central OK"; } // receiveUpdateFromCentral /*************************************************************************/ /** * Clean up resources (connections) * @return exit * @throws Exception */ private String exit() throws Exception { log.info ("exit"); ProcessInfo pi = getProcessInfo(); Object result = doIt(ReplicationLocal.START, "exit", null); return "exit"; } // exit } // ReplicationRemote --- NEW FILE: ProjectSetType.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 and ComPiere, Inc. * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.process; import java.math.*; import org.compiere.model.*; /** * Set Project Type * * @author Jorg Janke * @version $Id: ProjectSetType.java,v 1.3.2.1 2003/09/24 17:45:36 jpedersen Exp $ */ public class ProjectSetType extends SvrProcess { /** Project directly from Project */ private int m_C_Project_ID = 0; /** Project Type Parameter */ private int m_C_ProjectType_ID = 0; /** * 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("C_ProjectType_ID")) m_C_ProjectType_ID = ((BigDecimal)para[i].getParameter()).intValue(); else log.error("prepare - Unknown Parameter: " + name); } } // prepare /** * Perrform process. * @return Message (clear text) * @throws Exception if not successful */ protected String doIt() throws Exception { m_C_Project_ID = getRecord_ID(); log.info("doIt - C_Project_ID=" + m_C_Project_ID + ", C_ProjectType_ID=" + m_C_ProjectType_ID); // MProject project = new MProject (getCtx(), m_C_Project_ID); if (project.getC_Project_ID() == 0 || project.getC_Project_ID() != m_C_Project_ID) throw new IllegalArgumentException("Project not found C_Project_ID=" + m_C_Project_ID); if (project.getC_ProjectType_IDasInt() > 0) throw new IllegalArgumentException("Project already has Type (Cannot overwrite) " + project.getC_ProjectType_ID()); // MProjectType type = new MProjectType (getCtx(), m_C_ProjectType_ID); if (type.getC_ProjectType_ID() == 0 || type.getC_ProjectType_ID() != m_C_ProjectType_ID) throw new IllegalArgumentException("Project Type not found C_ProjectType_ID=" + m_C_ProjectType_ID); // Set & Copy if Service project.setProjectType(type); if (!project.save()) throw new Exception ("@Error@"); return "OK"; } // doIt } // ProjectSetType --- NEW FILE: CopyFromJournal.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 and ComPiere, Inc. * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.process; import java.math.*; import org.compiere.model.*; /** * Copy GL Batch Journal/Lines * * @author Jorg Janke * @version $Id: CopyFromJournal.java,v 1.2.2.1 2003/09/24 17:45:36 jpedersen Exp $ */ public class CopyFromJournal extends SvrProcess { private int m_GL_JournalBatch_ID = 0; /** * 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("GL_JournalBatch_ID")) m_GL_JournalBatch_ID = ((BigDecimal)para[i].getParameter()).intValue(); else log.error("prepare - Unknown Parameter: " + name); } } // prepare /** * Perrform process. * @return Message (clear text) * @throws Exception if not successful */ protected String doIt() throws Exception { int To_GL_JournalBatch_ID = getRecord_ID(); log.info("doIt - From GL_JournalBatch_ID=" + m_GL_JournalBatch_ID + " to " + To_GL_JournalBatch_ID); if (To_GL_JournalBatch_ID == 0) throw new IllegalArgumentException("Target GL_JournalBatch_ID == 0"); if (m_GL_JournalBatch_ID == 0) throw new IllegalArgumentException("Source GL_JournalBatch_ID == 0"); MJournalBatch from = new MJournalBatch (getCtx(), m_GL_JournalBatch_ID); MJournalBatch to = new MJournalBatch (getCtx(), To_GL_JournalBatch_ID); // int no = to.copyDetailsFrom (from); // return "@Copied@=" + no; } // doIt } --- NEW FILE: ImportInventory.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 Business Solution * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc. * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.process; import java.sql.*; import java.math.*; import org.compiere.model.*; import org.compiere.util.*; /** * Import Physical Inventory fom I_Inventory * * @author Jorg Janke * @version $Id: ImportInventory.java,v 1.2.2.1 2003/09/24 17:45:36 jpedersen Exp $ */ public class ImportInventory 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; /** Location to be imported to */ private int m_M_Locator_ID = 0; /** Default Date */ private Timestamp m_MovementDate = null; /** Delete old Imported */ private boolean m_deleteOldImported = false; /** * 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("M_Locator_ID")) m_M_Locator_ID = ((BigDecimal)para[i].getParameter()).intValue(); else if (name.equals("MovementDate")) m_MovementDate = (Timestamp)para[i].getParameter(); else if (name.equals("DeleteOldImported")) m_deleteOldImported = "Y".equals(para[i].getParameter()); else log.error("prepare - Unknown Parameter: " + name); } } // 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_Inventory " + "WHERE I_IsImported='Y'").append (clientCheck); no = DB.executeUpdate (sql.toString ()); log.debug ("doIt - Delete Old Impored =" + no); } // Set Client, Org, Location, IsActive, Created/Updated sql = new StringBuffer ("UPDATE I_Inventory " + "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 ("),"); if (m_M_Locator_ID != 0) sql.append(" M_Locator_ID = COALESCE (M_Locator_ID,").append (m_M_Locator_ID).append ("),"); if (m_MovementDate != null) sql.append(" MovementDate = COALESCE (MovementDate,").append (DB.TO_DATE(m_MovementDate)).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," + " M_Warehouse_ID = NULL," // reset + " I_IsImported = 'N' " + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); no = DB.executeUpdate (sql.toString ()); log.info ("doIt - Reset=" + no); sql = new StringBuffer ("UPDATE I_Inventory 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 ()); if (no != 0) log.warn ("doIt - Invalid Org=" + no); // Location sql = new StringBuffer ("UPDATE I_Inventory i " + "SET M_Locator_ID=(SELECT M_Locator_ID FROM M_Locator l" + " WHERE i.LocatorValue=l.Value AND i.AD_Client_ID=l.AD_Client_ID AND ROWNUM=1) " + "WHERE M_Locator_ID IS NULL AND LocatorValue IS NOT NULL" + " AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString ()); log.debug("doIt - Set Locator from Value =" + no); sql = new StringBuffer ("UPDATE I_Inventory i " + "SET M_Locator_ID=(SELECT M_Locator_ID FROM M_Locator l" + " WHERE i.X=l.X AND i.Y=l.Y AND i.Z=l.Z AND i.AD_Client_ID=l.AD_Client_ID AND ROWNUM=1) " + "WHERE M_Locator_ID IS NULL AND X IS NOT NULL AND Y IS NOT NULL AND Z IS NOT NULL" + " AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString ()); log.debug("doIt - Set Locator from X,Y,Z =" + no); sql = new StringBuffer ("UPDATE I_Inventory " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Location, ' " + "WHERE M_Locator_ID IS NULL" + " AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString ()); if (no != 0) log.warn ("doIt - No Location=" + no); // Set M_Warehouse_ID sql = new StringBuffer ("UPDATE I_Inventory i " + "SET M_Warehouse_ID=(SELECT M_Warehouse_ID FROM M_Locator l WHERE i.M_Locator_ID=l.M_Locator_ID) " + "WHERE M_Locator_ID IS NOT NULL" + " AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString ()); log.debug("doIt - Set Warehouse from Locator =" + no); sql = new StringBuffer ("UPDATE I_Inventory " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Warehouse, ' " + "WHERE M_Warehouse_ID IS NULL" + " AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString ()); if (no != 0) log.warn ("doIt - No Warehouse=" + no); // Product sql = new StringBuffer ("UPDATE I_Inventory i " + "SET M_Product_ID=(SELECT M_Product_ID FROM M_Product p" + " WHERE i.Value=p.Value AND i.AD_Client_ID=p.AD_Client_ID AND ROWNUM=1) " + "WHERE M_Product_ID IS NULL AND Value IS NOT NULL" + " AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString ()); log.debug("doIt - Set Product from Value=" + no); sql = new StringBuffer ("UPDATE I_Inventory i " + "SET M_Product_ID=(SELECT M_Product_ID FROM M_Product p" + " WHERE i.UPC=p.UPC AND i.AD_Client_ID=p.AD_Client_ID AND ROWNUM=1) " + "WHERE M_Product_ID IS NULL AND UPC IS NOT NULL" + " AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString ()); log.debug("doIt - Set Product from UPC=" + no); sql = new StringBuffer ("UPDATE I_Inventory " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Product, ' " + "WHERE M_Product_ID IS NULL" + " AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString ()); if (no != 0) log.warn ("doIt - No Product=" + no); // No QtyCount sql = new StringBuffer ("UPDATE I_Inventory " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Qty Count, ' " + "WHERE QtyCount IS NULL" + " AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString ()); if (no != 0) log.warn ("doIt - No QtyCount=" + no); /*********************************************************************/ MInventory inventory = null; int noInsert = 0; int noInsertLine = 0; // Go through Inventory Records sql = new StringBuffer ("SELECT * FROM I_Inventory " + "WHERE I_IsImported='N'").append (clientCheck) .append(" ORDER BY M_Warehouse_ID, TRUNC(MovementDate), I_Inventory_ID"); try { PreparedStatement pstmt = DB.prepareStatement (sql.toString ()); ResultSet rs = pstmt.executeQuery (); // int x_M_Warehouse_ID = -1; Timestamp x_MovementDate = null; while (rs.next()) { X_I_Inventory imp = new X_I_Inventory (getCtx (), rs); Timestamp MovementDate = TimeUtil.getDay(imp.getMovementDate()); if (inventory == null || imp.getM_Warehouse_ID() != x_M_Warehouse_ID || !MovementDate.equals(x_MovementDate)) { inventory = new MInventory (getCtx(), 0); inventory.setClientOrg(imp.getAD_Client_ID(), imp.getAD_Org_ID()); inventory.setName("I " + imp.getM_Warehouse... [truncated message content] |