libero HR: Quality Assurance Task

* added proper serialVersionUID

MHRConcept:
* implement caching

MHRConceptCategory:
* added

MHRMovement:
* more helper methods
* cleanup; removed deprecated methods

MHRPayroll:
* implement caching

MRPeriod:
* added

MHRProcess:
* huge refactoring
* moved code from prepareIt to completeIt
* use non-static variables & methods
This commit is contained in:
teo_sarca 2009-01-23 13:44:53 +00:00
parent 17e5112943
commit 19cc25a39e
12 changed files with 994 additions and 674 deletions

View File

@ -75,7 +75,7 @@ public class Doc_Payroll extends Doc
private DocLine[] loadLines(MHRProcess process)
{
ArrayList<DocLine> list = new ArrayList<DocLine>();
MHRMovement[] lines = process.getLines(true, process.getHR_Process_ID());
MHRMovement[] lines = process.getLines(true);
for (int i = 0; i < lines.length; i++)
{
MHRMovement line = lines[i];

View File

@ -23,7 +23,10 @@ import java.util.Properties;
*/
public class MHRAttribute extends X_HR_Attribute
{
private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 3783311896401143394L;
/**
* @param ctx

View File

@ -36,7 +36,15 @@ import org.compiere.util.Util;
*/
public class MHRConcept extends X_HR_Concept
{
private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 8736925494645172953L;
/** Cache */
private static CCache<Integer, MHRConcept> s_cache = new CCache<Integer, MHRConcept>(Table_Name, 100);
/** Cache by Value */
private static CCache<String, MHRConcept> s_cacheValue = new CCache<String, MHRConcept>(Table_Name+"_Value", 100);
public static MHRConcept get(Properties ctx, int HR_Concept_ID)
{
@ -59,8 +67,80 @@ public class MHRConcept extends X_HR_Concept
return concept;
}
/** Cache */
private static CCache<Integer, MHRConcept> s_cache = new CCache<Integer, MHRConcept>(Table_Name, 100);
/**
* Get Concept by Value
* @param ctx
* @param value
* @return
*/
public static MHRConcept forValue(Properties ctx, String value)
{
if (Util.isEmpty(value, true))
{
return null;
}
int AD_Client_ID = Env.getAD_Client_ID(ctx);
final String key = AD_Client_ID+"#"+value;
MHRConcept concept = s_cacheValue.get(key);
if (concept != null)
{
return concept;
}
final String whereClause = COLUMNNAME_Value+"=? AND AD_Client_ID IN (?,?)";
concept = new Query(ctx, Table_Name, whereClause, null)
.setParameters(new Object[]{value, 0, AD_Client_ID})
.setOnlyActiveRecords(true)
.setOrderBy("AD_Client_ID DESC")
.first();
if (concept != null)
{
s_cacheValue.put(key, concept);
s_cache.put(concept.get_ID(), concept);
}
return concept;
}
/**
* Get Employee's of Payroll Type
* @param payroll_id Payroll ID
* @param department_id Department ID
* @param employee_id Employee_ID
* @param sqlwhere Clause SQLWhere
* @return lines
*/
public static MHRConcept[] getConcepts (int payroll_id, int department_id, int employee_id, String sqlWhere)
{
Properties ctx = Env.getCtx();
List<Object> params = new ArrayList<Object>();
StringBuffer whereClause = new StringBuffer();
whereClause.append("AD_Client_ID=?");
params.add(Env.getAD_Client_ID(Env.getCtx()));
whereClause.append(" AND EXISTS (SELECT 1 FROM HR_Attribute a WHERE a.HR_Concept_ID=HR_Concept.HR_Concept_ID ")
.append(" AND (a.HR_Payroll_ID=? OR a.HR_Payroll_ID IS NULL) )");
params.add(payroll_id);
if (department_id != 0 )
{
whereClause.append(" AND HR_Concept.HR_Department_ID=?");
params.add(department_id);
}
if (Util.isEmpty(sqlWhere))
{
whereClause.append(sqlWhere);
}
List<MHRConcept> list = new Query(ctx, Table_Name, whereClause.toString(), null)
.setParameters(params)
.setOnlyActiveRecords(true)
.setOrderBy(COLUMNNAME_Value)
.list();
return list.toArray(new MHRConcept[list.size()]);
} // getConcept
/**
* Standard Constructor
@ -95,48 +175,6 @@ public class MHRConcept extends X_HR_Concept
super(ctx, rs, trxName);
}
/**
* Get Employee's of Payroll Type
* @param payroll_id Payroll ID
* @param department_id Department ID
* @param employee_id Employee_ID
* @param sqlwhere Clause SQLWhere
* @return lines
*/
public static MHRConcept[] getConcepts (int payroll_id, int department_id, int employee_id, String sqlWhere)
{
Properties ctx = Env.getCtx();
List<Object> params = new ArrayList<Object>();
StringBuffer whereClause = new StringBuffer();
whereClause.append("IsActive='Y' AND AD_Client_ID=?");
params.add(Env.getAD_Client_ID(Env.getCtx()));
whereClause.append(" AND EXISTS (SELECT 1 FROM HR_Attribute a WHERE a.HR_Concept_ID=HR_Concept.HR_Concept_ID ")
.append(" AND (a.HR_Payroll_ID=? OR a.HR_Payroll_ID IS NULL) )");
params.add(payroll_id);
if (department_id != 0 )
{
whereClause.append(" AND HR_Concept.HR_Department_ID=?");
params.add(department_id);
}
if (Util.isEmpty(sqlWhere))
{
whereClause.append(sqlWhere);
}
List<MHRConcept> list = new Query(ctx, Table_Name, whereClause.toString(), null)
.setParameters(params)
.setOrderBy(COLUMNNAME_Value)
.list();
return list.toArray(new MHRConcept[list.size()]);
} // getConcept
public int getConceptAccountCR()
{
String sql = " HR_Expense_Acct FROM HR_Concept c " +

View File

@ -0,0 +1,91 @@
/**
*
*/
package org.eevolution.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.model.Query;
import org.compiere.util.CCache;
import org.compiere.util.Env;
/**
* HR Concept Category
*
* @author Cristina Ghita, www.arhipac.ro
*/
public class MHRConceptCategory extends X_HR_Concept_Category
{
/**
*
*/
private static final long serialVersionUID = 8470029939291479283L;
private static CCache<Integer, MHRConceptCategory> s_cache = new CCache<Integer, MHRConceptCategory>(Table_Name, 20);
private static CCache<String, MHRConceptCategory> s_cacheValue = new CCache<String, MHRConceptCategory>(Table_Name+"_Value", 20);
public static MHRConceptCategory get(Properties ctx, int HR_Concept_Category_ID)
{
if (HR_Concept_Category_ID <= 0)
{
return null;
}
// Try cache
MHRConceptCategory cc = s_cache.get(HR_Concept_Category_ID);
if (cc != null)
{
return cc;
}
// Load from DB
cc = new MHRConceptCategory(ctx, HR_Concept_Category_ID, null);
if (cc.get_ID() != HR_Concept_Category_ID)
{
return null;
}
if (cc != null)
{
s_cache.put(HR_Concept_Category_ID, cc);
}
return cc;
}
public static MHRConceptCategory forValue(Properties ctx, String value)
{
if (value == null)
{
return null;
}
final int AD_Client_ID = Env.getAD_Client_ID(ctx);
// Try cache
final String key = AD_Client_ID+"#"+value;
MHRConceptCategory cc = s_cacheValue.get(key);
if (cc != null)
{
return cc;
}
// Try database
final String whereClause = COLUMNNAME_Value+"=? AND AD_Client_ID IN (?,?)";
cc = new Query(ctx, Table_Name, whereClause, null)
.setParameters(new Object[]{value, 0, AD_Client_ID})
.setOnlyActiveRecords(true)
.setOrderBy("AD_Client_ID DESC")
.first();
if (cc != null)
{
s_cacheValue.put(key, cc);
s_cache.put(cc.get_ID(), cc);
}
return cc;
}
public MHRConceptCategory(Properties ctx, int HR_Concept_Category_ID, String trxName)
{
super(ctx, HR_Concept_Category_ID, trxName);
}
public MHRConceptCategory(Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
}
}

View File

@ -27,7 +27,10 @@ import org.compiere.util.Env;
*/
public class MHRDepartment extends X_HR_Department
{
private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 83878114891519775L;
public static List<MHRDepartment> getAll(Properties ctx)
{

View File

@ -32,9 +32,12 @@ import org.compiere.util.Env;
* @author Victor Perez
* @author Cristina Ghita, www.arhipac.ro
*/
public class MHREmployee extends X_HR_Employee //--
public class MHREmployee extends X_HR_Employee
{
private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = -7083160315471023587L;
public static MHREmployee get(Properties ctx, int HR_Employee_ID)
{

View File

@ -14,23 +14,27 @@
* Contributor(s): Victor Perez www.e-evolution.com *
*****************************************************************************/
package org.eevolution.model;
import java.sql.PreparedStatement;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.sql.Timestamp;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.DB;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.util.Env;
import org.compiere.util.Util;
/**
* Payroll Concept for HRayroll Module
*
* @author Oscar Gómez Islas
* @version $Id: HRPayroll.java,v 1.0 2005/10/05 ogomezi
* @author Teo Sarca, www.arhipac.ro
*/
public class MHRMovement extends X_HR_Movement
{
private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 6705848510397126140L;
/**
* Standard Constructor
@ -41,7 +45,7 @@ public class MHRMovement extends X_HR_Movement
public MHRMovement (Properties ctx, int HR_Movement_ID, String trxName)
{
super (ctx, HR_Movement_ID, trxName);
} // HRConcept
}
/**
* Load Constructor
@ -52,101 +56,72 @@ public class MHRMovement extends X_HR_Movement
public MHRMovement (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // End Load Constructor
}
public MHRMovement (MHRProcess proc, MHRConcept concept)
{
this(proc.getCtx(), 0, proc.get_TrxName());
}
public void addAmount(BigDecimal amount)
{
setAmount(getAmount().add(amount != null ? amount : Env.ZERO));
}
public void addQty(BigDecimal qty)
{
setQty(getAmount().add(qty != null ? qty : Env.ZERO));
}
/**
* Get Employee's of Payroll Type
* @param payroll Payroll ID
* @param department Department ID
* @param employee Employee_ID
* @param sqlwhere Clause SQLWhere
* @return lines
* @return true if all movement values (Amount, Qty, Text) are empty or negative
*/
public MHRMovement[] getmovEmployeeok (int payroll, int department, int employee, String sqlWhere)
public boolean isEmpty()
{
ArrayList<MHRMovement> list = new ArrayList<MHRMovement>();
String sql = "SELECT * FROM HR_Concept WHERE IsActive='Y' AND (HR_Payroll_ID=? OR HR_Payroll_ID IS NULL)";
if (department != 0 )
sql += " AND HR_Department_ID = " + department + " ";
if (sqlWhere != null)
sql += sqlWhere;
sql += " ORDER BY Value";
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, payroll);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
MHRMovement concept = new MHRMovement(getCtx(), rs.getInt(1), get_TrxName());
list.add(concept);
}
rs.close();
pstmt.close();
pstmt = null;
}catch (Exception e)
{
log.log(Level.SEVERE, "getConcept's", e);
}
finally
{
try {
if (pstmt != null)
pstmt.close ();
}catch (Exception e)
{}
pstmt = null;
}
MHRMovement[] linesConcept = new MHRMovement[list.size()];
list.toArray(linesConcept);
return linesConcept;
} // getmovEmployee
return getQty().signum() < 0
&& getAmount().signum() < 0
&& Util.isEmpty(getTextMsg());
}
/**
* Get Employee's of Payroll Type
* @param payroll Payroll ID
* @param department Department ID
* @param employee Employee_ID
* @param sqlwhere Clause SQLWhere
* @return lines
* According to the concept type, it's saved in the column specified for the purpose
* @param columnType column type (see MHRConcept.COLUMNTYPE_*)
* @param value
*/
@Deprecated
public MHRMovement[] getMovementOk (int HR_Process_ID)
public void setColumnValue(Object value)
{
ArrayList<MHRMovement> list = new ArrayList<MHRMovement>();
String sql = "SELECT * FROM HR_Movement m" +
" INNER JOIN HR_Concept_Acct ca ON (ca.HR_Concept_ID=m.HR_Concept_ID AND ca.IsActive = 'Y')"+
" WHERE HR_Process_ID=? AND (m.Qty <> 0 OR m.Amount <> 0) ";
sql += " ORDER BY Value";
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, HR_Process_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
final String columnType = getColumnType();
if (MHRConcept.COLUMNTYPE_Quantity.equals(columnType))
{
BigDecimal qty = new BigDecimal(value.toString());
setQty(qty);
setAmount(Env.ZERO);
}
else if(MHRConcept.COLUMNTYPE_Amount.equals(columnType))
{
BigDecimal amount = new BigDecimal(value.toString());
setAmount(amount);
setQty(Env.ZERO);
}
else if(MHRConcept.COLUMNTYPE_Text.equals(columnType))
{
setTextMsg(value.toString().trim());
}
else if(MHRConcept.COLUMNTYPE_Date.equals(columnType))
{
if (value instanceof Timestamp)
{
MHRMovement movement = new MHRMovement(getCtx(), rs.getInt(1), get_TrxName());
list.add(movement);
setServiceDate((Timestamp)value);
}
else
{
setServiceDate(Timestamp.valueOf(value.toString().trim().substring(0, 10)+ " 00:00:00.0"));
}
rs.close();
pstmt.close();
pstmt = null;
}catch (Exception e)
{
log.log(Level.SEVERE, "getConcept's", e);
}
finally
else
{
try {
if (pstmt != null)
pstmt.close ();
}catch (Exception e)
{}
pstmt = null;
throw new AdempiereException("@NotSupported@ @ColumnType@ - "+columnType);
}
MHRMovement[] movementLines = new MHRMovement[list.size()];
list.toArray(movementLines);
return movementLines;
} // getMovement
}
} // HRMovement

View File

@ -19,15 +19,92 @@ import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.model.MCalendar;
import org.compiere.model.Query;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.compiere.util.Util;
/**
* Payroll for HRayroll Module
*
* @author Oscar Gómez Islas
* @version $Id: HRPayroll.java,v 1.0 2005/10/05 ogomezi
*
* @author Cristina Ghita, www.arhipac.ro
*/
public class MHRPayroll extends X_HR_Payroll
{
/**
*
*/
private static final long serialVersionUID = -1407037967021019961L;
/** Cache */
private static CCache<Integer, MHRPayroll> s_cache = new CCache<Integer, MHRPayroll>(Table_Name, 10);
/** Cache */
private static CCache<String, MHRPayroll> s_cacheValue = new CCache<String, MHRPayroll>(Table_Name+"_Value", 10);
/**
* Get Payroll by Value
* @param ctx
* @param value
* @return payroll
*/
public static MHRPayroll forValue(Properties ctx, String value)
{
if (Util.isEmpty(value, true))
{
return null;
}
int AD_Client_ID = Env.getAD_Client_ID(ctx);
final String key = AD_Client_ID+"#"+value;
MHRPayroll payroll = s_cacheValue.get(key);
if (payroll != null)
{
return payroll;
}
final String whereClause = COLUMNNAME_Value+"=? AND AD_Client_ID IN (?,?)";
payroll = new Query(ctx, Table_Name, whereClause, null)
.setParameters(new Object[]{value, 0, AD_Client_ID})
.setOnlyActiveRecords(true)
.setOrderBy("AD_Client_ID DESC")
.first();
if (payroll != null)
{
s_cacheValue.put(key, payroll);
s_cache.put(payroll.get_ID(), payroll);
}
return payroll;
}
/**
* Get Payroll by ID
* @param ctx
* @param HR_Payroll_ID
* @return payroll
*/
public static MHRPayroll get(Properties ctx, int HR_Payroll_ID)
{
if (HR_Payroll_ID <= 0)
return null;
//
MHRPayroll payroll = s_cache.get(HR_Payroll_ID);
if (payroll != null)
return payroll;
//
payroll = new MHRPayroll(ctx, HR_Payroll_ID, null);
if (payroll.get_ID() != HR_Payroll_ID)
{
payroll = null;
}
else
{
s_cache.put(HR_Payroll_ID, payroll);
}
return payroll;
}
/**
* Standard Constructor
* @param ctx context
@ -62,5 +139,4 @@ public class MHRPayroll extends X_HR_Payroll
setClientOrg(calendar);
//setC_Calendar_ID(calendar.getC_Calendar_ID());
} // HRPayroll
} // MPayroll

View File

@ -32,7 +32,10 @@ import org.compiere.util.DB;
*/
public class MHRPayrollConcept extends X_HR_PayrollConcept
{
private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = -4335196239535511224L;
/**
* Standard Constructor
@ -84,18 +87,13 @@ public class MHRPayrollConcept extends X_HR_PayrollConcept
return list.toArray(new MHRPayrollConcept[list.size()]);
}
public MHRConcept getConcept()
{
return new MHRConcept(getCtx(),this.getHR_Concept_ID(),get_TrxName());
}
@Override
protected boolean beforeSave(boolean newRecord)
{
if (getSeqNo() == 0)
{
String sql = "SELECT COALESCE(MAX(SeqNo),0) FROM HR_PayrollConcept WHERE HR_Payroll_ID=?";
int lastSeqNo = DB.getSQLValue(get_TrxName(), sql, getHR_Payroll_ID());
int lastSeqNo = DB.getSQLValueEx(get_TrxName(), sql, getHR_Payroll_ID());
if (lastSeqNo < 0)
lastSeqNo = 0;
setSeqNo(lastSeqNo + 10);

View File

@ -0,0 +1,58 @@
/**
*
*/
package org.eevolution.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.CCache;
/**
* HR Period
* @author Teo Sarca, www.arhipac.ro
*/
public class MHRPeriod extends X_HR_Period
{
/**
*
*/
private static final long serialVersionUID = -7787966459848200539L;
private static CCache<Integer, MHRPeriod> s_cache = new CCache<Integer, MHRPeriod>(Table_Name, 20);
public static MHRPeriod get(Properties ctx, int HR_Period_ID)
{
if (HR_Period_ID <= 0)
{
return null;
}
//
MHRPeriod period = s_cache.get(HR_Period_ID);
if (period != null)
{
return period;
}
// Try Load
period = new MHRPeriod(ctx, HR_Period_ID, null);
if (period.get_ID() == HR_Period_ID)
{
s_cache.put(HR_Period_ID, period);
}
else
{
period = null;
}
return period;
}
public MHRPeriod(Properties ctx, int HR_Period_ID, String trxName)
{
super(ctx, HR_Period_ID, trxName);
}
public MHRPeriod(Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -30,10 +30,14 @@ import org.compiere.util.TimeUtil;
* MHRYear Year for a Payroll
*
* @author Oscar Gómez Islas
* @version $Id: HRYear.java,v 1.0 2007/04/25 ogomezi
*/
public class MHRYear extends X_HR_Year
{
/**
*
*/
private static final long serialVersionUID = -7789699154024839462L;
/**
* Standard Constructor
* @param ctx context