use of com.axelor.apps.hr.db.LeaveLine in project axelor-open-suite by axelor.
the class LeaveServiceImpl method manageSentLeaves.
@Override
@Transactional(rollbackOn = { Exception.class })
public void manageSentLeaves(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.setDaysToValidate(leaveLine.getDaysToValidate().add(leave.getDuration()));
} else {
leaveLine.setDaysToValidate(leaveLine.getDaysToValidate().subtract(leave.getDuration()));
}
}
use of com.axelor.apps.hr.db.LeaveLine in project axelor-open-suite by axelor.
the class LeaveServiceImpl method validate.
@Transactional(rollbackOn = { Exception.class })
@Override
public void validate(LeaveRequest leaveRequest) throws AxelorException {
if (leaveRequest.getLeaveReason().getUnitSelect() == LeaveReasonRepository.UNIT_SELECT_DAYS) {
isOverlapped(leaveRequest);
}
if (leaveRequest.getLeaveReason().getManageAccumulation()) {
manageValidateLeaves(leaveRequest);
}
leaveRequest.setStatusSelect(LeaveRequestRepository.STATUS_VALIDATED);
leaveRequest.setValidatedBy(AuthUtils.getUser());
leaveRequest.setValidationDate(appBaseService.getTodayDate(leaveRequest.getCompany()));
LeaveLine leaveLine = Beans.get(LeaveLineRepository.class).all().filter("self.leaveReason = :leaveReason AND self.employee = :employee").bind("leaveReason", leaveRequest.getLeaveReason()).bind("employee", leaveRequest.getUser().getEmployee()).fetchOne();
if (leaveLine != null) {
leaveRequest.setQuantityBeforeValidation(leaveLine.getQuantity());
}
leaveRequestRepo.save(leaveRequest);
createEvents(leaveRequest);
}
use of com.axelor.apps.hr.db.LeaveLine in project axelor-open-suite by axelor.
the class HumanResourceMobileController method getLeaveReason.
/*
* 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:getLeaveReason
* Content-Type: application/json
*
* URL: com.axelor.apps.hr.mobile.HumanResourceMobileController:getLeaveReason
* fields: no field
*
* payload:
* { "data": {
* "action": "com.axelor.apps.hr.mobile.HumanResourceMobileController:getLeaveReason"
* } }
*/
@Transactional
public void getLeaveReason(ActionRequest request, ActionResponse response) {
try {
User user = AuthUtils.getUser();
List<Map<String, String>> dataList = new ArrayList<>();
if (user == null || user.getEmployee() == null) {
List<LeaveReason> leaveReasonList = Beans.get(LeaveReasonRepository.class).all().fetch();
for (LeaveReason leaveReason : leaveReasonList) {
if (leaveReason.getUnitSelect() == LeaveReasonRepository.UNIT_SELECT_DAYS) {
Map<String, String> map = new HashMap<>();
map.put("name", leaveReason.getName());
map.put("id", leaveReason.getId().toString());
dataList.add(map);
}
}
} else if (user.getEmployee() != null) {
List<LeaveLine> leaveLineList = Beans.get(LeaveLineRepository.class).all().filter("self.employee = ?1", user.getEmployee()).order("name").fetch();
String tmpName = "";
for (LeaveLine leaveLine : leaveLineList) {
String name = leaveLine.getName();
if (tmpName != name) {
Map<String, String> map = new HashMap<>();
map.put("name", leaveLine.getName());
map.put("id", leaveLine.getLeaveReason().getId().toString());
map.put("quantity", leaveLine.getQuantity().toString());
dataList.add(map);
}
tmpName = name;
}
}
response.setData(dataList);
response.setTotal(dataList.size());
} catch (Exception e) {
response.setStatus(-1);
response.setError(e.getMessage());
}
}
use of com.axelor.apps.hr.db.LeaveLine in project axelor-open-suite by axelor.
the class BatchLeaveManagement method createLeaveManagement.
@Transactional(rollbackOn = { Exception.class })
public void createLeaveManagement(Employee employee) throws AxelorException {
if (employee == null || EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
return;
}
batch = batchRepo.find(batch.getId());
LeaveLine leaveLine = null;
LeaveReason leaveReason = batch.getHrBatch().getLeaveReason();
leaveLine = leaveServiceProvider.get().addLeaveReasonOrCreateIt(employee, leaveReason);
BigDecimal dayNumber = batch.getHrBatch().getUseWeeklyPlanningCoef() ? batch.getHrBatch().getDayNumber().multiply(employee.getWeeklyPlanning().getLeaveCoef()) : batch.getHrBatch().getDayNumber();
dayNumber = dayNumber.subtract(new BigDecimal(publicHolidayService.getImposedDayNumber(employee, batch.getHrBatch().getStartDate(), batch.getHrBatch().getEndDate())));
LeaveManagement leaveManagement = leaveManagementService.createLeaveManagement(leaveLine, AuthUtils.getUser(), batch.getHrBatch().getComments(), null, batch.getHrBatch().getStartDate(), batch.getHrBatch().getEndDate(), dayNumber);
BigDecimal qty = leaveLine.getQuantity().add(dayNumber);
BigDecimal totalQty = leaveLine.getTotalQuantity().add(dayNumber);
try {
int integer = LeaveLine.class.getDeclaredField("quantity").getAnnotation(Digits.class).integer();
BigDecimal limit = new BigDecimal((long) Math.pow(10, integer));
if (qty.compareTo(limit) >= 0 || totalQty.compareTo(limit) >= 0) {
throw new AxelorException(employee, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.BATCH_LEAVE_MANAGEMENT_QTY_OUT_OF_BOUNDS), limit.longValue());
}
} catch (NoSuchFieldException | SecurityException e) {
throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR);
}
leaveLine.setQuantity(qty.setScale(4, RoundingMode.HALF_UP));
leaveLine.setTotalQuantity(totalQty.setScale(4, RoundingMode.HALF_UP));
leaveManagementRepository.save(leaveManagement);
leaveLineRepository.save(leaveLine);
updateEmployee(employee);
}
Aggregations