FR [ 2039775 ] Refactor/cleanup HRCreatePeriods code
This commit is contained in:
parent
9309d3c6d1
commit
edc4d5a3f0
|
@ -16,12 +16,15 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.eevolution.model;
|
package org.eevolution.model;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.ResultSet;
|
||||||
import java.text.*;
|
import java.sql.Timestamp;
|
||||||
import java.util.*;
|
import java.util.Properties;
|
||||||
import java.util.logging.*;
|
|
||||||
import org.compiere.util.*;
|
import org.compiere.model.MCalendar;
|
||||||
import org.compiere.model.*;
|
import org.compiere.model.MPeriod;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.Msg;
|
||||||
|
import org.compiere.util.TimeUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MHRYear Year for a Payroll
|
* MHRYear Year for a Payroll
|
||||||
|
@ -72,37 +75,34 @@ public class MHRYear extends X_HR_Year
|
||||||
* @param HR_Payroll_ID
|
* @param HR_Payroll_ID
|
||||||
* @return true if created
|
* @return true if created
|
||||||
*/
|
*/
|
||||||
public boolean createPeriods(int HR_Payroll_ID,int HR_Year_ID, int C_Year_ID)
|
public boolean createPeriods()
|
||||||
{
|
{
|
||||||
|
|
||||||
Timestamp StartDate = new Timestamp (System.currentTimeMillis());
|
|
||||||
Timestamp EndDate = new Timestamp (System.currentTimeMillis());
|
|
||||||
int C_Period_ID = 0;
|
|
||||||
int sumDays = 0;
|
int sumDays = 0;
|
||||||
int C_Calendar_ID = DB.getSQLValue("C_Calendar", "SELECT C_Calendar_ID FROM C_Year WHERE C_Year_ID = "+C_Year_ID);
|
int C_Calendar_ID = DB.getSQLValue(get_TrxName(), "SELECT C_Calendar_ID FROM C_Year WHERE C_Year_ID = ?", getC_Year_ID());
|
||||||
if (C_Calendar_ID == 0)
|
if (C_Calendar_ID <= 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
MHRYear hr_year = new MHRYear(Env.getCtx(),HR_Year_ID,get_TrxName());
|
MHRPayroll payroll = new MHRPayroll(getCtx(), getHR_Payroll_ID(), get_TrxName());
|
||||||
|
|
||||||
for (int period = 1; period <= getQty(); period++)
|
for (int period = 1; period <= getQty(); period++)
|
||||||
{
|
{
|
||||||
sumDays = period != 1 ? (period-1) * (getNetDays()) : 0;
|
sumDays = period != 1 ? (period-1) * (getNetDays()) : 0;
|
||||||
StartDate = TimeUtil.addDays(getStartDate(),sumDays);
|
Timestamp StartDate = TimeUtil.addDays(getStartDate(),sumDays);
|
||||||
EndDate = TimeUtil.addDays(StartDate,getNetDays()-1);
|
Timestamp EndDate = TimeUtil.addDays(StartDate,getNetDays()-1);
|
||||||
C_Period_ID = DB.getSQLValue("C_Period","SELECT C_Period_ID FROM C_Period p "
|
int C_Period_ID = DB.getSQLValue(get_TrxName(),
|
||||||
+ " INNER JOIN C_Year y ON (p.C_Year_ID=y.C_Year_ID) "
|
"SELECT C_Period_ID FROM C_Period p "
|
||||||
+ " WHERE " + DB.TO_DATE(EndDate)
|
+ " INNER JOIN C_Year y ON (p.C_Year_ID=y.C_Year_ID) "
|
||||||
+ " BETWEEN p.startdate AND p.endDate AND y.C_Calendar_ID=" + C_Calendar_ID);
|
+ " WHERE "
|
||||||
if(C_Period_ID == 0)
|
+ " ? BETWEEN p.startdate AND p.endDate"
|
||||||
|
+ " AND y.C_Calendar_ID=?",
|
||||||
|
EndDate, C_Calendar_ID);
|
||||||
|
if(C_Period_ID <= 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
MPeriod m_period = new MPeriod(getCtx(), C_Period_ID , get_TrxName());
|
MPeriod m_period = MPeriod.get(getCtx(), C_Period_ID);
|
||||||
MHRPayroll payroll = new MHRPayroll(Env.getCtx(),HR_Payroll_ID,get_TrxName());
|
X_HR_Period HR_Period = new X_HR_Period(getCtx(), 0, get_TrxName());
|
||||||
X_HR_Period HR_Period = new X_HR_Period(Env.getCtx(),0,get_TrxName());
|
HR_Period.setAD_Org_ID(getAD_Org_ID());
|
||||||
HR_Period.setAD_Org_ID(hr_year.getAD_Org_ID());
|
HR_Period.setHR_Year_ID(getHR_Year_ID());
|
||||||
HR_Period.setHR_Year_ID(hr_year.getHR_Year_ID());
|
HR_Period.setHR_Payroll_ID(getHR_Payroll_ID());
|
||||||
HR_Period.setHR_Payroll_ID(HR_Payroll_ID);
|
|
||||||
HR_Period.setName(StartDate.toString().substring(0, 10)+" "+Msg.translate(getCtx(), "To")+" "+EndDate.toString().substring(0, 10) );
|
HR_Period.setName(StartDate.toString().substring(0, 10)+" "+Msg.translate(getCtx(), "To")+" "+EndDate.toString().substring(0, 10) );
|
||||||
HR_Period.setDescription(Msg.translate(getCtx(), "HR_Payroll_ID")+" "+payroll.getName().trim()+" "+Msg.translate(getCtx(), "From")+ " "+period+" " +Msg.translate(getCtx(), "To")+" "+ StartDate.toString().substring(0, 10)+" al "+EndDate.toString().substring(0, 10));
|
HR_Period.setDescription(Msg.translate(getCtx(), "HR_Payroll_ID")+" "+payroll.getName().trim()+" "+Msg.translate(getCtx(), "From")+ " "+period+" " +Msg.translate(getCtx(), "To")+" "+ StartDate.toString().substring(0, 10)+" al "+EndDate.toString().substring(0, 10));
|
||||||
HR_Period.setPeriodNo(period);
|
HR_Period.setPeriodNo(period);
|
||||||
|
@ -112,9 +112,7 @@ public class MHRYear extends X_HR_Year
|
||||||
HR_Period.setEndDate(EndDate);
|
HR_Period.setEndDate(EndDate);
|
||||||
HR_Period.setDateAcct(EndDate);
|
HR_Period.setDateAcct(EndDate);
|
||||||
HR_Period.setIsActive(true);
|
HR_Period.setIsActive(true);
|
||||||
//
|
HR_Period.saveEx();
|
||||||
if ( !HR_Period.save() ) // Creates Period Control
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} // createPeriods
|
} // createPeriods
|
||||||
|
|
|
@ -17,10 +17,9 @@
|
||||||
//package org.eevolution.process;
|
//package org.eevolution.process;
|
||||||
package org.eevolution.process;
|
package org.eevolution.process;
|
||||||
|
|
||||||
import org.compiere.model.*;
|
|
||||||
import org.compiere.util.*;
|
|
||||||
import org.compiere.process.SvrProcess;
|
import org.compiere.process.SvrProcess;
|
||||||
import org.eevolution.model.*;
|
import org.compiere.util.Msg;
|
||||||
|
import org.eevolution.model.MHRYear;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create Periods of Payroll
|
* Create Periods of Payroll
|
||||||
|
@ -30,15 +29,11 @@ import org.eevolution.model.*;
|
||||||
*/
|
*/
|
||||||
public class HRCreatePeriods extends SvrProcess
|
public class HRCreatePeriods extends SvrProcess
|
||||||
{
|
{
|
||||||
private int p_HR_Payroll_ID = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare
|
* Prepare
|
||||||
*/
|
*/
|
||||||
protected void prepare ()
|
protected void prepare ()
|
||||||
{
|
{
|
||||||
int payroll_ID = 0;
|
|
||||||
|
|
||||||
} // prepare
|
} // prepare
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,15 +45,14 @@ public class HRCreatePeriods extends SvrProcess
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
int year_ID = getRecord_ID();
|
int year_ID = getRecord_ID();
|
||||||
p_HR_Payroll_ID = DB.getSQLValue("HR_Year", "SELECT HR_Payroll_ID FROM HR_Year WHERE HR_Year_ID = "+year_ID);
|
|
||||||
MHRYear year = new MHRYear (getCtx(), getRecord_ID(), get_TrxName());
|
MHRYear year = new MHRYear (getCtx(), getRecord_ID(), get_TrxName());
|
||||||
if (year_ID == 0 || year.get_ID() != year_ID)
|
if (year.get_ID() <= 0 || year.get_ID() != year_ID)
|
||||||
return "Year not exist";
|
return "Year not exist";
|
||||||
else if(year.isProcessed())
|
else if(year.isProcessed())
|
||||||
return "No Created, The Period's exist";
|
return "No Created, The Period's exist";
|
||||||
log.info(year.toString());
|
log.info(year.toString());
|
||||||
//
|
//
|
||||||
if (year.createPeriods(p_HR_Payroll_ID,year_ID, year.getC_Year_ID())){
|
if (year.createPeriods()){
|
||||||
year.setProcessed(true);
|
year.setProcessed(true);
|
||||||
year.save();
|
year.save();
|
||||||
return "@OK@ Create Periods";
|
return "@OK@ Create Periods";
|
||||||
|
|
Loading…
Reference in New Issue