Adempiere 3.1.2

This commit is contained in:
vpj-cd 2006-12-07 04:43:01 +00:00
parent 7dd562c52d
commit 297d3015fb
4 changed files with 2289 additions and 2340 deletions

View File

@ -3,485 +3,485 @@
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.acct; package org.compiere.acct;
import java.sql.*; import java.sql.*;
import java.util.*; import java.util.*;
import java.util.logging.*; import java.util.logging.*;
import javax.swing.*; import javax.swing.*;
import org.compiere.model.*; import org.compiere.model.*;
import org.compiere.report.core.*; import org.compiere.report.core.*;
import org.compiere.util.*; import org.compiere.util.*;
/** /**
* Account Viewer State - maintaines State information for the Account Viewer * Account Viewer State - maintaines State information for the Account Viewer
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: AcctViewerData.java,v 1.3 2006/08/10 01:00:27 jjanke Exp $ * @version $Id: AcctViewerData.java,v 1.3 2006/08/10 01:00:27 jjanke Exp $
*/ */
class AcctViewerData class AcctViewerData
{ {
/** /**
* Constructor * Constructor
* @param ctx context * @param ctx context
* @param windowNo window no * @param windowNo window no
* @param ad_Client_ID client * @param ad_Client_ID client
* @param ad_Table_ID table * @param ad_Table_ID table
*/ */
public AcctViewerData (Properties ctx, int windowNo, int ad_Client_ID, int ad_Table_ID) public AcctViewerData (Properties ctx, int windowNo, int ad_Client_ID, int ad_Table_ID)
{ {
WindowNo = windowNo; WindowNo = windowNo;
AD_Client_ID = ad_Client_ID; AD_Client_ID = ad_Client_ID;
if (AD_Client_ID == 0) if (AD_Client_ID == 0)
AD_Client_ID = Env.getContextAsInt(Env.getCtx(), WindowNo, "AD_Client_ID"); AD_Client_ID = Env.getContextAsInt(Env.getCtx(), WindowNo, "AD_Client_ID");
if (AD_Client_ID == 0) if (AD_Client_ID == 0)
AD_Client_ID = Env.getContextAsInt(Env.getCtx(), "AD_Client_ID"); AD_Client_ID = Env.getContextAsInt(Env.getCtx(), "AD_Client_ID");
AD_Table_ID = ad_Table_ID; AD_Table_ID = ad_Table_ID;
// //
ASchemas = MAcctSchema.getClientAcctSchema(ctx, AD_Client_ID); ASchemas = MAcctSchema.getClientAcctSchema(ctx, AD_Client_ID);
ASchema = ASchemas[0]; ASchema = ASchemas[0];
} // AcctViewerData } // AcctViewerData
/** Window */ /** Window */
public int WindowNo; public int WindowNo;
/** Client */ /** Client */
public int AD_Client_ID; public int AD_Client_ID;
/** All Acct Schema */ /** All Acct Schema */
public MAcctSchema[] ASchemas = null; public MAcctSchema[] ASchemas = null;
/** This Acct Schema */ /** This Acct Schema */
public MAcctSchema ASchema = null; public MAcctSchema ASchema = null;
// Selection Info // Selection Info
/** Document Query */ /** Document Query */
public boolean documentQuery = false; public boolean documentQuery = false;
/** Acct Schema */ /** Acct Schema */
public int C_AcctSchema_ID = 0; public int C_AcctSchema_ID = 0;
/** Posting Type */ /** Posting Type */
public String PostingType = ""; public String PostingType = "";
/** Organization */ /** Organization */
public int AD_Org_ID = 0; public int AD_Org_ID = 0;
/** Date From */ /** Date From */
public Timestamp DateFrom = null; public Timestamp DateFrom = null;
/** Date To */ /** Date To */
public Timestamp DateTo = null; public Timestamp DateTo = null;
// Dodument Table Selection Info // Dodument Table Selection Info
/** Table ID */ /** Table ID */
public int AD_Table_ID; public int AD_Table_ID;
/** Record */ /** Record */
public int Record_ID; public int Record_ID;
/** Containing Column and Query */ /** Containing Column and Query */
public HashMap<String,String> whereInfo = new HashMap<String,String>(); public HashMap<String,String> whereInfo = new HashMap<String,String>();
/** Containing TableName and AD_Table_ID */ /** Containing TableName and AD_Table_ID */
public HashMap<String,Integer> tableInfo = new HashMap<String,Integer>(); public HashMap<String,Integer> tableInfo = new HashMap<String,Integer>();
// Display Info // Display Info
/** Display Qty */ /** Display Qty */
boolean displayQty = false; boolean displayQty = false;
/** Display Source Surrency */ /** Display Source Surrency */
boolean displaySourceAmt = false; boolean displaySourceAmt = false;
/** Display Document info */ /** Display Document info */
boolean displayDocumentInfo = false; boolean displayDocumentInfo = false;
// //
String sortBy1 = ""; String sortBy1 = "";
String sortBy2 = ""; String sortBy2 = "";
String sortBy3 = ""; String sortBy3 = "";
String sortBy4 = ""; String sortBy4 = "";
// //
boolean group1 = false; boolean group1 = false;
boolean group2 = false; boolean group2 = false;
boolean group3 = false; boolean group3 = false;
boolean group4 = false; boolean group4 = false;
/** Leasing Columns */ /** Leasing Columns */
private int m_leadingColumns = 0; private int m_leadingColumns = 0;
/** UserElement1 Reference */ /** UserElement1 Reference */
private String m_ref1 = null; private String m_ref1 = null;
/** UserElement2 Reference */ /** UserElement2 Reference */
private String m_ref2 = null; private String m_ref2 = null;
/** Logger */ /** Logger */
private static CLogger log = CLogger.getCLogger(AcctViewerData.class); private static CLogger log = CLogger.getCLogger(AcctViewerData.class);
/** /**
* Dispose * Dispose
*/ */
public void dispose() public void dispose()
{ {
ASchemas = null; ASchemas = null;
ASchema = null; ASchema = null;
// //
whereInfo.clear(); whereInfo.clear();
whereInfo = null; whereInfo = null;
// //
Env.clearWinContext(WindowNo); Env.clearWinContext(WindowNo);
} // dispose } // dispose
/************************************************************************** /**************************************************************************
* Fill Accounting Schema * Fill Accounting Schema
* @param cb JComboBox to be filled * @param cb JComboBox to be filled
*/ */
protected void fillAcctSchema (JComboBox cb) protected void fillAcctSchema (JComboBox cb)
{ {
for (int i = 0; i < ASchemas.length; i++) for (int i = 0; i < ASchemas.length; i++)
cb.addItem(new KeyNamePair(ASchemas[i].getC_AcctSchema_ID(), cb.addItem(new KeyNamePair(ASchemas[i].getC_AcctSchema_ID(),
ASchemas[i].getName())); ASchemas[i].getName()));
} // fillAcctSchema } // fillAcctSchema
/** /**
* Fill Posting Type * Fill Posting Type
* @param cb JComboBox to be filled * @param cb JComboBox to be filled
*/ */
protected void fillPostingType (JComboBox cb) protected void fillPostingType (JComboBox cb)
{ {
int AD_Reference_ID = 125; int AD_Reference_ID = 125;
ValueNamePair[] pt = MRefList.getList(AD_Reference_ID, true); ValueNamePair[] pt = MRefList.getList(AD_Reference_ID, true);
for (int i = 0; i < pt.length; i++) for (int i = 0; i < pt.length; i++)
cb.addItem(pt[i]); cb.addItem(pt[i]);
} // fillPostingType } // fillPostingType
/** /**
* Fill Table with * Fill Table with
* ValueNamePair (TableName, translatedKeyColumnName) * ValueNamePair (TableName, translatedKeyColumnName)
* and tableInfo with (TableName, AD_Table_ID) * and tableInfo with (TableName, AD_Table_ID)
* and select the entry for AD_Table_ID * and select the entry for AD_Table_ID
* *
* @param cb JComboBox to be filled * @param cb JComboBox to be filled
*/ */
protected void fillTable (JComboBox cb) protected void fillTable (JComboBox cb)
{ {
ValueNamePair select = null; ValueNamePair select = null;
// //
String sql = "SELECT AD_Table_ID, TableName FROM AD_Table t " String sql = "SELECT AD_Table_ID, TableName FROM AD_Table t "
+ "WHERE EXISTS (SELECT * FROM AD_Column c" + "WHERE EXISTS (SELECT * FROM AD_Column c"
+ " WHERE t.AD_Table_ID=c.AD_Table_ID AND c.ColumnName='Posted')" + " WHERE t.AD_Table_ID=c.AD_Table_ID AND c.ColumnName='Posted')"
+ " AND IsView='N'"; + " AND IsView='N'";
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql, null); PreparedStatement pstmt = DB.prepareStatement(sql, null);
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
int id = rs.getInt(1); int id = rs.getInt(1);
String tableName = rs.getString(2); String tableName = rs.getString(2);
String name = Msg.translate(Env.getCtx(), tableName+"_ID"); String name = Msg.translate(Env.getCtx(), tableName+"_ID");
// //
ValueNamePair pp = new ValueNamePair(tableName, name); ValueNamePair pp = new ValueNamePair(tableName, name);
cb.addItem(pp); cb.addItem(pp);
tableInfo.put (tableName, new Integer(id)); tableInfo.put (tableName, new Integer(id));
if (id == AD_Table_ID) if (id == AD_Table_ID)
select = pp; select = pp;
} }
rs.close(); rs.close();
pstmt.close(); pstmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
if (select != null) if (select != null)
cb.setSelectedItem(select); cb.setSelectedItem(select);
} // fillTable } // fillTable
/** /**
* Fill Org * Fill Org
* *
* @param cb JComboBox to be filled * @param cb JComboBox to be filled
*/ */
protected void fillOrg (JComboBox cb) protected void fillOrg (JComboBox cb)
{ {
KeyNamePair pp = new KeyNamePair(0, ""); KeyNamePair pp = new KeyNamePair(0, "");
cb.addItem(pp); cb.addItem(pp);
String sql = "SELECT AD_Org_ID, Name FROM AD_Org WHERE AD_Client_ID=? ORDER BY Value"; String sql = "SELECT AD_Org_ID, Name FROM AD_Org WHERE AD_Client_ID=? ORDER BY Value";
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql, null); PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Client_ID); pstmt.setInt(1, AD_Client_ID);
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
cb.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2))); cb.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2)));
rs.close(); rs.close();
pstmt.close(); pstmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
} // fillOrg } // fillOrg
/** /**
* Get Button Text * Get Button Text
* *
* @param tableName table * @param tableName table
* @param columnName column * @param columnName column
* @param selectSQL sql * @param selectSQL sql
* @return Text on button * @return Text on button
*/ */
protected String getButtonText (String tableName, String columnName, String selectSQL) protected String getButtonText (String tableName, String columnName, String selectSQL)
{ {
// SELECT (<embedded>) FROM tableName avd WHERE avd.<selectSQL> // SELECT (<embedded>) FROM tableName avd WHERE avd.<selectSQL>
StringBuffer sql = new StringBuffer ("SELECT ("); StringBuffer sql = new StringBuffer ("SELECT (");
Language language = Env.getLanguage(Env.getCtx()); Language language = Env.getLanguage(Env.getCtx());
sql.append(MLookupFactory.getLookup_TableDirEmbed(language, columnName, "avd")) sql.append(MLookupFactory.getLookup_TableDirEmbed(language, columnName, "avd"))
.append(") FROM ").append(tableName).append(" avd WHERE avd.").append(selectSQL); .append(") FROM ").append(tableName).append(" avd WHERE avd.").append(selectSQL);
String retValue = "<" + selectSQL + ">"; String retValue = "<" + selectSQL + ">";
try try
{ {
Statement stmt = DB.createStatement(); Statement stmt = DB.createStatement();
ResultSet rs = stmt.executeQuery(sql.toString()); ResultSet rs = stmt.executeQuery(sql.toString());
if (rs.next()) if (rs.next())
retValue = rs.getString(1); retValue = rs.getString(1);
rs.close(); rs.close();
stmt.close(); stmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql.toString(), e); log.log(Level.SEVERE, sql.toString(), e);
} }
return retValue; return retValue;
} // getButtonText } // getButtonText
/************************************************************************** /**************************************************************************
/** /**
* Create Query and submit * Create Query and submit
* @return Report Model * @return Report Model
*/ */
protected RModel query() protected RModel query()
{ {
// Set Where Clause // Set Where Clause
StringBuffer whereClause = new StringBuffer(); StringBuffer whereClause = new StringBuffer();
// Add Organization // Add Organization
if (C_AcctSchema_ID != 0) if (C_AcctSchema_ID != 0)
whereClause.append(RModel.TABLE_ALIAS) whereClause.append(RModel.TABLE_ALIAS)
.append(".C_AcctSchema_ID=").append(C_AcctSchema_ID); .append(".C_AcctSchema_ID=").append(C_AcctSchema_ID);
// Posting Type Selected // Posting Type Selected
if (PostingType != null && PostingType.length() > 0) if (PostingType != null && PostingType.length() > 0)
{ {
if (whereClause.length() > 0) if (whereClause.length() > 0)
whereClause.append(" AND "); whereClause.append(" AND ");
whereClause.append(RModel.TABLE_ALIAS) whereClause.append(RModel.TABLE_ALIAS)
.append(".PostingType='").append(PostingType).append("'"); .append(".PostingType='").append(PostingType).append("'");
} }
// //
if (documentQuery) if (documentQuery)
{ {
if (whereClause.length() > 0) if (whereClause.length() > 0)
whereClause.append(" AND "); whereClause.append(" AND ");
whereClause.append(RModel.TABLE_ALIAS).append(".AD_Table_ID=").append(AD_Table_ID) whereClause.append(RModel.TABLE_ALIAS).append(".AD_Table_ID=").append(AD_Table_ID)
.append(" AND ").append(RModel.TABLE_ALIAS).append(".Record_ID=").append(Record_ID); .append(" AND ").append(RModel.TABLE_ALIAS).append(".Record_ID=").append(Record_ID);
} }
else else
{ {
// get values (Queries) // get values (Queries)
Iterator it = whereInfo.values().iterator(); Iterator it = whereInfo.values().iterator();
while (it.hasNext()) while (it.hasNext())
{ {
String where = (String)it.next(); String where = (String)it.next();
if (where != null && where.length() > 0) // add only if not empty if (where != null && where.length() > 0) // add only if not empty
{ {
if (whereClause.length() > 0) if (whereClause.length() > 0)
whereClause.append(" AND "); whereClause.append(" AND ");
whereClause.append(RModel.TABLE_ALIAS).append(".").append(where); whereClause.append(RModel.TABLE_ALIAS).append(".").append(where);
} }
} }
if (DateFrom != null || DateTo != null) if (DateFrom != null || DateTo != null)
{ {
if (whereClause.length() > 0) if (whereClause.length() > 0)
whereClause.append(" AND "); whereClause.append(" AND ");
if (DateFrom != null && DateTo != null) if (DateFrom != null && DateTo != null)
whereClause.append("TRUNC(").append(RModel.TABLE_ALIAS).append(".DateAcct) BETWEEN ") whereClause.append("TRUNC(").append(RModel.TABLE_ALIAS).append(".DateAcct) BETWEEN ")
.append(DB.TO_DATE(DateFrom)).append(" AND ").append(DB.TO_DATE(DateTo)); .append(DB.TO_DATE(DateFrom)).append(" AND ").append(DB.TO_DATE(DateTo));
else if (DateFrom != null) else if (DateFrom != null)
whereClause.append("TRUNC(").append(RModel.TABLE_ALIAS).append(".DateAcct) >= ") whereClause.append("TRUNC(").append(RModel.TABLE_ALIAS).append(".DateAcct) >= ")
.append(DB.TO_DATE(DateFrom)); .append(DB.TO_DATE(DateFrom));
else // DateTo != null else // DateTo != null
whereClause.append("TRUNC(").append(RModel.TABLE_ALIAS).append(".DateAcct) <= ") whereClause.append("TRUNC(").append(RModel.TABLE_ALIAS).append(".DateAcct) <= ")
.append(DB.TO_DATE(DateTo)); .append(DB.TO_DATE(DateTo));
} }
// Add Organization // Add Organization
if (AD_Org_ID != 0) if (AD_Org_ID != 0)
{ {
if (whereClause.length() > 0) if (whereClause.length() > 0)
whereClause.append(" AND "); whereClause.append(" AND ");
whereClause.append(RModel.TABLE_ALIAS).append(".AD_Org_ID=").append(AD_Org_ID); whereClause.append(RModel.TABLE_ALIAS).append(".AD_Org_ID=").append(AD_Org_ID);
} }
} }
// Set Order By Clause // Set Order By Clause
StringBuffer orderClause = new StringBuffer(); StringBuffer orderClause = new StringBuffer();
if (sortBy1.length() > 0) if (sortBy1.length() > 0)
orderClause.append(RModel.TABLE_ALIAS).append(".").append(sortBy1); orderClause.append(RModel.TABLE_ALIAS).append(".").append(sortBy1);
if (sortBy2.length() > 0) if (sortBy2.length() > 0)
{ {
if (orderClause.length() > 0) if (orderClause.length() > 0)
orderClause.append(","); orderClause.append(",");
orderClause.append(RModel.TABLE_ALIAS).append(".").append(sortBy2); orderClause.append(RModel.TABLE_ALIAS).append(".").append(sortBy2);
} }
if (sortBy3.length() > 0) if (sortBy3.length() > 0)
{ {
if (orderClause.length() > 0) if (orderClause.length() > 0)
orderClause.append(","); orderClause.append(",");
orderClause.append(RModel.TABLE_ALIAS).append(".").append(sortBy3); orderClause.append(RModel.TABLE_ALIAS).append(".").append(sortBy3);
} }
if (sortBy4.length() > 0) if (sortBy4.length() > 0)
{ {
if (orderClause.length() > 0) if (orderClause.length() > 0)
orderClause.append(","); orderClause.append(",");
orderClause.append(RModel.TABLE_ALIAS).append(".").append(sortBy4); orderClause.append(RModel.TABLE_ALIAS).append(".").append(sortBy4);
} }
if (orderClause.length() == 0) if (orderClause.length() == 0)
orderClause.append(RModel.TABLE_ALIAS).append(".Fact_Acct_ID"); orderClause.append(RModel.TABLE_ALIAS).append(".Fact_Acct_ID");
RModel rm = getRModel(); RModel rm = getRModel();
// Groups // Groups
if (group1 && sortBy1.length() > 0) if (group1 && sortBy1.length() > 0)
rm.setGroup(sortBy1); rm.setGroup(sortBy1);
if (group2 && sortBy2.length() > 0) if (group2 && sortBy2.length() > 0)
rm.setGroup(sortBy2); rm.setGroup(sortBy2);
if (group3 && sortBy3.length() > 0) if (group3 && sortBy3.length() > 0)
rm.setGroup(sortBy3); rm.setGroup(sortBy3);
if (group4 && sortBy4.length() > 0) if (group4 && sortBy4.length() > 0)
rm.setGroup(sortBy4); rm.setGroup(sortBy4);
// Totals // Totals
rm.setFunction("AmtAcctDr", RModel.FUNCTION_SUM); rm.setFunction("AmtAcctDr", RModel.FUNCTION_SUM);
rm.setFunction("AmtAcctCr", RModel.FUNCTION_SUM); rm.setFunction("AmtAcctCr", RModel.FUNCTION_SUM);
rm.query (Env.getCtx(), whereClause.toString(), orderClause.toString()); rm.query (Env.getCtx(), whereClause.toString(), orderClause.toString());
return rm; return rm;
} // query } // query
/** /**
* Create Report Model (Columns) * Create Report Model (Columns)
* @return Report Model * @return Report Model
*/ */
private RModel getRModel() private RModel getRModel()
{ {
Properties ctx = Env.getCtx(); Properties ctx = Env.getCtx();
RModel rm = new RModel("Fact_Acct"); RModel rm = new RModel("Fact_Acct");
// Add Key (Lookups) // Add Key (Lookups)
ArrayList keys = createKeyColumns(); ArrayList keys = createKeyColumns();
int max = m_leadingColumns; int max = m_leadingColumns;
if (max == 0) if (max == 0)
max = keys.size(); max = keys.size();
for (int i = 0; i < max; i++) for (int i = 0; i < max; i++)
{ {
String column = (String)keys.get(i); String column = (String)keys.get(i);
if (column != null && column.startsWith("Date")) if (column != null && column.startsWith("Date"))
rm.addColumn(new RColumn(ctx, column, DisplayType.Date)); rm.addColumn(new RColumn(ctx, column, DisplayType.Date));
else if (column != null && column.endsWith("_ID")) else if (column != null && column.endsWith("_ID"))
rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir)); rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir));
} }
// Main Info // Main Info
rm.addColumn(new RColumn(ctx, "AmtAcctDr", DisplayType.Amount)); rm.addColumn(new RColumn(ctx, "AmtAcctDr", DisplayType.Amount));
rm.addColumn(new RColumn(ctx, "AmtAcctCr", DisplayType.Amount)); rm.addColumn(new RColumn(ctx, "AmtAcctCr", DisplayType.Amount));
if (displaySourceAmt) if (displaySourceAmt)
{ {
if (!keys.contains("DateTrx")) if (!keys.contains("DateTrx"))
rm.addColumn(new RColumn(ctx, "DateTrx", DisplayType.Date)); rm.addColumn(new RColumn(ctx, "DateTrx", DisplayType.Date));
rm.addColumn(new RColumn(ctx, "C_Currency_ID", DisplayType.TableDir)); rm.addColumn(new RColumn(ctx, "C_Currency_ID", DisplayType.TableDir));
rm.addColumn(new RColumn(ctx, "AmtSourceDr", DisplayType.Amount)); rm.addColumn(new RColumn(ctx, "AmtSourceDr", DisplayType.Amount));
rm.addColumn(new RColumn(ctx, "AmtSourceCr", DisplayType.Amount)); rm.addColumn(new RColumn(ctx, "AmtSourceCr", DisplayType.Amount));
rm.addColumn(new RColumn(ctx, "Rate", DisplayType.Amount, rm.addColumn(new RColumn(ctx, "Rate", DisplayType.Amount,
"CASE WHEN (AmtSourceDr + AmtSourceCr) = 0 THEN 0" "CASE WHEN (AmtSourceDr + AmtSourceCr) = 0 THEN 0"
+ " ELSE (AmtAcctDr + AmtAcctCr) / (AmtSourceDr + AmtSourceCr) END")); + " ELSE (AmtAcctDr + AmtAcctCr) / (AmtSourceDr + AmtSourceCr) END"));
} }
// Remaining Keys // Remaining Keys
for (int i = max; i < keys.size(); i++) for (int i = max; i < keys.size(); i++)
{ {
String column = (String)keys.get(i); String column = (String)keys.get(i);
if (column != null && column.startsWith("Date")) if (column != null && column.startsWith("Date"))
rm.addColumn(new RColumn(ctx, column, DisplayType.Date)); rm.addColumn(new RColumn(ctx, column, DisplayType.Date));
else if (column.startsWith("UserElement")) else if (column.startsWith("UserElement"))
{ {
if (column.indexOf("1") != -1) if (column.indexOf("1") != -1)
rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir, null, 0, m_ref1)); rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir, null, 0, m_ref1));
else else
rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir, null, 0, m_ref2)); rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir, null, 0, m_ref2));
} }
else if (column != null && column.endsWith("_ID")) else if (column != null && column.endsWith("_ID"))
rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir)); rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir));
} }
// Info // Info
if (!keys.contains("DateAcct")) if (!keys.contains("DateAcct"))
rm.addColumn(new RColumn(ctx, "DateAcct", DisplayType.Date)); rm.addColumn(new RColumn(ctx, "DateAcct", DisplayType.Date));
if (!keys.contains("C_Period_ID")) if (!keys.contains("C_Period_ID"))
rm.addColumn(new RColumn(ctx, "C_Period_ID", DisplayType.TableDir)); rm.addColumn(new RColumn(ctx, "C_Period_ID", DisplayType.TableDir));
if (displayQty) if (displayQty)
{ {
rm.addColumn(new RColumn(ctx, "C_UOM_ID", DisplayType.TableDir)); rm.addColumn(new RColumn(ctx, "C_UOM_ID", DisplayType.TableDir));
rm.addColumn(new RColumn(ctx, "Qty", DisplayType.Quantity)); rm.addColumn(new RColumn(ctx, "Qty", DisplayType.Quantity));
} }
if (displayDocumentInfo) if (displayDocumentInfo)
{ {
rm.addColumn(new RColumn(ctx, "AD_Table_ID", DisplayType.TableDir)); rm.addColumn(new RColumn(ctx, "AD_Table_ID", DisplayType.TableDir));
rm.addColumn(new RColumn(ctx, "Record_ID", DisplayType.ID)); rm.addColumn(new RColumn(ctx, "Record_ID", DisplayType.ID));
rm.addColumn(new RColumn(ctx, "Description", DisplayType.String)); rm.addColumn(new RColumn(ctx, "Description", DisplayType.String));
} }
if (PostingType == null || PostingType.length() == 0) if (PostingType == null || PostingType.length() == 0)
rm.addColumn(new RColumn(ctx, RModel.TABLE_ALIAS+".PostingType", DisplayType.List, rm.addColumn(new RColumn(ctx, "PostingType", DisplayType.List,
MFactAcct.POSTINGTYPE_AD_Reference_ID)); MFactAcct.POSTINGTYPE_AD_Reference_ID));
return rm; return rm;
} // createRModel } // createRModel
/** /**
* Create the key columns in sequence * Create the key columns in sequence
* @return List of Key Columns * @return List of Key Columns
*/ */
private ArrayList createKeyColumns() private ArrayList createKeyColumns()
{ {
ArrayList<String> columns = new ArrayList<String>(); ArrayList<String> columns = new ArrayList<String>();
m_leadingColumns = 0; m_leadingColumns = 0;
// Sorting Fields // Sorting Fields
columns.add(sortBy1); // may add "" columns.add(sortBy1); // may add ""
if (!columns.contains(sortBy2)) if (!columns.contains(sortBy2))
columns.add(sortBy2); columns.add(sortBy2);
if (!columns.contains(sortBy3)) if (!columns.contains(sortBy3))
columns.add(sortBy3); columns.add(sortBy3);
if (!columns.contains(sortBy4)) if (!columns.contains(sortBy4))
columns.add(sortBy4); columns.add(sortBy4);
// Add Account Segments // Add Account Segments
MAcctSchemaElement[] elements = ASchema.getAcctSchemaElements(); MAcctSchemaElement[] elements = ASchema.getAcctSchemaElements();
for (int i = 0; i < elements.length; i++) for (int i = 0; i < elements.length; i++)
{ {
if (m_leadingColumns == 0 && columns.contains("AD_Org_ID") && columns.contains("Account_ID")) if (m_leadingColumns == 0 && columns.contains("AD_Org_ID") && columns.contains("Account_ID"))
m_leadingColumns = columns.size(); m_leadingColumns = columns.size();
// //
MAcctSchemaElement ase = elements[i]; MAcctSchemaElement ase = elements[i];
String columnName = ase.getColumnName(); String columnName = ase.getColumnName();
if (columnName.startsWith("UserElement")) if (columnName.startsWith("UserElement"))
{ {
if (columnName.indexOf("1") != -1) if (columnName.indexOf("1") != -1)
m_ref1 = ase.getDisplayColumnName(); m_ref1 = ase.getDisplayColumnName();
else else
m_ref2 = ase.getDisplayColumnName(); m_ref2 = ase.getDisplayColumnName();
} }
if (!columns.contains(columnName)) if (!columns.contains(columnName))
columns.add(columnName); columns.add(columnName);
} }
if (m_leadingColumns == 0 && columns.contains("AD_Org_ID") && columns.contains("Account_ID")) if (m_leadingColumns == 0 && columns.contains("AD_Org_ID") && columns.contains("Account_ID"))
m_leadingColumns = columns.size(); m_leadingColumns = columns.size();
return columns; return columns;
} // createKeyColumns } // createKeyColumns
} // AcctViewerData } // AcctViewerData

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -3,10 +3,10 @@
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms version 2 of the GNU General Public License as published * under the terms version 2 of the GNU General Public License as published
* by the Free Software Foundation. This program is distributed in the hope * by the Free Software Foundation. This program is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along * You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
@ -15,405 +15,405 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.cm.request; package org.compiere.cm.request;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Properties; import java.util.Properties;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.compiere.model.MColumn; import org.compiere.model.MColumn;
import org.compiere.model.MRequest; import org.compiere.model.MRequest;
import org.compiere.model.MTable; import org.compiere.model.MTable;
import org.compiere.model.PO; import org.compiere.model.PO;
import org.compiere.model.X_AD_Reference; import org.compiere.model.X_AD_Reference;
import org.compiere.util.DB; import org.compiere.util.DB;
/** /**
* Request Class to create or update Requests. * Request Class to create or update Requests.
* *
* @author Kai Viiksaar * @author Kai Viiksaar
* @version $Id: Request.java,v 1.3 2006/10/16 11:34:47 comdivision Exp $ * @version $Id: Request.java,v 1.3 2006/10/16 11:34:47 comdivision Exp $
*/ */
public class Request { public class Request {
//Integer values //Integer values
private final static int i_integer = 11; private final static int i_integer = 11;
private final static int i_id = 13; private final static int i_id = 13;
private final static int i_table = 18; private final static int i_table = 18;
private final static int i_tableDirect = 19; private final static int i_tableDirect = 19;
private final static int i_rowID = 26; private final static int i_rowID = 26;
private final static int i_searchField = 30; private final static int i_searchField = 30;
//BigDecimal values //BigDecimal values
private final static int bd_amount = 12; private final static int bd_amount = 12;
private final static int bd_floatNumber = 22; private final static int bd_floatNumber = 22;
private final static int bd_quantity = 29; private final static int bd_quantity = 29;
private final static int bd_costsAndPrice = 37; private final static int bd_costsAndPrice = 37;
//Date values //Date values
private final static int d_date = 15; private final static int d_date = 15;
private final static int d_dateTime = 16; private final static int d_dateTime = 16;
private final static int d_time = 24; private final static int d_time = 24;
//String values //String values
private final static int s_string = 10; private final static int s_string = 10;
private final static int s_text = 14; private final static int s_text = 14;
private final static int s_textLong = 36; private final static int s_textLong = 36;
private final static int s_list = 17; private final static int s_list = 17;
private final static int s_location = 21; private final static int s_location = 21;
private final static int s_binary = 23; private final static int s_binary = 23;
private final static int s_account = 25; private final static int s_account = 25;
private final static int s_color = 27; private final static int s_color = 27;
private final static int s_button = 28; private final static int s_button = 28;
private final static int s_warehousLocator = 31; private final static int s_warehousLocator = 31;
private final static int simage = 32; private final static int simage = 32;
private final static int s_assignment = 33; private final static int s_assignment = 33;
private final static int s_memo = 34; private final static int s_memo = 34;
private final static int s_productAttribute = 35; private final static int s_productAttribute = 35;
//Boolean values //Boolean values
private final static int b_bool = 20; private final static int b_bool = 20;
/** /**
* Creates a new Request. * Creates a new Request.
* *
* @param request * @param request
* @param ctx * @param ctx
* @return new Request ID * @return new Request ID
*/ */
public static String createRequest(HttpServletRequest request, Properties ctx) { public static String createRequest(HttpServletRequest request, Properties ctx) {
String l_szTrxName = null; String l_szTrxName = null;
String l_szReturn = null; String l_szReturn = null;
boolean l_bSuccess = true; boolean l_bSuccess = true;
BigDecimal l_bdAmt = getParameterAsBD(request, "RequestAmt"); BigDecimal l_bdAmt = getParameterAsBD(request, "RequestAmt");
int l_nOrgID = getParameterAsInt(request, "AD_Org_ID"); int l_nOrgID = getParameterAsInt(request, "AD_Org_ID");
//int l_nSalesRepID = getParameterAsInt(request, "SalesRep_ID"); //int l_nSalesRepID = getParameterAsInt(request, "SalesRep_ID");
int l_nRoleID = getParameterAsInt(request, "AD_Role_ID"); int l_nRoleID = getParameterAsInt(request, "AD_Role_ID");
int l_nRReqTypeID = getParameterAsInt(request, "R_RequestType_ID"); int l_nRReqTypeID = getParameterAsInt(request, "R_RequestType_ID");
int l_nRGroupID = getParameterAsInt(request, "R_Group_ID"); int l_nRGroupID = getParameterAsInt(request, "R_Group_ID");
int l_nRCategoryID = getParameterAsInt(request, "R_Category_ID"); int l_nRCategoryID = getParameterAsInt(request, "R_Category_ID");
int l_nRReqRelID = getParameterAsInt(request, "R_RequestRelated_ID"); int l_nRReqRelID = getParameterAsInt(request, "R_RequestRelated_ID");
int l_nRStatusID = getParameterAsInt(request, "R_Status_ID"); int l_nRStatusID = getParameterAsInt(request, "R_Status_ID");
int l_nRResolID = getParameterAsInt(request, "R_Resolution_ID"); int l_nRResolID = getParameterAsInt(request, "R_Resolution_ID");
int l_nBPartnerID = getParameterAsInt(request, "C_BPartner_ID"); int l_nBPartnerID = getParameterAsInt(request, "C_BPartner_ID");
int l_nUserID = getParameterAsInt(request, "AD_User_ID"); int l_nUserID = getParameterAsInt(request, "AD_User_ID");
int l_nProjectID = getParameterAsInt(request, "C_Project_ID"); int l_nProjectID = getParameterAsInt(request, "C_Project_ID");
int l_nAssetID = getParameterAsInt(request, "A_Asset_ID"); int l_nAssetID = getParameterAsInt(request, "A_Asset_ID");
int l_nOrderID = getParameterAsInt(request, "C_Order_ID"); int l_nOrderID = getParameterAsInt(request, "C_Order_ID");
int l_nInvoiceID = getParameterAsInt(request, "C_Invoice_ID"); int l_nInvoiceID = getParameterAsInt(request, "C_Invoice_ID");
int l_nProductID = getParameterAsInt(request, "M_Product_ID"); int l_nProductID = getParameterAsInt(request, "M_Product_ID");
int l_nPaymentID = getParameterAsInt(request, "C_Payment_ID"); int l_nPaymentID = getParameterAsInt(request, "C_Payment_ID");
int l_nInOutID = getParameterAsInt(request, "M_InOut_ID"); int l_nInOutID = getParameterAsInt(request, "M_InOut_ID");
int l_nRMAID = getParameterAsInt(request, "M_RMA_ID"); int l_nRMAID = getParameterAsInt(request, "M_RMA_ID");
int l_nCampaignID = getParameterAsInt(request, "C_Campaign_ID"); int l_nCampaignID = getParameterAsInt(request, "C_Campaign_ID");
/* /*
* Durchlauf der Parameter Werte. Dabei werden alle <EFBFBD>bergebenen Parameter * Durchlauf der Parameter Werte. Dabei werden alle übergebenen Parameter
* als Columns in der MColumn gesucht und bei einem Treffer diese Werte * als Columns in der MColumn gesucht und bei einem Treffer diese Werte
* dann <EFBFBD>ber set_ValueOfColumn gesetzt * dann über set_ValueOfColumn gesetzt
*/ */
/* MRequest l_newRequest = new MRequest(ctx, 0, l_szTrxName); /* MRequest l_newRequest = new MRequest(ctx, 0, l_szTrxName);
Enumeration l_eParameterNames = request.getParameterNames(); Enumeration l_eParameterNames = request.getParameterNames();
MColumn curColumn = null; MColumn curColumn = null;
int l_nColumnID = 0; int l_nColumnID = 0;
int l_nRefID = 0; int l_nRefID = 0;
while (l_eParameterNames.hasMoreElements()) { while (l_eParameterNames.hasMoreElements()) {
String name = l_eParameterNames.nextElement().toString(); String name = l_eParameterNames.nextElement().toString();
l_nColumnID = l_newRequest.get_ColumnIndex(name); l_nColumnID = l_newRequest.get_ColumnIndex(name);
if (l_nColumnID > -1) { if (l_nColumnID > -1) {
curColumn = new MColumn(ctx, l_nColumnID, l_szTrxName); curColumn = new MColumn(ctx, l_nColumnID, l_szTrxName);
l_nRefID = curColumn.getAD_Reference_ID(); l_nRefID = curColumn.getAD_Reference_ID();
if (l_nRefID == b_bool) { if (l_nRefID == b_bool) {
l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsBool(request, name)); l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsBool(request, name));
} else if (l_nRefID == bd_amount || l_nRefID == bd_costsAndPrice || l_nRefID == bd_floatNumber || l_nRefID == bd_quantity) { } else if (l_nRefID == bd_amount || l_nRefID == bd_costsAndPrice || l_nRefID == bd_floatNumber || l_nRefID == bd_quantity) {
l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsBD(request, name)); l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsBD(request, name));
} else if (l_nRefID == d_date || l_nRefID == d_dateTime || l_nRefID == d_time) { } else if (l_nRefID == d_date || l_nRefID == d_dateTime || l_nRefID == d_time) {
l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsDate(request, name)); l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsDate(request, name));
} else if (l_nRefID == i_id || l_nRefID == i_integer || l_nRefID == i_rowID || l_nRefID == i_searchField || l_nRefID == i_table || l_nRefID == i_table) { } else if (l_nRefID == i_id || l_nRefID == i_integer || l_nRefID == i_rowID || l_nRefID == i_searchField || l_nRefID == i_table || l_nRefID == i_table) {
l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsInt(request, name)); l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsInt(request, name));
} else { } else {
l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsString(request, name)); l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsString(request, name));
} }
} }
} }
l_bSuccess &= l_newRequest.save(); l_bSuccess &= l_newRequest.save();
*/ */
MRequest newRequest = new MRequest(ctx, 0, l_szTrxName); MRequest newRequest = new MRequest(ctx, 0, l_szTrxName);
// values for values no fieldgroup // values for values no fieldgroup
newRequest.setAD_Org_ID(l_nOrgID); newRequest.setAD_Org_ID(l_nOrgID);
newRequest.setDueType(getParameterAsString(request, "DueType")); newRequest.setDueType(getParameterAsString(request, "DueType"));
newRequest.setR_RequestType_ID(l_nRReqTypeID); newRequest.setR_RequestType_ID(l_nRReqTypeID);
newRequest.setR_Group_ID(l_nRGroupID); newRequest.setR_Group_ID(l_nRGroupID);
newRequest.setR_Category_ID(l_nRCategoryID); newRequest.setR_Category_ID(l_nRCategoryID);
newRequest.setR_RequestRelated_ID(l_nRReqRelID); newRequest.setR_RequestRelated_ID(l_nRReqRelID);
newRequest.setR_Status_ID(l_nRStatusID); newRequest.setR_Status_ID(l_nRStatusID);
newRequest.setR_Resolution_ID(l_nRResolID); newRequest.setR_Resolution_ID(l_nRResolID);
newRequest.setPriority(getParameterAsString(request, "Priority")); newRequest.setPriority(getParameterAsString(request, "Priority"));
newRequest.setPriorityUser(getParameterAsString(request, "PriorityUser")); newRequest.setPriorityUser(getParameterAsString(request, "PriorityUser"));
newRequest.setSummary(getParameterAsString(request, "Summary")); newRequest.setSummary(getParameterAsString(request, "Summary"));
newRequest.setConfidentialType(getParameterAsString(request, "ConfidentialType")); newRequest.setConfidentialType(getParameterAsString(request, "ConfidentialType"));
newRequest.setIsInvoiced(getParameterAsBool(request, "IsInvoiced")); newRequest.setIsInvoiced(getParameterAsBool(request, "IsInvoiced"));
// Mandatory values for fieldgroup Action // Mandatory values for fieldgroup Action
newRequest.setConfidentialTypeEntry(getParameterAsString(request, "ConfidentialTypeEntry")); newRequest.setConfidentialTypeEntry(getParameterAsString(request, "ConfidentialTypeEntry"));
newRequest.setAD_Role_ID(l_nRoleID); newRequest.setAD_Role_ID(l_nRoleID);
//newRequest.setSalesRep_ID(l_nSalesRepID); //newRequest.setSalesRep_ID(l_nSalesRepID);
// values for fieldgroup Reference // values for fieldgroup Reference
newRequest.setC_BPartner_ID(l_nBPartnerID); newRequest.setC_BPartner_ID(l_nBPartnerID);
newRequest.setAD_User_ID(l_nUserID); newRequest.setAD_User_ID(l_nUserID);
newRequest.setC_Project_ID(l_nProjectID); newRequest.setC_Project_ID(l_nProjectID);
newRequest.setA_Asset_ID(l_nAssetID); newRequest.setA_Asset_ID(l_nAssetID);
newRequest.setC_Order_ID(l_nOrderID); newRequest.setC_Order_ID(l_nOrderID);
newRequest.setC_Invoice_ID(l_nInvoiceID); newRequest.setC_Invoice_ID(l_nInvoiceID);
newRequest.setM_Product_ID(l_nProductID); newRequest.setM_Product_ID(l_nProductID);
newRequest.setC_Payment_ID(l_nPaymentID); newRequest.setC_Payment_ID(l_nPaymentID);
newRequest.setM_InOut_ID(l_nInOutID); newRequest.setM_InOut_ID(l_nInOutID);
newRequest.setM_RMA_ID(l_nRMAID); newRequest.setM_RMA_ID(l_nRMAID);
newRequest.setRequestAmt(l_bdAmt); newRequest.setRequestAmt(l_bdAmt);
newRequest.setC_Campaign_ID(l_nCampaignID); newRequest.setC_Campaign_ID(l_nCampaignID);
l_bSuccess &= newRequest.save(); l_bSuccess &= newRequest.save();
if (l_bSuccess) { if (l_bSuccess) {
try { try {
DB.commit(true, l_szTrxName); DB.commit(true, l_szTrxName);
l_szReturn = "" + newRequest.get_ID(); l_szReturn = "" + newRequest.get_ID();
} catch (Exception e) { } catch (Exception e) {
l_szReturn = e.getMessage(); l_szReturn = e.getMessage();
} }
} }
return l_szReturn; return l_szReturn;
} }
/** /**
* Updates a Request. * Updates a Request.
* *
* @param request * @param request
* @param ctx * @param ctx
* @return * @return
*/ */
public static String changeRequest(HttpServletRequest request, Properties ctx) { public static String changeRequest(HttpServletRequest request, Properties ctx) {
String l_szTrxName = null; String l_szTrxName = null;
String l_szReturn = null; String l_szReturn = null;
boolean l_bSuccess = true; boolean l_bSuccess = true;
BigDecimal l_bdAmt = getParameterAsBD(request, "RequestAmt"); BigDecimal l_bdAmt = getParameterAsBD(request, "RequestAmt");
int l_nReqID = getParameterAsInt(request, "R_Request_ID"); int l_nReqID = getParameterAsInt(request, "R_Request_ID");
int l_nOrgID = getParameterAsInt(request, "AD_Org_ID"); int l_nOrgID = getParameterAsInt(request, "AD_Org_ID");
//int l_nSalesRepID = getParameterAsInt(request, "SalesRep_ID"); //int l_nSalesRepID = getParameterAsInt(request, "SalesRep_ID");
int l_nRReqTypeID = getParameterAsInt(request, "R_RequestType_ID"); int l_nRReqTypeID = getParameterAsInt(request, "R_RequestType_ID");
int l_nRGroupID = getParameterAsInt(request, "R_Group_ID"); int l_nRGroupID = getParameterAsInt(request, "R_Group_ID");
int l_nRCategoryID = getParameterAsInt(request, "R_Category_ID"); int l_nRCategoryID = getParameterAsInt(request, "R_Category_ID");
int l_nRReqRelID = getParameterAsInt(request, "R_RequestRelated_ID"); int l_nRReqRelID = getParameterAsInt(request, "R_RequestRelated_ID");
int l_nRStatusID = getParameterAsInt(request, "R_Status_ID"); int l_nRStatusID = getParameterAsInt(request, "R_Status_ID");
int l_nRResolID = getParameterAsInt(request, "R_Resolution_ID"); int l_nRResolID = getParameterAsInt(request, "R_Resolution_ID");
int l_nBPartnerID = getParameterAsInt(request, "C_BPartner_ID"); int l_nBPartnerID = getParameterAsInt(request, "C_BPartner_ID");
int l_nUserID = getParameterAsInt(request, "AD_User_ID"); int l_nUserID = getParameterAsInt(request, "AD_User_ID");
int l_nProjectID = getParameterAsInt(request, "C_Project_ID"); int l_nProjectID = getParameterAsInt(request, "C_Project_ID");
int l_nAssetID = getParameterAsInt(request, "A_Asset_ID"); int l_nAssetID = getParameterAsInt(request, "A_Asset_ID");
int l_nOrderID = getParameterAsInt(request, "C_Order_ID"); int l_nOrderID = getParameterAsInt(request, "C_Order_ID");
int l_nInvoiceID = getParameterAsInt(request, "C_Invoice_ID"); int l_nInvoiceID = getParameterAsInt(request, "C_Invoice_ID");
int l_nProductID = getParameterAsInt(request, "M_Product_ID"); int l_nProductID = getParameterAsInt(request, "M_Product_ID");
int l_nPaymentID = getParameterAsInt(request, "C_Payment_ID"); int l_nPaymentID = getParameterAsInt(request, "C_Payment_ID");
int l_nInOutID = getParameterAsInt(request, "M_InOut_ID"); int l_nInOutID = getParameterAsInt(request, "M_InOut_ID");
int l_nRMAID = getParameterAsInt(request, "M_RMA_ID"); int l_nRMAID = getParameterAsInt(request, "M_RMA_ID");
int l_nCampaignID = getParameterAsInt(request, "C_Campaign_ID"); int l_nCampaignID = getParameterAsInt(request, "C_Campaign_ID");
int l_nResponseID = getParameterAsInt(request, "R_StandardResponse_ID"); int l_nResponseID = getParameterAsInt(request, "R_StandardResponse_ID");
int l_nMailTextID = getParameterAsInt(request, "R_MailText_ID"); int l_nMailTextID = getParameterAsInt(request, "R_MailText_ID");
int l_nActivityID = getParameterAsInt(request, "C_Activity_ID"); int l_nActivityID = getParameterAsInt(request, "C_Activity_ID");
int l_nProdSpentID = getParameterAsInt(request, "M_ProductSpent_ID"); int l_nProdSpentID = getParameterAsInt(request, "M_ProductSpent_ID");
BigDecimal l_QtySpent = getParameterAsBD(request, "QtySpent"); BigDecimal l_QtySpent = getParameterAsBD(request, "QtySpent");
BigDecimal l_QtyInvoiced = getParameterAsBD(request, "QtyInvoiced"); BigDecimal l_QtyInvoiced = getParameterAsBD(request, "QtyInvoiced");
BigDecimal l_QtyPlan = getParameterAsBD(request, "QtyPlan"); BigDecimal l_QtyPlan = getParameterAsBD(request, "QtyPlan");
Timestamp l_tsDateNextAction = getParameterAsDate(request, "DateNextAction"); Timestamp l_tsDateNextAction = getParameterAsDate(request, "DateNextAction");
Timestamp l_tsDateStartPlan = getParameterAsDate(request, "DateStartPlan"); Timestamp l_tsDateStartPlan = getParameterAsDate(request, "DateStartPlan");
Timestamp l_tsDateCompletePlan = getParameterAsDate(request, "DateCompletePlan"); Timestamp l_tsDateCompletePlan = getParameterAsDate(request, "DateCompletePlan");
Timestamp l_tsStartDate = getParameterAsDate(request, "StartDate"); Timestamp l_tsStartDate = getParameterAsDate(request, "StartDate");
Timestamp l_tsCloseDate = getParameterAsDate(request, "CloseDate"); Timestamp l_tsCloseDate = getParameterAsDate(request, "CloseDate");
MRequest newRequest = new MRequest(ctx, l_nReqID, l_szTrxName); MRequest newRequest = new MRequest(ctx, l_nReqID, l_szTrxName);
// values for values no fieldgroup // values for values no fieldgroup
newRequest.setAD_Org_ID(l_nOrgID); newRequest.setAD_Org_ID(l_nOrgID);
newRequest.setDueType(getParameterAsString(request, "DueType")); newRequest.setDueType(getParameterAsString(request, "DueType"));
newRequest.setR_RequestType_ID(l_nRReqTypeID); newRequest.setR_RequestType_ID(l_nRReqTypeID);
newRequest.setR_Group_ID(l_nRGroupID); newRequest.setR_Group_ID(l_nRGroupID);
newRequest.setR_Category_ID(l_nRCategoryID); newRequest.setR_Category_ID(l_nRCategoryID);
newRequest.setR_RequestRelated_ID(l_nRReqRelID); newRequest.setR_RequestRelated_ID(l_nRReqRelID);
newRequest.setR_Status_ID(l_nRStatusID); newRequest.setR_Status_ID(l_nRStatusID);
newRequest.setR_Resolution_ID(l_nRResolID); newRequest.setR_Resolution_ID(l_nRResolID);
newRequest.setPriority(getParameterAsString(request, "Priority")); newRequest.setPriority(getParameterAsString(request, "Priority"));
newRequest.setPriorityUser(getParameterAsString(request, "PriorityUser")); newRequest.setPriorityUser(getParameterAsString(request, "PriorityUser"));
newRequest.setSummary(getParameterAsString(request, "Summary")); newRequest.setSummary(getParameterAsString(request, "Summary"));
newRequest.setConfidentialType(getParameterAsString(request, "ConfidentialType")); newRequest.setConfidentialType(getParameterAsString(request, "ConfidentialType"));
newRequest.setIsInvoiced(getParameterAsBool(request, "IsInvoiced")); newRequest.setIsInvoiced(getParameterAsBool(request, "IsInvoiced"));
// values for fieldgroup Action // values for fieldgroup Action
newRequest.setDateNextAction(l_tsDateNextAction); newRequest.setDateNextAction(l_tsDateNextAction);
newRequest.setConfidentialTypeEntry(getParameterAsString(request, "ConfidentialTypeEntry")); newRequest.setConfidentialTypeEntry(getParameterAsString(request, "ConfidentialTypeEntry"));
newRequest.setR_StandardResponse_ID(l_nResponseID); newRequest.setR_StandardResponse_ID(l_nResponseID);
newRequest.setR_MailText_ID(l_nMailTextID); newRequest.setR_MailText_ID(l_nMailTextID);
newRequest.setResult(getParameterAsString(request, "Result")); newRequest.setResult(getParameterAsString(request, "Result"));
newRequest.setC_Activity_ID(l_nActivityID); newRequest.setC_Activity_ID(l_nActivityID);
newRequest.setQtyPlan(l_QtyPlan); newRequest.setQtyPlan(l_QtyPlan);
newRequest.setQtySpent(l_QtySpent); newRequest.setQtySpent(l_QtySpent);
newRequest.setM_ProductSpent_ID(l_nProdSpentID); newRequest.setM_ProductSpent_ID(l_nProdSpentID);
newRequest.setQtyInvoiced(l_QtyInvoiced); newRequest.setQtyInvoiced(l_QtyInvoiced);
newRequest.setDateStartPlan(l_tsDateStartPlan); newRequest.setDateStartPlan(l_tsDateStartPlan);
newRequest.setDateCompletePlan(l_tsDateCompletePlan); newRequest.setDateCompletePlan(l_tsDateCompletePlan);
newRequest.setStartDate(l_tsStartDate); newRequest.setStartDate(l_tsStartDate);
newRequest.setCloseDate(l_tsCloseDate); newRequest.setCloseDate(l_tsCloseDate);
// values for fieldgroup Reference // values for fieldgroup Reference
newRequest.setC_BPartner_ID(l_nBPartnerID); newRequest.setC_BPartner_ID(l_nBPartnerID);
newRequest.setAD_User_ID(l_nUserID); newRequest.setAD_User_ID(l_nUserID);
newRequest.setC_Project_ID(l_nProjectID); newRequest.setC_Project_ID(l_nProjectID);
newRequest.setA_Asset_ID(l_nAssetID); newRequest.setA_Asset_ID(l_nAssetID);
newRequest.setC_Order_ID(l_nOrderID); newRequest.setC_Order_ID(l_nOrderID);
newRequest.setC_Invoice_ID(l_nInvoiceID); newRequest.setC_Invoice_ID(l_nInvoiceID);
newRequest.setM_Product_ID(l_nProductID); newRequest.setM_Product_ID(l_nProductID);
newRequest.setC_Payment_ID(l_nPaymentID); newRequest.setC_Payment_ID(l_nPaymentID);
newRequest.setM_InOut_ID(l_nInOutID); newRequest.setM_InOut_ID(l_nInOutID);
newRequest.setM_RMA_ID(l_nRMAID); newRequest.setM_RMA_ID(l_nRMAID);
newRequest.setRequestAmt(l_bdAmt); newRequest.setRequestAmt(l_bdAmt);
newRequest.setC_Campaign_ID(l_nCampaignID); newRequest.setC_Campaign_ID(l_nCampaignID);
l_bSuccess &= newRequest.save(); l_bSuccess &= newRequest.save();
if (l_bSuccess) { if (l_bSuccess) {
try { try {
DB.commit(true, l_szTrxName); DB.commit(true, l_szTrxName);
l_szReturn = "" + newRequest.get_ID(); l_szReturn = "" + newRequest.get_ID();
} catch (Exception e) { } catch (Exception e) {
l_szReturn = e.getMessage(); l_szReturn = e.getMessage();
} }
} }
return l_szReturn; return l_szReturn;
} }
/** /**
* Returns a Request Parameter as String. * Returns a Request Parameter as String.
* Removes format characters. * Removes format characters.
* *
* @param request * @param request
* @param parameterName * @param parameterName
* @return * @return
*/ */
private static String getParameterAsString(HttpServletRequest request, String parameterName) { private static String getParameterAsString(HttpServletRequest request, String parameterName) {
String l_szReturn = new String(""); String l_szReturn = new String("");
if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") { if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") {
l_szReturn = request.getParameter(parameterName).toString(); l_szReturn = request.getParameter(parameterName).toString();
l_szReturn = l_szReturn.replace("\r",""); l_szReturn = l_szReturn.replace("\r","");
l_szReturn = l_szReturn.replace("\n",""); l_szReturn = l_szReturn.replace("\n","");
} }
return l_szReturn; return l_szReturn;
} }
/** /**
* Returns a Request Parameter as Integer. * Returns a Request Parameter as Integer.
* *
* @param request * @param request
* @param parameterName * @param parameterName
* @return value, 0 if no parameter or parse error * @return value, 0 if no parameter or parse error
*/ */
private static int getParameterAsInt(HttpServletRequest request, String parameterName) { private static int getParameterAsInt(HttpServletRequest request, String parameterName) {
int l_nID = 0; int l_nID = 0;
if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") { if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") {
try { try {
l_nID = Integer.parseInt(request.getParameter(parameterName)); l_nID = Integer.parseInt(request.getParameter(parameterName));
} catch (Exception e) { } catch (Exception e) {
l_nID = 0; l_nID = 0;
} }
} }
return l_nID; return l_nID;
} }
/** /**
* Returns a Request Parameter as BigDecimal. * Returns a Request Parameter as BigDecimal.
* *
* @param request * @param request
* @param parameterName * @param parameterName
* @return value, 0 if no parameter or parse error * @return value, 0 if no parameter or parse error
*/ */
private static BigDecimal getParameterAsBD(HttpServletRequest request, String parameterName) { private static BigDecimal getParameterAsBD(HttpServletRequest request, String parameterName) {
BigDecimal l_bdValue = new BigDecimal(0); BigDecimal l_bdValue = new BigDecimal(0);
if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") { if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") {
try { try {
String l_szValue = request.getParameter(parameterName); String l_szValue = request.getParameter(parameterName);
l_szValue = l_szValue.replace(",", "."); l_szValue = l_szValue.replace(",", ".");
l_bdValue = new BigDecimal(Float.parseFloat(l_szValue)); l_bdValue = new BigDecimal(Float.parseFloat(l_szValue));
} catch (Exception e) { } catch (Exception e) {
l_bdValue = new BigDecimal(0); l_bdValue = new BigDecimal(0);
} }
} }
l_bdValue = l_bdValue.setScale(2, BigDecimal.ROUND_CEILING); l_bdValue = l_bdValue.setScale(2, BigDecimal.ROUND_CEILING);
return l_bdValue; return l_bdValue;
} }
/** /**
* Returns a Parameter as boolean. * Returns a Parameter as boolean.
* *
* @param request * @param request
* @param parameterName * @param parameterName
* @return true if parameter != null * @return true if parameter != null
*/ */
private static boolean getParameterAsBool(HttpServletRequest request, String parameterName) { private static boolean getParameterAsBool(HttpServletRequest request, String parameterName) {
boolean l_bIs = false; boolean l_bIs = false;
if (request.getParameter(parameterName) != null) { if (request.getParameter(parameterName) != null) {
l_bIs = true; l_bIs = true;
} }
return l_bIs; return l_bIs;
} }
/** /**
* Returns a Parameter as Timestamp. * Returns a Parameter as Timestamp.
* *
* @param request * @param request
* @param parameterName * @param parameterName
* @return Timestamp or null * @return Timestamp or null
*/ */
private static Timestamp getParameterAsDate(HttpServletRequest request, String parameterName) { private static Timestamp getParameterAsDate(HttpServletRequest request, String parameterName) {
Date myDate = new Date(); Date myDate = new Date();
SimpleDateFormat ger = new SimpleDateFormat("dd.MM.yyyy"); SimpleDateFormat ger = new SimpleDateFormat("dd.MM.yyyy");
long time = 0; long time = 0;
if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") { if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") {
try { try {
myDate = ger.parse(request.getParameter(parameterName).toString()); myDate = ger.parse(request.getParameter(parameterName).toString());
time = myDate.getTime(); time = myDate.getTime();
} catch (ParseException e) { } catch (ParseException e) {
return null; return null;
} }
return new Timestamp(time); return new Timestamp(time);
} }
return null; return null;
} }
} }