use of com.axelor.apps.hr.db.LeaveReason 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.LeaveReason in project axelor-open-suite by axelor.
the class LeaveController method leaveReasonToJustify.
/* Count Tags displayed on the menu items */
@Transactional
public void leaveReasonToJustify(ActionRequest request, ActionResponse response) {
try {
LeaveRequest leave = request.getContext().asType(LeaveRequest.class);
Boolean leaveToJustify = leave.getToJustifyLeaveReason();
LeaveLine leaveLine = null;
if (!leaveToJustify) {
return;
}
Company company = leave.getCompany();
if (leave.getUser() == null) {
return;
}
if (company == null) {
company = leave.getUser().getActiveCompany();
}
if (company == null) {
return;
}
Beans.get(HRConfigService.class).getLeaveReason(company.getHrConfig());
Employee employee = leave.getUser().getEmployee();
LeaveReason leaveReason = Beans.get(LeaveReasonRepository.class).find(company.getHrConfig().getToJustifyLeaveReason().getId());
if (employee != null) {
employee = Beans.get(EmployeeRepository.class).find(leave.getUser().getEmployee().getId());
leaveLine = Beans.get(LeaveService.class).addLeaveReasonOrCreateIt(employee, leaveReason);
response.setValue("leaveLine", leaveLine);
}
} catch (AxelorException e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.hr.db.LeaveReason 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.LeaveReason 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