HR & Payroll improvements:
* code cleanup * convert pseudo-static methods to static methods * improved exception handling * removed commented code * minor refactoring
This commit is contained in:
parent
e2bbd1f0cf
commit
98fbc7cf45
|
@ -15,29 +15,115 @@
|
|||
*****************************************************************************/
|
||||
package org.eevolution.model;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.model.MBPartner;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.model.Query;
|
||||
import org.compiere.util.CCache;
|
||||
import org.compiere.util.Env;
|
||||
|
||||
|
||||
/**
|
||||
* Invoice Line Model
|
||||
* HR Employee Model
|
||||
*
|
||||
* @version $Id: MInvoiceLine.java,v 1.54 2005/05/29 06:34:11 jjanke Exp $
|
||||
* @author Victor Perez
|
||||
* @author Cristina Ghita, www.arhipac.ro
|
||||
*/
|
||||
public class MHREmployee extends X_HR_Employee //--
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** Static Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MHREmployee.class);
|
||||
public static MHREmployee get(Properties ctx, int HR_Employee_ID)
|
||||
{
|
||||
if (HR_Employee_ID <= 0)
|
||||
return null;
|
||||
//
|
||||
MHREmployee employee = s_cache.get(HR_Employee_ID);
|
||||
if (employee != null)
|
||||
return employee;
|
||||
//
|
||||
employee = new MHREmployee(ctx, HR_Employee_ID, null);
|
||||
if (employee.get_ID() != HR_Employee_ID)
|
||||
{
|
||||
employee = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_cache.put(HR_Employee_ID, employee);
|
||||
}
|
||||
return employee;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Employees of Process
|
||||
* @param p HR Process
|
||||
* @return Array of Business Partners
|
||||
*/
|
||||
public static MBPartner[] getEmployees (MHRProcess p)
|
||||
{
|
||||
List<Object> params = new ArrayList<Object>();
|
||||
StringBuffer whereClause = new StringBuffer();
|
||||
whereClause.append(" EXISTS (SELECT 1 FROM HR_Employee e WHERE e.C_BPartner_ID = C_BPartner.C_BPartner_ID ");
|
||||
|
||||
// Just active employee
|
||||
whereClause.append(" AND e.IsActive=? ");
|
||||
params.add(true);
|
||||
|
||||
|
||||
if(p.getHR_Payroll_ID() != 0 && p.getHR_Period_ID() != 0) // this payroll not content periods, NOT IS a Regular Payroll > ogi-cd 28Nov2007
|
||||
{
|
||||
whereClause.append(" AND (e.HR_Payroll_ID IS NULL OR e.HR_Payroll_ID=?) " );
|
||||
params.add(p.getHR_Payroll_ID());
|
||||
}
|
||||
|
||||
if(p.getHR_Period_ID() != 0)
|
||||
{
|
||||
whereClause.append(" AND e.StartDate <=? ");
|
||||
params.add(new X_HR_Period(p.getCtx(), p.getHR_Period_ID(), null).getEndDate());
|
||||
}
|
||||
else
|
||||
{
|
||||
whereClause.append(" AND e.StartDate <=? ");
|
||||
params.add(p.getDateAcct());
|
||||
}
|
||||
|
||||
if (p.getHR_Department_ID() != 0) // Selected Department
|
||||
{
|
||||
whereClause.append(" AND e.HR_Department_ID =? ");
|
||||
params.add(p.getHR_Department_ID());
|
||||
}
|
||||
|
||||
whereClause.append(" ) "); // end select from HR_Employee
|
||||
|
||||
if (p.getC_BPartner_ID() != 0 ) // Selected Employee
|
||||
{
|
||||
whereClause.append(" AND C_BPartner_ID =? ");
|
||||
params.add(p.getC_BPartner_ID());
|
||||
}
|
||||
|
||||
List<MBPartner> list = new Query(p.getCtx(), MBPartner.Table_Name, whereClause.toString(), p.get_TrxName())
|
||||
.setParameters(params)
|
||||
.setOnlyActiveRecords(true)
|
||||
.setOrderBy(COLUMNNAME_Name)
|
||||
.list();
|
||||
|
||||
return list.toArray(new MBPartner[list.size()]);
|
||||
} // getEmployees
|
||||
|
||||
public static MHREmployee getActiveEmployee(Properties ctx, int C_BPartner_ID, String trxName)
|
||||
{
|
||||
return new Query(ctx, Table_Name, COLUMNNAME_C_BPartner_ID+"=?", trxName)
|
||||
.setOnlyActiveRecords(true)
|
||||
.setParameters(new Object[]{C_BPartner_ID})
|
||||
.setOrderBy(COLUMNNAME_HR_Employee_ID+" DESC") // just in case...
|
||||
.first();
|
||||
}
|
||||
|
||||
/** Cache */
|
||||
private static CCache<Integer, MHREmployee> s_cache = new CCache<Integer, MHREmployee>(Table_Name, 1000);
|
||||
|
||||
/**************************************************************************
|
||||
* Invoice Line Constructor
|
||||
|
@ -63,63 +149,4 @@ public class MHREmployee extends X_HR_Employee //--
|
|||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MHREmployee
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get Employee's of Payroll Type
|
||||
* @param payroll Payroll ID
|
||||
* @param department Department ID
|
||||
* @param employee Employee ID
|
||||
* @param sqlwhere Clause SQLWhere
|
||||
* @return lines
|
||||
*/
|
||||
public MBPartner[] getEmployees (MHRProcess p) //, String columnSql) //int process, int payroll, int period, int department, int employee,String columnsql)
|
||||
{
|
||||
log.log(Level.INFO,"period: " +p.getHR_Period_ID()+ ", payroll: " +p.getHR_Payroll_ID()+ ", department: " +p.getHR_Department_ID()+ ", employee: " + p.getC_BPartner_ID());
|
||||
ArrayList<MBPartner> list = new ArrayList<MBPartner>();
|
||||
String sql = "SELECT bp.C_BPartner_ID FROM C_BPartner bp INNER JOIN HR_Employee e ON(e.C_BPartner_ID=bp.C_BPartner_ID)" +
|
||||
" WHERE bp.IsActive = 'Y' AND e.IsActive = 'Y'";
|
||||
if(p.getHR_Payroll_ID() != 0 && p.getHR_Period_ID() != 0) // this payroll not content periods, NOT IS a Regular Payroll > ogi-cd 28Nov2007
|
||||
sql += " AND (e.HR_Payroll_ID IS NULL OR e.HR_Payroll_ID=" + p.getHR_Payroll_ID() + ") ";
|
||||
if(p.getHR_Period_ID() != 0)
|
||||
sql += " AND e.StartDate <= " + DB.TO_DATE(new X_HR_Period(Env.getCtx(),p.getHR_Period_ID(),null).getEndDate());
|
||||
else
|
||||
sql += " AND e.StartDate <= " + p.getDateAcct();
|
||||
if (p.getHR_Department_ID() != 0 ) // Department Selected
|
||||
sql += " AND e.HR_Department_ID = " + p.getHR_Department_ID();
|
||||
if (p.getC_BPartner_ID() != 0 ) // Employee Selected
|
||||
sql += " AND bp.C_BPartner_ID = " + p.getC_BPartner_ID();
|
||||
sql += " ORDER BY bp.Name";
|
||||
|
||||
s_log.log(Level.INFO, sql);
|
||||
PreparedStatement pstmt = null;
|
||||
try {
|
||||
pstmt = DB.prepareStatement(sql, get_TrxName());
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
MBPartner Employee = new MBPartner(getCtx(), rs.getInt("C_BPartner_ID"), get_TrxName());
|
||||
list.add(Employee);
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, "getEmployee's", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try {
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
}catch (Exception e)
|
||||
{}
|
||||
pstmt = null;
|
||||
}
|
||||
MBPartner[] linesEmployee = new MBPartner[list.size()];
|
||||
list.toArray(linesEmployee);
|
||||
return linesEmployee;
|
||||
} // getEmployees
|
||||
} // MHREmployee
|
||||
|
|
|
@ -30,6 +30,8 @@ import org.compiere.util.DB;
|
|||
*/
|
||||
public class MHRMovement extends X_HR_Movement
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
|
@ -52,17 +54,6 @@ public class MHRMovement extends X_HR_Movement
|
|||
super(ctx, rs, trxName);
|
||||
} // End Load Constructor
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord
|
||||
* @return true
|
||||
*/
|
||||
/* protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
return true;
|
||||
} // beforeSave*/
|
||||
|
||||
|
||||
/**
|
||||
* Get Employee's of Payroll Type
|
||||
* @param payroll Payroll ID
|
||||
|
@ -119,6 +110,7 @@ public class MHRMovement extends X_HR_Movement
|
|||
* @param sqlwhere Clause SQLWhere
|
||||
* @return lines
|
||||
*/
|
||||
@Deprecated
|
||||
public MHRMovement[] getMovementOk (int HR_Process_ID)
|
||||
{
|
||||
ArrayList<MHRMovement> list = new ArrayList<MHRMovement>();
|
||||
|
|
|
@ -16,13 +16,11 @@
|
|||
package org.eevolution.model;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.compiere.model.Query;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
|
||||
/**
|
||||
* Payroll Concept for HRayroll Module
|
||||
|
@ -73,25 +71,18 @@ public class MHRPayrollConcept extends X_HR_PayrollConcept
|
|||
|
||||
/**
|
||||
* Get Concept's of Payroll Type
|
||||
* @param payroll: payroll Type
|
||||
* @param sqlWhere: clausule SQL Where
|
||||
* @return array Concept
|
||||
* @param p HR process
|
||||
* @return array of HR concepts
|
||||
*/
|
||||
public static MHRPayrollConcept[] getPayrollConcepts (MHRProcess p)
|
||||
{
|
||||
StringBuffer whereClause = new StringBuffer();
|
||||
List<Object> params = new ArrayList<Object>();
|
||||
|
||||
whereClause.append("IsActive='Y' AND HR_Payroll_ID=?");
|
||||
params.add(p.getHR_Payroll_ID());
|
||||
|
||||
List<MHRPayrollConcept> list = new Query(Env.getCtx(), Table_Name, whereClause.toString(), null)
|
||||
.setParameters(params)
|
||||
List<MHRPayrollConcept> list = new Query(p.getCtx(), Table_Name, COLUMNNAME_HR_Payroll_ID+"=?", null)
|
||||
.setOnlyActiveRecords(true)
|
||||
.setParameters(new Object[]{p.getHR_Payroll_ID()})
|
||||
.setOrderBy(COLUMNNAME_SeqNo)
|
||||
.list();
|
||||
|
||||
return list.toArray(new MHRPayrollConcept[list.size()]);
|
||||
} // getConcept
|
||||
}
|
||||
|
||||
public MHRConcept getConcept()
|
||||
{
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Hashtable;
|
|||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.exceptions.AdempiereException;
|
||||
import org.compiere.model.MBPartner;
|
||||
import org.compiere.model.MDocType;
|
||||
import org.compiere.model.MPeriod;
|
||||
|
@ -111,14 +112,13 @@ public class MHRProcess extends X_HR_Process implements DocAction {
|
|||
* Set Processed.
|
||||
* @param processed processed
|
||||
*/
|
||||
public void setProcessed(boolean processed) {
|
||||
public void setProcessed(boolean processed)
|
||||
{
|
||||
super.setProcessed(processed);
|
||||
if (get_ID() == 0)
|
||||
return;
|
||||
String set = "SET Processed='"
|
||||
+ (processed ? "Y" : "N")
|
||||
+ "' WHERE HR_Process_ID=" + getHR_Process_ID();
|
||||
int noLine = DB.executeUpdate("UPDATE HR_Process " + set , get_TrxName());
|
||||
final String sql = "UPDATE HR_Process SET Processed=? WHERE HR_Process_ID=?";
|
||||
DB.executeUpdateEx(sql, new Object[]{processed, get_ID()}, get_TrxName());
|
||||
} // setProcessed
|
||||
|
||||
|
||||
|
@ -126,19 +126,21 @@ public class MHRProcess extends X_HR_Process implements DocAction {
|
|||
* before Save
|
||||
* Create lines From concept payment
|
||||
*/
|
||||
protected boolean beforeSave(boolean newRecord) {
|
||||
if (getAD_Client_ID() == 0) {
|
||||
m_processMsg = "AD_Client_ID = 0";
|
||||
return false;
|
||||
protected boolean beforeSave(boolean newRecord)
|
||||
{
|
||||
if (getAD_Client_ID() == 0)
|
||||
{
|
||||
throw new AdempiereException("@AD_Client_ID@ = 0");
|
||||
}
|
||||
if (getAD_Org_ID() == 0) {
|
||||
if (getAD_Org_ID() == 0)
|
||||
{
|
||||
int context_AD_Org_ID = Env.getAD_Org_ID(getCtx());
|
||||
if (context_AD_Org_ID == 0) {
|
||||
m_processMsg = "AD_Org_ID = 0";
|
||||
return false;
|
||||
if (context_AD_Org_ID == 0)
|
||||
{
|
||||
throw new AdempiereException("@AD_Org_ID@ = *");
|
||||
}
|
||||
setAD_Org_ID(context_AD_Org_ID);
|
||||
log.warning("beforeSave - Changed Org to Context=" + context_AD_Org_ID);
|
||||
log.warning("Changed Org to Context=" + context_AD_Org_ID);
|
||||
}
|
||||
setC_DocType_ID(getC_DocTypeTarget_ID());
|
||||
|
||||
|
@ -198,10 +200,9 @@ public class MHRProcess extends X_HR_Process implements DocAction {
|
|||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE);
|
||||
if (m_processMsg != null)
|
||||
return DocAction.STATUS_Invalid;
|
||||
org.compiere.model.MDocType dt = MDocType.get(getCtx(), getC_DocTypeTarget_ID());
|
||||
|
||||
// Std Period open?
|
||||
MPeriod.testPeriodOpen(getCtx(), period.getDateAcct(), dt.getDocBaseType());
|
||||
MPeriod.testPeriodOpen(getCtx(), period.getDateAcct(), getC_DocTypeTarget_ID());
|
||||
|
||||
// New or in Progress/Invalid
|
||||
if ( DOCSTATUS_Drafted.equals(getDocStatus())
|
||||
|
@ -236,13 +237,12 @@ public class MHRProcess extends X_HR_Process implements DocAction {
|
|||
Env.setContext(Env.getCtx(), "_To", period.getEndDate());
|
||||
}
|
||||
|
||||
// RE-Process, delete movement exept concept type Incidence
|
||||
// RE-Process, delete movement except concept type Incidence
|
||||
int delete = DB.executeUpdate("DELETE FROM HR_Movement m WHERE HR_Process_ID = " +getHR_Process_ID()+ " AND IsRegistered != 'Y' ", get_TrxName());
|
||||
log.info("info HR_Movement deleted = "+ delete + " records");
|
||||
// Concepts
|
||||
|
||||
linesConcept = MHRPayrollConcept.getPayrollConcepts(this);
|
||||
// Employees
|
||||
linesEmployee = new MHREmployee(Env.getCtx(),0,get_TrxName()).getEmployees(this);
|
||||
linesEmployee = MHREmployee.getEmployees(this);
|
||||
//
|
||||
int count = 1;
|
||||
for(MBPartner bp: linesEmployee) //=============================================================== Employee
|
||||
|
@ -250,9 +250,7 @@ public class MHRProcess extends X_HR_Process implements DocAction {
|
|||
log.info("Employee " + count + " ---------------------- " + bp.getName());
|
||||
count++;
|
||||
m_bpartner = bp.getC_BPartner_ID();
|
||||
int employee_ID=0;
|
||||
employee_ID = DB.getSQLValue(get_TrxName(), "SELECT HR_Employee_ID FROM HR_Employee WHERE HR_Employee.IsActive='Y' AND C_BPartner_ID="+m_bpartner);
|
||||
X_HR_Employee employee = new X_HR_Employee(Env.getCtx(),employee_ID,get_TrxName());
|
||||
MHREmployee employee = MHREmployee.getActiveEmployee(getCtx(), m_bpartner, get_TrxName());
|
||||
//Env.setContext(Env.getCtx(), "_DateBirth", employee.getDateBirth());
|
||||
Env.setContext(Env.getCtx(), "_DateStart", employee.getStartDate());
|
||||
Env.setContext(Env.getCtx(), "_DateEnd", employee.getEndDate() == null ? "2999-12-31 00:00:00 0.0" : employee.getEndDate().toString());
|
||||
|
@ -275,8 +273,12 @@ public class MHRProcess extends X_HR_Process implements DocAction {
|
|||
+ " AND att.isActive ='Y'"
|
||||
+ " AND EXISTS (SELECT * FROM HR_Concept conc WHERE conc.HR_Concept_ID = att.HR_Concept_ID )";
|
||||
if (concept.isEmployee())
|
||||
{
|
||||
attSql += " AND att.C_BPartner_ID = " + employee.getC_BPartner_ID();
|
||||
attSql += " AND (att.HR_Employee_ID =" + employee.get_ID() + " OR att.HR_Employee_ID IS NULL)";
|
||||
}
|
||||
|
||||
attSql += " ORDER BY att.ValidFrom DESC";
|
||||
m_attribute = DB.getSQLValue(get_TrxName(),attSql);
|
||||
if (m_attribute < 0 || concept.isRegistered())
|
||||
{
|
||||
|
@ -284,10 +286,9 @@ public class MHRProcess extends X_HR_Process implements DocAction {
|
|||
continue;
|
||||
}
|
||||
MHRAttribute att = new MHRAttribute(Env.getCtx(),m_attribute,get_TrxName());
|
||||
|
||||
log.info("Concept - " + concept.getName());
|
||||
if(!concept.getType().equals(MHRConcept.TYPE_RuleEngine)) // Not Rule Engine - Only put HashTable
|
||||
{
|
||||
log.info("Concept - " + concept.getName());
|
||||
MHRMovement movement = new MHRMovement (Env.getCtx(), 0, get_TrxName());
|
||||
movement.setQty(att.getQty());
|
||||
movement.setAmount(att.getAmount());
|
||||
|
@ -307,7 +308,7 @@ public class MHRProcess extends X_HR_Process implements DocAction {
|
|||
movement.setIsRegistered(concept.isRegistered());
|
||||
movement.setC_Activity_ID(employee.getC_Activity_ID());
|
||||
movement.setProcessed(true);
|
||||
m_movement.put(new Integer(m_concept), movement);
|
||||
m_movement.put(m_concept, movement);
|
||||
}
|
||||
else // Rule Engine, Process and put HashTable
|
||||
{
|
||||
|
@ -372,20 +373,20 @@ public class MHRProcess extends X_HR_Process implements DocAction {
|
|||
movement.setIsRegistered(concept.isRegistered());
|
||||
movement.setC_Activity_ID(employee.getC_Activity_ID());
|
||||
movement.setProcessed(true);
|
||||
m_movement.put(new Integer(m_concept), movement);
|
||||
m_movement.put(m_concept, movement);
|
||||
} // Attribute Rule Engine
|
||||
} // concept
|
||||
|
||||
|
||||
for (MHRPayrollConcept pc: linesConcept)
|
||||
{
|
||||
MHRMovement m = m_movement.get(new Integer(pc.getHR_Concept_ID()));
|
||||
MHRConcept c = new MHRConcept(Env.getCtx(),pc.getHR_Concept_ID(),get_TrxName());
|
||||
MHRMovement m = m_movement.get(pc.getHR_Concept_ID());
|
||||
if(m == null)
|
||||
continue;
|
||||
MHRConcept c = MHRConcept.get(getCtx(), pc.getHR_Concept_ID());
|
||||
if( !c.isRegistered() &&
|
||||
(m.getQty().signum() > 0
|
||||
|| m.getAmount().signum() > 0
|
||||
(m.getQty().signum() >= 0
|
||||
|| m.getAmount().signum() >= 0
|
||||
|| !Util.isEmpty(m.getTextMsg()))
|
||||
)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue