diff --git a/base/src/org/eevolution/model/MHRConcept.java b/base/src/org/eevolution/model/MHRConcept.java index 4212a0f309..4fb4cb7e6a 100644 --- a/base/src/org/eevolution/model/MHRConcept.java +++ b/base/src/org/eevolution/model/MHRConcept.java @@ -15,23 +15,53 @@ *****************************************************************************/ package org.eevolution.model; -import java.math.BigDecimal; -import java.sql.*; -import java.text.*; -import java.util.*; -import java.util.logging.*; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; -import org.compiere.util.*; -import org.compiere.model.*; +import org.compiere.model.Query; +import org.compiere.util.CCache; +import org.compiere.util.DB; +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 Cristina Ghita, www.arhipac.ro */ public class MHRConcept extends X_HR_Concept { + private static final long serialVersionUID = 1L; + + public static MHRConcept get(Properties ctx, int HR_Concept_ID) + { + if (HR_Concept_ID <= 0) + return null; + // + MHRConcept concept = s_cache.get(HR_Concept_ID); + if (concept != null) + return concept; + // + concept = new MHRConcept(ctx, HR_Concept_ID, null); + if (concept.get_ID() != HR_Concept_ID) + { + concept = null; + } + else + { + s_cache.put(HR_Concept_ID, concept); + } + return concept; + } + + /** Cache */ + private static CCache s_cache = new CCache(Table_Name, 100); + /** * Standard Constructor * @param ctx context @@ -64,66 +94,54 @@ public class MHRConcept extends X_HR_Concept { super(ctx, rs, trxName); } - - + + /** * Get Employee's of Payroll Type - * @param payroll Payroll ID - * @param department Department ID - * @param employee Employee_ID + * @param payroll_id Payroll ID + * @param department_id Department ID + * @param employee_id Employee_ID * @param sqlwhere Clause SQLWhere * @return lines */ - public MHRConcept[] getConcepts (int payroll, int department, int employee, String sqlWhere) + public static MHRConcept[] getConcepts (int payroll_id, int department_id, int employee_id, String sqlWhere) { - ArrayList list = new ArrayList(); - String sql = "SELECT * FROM HR_Concept c WHERE c.IsActive='Y' AND c.AD_Client_ID=" +Env.getAD_Client_ID(Env.getCtx())+ - " AND Exists(SELECT * FROM HR_Attribute a WHERE a.HR_Concept_ID=c.HR_Concept_ID " + - " AND (a.HR_Payroll_ID=? OR HR_Payroll_ID IS NULL) )"; - if (department != 0 ) - sql += " AND c.HR_Department_ID = " + department + " "; - if (sqlWhere != null) - sql += sqlWhere; - sql += " ORDER BY c.Value"; + Properties ctx = Env.getCtx(); + List params = new ArrayList(); + StringBuffer whereClause = new StringBuffer(); - log.log(Level.INFO, "Sql : "); + whereClause.append("IsActive='Y' AND AD_Client_ID=?"); + params.add(Env.getAD_Client_ID(Env.getCtx())); - PreparedStatement pstmt = null; - try { - pstmt = DB.prepareStatement(sql, get_TrxName()); - pstmt.setInt(1, payroll); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - MHRConcept concept = new MHRConcept(getCtx(), rs.getInt("HR_Concept_ID"), get_TrxName()); - list.add(concept); - } - rs.close(); - pstmt.close(); - pstmt = null; - }catch (Exception e){ - log.log(Level.SEVERE, "getConcept's", e); + 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); } - finally { - try { - if (pstmt != null) - pstmt.close (); - }catch (Exception e) - {} - pstmt = null; + + if (Util.isEmpty(sqlWhere)) + { + whereClause.append(sqlWhere); } - MHRConcept[] linesConcept = new MHRConcept[list.size()]; - list.toArray(linesConcept); - return linesConcept; + + List 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 " + - " INNER JOIN HR_Concept_Acct ca ON (c.HR_Concept_ID=ca.HR_Concept_ID)" + - " WHERE c.HR_Concept_ID " + getHR_Concept_ID(); + " INNER JOIN HR_Concept_Acct ca ON (c.HR_Concept_ID=ca.HR_Concept_ID)" + + " WHERE c.HR_Concept_ID " + getHR_Concept_ID(); int result = DB.getSQLValue("ConceptCR", sql); if (result > 0) return result; @@ -133,12 +151,12 @@ public class MHRConcept extends X_HR_Concept public int getConceptAccountDR() { String sql = " HR_Revenue_Acct FROM HR_Concept c " + - " INNER JOIN HR_Concept_Acct ca ON (c.HR_Concept_ID=ca.HR_Concept_ID)" + - " WHERE c.HR_Concept_ID " + getHR_Concept_ID(); + " INNER JOIN HR_Concept_Acct ca ON (c.HR_Concept_ID=ca.HR_Concept_ID)" + + " WHERE c.HR_Concept_ID " + getHR_Concept_ID(); int result = DB.getSQLValue("ConceptCR", sql); if (result > 0) return result; return 0; } - + } // HRConcept \ No newline at end of file diff --git a/base/src/org/eevolution/model/MHRPayrollConcept.java b/base/src/org/eevolution/model/MHRPayrollConcept.java index 4bf57acc20..0f7640c476 100644 --- a/base/src/org/eevolution/model/MHRPayrollConcept.java +++ b/base/src/org/eevolution/model/MHRPayrollConcept.java @@ -15,22 +15,27 @@ *****************************************************************************/ package org.eevolution.model; -import java.sql.*; -import java.text.*; -import java.util.*; -import java.util.logging.*; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; -import org.compiere.util.*; -import org.compiere.model.*; +import org.compiere.model.Query; +import org.compiere.util.DB; +import org.compiere.util.Env; /** * Payroll Concept for HRayroll Module * * @author Oscar Gómez Islas * @version $Id: HRPayrollConcept.java,v 1.0 2005/10/05 ogomezi + * + * @author Cristina Ghita, www.arhipac.ro */ public class MHRPayrollConcept extends X_HR_PayrollConcept { + private static final long serialVersionUID = 1L; + /** * Standard Constructor * @param ctx context @@ -51,68 +56,62 @@ public class MHRPayrollConcept extends X_HR_PayrollConcept super(ctx, rs, trxName); } + /** + * Concept constructor + * @param concept + */ + public MHRPayrollConcept (MHRConcept concept, int payroll_id) + { + super(concept.getCtx(), 0, concept.get_TrxName()); + setHR_Payroll_ID(payroll_id); + setHR_Concept_ID(concept.get_ID()); + setName(concept.getName()); + //setAD_Rule_Engine_ID(concept.getAD_Rule_Engine_ID()); + //setIsIncluded(true); + setIsActive(true); + } + /** * Get Concept's of Payroll Type * @param payroll: payroll Type * @param sqlWhere: clausule SQL Where * @return array Concept */ - public MHRPayrollConcept[] getPayrollConcepts (MHRProcess p) //, String columnSql) //(int payroll_ID, int period_ID, Timestamp dateacct, String columnSql) //(int process, String columnSql) // ogi-cd change payroll witch process + public static MHRPayrollConcept[] getPayrollConcepts (MHRProcess p) { - ArrayList listc = new ArrayList(); - String From = "", To=""; // valid the attribute of this concept witch the valid range - From = DB.TO_DATE(p.getDateAcct()); - if (p.getHR_Period_ID() != 0) - { - X_HR_Period pd = new X_HR_Period(Env.getCtx(),p.getHR_Period_ID(),get_TrxName()); - From = DB.TO_DATE(pd.getStartDate()); - To = DB.TO_DATE(pd.getEndDate()); - } + StringBuffer whereClause = new StringBuffer(); + List params = new ArrayList(); - String sql = "SELECT pc.HR_PayrollConcept_ID FROM HR_PayrollConcept pc " // change HR_Concept_ID with HR_Attribute_ID att.HR_Concept_ID - + " INNER JOIN HR_Concept cp ON (cp.HR_Concept_ID=pc.HR_Concept_ID) " - //+ " INNER JOIN HR_Attribute att ON (att.HR_Concept_ID=cp.HR_Concept_ID)" - + " WHERE pc.IsActive='Y' AND pc.HR_Payroll_ID=?"; // AND att.IsActive = 'Y' - //+ " AND " +From+ " >= att.validfrom "; // AND " +To+ " <= att.ValidTo " - //if (columnSql != null) - // sql += " " + columnSql; - sql += " ORDER BY pc.Seqno"; // att.ValidFrom DESC, + whereClause.append("IsActive='Y' AND HR_Payroll_ID=?"); + params.add(Env.getAD_Client_ID(Env.getCtx())); - log.log(Level.INFO, sql); + List list = new Query(Env.getCtx(), Table_Name, whereClause.toString(), null) + .setParameters(params) + .setOrderBy(COLUMNNAME_SeqNo) + .list(); - PreparedStatement pstmt = null; - try { - pstmt = DB.prepareStatement(sql, get_TrxName()); - pstmt.setInt(1, p.getHR_Payroll_ID()); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - MHRPayrollConcept concept = new MHRPayrollConcept(getCtx(), rs.getInt(1), get_TrxName()); - listc.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; - } - MHRPayrollConcept[] linesConcept = new MHRPayrollConcept[listc.size()]; - listc.toArray(linesConcept); - return linesConcept; + return list.toArray(new MHRPayrollConcept[list.size()]); } // getConcept - + 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()); + if (lastSeqNo < 0) + lastSeqNo = 0; + setSeqNo(lastSeqNo + 10); + } + + return true; + } + + } \ No newline at end of file diff --git a/base/src/org/eevolution/model/MHRProcess.java b/base/src/org/eevolution/model/MHRProcess.java index 0ea28b2f78..cc9a2fc57b 100644 --- a/base/src/org/eevolution/model/MHRProcess.java +++ b/base/src/org/eevolution/model/MHRProcess.java @@ -50,6 +50,11 @@ import org.compiere.util.Util; *
  • BF [ 2031197 ] Skips saving */ public class MHRProcess extends X_HR_Process implements DocAction { + /** + * + */ + private static final long serialVersionUID = 1L; + public static int m_process = 0; public static int m_bpartner = 0; public static int m_concept = 0; @@ -235,7 +240,7 @@ public class MHRProcess extends X_HR_Process implements DocAction { 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 = new MHRPayrollConcept(Env.getCtx(),0,get_TrxName()).getPayrollConcepts(this); + linesConcept = MHRPayrollConcept.getPayrollConcepts(this); // Employees linesEmployee = new MHREmployee(Env.getCtx(),0,get_TrxName()).getEmployees(this); // diff --git a/base/src/org/eevolution/process/HRCreateConcept.java b/base/src/org/eevolution/process/HRCreateConcept.java index cbb5bb7cd5..8c43425039 100644 --- a/base/src/org/eevolution/process/HRCreateConcept.java +++ b/base/src/org/eevolution/process/HRCreateConcept.java @@ -14,17 +14,18 @@ //package org.eevolution.process; package org.eevolution.process; -import java.util.Properties; -import org.compiere.model.*; -import org.compiere.util.*; import org.compiere.process.SvrProcess; -import org.eevolution.model.*; +import org.compiere.util.DB; +import org.eevolution.model.MHRConcept; +import org.eevolution.model.MHRPayrollConcept; /** * Create Concept of current Payroll * * @author Oscar Gómez Islas * @version $Id: HRCreateConcept.java,v 1.0 2005/10/24 04:58:38 ogomezi Exp $ + * + * @author Cristina Ghita, www.arhipac.ro */ public class HRCreateConcept extends SvrProcess { @@ -45,31 +46,25 @@ public class HRCreateConcept extends SvrProcess */ protected String doIt () throws Exception { - int count = 1; - int LastSeqNo = DB.getSQLValue("HR_PayrollConcept","SELECT COALESCE(MAX(SeqNo),0) FROM HR_PayrollConcept WHERE HR_Payroll_ID=" + p_HR_Payroll_ID) > 0 - ? DB.getSQLValue("HR_PayrollConcept","SELECT COALESCE(MAX(SeqNo),0) FROM HR_PayrollConcept WHERE HR_Payroll_ID=" + p_HR_Payroll_ID) : 0; - MHRConcept[] linesConcept = new MHRConcept(Env.getCtx(),0,null).getConcepts(p_HR_Payroll_ID,0,0,""); - for(int j = 0; j < linesConcept.length; j++){ // Ciclo para cada Concepto de la Tabla HR_Concept - MHRConcept concept = linesConcept[j]; - int HR_Concept_ID = concept.getHR_Concept_ID(); - // Que sea uno nuevo y que además sea del mismo Cliente. - if( DB.getSQLValue("HR_PayrollConcept","SELECT HR_Concept_ID FROM HR_PayrollConcept "+ - " WHERE HR_Payroll_ID=" + p_HR_Payroll_ID + " AND HR_Concept_ID=" + - HR_Concept_ID) < 0 ) + int count = 0; + + for(MHRConcept concept : MHRConcept.getConcepts(p_HR_Payroll_ID, 0, 0, null)) + { + int HR_Concept_ID = concept.get_ID(); + if(isPayrollConcept(HR_Concept_ID)) { - LastSeqNo = LastSeqNo + 10; - org.eevolution.model.X_HR_PayrollConcept payrollConcept = new org.eevolution.model.X_HR_PayrollConcept (Env.getCtx(), 0, null); - payrollConcept.setHR_Payroll_ID(p_HR_Payroll_ID); - payrollConcept.setHR_Concept_ID(HR_Concept_ID); - payrollConcept.setName(concept.getName()); - //payrollConcept.setAD_Rule_Engine_ID(concept.getAD_Rule_Engine_ID()); - //payrollConcept.setIsIncluded(true); - payrollConcept.setIsActive(true); - payrollConcept.setSeqNo(LastSeqNo); - payrollConcept.save(); - count ++; + MHRPayrollConcept payrollConcept = new MHRPayrollConcept (concept, p_HR_Payroll_ID); + payrollConcept.set_TrxName(get_TrxName()); + payrollConcept.saveEx(); + count++; } - } // Ciclo por Concepto - return "@OK Create / Actualize Concept@: " + (count-1) +" Records."; + } + return "@Created@/@Updated@ #" + count; } // doIt + + private boolean isPayrollConcept(int HR_Concept_ID) + { + final String sql = "SELECT HR_Concept_ID FROM HR_PayrollConcept WHERE HR_Payroll_ID=? AND HR_Concept_ID=?"; + return DB.getSQLValue(get_TrxName(),sql, p_HR_Payroll_ID, HR_Concept_ID) > 0; + } } // Create Concept of the current Payroll