use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class LeaveServiceImpl method manageValidateLeaves.
@Override
@Transactional(rollbackOn = { Exception.class })
public void manageValidateLeaves(LeaveRequest leave) throws AxelorException {
Employee employee = leave.getUser().getEmployee();
if (employee == null) {
throw new AxelorException(leave, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), leave.getUser().getName());
}
LeaveLine leaveLine = leaveLineRepo.all().filter("self.employee = ?1 AND self.leaveReason = ?2", employee, leave.getLeaveReason()).fetchOne();
if (leaveLine == null) {
throw new AxelorException(leave, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_LINE), employee.getName(), leave.getLeaveReason().getName());
}
if (leave.getInjectConsumeSelect() == LeaveRequestRepository.SELECT_CONSUME) {
leaveLine.setQuantity(leaveLine.getQuantity().subtract(leave.getDuration()));
if (leaveLine.getQuantity().signum() == -1 && !employee.getNegativeValueLeave()) {
throw new AxelorException(leave, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_ALLOW_NEGATIVE_VALUE_EMPLOYEE), employee.getName());
}
if (leaveLine.getQuantity().signum() == -1 && !leave.getLeaveReason().getAllowNegativeValue()) {
throw new AxelorException(leave, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_ALLOW_NEGATIVE_VALUE_REASON), leave.getLeaveReason().getName());
}
leaveLine.setDaysToValidate(leaveLine.getDaysToValidate().subtract(leave.getDuration()));
leaveLine.setDaysValidated(leaveLine.getDaysValidated().add(leave.getDuration()));
} else {
leaveLine.setQuantity(leaveLine.getQuantity().add(leave.getDuration()));
leaveLine.setDaysToValidate(leaveLine.getDaysToValidate().add(leave.getDuration()));
}
}
use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class HumanResourceMobileController method insertLeave.
/*
* This method is used in mobile application.
* It was in LeaveServiceImpl
* @param request
* @param response
*
* POST /open-suite-webapp/ws/action/com.axelor.apps.hr.mobile.HumanResourceMobileController:insertLeave
* Content-Type: application/json
*
* URL: com.axelor.apps.hr.mobile.HumanResourceMobileController:insertLeave
* fields: leaveReason, fromDateT, startOn, toDateT, endOn, comment
*
* payload:
* { "data": {
* "action": "com.axelor.apps.hr.mobile.HumanResourceMobileController:insertLeave",
* "leaveReason": 10,
* "fromDateT": "2018-02-22T10:30:00",
* "startOn": 1,
* "toDateT": "2018-02-24T:19:30:00",
* "endOn": 1,
* "comment": "no"
* } }
*/
@Transactional(rollbackOn = { Exception.class })
public void insertLeave(ActionRequest request, ActionResponse response) throws AxelorException {
AppBaseService appBaseService = Beans.get(AppBaseService.class);
User user = AuthUtils.getUser();
Map<String, Object> requestData = request.getData();
LeaveReason leaveReason = Beans.get(LeaveReasonRepository.class).find(Long.valueOf(requestData.get("leaveReason").toString()));
Employee employee = user.getEmployee();
if (employee == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), user.getName());
}
if (leaveReason != null) {
LeaveRequest leave = new LeaveRequest();
leave.setUser(user);
Company company = null;
if (employee.getMainEmploymentContract() != null) {
company = employee.getMainEmploymentContract().getPayCompany();
}
leave.setCompany(company);
LeaveLine leaveLine = Beans.get(LeaveLineRepository.class).all().filter("self.employee = ?1 AND self.leaveReason = ?2", employee, leaveReason).fetchOne();
if (leaveLine == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_LINE), employee.getName(), leaveReason.getName());
}
leave.setLeaveReason(leaveReason);
leave.setRequestDate(appBaseService.getTodayDate(company));
if (requestData.get("fromDateT") != null) {
leave.setFromDateT(LocalDateTime.parse(requestData.get("fromDateT").toString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME));
}
leave.setStartOnSelect(new Integer(requestData.get("startOn").toString()));
if (requestData.get("toDateT") != null) {
leave.setToDateT(LocalDateTime.parse(requestData.get("toDateT").toString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME));
}
leave.setEndOnSelect(new Integer(requestData.get("endOn").toString()));
leave.setDuration(Beans.get(LeaveService.class).computeDuration(leave));
leave.setStatusSelect(LeaveRequestRepository.STATUS_AWAITING_VALIDATION);
if (requestData.get("comments") != null) {
leave.setComments(requestData.get("comments").toString());
}
leave = Beans.get(LeaveRequestRepository.class).save(leave);
response.setTotal(1);
response.setValue("id", leave.getId());
}
}
use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class BatchLeaveManagement method generateLeaveManagementLines.
public void generateLeaveManagementLines(List<Employee> employeeList) {
for (Employee employee : employeeList.stream().filter(Objects::nonNull).collect(Collectors.toList())) {
employee = employeeRepository.find(employee.getId());
if (EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
continue;
}
try {
createLeaveManagement(employee);
} catch (AxelorException e) {
TraceBackService.trace(e, ExceptionOriginRepository.LEAVE_MANAGEMENT, batch.getId());
incrementAnomaly();
if (e.getCategory() == TraceBackRepository.CATEGORY_NO_VALUE) {
noValueAnomaly++;
}
if (e.getCategory() == TraceBackRepository.CATEGORY_CONFIGURATION_ERROR) {
confAnomaly++;
}
} finally {
total++;
JPA.clear();
}
}
}
use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class BatchPayrollPreparationGeneration method generatePayrollPreparations.
public void generatePayrollPreparations(List<Employee> employeeList) {
for (Employee employee : employeeList.stream().filter(Objects::nonNull).collect(Collectors.toList())) {
employee = employeeRepository.find(employee.getId());
if (EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
continue;
}
try {
hrBatch = hrBatchRepository.find(batch.getHrBatch().getId());
if (hrBatch.getCompany() != null) {
company = companyRepository.find(hrBatch.getCompany().getId());
}
if (employee.getMainEmploymentContract() != null && employee.getMainEmploymentContract().getStatus() != EmploymentContractRepository.STATUS_CLOSED) {
createPayrollPreparation(employee);
}
} catch (AxelorException e) {
TraceBackService.trace(e, ExceptionOriginRepository.LEAVE_MANAGEMENT, batch.getId());
incrementAnomaly();
if (e.getCategory() == TraceBackRepository.CATEGORY_NO_UNIQUE_KEY) {
duplicateAnomaly++;
} else if (e.getCategory() == TraceBackRepository.CATEGORY_CONFIGURATION_ERROR) {
configurationAnomaly++;
}
} finally {
total++;
JPA.clear();
}
}
}
use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class BatchSeniorityLeaveManagement method generateLeaveManagementLines.
public void generateLeaveManagementLines(List<Employee> employeeList) {
for (Employee employee : employeeList.stream().filter(Objects::nonNull).collect(Collectors.toList())) {
employee = employeeRepository.find(employee.getId());
if (EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
continue;
}
try {
createLeaveManagement(employee);
} catch (AxelorException e) {
TraceBackService.trace(e, ExceptionOriginRepository.LEAVE_MANAGEMENT, batch.getId());
incrementAnomaly();
if (e.getCategory() == TraceBackRepository.CATEGORY_NO_VALUE) {
noValueAnomaly++;
}
if (e.getCategory() == TraceBackRepository.CATEGORY_CONFIGURATION_ERROR) {
confAnomaly++;
}
} finally {
total++;
JPA.clear();
}
}
}
Aggregations